Skip to main content

Setuptools plugin for compiling CUDA-enable extension modules

Project description

Setuptools plugin for CUDA extensions

PyPI version ![github actions](https://github. com/euro-hpc-pl/setuptools_cuda/actions/workflows/build_and_test_examples.yml/badge.svg)

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.

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

setuptools-cuda-0.0.0.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

setuptools_cuda-0.0.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file setuptools-cuda-0.0.0.tar.gz.

File metadata

  • Download URL: setuptools-cuda-0.0.0.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for setuptools-cuda-0.0.0.tar.gz
Algorithm Hash digest
SHA256 9c9b2406365162f9309c0f2260d6f17ecd2aa060b9c63486c637d87deac1b616
MD5 599a0551b33d4701ab53ef1d96504ead
BLAKE2b-256 e1b531369d72c284a4f9f75124b71499967aac7503a796a0bd727e62d90e0ef7

See more details on using hashes here.

File details

Details for the file setuptools_cuda-0.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for setuptools_cuda-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5f795da3c060023d6f789b169235b9bbd3bf1d11123b7e2686222bd990cb8c26
MD5 8627fa981cdb8fe4b136e1100c6bbdfe
BLAKE2b-256 849e364884f2ac0b27a497fcf2042020436220582bc60e4f286f636ae46df9f1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page