Skip to main content

Setuptools CUDA C++

PyPI - Version PyPI - Python Version GitHub - Dependencies GitHub - Issues GitHub - Last commit

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

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

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

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 making a custom build-backend.

2. Example for "pyproject.toml build" (with setuptools >= 61.0.0):

pyproject.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

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:

CUDAHOME
├── bin
│   └── nvcc
├── include
│   └── cudart.h
├── lib
└── nvml

License

setuptools-cuda-cpp is distributed under the terms of the MIT license.

Acknowledgements

The package is based on cpp_extension, 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.

Metadata

Release files for setuptools-cuda-cpp 0.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for setuptools-cuda-cpp 0.1.8
File Size Uploaded Provenance Actions
setuptools-cuda-cpp-0.1.8.tar.gz 23.7 kB Without provenance Details for setuptools-cuda-cpp-0.1.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for setuptools-cuda-cpp 0.1.8
File Interpreter ABI Platform Actions
setuptools_cuda_cpp-0.1.8-py3-none-any.whl Python 3 none any Details for setuptools_cuda_cpp-0.1.8-py3-none-any.whl

Total release size: 42.1 kB

Release files / setuptools-cuda-cpp-0.1.8.tar.gz

Download URL setuptools-cuda-cpp-0.1.8.tar.gz
Size 23.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7b17eef33060c8b6dc36a8e9f86d6e5ac69a4b6f33f3884d85b8ab05a9526b92
BLAKE2b-256 checksum
How to use checksums
442d0d18183db086bd1386410a8baed4b71ce050648d399efc2fdbabb60032b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.27.1

Release files / setuptools_cuda_cpp-0.1.8-py3-none-any.whl

Download URL setuptools_cuda_cpp-0.1.8-py3-none-any.whl
Size 18.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
809d018d513e17ac32d4d97ad01c03713b9e1978bae3037eda4f8b3919b76ee2
BLAKE2b-256 checksum
How to use checksums
0a4b9a0a263f0a650dd5942030c79d372828e7a8097e643ca17bcceabfdca5f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.27.1

Security for setuptools-cuda-cpp 0.1.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.8 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page