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
6 changes: 0 additions & 6 deletions cuda_bindings_13/tests/example_tests/run_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
DEFAULT_SAMPLES_DIR = REPO_ROOT / "samples" / "cuda_bindings"
SAMPLE_NAMESPACE = "cuda_bindings"

build_run_plan = _runner.build_run_plan
collect_sample_entries = _runner.collect_sample_entries
get_gpu_count = _runner.get_gpu_count
load_config = _runner.load_config
run_sample = _runner.run_sample


def main(argv: list[str] | None = None) -> int:
return _runner.main(
Expand Down
40 changes: 5 additions & 35 deletions cuda_bindings_13/tests/example_tests/test_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,22 @@
from __future__ import annotations

import os
import sys

import pytest
from run_samples import (
DEFAULT_CONFIG,
DEFAULT_SAMPLES_DIR,
SAMPLE_NAMESPACE,
build_run_plan,
collect_sample_entries,
get_gpu_count,
load_config,
run_sample,
)
from cuda_python_test_helpers.sample_runner import SampleSuite
from run_samples import DEFAULT_CONFIG, DEFAULT_SAMPLES_DIR, SAMPLE_NAMESPACE

_ENTRIES = collect_sample_entries(DEFAULT_SAMPLES_DIR, SAMPLE_NAMESPACE)
_SAMPLES = sorted(_ENTRIES)
_CONFIG = load_config(DEFAULT_CONFIG)
_GPU_COUNT = get_gpu_count() if _SAMPLES else 0
_SUITE = SampleSuite(DEFAULT_SAMPLES_DIR, SAMPLE_NAMESPACE, DEFAULT_CONFIG)
_CUDA_12_PIXI_ENV = os.environ.get("PIXI_ENVIRONMENT_NAME") == "cu12"


@pytest.mark.parallel_threads_limit(1)
@pytest.mark.parametrize("sample_key", _SAMPLES)
@pytest.mark.parametrize("sample_key", _SUITE.keys)
@pytest.mark.samples
@pytest.mark.skipif(
_CUDA_12_PIXI_ENV,
reason="cuda.bindings samples require cuda-python 13 or newer",
)
@pytest.mark.agent_authored(model="gpt-5")
def test_sample(sample_key: str) -> None:
if _GPU_COUNT == 0:
pytest.skip("No CUDA GPU detected on the test runner")

entry = _ENTRIES.get(sample_key)
if entry is None or not entry.is_file():
pytest.fail(f"Sample entrypoint missing: {sample_key}")

plan = build_run_plan(entry, _CONFIG, _GPU_COUNT, sample_key=sample_key)
result = run_sample(plan)

if result.status == "WAIVED":
if result.detail.startswith("unmet package requirement(s):"):
pytest.fail(f"sample dependencies are not satisfied: {result.detail}")
pytest.skip(result.detail or "sample waived")
if result.status == "PASS":
return

sys.stdout.flush()
pytest.fail(f"sample {sample_key} returned status={result.status} (rc={result.return_code}): {result.detail}")
_SUITE.check(sample_key, fail_on_unmet_dependencies=True)
10 changes: 3 additions & 7 deletions cuda_core/tests/example_tests/run_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,16 @@
DEFAULT_SAMPLES_DIR = REPO_ROOT / "samples" / "cuda_core"
SAMPLE_NAMESPACE = "cuda_core"

DEFAULT_TIMEOUT = _runner.DEFAULT_TIMEOUT
DependencyMetadataError = _runner.DependencyMetadataError
# Re-exported for the runner unit tests in test_run_samples.py and
# test_sample_verification.py.
RunPlan = _runner.RunPlan
RunResult = _runner.RunResult
build_run_plan = _runner.build_run_plan
collect_sample_entries = _runner.collect_sample_entries
discover_samples = _runner.discover_samples
get_gpu_count = _runner.get_gpu_count
get_sample_id = _runner.get_sample_id
load_config = _runner.load_config
missing_dependencies = _runner.missing_dependencies
run_sample = _runner.run_sample

# Kept available for runner unit tests that patch distribution metadata.
# Patched by the runner unit tests to fake distribution metadata.
importlib = _runner.importlib


Expand Down
71 changes: 68 additions & 3 deletions cuda_core/tests/example_tests/test_run_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@


class _Distribution:
def __init__(self, version: str, extras: tuple[str, ...] = ()) -> None:
def __init__(self, version: str, extras: tuple[str, ...] = (), requires: tuple[str, ...] | None = None) -> None:
self.version = version
if requires is None:
self.requires = None
else:
self.requires = list(requires)
self.metadata = Message()
for extra in extras:
self.metadata["Provides-Extra"] = extra
Expand All @@ -39,8 +43,8 @@ def distribution(name: str) -> _Distribution:

monkeypatch.setattr(run_samples.importlib.metadata, "distribution", distribution)

def install(name: str, version: str, extras: tuple[str, ...] = ()) -> None:
installed[canonicalize_name(name)] = _Distribution(version, extras)
def install(name: str, version: str, extras: tuple[str, ...] = (), requires: tuple[str, ...] | None = None) -> None:
installed[canonicalize_name(name)] = _Distribution(version, extras, requires)

return install, requested

Expand Down Expand Up @@ -524,3 +528,64 @@ def test_importable_module_does_not_satisfy_distribution_requirement(

assert len(missing) == 1
assert "no provider distribution installed" in missing[0]


# Mirrors cuda-core's metadata: cu13 -> cuda-core[minimal-sysctk13] -> cuda-bindings.
_CUDA_CORE_REQUIRES = (
'cuda-bindings>=13.5.0,<14; extra == "minimal-sysctk13"',
'cuda-core[minimal-sysctk13]; extra == "cu13"',
)
_CUDA_CORE_EXTRAS = ("minimal-sysctk13", "cu13")


@pytest.mark.parametrize(
("bindings_version", "is_met"),
[
("13.5.0", True),
("12.9.8", False),
],
)
@pytest.mark.agent_authored(model="claude-sonnet-5-5")
def test_extra_dependencies_are_checked_transitively(
tmp_path: Path, installed_distributions, bindings_version: str, is_met: bool
) -> None:
install, _ = installed_distributions
install("cuda-core", "1.3.0", extras=_CUDA_CORE_EXTRAS, requires=_CUDA_CORE_REQUIRES)
install("cuda-bindings", bindings_version)

missing = run_samples.missing_dependencies(_sample(tmp_path, "['cuda-core[cu13]>=1.1']"))

if is_met:
assert missing == []
else:
assert len(missing) == 1
assert "extra minimal-sysctk13 requires cuda-bindings<14,>=13.5.0" in missing[0]
assert f"cuda-bindings {bindings_version}" in missing[0]


@pytest.mark.agent_authored(model="claude-sonnet-5-5")
def test_extra_dependency_that_is_not_installed_is_accepted(tmp_path: Path, installed_distributions) -> None:
install, requested = installed_distributions
install("cuda-core", "1.3.0", extras=_CUDA_CORE_EXTRAS, requires=_CUDA_CORE_REQUIRES)

missing = run_samples.missing_dependencies(_sample(tmp_path, "['cuda-core[cu13]>=1.1']"))

assert missing == []
assert "cuda-bindings" in requested


@pytest.mark.agent_authored(model="claude-sonnet-5-5")
def test_extra_dependency_cycle_terminates(tmp_path: Path, installed_distributions) -> None:
install, _ = installed_distributions
install(
"alpha",
"1.0",
extras=("a", "b"),
requires=('alpha[b]; extra == "a"', 'alpha[a]; extra == "b"', 'beta>=2; extra == "b"'),
)
install("beta", "1.0")

missing = run_samples.missing_dependencies(_sample(tmp_path, "['alpha[a]']"))

assert len(missing) == 1
assert "extra b requires beta>=2" in missing[0]
47 changes: 7 additions & 40 deletions cuda_core/tests/example_tests/test_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,24 @@

from __future__ import annotations

import sys

import pytest
from run_samples import (
DEFAULT_CONFIG,
DEFAULT_SAMPLES_DIR,
SAMPLE_NAMESPACE,
build_run_plan,
collect_sample_entries,
get_gpu_count,
load_config,
run_sample,
)
from cuda_python_test_helpers.sample_runner import SampleSuite
from run_samples import DEFAULT_CONFIG, DEFAULT_SAMPLES_DIR, SAMPLE_NAMESPACE

_ENTRIES = collect_sample_entries(DEFAULT_SAMPLES_DIR, SAMPLE_NAMESPACE)
_SAMPLES = sorted(_ENTRIES)
_CONFIG = load_config(DEFAULT_CONFIG)
# Resolve GPU count once at collection time so we report the same skip reason
# consistently across the parametrized test ids.
_GPU_COUNT = get_gpu_count() if _SAMPLES else 0
_SUITE = SampleSuite(DEFAULT_SAMPLES_DIR, SAMPLE_NAMESPACE, DEFAULT_CONFIG)


# Samples launch full GPU workloads in their own subprocess, so keep them
# serialized when the suite is run under pytest-run-parallel.
# For sample_key values: cuda_core/binarySearch, cuda_core/cudaComputeLambdas, cuda_core/customTensorFlowKernel,
# cuda_core/glInteropFluidNumbaCudaMlir, cuda_core/glInteropFluid, cuda_core/glInteropMipmapLod,
# cuda_core/glInteropPlasma, cuda_core/greenContext, cuda_core/matrixMulSharedMem, cuda_core/multiGPUGradientAverage,
# cuda_core/pageRank, cuda_core/parallelReduction, cuda_core/prefixSum, cuda_core/processCheckpoint,
# cuda_core/reductionMultiBlockCG, cuda_core/simplePrint, cuda_core/tmaTensorMap:
# cuda_core/pageRank, cuda_core/parallelReduction, cuda_core/prefixSum, cuda_core/reductionMultiBlockCG,
# cuda_core/simplePrint, cuda_core/tmaTensorMap:
# This test is not currently run in any CI job
@pytest.mark.parallel_threads_limit(1)
@pytest.mark.parametrize("sample_key", _SAMPLES)
@pytest.mark.parametrize("sample_key", _SUITE.keys)
@pytest.mark.samples
@pytest.mark.agent_authored(model="gpt-5")
def test_sample(sample_key: str) -> None:
if _GPU_COUNT == 0:
pytest.skip("No CUDA GPU detected on the test runner")

entry = _ENTRIES.get(sample_key)
if entry is None or not entry.is_file():
pytest.fail(f"Sample entrypoint missing: {sample_key}")

plan = build_run_plan(entry, _CONFIG, _GPU_COUNT, sample_key=sample_key)
result = run_sample(plan)

if result.status == "WAIVED":
pytest.skip(result.detail or "sample waived")
if result.status == "PASS":
return

# Re-print captured output through stdout/stderr so pytest's failure
# capture surfaces it in the report.
sys.stdout.flush()
pytest.fail(f"sample {sample_key} returned status={result.status} (rc={result.return_code}): {result.detail}")
_SUITE.check(sample_key)
Loading
Loading