6.2.5 · D3 · HinglishGPU Architecture

Worked examplesWarps and warp scheduling

4,290 words20 min read↑ Read in English

6.2.5 · D3 · Hardware › GPU Architecture › Warps and warp scheduling

Ye parent topic ka "roll up your sleeves" wala page hai. Hum yahan theory dobara nahi padhayenge — instead hum har tarah ki situation ko dhundhte hain jo parent note mein ho sakti hai, aur har ek ko number tak le jaate hain. Agar koi term unfamiliar lage, parent note mein uski neenv rakhi gayi hai; yahan hum usse use karte hain.

Kuch bhi start karne se pehle, teen numbers ka ek plain-language recap — kyunki neeche ka har example inhi se bana hai:

Recall Teen quantities jo har example mein kaam aati hain
  • Warp size ::: 32 threads (NVIDIA hardware par fixed). Ek warp 32 threads ka ek bundle hota hai jo ek instruction fetch share karte hain.
  • Linear thread index ::: ek 3D (x,y,z) thread coordinate ko ek single counting number mein flatten karo, x sabse fast chalega.
  • Warp ID ::: woh linear index 32 se divide karke, neeche ki taraf round karo. Toh threads 0–31 → warp 0, 32–63 → warp 1, aur aise hi aage.

Scenario matrix

Is table ko ek checklist ki tarah socho. Har cell ek class of problem hai. Neeche, har worked example par un cell(s) ki stamp hai jo woh clear karta hai. Aakhir mein, koi bhi cell chhuti nahi — exam mein koi aisa warp scenario nahi milega jise humne skip kiya ho.

# Case class Isme kya tricky hai Covered by
A Clean 1D block, multiple of 32 "No waste" baseline Ex 1
B Block not a multiple of 32 Tail mein partial (wasted) warp Ex 2
C 2D block, row-major flatten Warps rows ko kaat ke jaate hain Ex 3
C2 True 3D block, non-unit depth term actually fire karta hai Ex 3b
D Degenerate: block 32 se chhota Ek warp, mostly idle lanes Ex 4
E Latency hiding — enough warps? warps chahiye Ex 5
F Limiting case: loads ke beech zero compute Koi hiding possible nahi — memory bound Ex 6
G Warp divergence, dono branches li gayi Serialized paths, slowdown factor Ex 7
H Divergence edge: sabhi threads same branch Zero penalty (real divergence nahi) Ex 8
I Real-world word problem Waste bachane ke liye block dims chunna Ex 9
J Exam twist: occupancy vs. warps-needed Hardware cap ideal number ko beat karta hai Ex 10

Group 1 — Threads kahan jaate hain? (cells A, B, C, C2, D)

Charon ke peeche ek hi formula:

Recall Total threads vs. total warps — rounding rule precisely samjho

Maano total thread count hai. Do baatein kabhi confuse mat karna:

  • Sabse bada warp ID hai (aakhri linear index ka floor, jo ki hai kyunki indices 0 se count hote hain). Warp IDs chalte hain .
  • Warps ki sankhya isliye hai , aur yeh (total ka ceiling) ke barabar hai.

Ye dono kyun agree karte hain? Likho , jahan 32 ke complete groups ki whole number hai aur remainder hai (). Do cases:

  • Agar : block 32 ka exact multiple hai. Aakhri index hai , toh , jisse milte hain warps. Aur . Same.
  • Agar : aakhri index hai jahan , toh , jisse milte hain warps. Aur (fraction ko upar round karo). Same.

Toh dono cases mein dono sides identical value par aate hain — yahi wajah hai ki "aakhri index ko floor karo, phir ek add karo" (jo top warp ka ID batata hai) "total ko ceil karo" (jo batata hai kitne warps hain) ke barabar hota hai.

Ek-line takeaway ::: har positive integer ke liye, kyunki split karne par dono sides (agar ) ya (agar ) ke barabar hoti hain.

Example 1 — Cell A: clean 1D block

Example 2 — Cell B: 32 ka multiple nahi

Example 3 — Cell C: 2D block, warps rows ko kaat ke jaate hain

Example 3b — Cell C2: ek sachi 3D block (depth actually matters)

Example 4 — Cell D (degenerate): block ek warp se chhota


Group 2 — Kya scheduler busy rehega? (cells E, F, J)

Parent ka latency-hiding count yaad karo. Plain words mein: jab ek warp cycles memory ke liye wait karta hai, scheduler doosre warps chalata hai. Agar ek warp memory requests ke beech useful instructions karta hai, toh itne warps chahiye ki "baaki sab ka kaam" wait ko fill kare.

Example 5 — Cell E: latency hide karne ke liye kaafi warps

Example 6 — Cell F (limiting case): loads ke beech zero compute

Example 10 — Cell J (exam twist): ideal warps vs. hardware cap

Pehle, woh scheduler-level formula jo yeh example use karta hai. Parent note count per scheduler chalata hai, toh use karne se pehle uske symbols name karna zaroori hai:


Group 3 — Divergence cost (cells G, H)

Jab ek warp ke threads mein disagree ho ki kaun sa branch lena hai, warp dono branches ek ke baad ek chalata hai, har baar un lanes ko mask kar ke jo participate nahi karni chahiye. Pattern-level tricks ke liye dekho Branch-Divergence-Patterns.

Example 7 — Cell G: dono branches populated

Example 8 — Cell H (edge case): sab threads agree karte hain


Group 4 — Word problem (cell I)

Example 9 — Cell I: image kernel ke liye block dims chunna


Recall Quick self-test

Ek (72,1,1) block: kitne warps aur kitne wasted lanes? ::: warps; tail warp mein active hain → 24 wasted lanes. Ek (8,4,3) block: kitne warps? ::: warps (ek per z-slice, kyunki har slice exactly 32 threads hai). , : hide karne ke liye kitne warps chahiye? ::: warps. 16 lanes if leti hain (cost 40), 16 else (cost 40): slowdown? ::: .