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

[BUG] Investigate Inconsistencies With Array Shape and Strides #420

Open
christophercrouzet opened this issue Jan 9, 2025 · 0 comments
Open
Labels
bug Something isn't working

Comments

@christophercrouzet
Copy link
Member

Bug Description

Test case 1:

import torch
import warp as wp


# Setting the device to CUDA yields different results.
device = "cpu"


with wp.ScopedDevice(device):
    torch_device = wp.device_to_torch(device)

    torch_arr = torch.tensor(
        (
            ( 1,  2,  3,  4),
            ( 5,  6,  7,  8),
            ( 9, 10, 11, 12),
            (13, 14, 15, 16),
            (17, 18, 19, 20),
            (21, 22, 23, 24),
        ),
        dtype=torch.int32,
        device=torch_device,
    )
    assert torch_arr.size() == (6, 4)
    assert torch_arr.stride() == (4, 1)

    warp_arr = wp.array(torch_arr)
    assert warp_arr.shape == (6, 4)
    assert warp_arr.strides == (16, 4)

    torch_arr = torch.as_strided(
        torch_arr,
        size=torch_arr.size(),
        stride=(torch_arr.stride(1), torch_arr.stride(0)),
    )
    assert torch_arr.size() == (6, 4)
    assert torch_arr.stride() == (1, 4)

    arr_i32 = wp.array(torch_arr, dtype=wp.int32)
    arr_v2i = wp.array(torch_arr, dtype=wp.vec2i)
    print(f"arr_i32 strides: {arr_i32.strides}, expected: (4, 16), correct: {arr_i32.strides == (4, 16)}")
    print(f"arr_v2i strides: {arr_v2i.strides}, expected: (8, 16), correct: {arr_v2i.strides == (8, 16)}")

# cpu:
# arr_i32 strides: (4, 16), expected: (4, 16), correct: True
# arr_v2i strides: (16, 8), expected: (8, 16), correct: False

# cuda:
# arr_i32 strides: (4, 16), expected: (4, 16), correct: True
# arr_v2i strides: (16, 8), expected: (8, 16), correct: False

Test case 2:

import warp as wp


with wp.ScopedDevice("cuda"):
    array = wp.array(((1, 2), (3, 4), (5, 6)), dtype=wp.vec2s)
    view = wp.array(array, dtype=wp.vec3s)
    assert view.dtype is wp.vec3s
    print(f"shape: {view.shape}, expected: (2,), correct: {view.shape == (2,)}")
    print(f"strides: {view.strides}, expected: (6,), correct: {view.strides == (6,)}")

# RuntimeError: The inner dimensions of the input data are not compatible with the requested vector type vec3s: expected an inner dimension that is a multiple of 3

Test case 3:

import warp as wp


with wp.ScopedDevice("cuda"):
    array = wp.array(((1, 2, 3), (4, 5, 6), (7, 8, 9)), dtype=wp.mat33d)
    view = wp.array(array, dtype=wp.vec3d)
    assert view.dtype is wp.vec3d
    print(f"shape: {view.shape}, expected: (3,), correct: {view.shape == (3,)}")
    print(f"strides: {view.strides}, expected: (24,), correct: {view.strides == (24,)}")

# shape: (1, 3), expected: (3,), correct: False
# strides: (72, 24), expected: (24,), correct: False

System Information

No response

@christophercrouzet christophercrouzet added the bug Something isn't working label Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant