CUDA, PyTorch, and Triton implementations for selected LeetGPU exercises.
Each exercise directory owns its implementations and metadata:
src_cuda.cu: CUDA implementations.cuda_registry.cuh: implementation names, test cases, benchmark axes.test_cuda.cu: GoogleTest correctness tests.benchmark_cuda.cu: NVBench benchmarks.src_python.py/src_triton.py: Python framework implementations when available.
- CUDA Toolkit 12.8+ or 13.x.
- CMake 3.30+.
- A C++17 host compiler supported by CUDA.
- Python 3.12+ and uv.
This repo is tested on WSL2 Ubuntu 24.04 with a GeForce RTX 3070 Laptop GPU and CUDA 13.0.
uv sync
make build
make test
make py-testRelease benchmarks:
make build-release
make benchRun a single benchmark implementation with NVBench axes:
./build/001e_vector_addition_benchmark --axis "implementation=basic" --axis "N=1048576"
./build/001m_reduction_benchmark --axis "implementation=cub" --axis "N=16777216"
./build/002e_matrix_multiplication_benchmark --axis "implementation=smem_2d" --axis "case=square_512"CMake presets are also available:
cmake --preset linux-debug
cmake --build --preset linux-debug
ctest --preset linux-debugInstall CUDA Toolkit, Visual Studio 2022 with C++ build tools, CMake, and Python 3.12. From a Developer PowerShell:
cmake --preset windows-vs-debug
cmake --build --preset windows-vs-debug
ctest --preset windows-vs-debugOpen build/windows-vs/LeetGPU.sln to debug individual *_test or
*_benchmark targets.
You can also open this repository directly from Visual Studio:
- Use
File -> Open -> Folder...and selectD:\Projects\LeetGPU. - Select the
windows-vs-debugCMake preset. - Wait for CMake configure to finish.
- Open
View -> Other Windows -> CMake Targets View. - Right-click a target such as
002e_matrix_multiplication_testand chooseDebug.
Benchmark targets accept NVBench arguments in the Visual Studio project debug settings. Examples:
--profile --axis implementation=basic --axis N=1048576
--profile --axis implementation=cub --axis N=16777216
--profile --axis implementation=smem_2d --axis case=square_512
Common Visual Studio issues:
-
If CUDA is not detected, confirm the Windows CUDA Toolkit is installed and integrated with Visual Studio, then retry from a Developer PowerShell.
-
If the
windows-vs-debugpreset is missing, open the folder that containsCMakePresets.json, not thebuild/directory. -
If architecture detection fails, configure manually with an explicit value, for example
-DCMAKE_CUDA_ARCHITECTURES=86for an RTX 3070 or90for H100. -
Triton is only a Linux dependency in this project. Windows Visual Studio is intended for the C++/CUDA tests and benchmarks.
-
NVBench and GTest are fetched by CMake on first configure, so the first Visual Studio configure can take a while and requires network access.
-
If CTest reports a target such as
002e_matrix_multiplication_test_NOT_BUILT, that test executable was not built or its GoogleTest discovery step did not run. Build the target explicitly, then rerun CTest:cmake --build --preset windows-vs-debug --target 002e_matrix_multiplication_test ctest --preset windows-vs-debug
If the explicit build fails, fix the first compile or link error in that build output. If the explicit build succeeds but CTest still reports
NOT_BUILT, remove the stale Visual Studio build directory and configure again:Remove-Item -Recurse -Force build\windows-vs cmake --preset windows-vs-debug cmake --build --preset windows-vs-debug ctest --preset windows-vs-debug
uv sync
uv run pytest -rs
uv run ruff check .The default Python tests cover PyTorch and Triton. The PyTorch C++/CUDA extension path is optional because it invokes just-in-time compilation:
LEETGPU_TEST_TORCH_EXTENSION=1 uv run pytest 001e-vector-addition -rsLast validated in WSL2 with CUDA 13.0:
make clean && make build
ctest --test-dir build --output-on-failure
make py-test
uv run ruff check .
uv run ruff format --check .The CUDA suite currently discovers 136 tests across vector addition, reduction, and matrix multiplication.
Generated .ncu-rep files are ignored by git. Example:
mkdir -p out/profiles
ncu --set=full \
-f \
--kernel-name-base demangled \
--kernel-name 'regex:vector_add' \
-o out/profiles/vector_add \
./build/001e_vector_addition_benchmark \
--profile \
--axis "implementation=basic" \
--axis "N=67108864"Open the report in Nsight Compute GUI on Windows, or inspect it with:
ncu -i out/profiles/vector_add.ncu-rep