Skip to content

Commit

Permalink
TESTL: GPU map
Browse files Browse the repository at this point in the history
  • Loading branch information
jacky1c committed Sep 8, 2024
1 parent 9890630 commit c3ecffd
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions minitorch/cuda_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,18 @@ def _map(

out_index = cuda.local.array(MAX_DIMS, numba.int32)
in_index = cuda.local.array(MAX_DIMS, numba.int32)
i = cuda.blockIdx.x * cuda.blockDim.x + cuda.threadIdx.x
x = cuda.blockIdx.x * cuda.blockDim.x + cuda.threadIdx.x
# TODO: Implement for Task 3.3.
raise NotImplementedError("Need to implement for Task 3.3")
# raise NotImplementedError("Need to implement for Task 3.3")
out_i = numba.cuda.blockIdx.x * THREADS_PER_BLOCK + numba.cuda.threadIdx.x
if out_i < out.size:
out_index = numba.cuda.local.array(MAX_DIMS, numba.int32)
in_index = numba.cuda.local.array(MAX_DIMS, numba.int32)
to_index(out_i, out_shape, out_index)
broadcast_index(out_index, out_shape, in_shape, in_index)
in_position = index_to_position(in_index, in_strides)
out_position = index_to_position(out_index, out_strides)
out[out_position] = fn(in_storage[in_position])

return cuda.jit()(_map) # type: ignore

Expand Down

0 comments on commit c3ecffd

Please sign in to comment.