#420·warp

[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:

python
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
  1. On CPU, copy=False can still copy. When the input can't be aliased as vec2i, the CPU path copies it without warning, so writes to the result never reach t. CUDA raises in the same situation.
  2. On CUDA, copy has no effect, and the docstring doesn't say so. Every __cuda_array_interface__ input is aliased, even with copy=True. docs/user_guide/runtime.rst already documents wp.array(cupy_array) as zero-copy by default, but the copy docstring says the parameter chooses between copying and aliasing.
  3. Minor: the same rejection gives different error messages on each device. For example, converting a (3,) vec2s array to vec3s fails with The inner dimensions of the input data are not compatible ... on CPU and The shape of the input array (3, 2) is not compatible ... on CUDA.

Expected behavior

  • copy=False aliases the input or raises, on every device. It never copies without telling the caller.
  • CUDA keeps aliasing __cuda_array_interface__ inputs regardless of copy, and raises when an input can't be aliased. The copy docstring documents this.
  • The same failure raises the same error on every device.