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 is_contiguous_logic issue in dlpack #668

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/python/library/tests/test_cuda_shared_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class DLPackTest(unittest.TestCase):
def test_from_gpu(self):
# Create GPU tensor via PyTorch and CUDA shared memory region with
# enough space
gpu_tensor = torch.ones(4, 4).cuda(0)
gpu_tensor = torch.ones(1, 4, 4).cuda(0)
byte_size = 64
shm_handle = cudashm.create_shared_memory_region("cudashm_data", byte_size, 0)

Expand All @@ -51,7 +51,7 @@ def test_from_gpu(self):

# Make sure the DLPack specification of the shared memory region can
# be consumed by PyTorch
smt = cudashm.as_shared_memory_tensor(shm_handle, "FP32", [4, 4])
smt = cudashm.as_shared_memory_tensor(shm_handle, "FP32", [1, 4, 4])
generated_torch_tensor = torch.from_dlpack(smt)
self.assertTrue(torch.allclose(gpu_tensor, generated_torch_tensor))

Expand Down
3 changes: 3 additions & 0 deletions src/python/library/tritonclient/utils/_dlpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ def is_contiguous_data(
calculated_stride = 1
# iterate stride in reverse order [ndim-1, -1)
for i in reversed(range(ndim)):
# don't check stride when shape is 1
if shape[i] == 1:
continue
if stride[i] != calculated_stride:
return False
calculated_stride *= shape[i]
Expand Down