CUDA Elementwise Maximum
Problem Statement
Compute the elementwise maximum of two 1D arrays: out[i] = max(a[i], b[i]).
Background
A two-input elementwise kernel: load one value from each array and keep the larger. This is the pattern behind np.maximum and elementwise gating.
Your Task
Implement emax_kernel and run(n=1024) comparing to np.maximum(a, b).
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
n = 1024
True
- The input
n = 1024determines the size of the 1D arraysaandb. - The
emax_kernelfunction is launched, computing the elementwise maximum ofaandbusing the formula . - The result from the GPU is compared to the reference result from
np.maximum(a, b)usingnp.allclose. - The comparison returns
Trueif the two results are close enough, indicating that the GPU computation was correct, resulting in the outputTrue.
Constraints
- out[i] = a[i] if a[i] > b[i] else b[i]
- Two input arrays, one output
- Bounds-check the global index