r/learnmachinelearning • • Oct 27 '26

Tutorial How I would get started with CUDA

Post image

I started learning CUDA a while back to work on inference and understand FlashAttention. I read a lot of blogs on various topics, but the order was always confusing, so I wrote up the order that I'd pick if I started over.

What it covers:
- H100 architecture
- CUDA software mental model
- Getting started with Matrix Multiplication and building up to a very optimized solution
- Understanding how all of these add to optimization constraints
- An introduction to reading and understanding PTX(the compiler code)

It's meant to be a starter overview that will get you confident enough to read deeper, niche resources. I'd appreciate any feedback or corrections. Cheers!

Link to blog

183 Upvotes

15 comments sorted by

3

u/kbr89 29d ago

Starting from the hardware is the right call, the later rules make a lot more sense that way. One correction since you asked for them: an H100 SM has 128 FP32 CUDA cores, so 32 per quadrant, not 256 (132 SMs x 128 = 16,896 on the SXM5). And one note for anyone following along without an H100: TMA only arrived with Hopper and wgmma is Hopper-specific (sm_90a), so on an RTX 30 or 40 card the ceiling to practise on is cp.async double buffering plus warp-level mma.sync. That still covers most of the matmul build-up, and you can rent an H100 by the hour for the last step.

1

u/readitonly 29d ago

Thanks for pointing that out

1

u/blazing_cannon Oct 27 '26

great. how long did it take to learn all these?

4

u/readitonly Oct 27 '26 edited Oct 27 '26

took around 3-4 months on and off. I had to visit some topics multiple times after a long break. I started with solving questions first (in leetgpu.com), took more than a month to build a good enough mental model to continue studying further.

1

u/TechMelchior Oct 27 '26

Seems interesting I'll read it today !

1

u/[deleted] Oct 27 '26

[removed] β€” view removed comment

1

u/readitonly Oct 27 '26

yes, do start with CUDA. For me, it felt like using an entirely new part of my brain. It was painful then super fun

5

u/Honest_Structure_291 Oct 27 '26

My cuda Journey stopped After

model = model.to(device)
x = x.to(device)
output = model(x)

πŸ˜‚

2

u/Will-Waste-63 Oct 27 '26

Dont forget about, torch.cuda.is_available(), and device = torch.device("cuda") the most important one.

1

u/Honest_Structure_291 Oct 27 '26

Ah thatβ€˜s the reason I always get

NameError: name 'device' is not defined

And I thought my gpu was broken

5

u/[deleted] Oct 27 '26

[removed] β€” view removed comment

2

u/readitonly Oct 27 '26 edited Oct 27 '26

i agree, thanks for pointing that out!! I have highlighted how and where to use profiling and also the roofline model. any other feedback is welcome. I can edit those in πŸ™Œ