CUDA kernels for machine learning systems optimization
Project description
kernel-craft Python API
CUDA convolution kernels exposed to Python with numpy and PyTorch support.
Installation
Build from source with CMake:
cd /path/to/kernel-craft
mkdir build && cd build
cmake ..
make kernel_craft_python
The module will be at src/python/build/kernel_craft_python.cpython-*.so.
Usage
import sys
sys.path.insert(0, 'src/python/build')
import kernel_craft_python as kc
import numpy as np
# Input: 2D float32 numpy array
input = np.random.randn(256, 256).astype(np.float32)
kernel = np.random.randn(3, 3).astype(np.float32)
# Naive convolution
out = kc.conv_naive(input, kernel) # -> np.ndarray
# Tiled convolution with configurable tile size
out = kc.conv_tiled(input, kernel, tile_w=8, tile_h=8) # -> np.ndarray
Version
import kernel_craft_python as kc
print(kc.__version__) # "0.1.0"
PyTorch Tensors
import torch
import kernel_craft_python as kc
# Input: 2D float32 PyTorch tensor on CUDA
input = torch.rand(256, 256, dtype=torch.float32, device='cuda')
kernel = torch.rand(3, 3, dtype=torch.float32, device='cuda')
# Naive convolution
out = kc.conv_naive(input, kernel) # -> torch.Tensor on GPU
# Tiled convolution
out = kc.conv_tiled(input, kernel, tile_w=16, tile_h=16) # -> torch.Tensor on GPU
API Reference
| Function | Input Type | Output Type |
|---|---|---|
conv_naive(input, kernel) |
np.ndarray or Tensor | np.ndarray or Tensor |
conv_tiled(input, kernel, tile_w, tile_h) |
np.ndarray or Tensor | np.ndarray or Tensor |
Parameters
input: Input image (2D, float32)kernel: Convolution kernel (2D, float32, odd dimension)tile_w: Tile width for tiled convolution (default: 8)tile_h: Tile height for tiled convolution (default: 8)
Supported Tile Sizes
- 8x8 (default, best overall performance)
- 16x16
- 32x32
Error Handling
All functions raise RuntimeError with descriptive messages for:
- Invalid input dimensions (must be 2D)
- Invalid kernel dimensions (must be 2D, square, odd-sized)
- Invalid dtype (must be float32)
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
kernel_craft-0.1.0.tar.gz
(117.6 kB
view details)
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
kernel_craft-0.1.0-py3-none-any.whl
(116.3 kB
view details)
File details
Details for the file kernel_craft-0.1.0.tar.gz.
File metadata
- Download URL: kernel_craft-0.1.0.tar.gz
- Upload date:
- Size: 117.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb380d7b361f30ae261fd6ff6501ef0def80d9490256838e94cf780b46638ccd
|
|
| MD5 |
a01a1ec8fd33facd8add3ef1af7c0c74
|
|
| BLAKE2b-256 |
55759c3f498be8be492253501b25ad7e5e41c957cd26563616937f62dbccb986
|
File details
Details for the file kernel_craft-0.1.0-py3-none-any.whl.
File metadata
- Download URL: kernel_craft-0.1.0-py3-none-any.whl
- Upload date:
- Size: 116.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac1ce95853d59bfab016b6f601217dddc57a9e34f374a9bf3ea4d82f3cbb2044
|
|
| MD5 |
06aa3e4ec7811619e59bb2a6d5074c22
|
|
| BLAKE2b-256 |
1cd62e0b97e41029e54329f98431a3975a5784ba01d9256a03895f070a7c5b05
|