Task 5 of 5
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.
ramp return scale * this.thread.x,
then call it twice — once with 2.5, once with 0.5.scale parameterKernel arguments are ordinary function parameters:
function (scale) { … }, called as await ramp(3). Every one of
the 64 threads receives the same 3.
return scale * this.thread.x; — the argument is shared, the
index is per-thread, the product is different in every cell.
setBytes. And build-once/dispatch-many is universal too — shader and kernel
compilation is expensive everywhere, so it's paid once up front.
This page is an interactive exercise — the editor, the GPU runner and your saved progress need JavaScript. The text above is the full brief.