Simple CMAKE make project for extending PyTorch with custom cuda kernels for doing all the things that I wanna try.
pip install scikit_build_core
pip install pyproject-metadata
# Install in editable mode
pip install -v --no-build-isolation -e .
This will invoke the pyproject.toml
file and build the project with the scikit-build
package.
Including, calling cmake and building the shared library.
- Lets make a test env:
conda create -n test_env python=3.10
conda activate test_env
# Install nightly torch
pip3 install -U --pre torch --index-url https://download.pytorch.org/whl/nightly/cu121
- Lets run the build command
pip install .
This will invoke cmake which in turn will build the shared library and installed into driss_torch/lib/libdriss_torch.so
So this will go and build the libdriss_torch.so shared library. In which there will be a number of ops that have been registered.
In the python package driss_torch
there will be small wrappers around the cpp ops with better type hints and documentation.
Could use .ini but this more fun.
The total install command from scratch can take a second. If you want a faster dev flow cd into build and once you change your sources of the lib just run ninja
to rebuild the shared library. This will not work if you are adding and deleting files.
You should be able to grab the ops by doing something like
import torch
import driss_torch
a = torch.randn(10, 10, device='cuda')
b = driss_torch.add_one(b)
print(b)
pre-commit install
pytest test/
This calls cmake directly in the build dir.
# In the root directory
mkdir build && cd build
# Configure the build, to build with compute arch
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -GNinja -DTORCH_CUDA_ARCH_LIST=9.0 ..