Solutions to LeetGPU challenges, written in CUDA.
problems/— challenge statements fetched from leetgpu.comsrc/— solutions (CUDA.cu; #41 Simple Inference is PyTorch-only)ROCm/— HIP ports of the solutions (generated withhipify-perl)tests/— local test harnesses built from each spec's examplestools/— fetch / compile-check / remote-run scripts
Every problem has a harness in tests/ that feeds the spec's example inputs to
solve() on your own GPU and checks the output — see
tests/README.md for details.
# AMD GPU (ROCm / hipcc), tests link ROCm/*.hip
tests/run_tests.sh # all problems
GPU_ARCH=gfx1100 tests/run_tests.sh # non-default arch (default gfx1201)
# NVIDIA GPU (CUDA / nvcc), tests link src/*.cu
tests/run_tests_cuda.sh
NVCC_ARCH="-arch=sm_86" tests/run_tests_cuda.sh
# single problem, either runtime
tests/run_tests.sh softmax
tests/run_tests_cuda.sh softmax
# 41 Simple Inference (PyTorch)
python3 tests/test_simple_inference.pyStatus: all 88 GPU tests + the PyTorch test pass on ROCm (RX 9070 XT, gfx1201). These are the small spec examples only — LeetGPU's official judge additionally runs large hidden tests and performance measurement.
| # | Title | Difficulty | Problem | Solution |
|---|---|---|---|---|
| 1 | Vector Addition | easy | spec | src |
| 2 | Matrix Multiplication | easy | spec | src |
| 3 | Matrix Transpose | easy | spec | src |
| 4 | Reduction | medium | spec | src |
| 5 | Softmax | medium | spec | src |
| 6 | Softmax Attention | medium | spec | src |
| 7 | Color Inversion | easy | spec | src |
| 8 | Matrix Addition | easy | spec | src |
| 9 | 1D Convolution | easy | spec | src |
| 10 | 2D Convolution | medium | spec | src |
| 11 | 3D Convolution | medium | spec | src |
| 12 | Multi-Head Attention | hard | spec | src |
| 13 | Histogramming | medium | spec | src |
| 14 | Multi-Agent Simulation | hard | spec | src |
| 15 | Sorting | hard | spec | src |
| 16 | Prefix Sum | medium | spec | src |
| 17 | Dot Product | medium | spec | src |
| 18 | Sparse Matrix-Vector Multiplication | medium | spec | src |
| 19 | Reverse Array | easy | spec | src |
| 20 | K-Means Clustering | hard | spec | src |
| 21 | ReLU | easy | spec | src |
| 22 | General Matrix Multiplication (GEMM) | medium | spec | src |
| 23 | Leaky ReLU | easy | spec | src |
| 24 | Rainbow Table | easy | spec | src |
| 25 | Categorical Cross Entropy Loss | medium | spec | src |
| 27 | Mean Squared Error | medium | spec | src |
| 28 | Gaussian Blur | medium | spec | src |
| 29 | Top K Selection | medium | spec | src |
| 30 | Batched Matrix Multiplication | medium | spec | src |
| 31 | Matrix Copy | easy | spec | src |
| 32 | INT8 Quantized MatMul | medium | spec | src |
| 33 | Ordinary Least Squares | medium | spec | src |
| 34 | Logistic Regression | medium | spec | src |
| 35 | Monte Carlo Integration | medium | spec | src |
| 36 | Radix Sort | hard | spec | src |
| 37 | Matrix Power | medium | spec | src |
| 38 | Nearest Neighbor | medium | spec | src |
| 39 | Fast Fourier Transform | hard | spec | src |
| 40 | Batch Normalization | medium | spec | src |
| 41 | Simple Inference | easy | spec | src |
| 42 | 2D Max Pooling | medium | spec | src |
| 43 | Count Array Element | medium | spec | src |
| 44 | Count 2D Array Element | medium | spec | src |
| 45 | Count 3D Array Element | medium | spec | src |
| 46 | BFS Shortest Path | hard | spec | src |
| 47 | Subarray Sum | medium | spec | src |
| 48 | 2D Subarray Sum | medium | spec | src |
| 49 | 3D Subarray Sum | medium | spec | src |
| 50 | RMS Normalization | medium | spec | src |
| 51 | Max Subarray Sum | medium | spec | src |
| 52 | Sigmoid Linear Unit | easy | spec | src |
| 53 | Causal Self-Attention | hard | spec | src |
| 54 | Swish-Gated Linear Unit | easy | spec | src |
| 55 | Attention with Linear Biases | medium | spec | src |
| 56 | Linear Self-Attention | hard | spec | src |
| 57 | FP16 Batched Matrix Multiplication | medium | spec | src |
| 58 | FP16 Dot Product | medium | spec | src |
| 59 | Sliding Window Self-Attention | hard | spec | src |
| 60 | Top-p Sampling | medium | spec | src |
| 61 | Rotary Positional Embedding | medium | spec | src |
| 62 | Value Clipping | easy | spec | src |
| 63 | Interleave Arrays | easy | spec | src |
| 64 | Weight Dequantization | medium | spec | src |
| 65 | Gaussian Error Gated Linear Unit | easy | spec | src |
| 66 | RGB to Grayscale | easy | spec | src |
| 67 | MoE Top-K Gating | medium | spec | src |
| 68 | Sigmoid Activation | easy | spec | src |
| 69 | 2D Jacobi Stencil | medium | spec | src |
| 70 | Segmented Exclusive Prefix Sum | medium | spec | src |
| 71 | Parallel Merge | medium | spec | src |
| 72 | Stream Compaction | medium | spec | src |
| 73 | All-Pairs Shortest Paths | hard | spec | src |
| 74 | GPT-2 Transformer Block | hard | spec | src |
| 75 | Sparse Matrix-Dense Matrix Multiplication | medium | spec | src |
| 76 | Adder Transformer Inference | medium | spec | src |
| 78 | 2D FFT | medium | spec | src |
| 80 | Grouped Query Attention | medium | spec | src |
| 81 | INT4 Weight-Only Quantized MatMul | medium | spec | src |
| 82 | Linear Recurrence | medium | spec | src |
| 84 | SwiGLU MLP Block | medium | spec | src |
| 85 | LoRA Linear | medium | spec | src |
| 87 | Speculative Decoding Verification | medium | spec | src |
| 90 | Causal Depthwise Conv1d | medium | spec | src |
| 92 | Decaying Causal Attention | medium | spec | src |
| 93 | Llama Transformer Block | hard | spec | src |
| 94 | SSM Selective Scan | medium | spec | src |
| 96 | INT8 KV-Cache Attention | medium | spec | src |
| 105 | Group Normalization | medium | spec | src |
| 106 | Token Embedding Layer | medium | spec | src |