Task 2 of 6

Shape the Output: 2D

output is not just a size — it's a shape. output: [16] launches a line of 16 threads; output: [16, 16] launches a 16×16 grid of 256 threads, and each one gets two coordinates: this.thread.x (column) and this.thread.y (row).

The result comes back with the same shape: a 2D kernel returns an array of rows, indexed result[y][x].

output is a shape — [6] is a line, [4, 4] is rows of rows
Goal: turn the kernel into a 16×16 grid that computes a multiplication table — cell [y][x] holds (x + 1) * (y + 1).

Requirements

Hint 1 — reading the shape

output: [width, height] — x runs over width, y over height. The returned value lands in result[y][x].

Same idea elsewhere

2D and 3D launch grids are first-class everywhere: CUDA's dim3 grid/block sizes, WebGPU's workgroup_size and dispatch dimensions. Choosing the launch shape to match the output shape is the same design move on every platform.

All tasks in Data In, Data Out

  1. Pass an Array In
  2. Shape the Output: 2D
  3. Grayscale, the GPU way
  4. Read the Results Back
  5. Images Are Just Arrays
  6. Put It Together: Two Kernels

This page is an interactive exercise — the editor, the GPU runner and your saved progress need JavaScript. The text above is the full brief.