From 0e2e5f04cc0b6cca814228af96358d6f1dd7daa7 Mon Sep 17 00:00:00 2001 From: Vladislav Zhurba Date: Thu, 16 Jan 2025 14:46:31 -0800 Subject: [PATCH] Update benchmarks and enable them --- cuda_bindings/README.md | 10 +++++----- cuda_bindings/benchmarks/__init__.py | 0 .../{perf_test_utils.py => conftest.py} | 6 +++--- cuda_bindings/benchmarks/kernels.py | 2 +- cuda_bindings/benchmarks/test_cupy.py | 17 +++++++---------- cuda_bindings/benchmarks/test_launch_latency.py | 7 +++---- cuda_bindings/benchmarks/test_numba.py | 2 +- .../benchmarks/test_pointer_attributes.py | 5 ++--- 8 files changed, 22 insertions(+), 27 deletions(-) delete mode 100644 cuda_bindings/benchmarks/__init__.py rename cuda_bindings/benchmarks/{perf_test_utils.py => conftest.py} (95%) diff --git a/cuda_bindings/README.md b/cuda_bindings/README.md index 3ece5667dc..57e7c2b0b4 100644 --- a/cuda_bindings/README.md +++ b/cuda_bindings/README.md @@ -105,10 +105,10 @@ To run these samples: * `python -m pytest tests/cython/` against editable installations * `pytest tests/cython/` against installed packages -### Benchmark (WIP) +### Benchmark -Benchmarks were used for performance analysis during initial release of CUDA Python. Today they need to be updated the 12.x toolkit and are work in progress. +Allows for analyzing binding performance using plugin [pytest-benchmark](https://github.com/ionelmc/pytest-benchmark). -The intended way to run these benchmarks was: -* `python -m pytest --benchmark-only benchmark/` against editable installations -* `pytest --benchmark-only benchmark/` against installed packages +To run these benchmarks: +* `python -m pytest --benchmark-only benchmarks/` against editable installations +* `pytest --benchmark-only benchmarks/` against installed packages diff --git a/cuda_bindings/benchmarks/__init__.py b/cuda_bindings/benchmarks/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/cuda_bindings/benchmarks/perf_test_utils.py b/cuda_bindings/benchmarks/conftest.py similarity index 95% rename from cuda_bindings/benchmarks/perf_test_utils.py rename to cuda_bindings/benchmarks/conftest.py index 7cfcf9f9a6..e1d72d26dc 100644 --- a/cuda_bindings/benchmarks/perf_test_utils.py +++ b/cuda_bindings/benchmarks/conftest.py @@ -1,4 +1,4 @@ -# Copyright 2021-2024 NVIDIA Corporation. All rights reserved. +# Copyright 2021-2025 NVIDIA Corporation. All rights reserved. # # Please refer to the NVIDIA end user license agreement (EULA) associated # with this source code for terms and conditions that govern your use of @@ -25,7 +25,7 @@ def ASSERT_DRV(err): raise RuntimeError(f"Unknown error type: {err}") -@pytest.fixture +@pytest.fixture(scope="function") def init_cuda(): # Initialize (err,) = cuda.cuInit(0) @@ -47,7 +47,7 @@ def init_cuda(): ASSERT_DRV(err) -@pytest.fixture +@pytest.fixture(scope="function") def load_module(): module = None diff --git a/cuda_bindings/benchmarks/kernels.py b/cuda_bindings/benchmarks/kernels.py index 259c6e3ca4..119727b2d7 100644 --- a/cuda_bindings/benchmarks/kernels.py +++ b/cuda_bindings/benchmarks/kernels.py @@ -1,4 +1,4 @@ -# Copyright 2021-2024 NVIDIA Corporation. All rights reserved. +# Copyright 2021-2025 NVIDIA Corporation. All rights reserved. # # Please refer to the NVIDIA end user license agreement (EULA) associated # with this source code for terms and conditions that govern your use of diff --git a/cuda_bindings/benchmarks/test_cupy.py b/cuda_bindings/benchmarks/test_cupy.py index 6e847853e9..68fdd9831a 100644 --- a/cuda_bindings/benchmarks/test_cupy.py +++ b/cuda_bindings/benchmarks/test_cupy.py @@ -1,4 +1,4 @@ -# Copyright 2021-2024 NVIDIA Corporation. All rights reserved. +# Copyright 2021-2025 NVIDIA Corporation. All rights reserved. # # Please refer to the NVIDIA end user license agreement (EULA) associated # with this source code for terms and conditions that govern your use of @@ -9,17 +9,14 @@ import pytest -# Always skip since cupy is not CTK 12.x yet -skip_tests = True -if not skip_tests: - try: - import cupy +try: + import cupy - skip_tests = False - except ImportError: - skip_tests = True + skip_tests = False +except ImportError: + skip_tests = True -from .kernels import kernel_string +from kernels import kernel_string def launch(kernel, args=()): diff --git a/cuda_bindings/benchmarks/test_launch_latency.py b/cuda_bindings/benchmarks/test_launch_latency.py index f16e971adc..7af5f84cc3 100755 --- a/cuda_bindings/benchmarks/test_launch_latency.py +++ b/cuda_bindings/benchmarks/test_launch_latency.py @@ -1,4 +1,4 @@ -# Copyright 2021-2024 NVIDIA Corporation. All rights reserved. +# Copyright 2021-2025 NVIDIA Corporation. All rights reserved. # # Please refer to the NVIDIA end user license agreement (EULA) associated # with this source code for terms and conditions that govern your use of @@ -8,12 +8,11 @@ import ctypes import pytest +from conftest import ASSERT_DRV +from kernels import kernel_string from cuda import cuda -from .kernels import kernel_string -from .perf_test_utils import ASSERT_DRV - def launch(kernel, stream, args=(), arg_types=()): cuda.cuLaunchKernel( diff --git a/cuda_bindings/benchmarks/test_numba.py b/cuda_bindings/benchmarks/test_numba.py index f7a4db7e9f..36361d351f 100644 --- a/cuda_bindings/benchmarks/test_numba.py +++ b/cuda_bindings/benchmarks/test_numba.py @@ -1,4 +1,4 @@ -# Copyright 2021-2024 NVIDIA Corporation. All rights reserved. +# Copyright 2021-2025 NVIDIA Corporation. All rights reserved. # # Please refer to the NVIDIA end user license agreement (EULA) associated # with this source code for terms and conditions that govern your use of diff --git a/cuda_bindings/benchmarks/test_pointer_attributes.py b/cuda_bindings/benchmarks/test_pointer_attributes.py index f03be1e1ea..5c9dbc2b64 100644 --- a/cuda_bindings/benchmarks/test_pointer_attributes.py +++ b/cuda_bindings/benchmarks/test_pointer_attributes.py @@ -1,4 +1,4 @@ -# Copyright 2021-2024 NVIDIA Corporation. All rights reserved. +# Copyright 2021-2025 NVIDIA Corporation. All rights reserved. # # Please refer to the NVIDIA end user license agreement (EULA) associated # with this source code for terms and conditions that govern your use of @@ -8,11 +8,10 @@ import random import pytest +from conftest import ASSERT_DRV from cuda import cuda -from .perf_test_utils import ASSERT_DRV - random.seed(0) idx = 0