# Pass Something In

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

So far every kernel has conjured its output from thread coordinates alone. Real
kernels also take **arguments** — declare a parameter on the kernel function,
pass a value when you call it, and every thread sees that same value. Combine it with
`this.thread.x` and each thread computes something different from shared
input.

Here's the payoff: a compiled kernel is **reusable**. Build it once, call it
with `2.5`, call it again with `0.5` — two parallel launches, zero
recompiles. That build-once/call-many rhythm is how all real GPU code is structured.

## Goal

**Goal:** make `ramp` return `scale * this.thread.x`,
then call it twice — once with `2.5`, once with `0.5`.

## Requirements

- Give the kernel function a `scale` parameter
- Multiply the shared argument by this thread's index — shared argument × thread identity
- Call the kernel twice with different scales (already wired up)

## Hint 1 — where arguments come from

Kernel arguments are ordinary function parameters:
`function (scale) { … }`, called as `await ramp(3)`. Every one of
the 64 threads receives the same `3`.

## Hint 2 — the body

`return scale * this.thread.x;` — the argument is shared, the
index is per-thread, the product is different in every cell.

## Same idea elsewhere

A value shared by all threads is a *uniform*: WebGPU binds it as a uniform
buffer, CUDA and ROCm pass it as a kernel launch parameter, Metal hands it over with
`setBytes`. And build-once/dispatch-many is universal too — shader and kernel
compilation is expensive everywhere, so it's paid once up front.

## Starter code

```js
// Arguments are shared by all threads; this.thread.x stays per-thread.
const gpu = new GPU({ mode });

const ramp = gpu.createKernel(function (scale) {
  // TODO: scale this thread's index by the argument
  return this.thread.x;
}, { output: [64] });

// One kernel, two launches — no recompilation between calls.
console.log('scale 2.5:', await ramp(2.5));
console.log('scale 0.5:', await ramp(0.5));
```

---

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

[Previous task](https://gpu.rocks/learn/hello-kernel-f1399353/4.md)
