From 8cbea18708e06ddbb64f2d2d92f97b62b6e61ef8 Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Mon, 30 Dec 2024 02:03:21 +0000 Subject: [PATCH 1/6] switch to use new random impl --- cuda_core/examples/saxpy.py | 9 +++++---- cuda_core/examples/vector_add.py | 5 +++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/cuda_core/examples/saxpy.py b/cuda_core/examples/saxpy.py index 8caa4d4a5..d1d7211f2 100644 --- a/cuda_core/examples/saxpy.py +++ b/cuda_core/examples/saxpy.py @@ -47,8 +47,9 @@ # prepare input/output size = cp.uint64(64) a = dtype(10) -x = cp.random.random(size, dtype=dtype) -y = cp.random.random(size, dtype=dtype) +rng = cp.random.default_rng() +x = rng.random(size, dtype=dtype) +y = rng.random(size, dtype=dtype) out = cp.empty_like(x) dev.sync() # cupy runs on a different stream from s, so sync before accessing @@ -73,8 +74,8 @@ # prepare input size = cp.uint64(128) a = dtype(42) -x = cp.random.random(size, dtype=dtype) -y = cp.random.random(size, dtype=dtype) +x = rng.random(size, dtype=dtype) +y = rng.random(size, dtype=dtype) dev.sync() # prepare output diff --git a/cuda_core/examples/vector_add.py b/cuda_core/examples/vector_add.py index 550eaf2a2..172653277 100644 --- a/cuda_core/examples/vector_add.py +++ b/cuda_core/examples/vector_add.py @@ -42,8 +42,9 @@ # prepare input/output size = 50000 -a = cp.random.random(size, dtype=dtype) -b = cp.random.random(size, dtype=dtype) +rng = cp.random.default_rng() +a = rng.random(size, dtype=dtype) +b = rng.random(size, dtype=dtype) c = cp.empty_like(a) # cupy runs on a different stream from s, so sync before accessing From b900413e4eecec93f15baca3be89bc59ad68aaf5 Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Mon, 30 Dec 2024 02:03:34 +0000 Subject: [PATCH 2/6] enable cupy in test --- .github/workflows/gh-build-and-test.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/gh-build-and-test.yml b/.github/workflows/gh-build-and-test.yml index 51f4bd87b..5ccde272d 100644 --- a/.github/workflows/gh-build-and-test.yml +++ b/.github/workflows/gh-build-and-test.yml @@ -317,8 +317,6 @@ jobs: pushd ./cuda_core # TODO: add requirements.txt for test deps? - pip install pytest - # TODO: add CuPy to test deps (which would require cuRAND) - # pip install "cupy-cuda${TEST_CUDA_MAJOR}x" + pip install pytest "cupy-cuda${TEST_CUDA_MAJOR}x" pytest -rxXs tests/ popd From 58116046d1081f4b91cc4d8dfa5c551b16527e4b Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Mon, 30 Dec 2024 02:54:06 +0000 Subject: [PATCH 3/6] cupy is not yet supported on PY313 --- .github/workflows/gh-build-and-test.yml | 7 +++---- cuda_core/tests/requirements-cu11.txt | 2 ++ cuda_core/tests/requirements-cu12.txt | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 cuda_core/tests/requirements-cu11.txt create mode 100644 cuda_core/tests/requirements-cu12.txt diff --git a/.github/workflows/gh-build-and-test.yml b/.github/workflows/gh-build-and-test.yml index 5ccde272d..c2dc50c6b 100644 --- a/.github/workflows/gh-build-and-test.yml +++ b/.github/workflows/gh-build-and-test.yml @@ -300,9 +300,9 @@ jobs: - name: Run cuda.core tests shell: bash --noprofile --norc -xeuo pipefail {0} run: | - if [[ $SKIP_CUDA_BINDINGS_TEST == 1 ]]; then + if [[ ${{ matrix.python-version }} == "3.13" ]]; then # TODO: remove this hack once cuda-python has a cp313 build - if [[ ${{ matrix.python-version }} == "3.13" ]]; then + if [[ $SKIP_CUDA_BINDINGS_TEST == 1 ]]; then echo "Python 3.13 + cuda-python ${{ matrix.cuda-version }} is not supported, skipping the test..." exit 0 fi @@ -316,7 +316,6 @@ jobs: popd pushd ./cuda_core - # TODO: add requirements.txt for test deps? - pip install pytest "cupy-cuda${TEST_CUDA_MAJOR}x" + pip install -r "tests/requirements-cu${TEST_CUDA_MAJOR}.txt" pytest -rxXs tests/ popd diff --git a/cuda_core/tests/requirements-cu11.txt b/cuda_core/tests/requirements-cu11.txt new file mode 100644 index 000000000..2e8135b71 --- /dev/null +++ b/cuda_core/tests/requirements-cu11.txt @@ -0,0 +1,2 @@ +# TODO: remove this hack once cupy has a cp313 build +cupy-cuda12x; python_version < "3.13" diff --git a/cuda_core/tests/requirements-cu12.txt b/cuda_core/tests/requirements-cu12.txt new file mode 100644 index 000000000..2e8135b71 --- /dev/null +++ b/cuda_core/tests/requirements-cu12.txt @@ -0,0 +1,2 @@ +# TODO: remove this hack once cupy has a cp313 build +cupy-cuda12x; python_version < "3.13" From 2e4a993e7a7299892654bc8d14c3878e2bbb00e9 Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Mon, 30 Dec 2024 02:54:36 +0000 Subject: [PATCH 4/6] get_kernel requires a valid cuda context on CUDA 11 --- cuda_core/examples/strided_memory_view.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cuda_core/examples/strided_memory_view.py b/cuda_core/examples/strided_memory_view.py index 564d7fa01..2cc25989e 100644 --- a/cuda_core/examples/strided_memory_view.py +++ b/cuda_core/examples/strided_memory_view.py @@ -91,6 +91,7 @@ gpu_prog = Program(gpu_code, code_type="c++") # To know the GPU's compute capability, we need to identify which GPU to use. dev = Device(0) + dev.set_current() arch = "".join(f"{i}" for i in dev.compute_capability) mod = gpu_prog.compile( target_type="cubin", @@ -156,7 +157,6 @@ def my_func(arr, work_stream): # This takes the GPU path if cp: - dev.set_current() s = dev.create_stream() # Create input array on GPU arr_gpu = cp.ones(1024, dtype=cp.int32) From fa3df13e5df832b63b7fcb44b2d8cd46e7e8b00c Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Mon, 30 Dec 2024 03:23:13 +0000 Subject: [PATCH 5/6] complete cuda-core test requirements --- cuda_core/tests/requirements-cu11.txt | 1 + cuda_core/tests/requirements-cu12.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/cuda_core/tests/requirements-cu11.txt b/cuda_core/tests/requirements-cu11.txt index 2e8135b71..2e82e12da 100644 --- a/cuda_core/tests/requirements-cu11.txt +++ b/cuda_core/tests/requirements-cu11.txt @@ -1,2 +1,3 @@ +pytest # TODO: remove this hack once cupy has a cp313 build cupy-cuda12x; python_version < "3.13" diff --git a/cuda_core/tests/requirements-cu12.txt b/cuda_core/tests/requirements-cu12.txt index 2e8135b71..2e82e12da 100644 --- a/cuda_core/tests/requirements-cu12.txt +++ b/cuda_core/tests/requirements-cu12.txt @@ -1,2 +1,3 @@ +pytest # TODO: remove this hack once cupy has a cp313 build cupy-cuda12x; python_version < "3.13" From 9756b1a863c066d3fa89bfb4ea7cfc81609a217a Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Mon, 30 Dec 2024 03:29:54 +0000 Subject: [PATCH 6/6] fix typo --- cuda_core/tests/requirements-cu11.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cuda_core/tests/requirements-cu11.txt b/cuda_core/tests/requirements-cu11.txt index 2e82e12da..8fb37e92e 100644 --- a/cuda_core/tests/requirements-cu11.txt +++ b/cuda_core/tests/requirements-cu11.txt @@ -1,3 +1,3 @@ pytest # TODO: remove this hack once cupy has a cp313 build -cupy-cuda12x; python_version < "3.13" +cupy-cuda11x; python_version < "3.13"