Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Numba serialization when strides is None #3166

Merged
merged 4 commits into from Oct 24, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion distributed/protocol/numba.py
Expand Up @@ -18,9 +18,20 @@ def serialize_numba_ndarray(x):
@cuda_deserialize.register(numba.cuda.devicearray.DeviceNDArray)
def deserialize_numba_ndarray(header, frames):
(frame,) = frames
strides = header["strides"]

# Starting with __cuda_array_interface__ version 2, strides can be None,
# meaning the array is C-contiguous, so we have to calculate it.
if strides is None:
itemsize = np.dtype(header["typestr"]).itemsize
strides = list(header["shape"][1:]) + [itemsize]
for i in range(len(strides) - 1, 0, -1):
strides[i - 1] *= strides[i]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want something like the following?

strides = np.cumprod(shape[::-1]) * itemsize

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why didn't this show up in tests? Don't we test with a C-contiguous array?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion, it's indeed what I wanted and couldn't think of when I wrote the code.

There are two reasons it didn't show up in the tests:

  1. CUDA code is not being tested by CI;
  2. Numba >= 0.46.0 is required (which contains version 2 of __cuda_array_interface__.

strides = tuple(strides)

arr = numba.cuda.devicearray.DeviceNDArray(
header["shape"],
header["strides"],
strides,
np.dtype(header["typestr"]),
gpu_data=numba.cuda.as_cuda_array(frame).gpu_data,
)
Expand Down