Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backport] Add import test without CUDA Toolkit #8231

Merged
merged 1 commit into from
Mar 11, 2024
Merged
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
4 changes: 2 additions & 2 deletions .pfnci/linux/tests/cuda-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export CUPY_NVCC_GENERATE_CODE="arch=compute_70,code=sm_70"

# Make sure that CuPy can be imported without CUDA Toolkit installed.
rm -rf /usr/local/cuda*
pushd /
python3 -c 'import cupy, cupyx; cupy.show_config(_full=True)'
pushd tests/import_tests
python3 test_import.py
popd

"$ACTIONS/cleanup.sh"
50 changes: 50 additions & 0 deletions tests/import_tests/test_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import cupy
from cupyx import jit

"""
Test to ensure that this file can be imported without CUDA Toolkit.
"""


@cupy.memoize()
def user_func(a: cupy.ndarray):
a.sum()


squared_diff = cupy.ElementwiseKernel(
'float32 x, float32 y',
'float32 z',
'z = (x - y) * (x - y)',
'squared_diff')


l2norm_kernel = cupy.ReductionKernel(
'T x', # input params
'T y', # output params
'x * x', # map
'a + b', # reduce
'y = sqrt(a)', # post-reduction map
'0', # identity value
'l2norm' # kernel name
)

complex_kernel = cupy.RawKernel(r'''
#include <cupy/complex.cuh>
extern "C" __global__
void my_func(const complex<float>* x1, const complex<float>* x2,
complex<float>* y, float a) {
int tid = blockDim.x * blockIdx.x + threadIdx.x;
y[tid] = x1[tid] + a * x2[tid];
}
''', 'my_func')


@jit.rawkernel()
def elementwise_copy(x, y, size):
tid = jit.blockIdx.x * jit.blockDim.x + jit.threadIdx.x
ntid = jit.gridDim.x * jit.blockDim.x
for i in range(tid, size, ntid):
y[i] = x[i]


cupy.show_config(_full=True)