Skip to content

Commit

Permalink
Merge branch 'main' into replace-stream-attribute-with-method
Browse files Browse the repository at this point in the history
  • Loading branch information
NaderAlAwar authored Jan 15, 2025
2 parents 2db4743 + ee8d7cd commit 777b106
Show file tree
Hide file tree
Showing 19 changed files with 187 additions and 89 deletions.
31 changes: 29 additions & 2 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ jobs:
name: ${{ env.CUDA_CORE_ARTIFACT_NAME }}
path: ${{ env.CUDA_CORE_ARTIFACTS_DIR }}/*.whl
if-no-files-found: error
overwrite: 'true'

- name: Set up mini CTK
uses: ./.github/actions/fetch_ctk
Expand Down Expand Up @@ -170,7 +169,35 @@ jobs:
name: ${{ env.CUDA_BINDINGS_ARTIFACT_NAME }}
path: ${{ env.CUDA_BINDINGS_ARTIFACTS_DIR }}/*.whl
if-no-files-found: error
overwrite: 'true'

# upload-artifact's "overwrite: true" option has a race condition among parallel
# jobs, so we let job 0 do the work
- name: Build and check cuda-python wheel
if: ${{ strategy.job-index == 0 }}
run: |
pushd cuda_python
pip wheel -v --no-deps .
twine check *.whl
popd
- name: List the cuda-python artifacts directory
if: ${{ strategy.job-index == 0 }}
run: |
if [[ "${{ matrix.host-platform }}" == win* ]]; then
export CHOWN=chown
else
export CHOWN="sudo chown"
fi
$CHOWN -R $(whoami) cuda_python/*.whl
ls -lahR cuda_python
- name: Upload cuda-python build artifacts
if: ${{ strategy.job-index == 0 }}
uses: actions/upload-artifact@v4
with:
name: cuda-python-wheel
path: cuda_python/*.whl
if-no-files-found: error

- name: Pass environment variables to the next runner
id: pass_env
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ jobs:
echo "CUDA_BINDINGS_ARTIFACT_NAME=${CUDA_BINDINGS_ARTIFACT_BASENAME}-${{ github.sha }}" >> $GITHUB_ENV
echo "CUDA_BINDINGS_ARTIFACTS_DIR=$(realpath "$REPO_DIR/cuda_bindings/dist")" >> $GITHUB_ENV
- name: Download cuda-python build artifacts
uses: actions/download-artifact@v4
with:
name: cuda-python-wheel
path: .

- name: Display structure of downloaded cuda-python artifacts
run: |
pwd
ls -lahR .
- name: Download cuda.bindings build artifacts
uses: actions/download-artifact@v4
with:
Expand Down Expand Up @@ -102,6 +113,8 @@ jobs:
pip install *.whl
popd
pip install cuda_python*.whl
- name: Build all (latest) docs
id: build
run: |
Expand Down
25 changes: 24 additions & 1 deletion .github/workflows/test-wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,21 @@ jobs:
dependencies: "build-essential jq wget"
dependent_exes: "gcc jq wget"

- name: Download cuda-python build artifacts
if: ${{ env.SKIP_CUDA_BINDINGS_TEST == '0'}}
uses: actions/download-artifact@v4
with:
name: cuda-python-wheel
path: .

- name: Download cuda.bindings build artifacts
if: ${{ env.SKIP_CUDA_BINDINGS_TEST == '0'}}
uses: actions/download-artifact@v4
with:
name: ${{ env.CUDA_BINDINGS_ARTIFACT_NAME }}
path: ${{ env.CUDA_BINDINGS_ARTIFACTS_DIR }}

- name: Download cuda.bindings build artifacts from the prior branch
- name: Download cuda-python & cuda.bindings build artifacts from the prior branch
if: ${{ env.SKIP_CUDA_BINDINGS_TEST == '1'}}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -120,6 +127,14 @@ jobs:
mkdir -p "${{ env.CUDA_BINDINGS_ARTIFACTS_DIR }}"
mv $OLD_BASENAME/*.whl "${{ env.CUDA_BINDINGS_ARTIFACTS_DIR }}"/
gh run download $LATEST_PRIOR_RUN_ID -p cuda-python-wheel -R NVIDIA/cuda-python
mv cuda-python-wheel/*.whl .
- name: Display structure of downloaded cuda-python artifacts
run: |
pwd
ls -lahR .
- name: Display structure of downloaded cuda.bindings artifacts
run: |
pwd
Expand Down Expand Up @@ -203,3 +218,11 @@ jobs:
pip install -r "tests/requirements-cu${TEST_CUDA_MAJOR}.txt"
pytest -rxXs tests/
popd
- name: Ensure cuda-python installable
run: |
if [[ "${{ inputs.local-ctk }}" == 1 ]]; then
pip install cuda_python*.whl
else
pip install $(ls cuda_python*.whl)[all]
fi
16 changes: 8 additions & 8 deletions cuda_bindings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ Differences between these options are described in [Installation](https://nvidia
CUDA Python is supported on all platforms that CUDA is supported. Specific dependencies are as follows:

* Driver: Linux (450.80.02 or later) Windows (456.38 or later)
* CUDA Toolkit 12.0 to 12.6
* CUDA Toolkit 12.x

Only the NVRTC redistributable component is required from the CUDA Toolkit. [CUDA Toolkit Documentation](https://docs.nvidia.com/cuda/index.html) Installation Guides can be used for guidance. Note that the NVRTC component in the Toolkit can be obtained via PYPI, Conda or Local Installer.
Only the NVRTC and nvJitLink redistributable components are required from the CUDA Toolkit, which can be obtained via PyPI, Conda, or local installers (as described in the CUDA Toolkit [Windows](https://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html) and [Linux](https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html) Installation Guides).

### Supported Python Versions

Expand Down Expand Up @@ -63,8 +63,8 @@ Latest dependencies can be found in [requirements.txt](https://github.com/NVIDIA

Multiple testing options are available:

* Cython Unit Tests
* Python Unit Tests
* Cython Unit Tests
* Samples
* Benchmark

Expand All @@ -73,18 +73,18 @@ Multiple testing options are available:
Responsible for validating different binding usage patterns. Unit test `test_kernelParams.py` is particularly special since it demonstrates various approaches in setting up kernel launch parameters.

To run these tests:
* `python -m pytest tests/` against local builds
* `python -m pytest tests/` against editable installations
* `pytest tests/` against installed packages

### Cython Unit Tests

Cython tests are located in `tests/cython` and need to be built. Furthermore they need CUDA Toolkit headers matching the major-minor of CUDA Python. To build them:
Cython tests are located in `tests/cython` and need to be built. These builds have the same CUDA Toolkit header requirements as [Installing from Source](https://nvidia.github.io/cuda-python/cuda-bindings/latest/install.html#requirements) where the major.minor version must match `cuda.bindings`. To build them:

1. Setup environment variable `CUDA_HOME` with the path to the CUDA Toolkit installation.
2. Run `build_tests` script located in `test/cython` appropriate to your platform. This will both cythonize the tests and build them.

To run these tests:
* `python -m pytest tests/cython/` against local builds
* `python -m pytest tests/cython/` against editable installations
* `pytest tests/cython/` against installed packages

### Samples
Expand All @@ -102,13 +102,13 @@ In addition, extra examples are included:
wrappers of the driver API.

To run these samples:
* `python -m pytest tests/cython/` against local builds
* `python -m pytest tests/cython/` against editable installations
* `pytest tests/cython/` against installed packages

### Benchmark (WIP)

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.

The intended way to run these benchmarks was:
* `python -m pytest --benchmark-only benchmark/` against local builds
* `python -m pytest --benchmark-only benchmark/` against editable installations
* `pytest --benchmark-only benchmark/` against installed packages
2 changes: 1 addition & 1 deletion cuda_bindings/cuda/bindings/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
# this software and related documentation outside the terms of the EULA
# is strictly prohibited.

__version__ = "12.6.2.post1"
__version__ = "12.6.3"
80 changes: 20 additions & 60 deletions cuda_bindings/docs/source/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,91 +2,51 @@

## Runtime Requirements

CUDA Python is supported on all platforms that CUDA is supported. Specific
dependencies are as follows:
`cuda.bindings` supports the same platforms as CUDA. Runtime dependencies are:

* Driver: Linux (450.80.02 or later) Windows (456.38 or later)
* CUDA Toolkit 12.0 to 12.6
* CUDA Toolkit 12.x

```{note} Only the NVRTC redistributable component is required from the CUDA Toolkit. [CUDA Toolkit Documentation](https://docs.nvidia.com/cuda/index.html) Installation Guides can be used for guidance. Note that the NVRTC component in the Toolkit can be obtained via PYPI, Conda or Local Installer.
```{note}
Only the NVRTC and nvJitLink redistributable components are required from the CUDA Toolkit, which can be obtained via PyPI, Conda, or local installers (as described in the CUDA Toolkit [Windows](https://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html) and [Linux](https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html) Installation Guides).
```

## Installing from PyPI

```{code-block} shell
pip install cuda-python
```console
$ pip install cuda-python
```

## Installing from Conda

```{code-block} shell
conda install -c nvidia cuda-python
```console
$ conda install -c conda-forge cuda-python
```

Conda packages are assigned a dependency to CUDA Toolkit:

* cuda-cudart (Provides CUDA headers to enable writting NVRTC kernels with CUDA types)
* cuda-nvrtc (Provides NVRTC shared library)

## Installing from Source

### Build Requirements
### Requirements

* CUDA Toolkit headers
* Cython
* pyclibrary
* CUDA Toolkit headers[^1]

Remaining build and test dependencies are outlined in [requirements.txt](https://github.com/NVIDIA/cuda-python/blob/main/requirements.txt)
[^1]: User projects that `cimport` CUDA symbols in Cython must also use CUDA Toolkit (CTK) types as provided by the `cuda.bindings` major.minor version. This results in CTK headers becoming a transitive dependency of downstream projects through CUDA Python.

The version of CUDA Toolkit headers must match the major.minor of CUDA Python. Note that minor version compatibility will still be maintained.
Source builds require that the provided CUDA headers are of the same major.minor version as the `cuda.bindings` you're trying to build. Despite this requirement, note that the minor version compatibility is still maintained. Use the `CUDA_HOME` (or `CUDA_PATH`) environment variable to specify the location of your headers. For example, if your headers are located in `/usr/local/cuda/include`, then you should set `CUDA_HOME` with:

During the build process, environment variable `CUDA_HOME` or `CUDA_PATH` are used to find the location of CUDA headers. In particular, if your headers are located in path `/usr/local/cuda/include`, then you should set `CUDA_HOME` as follows:

```
export CUDA_HOME=/usr/local/cuda
```console
$ export CUDA_HOME=/usr/local/cuda
```

### In-place

To compile the extension in-place, run:

```{code-block} shell
python setup.py build_ext --inplace
```{note}
Only `cydriver`, `cyruntime` and `cynvrtc` are impacted by the header requirement.
```

To compile for debugging the extension modules with gdb, pass the `--debug`
argument to setup.py.

### Develop
### Editable Install

You can use

```{code-block} shell
pip install -e .
```console
$ pip install -v -e .
```

to install the module as editible in your current Python environment (e.g. for
testing of porting other libraries to use the binding).

## Build the Docs

```{code-block} shell
conda env create -f docs_src/environment-docs.yml
conda activate cuda-python-docs
```
Then compile and install `cuda-python` following the steps above.

```{code-block} shell
cd docs_src
make html
open build/html/index.html
```

### Publish the Docs

```{code-block} shell
git checkout gh-pages
cd docs_src
make html
cp -a build/html/. ../docs/
```
to install the module as editable in your current Python environment (e.g. for testing of porting other libraries to use the binding).
5 changes: 5 additions & 0 deletions cuda_bindings/docs/source/module/nvjitlink.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
nvjitlink
=========

Note
----

The nvjitlink bindings are not supported on nvJitLink installations <12.3. Ensure the installed CUDA toolkit's nvJitLink version is >=12.3.

Functions
---------

Expand Down
2 changes: 1 addition & 1 deletion cuda_bindings/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ requires = ["setuptools", "cython", "pyclibrary"]
build-backend = "setuptools.build_meta"

[project]
name = "cuda-python"
name = "cuda-bindings"
description = "Python bindings for CUDA"
authors = [{name = "NVIDIA Corporation", email = "cuda-python-conduct@nvidia.com"},]
license = {file = "LICENSE"}
Expand Down
6 changes: 3 additions & 3 deletions cuda_bindings/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ def build_extension(self, ext):
# Allow extensions to discover libraries at runtime
# relative their wheels installation.
if ext.name == "cuda.bindings._bindings.cynvrtc":
ldflag = f"-Wl,--disable-new-dtags,-rpath,$ORIGIN/../../../nvidia/cuda_nvrtc/lib"
ldflag = "-Wl,--disable-new-dtags,-rpath,$ORIGIN/../../../nvidia/cuda_nvrtc/lib"
elif ext.name == "cuda.bindings._internal.nvjitlink":
ldflag = f"-Wl,--disable-new-dtags,-rpath,$ORIGIN/../../../nvidia/nvjitlink/lib"
ldflag = "-Wl,--disable-new-dtags,-rpath,$ORIGIN/../../../nvidia/nvjitlink/lib"
else:
ldflag = None

Expand All @@ -326,7 +326,7 @@ def build_extension(self, ext):
cmdclass = {
"bdist_wheel": WheelsBuildExtensions,
"build_ext": ParallelBuildExtensions,
}
}

# ----------------------------------------------------------------------
# Setup
Expand Down
4 changes: 1 addition & 3 deletions cuda_bindings/tests/test_nvjitlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ def ptx_header(version, arch):
def check_nvjitlink_usable():
from cuda.bindings._internal import nvjitlink as inner_nvjitlink

if inner_nvjitlink._inspect_function_pointer("__nvJitLinkVersion") == 0:
return False
return True
return inner_nvjitlink._inspect_function_pointer("__nvJitLinkVersion") != 0


pytestmark = pytest.mark.skipif(
Expand Down
2 changes: 1 addition & 1 deletion cuda_core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ for more details, including how to sign your commits.
## Testing

To run these tests:
* `python -m pytest tests/` against local builds
* `python -m pytest tests/` against editable installations
* `pytest tests/` against installed packages
5 changes: 2 additions & 3 deletions cuda_core/cuda/core/experimental/_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE

import importlib.metadata
from dataclasses import dataclass
from typing import Optional, Union

Expand All @@ -11,7 +10,7 @@
from cuda.core.experimental._kernel_arg_handler import ParamHolder
from cuda.core.experimental._module import Kernel
from cuda.core.experimental._stream import Stream
from cuda.core.experimental._utils import CUDAError, check_or_create_options, handle_return
from cuda.core.experimental._utils import CUDAError, check_or_create_options, get_binding_version, handle_return

# TODO: revisit this treatment for py313t builds
_inited = False
Expand All @@ -25,7 +24,7 @@ def _lazy_init():

global _use_ex
# binding availability depends on cuda-python version
_py_major_minor = tuple(int(v) for v in (importlib.metadata.version("cuda-python").split(".")[:2]))
_py_major_minor = get_binding_version()
_driver_ver = handle_return(cuda.cuDriverGetVersion())
_use_ex = (_driver_ver >= 11080) and (_py_major_minor >= (11, 8))
_inited = True
Expand Down
Loading

0 comments on commit 777b106

Please sign in to comment.