From a13d6bef4fac677871170bf35dfcb18e11b89cb6 Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Mon, 6 Jan 2025 12:26:44 -0500 Subject: [PATCH 01/10] Enable Cython tests for `cuda.bindings` (#323) * enable Cython tests for cuda.bindings * build Cython test modules * Update gh-build-and-test.yml * Install system gcc * No sudo * also set CUDA_HOME * Try to find Python include * nit: add a skip condition and comments * simplify --- .github/actions/fetch_ctk/action.yml | 1 + .github/workflows/build-and-test.yml | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/actions/fetch_ctk/action.yml b/.github/actions/fetch_ctk/action.yml index 8365b3f2..18750c2d 100644 --- a/.github/actions/fetch_ctk/action.yml +++ b/.github/actions/fetch_ctk/action.yml @@ -146,5 +146,6 @@ runs: run: | CUDA_PATH=$(realpath "./cuda_toolkit") echo "CUDA_PATH=${CUDA_PATH}" >> $GITHUB_ENV + echo "CUDA_HOME=${CUDA_PATH}" >> $GITHUB_ENV echo "${CUDA_PATH}/bin" >> $GITHUB_PATH echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-}:${CUDA_PATH}/lib" >> $GITHUB_ENV diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index ff5041c8..a42955a8 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -234,6 +234,9 @@ jobs: uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} + env: + # we use self-hosted runners on which setup-python behaves weirdly... + AGENT_TOOLSDIRECTORY: "/opt/hostedtoolcache" - name: Set up mini CTK uses: ./.github/actions/fetch_ctk @@ -255,6 +258,13 @@ jobs: pushd ./cuda_bindings pip install -r requirements.txt pytest -rxXs tests/ - # TODO: enable cython tests - #pytest tests/cython + if [[ "${{ matrix.host-platform }}" == linux* ]]; then + # cython tests require gcc + apt install -y build-essential + bash tests/cython/build_tests.sh + elif [[ "${{ matrix.host-platform }}" == win* ]]; then + # TODO: enable this once win-64 runners are up + exit 1 + fi + pytest -rxXs tests/cython popd From ea703c4361e4003d1f8b064bd834ac12de6d2acf Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Mon, 6 Jan 2025 17:11:22 -0500 Subject: [PATCH 02/10] minimal treatment from #252 --- .github/workflows/build-and-test.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index a42955a8..2972fda5 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -258,13 +258,14 @@ jobs: pushd ./cuda_bindings pip install -r requirements.txt pytest -rxXs tests/ + cd tests_cython if [[ "${{ matrix.host-platform }}" == linux* ]]; then # cython tests require gcc apt install -y build-essential - bash tests/cython/build_tests.sh + CPLUS_INCLUDE_PATH=$CUDA_HOME/include:$CPLUS_INCLUDE_PATH cythonize -3 -i test_*.pyx elif [[ "${{ matrix.host-platform }}" == win* ]]; then # TODO: enable this once win-64 runners are up exit 1 fi - pytest -rxXs tests/cython + pytest -rxXs . popd From c983107767076a2fbd808413f03b29772bfc0f5b Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Mon, 6 Jan 2025 17:57:20 -0500 Subject: [PATCH 03/10] avoid unbound variable --- .github/workflows/build-and-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 2972fda5..8252c4ed 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -262,7 +262,7 @@ jobs: if [[ "${{ matrix.host-platform }}" == linux* ]]; then # cython tests require gcc apt install -y build-essential - CPLUS_INCLUDE_PATH=$CUDA_HOME/include:$CPLUS_INCLUDE_PATH cythonize -3 -i test_*.pyx + CPLUS_INCLUDE_PATH=$CUDA_HOME/include:${CPLUS_INCLUDE_PATH:-} cythonize -3 -i test_*.pyx elif [[ "${{ matrix.host-platform }}" == win* ]]; then # TODO: enable this once win-64 runners are up exit 1 From 75674821911c46f80f082ffb1fc9d52833943be1 Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Wed, 8 Jan 2025 00:00:40 -0500 Subject: [PATCH 04/10] try this --- .github/workflows/build-and-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 8252c4ed..ab7be8f7 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -262,7 +262,7 @@ jobs: if [[ "${{ matrix.host-platform }}" == linux* ]]; then # cython tests require gcc apt install -y build-essential - CPLUS_INCLUDE_PATH=$CUDA_HOME/include:${CPLUS_INCLUDE_PATH:-} cythonize -3 -i test_*.pyx + CPLUS_INCLUDE_PATH="$CUDA_HOME/include:${CPLUS_INCLUDE_PATH:-}" cythonize -3 -i test_*.pyx elif [[ "${{ matrix.host-platform }}" == win* ]]; then # TODO: enable this once win-64 runners are up exit 1 From 718b9848a9ea36c93b68c701809502ce172534a6 Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Wed, 8 Jan 2025 21:55:29 -0500 Subject: [PATCH 05/10] try this --- .github/workflows/build-and-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index ab7be8f7..549bbff8 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -262,7 +262,7 @@ jobs: if [[ "${{ matrix.host-platform }}" == linux* ]]; then # cython tests require gcc apt install -y build-essential - CPLUS_INCLUDE_PATH="$CUDA_HOME/include:${CPLUS_INCLUDE_PATH:-}" cythonize -3 -i test_*.pyx + CPLUS_INCLUDE_PATH="$CUDA_HOME/include" cythonize -3 -i test_*.pyx elif [[ "${{ matrix.host-platform }}" == win* ]]; then # TODO: enable this once win-64 runners are up exit 1 From ee46113640b1737715df859222325685d137dd6e Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Thu, 9 Jan 2025 01:14:00 -0500 Subject: [PATCH 06/10] Update build-and-test.yml --- .github/workflows/build-and-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 549bbff8..c2a07390 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -261,6 +261,7 @@ jobs: cd tests_cython if [[ "${{ matrix.host-platform }}" == linux* ]]; then # cython tests require gcc + apt update apt install -y build-essential CPLUS_INCLUDE_PATH="$CUDA_HOME/include" cythonize -3 -i test_*.pyx elif [[ "${{ matrix.host-platform }}" == win* ]]; then From 05267c2db01ce121c366c0c506034f68751d4d94 Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Thu, 9 Jan 2025 22:40:35 -0500 Subject: [PATCH 07/10] try this --- .github/workflows/build-and-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index c2a07390..03e8db95 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -263,6 +263,7 @@ jobs: # cython tests require gcc apt update apt install -y build-essential + ls -l $CUDA_HOME/include CPLUS_INCLUDE_PATH="$CUDA_HOME/include" cythonize -3 -i test_*.pyx elif [[ "${{ matrix.host-platform }}" == win* ]]; then # TODO: enable this once win-64 runners are up From 23729a2bca638176fa48ab33a014e5f7b764de3f Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Thu, 9 Jan 2025 23:27:46 -0500 Subject: [PATCH 08/10] Create build_tests.sh --- cuda_bindings/tests_cython/build_tests.sh | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 cuda_bindings/tests_cython/build_tests.sh diff --git a/cuda_bindings/tests_cython/build_tests.sh b/cuda_bindings/tests_cython/build_tests.sh new file mode 100644 index 00000000..d18a6aaa --- /dev/null +++ b/cuda_bindings/tests_cython/build_tests.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +cd "$(dirname "$0")" +CPLUS_INCLUDE_PATH=$CUDA_HOME/include:$CPLUS_INCLUDE_PATH cythonize -3 -i test_*.pyx From 98e3d78c618c4a82c3e82acde1bead9535a6962f Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Thu, 9 Jan 2025 23:29:31 -0500 Subject: [PATCH 09/10] Update build-and-test.yml --- .github/workflows/build-and-test.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 03e8db95..def159f5 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -258,16 +258,13 @@ jobs: pushd ./cuda_bindings pip install -r requirements.txt pytest -rxXs tests/ - cd tests_cython if [[ "${{ matrix.host-platform }}" == linux* ]]; then # cython tests require gcc - apt update apt install -y build-essential - ls -l $CUDA_HOME/include - CPLUS_INCLUDE_PATH="$CUDA_HOME/include" cythonize -3 -i test_*.pyx + bash tests_cython/build_tests.sh elif [[ "${{ matrix.host-platform }}" == win* ]]; then # TODO: enable this once win-64 runners are up exit 1 fi - pytest -rxXs . + pytest -rxXs tests_cython popd From d32a05cb2f87e1898f53b0f49e593d505afadf3c Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Fri, 10 Jan 2025 05:34:39 +0000 Subject: [PATCH 10/10] ensure using c++ --- cuda_bindings/tests_cython/test_ccuda.pyx | 5 ++++- cuda_bindings/tests_cython/test_ccudart.pyx | 3 +++ cuda_bindings/tests_cython/test_interoperability_cython.pyx | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cuda_bindings/tests_cython/test_ccuda.pyx b/cuda_bindings/tests_cython/test_ccuda.pyx index b216323e..5b625ce4 100644 --- a/cuda_bindings/tests_cython/test_ccuda.pyx +++ b/cuda_bindings/tests_cython/test_ccuda.pyx @@ -5,6 +5,9 @@ # this software. Any use, reproduction, disclosure, or distribution of # this software and related documentation outside the terms of the EULA # is strictly prohibited. + +# distutils: language=c++ + from libc.string cimport ( memset, memcmp @@ -53,4 +56,4 @@ def test_ccuda_memcpy(): err = ccuda.cuMemFree(dptr) assert(err == 0) err = ccuda.cuCtxDestroy(ctx) - assert(err == 0) \ No newline at end of file + assert(err == 0) diff --git a/cuda_bindings/tests_cython/test_ccudart.pyx b/cuda_bindings/tests_cython/test_ccudart.pyx index 0871da40..e5781698 100644 --- a/cuda_bindings/tests_cython/test_ccudart.pyx +++ b/cuda_bindings/tests_cython/test_ccudart.pyx @@ -5,6 +5,9 @@ # this software. Any use, reproduction, disclosure, or distribution of # this software and related documentation outside the terms of the EULA # is strictly prohibited. + +# distutils: language=c++ + from libc.string cimport ( memset, memcmp diff --git a/cuda_bindings/tests_cython/test_interoperability_cython.pyx b/cuda_bindings/tests_cython/test_interoperability_cython.pyx index d5a045ed..8a42e6e3 100644 --- a/cuda_bindings/tests_cython/test_interoperability_cython.pyx +++ b/cuda_bindings/tests_cython/test_interoperability_cython.pyx @@ -5,6 +5,9 @@ # this software. Any use, reproduction, disclosure, or distribution of # this software and related documentation outside the terms of the EULA # is strictly prohibited. + +# distutils: language=c++ + import pytest import cuda.cuda as cuda import cuda.cudart as cudart