Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-wheel-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ jobs:
if: ${{ inputs.test-mode == 'nightly-pytorch' }}
run: |
pushd cuda_core
pytest -rsxXfE -v --exclude-warning-annotations --junitxml "${GITHUB_WORKSPACE}/test-results/junit-pytorch-interop.xml" tests/test_utils.py tests/example_tests/ | python "${GITHUB_WORKSPACE}/.ci-control/ci/tools/fold_pytest_sections.py"
pytest -rsxXfE -v --exclude-warning-annotations --junitxml "${GITHUB_WORKSPACE}/test-results/junit-pytorch-interop.xml" -m "torch or samples" tests/ | python "${GITHUB_WORKSPACE}/.ci-control/ci/tools/fold_pytest_sections.py"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Major · Functional Correctness · Heavy lift

important: Nightly PyTorch runs can pass without the DLPack tests.

The nightly-pytorch step runs the workflow file from the nightly run's ref. It checks out tests at inputs.sha, which is the head of the latest successful main CI run. If that tests revision predates the torch marks, -m "torch or samples" omits all five DLPack tests. The step still passes when a sample test is selected and passes. The same applies to the Windows step.

The nightly workflow can start from a PR branch or from a main commit that is newer than the pinned tests revision. In both cases the workflow file and the tests can come from different revisions.

The nightly-pytorch step must not pass when the DLPack tests are not selected. Choose a mechanism that guarantees this for any tests revision the nightly run can check out.

popd
- name: Checkout numba-cuda tests at matching tag
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-wheel-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ jobs:
shell: bash --noprofile --norc -xeuo pipefail {0}
run: |
pushd cuda_core
pytest -rsxXfE -v --exclude-warning-annotations --junitxml "${GITHUB_WORKSPACE}/test-results/junit-pytorch-interop.xml" tests/test_utils.py tests/example_tests/ | python "${GITHUB_WORKSPACE}/.ci-control/ci/tools/fold_pytest_sections.py"
pytest -rsxXfE -v --exclude-warning-annotations --junitxml "${GITHUB_WORKSPACE}/test-results/junit-pytorch-interop.xml" -m "torch or samples" tests/ | python "${GITHUB_WORKSPACE}/.ci-control/ci/tools/fold_pytest_sections.py"
popd

- name: Checkout numba-cuda tests at matching tag
Expand Down
1 change: 1 addition & 0 deletions cuda_core/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ filterwarnings =
error::helpers.memory.BaselineMemoryResourceReleasedWarning
markers =
samples: tests for cuda.core standalone samples
torch: test needs PyTorch; the nightly-pytorch CI job selects tests by this marker
# Keep this authorship marker registry in sync across all pytest config roots.
# Search for "agent_authored(model)" before editing.
agent_authored(model): agent-authored test not yet materially human-reviewed
Expand Down
35 changes: 21 additions & 14 deletions cuda_core/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ def _arr_dtype(arr):
return arr.dtype


def _torch_param(*values, id):
"""A pytest.param that needs PyTorch, so the nightly-pytorch CI job selects it."""
return pytest.param(*values, id=id, marks=pytest.mark.torch)


def _cpu_array_samples():
samples = [
np.empty(3, dtype=np.int32),
Expand All @@ -132,16 +137,16 @@ def _cpu_array_samples():
]
if torch is not None:
samples += [
pytest.param(torch.arange(12, dtype=torch.float32), id="torch-1d"),
pytest.param(torch.arange(24, dtype=torch.float32).reshape(2, 3, 4), id="torch-nd"),
pytest.param(torch.tensor(42.0), id="torch-scalar"),
pytest.param(torch.empty(0, dtype=torch.float32), id="torch-empty"),
pytest.param(
_torch_param(torch.arange(12, dtype=torch.float32), id="torch-1d"),
_torch_param(torch.arange(24, dtype=torch.float32).reshape(2, 3, 4), id="torch-nd"),
_torch_param(torch.tensor(42.0), id="torch-scalar"),
_torch_param(torch.empty(0, dtype=torch.float32), id="torch-empty"),
_torch_param(
torch.arange(12, dtype=torch.float32).reshape(3, 4).t(),
id="torch-non-contiguous",
),
pytest.param(torch.arange(100, dtype=torch.int64)[10:20], id="torch-sliced"),
pytest.param(
_torch_param(torch.arange(100, dtype=torch.int64)[10:20], id="torch-sliced"),
_torch_param(
torch.arange(60, dtype=torch.float32).reshape(6, 10)[1:4, 2:7],
id="torch-sliced-2d",
),
Expand Down Expand Up @@ -206,25 +211,25 @@ def gpu_array_samples():
]
if torch is not None:
samples += [
pytest.param(torch.arange(12, dtype=torch.float32, device="cuda"), True, id="torch-1d"),
pytest.param(
_torch_param(torch.arange(12, dtype=torch.float32, device="cuda"), True, id="torch-1d"),
_torch_param(
torch.arange(24, dtype=torch.float32, device="cuda").reshape(2, 3, 4),
True,
id="torch-nd",
),
pytest.param(torch.tensor(42.0, dtype=torch.float32, device="cuda"), False, id="torch-scalar"),
pytest.param(torch.empty(0, dtype=torch.float32, device="cuda"), False, id="torch-empty"),
pytest.param(
_torch_param(torch.tensor(42.0, dtype=torch.float32, device="cuda"), False, id="torch-scalar"),
_torch_param(torch.empty(0, dtype=torch.float32, device="cuda"), False, id="torch-empty"),
_torch_param(
torch.arange(12, dtype=torch.float32, device="cuda").reshape(3, 4).t(),
True,
id="torch-non-contiguous",
),
pytest.param(
_torch_param(
torch.arange(100, dtype=torch.int64, device="cuda")[10:20],
True,
id="torch-sliced",
),
pytest.param(
_torch_param(
torch.arange(60, dtype=torch.float32, device="cuda").reshape(6, 10)[1:4, 2:7],
True,
id="torch-sliced-2d",
Expand Down Expand Up @@ -762,6 +767,7 @@ def test_ml_dtypes_bfloat16_dlpack(init_cuda, slices):
)
@pytest.mark.skipif(ml_dtypes is None, reason="ml_dtypes is not installed")
@pytest.mark.skipif(torch is None, reason="PyTorch is not installed")
@pytest.mark.torch
def test_ml_dtypes_bfloat16_torch_dlpack(init_cuda, slices):
a = torch.tensor([1, 2, 3, 4, 5, 6], dtype=torch.bfloat16, device="cuda").reshape(2, 3)[slices]
smv = StridedMemoryView.from_dlpack(a, stream_ptr=0)
Expand Down Expand Up @@ -975,6 +981,7 @@ def test_array_interface_mask_rejected():
),
],
)
@pytest.mark.torch
def test_torch_tensor_bridge_dtypes(init_cuda, dtype):
"""Verify that dtype mapping via the tensor bridge matches torch's own dtype."""
torch_dtype = getattr(torch, dtype)
Expand Down
5 changes: 5 additions & 0 deletions cuda_core/tests/test_utils_dlpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ def torch_module():
@pytest.mark.parametrize("module", ["application_adapter", "torch_adapter", "torch.adapters", "torchvision.adapters"])
@pytest.mark.parametrize("has_data_ptr", [False, True])
@pytest.mark.agent_authored(model="gpt-6")
@pytest.mark.torch
def test_protocol_adapter_uses_protocol_on_first_and_cached_import(entry, module, has_data_ptr, torch_module):
"""Non-Tensor adapters retain their protocol routing on repeated imports."""

Expand Down Expand Up @@ -401,6 +402,7 @@ def array_interface(self):
@pytest.mark.parametrize("entry", ["from_dlpack", "from_any_interface"])
@pytest.mark.parametrize("legacy_dlpack", [False, True])
@pytest.mark.agent_authored(model="gpt-6")
@pytest.mark.torch
def test_class_proxy_is_not_a_native_tensor(entry, legacy_dlpack, torch_module):
"""A proxy advertising Tensor through __class__ still uses its DLPack protocol."""
from cuda_python_test_helpers.subprocess_runner import run_python_snippet
Expand Down Expand Up @@ -447,6 +449,7 @@ def __dlpack__(self, **kwargs):
[(None, False), ("torch_custom", False), ("application_tensor", False), ("application_tensor", True)],
)
@pytest.mark.agent_authored(model="gpt-6")
@pytest.mark.torch
def test_real_tensor_and_subclasses_keep_existing_routes(entry, module, legacy_dlpack, torch_module):
"""Real Tensors and subclasses preserve their data and existing import routes."""
torch = torch_module
Expand Down Expand Up @@ -476,6 +479,7 @@ def dlpack(self, **kwargs):
@pytest.mark.parametrize("entry", ["from_cuda_array_interface", "from_any_interface"])
@pytest.mark.parametrize("module", ["application_cuda", "torch_cuda_adapter", "torchvision.adapters"])
@pytest.mark.agent_authored(model="gpt-6")
@pytest.mark.torch
def test_cuda_adapter_uses_real_device_storage(init_cuda, entry, module, torch_module):
"""Torch-looking CAI adapters import real device storage through their protocol."""
source = np.arange(4, dtype=np.int32)
Expand Down Expand Up @@ -589,6 +593,7 @@ def __array_interface__(self):


@pytest.mark.agent_authored(model="gpt-6")
@pytest.mark.torch
def test_torch_tensor_type_lookup_is_cached(torch_module):
"""Distinct candidate types reuse Torch metadata after a protocol-only import."""
from cuda_python_test_helpers.subprocess_runner import run_python_snippet
Expand Down
Loading