Develop C++/CUDA extensions with PyTorch like Python scripts
Project description
CharonLoad
CharonLoad is a bridge between Python code and rapidly developed custom C++/CUDA extensions to make writing high-performance research code with PyTorch easy:
- 🔥 PyTorch C++ API detection and linking
- 🔨 Automatic just-in-time (JIT) compilation of the C++/CUDA part
- 📦 Cached incremental builds and automatic clean builds
- 🔗 Full power of CMake for handling C++ dependencies
- ⌨️ Python stub file generation for syntax highlighting and auto-completion in VS Code
- 🐛 Interactive mixed Python/C++ debugging support in VS Code via Python C++ Debugger extension
CharonLoad reduces the burden to start writing and experimenting with custom GPU kernels in PyTorch by getting complex boilerplate code and common pitfalls out of your way. Developing C++/CUDA code with CharonLoad feels similar to writing Python scripts and lets you follow the same familiar workflow.
Installation
CharonLoad requires Python >=3.8 and can be installed from PyPI:
pip install charonload
Quick Start
CharonLoad only requires minimal changes to existing projects. In particular, a small configuration of the C++/CUDA project is added in the Python part while the CMake and C++ part should adopt some predefined functions:
-
<your_project>/main.py
import charonload VSCODE_STUBS_DIRECTORY = pathlib.Path(__file__).parent / "typings" charonload.module_config["my_cpp_cuda_ext"] = charonload.Config( project_directory=pathlib.Path(__file__).parent / "<my_cpp_cuda_ext>", build_directory="custom/build/directory", # optional stubs_directory=VSCODE_STUBS_DIRECTORY, # optional ) import other_module
-
<your_project>/other_module.py
import my_cpp_cuda_ext # JIT compiles and loads the extension tensor_from_ext = my_cpp_cuda_ext.generate_tensor()
-
<your_project>/<my_cpp_cuda_ext>/CMakeLists.txt
find_package(charonload) if(charonload_FOUND) charonload_add_torch_library(${TORCH_EXTENSION_NAME} MODULE) target_sources(${TORCH_EXTENSION_NAME} PRIVATE src/<my_bindings>.cpp) # Further properties, e.g. link against other 3rd-party libraries, etc. # ... endif()
-
<your_project>/<my_cpp_cuda_ext>/src/<my_bindings>.cpp
#include <torch/python.h> torch::Tensor generate_tensor(); // Implemented somewhere in <my_cpp_cuda_ext> PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { m.def("generate_tensor", &generate_tensor, "Optional Python docstring"); }
Contributing
If you would like to contribute to CharonLoad, you can find more information in the Contributing guide.
License
MIT
Contact
Patrick Stotko - stotko@cs.uni-bonn.de
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 charonload-0.1.4.tar.gz
.
File metadata
- Download URL: charonload-0.1.4.tar.gz
- Upload date:
- Size: 25.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3c456738a9fa7bdc3474460a6d11533aa60c13979c22e7f71c3e8737e726f88 |
|
MD5 | c1d2d041b97008a912d15d91842e22c5 |
|
BLAKE2b-256 | 9798c4e9ec79f3876602340d8e666cc1d8af005b9b7113142960fd699dd44184 |
Provenance
The following attestation bundles were made for charonload-0.1.4.tar.gz
:
- Repository: vc-bonn/charonload
- Workflow: pypi.yml
-
Statement type: https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
charonload-0.1.4.tar.gz
- Subject digest:
f3c456738a9fa7bdc3474460a6d11533aa60c13979c22e7f71c3e8737e726f88
- Transparency log index: 147576422
- Transparency log integration time:
- Predicate type:
File details
Details for the file charonload-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: charonload-0.1.4-py3-none-any.whl
- Upload date:
- Size: 30.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79f9627f36e9859c0319ae0adfd578f4a57289d8324d835c5895d162aacd4205 |
|
MD5 | f47656c5e3476c4a24a5a3515bda19d3 |
|
BLAKE2b-256 | 427aeab7b860b4ad38a81b4a421f346843588eef42ed44a4e74aff99984ab521 |
Provenance
The following attestation bundles were made for charonload-0.1.4-py3-none-any.whl
:
- Repository: vc-bonn/charonload
- Workflow: pypi.yml
-
Statement type: https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
charonload-0.1.4-py3-none-any.whl
- Subject digest:
79f9627f36e9859c0319ae0adfd578f4a57289d8324d835c5895d162aacd4205
- Transparency log index: 147576424
- Transparency log integration time:
- Predicate type: