6.5.7 · D3 · HinglishAdvanced & Emerging Architectures

Worked examplesGoogle TPU architecture and systolic arrays

4,150 words19 min read↑ Read in English

6.5.7 · D3 · Hardware › Advanced & Emerging Architectures › Google TPU architecture and systolic arrays

Yeh worked-examples companion hai parent TPU note ka. Wahan humne why aur how build kiya tha ek dataflow systolic array ka. Yahan hum har case class drill karte hain jo tum meet kar sakte ho — tiny multiplies, degenerate shapes, batch limits, quantization edge cases, aur ek exam twist — har ek ground up se kaam karte hue.

Shuru karne se pehle, ek promise contract se: koi bhi symbol tab tak appear nahi hoga jab tak woh define na ho. Agar parent ne use kiya, toh hum use yahan dubara earn karte hain.


Scenario matrix

Is topic ke har question ko tum ek yaa zyada cells mein daal sakte ho. Neeche ke examples unke cell label ke saath hain.

# Case class Kya tricky hai Example
A Plain square multiply "kya wiring sach mein dot product compute karti hai?" sanity check Ex 1
B Non-square / rectangular () array tumhare data ke liye square-shaped nahi Ex 2
C Degenerate: array data se bada ( matrix side) wasted cells, low utilization Ex 3
D Limiting: tiny batch vs huge batch pipeline fill dominate karta hai vs vanish ho jata hai Ex 4
E Throughput / roofline (peak FLOP/s) se scale karta hai, linearly nahi Ex 5
F Memory-traffic saving (arithmetic intensity) reuse factor = Ex 6
G Zero / sign / zero-point quantization mein 8-bit overflow, negatives, dequant offset Ex 7
H Real-world word problem ek layer ko cycles & time mein translate karo Ex 8
I Exam twist: matrix array se bada (tiling) tumhe multiply split karni padegi Ex 9

Chalo har cell ko hit karte hain.


Example 1 — Case A: plain multiply (kya wiring kaam karti hai?)

Forecast: guess karo aage padhne se pehle — kya yeh hai, ya ?

Neeche ki figure ek saath poori picture dikhati hai: steps se pehle ise padho.

Figure — Google TPU architecture and systolic arrays

Figure kaise padhein (annotation walk-through):

  • Char lavender rounded boxes hardware cells hain. Har ek par weight label hai jo woh store karta hai: box ki vertical position row hai (top = , bottom = ), uski horizontal position column hai (left = , right = ).
  • Left par do coral arrows ki rows hain jo cells mein rightward march kar rahi hain — ek activation ek baar read hoti hai aur cell-to-cell pass hoti hai (yahi ek-read-many-uses trick hai).
  • Bottom par do mint arrows partial sums hain jo har column se downward drop kar rahi hain; column se jo number girta hai woh exactly hai. Un do mint labels dekho — wahi jawab hai jo tum abhi derive karne wale ho.

Steps.

  1. Weights load karo. Cell mein store hota hai. Toh cells ka left column (column ) mein (top, row ) aur (bottom, row ) hai. Right column () mein aur hai. (Yeh figure mein char lavender boxes hain.) Yeh step kyun? Output ko chahiye wahan jo matching paas karegi. Column output column ka owner hai.

  2. ki row stream karo, yaani , top mein (top coral arrow) aur yeh across walk karta hai. Column 1 accumulate karta hai: Yeh step kyun? Har cell karta hai . Partial sum neeche travel karta hai (mint arrow), har cell se ek product uthata hua — yahi hai dot product .

  3. Same row column mein: Yeh step kyun? Wahi activation row ek doosre column of cells ke liye reuse hoti hai bina kisi naye memory read ke — yahi woh reuse hai jo column-parallelism deta hai. Yeh second dot product compute karta hai.

  4. ki row stream karo, : Yeh step kyun? ki naya row ek naya row of produce karta hai: weights cells mein stationary rehte hain jabke successive activation rows stream karte hain, toh ek weight-load poore batch ki service karta hai.

Forecast check: correct pehla option. Agar tumne guess kiya toh tumne ki row ko ki row (column nahi) se pair kiya; dot product ke column se neeche chalta hai, toh doosra factor hai jisme vary karta hai, nahi.

Verify: by hand, . Array ne sum in space wire kiya loop in time ki jagah — same answer. ✓


Example 2 — Case B: rectangular multiply ( by )

Forecast: pehle ki shape aur total MAC count guess karo.

Steps.

  1. Shape rule. hai , hai . Shared dimension (woh length jis par hum sum karte hain) match karni chahiye — karti hai. Toh hai . Yeh step kyun? tabhi sense karta hai jab ka column count equals ka row count ().

  2. Outputs count karo. mein entries hain. Yeh step kyun? Har entry ko array mein apna खुद ka accumulator cell chahiye, toh outputs count karna batata hai kitne result cells (aur streamed activations ke columns) computation occupy karti hai.

  3. MACs count karo. Har entry products ka sum hai, toh total MACs . Yeh step kyun? Matmul mein total kaam hamesha MACs hota hai — yahi number array ko hit karta hai.

  4. Array depth needed. Partial-sum direction kam se kam cells deep honi chahiye taaki ek poora dot product accumulate ho sake jab woh neeche flow kare. Ek array ek pass mein handle karta hai. Yahan , toh array ka zyada hissa idle hai — yeh Case C ka foreshadowing hai. Yeh step kyun? Contraction length set karta hai ki partial sum ko kitni dur travel karni hai poori hone ke liye; agar array depth se zyada hoti toh tumhe tile karna padta (Example 9), isliye ko se check karna decide karta hai ki ek pass kaafi hai ya nahi.

Forecast check: hai (square nahi — output se aur se inherit karta hai), aur MAC count hai . Agar tumne ya shape guess ki, toh yaad rakho contraction dimension result se disappear ho jati hai; sirf aur bachte hain.

Verify: MACs; shape mein entries hain; . Consistent. ✓


Example 3 — Case C: array data se bada (utilization)

Forecast: guess karo — kya yeh ke near hai, ke near, ya tiny?

Steps.

  1. Useful cells. Ek multiply zyada se zyada output cells busy rakhti hai (aur depth ). Yeh step kyun? Sirf woh cells jo real own karte hain aur real operands dekhte hain kuch compute karte hain.

  2. Total cells. . Yeh step kyun? Array ek fixed physical grid hai; uska cell count hardware ka constant hai, isliye yeh woh denominator hai jiske against kisi bhi problem ka useful work measure hota hai.

  3. Utilization: Yeh step kyun? Yeh degenerate case hai — array ek fixed-size grid hai; chhote problems unused silicon mein dub jaate hain.

Forecast check: answer tiny hai (), ya ke near nahi. Intuition trap yeh hai ki " fair chunk use karta hai"; actually utilization hai, jo quickly collapse ho jaati hai jab data se bahut chhota ho.

Verify: , yaani . Yahi reason hai ki parent note kehta hai TPUs bade matrices ke liye hain — chhote ops catastrophically wasteful hain. ✓


Example 4 — Case D: batch size ki do limits

Forecast: nearest percent tak guess karo, aur huge ke liye kya approach karta hai.

Steps.

  1. Formula kahan se aata hai. Total cycles . Sirf cycles results emit karte hain; fill overhead hai. Toh . Yeh step kyun? Pehla result tabhi aata hai jab data diagonally sab rows aur columns cross kar le — woh diagonal delay clocks hai.

  2. Limit with : Yeh step kyun? Ek tiny op ek hi result ke liye poora fill cost pay karta hai — worst case. (Yeh parent ka "latency of one small matmul" trap hai.)

  3. Limit : Yeh step kyun? Jaise batch badhta hai, fixed 511-cycle fill negligible ho jaata hai — array full efficiency par run karta hai. TPUs throughput machines hain.

  4. solve karo, yeh dhyan rakhte hue ki puri sankhya hai. Pehle equality set karo: Yeh step kyun? activation rows count karta hai, isliye yeh ek non-negative integer hona chahiye — fractional batch meaningless hai. mein increasing hai, isliye hume sabse chhota integer chahiye jisme ho. Equality boundary exactly integer par land karti hai: check karo (exactly ), jabki . Agar boundary fractional hoti toh hum ceiling lete; yahan yeh already integral hai, toh answer hai.

Forecast check: (buri tarah chhota — ek op poori pipeline fill waste karta hai), aur huge-batch limit exactly hai. Agar tumne ke near guess kiya, tumne underestimate kiya ki fixed -cycle fill ek single streamed row ke relative kitna bada hai.

Verify: ; ; ; aur confirm karta hai ki sabse chhota integer qualify karne wala hai. ✓


Example 5 — Case E: peak throughput ke roop mein scale karta hai

Forecast: TOPS number guess karo, phir guess karo ki double karne par yeh kitna multiply hota hai (×2 ya ×4?).

Steps.

  1. Formula. cells, har ek steady state mein 1 MAC/clock, 2 ops per MAC: Yeh step kyun? cells mein se har ek har clock fire karta hai — parallelism spatial hai, isliye throughput area .

  2. plug karo:

  3. Side double karo, : Yeh step kyun? double karna throughput quadruple karta hai — yeh "CPU ki tarah clock×cores nahi" wali lesson hai.

Forecast check: answer TOPS hai, aur double karna throughput ×4 multiply karta hai, ×2 nahi. Agar tumne ×2 guess kiya toh tum linearly soch rahe the (jaise CPU cores add karna); array area mein grow karta hai, isliye factor squared hai.

Verify: ops/s; ; ratio scaling confirm karta hai. Yeh peak kaise flat "compute-bound" ceiling ban jaati hai dekho Roofline model mein. ✓


Example 6 — Case F: memory-traffic saving (arithmetic intensity)

Forecast: ratio guess karo — kya yeh ×16, ×256, ya ×65536 ke aas paas hai?

Steps.

  1. Naïve reads. Har MAC apne do operands dobara fetch karta hai. MACs ki count , har ek ko 2 reads chahiye: Yeh step kyun? Yeh memory-wall worst case hai — compute sasta hai, data move karna nahi.

  2. Systolic reads. aur mein se har ek ( entries each) ek baar read hota hai:

  3. Ratio: Yeh step kyun? Reuse factor array side ke equal hai: fetch kiya hua har byte cells ki ek poori row/column ko feed karta hai.

  4. Arithmetic intensity (MACs per input read):

Forecast check: ratio ×256 hai (equals ), ×16 ya ×65536 nahi. Agar tumne ×65536 guess kiya toh tumne ise cell count se confuse kiya; reuse factor array side hai, kyunki har input cells ki ek row/column feed karta hai, poori grid ko nahi.

Verify: ; ratio ; AI . ✓


Example 7 — Case G: 8-bit MACs mein zero, sign, zero-point, aur overflow

Forecast: padhne se pehle — ek 8-bit×8-bit product ki sabse badi magnitude guess karo, aur guess karo kyun hume sirf scale ki jagah ek offset (zero-point) chahiye.

Steps.

  1. (a) Zero weight. Agar toh kisi bhi activation ke liye . Cell phir bhi along pass karta hai. Yeh step kyun? Zero hardware mein special nahi hai — yeh kisi bhi number ki tarah flow karta hai; isliye zeros dense array par automatically time save nahi karte.

  2. (b) Most-negative aur most-positive product (sign corners). Extreme positive signed product do negatives se hai: aur sabse negative single product ek negative aur sabse bade positive se: Dono 16 bits mein easily fit ho jaate hain. Yeh step kyun? Sign corner cover karta hai — do negatives sabse bada positive dete hain, mixed signs sabse zyada negative dete hain, toh humne dikhaya ki dono sign quadrants multiplier par overflow ke bina handle hote hain.

  3. (c) Koi accumulator overflow nahi. worst-case products ki magnitude sum karo: Ek signed 32-bit register tak hold karta hai. Kyunki , overflow nahi. Yeh step kyun? Explain karta hai kyun accumulator (32-bit) deliberately operands (8-bit) se wider hai: bahut saare products sum karna running total badhata hai, toh use headroom chahiye jo 8-bit inputs mein nahi hai.

  4. (d) Ek concrete value quantize phir dequantize karo. ReLU activation range lo jo unsigned codes par map hoti hai. Toh scale hai aur zero-point hai (real code par map hota hai). quantize karo: Wapas dequantize karo: Round-trip error hai , lagbhag aadha scale step — 8 bits ki cost. Yeh step kyun? Poora quantize → compute → dequantize loop dikhata hai jo TPU actually run karta hai: integers MAC array se flow karte hain (cheap, dense), aur results baad mein se rescale hote hain. Zero-point wahi hai jo lopsided (all-positive) range fit karta hai.

Forecast check: sabse badi magnitude wala single product hai ( se), do negatives se milta hai, do large positives se nahi (jinका max hai). Aur zero-point isliye chahiye kyunki akela scale sirf ek range stretch kar sakta hai jo ke aas paas symmetric ho; offset range slide karta hai taaki all-positive interval jaise saare 256 codes use kar sake.

Verify: ; ; ; ; aur , error . Quantization and 8-bit inference dekho. ✓


Example 8 — Case H: real-world word problem (ek dense layer ka runtime)

Forecast: guess karo ki kya fill cost ( cycles) answer mein noticeably fark karti hai.

Steps.

  1. Cycles. . Yeh step kyun? Fill/drain ek baar 511 cycles, phir rows ke liye ek result-row per clock.

  2. Efficiency check. — ek fat batch fill amortize karta hai, exactly jaise Case D ne predict kiya.

  3. Time. Ek cycle . Toh Yeh step kyun? Abstract cycles ko wall-clock number mein convert karta hai — unit (s) wahi hai jo ek engineer actually report karta hai.

Forecast check: fill yahan barely matter karti hai — par cycles sirf overhead hai, toh . Bade batch ke saath fixed fill almost invisible hai, yahi reason hai ki TPUs aggressively batch karte hain.

Verify: cycles ; ; time s s. ✓


Example 9 — Case I: exam twist — matrix array se bada (tiling)

Forecast: pehle tiles ki count guess karo, aur kya total MAC count untiled se different hoga.

Steps.

  1. Har dimension split karo. , toh , , ko blocks mein todo. Kyunki teen matrix dimensions mein se har ek () chunks mein split hota hai, output tiles ki ek grid ban jaati hai output tiles. Yeh step kyun? Array ek fixed window hai; tum ise bade problem par slide karte ho — yeh tiling hai, standard fix jab matrix hardware se bada ho.

  2. Output tile per passes. Har output block contraction tile index par sum karta hai, aur bhi pieces mein split hota hai. Toh 4 output tiles mein se har ek ko accumulate-passes chahiye. Yeh step kyun? Ek pass ek weight block load karta hai aur ek -column slab stream karta hai; tumhe ek pass per (output-tile, contraction-tile) pair chahiye, unke partial sums add karte hue.

  3. Total MACs (untiled count ke equal hona chahiye). Har pass ek poori multiply drive karta hai, yaani MACs. Saare 8 passes mein: Ek untiled multiply se compare karo, jo MACs karta hai — identical. Yeh step kyun? Tiling kaam ko space/time mein rearrange karta hai lekin arithmetic total kabhi nahi badalta — woh equality () correctness invariant hai jo tum exam mein check karte ho.

Forecast check: 4 output tiles aur 8 total passes hain, aur MAC count ke identical hai. Agar tumne guess kiya ki total MACs shrink honge, yaad rakho tiling sirf kaam reorder karta hai — arithmetic conserved hai.

Verify: output tiles ; contraction tiles ; passes ; . ✓


Recap

Recall 256×256 array par 90% efficiency kaunsa batch size deta hai?

rows. ::: ~4600 rows — TPUs ko bade batches chahiye.

Recall Array side double karne par throughput kyun quadruple hoti hai?

Throughput ; yeh area ke saath scale karta hai kyunki saare cells har clock fire karte hain. ::: Yeh spatial (area) parallelism hai, linear nahi.

Recall Kya tiling total MAC count badalta hai?

Nahi — . Tiling sirf same arithmetic reorder karta hai. ::: Same total kaam, passes mein split.

Recall 8-bit quantization mein zero-point kya karta hai?

Yeh woh integer code hai jo real value represent karta hai, jo ek lopsided (all-positive, post-ReLU) range ko bina waste ke 8-bit codes mein fit karne deta hai. ::: Woh offset jo real 0 ko integer space mein anchor karta hai.

Related depth: GPU architecture and SIMT execution · ASIC vs FPGA vs general-purpose processors · Roofline model.