Skip to main content

Setuptools plugin for CUDA extensions

PyPI version github actions

The setuptools-cuda is a setuptools plugin for building CUDA enabled Python extension modules.

How does it compare to other packages on the market?

As far as the authors of this package know, other CUDA-oriented Python projects focus mostly on providing higher-level abstractions over CUDA that can be accessed in Python. For instance, the well-known PyCUDA provides GPUArray and SourceModule abstractions.

However, when it comes to compiling extension modules that use CUDA, surprisingly there seems to be no good solution that just works out of the box. Typically, people tend to integrate the CUDA code into their extension modules either using some third-party build systems or by writing some ad-hoc hacks for setuptools (see e.g. this StakOverflow question).

The setuptools-cuda tries to fill this niche. It allows one for defining extension modules containing .cu compilation units that will be compiled with nvcc. Such extensions can then be build using normal setuptools build procedures.

Quickstart

Using setuptools-cuda is easy and requires you to perform the following steps.

  1. Add setuptools-cuda to your build-system requirements in pyproject.toml. For instance like this:

    [build-system]
    requires = ["setuptools", "wheel", "cython", "setuptools-cuda"]
    

    If you are not using isolated builds, you should install setuptools-cuda in your environment using pip.

  2. Declare your extension module by passing list of CudaExtension objects to cuda_extensions keyword to the setup() function call in setup.py. For instance, one of the examples in this repository has the following setup.py file:

    from setuptools import setup
    
    from setuptools_cuda import CudaExtension
    
    setup(
        cuda_extensions=[
            CudaExtension(
                name="thrust",
                sources=["thrustcu/thrustcu.pyx", "thrustcu/thrustcu_impl.cu"],
            ),
        ],
    )
    
  3. IMPORTANT define CUDAHOME environment variable. It should point to the CUDA installation location. E.g.

    export CUDAHOME=/opt/nvidia/hpc_sdk/Linux_x86_64/23.1/cuda
    

    If you won't define the CUDAHOME evironmental variable, setuptools-cuda will do its best to guess it, but our experience shows that it might fail miserably (and probably silently).

  4. Build your package as usual. Typically just running pip install should do.

Acknowledgements

This package was inspired by setuptools-rust package.

Metadata

Release files for setuptools-cuda 0.0.6

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 0.0.6
File Size Uploaded Provenance
setuptools-cuda-0.0.6.tar.gz 17.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for setuptools-cuda 0.0.6
File Interpreter ABI Platform
setuptools_cuda-0.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 23.4 kB

Release files / setuptools-cuda-0.0.6.tar.gz

Download URL setuptools-cuda-0.0.6.tar.gz
Size 17.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2f83b71ae0d63c206aa21e375b6a215a82f0ce0c27a7fc02edcefa18d672b5ef
BLAKE2b-256 checksum
How to use checksums
70e7e9f3fd710f9317daa9b5a651396746da4e84b9c74845a43b0c19a05be990
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / setuptools_cuda-0.0.6-py3-none-any.whl

Download URL setuptools_cuda-0.0.6-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ef27f04ac392016181717e10b2083168c7db4a43d4b63cf86c8bfcea7a3d55f7
BLAKE2b-256 checksum
How to use checksums
1264a37b2e4184fd0b989502b1e6b4861e9486aece8e6b2e093be548c49d6a2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Security for setuptools-cuda 0.0.6

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.

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