# Pass an Array In

*Task 1 of 6 · [Data In, Data Out](https://gpu.rocks/learn/data-in-data-out-42b68d01.md) · GPU.js Learn*

Kernels don't reach out and grab data — data is **handed to them**
as arguments, and every thread sees the same arguments. What differs between threads is
exactly one thing: `this.thread.x`, the index of the output cell this thread owns.

Here `data` is a 64-number array. The kernel below runs 64 times — once per
output cell — and each run should pick out *its own* element.

## Goal

**Goal:** make the kernel return **double** the element of
`data` that belongs to this thread.

## Requirements

- Pass `data` into the kernel as an argument (already wired up)
- Index it with `this.thread.x` — no loops over the array
- Return the element multiplied by `2`

## Hint 1 — which element is mine?

With `output: [64]` there are 64 threads, numbered
`this.thread.x` = 0…63. Thread 7 should read `data[7]`.

## Hint 2 — the one-liner

The whole kernel body is a single statement:
`return data[this.thread.x] * 2;`

## Same idea elsewhere

Arguments-in, index-by-thread-id is the universal GPGPU calling convention:
CUDA kernels get device pointers plus `threadIdx`, WebGPU compute shaders get
bound buffers plus `global_invocation_id`. Same shape, different spelling.

## Starter code

```js
// A kernel runs once per output cell — 64 cells here, 64 threads.
const gpu = new GPU({ mode });

const double = gpu.createKernel(function (data) {
  // TODO: return double the value that belongs to THIS thread.
  // Which element is yours? this.thread.x knows.
  return 0;
}, { output: [64] });

const result = await double(data);
console.log(result);
```

---

Interactive version: https://gpu.rocks/learn/data-in-data-out-42b68d01/1

[Next task](https://gpu.rocks/learn/data-in-data-out-42b68d01/2.md)
