Setuptools plugin for compiling CUDA-enable extension modules
Project description
Setuptools plugin for CUDA extensions
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.
-
Add
setuptools-cuda
to yourbuild-system
requirements inpyproject.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 usingpip
. -
Declare your extension module by passing list of
CUDAExtension
objects tocuda_extensions
keyword to thesetup()
function call insetup.py
. For instance, one of the examples in this repository has the followingsetup.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"], ), ], )
-
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). -
Build your package as usual. Typically just running
pip install
should do.
Acknowledgements
This package was inspired by setuptools-rust package.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file setuptools-cuda-0.0.3.tar.gz
.
File metadata
- Download URL: setuptools-cuda-0.0.3.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d7508d0fe07cd35ee6a58ec7f0fad33272a6c850c870aeb1ec6b51993fd883b |
|
MD5 | ddc927edda344f370f81a109ea81ea22 |
|
BLAKE2b-256 | e3e912ea05cc488ae57e20bc691809bbfee65dba73ef74ae53c524872a6b1cb5 |
File details
Details for the file setuptools_cuda-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: setuptools_cuda-0.0.3-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3cc86febcc54d1a7235986e9611b2ddcc1b45042dec43cb9811c319c48e0a212 |
|
MD5 | 7af85994cc2f9f0937c4e51790cc2320 |
|
BLAKE2b-256 | 46394513e7c7879acd77e2013cc58de3095e459e0b1aa304e3655a6920b193e5 |