# A Second Dimension: this.thread.y

*Task 4 of 5 · [Hello, Kernel](https://gpu.rocks/learn/hello-kernel-f1399353.md) · GPU.js Learn*

Threads don't have to line up in a row. Give `output` two numbers —
`output: [8, 8]` — and gpu.js launches an 8×8 **grid** of 64
threads. Each one now has two coordinates: `this.thread.x` is its column and
`this.thread.y` is its row, and the result comes back as an array of rows you
read as `result[y][x]`.

To prove both coordinates are live, paint a classic: a checkerboard. A cell is
“black” or “white” depending on whether `x + y` is even
or odd — which is just `(x + y) % 2`.

## Figures

- **two coordinates per thread — the grid is the picture**

## Goal

**Goal:** launch an 8×8 grid where each cell holds
`(x + y) % 2` — an alternating pattern of 0s and 1s.

## Requirements

- Change `output` to a grid: `[8, 8]`
- Use `this.thread.x` *and* `this.thread.y`
- Return 0 or 1 in a checkerboard — the parity of the two coordinates added together

## Hint 1 — what changes with 2D?

Two things: `output` gets a second number
(`[width, height]`), and `this.thread.y` starts meaning
something. Nothing else about the kernel changes.

## Hint 2 — the pattern

```js
return (this.thread.x + this.thread.y) % 2;
```

Neighbours differ by one in `x` or `y`, so the parity flips
checkerboard-style.

## Same idea elsewhere

GPUs are built around 2D grids because images are 2D: ROCm and CUDA launch
`dim3`-shaped blocks, WebGPU dispatches workgroups across x/y/z, and Metal's
grids are up to three-dimensional. One thread per pixel — the idea **Data In, Data
Out** runs with —
starts exactly here.

## Starter code

```js
// output: [width, height] launches a whole grid of threads.
const gpu = new GPU({ mode });

const board = gpu.createKernel(function () {
  // TODO: return (x + y) % 2 using BOTH thread coordinates
  return this.thread.x % 2;
}, {
  // TODO: make this an 8×8 grid, not an 8-cell line
  output: [8],
});

const result = await board();
console.log(result);
```

---

Interactive version: https://gpu.rocks/learn/hello-kernel-f1399353/4

[Previous task](https://gpu.rocks/learn/hello-kernel-f1399353/3.md) · [Next task](https://gpu.rocks/learn/hello-kernel-f1399353/5.md)
