Worked examples — Streaming multiprocessors (SM)
6.2.2 · D3· Hardware › GPU Architecture › Streaming multiprocessors (SM)
Ye page Streaming multiprocessors (SM) ki "har case grind karo" companion hai. Parent note ne tumhe formulas diye; yahan hum unhe har tarah ke input se torture karte hain: normal numbers, zero, degenerate limits, ek word problem, aur ek exam trap. Pehle scenario matrix padho, phir har solution se pehle guess karo.
Kisi bhi symbol se pehle, yahan sirf wahi quantities hain jo hum is page par use karte hain. Har ek ek plain count hai jo tum haath se bhi ginn sakte ho.
Scenario matrix
Har SM sizing question in cells mein se ek mein aata hai. Neeche ke examples [Cell N] label kiye hain taaki tum dekh sako ki poora space cover kiya gaya hai.
| Cell | Case class | Limiting resource | Chhupa hua trap |
|---|---|---|---|
| 1 | Register-bound, clean divide | Registers per thread | koi nahi — warm-up |
| 2 | Register-bound, non-integer divide | Registers (floor kick karta hai) | tumhe neeche round karna hai, slots waste hote hain |
| 3 | Shared-memory-bound | KB of Shared-memory per block | shared mem, registers nahi, cap hai |
| 4 | Warp-count-ceiling-bound | Max warps/SM (64) | resources plenty hain — hardware cap lagata hai |
| 5 | Zero / degenerate input | occupancy | ek block jo fit hi nahi ho sakta |
| 6 | Limiting behaviour | latency vs. warps () | ek point ke baad zyada warps help karna band kar dete hain |
| 7 | Word problem (real workload) | blocks across SMs | blocks ki "leftover wave" |
| 8 | Exam twist | [[Warp-scheduling | divergence]] + occupancy interact karte hain |
Neeche ki single figure woh mental model hai jo har cell share karta hai: SM ek bucket hai jiske kaafi lids hain, aur sabse neechi lid water level set karti hai. Yeh picture dimag mein rakho — har worked example mein hum har lid ki height compute karte hain aur sabse neechi padhte hain.

Floor kyun aur min kyun? Floor (⌊ ⌋) isliye hai kyunki partially-resident block bekar hai — ya to poora fit hota hai ya nahi. min isliye hai kyunki har ceiling upar ki figure mein bucket ki ek lid hai: tum usi lid se block hote ho jo sabse neechi hai, yani jo resource pehle khatam hoti hai. Chawthi lid, , ek alag hardware limit hai: registers aur warp slots spare mein hone ke bawajood, ek SM se zyada blocks ek saath host karne se mana kar deta hai.
Example 1 — Register-bound, clean divide [Cell 1]
Forecast: Abhi guess karo — kya yeh SM full hai, half hai, ya starved hai?
- Registers per block . Yeh step kyun? Ek block ko apne saare threads ke liye ek saath registers reserve karne padte hain; wahi reservation pool ke liye compete karti hai.
- Register-limited blocks . (Yeh s01 figure mein register lid hai.) Yeh step kyun? Har block ko 8192 registers chahiye; 65536 ka pool evenly divide hota hai, toh 8 blocks fit hote hain kuch leftover nahi.
- Warp-ceiling blocks . (Warp lid.) Yeh step kyun? Independently, hardware resident warps ko 64 par cap karta hai; har block warps hai, toh us rule se bhi zyada se zyada 8 blocks.
- Blocks/SM . Active warps . Yeh step kyun? Dono lids 8 par hain — paani 8 tak uthta hai, koi waste nahi. Blocks ko warps-per-block se multiply karo resident warps count karne ke liye.
- Occupancy .
Verify: 64 active warps exactly hai, aur 8 blocks × 256 = 2048 threads = SM ka max. Do independent ceilings ka 100% par agree karna sanity check hai.
Example 2 — Register-bound, non-integer divide [Cell 2]
Forecast: Pool same hai; har thread 4× zyada registers leta hai. Kya occupancy exactly 25% tak girti hai, ya rounding use aur bura banata hai?
- Registers per block . Yeh step kyun? Same reservation logic — zyada registers per thread block ki demand multiply karta hai.
- Register-limited blocks . Yeh step kyun? yahan exactly hai, toh floor kuch nahi badalta — lekin hamesha apply karo.
- Active warps .
- Occupancy .
Rounding trap (yeh Cell 2 kyun hai): ab 130 registers/thread kar do. Registers/block , aur . Thodi si badhot tumhe 2 blocks se 1 block par gira deti hai → 8 warps → . Sirf 2 extra registers par aadhi occupancy gaayab ho gayi, kyunki floor ne fractional block phek diya — register lid 2 se thodi neeche aa gayi.
Verify: ✓ (fits), lekin ✗ (nahi fits), confirming karta hai ki doosra case sirf 1 block host kar sakta hai.
Example 3 — Shared-memory-bound [Cell 3]
Forecast: Registers kehte hain "tons of blocks fit honge." Kya registers jeetenge, ya shared memory tumhe clamp karega?
- Register-limited blocks . Yeh step kyun? Register lid establish karo taaki hum prove kar sakein ki yeh binding wali nahi hai.
- Shared-memory-limited blocks . Yeh step kyun? Pehle bytes mein convert karo honest unit consistency ke liye: bytes aur bytes. Phir bytes ÷ bytes/block = blocks (KB bhi cancel ho jaata, lekin convert karne se koi doubt nahi rehta). 96 KB mein sirf do 48-KB chunks fit hote hain. Yeh shared-memory lid hai.
- Warp-ceiling blocks .
- Blocks/SM . Active warps . Yeh step kyun? Shared memory s01 figure mein sabse neechi lid hai — wahi decide karti hai, chahe registers 128 blocks host kar sakti.
- Occupancy .
Verify: ✓ fits; teesre block ko chahiye honge ✗. Shared memory, registers nahi, ceiling confirmed hai — is cell ka poora point yahi hai.
Example 4 — Warp-ceiling-bound [Cell 4]
Forecast: Sab kuch sasta hai. Toh occupancy 100% hai… right?
- Register-limited blocks . Yeh step kyun? Pehle register lid compute karo taaki hum prove kar sakein registers is kernel ko limit nahi kar rahe — har block ko sirf 1024 registers chahiye, toh 64 blocks register-wise fit honge.
- Warp-ceiling blocks . Yeh step kyun? Har block sirf warps hai, toh 64-warp ceiling 32 blocks allow karta hai — registers se kam. Warp lid register lid se neeche baith jaati hai.
- Blocks/SM . Active warps . Yeh step kyun? Sabse neechi lid lo (32, warp ceiling), phir resident blocks ko warps-per-block se multiply karo () count karne ke liye ki SM par actually kitne warps rehte hain.
- Occupancy . Yeh step kyun? Active warps ko se divide karo; yahan warp ceiling aur occupancy definition dono 64 share karte hain, toh ek warp-bound kernel phir bhi 100% reach karta hai.
Subtle point: tumne 100% reach kiya, lekin tum warp/block ceilings se pinned ho, resources se nahi. Agar SM resident blocks ko par bhi cap karta, toh tumhe warps milte despite mountains of free registers. Chhote blocks warp budget ko block-count lid ke through waste kar sakte hain.
Verify: warps ✓, aur registers ✓ (registers spare mein hain, confirm karta hai ki woh limit nahi hain). ke saath min hoga blocks → 32 warps → 50%.
Example 5 — Zero / degenerate input [Cell 5]
Forecast: Guess karo ki occupancy small-but-positive hai, ya literally zero.
- Registers per block . Yeh step kyun? Demand exactly compute karo jaise hamesha — extreme inputs ke liye koi shortcut nahi.
- Register-limited blocks . Yeh step kyun? Block ko pure SM se zyada registers chahiye. 0.5 ka floor 0 hai — tum aadha block host nahi kar sakte. Register lid bucket ke floor tak aa gayi.
- Blocks/SM . Active warps . Yeh step kyun? Jis bhi min mein 0 ho woh 0 hai; zero resident blocks ke saath zero resident warps hain.
- Occupancy — ek launch failure (
too many resources requested), degenerate case.
Yeh kyun matter karta hai: occupancy 0 ek real, catchable outcome hai, abstraction nahi. Fix wahi hai jo hamesha hai: registers per thread kam karo, ya block chhota karo taaki ho.
Verify: 256 regs/thread par sabse bada block jo fit hoga woh satisfy karta hai . Toh 512 threads edge ke bahar hai → 0 blocks. Boundary confirmed.
Example 6 — Limiting behaviour: warps vs. latency [Cell 6]
Forecast: Kya throughput hamesha badhta rehta hai, ya flatten ho jaata hai?
Key ratio yeh hai ki kitne independent warps chahiye pipeline ko 300-cycle stall ke dauran busy rakhne ke liye. Jab ek warp wait karta hai, scheduler doosre chalata hai.
- Warps needed to fully hide the stall latency in cycles (ek warp per cycle issue karna waiting ke ek cycle ko cover karta hai). Yeh step kyun? Har cycle tum ek warp dete ho; 300 cycles mein kabhi idle na ho iske liye ~300 ready warps chahiye.
- Efficiency model — useful fraction of a cycle jo actually fill hoti hai. Yeh step kyun? 300 warps se neeche tum 300 cycles mein se cover karte ho; 300 se upar tum already har cycle fill karte ho.
- Limiting behaviour: ke liye, (saturated). Extra warps kuch nahi add karte — yeh plateau hai. Yeh step kyun? Jab har cycle busy ho, zyada warps ek cycle ko "ek se zyada full" nahi bana sakte.
- Reality check for one SM: , toh ek scheduler wala ek single SM reach karta hai — yeh akele 300-cycle stall fully hide nahi kar sakta. Multiple schedulers per SM (typically 4) aur chhote average stalls gap ko close karte hain.

Verify: par: . par: . par: phir bhi (plateau). Curve ek rising line hai jo par flatten ho jaati hai.
Example 7 — Word problem: ek real launch across the GPU [Cell 7]
Forecast: Blocks (40) se zyada SMs (80) hain — guess karo GPU over- ya under-utilised hai.
Pehle, ek symbol jis ki humein ab zaroorat hai. Floor (round down) ke saath, hum iska mirror use karte hain:
- Total block-slots jo GPU ek saath offer karta hai slots. Yeh step kyun? Yeh GPU ki combined capacity hai ek wave ke liye; hum apne 40 blocks ko iske against compare karte hain dekhne ke liye ki kya sab ek saath fit hote hain.
- SMs jo block receive karte hain . Yeh step kyun? Grid distribution unit har block ko ek SM ko deta hai, pehle ek block per SM; sirf 40 blocks ke saath, sirf 40 SMs light up karte hain.
- Idle SMs — GPU ka aadha hissa is launch mein idle baitha hai. Yeh step kyun? Blocks distribution ki unit hain; bahut kam blocks SMs ko starve karte hain chahe har block ki occupancy kitni bhi achi ho.
- Waves wave. Yeh step kyun? "Wave" ek round of concurrently resident blocks hai. Saare 40 blocks 640 available slots mein fit ho jaate hain, toh ek single wave poori grid clear kar deti hai — aur ceiling fraction 0.0625 ko 1 whole wave mein turn kar deta hai.
Lesson: Example 1 mein occupancy per SM 100% thi, phir bhi whole-GPU utilisation yahan sirf hai kyunki grid bahut chhota tha. Bahut zyada blocks launch karo SMs se.
Corner case — ek badi grid jise multiple waves chahiye: same kernel ko 2000 blocks ke saath relaunch karo. Ab block-slots (640) exceed ho jaate hain, toh waves waves. Pehli 3 waves mein se har ek saare 640 slots fill karti hai ( blocks); 4th wave mein sirf blocks hain, sirf SMs light up karte hain jabki doosre 70 us final wave ke dauran idle rehte hain. Full waves efficient hain; ragged tail wave SMs waste karta hai — ek wajah grids is size ki karo ki tail chhoti ya absent ho.
Verify (small grid): total threads ; idle SM fraction ; ek wave kyunki block-slots. Verify (big grid): waves, tail mein blocks hain, SMs use ho rahe hain. ✓
Example 8 — Exam twist: divergence tumhari occupancy win kha jaata hai [Cell 8]
Forecast: Occupancy equal hai — toh zaroor tie honge?
- Kernel X cost: har instruction warp par ek baar chalta hai, saare 32 lanes active. Baseline kaam. Yeh step kyun? Koi divergence nahi matlab ek pass saare 32 threads ko ek saath cover karta hai — ideal case.
- Kernel Y, pehla path: warp
ifbranch sirf 16 lanes active (threads 0–15) ke saath execute karta hai, doosre 16 lanes masked off aur idle hain. Yeh step kyun? Ek warp mein threads ek instruction pointer share karte hain (parent note ka SIMT rule), toh doosra branch lene wale lanes wait karte hain — woh same cycle mein alag instruction nahi chala sakte. - Kernel Y, doosra path: warp phir
elsebranch execute karta hai threads 16–31 active ke saath aur threads 0–15 masked off. Yeh step kyun? Do branches overlap nahi kar sakti; hardware unhe branched region ke upar do passes mein serialize karta hai. - Slowdown factor branched region ke liye : region do baar traverse hoti hai, aur har pass mein aadhe lanes kuch useful nahi karte. Yeh step kyun? Code par do serial passes jo ek non-divergent warp ek pass mein cover karta, exactly double instruction issues hai.
- Conclusion: Kernel X pehle khatam hota hai. Kernel Y divergent region par ~2× slower hai despite identical 100% occupancy.
Trap: occupancy measure karta hai kitne warps resident hain, na ki har warp ke lanes kitni efficiently use ho rahe hain. High occupancy + high divergence lower occupancy + no divergence se haar sakta hai.
Verify: Y ki lane-utilisation branch mein , yaani 50% issued lane-slots useful hain → runtime ratio . Dono ki occupancy . ✓
Recall Self-check: kaun si ceiling bind karti hai?
Kernel: 100 regs/thread, 256 threads/block, 32 KB shared/block. SM: 65536 regs, 64 KB shared, . Kaun sa resource occupancy limit karta hai? ::: Registers: ; shared ; warps . Min hai 2 (registers aur shared memory ke beech tie) → 16 warps → 25%. Do kernels equal occupancy par alag speeds par kyun chal sakte hain? ::: Occupancy resident warps count karta hai, lane efficiency nahi; warp divergence lanes idle karta hai occupancy change kiye bina. Example 7 mein, GPU sirf 50% utilised kyun hai despite 100% per-SM occupancy? ::: Bahut kam blocks (40) SMs ki sankhya (80) ke liye; blocks distribution ki unit hain, toh 40 SMs idle rehte hain.
See also: CUDA-cores · Tensor-cores · Hinglish version