A collection of high-performance CUDA kernels for parallel computing tasks. I'm writing these as I learn CUDA.
| kernel | time | reference impl. |
|---|---|---|
| vector add | 0.017 ± 0.001 ms | 0.016 ± 0.001 ms |
Measured on my RTX 3090 discrete GPU. Size of arrays found in tests (./src/tests), also same sizes between my kernels
and the PyTorch/Triton ones.
1. Clone the repository:
git clone https://github.com/stefanasandei/cuda-kernels.git --recursive
cd cuda-kernelsIf you forgot the --recursive flag, run this to fetch submodules:
git submodule update --init --recursive2. Create build directory:
mkdir build && cd build3. Configure with CMake:
cmake ..4. Build the project:
make -j$(nproc)Afterwards you can run the tests:
./tests/testscuda-kernels/
├── CMakeLists.txt # Root build configuration
├── lib/
│ ├── CMakeLists.txt # Library build config
│ ├── common/ # Common utility files
│ └── googletest/ # Google Test framework
├── src/
│ ├── CMakeLists.txt # Source build config
│ └── example_kernel/
│ └── example_kernel.cu # kernel implementation
└── tests/
├── CMakeLists.txt # Test build configuration
└── example_kernel.cpp # tests for the kernel
- Create a new directory in
src/for your kernel - Implement the kernel in a
.cufile - Add the host wrapper function declaration in the
./src/kernels.hfile - Add unit tests in
tests/, a cpp file that calls the host wrapper
The vector_add kernel is the simplest one, as an example for the implementation.
MIT © Asandei Stefan-Alexandru. All rights reserved.