LLM System Design Interview, issue 43, May 6, 2026

The Kernel Masking Trick

Senior AI Systems Engineer interview at OpenAI, and the interviewer asks:

To handle a few edge cases in your custom loss function, you add a basic if/else statement inside your CUDA kernel. Suddenly, your execution time doubles. What just happened?

Don’t say: The GPU’s branch predictor missed, causing pipeline stalls. We should try to handle the edge cases in PyTorch before passing the tensor to the kernel, or rewrite the logic to be simpler.

How innocent control flow silently burns precious compute cycles, and why running math on unused code paths is the elite secret to maximizing GPU throughput.

The full answer, with the mechanism and the arithmetic, is for paid subscribers on Substack.

Read it on Substack

Get the next one

Free on Substack. Unsubscribe in one click.