# Who Am I? this.thread.x

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

Sixteen identical 42s prove the launch works, but parallel code is only useful if
each thread can do something *different*. The trick: every thread knows which output
cell it owns. That number is `this.thread.x` — 0 for the first cell, 1 for the
next, up to `output − 1`.

Same function, same arguments, different `this.thread.x` — that one number is
the only thing telling the threads apart, and it's how each one finds its own work.

## Goal

**Goal:** make each of the 32 threads return **its own index**,
so the result counts `0, 1, 2, … 31`.

## Requirements

- Keep `output: [32]` — 32 threads
- Return `this.thread.x` from the kernel body
- No loops, no counters — the index is handed to you

## Hint 1 — it’s already there

You don't compute the index and you don't pass it in. Inside the kernel body,
`this.thread.x` is simply available — gpu.js fills it in per thread.

## Hint 2 — the one-liner

The entire kernel body: `return this.thread.x;`

## Same idea elsewhere

Every platform hands threads this same self-identity, just under a different name:
`threadIdx`/`blockIdx` in CUDA and ROCm/HIP,
`global_invocation_id` in WebGPU's WGSL,
`thread_position_in_grid` in Metal.

## Starter code

```js
// Every thread runs the same body — this.thread.x is what differs.
const gpu = new GPU({ mode });

const whoAmI = gpu.createKernel(function () {
  // TODO: return this thread's own index
  return 0;
}, { output: [32] });

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

---

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

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