Skip to content

test_dunder_dlpack hard-pins dl_device to kDLCPU, so it fails for any non-CPU-native library #456

Description

@antonwolfy

array_api_tests/test_dlpack.py::test_dunder_dlpack always requests a CPU DLPack device while independently drawing copy ∈ {True, False, None}, and treats any exception as a failure. For a device-backed library (GPU/SYCL/etc.), the copy=False + dl_device=(kDLCPU, 0) combination forces a device→host copy that the standard requires be refused with BufferError — so the test fails on spec-compliant behavior. It only passes for libraries whose default device is already CPU.

Reproduction

The test generates:

dl_device_kw=hh.kwargs(
    dl_device=st.tuples(  # XXX: the 2023.12 standard only mandates ... kDLCPU ?
        st.just(DLPackDeviceEnum.CPU.value),   # == 1 (kDLCPU)
        st.just(0)
    )
),
...
copy_kw=hh.kwargs(copy=st.booleans() | st.none()),

and then does:

def test_dunder_dlpack(x, copy_kw, max_version_kw, dl_device_kw, data):
    try:
        x.__dlpack__(**copy_kw, **max_version_kw, **dl_device_kw)
    except Exception as exc:      # BufferError is never expected/caught
        ph.add_note(exc, repro_snippet)
        raise

For a library whose default device is not kDLCPU, Hypothesis eventually draws copy=False, and x.__dlpack__(copy=False, dl_device=(kDLCPU, 0)) raises:

BufferError: array cannot be placed on the requested device without a copy

Example failing case (from dpnp/dpctl):

x=array([], dtype=bool),
copy_kw={'copy': False},
max_version_kw={'max_version': (1, 0)},
dl_device_kw={'dl_device': (1, 0)},

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions