Lecture 01 · Introduction

المحاضرة 01 · المقدمة

The hardware gap: cloud, mobile, tiny

فجوة العتاد: السحابة والهاتف والأجهزة الصغيرة جداً

Slides 17–24الشرائح 17–24 P3 SKIM

The supply side of the story: what a cloud GPU, a phone, a Jetson module and a microcontroller can hold and compute, and why a gap of five to six orders of magnitude forces the model, not the chip, to change.

جانب العرض من القصة: ما الذي تستطيع GPU سحابية وجوال ووحدة Jetson وmicrocontroller أن تحمله وتحسبه، ولماذا تفرض فجوة من خمس إلى ست مراتب عشرية أن يتغير النموذج لا الشريحة.

What gets askedما الذي يُسأل عنه

Short computations: TOPS per watt for one GPU, a ratio between two memory tiers (80 GB / 320 kB), and a "does this model fit" check that sends weights to flash and activations to SRAM. One concept in words: the memory wall.

حسابات قصيرة: TOPS/W لوحدة GPU واحدة، ونسبة بين طبقتين من الذاكرة (80 GB / 320 kB)، وفحص "هل يتسع النموذج" الذي يرسل الأوزان إلى flash وactivations إلى SRAM. ومفهوم واحد بالكلمات: memory wall.

Cloud GPUs, slides 17 and 18

وحدات GPU السحابية، الشريحتان 17 و18

Slide 17 repeats the three pillars to open the hardware pillar. Slide 18 plots five NVIDIA data-center GPUs on four charts. TOPS is trillions of operations per second, and one MAC counts as two operations (a multiply and an add).

تعيد الشريحة 17 الركائز الثلاث لتفتح ركيزة العتاد. وترسم الشريحة 18 خمس وحدات GPU من NVIDIA لمراكز البيانات في أربعة رسوم. TOPS تعني تريليونات العمليات في الثانية، وMAC الواحدة تُحسب عمليتين (ضرب وجمع).

TOPS = 2 × MACs per second1012    TOPS/W = peak TOPS / power

الصيغة: TOPS تساوي ضعف عدد MACs في الثانية مقسوماً على 1012، والكفاءة TOPS/W تساوي ذروة TOPS مقسومة على القدرة بالواط.

GPUDense FP16 TOPSTOPS الكثيفة بدقة FP16Bandwidth GB/sعرض النطاق GB/sPower Wالقدرة WMemory GBالذاكرة GBTOPS/W
P100 (2016)18.7732250160.075
V100 SXM (2017)125900300320.42
A100 SXM (2020)3122,039400800.78
H100 SXM (2022)9903,430700961.41
B100 SXM (2024)1,7508,1927001922.5

الجدول يلخص الشريحة 18. من P100 إلى B100: الأداء 18.7 إلى 1750 TOPS (94x)، والقدرة 250 إلى 700 W (2.8x)، والذاكرة 16 إلى 192 GB (12x)، وعرض النطاق 732 إلى 8192 GB/s (نحو 11x). العمود الأخير محسوب: TOPS/W تحسنت نحو 33x.

The memory wall

جدار الذاكرة (memory wall)

Compute ran 94x on only 2.8x the power, so almost all of it came from efficiency. But memory capacity and bandwidth ran only about 12x. Over two decades, peak server compute grew about 3.0x every two years while DRAM bandwidth grew about 1.6x. So the arithmetic units can consume data faster than memory delivers it, and data movement, not arithmetic, becomes the limit. That is the memory wall.

الحساب نما 94x مقابل 2.8x فقط في القدرة، فجاء معظمه من الكفاءة. لكن سعة الذاكرة وعرض نطاقها نميا نحو 12x فقط. وعلى مدى عقدين، نمت ذروة حساب الخوادم نحو 3.0x كل سنتين بينما نما عرض نطاق DRAM نحو 1.6x. لذلك تستطيع وحدات الحساب استهلاك البيانات أسرع مما تستطيع الذاكرة إيصالها، فيصبح نقل البيانات، لا الحساب، هو الحد. هذا هو memory wall.

Worked exampleمثال محلول

TOPS per watt, and MACs from TOPS:

TOPS/W، واستخراج MACs من TOPS:

A100:  312 / 400  = 0.78 TOPS/W
B100:  1750 / 700 = 2.5  TOPS/W        (about 3.2x better in four years)
A100 dense 312 TOPS  = 156 × 10^12 MACs/s   (divide by 2)
A100 "with sparsity" = 624 TOPS            (2:4 pruned weights only)

Mobile and robot accelerators, slides 19 to 21

مسرّعات الهواتف والروبوتات، الشرائح 19 إلى 21

A phone is a sealed, fanless slab, so its sustained power is capped near 10 W by heat. Every generation must deliver its gain as TOPS per watt. A Jetson is a system on module with active cooling, sold as a ladder of power tiers.

الجوال لوح مغلق بلا مروحة، لذا قدرته المستدامة محدودة قرب 10 W بسبب الحرارة، وكل جيل يجب أن يقدم تحسنه في صورة TOPS/W. أما Jetson فهو system on module بتبريد نشط، يُباع كسلّم من مستويات القدرة.

Qualcomm Hexagon

Qualcomm Hexagon

Snapdragon 845 to 8 Gen 1: 3 to 52 TOPS (17x) at about 9 to 10 W. 0.33 to 5.2 TOPS/W. Flat lid.

من Snapdragon 845 إلى 8 Gen 1: 3 إلى 52 TOPS (17x) عند نحو 9 إلى 10 W. من 0.33 إلى 5.2 TOPS/W. سقف قدرة ثابت.

Apple Neural Engine

Apple Neural Engine

A11 to A17 Pro: 0.6 to 35 TOPS (about 58x) at an estimated 6 to 8 W. Same flat lid, different vendor.

من A11 إلى A17 Pro: 0.6 إلى 35 TOPS (نحو 58x) عند قدرة تقديرية 6 إلى 8 W. السقف الثابت نفسه، من مُصنِّع آخر.

NVIDIA Jetson

NVIDIA Jetson

Nano 0.5 TOPS at 10 W to AGX Orin 275 TOPS at 60 W. Power climbs with the tier because robots can cool it.

من Nano 0.5 TOPS عند 10 W إلى AGX Orin 275 TOPS عند 60 W. القدرة ترتفع مع المستوى لأن الروبوتات تستطيع تبريده.

Microcontrollers, slide 22

المتحكمات الدقيقة (microcontrollers)، الشريحة 22

A microcontroller is a compact integrated circuit for embedded systems that puts a processor, memory and I/O peripherals on a single chip, with no DRAM and no operating system. The axes drop two prefixes: power in mW, memory in kB, and performance in DMIPS (Dhrystone MIPS), an index for integer computation, not a neural-network throughput.

Microcontroller دائرة متكاملة مدمجة للأنظمة المضمنة تجمع المعالج والذاكرة والمنافذ الطرفية (I/O) على شريحة واحدة، بلا DRAM وبلا نظام تشغيل. المحاور تنزل بادئتين: القدرة بـ mW، والذاكرة بـ kB، والأداء بـ DMIPS (Dhrystone MIPS)، وهو مؤشر للحساب الصحيح (integer) وليس إنتاجية شبكات عصبية.

BoardاللوحةCoreالنواةMHzDMIPSPower mWالقدرة mWSRAM kBSRAM kB
Arduino ZeroCortex-M0+4845632
Arduino DueCortex-M3841582696
STM32F407VGCortex-M4168210132196 (192 + 4 backup)196 (192 + 4 احتياطية)
STM32F746NGCortex-M7216462360320

الجدول يلخص الشريحة 22. احفظ السطر الأخير: STM32F746 بمعالج Cortex-M7 بتردد 216 MHz، و462 DMIPS، ونحو 360 mW، و320 kB من SRAM، و1 MB من flash. وهو المتحكم الذي شغّل عليه MCUNet نماذج الرؤية في الشريحة 7.

Three tiers, two budgets, slide 23

ثلاث فئات وميزانيتان، الشريحة 23

Slide 23 gives each tier two numbers. Activation memory is the read-write working memory during inference; what matters is the peak across layers (a layer's input and output must coexist). Weight storage holds the read-only model; what matters is the total. On an MCU these are SRAM and flash.

تعطي الشريحة 23 لكل طبقة رقمين. ذاكرة activations هي ذاكرة العمل للقراءة والكتابة أثناء الاستدلال، والمهم فيها الذروة عبر الطبقات (مدخل الطبقة ومخرجها يجب أن يتعايشا في الوقت نفسه). وتخزين الأوزان يحمل النموذج للقراءة فقط، والمهم فيه المجموع. على MCU هما SRAM وflash.

Bytes on a log scale (one tick = 10x) 100 kB 1 MB 10 MB 100 MB 1 GB 10 GB 100 GB 1 TB Cloud Mobile Tiny 80 GB act. ~TB/PB weights 4 GB act. 256 GB weights 320 kB SRAM 1 MB flash 80 GB / 320 kB = 250,000x upper bar = activation memory (read/write, peak) lower bar = weight storage (read-only, total)
Each gridline is a factor of ten. The phone to MCU step (12,500x in activation memory) dwarfs the cloud to phone step (20x).
كل خط شبكي يمثل عشرة أضعاف. القفزة من الجوال إلى MCU (12,500x في ذاكرة activations) أكبر بكثير من القفزة من السحابة إلى الجوال (20x). الشريط الأول لكل طبقة هو ذاكرة activations، والثاني هو تخزين الأوزان.
Worked exampleمثال محلول

Tier ratios, with 1 GB = 10⁶ kB and 1 GB = 10³ MB:

نسب الطبقات، باستخدام 1 GB = 10⁶ kB و1 GB = 10³ MB:

activation  cloud/mobile  80 GB / 4 GB    = 20x
activation  mobile/tiny   4,000,000 / 320 = 12,500x
activation  cloud/tiny    80,000,000 / 320 = 250,000x
storage     mobile/tiny   256 GB / 1 MB   = 256,000x
LLM gap     530B FP16 = 1.06 TB vs 1 MB flash ≈ 1,000,000x

Does this model fit? A mini exercise

هل يتسع هذا النموذج؟ تمرين صغير

Two checks, in order, against two separate budgets. Weights go to flash: params × bytes per param ≤ flash. Activations go to SRAM: for the worst layer, input tensor + output tensor ≤ SRAM. Pass both or it does not run.

فحصان بالترتيب مقابل ميزانيتين منفصلتين. الأوزان تذهب إلى flash: params × bytes per param ≤ flash. وactivations تذهب إلى SRAM: لأسوأ طبقة، input tensor + output tensor ≤ SRAM. يجب أن ينجح الاثنان وإلا فلن يعمل النموذج.

model params, layers 1. weights → flash params × bits / 8 ≤ 1 MB ? (total) 2. activations → SRAM max over layers of in + out ≤ 320 kB ? (peak) runs fail: cannot be stored fail: crashes at runtime
Flash constrains model size (read-only, total). SRAM constrains activation size (read-write, peak). They are checked separately.
flash تقيّد حجم النموذج (قراءة فقط، المجموع). وSRAM تقيّد حجم activations (قراءة وكتابة، الذروة). ويُفحص كل منهما على حدة.
Worked exampleمثال محلول

Target: STM32F746 (1 MB flash, 320 kB SRAM). A small CNN with 600k parameters in INT8; its worst layer turns a 112×112×16 INT8 map into a 112×112×32 map.

الهدف: STM32F746 (1 MB flash و320 kB SRAM). شبكة CNN صغيرة بـ 600k معامل بصيغة INT8، وأسوأ طبقة فيها تحوّل خريطة 112×112×16 إلى خريطة 112×112×32، والقيم كلها INT8.

weights:     600,000 × 1 B           = 600 kB   ≤ 1 MB flash     PASS
input map:   112 × 112 × 16 × 1 B    = 200,704 B
output map:  112 × 112 × 32 × 1 B    = 401,408 B
peak:        200,704 + 401,408       = 602,112 B ≈ 602 kB  > 320 kB   FAIL (1.9x over)

fix: halve the resolution to 56 × 56
peak:        56 × 56 × (16 + 32)     = 150,528 B ≈ 151 kB  ≤ 320 kB   PASS

Same weights, different verdict: resolution changes activations, not parameters. Now the real thing: ResNet-50 is 25.6M parameters, 25.6 MB even in INT8 (25.6x over flash) with a 7.2 MB peak activation (about 22x over SRAM). It fails both checks, and quantization alone (4x) closes neither.

الأوزان نفسها والحكم مختلف: الدقة المكانية للصورة تغيّر activations لا المعاملات. والآن المثال الحقيقي: ResNet-50 فيه 25.6M معامل، أي 25.6 MB حتى بصيغة INT8 (أكبر من flash بـ 25.6x)، وذروة activations 7.2 MB (أكبر من SRAM بنحو 22x). يفشل في الفحصين، وquantization وحدها (4x) لا تسد أياً منهما.

Slide 24 credits the framing to Prof. Song Han's MIT 6.5940, TinyML and Efficient Deep Learning Computing. The conclusion of the lecture: no hardware trend closes six orders of magnitude, so the model must shrink. That is pruning, quantization, NAS, distillation and co-design, the rest of the course.

تنسب الشريحة 24 هذا الإطار إلى مقرر MIT 6.5940 للبروفيسور Song Han، بعنوان TinyML and Efficient Deep Learning Computing. وخلاصة المحاضرة: لا يوجد اتجاه في العتاد يسد ست مراتب عشرية، لذلك يجب أن يصغر النموذج. وهذا هو pruning وquantization وNAS وdistillation وco-design، أي بقية المقرر.

Exam trapفخ امتحاني

Three ways to compare TOPS wrongly. One: TOPS counts 2 ops per MAC, so 312 TOPS is 156 T MACs/s, not 312. Two: NVIDIA headline numbers are often "with sparsity", exactly double the dense figure and reachable only with 2:4 pruned weights (A100: 624 sparse versus 312 dense). Slide 18 uses dense. Three: compare TOPS only at the same precision: Jetson Orin is quoted in sparse INT8, Nano and TX2 in FP16, the cloud slide in dense FP16, and Apple gives no precision at all. Also never compare DMIPS with TOPS; DMIPS has no MACs in it.

ثلاث طرق لمقارنة TOPS بشكل خاطئ. الأولى: TOPS تحسب عمليتين لكل MAC، فـ 312 TOPS تساوي 156 T MACs/s لا 312. الثانية: أرقام NVIDIA الدعائية غالباً تكون "with sparsity"، أي ضعف الرقم الكثيف (dense) بالضبط، ولا تتحقق إلا بأوزان مقلّمة بنمط 2:4 (A100: 624 مع sparsity مقابل 312 dense). والشريحة 18 تستخدم الأرقام الكثيفة. الثالثة: قارن TOPS فقط عند الدقة الرقمية نفسها: Jetson Orin مُعلن بـ INT8 مع sparsity، وNano وTX2 بـ FP16، وشريحة السحابة بـ FP16 كثيف، وApple لا تذكر الدقة إطلاقاً. ولا تقارن DMIPS بـ TOPS أبداً، فـ DMIPS لا تحتوي أي MACs.

Memory trickحيلة للحفظ

"80 GB, 4 GB, 320 kB; TB, 256 GB, 1 MB." Say the activation row then the storage row. And: "Flash is the bookshelf, SRAM is the desk." The whole book must fit on the shelf; only the pages open right now must fit on the desk.

"80 GB, 4 GB, 320 kB؛ TB, 256 GB, 1 MB." قل صف activations ثم صف التخزين. وتذكّر: "flash هي رف الكتب، وSRAM هي المكتب." الكتاب كله يجب أن يتسع على الرف، أما المكتب فيكفي أن تتسع عليه الصفحات المفتوحة الآن فقط.

Check yourself

اختبر نفسك

Using 1 GB = 1,000,000 kB, what is the ratio of cloud AI activation memory (80 GB) to tiny AI (320 kB)?

باستخدام 1 GB = 1,000,000 kB، ما نسبة ذاكرة activations في cloud AI (80 GB) إلى tiny AI (320 kB)؟

C. 80,000,000 kB / 320 kB = 250,000. A is the mobile to tiny activation ratio (4 GB / 320 kB). B is the mobile to tiny storage ratio (256 GB / 1 MB), a close-looking number on the other row.

الجواب C. 80,000,000 kB / 320 kB = 250,000. والخيار A هو نسبة activations من الجوال إلى tiny (4 GB / 320 kB). والخيار B هو نسبة التخزين من الجوال إلى tiny (256 GB / 1 MB)، رقم قريب الشكل من الصف الآخر.

A model's INT8 weights fit in the MCU's 1 MB flash, yet inference fails. What is the most likely reason?

أوزان نموذج بصيغة INT8 تتسع في 1 MB flash على MCU، ومع ذلك يفشل الاستدلال. ما السبب الأرجح؟

B. Flash and SRAM are separate budgets. Weights fitting flash says nothing about the read-write activations, which must fit SRAM at the worst layer. MobileNetV2 INT8 peaks at 1.7 MB, 5.3x over 320 kB. D is true of MCUs but is not a reason inference fails.

الجواب B. flash وSRAM ميزانيتان منفصلتان. اتساع الأوزان في flash لا يقول شيئاً عن activations (قراءة وكتابة) التي يجب أن تتسع في SRAM عند أسوأ طبقة. ذروة MobileNetV2 بصيغة INT8 هي 1.7 MB، أي أكبر من 320 kB بـ 5.3x. والخيار D صحيح عن MCUs لكنه ليس سبب الفشل.

An NVIDIA spec sheet lists an A100 at 624 TOPS FP16 "with sparsity". What is the fair dense figure, and how many MACs per second is it?

ورقة مواصفات NVIDIA تذكر A100 بـ 624 TOPS FP16 "with sparsity". ما الرقم الكثيف العادل، وكم MACs في الثانية يساوي؟

A. The sparse number is exactly double the dense one and needs 2:4 pruned weights, so dense is 312 TOPS. Each MAC is 2 operations, so 312 / 2 = 156 T MACs/s. B forgets the sparsity doubling; C multiplies by 2 instead of dividing.

الجواب A. الرقم مع sparsity ضعف الرقم الكثيف بالضبط ويحتاج أوزاناً مقلّمة بنمط 2:4، فالرقم الكثيف 312 TOPS. وكل MAC عمليتان، فـ 312 / 2 = 156 T MACs/s. الخيار B ينسى مضاعفة sparsity، والخيار C يضرب في 2 بدل القسمة.

From Snapdragon 845 to 8 Gen 1, TOPS grew about 17x while power stayed near 10 W. What forced that pattern?

من Snapdragon 845 إلى 8 Gen 1 نمت TOPS نحو 17x بينما بقيت القدرة قرب 10 W. ما الذي فرض هذا النمط؟

D. A sealed handheld device must stay cool enough to hold. Jetson, by contrast, climbs from 10 W to 60 W because robots have fans. The memory wall (B) is a cloud bandwidth story, not a power cap.

الجواب D. الجهاز المحمول المغلق يجب أن يبقى بارداً بما يكفي لحمله. وفي المقابل يصعد Jetson من 10 W إلى 60 W لأن الروبوتات فيها مراوح. وmemory wall (B) قصة عرض نطاق في السحابة، لا سقف قدرة.

What does the DMIPS figure on slide 22 measure?

ماذا يقيس رقم DMIPS في الشريحة 22؟

B. The slide footnote: DMIPS is "an index for integer computation". Dhrystone has no floating point and no MACs, so it cannot be compared with TOPS. The F746's 462 is 2.14 DMIPS/MHz × 216 MHz.

الجواب B. حاشية الشريحة تقول إن DMIPS هو "an index for integer computation". اختبار Dhrystone لا يحتوي فاصلة عائمة ولا MACs، فلا يمكن مقارنته بـ TOPS. ورقم 462 لـ F746 هو 2.14 DMIPS/MHz × 216 MHz.