6.2.15 · D3 · HinglishGPU Architecture

Worked examplesROCm - OpenCL alternatives

3,703 words17 min read↑ Read in English

6.2.15 · D3 · Hardware › GPU Architecture › ROCm - OpenCL alternatives

Yeh page ek drill hai. Parent topic ne tumhe bataya tha kya hai work-item model aur HIP porting. Yahan hum unhe har case class se guzarte hain — clean divisions, ragged leftovers, degenerate 1-element launches, 2D aur 3D grids, aur woh exam-twist jahan naive formula galat answer deta hai.

Shuru karne se pehle, ek promise: har symbol kamaya hua hai. Agar tumne kabhi get_global_id, "work-group", ya index formula nahi dekha, to pehle do callouts padho — woh poori vocabulary ek single picture se build karte hain.


Scenario matrix

Har launch jo tum ever configure karoge woh in cells mein se kisi ek mein aata hai. Neeche ke examples har ek ko kam se kam ek baar cover karte hain.

# Case class Kya special hai Example
A Clean 1D divide , ka exact multiple hai Ex 1
B Ragged 1D divide , ko divide nahi karta — padding + guard chahiye Ex 2
C Degenerate input (single element) ya empty Ex 3
D 2D NDRange rows × columns par index math Ex 4
E 3D NDRange volume, poora formula Ex 5
F Vendor mapping same code, AMD wavefront 64 vs NVIDIA warp 32 Ex 6
G Real-world word problem image blur, launch config choose karo Ex 7
H Exam twist naive G/L answer galat hai; ceiling division chahiye Ex 8

Worked examples

Throughout, hum kernel code ke andar do short names use karte hain: i us worker ka global id hai (yani int i = get_global_id(0);) aur n real data elements ki sankhya hai (yani n = G_data, sahi array length, kisi bhi padding se pehle). Output array C hai (upar defined).


Recall drill

Recall Kaunsa formula (group_id, local_id) ko wapas global_id mein convert karta hai?

global_id = group_id × local_size + local_id ::: saare full squads skip karo, phir apne local seat se andar jaao.

Recall Work-group count compute karte waqt tum UP kyun round karte ho?

Kyunki neeche round karne se real elements ka leftover partial squad uncomputed reh jaata — silent data loss. ::: (G + L - 1) / L use karo aur if (i < n) se guard karo.

Recall AMD vs NVIDIA par, same source compile kyun hota hai lekin tum local_size phir bhi change karte ho?

HIP/OpenCL ISA hide karta hai, lekin tum ko physical batch width (wavefront 64 / warp 32) se match karte ho taaki koi lane idle na baithe. ::: Dono taraf same total lanes.

Ceiling-division bug in a launch config
G/L (floor) launch karna instead of ceil(G/L) final partial group drop kar deta hai — hamesha round up karo.
Padding workers ko silence kiya jaana chahiye
if (get_global_id(0) < n) guard se taaki out-of-bounds lanes kuch na karein.