Skip to content

Commit 856662f

Browse files
authored
Merge pull request NVIDIA#334 from leofang/cupy
Add back CuPy as an optional test dependency + Fix an example bug
2 parents 54a93e6 + 9756b1a commit 856662f

File tree

6 files changed

+18
-13
lines changed

6 files changed

+18
-13
lines changed

.github/workflows/gh-build-and-test.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,9 @@ jobs:
300300
- name: Run cuda.core tests
301301
shell: bash --noprofile --norc -xeuo pipefail {0}
302302
run: |
303-
if [[ $SKIP_CUDA_BINDINGS_TEST == 1 ]]; then
303+
if [[ ${{ matrix.python-version }} == "3.13" ]]; then
304304
# TODO: remove this hack once cuda-python has a cp313 build
305-
if [[ ${{ matrix.python-version }} == "3.13" ]]; then
305+
if [[ $SKIP_CUDA_BINDINGS_TEST == 1 ]]; then
306306
echo "Python 3.13 + cuda-python ${{ matrix.cuda-version }} is not supported, skipping the test..."
307307
exit 0
308308
fi
@@ -316,9 +316,6 @@ jobs:
316316
popd
317317
318318
pushd ./cuda_core
319-
# TODO: add requirements.txt for test deps?
320-
pip install pytest
321-
# TODO: add CuPy to test deps (which would require cuRAND)
322-
# pip install "cupy-cuda${TEST_CUDA_MAJOR}x"
319+
pip install -r "tests/requirements-cu${TEST_CUDA_MAJOR}.txt"
323320
pytest -rxXs tests/
324321
popd

cuda_core/examples/saxpy.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@
4747
# prepare input/output
4848
size = cp.uint64(64)
4949
a = dtype(10)
50-
x = cp.random.random(size, dtype=dtype)
51-
y = cp.random.random(size, dtype=dtype)
50+
rng = cp.random.default_rng()
51+
x = rng.random(size, dtype=dtype)
52+
y = rng.random(size, dtype=dtype)
5253
out = cp.empty_like(x)
5354
dev.sync() # cupy runs on a different stream from s, so sync before accessing
5455

@@ -73,8 +74,8 @@
7374
# prepare input
7475
size = cp.uint64(128)
7576
a = dtype(42)
76-
x = cp.random.random(size, dtype=dtype)
77-
y = cp.random.random(size, dtype=dtype)
77+
x = rng.random(size, dtype=dtype)
78+
y = rng.random(size, dtype=dtype)
7879
dev.sync()
7980

8081
# prepare output

cuda_core/examples/strided_memory_view.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
gpu_prog = Program(gpu_code, code_type="c++")
9292
# To know the GPU's compute capability, we need to identify which GPU to use.
9393
dev = Device(0)
94+
dev.set_current()
9495
arch = "".join(f"{i}" for i in dev.compute_capability)
9596
mod = gpu_prog.compile(
9697
target_type="cubin",
@@ -156,7 +157,6 @@ def my_func(arr, work_stream):
156157

157158
# This takes the GPU path
158159
if cp:
159-
dev.set_current()
160160
s = dev.create_stream()
161161
# Create input array on GPU
162162
arr_gpu = cp.ones(1024, dtype=cp.int32)

cuda_core/examples/vector_add.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@
4242

4343
# prepare input/output
4444
size = 50000
45-
a = cp.random.random(size, dtype=dtype)
46-
b = cp.random.random(size, dtype=dtype)
45+
rng = cp.random.default_rng()
46+
a = rng.random(size, dtype=dtype)
47+
b = rng.random(size, dtype=dtype)
4748
c = cp.empty_like(a)
4849

4950
# cupy runs on a different stream from s, so sync before accessing
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pytest
2+
# TODO: remove this hack once cupy has a cp313 build
3+
cupy-cuda11x; python_version < "3.13"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pytest
2+
# TODO: remove this hack once cupy has a cp313 build
3+
cupy-cuda12x; python_version < "3.13"

0 commit comments

Comments
 (0)