PIXELBANKv9.1.0
Menu

Problem Statement

Implement SAXPY — "Single-precision A·X Plus Y" — the classic BLAS Level-1 kernel: out = a * x + y for two 1D arrays and a runtime scalar a.

Background

SAXPY is the textbook fused multiply-add over vectors. Each thread does one multiply and one add, reading two inputs and writing one output.

Your Task

Implement saxpy_kernel and run(n=1024, a=2.0) returning whether the result matches a * x + y.

How it is tested

Your solution must define a top-level function run(...) that allocates the inputs, copies them to the GPU, launches your @cuda.jit kernel, and returns a Python bool from np.allclose(gpu_result, reference). The grader prints run(...); the expected output is True.

Example:

Input:
n = 1024, a = 2.0
Output:
True
Reasoning:
  • The input values are n = 1024 and a = 2.0, which are used to generate two 1D arrays x and y of length n.
  • The saxpy_kernel function is launched on the GPU, where each thread performs the calculation out = a * x + y for corresponding elements in x and y.
  • The result is stored in the out array and copied back to the host, where it is compared to the reference result calculated using np.allclose(gpu_result, reference).
  • The comparison checks if the result of the GPU calculation out = 2.0 * x + y matches the reference result within a small tolerance, resulting in the output True if the results match.

Constraints:

  • out[i] = a * x[i] + y[i]
  • a is a runtime scalar argument
  • Bounds-check the global index
solution.py

Test Results

0/0
Run code to see test results.
CUDA SAXPY Kernel - Easy | PixelBank