Lesson 2 — Scalar parameters (SAXPY)
SAXPY (Single-precision A times X Plus Y) is the
canonical BLAS-1 operation: y[i] = alpha * x[i] + y[i].
It is a staple benchmark because it is memory-bandwidth-bound — the GPU
must stream every element through its caches at least twice.
Scalar uniforms
Scalars like alpha are not per-thread arrays; they are the
same value for every thread. In Sarek you declare them as plain typed
arguments (e.g., (alpha : float32)), and the transpiler
automatically packs them into a uniform buffer that every thread can read.
For this lesson alpha = 2.0 is injected automatically — you
can see it in Show generated WGSL as a field of the
Params uniform struct.
Your task
Complete the kernel so that y.(i) is updated in-place:
y[i] ← alpha * x[i] + y[i].
Click "Run on my GPU" to execute your kernel.
Hint
Float multiplication in OCaml is *. and addition is
+.. Read alpha directly — it is a scalar
argument available in every thread.