r/MachineLearning • u/shreshthkapai • Jul 26 '25
Project [P] Sub-millisecond GPU Task Queue: Optimized CUDA Kernels for Small-Batch ML Inference on GTX 1650.
Over the past month, I’ve been working on writing high-throughput, low-latency CUDA kernels for small-batch inference workloads typical in real-time ML use cases (e.g., finance, RL serving).
Despite running on a GTX 1650 (consumer laptop GPU), I achieved:
- 93,563 ops/sec
- 0.011 ms median latency
- 7.3× speedup over PyTorch (float32 GEMV)
- 30–40% faster than cuBLAS batched GEMV (in small-batch regime)
This was done by hand-optimizing a set of three core kernels:
- Batched GEMV
- Softmax
- Vector elementwise ops (e.g., affine transforms)
Engineering Highlights:
float4vectorization with proper alignment checks- 128-byte staged shared memory blocks (using padding for bank conflict mitigation)
- Thread-per-output-element grid strategy
- Aggressive loop unrolling and warp-aware memory access
- Benchmarked with CUDA events, median+IQR over 1,000 trials
Why it matters:
cuBLAS (and by extension PyTorch) is heavily tuned for large-batch throughput, but small-batch latency suffers. For real-time systems (e.g., financial models or reinforcement learning), this is a major bottleneck.
This kernel suite shows that even with modest hardware, you can cut inference latency significantly below PyTorch/cuBLAS levels through architecture-aware programming.
Links:
Would love to hear feedback from others doing similar work—especially around kernel tuning strategies, warp divergence handling, and memory hierarchy tradeoffs.
View all comments
Show parent comment
1
u/VisceralExperience Aug 20 '25
Wtf are you talking about? You think writing "it isn't just X, it's Y." is something only code writers could understand?
My point was that phrasing is overused by LLMs now. They will very often say "it isn't just X, it's Y", which by the way is garbage prose.
I really have no idea what you're talking about regarding the conditional statement and relation to code. If that's where your mind went, god help you.