[BUG] `wp.array()` handles `copy` and non-contiguous vector/matrix input differently on CPU and CUDA
Author: christophercrouzetCreated Jan 9, 2025Updated Sep 28, 2026
Labelsbuginterop
Bug Description
wp.array(data, dtype=..., copy=...) behaves differently on CPU and CUDA. On CPU, the input goes through NumPy. On CUDA, Warp reads __cuda_array_interface__ directly (see array._init_from_data in warp/_src/types.py). The difference shows when the input's last axis isn't contiguous:
import torch
import warp as wp
for device in ("cpu", "cuda:0"):
# (6, 4) int32 view whose last axis is not contiguous
t = torch.arange(24, dtype=torch.int32, device=wp.device_to_torch(device)).reshape(4, 6).T
for dtype in (wp.int32, wp.vec2i):
for copy in (True, False):
try:
a = wp.array(t, dtype=dtype, device=device, copy=copy)
result = f"shape={a.shape}, {'aliased' if a.ptr == t.data_ptr() else 'copied'}"
except RuntimeError as e:
result = f"RuntimeError: {e}"
print(f"{device:6} {dtype.__name__:5} copy={copy!s:5} -> {result}")Output on main (cf3147b):
cpu int32 copy=True -> shape=(6, 4), copied
cpu int32 copy=False -> shape=(6, 4), aliased
cpu vec2i copy=True -> shape=(6, 2), copied
cpu vec2i copy=False -> shape=(6, 2), copied
cuda:0 int32 copy=True -> shape=(6, 4), aliased
cuda:0 int32 copy=False -> shape=(6, 4), aliased
cuda:0 vec2i copy=True -> RuntimeError: The inner strides of the input array (4, 24) are not compatible with the requested data type vec2i
cuda:0 vec2i copy=False -> RuntimeError: The inner strides of the input array (4, 24) are not compatible with the requested data type vec2i- On CPU,
copy=Falsecan still copy. When the input can't be aliased asvec2i, the CPU path copies it without warning, so writes to the result never reacht. CUDA raises in the same situation. - On CUDA,
copyhas no effect, and the docstring doesn't say so. Every__cuda_array_interface__input is aliased, even withcopy=True.docs/user_guide/runtime.rstalready documentswp.array(cupy_array)as zero-copy by default, but thecopydocstring says the parameter chooses between copying and aliasing. - Minor: the same rejection gives different error messages on each device. For example, converting a
(3,)vec2sarray tovec3sfails withThe inner dimensions of the input data are not compatible ...on CPU andThe shape of the input array (3, 2) is not compatible ...on CUDA.
Expected behavior
copy=Falsealiases the input or raises, on every device. It never copies without telling the caller.- CUDA keeps aliasing
__cuda_array_interface__inputs regardless ofcopy, and raises when an input can't be aliased. Thecopydocstring documents this. - The same failure raises the same error on every device.
Source: NVIDIA/warp