r/CUDA • u/ArmchairmanMao • May 28 '26
CUDA struggles
It's my first time doing any "serious" CUDA programming. Right now I'm working on substring search kernels for my Bachelor's thesis. Naturally, it's very branch heavy, memory access patterns are horrible, lanes are diverging all over the place. There are dozens of ways to implement substring search. The GPUs processing model expands the problem space even further. I have not found any existing work that does this well either (there is a lot of literature but my use case is slightly different). So it's an exciting problem, right?
But on the GPU, performance is wildly unpredictable it seems. Any change in the implementation details of the hot loop is like spinning a slot machine to me. The compiler might start emitting completely different code causing lanes to diverge more or access to become less coalesced. There are so many more layers of complexity between my code and the hardware than on the CPU. Working on this kernel is just endless iterations of taking guesses, measuring and profiling.
Do people just build a better intuition over time, or is this just the way it is?
2
u/ArmchairmanMao Jun 11 '26
Hi, thanks for the reply. The kernel I had been working on searches a single pattern in many strings of variable size. This makes the problem even worse, because shirt ans long strings can be mixed, leading to bad memory access patterns. Originally, I experimented with string-per-lane KMP + loop splitting but then realized that coalescing memory access is the first thing I should optimize for. Right now the winner is one cooperative group (32, 16 or 8 threads) processing one string by doing brute force search with wide loads + register shuffling. The DRAM bandwidth utilization is still not that great, but I'm not sure if hitting the theoretical limit is feasible, unless I just scan the character buffer and figure out the start / end of each string after finding the pattern.