# Setuptools CUDA C++
[![PyPI - Version](https://img.shields.io/pypi/v/setuptools-cuda-cpp.svg)](https://pypi.org/project/setuptools-cuda-cpp)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/setuptools-cuda-cpp.svg)](https://pypi.org/project/setuptools-cuda-cpp)
[![GitHub - Dependencies](https://img.shields.io/librariesio/release/pypi/setuptools-cuda-cpp?label=deps)](https://pypi.org/project/setuptools-cuda-cpp)
[![GitHub - Issues](https://img.shields.io/github/issues/RafaelJVicente/setuptools-cuda-cpp?color=yellow)](https://github.com/RafaelJVicente/setuptools-cuda-cpp/issues)
[![GitHub - Last commit](https://img.shields.io/github/last-commit/RafaelJVicente/setuptools-cuda-cpp?color=purple)](https://github.com/RafaelJVicente/setuptools-cuda-cpp)
[//]: # ([![GitHub - Build](https://img.shields.io/github/actions/workflow/status/RafaelJVicente/setuptools-cuda-cpp/unit-tests.yml)](https://github.com/RafaelJVicente/setuptools-cuda-cpp))
The setuptools-cuda-cpp is a module that extends setuptools functionality for building hybrid C++ and CUDA extensions
for Python wrapper modules.
-----
**Table of Contents**
- [Summary](#summary)
- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
- [Issues](#issues)
- [License](#license)
- [Acknowledgements](#acknowledgements)
## Summary
This project meant to be a soft solution to include mixed c++/CUDA extensions in your projects, no matter if you are
using old python version (3.6+) or old GPU drivers (sm/compute arch 3.0+).
## Features
- Python version >= 3.6 .
- SM(StreamingMultiprocessor)/Compute architecture >= 3.0 .
- Cython compatible but not mandatory.
- Any CUDA version (since you can configure nvcc flags).
- Preloaded flags for cpp and CUDA compilers.
- Mixed compilations (.cpp and .cu files can be included in a single extension).
- Advanced find_cuda features (automatically try to find the CUDAHOME directory).
- Include NVIDIA Management Library (NVML) capabilities info.
## Installation
```console
pip install setuptools-cuda-cpp
```
## Usage
Add the library to your project configuration files ("pyproject.toml" and/or "setup.py/.cfg").
### 1. Example for "legacy build" (old python versions with setuptools < 61.0.0):
[**setup.py**](./examples/cuda_example/setup.py)
```python
from pathlib import Path
from setuptools import setup
from setuptools_cuda_cpp import CUDAExtension, BuildExtension, fix_dll
cuda_ext_path = Path('src/my_cuda_package/cuda_ext')
cuda_ext = CUDAExtension(
name='my_cuda_package.cuda_ext',
include_dirs=[cuda_ext_path / 'include'],
sources=[
cuda_ext_path / 'cuda_ext.cu',
cuda_ext_path / 'cuda_ext_wrapper.cpp',
],
libraries=fix_dll(['cudart']), # Use fix_dll() only for Windows compatibility (check documentation for more info).
extra_compile_args={
'cxx': ['-g'], # cpp compiler flags
'nvcc': ['-O2'], # nvcc flags
},
)
setup(
name='my-cuda-package',
version='0.0.1',
install_requires=['numpy', ],
extras_require={'cython': ['cython'], },
ext_modules=[cuda_ext],
cmdclass={'build_ext': BuildExtension},
)
```
You can also use pyproject.toml with [Flit](https://flit.pypa.io) making
a [custom build-backend](https://setuptools.pypa.io/en/latest/build_meta.html#dynamic-build-dependencies-and-other-build-meta-tweaks).
### 2. Example for "pyproject.toml build" (with setuptools >= 61.0.0):
[**pyproject.toml**](./examples/cuda_example/build_for_setuptools_61.0.0+/pyproject.toml)
```toml
[build-system]
requires = ["setuptools-cuda-cpp", "flit_core >=3.2,<4", "wheel", "cython"]
build-backend = "flit_core.buildapi"
[project]
name = "my-cuda-package"
dependencies = ["numpy"]
dynamic = ["version", "description"]
# ...
```
And configure the setup.py for the different extensions you want to use:
[**setup.py**](examples/cuda_example/build_for_setuptools_61.0.0+/setup.py)
```python
from pathlib import Path
from setuptools import setup
from setuptools_cuda_cpp import CUDAExtension, BuildExtension, fix_dll
cuda_ext_path = Path('src/my_cuda_package/cuda_ext')
cuda_ext = CUDAExtension(
name='my_cuda_package.cuda_ext',
include_dirs=[cuda_ext_path / 'include'],
sources=[
cuda_ext_path / 'cuda_ext.cu',
cuda_ext_path / 'cuda_ext_wrapper.cpp',
],
libraries=fix_dll(['cudart']), # Use fix_dll() only for Windows compatibility (check documentation for more info).
extra_compile_args={
'cxx': ['-g'], # cpp compiler flags
'nvcc': ['-O2'], # nvcc flags
},
)
setup(
ext_modules=[cuda_ext],
cmdclass={'build_ext': BuildExtension},
)
```
## Issues
If you receive a EnvironmentError exception you should set CUDAHOME environment variable pointing to the CUDA
installation path. This would happen if the find_cuda() method is not capable of locate it.
As reference the directory should contain:
```text
CUDAHOME
├── bin
│ └── nvcc
├── include
│ └── cudart.h
├── lib
└── nvml
```
## License
`setuptools-cuda-cpp` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
## Acknowledgements
The package is based on [cpp_extension](https://pytorch.org/docs/stable/cpp_extension.html), but it also includes:
- Support for deprecated older architectures (from sm / compute 3.0).
- Improved find_cuda system.
- Pathlib library and Windows missing dll support.
Raw data
{
"_id": null,
"home_page": null,
"name": "setuptools-cuda-cpp",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "cuda,extension,compilation,compile,cpp,c++,cross,ext,setuptools,wrapper",
"author": null,
"author_email": "\"Rafael J. Vicente\" <rafaelj.vicente@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/44/2d/0d18183db086bd1386410a8baed4b71ce050648d399efc2fdbabb60032b8/setuptools-cuda-cpp-0.1.8.tar.gz",
"platform": null,
"description": "# Setuptools CUDA C++\n\n[![PyPI - Version](https://img.shields.io/pypi/v/setuptools-cuda-cpp.svg)](https://pypi.org/project/setuptools-cuda-cpp)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/setuptools-cuda-cpp.svg)](https://pypi.org/project/setuptools-cuda-cpp)\n[![GitHub - Dependencies](https://img.shields.io/librariesio/release/pypi/setuptools-cuda-cpp?label=deps)](https://pypi.org/project/setuptools-cuda-cpp)\n[![GitHub - Issues](https://img.shields.io/github/issues/RafaelJVicente/setuptools-cuda-cpp?color=yellow)](https://github.com/RafaelJVicente/setuptools-cuda-cpp/issues)\n[![GitHub - Last commit](https://img.shields.io/github/last-commit/RafaelJVicente/setuptools-cuda-cpp?color=purple)](https://github.com/RafaelJVicente/setuptools-cuda-cpp)\n\n[//]: # ([![GitHub - Build](https://img.shields.io/github/actions/workflow/status/RafaelJVicente/setuptools-cuda-cpp/unit-tests.yml)](https://github.com/RafaelJVicente/setuptools-cuda-cpp))\n\nThe setuptools-cuda-cpp is a module that extends setuptools functionality for building hybrid C++ and CUDA extensions\nfor Python wrapper modules.\n\n-----\n\n**Table of Contents**\n\n- [Summary](#summary)\n- [Features](#features)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Issues](#issues)\n- [License](#license)\n- [Acknowledgements](#acknowledgements)\n\n## Summary\n\nThis project meant to be a soft solution to include mixed c++/CUDA extensions in your projects, no matter if you are\nusing old python version (3.6+) or old GPU drivers (sm/compute arch 3.0+).\n\n## Features\n\n- Python version >= 3.6 .\n- SM(StreamingMultiprocessor)/Compute architecture >= 3.0 .\n- Cython compatible but not mandatory.\n- Any CUDA version (since you can configure nvcc flags).\n- Preloaded flags for cpp and CUDA compilers.\n- Mixed compilations (.cpp and .cu files can be included in a single extension).\n- Advanced find_cuda features (automatically try to find the CUDAHOME directory).\n- Include NVIDIA Management Library (NVML) capabilities info.\n\n## Installation\n\n```console\npip install setuptools-cuda-cpp\n```\n\n## Usage\n\nAdd the library to your project configuration files (\"pyproject.toml\" and/or \"setup.py/.cfg\").\n\n### 1. Example for \"legacy build\" (old python versions with setuptools < 61.0.0):\n\n[**setup.py**](./examples/cuda_example/setup.py)\n\n```python\nfrom pathlib import Path\nfrom setuptools import setup\nfrom setuptools_cuda_cpp import CUDAExtension, BuildExtension, fix_dll\n\ncuda_ext_path = Path('src/my_cuda_package/cuda_ext')\ncuda_ext = CUDAExtension(\n name='my_cuda_package.cuda_ext',\n include_dirs=[cuda_ext_path / 'include'],\n sources=[\n cuda_ext_path / 'cuda_ext.cu',\n cuda_ext_path / 'cuda_ext_wrapper.cpp',\n ],\n libraries=fix_dll(['cudart']), # Use fix_dll() only for Windows compatibility (check documentation for more info).\n extra_compile_args={\n 'cxx': ['-g'], # cpp compiler flags\n 'nvcc': ['-O2'], # nvcc flags\n },\n)\n\nsetup(\n name='my-cuda-package',\n version='0.0.1',\n install_requires=['numpy', ],\n extras_require={'cython': ['cython'], },\n ext_modules=[cuda_ext],\n cmdclass={'build_ext': BuildExtension},\n)\n```\n\nYou can also use pyproject.toml with [Flit](https://flit.pypa.io) making\na [custom build-backend](https://setuptools.pypa.io/en/latest/build_meta.html#dynamic-build-dependencies-and-other-build-meta-tweaks).\n\n### 2. Example for \"pyproject.toml build\" (with setuptools >= 61.0.0):\n\n[**pyproject.toml**](./examples/cuda_example/build_for_setuptools_61.0.0+/pyproject.toml)\n\n```toml\n[build-system]\nrequires = [\"setuptools-cuda-cpp\", \"flit_core >=3.2,<4\", \"wheel\", \"cython\"]\nbuild-backend = \"flit_core.buildapi\"\n\n[project]\nname = \"my-cuda-package\"\ndependencies = [\"numpy\"]\ndynamic = [\"version\", \"description\"]\n# ...\n```\n\nAnd configure the setup.py for the different extensions you want to use:\n\n[**setup.py**](examples/cuda_example/build_for_setuptools_61.0.0+/setup.py)\n\n```python\nfrom pathlib import Path\nfrom setuptools import setup\nfrom setuptools_cuda_cpp import CUDAExtension, BuildExtension, fix_dll\n\ncuda_ext_path = Path('src/my_cuda_package/cuda_ext')\ncuda_ext = CUDAExtension(\n name='my_cuda_package.cuda_ext',\n include_dirs=[cuda_ext_path / 'include'],\n sources=[\n cuda_ext_path / 'cuda_ext.cu',\n cuda_ext_path / 'cuda_ext_wrapper.cpp',\n ],\n libraries=fix_dll(['cudart']), # Use fix_dll() only for Windows compatibility (check documentation for more info).\n extra_compile_args={\n 'cxx': ['-g'], # cpp compiler flags\n 'nvcc': ['-O2'], # nvcc flags\n },\n)\n\nsetup(\n ext_modules=[cuda_ext],\n cmdclass={'build_ext': BuildExtension},\n)\n```\n\n## Issues\n\nIf you receive a EnvironmentError exception you should set CUDAHOME environment variable pointing to the CUDA\ninstallation path. This would happen if the find_cuda() method is not capable of locate it.\nAs reference the directory should contain:\n\n```text\nCUDAHOME\n\u251c\u2500\u2500 bin\n\u2502 \u2514\u2500\u2500 nvcc\n\u251c\u2500\u2500 include\n\u2502 \u2514\u2500\u2500 cudart.h\n\u251c\u2500\u2500 lib\n\u2514\u2500\u2500 nvml\n```\n\n## License\n\n`setuptools-cuda-cpp` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.\n\n## Acknowledgements\nThe package is based on [cpp_extension](https://pytorch.org/docs/stable/cpp_extension.html), but it also includes:\n- Support for deprecated older architectures (from sm / compute 3.0).\n- Improved find_cuda system.\n- Pathlib library and Windows missing dll support.\n",
"bugtrack_url": null,
"license": null,
"summary": "Module that extends setuptools functionality for building hybrid C++ and CUDA extension for Python wrapper modules.",
"version": "0.1.8",
"split_keywords": [
"cuda",
"extension",
"compilation",
"compile",
"cpp",
"c++",
"cross",
"ext",
"setuptools",
"wrapper"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "0a4b9a0a263f0a650dd5942030c79d372828e7a8097e643ca17bcceabfdca5f6",
"md5": "0763abd4379708161c15abe41fc9aac5",
"sha256": "809d018d513e17ac32d4d97ad01c03713b9e1978bae3037eda4f8b3919b76ee2"
},
"downloads": -1,
"filename": "setuptools_cuda_cpp-0.1.8-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0763abd4379708161c15abe41fc9aac5",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 18319,
"upload_time": "2023-03-12T15:37:39",
"upload_time_iso_8601": "2023-03-12T15:37:39.062377Z",
"url": "https://files.pythonhosted.org/packages/0a/4b/9a0a263f0a650dd5942030c79d372828e7a8097e643ca17bcceabfdca5f6/setuptools_cuda_cpp-0.1.8-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "442d0d18183db086bd1386410a8baed4b71ce050648d399efc2fdbabb60032b8",
"md5": "8ee5c46fc5678b932a877351fcf5539a",
"sha256": "7b17eef33060c8b6dc36a8e9f86d6e5ac69a4b6f33f3884d85b8ab05a9526b92"
},
"downloads": -1,
"filename": "setuptools-cuda-cpp-0.1.8.tar.gz",
"has_sig": false,
"md5_digest": "8ee5c46fc5678b932a877351fcf5539a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 23737,
"upload_time": "2023-03-12T15:37:41",
"upload_time_iso_8601": "2023-03-12T15:37:41.697881Z",
"url": "https://files.pythonhosted.org/packages/44/2d/0d18183db086bd1386410a8baed4b71ce050648d399efc2fdbabb60032b8/setuptools-cuda-cpp-0.1.8.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-03-12 15:37:41",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "setuptools-cuda-cpp"
}