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.10 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.pyimport 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.pyimport 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.txtfind_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
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file charonload-0.3.1.tar.gz.
File metadata
- Download URL: charonload-0.3.1.tar.gz
- Upload date:
- Size: 28.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7f6ff33e9f752bf816b2d02914e7200820dbdae1dd50f2d2def67111178361b
|
|
| MD5 |
05413939f3bfbed8e5b7439ef23d5c44
|
|
| BLAKE2b-256 |
b44d7046348aa0b0878e13cf7f079313b2d679cbc502c069d33efd08718a20dc
|
Provenance
The following attestation bundles were made for charonload-0.3.1.tar.gz:
Publisher:
pypi.yml on vc-bonn/charonload
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
charonload-0.3.1.tar.gz -
Subject digest:
f7f6ff33e9f752bf816b2d02914e7200820dbdae1dd50f2d2def67111178361b - Sigstore transparency entry: 768520502
- Sigstore integration time:
-
Permalink:
vc-bonn/charonload@c96533a1b0325383358d951f965185eddae5ce07 -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/vc-bonn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@c96533a1b0325383358d951f965185eddae5ce07 -
Trigger Event:
release
-
Statement type:
File details
Details for the file charonload-0.3.1-py3-none-any.whl.
File metadata
- Download URL: charonload-0.3.1-py3-none-any.whl
- Upload date:
- Size: 33.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46ad1138da3da54df4271022c91fccabb0a9a2265b0ba8c3e4552ff0acff2f39
|
|
| MD5 |
2af1292720f8f06de8111eb74973952e
|
|
| BLAKE2b-256 |
b7f421e7a17c1163c45e0f958eb59e3066a31ef79da777698aa580f280873045
|
Provenance
The following attestation bundles were made for charonload-0.3.1-py3-none-any.whl:
Publisher:
pypi.yml on vc-bonn/charonload
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
charonload-0.3.1-py3-none-any.whl -
Subject digest:
46ad1138da3da54df4271022c91fccabb0a9a2265b0ba8c3e4552ff0acff2f39 - Sigstore transparency entry: 768520504
- Sigstore integration time:
-
Permalink:
vc-bonn/charonload@c96533a1b0325383358d951f965185eddae5ce07 -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/vc-bonn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@c96533a1b0325383358d951f965185eddae5ce07 -
Trigger Event:
release
-
Statement type: