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,11 +451,13 @@ else: ...@@ -451,11 +451,13 @@ else:
def zerocopy_to_dgl_ndarray_for_write(input): def zerocopy_to_dgl_ndarray_for_write(input):
assert input.is_contiguous(), ( if input.numel() > 0:
"Cannot convert non-contiguous tensors " # only check non-empty tensors
"to dgl ndarray for write. Call .to_contiguous() first." assert input.is_contiguous(), (
) "Cannot convert non-contiguous tensors "
check_is_view(input) "to dgl ndarray for write. Call .to_contiguous() first."
)
check_is_view(input)
return zerocopy_to_dgl_ndarray(input) return zerocopy_to_dgl_ndarray(input)
......
...@@ -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