PIXELBANKv9.1.0
Menu

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:

Input:
n = 1024
Output:
True
Reasoning:
  • The input n = 1024 determines the size of the 1D arrays a and b.
  • The emax_kernel function is launched, computing the elementwise maximum of a and b using the formula out[i]=maxโก(a[i],b[i])out[i] = \max(a[i], b[i]).
  • The result from the GPU is compared to the reference result from np.maximum(a, b) using np.allclose.
  • The comparison returns True if the two results are close enough, indicating that the GPU computation was correct, resulting in the output True.

Constraints:

  • out[i] = a[i] if a[i] > b[i] else b[i]
  • Two input arrays, one output
  • Bounds-check the global index
๐Ÿ”’

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.