Unverified Commit c08192cb authored by nv-dlasalle's avatar nv-dlasalle Committed by GitHub
Browse files

[Bugfix] Allow pinning of empty tensor (#6044)

parent b400af48
...@@ -451,6 +451,8 @@ else: ...@@ -451,6 +451,8 @@ else:
def zerocopy_to_dgl_ndarray_for_write(input): def zerocopy_to_dgl_ndarray_for_write(input):
if input.numel() > 0:
# only check non-empty tensors
assert input.is_contiguous(), ( assert input.is_contiguous(), (
"Cannot convert non-contiguous tensors " "Cannot convert non-contiguous tensors "
"to dgl ndarray for write. Call .to_contiguous() first." "to dgl ndarray for write. Call .to_contiguous() first."
......
...@@ -31,6 +31,10 @@ def test_pin_view(): ...@@ -31,6 +31,10 @@ def test_pin_view():
with pytest.raises(dgl.DGLError): with pytest.raises(dgl.DGLError):
dgl.utils.pin_memory_inplace(v) dgl.utils.pin_memory_inplace(v)
# make sure an empty view does not generate an error
u = t[10:10]
u = dgl.utils.pin_memory_inplace(u)
@pytest.mark.skipif( @pytest.mark.skipif(
F._default_context_str == "cpu", reason="Need gpu for this test." F._default_context_str == "cpu", reason="Need gpu for this test."
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment