Majid Al-RaimiLatency, throughput and energyزمن الاستجابة والإنتاجية والطاقة

COE 592Lecture 03المحاضرة 03Part 01الجزء 01

Latency, throughput and energyزمن الاستجابة والإنتاجية والطاقة

The efficiency triangle of storage, latency and energy, what latency and throughput each measure, why one does not imply the other, the analytical latency model, and why data movement dominates energy.مثلث الكفاءة (التخزين وزمن الاستجابة والطاقة)، وما يقيسه كل من زمن الاستجابة (latency) والإنتاجية (throughput)، ولماذا لا يستلزم أحدهما الآخر، ونموذج زمن الاستجابة التحليلي، ولماذا يهيمن نقل البيانات على استهلاك الطاقة.

Conceptsالمفاهيم
5
Slidesالشرائح
1-9
Readingمدة القراءة
30 min30 دقيقة
Understoodما فهمته
0/5 conceptsمفاهيم

Why this part mattersلماذا يهمّ هذا الجزء

Your research project will put a detector on an embedded board, and the board will judge it by three costs that have nothing to do with accuracy: does the model fit, does it answer before the next frame arrives, and does it drain the battery. Every metric in this lecture exists to predict one of those three costs before you ever flash the board.

This part gives you the map and the first three costs. It fixes the vocabulary (latency, throughput, energy), shows why a latency number is meaningless without the conditions it was measured under, works the batching example that exams love, derives a one-line latency model that separates what the network controls from what the hardware controls, and ends with the energy table that explains why every efficient design of the last decade is really a design for moving fewer bytes. Parts 02 to 04 then fill in the metrics that feed these costs.

سيضع مشروعك البحثي كاشفًا (detector) على لوحة مدمجة (embedded board)، وستحكم اللوحة عليه بثلاث تكاليف لا علاقة لها بالدقة: هل يتسع النموذج فيها، وهل يُخرج إجابته قبل وصول الإطار التالي، وهل يستنزف البطارية. كل مقياس في هذه المحاضرة موجود ليتنبأ بإحدى هذه التكاليف الثلاث قبل أن تحمّل البرنامج على اللوحة أصلًا.

يعطيك هذا الجزء الخريطة والتكاليف الثلاث الأولى. فهو يثبّت المصطلحات (latency وthroughput والطاقة)، ويبيّن لماذا لا معنى لرقم latency من دون الظروف التي قيس فيها، ويحل مثال الـ batching الذي تحبه الاختبارات، ويشتق نموذجًا للـ latency في سطر واحد يفصل ما تتحكم فيه الشبكة عما يتحكم فيه العتاد، ثم ينتهي بجدول الطاقة الذي يفسر لماذا كان كل تصميم كفء في العقد الأخير في حقيقته تصميمًا لنقل بايتات أقل. ثم تملأ الأجزاء من 02 إلى 04 المقاييس التي تغذي هذه التكاليف.

By the end you canفي نهاية هذا الجزء ستستطيع

  1. Place any efficiency metric in the memory or computation group and say which of storage, latency and energy it predicts.تضع أي مقياس كفاءة في مجموعة الذاكرة أو مجموعة الحساب، وتحدد أيّ التكاليف الثلاث يتنبأ بها: التخزين أو الـ latency أو الطاقة.
  2. Define latency and throughput, and compute both for a batched design.تعرّف الـ latency والـ throughput، وتحسب كليهما لتصميم يستخدم الـ batching.
  3. Explain with numbers why higher throughput does not imply lower latency, and lower latency does not imply higher throughput.تشرح بالأرقام لماذا لا يعني الـ throughput الأعلى latency أقل، ولا يعني الـ latency الأقل throughput أعلى.
  4. Write Latency ≈ max(T_computation, T_memory) with its sub-formulas, label each term NN or hardware specification, and decide compute-bound versus memory-bound.تكتب Latency ≈ max(T_computation, T_memory) مع صيغها الفرعية، وتصنّف كل حد على أنه مواصفة الشبكة (NN) أو مواصفة العتاد، وتقرر هل النموذج compute-bound أم memory-bound.
  5. Quote the 45 nm energy table and argue why data movement, not arithmetic, sets the energy bill of an inference.تستشهد بجدول الطاقة عند 45 nm وتبرهن لماذا يحدد نقلُ البيانات، لا الحسابُ، فاتورةَ الطاقة لعملية الاستدلال (inference).

Suppose the detector you trained in the cloud is to run on a Jetson-class board mounted on a vehicle. Before the board can use it, three separate questions must be answered. Does the model fit in the flash and RAM you have? Does one inference finish before the next camera frame lands, roughly every 33 ms at 30 frames per second? And how much charge does each inference pull from the battery? Slide 4 draws these as the three outer goals of a triangle, Smaller, Faster and Greener, and the three costs that quantify them: Storage, Latency and Energy.

افترض أن الكاشف الذي دربته في السحابة سيعمل على لوحة من فئة Jetson مثبتة على مركبة. قبل أن تستطيع اللوحة استخدامه يجب الإجابة عن ثلاثة أسئلة منفصلة. هل يتسع النموذج في ذاكرة الـ flashوالـ RAM المتاحة لديك؟ هل ينتهي استدلال واحد قبل وصول إطار الكاميرا التالي، أي تقريبًا كل 33 ms عند 30 إطارًا في الثانية؟ وكم من شحن البطارية يسحب كل استدلال؟ ترسم الشريحة 4 هذه الأسئلة على أنها الأهداف الخارجية الثلاثة لمثلث: أصغر (Smaller) وأسرع (Faster) وأكثر خضرة (Greener)، ومعها التكاليف الثلاث التي تقيسها: التخزين (Storage) والـ Latency والطاقة (Energy).

The part of the triangle that matters is the middle. All three costs are driven by only two resources, Computation and Memory. Storage is purely a memory question: how many bytes the weights occupy. Latency and energy depend on both, because an inference both performs arithmetic and moves data, and each of those takes time and burns charge. That is why the metric list on the side of the slide has exactly two groups. The efficiency metrics that are memory-related are the number of parameters, the model size and the total and peak number of activations. The computation-related ones are MACs, FLOPs with their rate FLOPS, and OPs with their rate OPS.

الجزء المهم من المثلث هو الوسط. فالتكاليف الثلاث كلها يحركها مَوردان فقط: الحساب (Computation) والذاكرة (Memory). التخزين مسألة ذاكرة بحتة: كم بايتًا تشغل الأوزان. أما الـ latency والطاقة فيعتمدان على الاثنين، لأن الاستدلال يجري عمليات حسابية وينقل بيانات معًا، وكل منهما يستهلك وقتًا ويحرق شحنًا. لهذا تحتوي قائمة المقاييس على جانب الشريحة على مجموعتين بالضبط. efficiency metrics المتعلقة بالذاكرة هي number of parameters (عدد المعاملات)، وmodel size (حجم النموذج)، والعدد الكلي للـ activations وpeak number of activations. أما المتعلقة بالحساب فهي MACs، وFLOPs مع معدلها FLOPS، وOPs مع معدلها OPS.

Resources feed costs, costs feed goals. Memory wires into all three costs, computation into latency and energy. Hover Storage to see that only the memory metrics predict it.الموارد تغذي التكاليف، والتكاليف تغذي الأهداف. الذاكرة متصلة بالتكاليف الثلاث كلها، والحساب متصل بالـ latency والطاقة. مرّر المؤشر على Storage لترى أن مقاييس الذاكرة وحدها هي التي تتنبأ به.
GoalالهدفCostالتكلفةResourceالموردMetrics that predict itالمقاييس التي تتنبأ به
SmallerأصغرStorageالتخزينMemoryالذاكرة#parameters, model sizeعدد المعاملات (#parameters)، وحجم النموذج
FasterأسرعLatencyالـ latencyComputation and memoryالحساب والذاكرةMACs, OPs, model size, peak #activationsMACs، وOPs، وحجم النموذج، والعدد الأقصى للـ activations
Greenerأكثر خضرةEnergyالطاقةComputation and memoryالحساب والذاكرةMACs, OPs, and above all the bytes movedMACs وOPs، وقبل كل شيء البايتات المنقولة
Each goal, the cost that quantifies it, the resource it draws on, and the metrics that predict itكل هدف، والتكلفة التي تقيسه، والمورد الذي يعتمد عليه، والمقاييس التي تتنبأ به

This taxonomy is the spine of the whole lecture. Parts 02 and 03 fill the memory group (parameters, model size, activations), part 04 fills the computation group (MACs, FLOPs, OPs), and this part explains the three costs those metrics are meant to predict. Whenever a later metric appears, place it here first: which group is it in, and which cost does it feed?

هذا التصنيف هو العمود الفقري للمحاضرة كلها. يملأ الجزءان 02 و03 مجموعة الذاكرة (المعاملات، حجم النموذج، الـ activations)، ويملأ الجزء 04 مجموعة الحساب (MACs، FLOPs، OPs)، ويشرح هذا الجزء التكاليف الثلاث التي يُفترض أن تتنبأ بها تلك المقاييس. كلما ظهر مقياس لاحقًا، ضعه هنا أولًا: في أي مجموعة هو، وأي تكلفة يغذي؟

Metrics you count versus costs you measureمقاييس تَعُدّها مقابل تكاليف تقيسها

One distinction keeps the rest of the part honest. Parameters and MACs are properties of the network alone. You can count them on paper from the layer shapes, and they do not change when you move the model to another chip. Latency, throughput and energy are properties of the network running on a specific processor with a specific runtime. They must be measured, or at least estimated from hardware numbers. The same split reappears in the latency model of concept 4 as NN specification versus hardware specification.

تمييز واحد يحفظ بقية الجزء دقيقًا. المعاملات والـ MACs خصائص للشبكة وحدها. يمكنك عدّها على الورق من أشكال الطبقات، ولا تتغير عندما تنقل النموذج إلى شريحة أخرى. أما Latency وthroughput والطاقة فهي خصائص للشبكة وهي تعمل على معالج محدد مع runtime محدد. يجب قياسها، أو على الأقل تقديرها من أرقام العتاد. ويعود هذا الانقسام نفسه في نموذج الـ latency في المفهوم 4 بوصفه مواصفة الشبكة (NN specification) مقابل مواصفة العتاد (hardware specification).

Quick checkاختبار سريع

In the efficiency triangle, which pair of resources drives all three of storage, latency and energy?في مثلث الكفاءة، أي زوج من الموارد يحرّك التكاليف الثلاث كلها: التخزين والـ latency والطاقة؟

Recall

Name the two groups of efficiency metrics, list the members of each, and say which cost each group predicts.سمِّ مجموعتَي مقاييس الكفاءة، واذكر أعضاء كل منهما، وقل أي تكلفة تتنبأ بها كل مجموعة.

Memory-related: #parameters, model size, total and peak #activations; they predict storage and the memory part of latency and energy. Computation-related: MAC, FLOP and FLOPS, OP and OPS; they predict the computation part of latency and energy.
المتعلقة بالذاكرة: #parameters، وحجم النموذج، والعدد الكلي والأقصى للـ activations؛ وهي تتنبأ بالتخزين وبجزء الذاكرة من الـ latency والطاقة. المتعلقة بالحساب: MAC، وFLOP وFLOPS، وOP وOPS؛ وهي تتنبأ بجزء الحساب من الـ latency والطاقة.

Slide 5 shows the same Cityscapes street segmented twice. The two masks look almost identical, and by the usual accuracy metric they are: SegFormer-B5 reaches 82.4 mIoU and EfficientViT-L1 reaches 82.7 mIoU. The difference is time. SegFormer needs 638 ms per frame and EfficientViT needs 45.9 ms (the slide rounds to 46 ms). At 30 frames per second a new frame arrives every 33 ms, so one model falls nineteen frames behind for every frame it finishes, and the other almost keeps up.

تعرض الشريحة 5 شارع Cityscapes نفسه مقسّمًا (segmented) مرتين. يبدو القناعان متطابقين تقريبًا، وهما كذلك وفق مقياس الدقة المعتاد: يصل SegFormer-B5 إلى 82.4 mIoU ويصل EfficientViT-L1 إلى 82.7 mIoU. الفرق هو الزمن. يحتاج SegFormer إلى 638 ms لكل إطار ويحتاج EfficientViT إلى 45.9 ms (تقرّبها الشريحة إلى 46 ms). عند 30 إطارًا في الثانية يصل إطار جديد كل 33 ms، لذا يتأخر أحد النموذجين تسعة عشر إطارًا عن كل إطار ينهيه، بينما يكاد الآخر يواكب.

That per-frame time is latency: the delay between starting one specific task and finishing it. Patterson and Hennessy call the same quantity response time or execution time, the time between the start and completion of a task. It is a property of one task, not of a stream of tasks, and the next concept shows why that restriction matters. The 13.9x gap (638 / 45.9) is exactly the headline of the EfficientViT paper, which reports up to 13.9x GPU latency reduction over SegFormer at the same or better accuracy (Cai et al., ICCV 2023).

هذا الزمن لكل إطار هو latency: التأخير بين بدء مهمة واحدة محددة وإنهائها. يسمي Patterson وHennessy الكمية نفسها زمن الاستجابة (response time) أو زمن التنفيذ (execution time)، أي الزمن بين بدء مهمة واكتمالها. إنه خاصية لمهمة واحدة، لا لسيل من المهام، والمفهوم التالي يبيّن لماذا يهم هذا القيد. الفارق 13.9x (638 / 45.9) هو بالضبط العنوان الرئيسي لورقة EfficientViT، التي تذكر خفضًا في الـ latency على الـ GPU يصل إلى 13.9x مقارنة بـ SegFormer مع دقة مساوية أو أفضل (Cai et al., ICCV 2023).

ModelالنموذجmIoUmIoUParametersالمعاملاتMACsMACsOrin latencyالـ latency على OrinA100 throughputالـ throughput على A100
SegFormer-B5SegFormer-B582.482.485M85M1460G1460G638 ms638 ms12 image/s12 image/s
EfficientViT-L1EfficientViT-L182.782.740M40M282G282G45.9 ms45.9 ms122 image/s122 image/s
Ratioالنسبة+0.3+0.32.1x fewerأقل بمقدار 2.1x5.2x fewerأقل بمقدار 5.2x13.9x fasterأسرع بمقدار 13.9x10x moreأكثر بمقدار 10x
Both models on Cityscapes at 1024 x 2048, from Table 3 of the EfficientViT paper. Latency on Jetson AGX Orin at batch size 1, throughput on an A100.النموذجان على Cityscapes بدقة 1024 x 2048، من الجدول 3 في ورقة EfficientViT. الـ latency على Jetson AGX Orin بـ batch size يساوي 1، والـ throughput على A100.

Read the ratio row carefully, because it plants the seed for concept 4. The MAC count falls 5.2x, but latency falls 13.9x. If latency were simply proportional to arithmetic, the two ratios would match. They do not, because SegFormer's softmax attention moves large intermediate tensors through memory, and that data movement, not its MACs, is what makes it slow on an edge GPU. MACs alone do not predict latency; they are one input to it.

اقرأ صف النسب بعناية، لأنه يزرع بذرة المفهوم 4. ينخفض عدد MAC بمقدار 5.2x، لكن الـ latency ينخفض بمقدار 13.9x. لو كان الـ latency متناسبًا ببساطة مع الحساب لتطابقت النسبتان. لكنهما لا تتطابقان، لأن الـ softmax attention في SegFormer ينقل tensors وسيطة كبيرة عبر الذاكرة، وهذا النقل للبيانات، لا عدد MACs، هو ما يجعله بطيئًا على GPU طرفي (edge). الـ MACs وحدها لا تتنبأ بالـ latency؛ إنها مُدخل واحد من مُدخلاته.

Four conditions every latency must stateأربعة شروط يجب أن يذكرها كل رقم latency

The slide's footnote is not fine print. Latency is measured, so it depends on everything in the measurement. The paper's setup sentence names four things: the hardware, the runtime, the numeric precision and the batch size. Change any one of them and the number changes, sometimes by an order of magnitude. The same paper measures EfficientViT-B1 at 24.3 ms on Orin and 0.82 s on a Jetson Nano, and SegFormer-B1 at 146 ms on Orin and 5.6 s on Nano. Same model, same precision, same batch size, different board: 34x to 38x apart.

الحاشية في أسفل الشريحة ليست تفاصيل هامشية. الـ latency يُقاس، لذا يعتمد على كل شيء في عملية القياس. جملة الإعداد في الورقة تسمي أربعة أشياء: العتاد، والـ runtime، والدقة العددية (precision)، وbatch size. غيّر أيًا منها فيتغير الرقم، أحيانًا بمرتبة عشرية كاملة. تقيس الورقة نفسها EfficientViT-B1 عند 24.3 ms على Orin و0.82 s على Jetson Nano، وSegFormer-B1 عند 146 ms على Orin و5.6 s على Nano. النموذج نفسه، والدقة العددية نفسها، والـ batch size نفسه، ولوحة مختلفة: الفرق من 34x إلى 38x.

The measurement conditions behind slide 5شروط القياس وراء الشريحة 5

Hardwareالعتاد
NVIDIA Jetson AGX Orin: 2048-core Ampere GPU, 64 Tensor Cores at 43 dense FP16 TFLOPS (the CUDA cores alone give 10.6), 204.8 GB/s LPDDR5, 15 W to 60 WNVIDIA Jetson AGX Orin: معالج رسومي GPU بمعمارية Ampere فيه 2048 نواة، و64 من الـ Tensor Cores بأداء 43 dense FP16 TFLOPS (أنوية CUDA وحدها تعطي 10.6)، وذاكرة LPDDR5 بعرض نطاق 204.8 GB/s، واستهلاك قدرة من 15 W إلى 60 W
Runtimeبيئة التشغيل (runtime)
TensorRT, which NVIDIA describes as turning a trained model into a fast, GPU-specific program for inference; the speedup depends on the model, precision, batch size and GPUTensorRT، الذي تصفه NVIDIA بأنه يحوّل النموذج المدرَّب إلى برنامج استدلال سريع ومخصص للـ GPU؛ ويعتمد مقدار التسريع على النموذج والدقة العددية والـ batch size والـ GPU
Precisionالدقة العددية
fp16, half the bytes per weight and activation of fp32fp16، أي نصف عدد البايتات لكل وزن ولكل activation مقارنة بـ fp32
Batch sizeحجم الدفعة (batch size)
1, one image per inference, which is what an on-device detector sees1، أي صورة واحدة لكل استدلال، وهذا ما يراه كاشف يعمل على الجهاز نفسه

Quick checkاختبار سريع

Which set of conditions must accompany a reported latency for it to be comparable?أي مجموعة من الشروط يجب أن ترافق رقم latency منشورًا حتى يمكن مقارنته؟

Recall

Define latency in one sentence and name the four conditions that slide 5 states for its numbers.عرّف الـ latency في جملة واحدة وسمِّ الشروط الأربعة التي تذكرها الشريحة 5 لأرقامها.

Latency is the delay to complete one specific task, here one segmentation of one frame. Conditions: hardware (Jetson AGX Orin), runtime (TensorRT), precision (fp16) and batch size (1).
الـ latency هو التأخير لإكمال مهمة واحدة محددة، وهي هنا تقسيم (segmentation) واحد لإطار واحد. الشروط: العتاد (Jetson AGX Orin)، والـ runtime (TensorRT)، والدقة العددية (fp16)، والـ batch size (1).

Slide 6 replaces one street with two mosaics of video clips and asks a different question: not how long one clip takes, but how many clips get done per second. One system manages 6.1 videos per second, the other 77.4. Those two numbers come from Table 5 of the TSM paper (Lin, Gan and Han, ICCV 2019): I3D at 306 GFLOPs versus TSM8F at 33 GFLOPs, both on a single Tesla P100.

تستبدل الشريحة 6 الشارعَ الواحد بفسيفساءين من مقاطع الفيديو وتطرح سؤالًا مختلفًا: ليس كم يستغرق مقطع واحد، بل كم مقطعًا يُنجَز في الثانية. أحد النظامين يعالج 6.1 فيديو في الثانية، والآخر 77.4. يأتي هذان الرقمان من الجدول 5 في ورقة TSM (Lin, Gan and Han, ICCV 2019): I3D عند 306 GFLOPs مقابل TSM8F عند 33 GFLOPs، وكلاهما على Tesla P100 واحدة.

That rate is throughput: the amount of work completed per unit time, what Patterson and Hennessy also call bandwidth. The TSM paper is unusually helpful here because it states its protocol: latency was measured with batch size 1 and throughput with batch size 16. TSM8F's latency is 17.4 ms. If throughput were the reciprocal of latency you would expect 1000 / 17.4 = 57.5 videos per second, yet the paper reports 77.4. The extra comes from batching, and it is the whole point of slide 7.

هذا المعدل هو throughput: مقدار العمل المنجز في وحدة الزمن، وهو ما يسميه Patterson وHennessy أيضًا عرض النطاق (bandwidth). ورقة TSM مفيدة على نحو غير معتاد هنا لأنها تذكر بروتوكولها: قيس الـ latency بـ batch size يساوي 1 والـ throughput بـ batch size يساوي 16. الـ latency للنموذج TSM8F هو 17.4 ms. لو كان الـ throughput مقلوب الـ latency لتوقعت 1000 / 17.4 = 57.5 فيديو في الثانية، لكن الورقة تذكر 77.4. الزيادة تأتي من الـ batching، وهي جوهر الشريحة 7 كله.

throughput=bTbatch,latency=Tbatch\text{throughput} = \frac{b}{T_{\text{batch}}}, \qquad \text{latency} = T_{\text{batch}}
b inputs processed together in one batch that takes T_batchb من المدخلات تُعالج معًا في دفعة واحدة تستغرق T_batch

Two designs, same processor, opposite answersتصميمان، المعالج نفسه، إجابتان متعاكستان

Slide 7 pits two designs against each other. Design 1 handles one image at a time and takes 50 ms per image. Design 2 takes four images together and finishes the whole group in 100 ms. Each image in Design 2 waits the full 100 ms, because nothing leaves the processor until the batch is done.

تضع الشريحة 7 تصميمين في مواجهة. التصميم 1 يعالج صورة واحدة في كل مرة ويستغرق 50 ms لكل صورة. التصميم 2 يأخذ أربع صور معًا وينهي المجموعة كلها في 100 ms. كل صورة في التصميم 2 تنتظر الـ 100 ms كاملة، لأن لا شيء يغادر المعالج حتى تكتمل الدفعة (batch).

DesignالتصميمHow images are handledطريقة معالجة الصورPer-image latencyالـ latency لكل صورةImages per batchعدد الصور في الدفعةBatch timeزمن الدفعةThroughputالـ throughput
Design 1التصميم 1One after anotherصورة تلو الأخرى50 ms50 ms1150 ms50 ms1 / 0.050 = 20 image/s1 / 0.050 = 20 image/s
Design 2التصميم 2Four in parallelأربع صور بالتوازي100 ms100 ms44100 ms100 ms4 / 0.100 = 40 image/s4 / 0.100 = 40 image/s
Slide 7's two designsتصميما الشريحة 7
Both lanes run for the same 200 ms. Design 1 finishes four images in four 50 ms steps. Design 2 finishes eight in two 100 ms steps, yet every one of its images waited twice as long.يعمل المساران المدة نفسها 200 ms. ينهي التصميم 1 أربع صور في أربع خطوات كل منها 50 ms. وينهي التصميم 2 ثماني صور في خطوتين كل منهما 100 ms، ومع ذلك انتظرت كل صورة من صوره ضعف المدة.

Worked exampleمثال محلول

Answering slide 7's two questionsالإجابة عن سؤالَي الشريحة 7

  1. Does higher throughput mean lower latency?هل يعني الـ throughput الأعلى latency أقل؟

    No. Design 2 has twice the throughput (40 versus 20 image/s) and twice the latency (100 versus 50 ms). Batching raised both, because throughput counts images and latency counts the wait of one image, and that image waits for its whole batch.
    لا. للتصميم 2 ضعف الـ throughput (40 مقابل 20 image/s) وضعف الـ latency (100 مقابل 50 ms). رفع الـ batching الاثنين معًا، لأن الـ throughput يعدّ الصور بينما يعدّ الـ latency انتظار صورة واحدة، وتلك الصورة تنتظر دفعتها كاملة.
  2. Does lower latency mean higher throughput?هل يعني الـ latency الأقل throughput أعلى؟

    No. Design 1 has half the latency and half the throughput. With no parallelism, a fast single lane still moves only one image per step, so a short step buys a short wait but not a high rate.
    لا. للتصميم 1 نصف الـ latency ونصف الـ throughput. من دون توازٍ، يبقى المسار الواحد السريع ينقل صورة واحدة فقط في كل خطوة، فالخطوة القصيرة تشتري انتظارًا قصيرًا لكنها لا تشتري معدلًا عاليًا.
  3. When the two coincideمتى يتطابق الاثنان

    Throughput equals 1 / latency only when the batch size is 1 and nothing is pipelined or run in parallel. Any batching or parallelism breaks the identity, always in the direction of more throughput per unit of latency.
    يساوي الـ throughput القيمة 1 / latency فقط عندما يكون الـ batch size مساويًا 1 ولا يوجد أي pipelining أو تشغيل متوازٍ. أي batching أو توازٍ يكسر هذه المساواة، ودائمًا في اتجاه throughput أكبر لكل وحدة من الـ latency.
SimulatorمحاكيLatency versus throughput under batchingزمن الاستجابة مقابل الإنتاجية مع التجميع في دفعات
images done atالصور المنجزة عند 1000 ms: 40
Latency per image100msevery image waits for its whole batch, so L = t_batchكل صورة تنتظر اكتمال دفعتها كلها، لذلك L = t_batch
Throughputالإنتاجية (throughput)40.0image/s4 / 100 ms
1 / latency10.0per sonly equals throughput when b = 1لا يساوي الإنتاجية إلا عندما b = 1

Batching multiplies throughput by b = 4 (4x the reciprocal of latency) while latency stays at 100 ms for every image. In one 1 s window this design completes 10 whole batches, 40 images. The TSM preset back-computes its batch time from the paper's 77.4 video/s at batch 16, so it illustrates the arithmetic rather than confirming it.يضاعف التجميع في دفعات الإنتاجية بمقدار b = 4 (أي 4x مقلوب زمن الاستجابة) بينما يبقى زمن الاستجابة 100 ms لكل صورة. وفي نافذة واحدة مدتها 1 s يُنجز هذا التصميم 10 دفعات كاملة، أي 40 صورة. يستنتج إعداد TSM المسبق زمن دفعته عكسيًا من القيمة 77.4 video/s الواردة في الورقة عند دفعة حجمها 16، فهو يوضح طريقة الحساب ولا يؤكد الرقم.

A second scenario for practiceسيناريو ثانٍ للتدريب

A cloud server serves the same model at two batch sizes. At batch 1 a request takes 2 ms. At batch 32 the whole batch takes 8 ms, because the GPU can spread thirty-two images over its cores far more efficiently than one.

خادم سحابي يقدّم النموذج نفسه بحجمَي batch مختلفين. عند batch يساوي 1 يستغرق الطلب 2 ms. وعند batch يساوي 32 تستغرق الدفعة كلها 8 ms، لأن الـ GPU يستطيع توزيع اثنتين وثلاثين صورة على أنويته بكفاءة أعلى بكثير من صورة واحدة.

SettingالإعدادBatch timeزمن الدفعةImages per batchعدد الصور في الدفعةLatency per imageالـ latency لكل صورةThroughputالـ throughput
Batch 1دفعة بحجم 12 ms2 ms112 ms2 ms500 image/s500 image/s
Batch 32دفعة بحجم 328 ms8 ms32328 ms8 ms4000 image/s4000 image/s
Changeالتغيّر4x longerأطول بمقدار 4x32x moreأكثر بمقدار 32x4x worseأسوأ بمقدار 4x8x betterأفضل بمقدار 8x
One server, two batch sizesخادم واحد بحجمَي batch مختلفين

Batching paid 4x latency to buy 8x throughput. Whether that is a good trade depends on who is waiting. A brake camera needs one frame answered now: latency, at batch size 1, which is why slide 5 measured that way. A data center indexing videos overnight needs clips per hour: throughput, at whatever batch size fills the GPU. Your research project sits on the first side of that line.

دفع الـ batching زيادة 4x في الـ latency ليشتري 8x في الـ throughput. هل هذه مقايضة جيدة؟ يعتمد ذلك على من ينتظر. كاميرا الفرامل تحتاج إلى إجابة عن إطار واحد الآن: أي latency، بـ batch size يساوي 1، ولهذا قاست الشريحة 5 بهذه الطريقة. أما مركز البيانات الذي يفهرس الفيديوهات طوال الليل فيحتاج إلى مقاطع في الساعة: أي throughput، بأي batch size يملأ الـ GPU. ومشروعك البحثي يقع في الجانب الأول من هذا الخط.

Quick checkاختبار سريع

Design 2 processes 4 images in parallel in 100 ms. What are its latency and throughput?التصميم 2 يعالج 4 صور بالتوازي في 100 ms. ما الـ latency والـ throughput له؟

Recall

A design processes 8 images together every 200 ms. What are its latency and throughput, and what would the naive reciprocal give?تصميم يعالج 8 صور معًا كل 200 ms. ما الـ latency والـ throughput له، وماذا سيعطي المقلوب الساذج؟

Latency 200 ms per image. Throughput 8 / 0.2 = 40 image/s. The reciprocal 1 / 0.2 = 5 per second is wrong by the batch size.
الـ latency هو 200 ms لكل صورة. الـ throughput هو 8 / 0.2 = 40 image/s. أما المقلوب 1 / 0.2 = 5 في الثانية فخاطئ بمقدار الـ batch size.

Concept 2 left a puzzle: MACs fell 5.2x but latency fell 13.9x. To resolve it you need a model of where the milliseconds go. Watch one layer execute. The processor loads the input activations, loads the layer's weights, multiplies and accumulates, and stores the output activations. Two of those steps are arithmetic; the other two are data movement. Real hardware does not wait for one to finish before starting the other. While the multipliers chew on the current tile, the memory system is already fetching the next weights, so the two streams run side by side and the layer finishes when the slower stream finishes.

ترك المفهوم 2 لغزًا: انخفضت الـ MACs بمقدار 5.2x لكن الـ latency انخفض بمقدار 13.9x. لحله تحتاج إلى نموذج لمكان ذهاب الملّي ثواني. راقب طبقة واحدة وهي تُنفَّذ. يحمّل المعالج الـ activations الداخلة، ويحمّل أوزان الطبقة، ويضرب ويجمع (multiply and accumulate)، ثم يخزّن الـ activations الخارجة. خطوتان من هذه الخطوات حساب، والخطوتان الأخريان نقل بيانات. والعتاد الحقيقي لا ينتظر انتهاء إحداهما قبل بدء الأخرى. فبينما تعمل وحدات الضرب على الجزء (tile) الحالي، يكون نظام الذاكرة قد بدأ بالفعل في جلب الأوزان التالية، فيجري التياران جنبًا إلى جنب وتنتهي الطبقة عندما ينتهي التيار الأبطأ.

Data movement and computation run on parallel tracks. The memory track sits idle while the multipliers catch up and stores the last outputs only after the last MAC, so the layer takes as long as the busier track, which is why the estimate is a max and not a sum.يجري نقل البيانات والحساب على مسارين متوازيين. يبقى مسار الذاكرة خاملًا بينما تلحق وحدات الضرب، ولا يخزّن المخرجات الأخيرة إلا بعد آخر MAC، لذا تستغرق الطبقة مدة المسار الأكثر انشغالًا، ولهذا يكون التقدير max لا مجموعًا.
Latency≈max⁡(Tcomputation,  Tmemory)\text{Latency} \approx \max\left(T_{\text{computation}},\; T_{\text{memory}}\right)
The two overlapped streamsالتدفقان المتداخلان
Tcomputation≈number of operations in the modeloperations per second the processor can doT_{\text{computation}} \approx \frac{\text{number of operations in the model}}{\text{operations per second the processor can do}}
NN specification over hardware specificationمواصفات الشبكة العصبية مقسومة على مواصفات العتاد
Tmemory≈Tmove(activations)+Tmove(weights)T_{\text{memory}} \approx T_{\text{move}}(\text{activations}) + T_{\text{move}}(\text{weights})
Both kinds of data must cross the same memory bus, so these addكلا نوعي البيانات يجب أن يعبر ناقل الذاكرة نفسه، لذلك يُجمعان
Tmove(weights)≈model sizememory bandwidth,Tmove(activations)≈input activation size+output activation sizememory bandwidthT_{\text{move}}(\text{weights}) \approx \frac{\text{model size}}{\text{memory bandwidth}}, \qquad T_{\text{move}}(\text{activations}) \approx \frac{\text{input activation size} + \text{output activation size}}{\text{memory bandwidth}}
Bytes over bytes per secondبايتات مقسومة على بايتات في الثانية

Computation time is the operation count divided by the rate at which the processor retires operations. Memory time is the bytes that must move divided by the memory bandwidth, once for the weights and once for the activations in and out. Now look at the colour coding on the slide, because it is the sentence the exam wants. Every numerator is a property of the network: operations, model size, activation sizes. Every denominator is a property of the processor: operations per second, bandwidth. That split is the NN specification versus hardware specification distinction, and it makes efficiency a co-design problem. You change numerators by redesigning the network, denominators by choosing hardware, and latency by whichever of the two you can actually afford to change.

Computation time (زمن الحساب) هو عدد العمليات مقسومًا على المعدل الذي ينجز به المعالج العمليات. Memory time (زمن الذاكرة) هو البايتات التي يجب نقلها مقسومة على memory bandwidth، مرة للأوزان ومرة للـ activations الداخلة والخارجة. انظر الآن إلى ترميز الألوان في الشريحة، لأنه الجملة التي يريدها الاختبار. كل بسط خاصية للشبكة: العمليات، حجم النموذج، أحجام الـ activations. وكل مقام خاصية للمعالج: العمليات في الثانية، عرض النطاق. هذا الانقسام هو تمييز NN specification versus hardware specification، وهو يجعل الكفاءة مسألة تصميم مشترك (co-design). تغيّر البسوط بإعادة تصميم الشبكة، والمقامات باختيار العتاد، والـ latency بأيهما تستطيع فعلًا تحمّل تغييره.

TermالحدNumerator: NN specificationالبسط: مواصفة الشبكة (NN specification)Denominator: hardware specificationالمقام: مواصفة العتاد (hardware specification)
T_computationT_computationNumber of operations in the model (MACs, OPs: part 04)عدد العمليات في النموذج (MACs، OPs: الجزء 04)Operations per second of the processor (OPS)عدد العمليات التي ينجزها المعالج في الثانية (OPS)
T_move(weights)T_move(weights)Model size (part 02)حجم النموذج (الجزء 02)Memory bandwidthعرض نطاق الذاكرة (memory bandwidth)
T_move(activations)T_move(activations)Input activation size + output activation size (peak #activations: part 03)حجم الـ activation الداخلة + حجم الـ activation الخارجة (العدد الأقصى للـ activations: الجزء 03)Memory bandwidthعرض نطاق الذاكرة (memory bandwidth)
Where each term of the model comes from, and which later part counts itمن أين يأتي كل حد في النموذج، وأي جزء لاحق يحسبه

The same model appears in the industry literature under different names. NVIDIA's GPU performance guide states that memory time is bytes accessed divided by memory bandwidth, math time is operations divided by math bandwidth, and the longer of the two shows what limits performance: math-limited if math time is longer, memory-limited if memory time is longer. The roofline model of Williams, Waterman and Patterson (CACM 2009) writes the same idea as a rate, attainable performance = min(peak compute, bandwidth x operational intensity). The vocabulary to adopt is compute-bound when T_computation wins and memory-bound when T_memory wins. One caution before using datasheet numbers: dividing by a peak OPS figure gives a floor on T_computation, not an estimate of it, because real kernels rarely keep every multiplier busy. The measured time over that floor is the inverse of the utilisation the runtime achieved.

يظهر النموذج نفسه في أدبيات الصناعة بأسماء مختلفة. يذكر دليل أداء الـ GPU من NVIDIA أن زمن الذاكرة هو البايتات المقروءة مقسومة على عرض نطاق الذاكرة، وزمن الحساب (math time) هو العمليات مقسومة على عرض نطاق الحساب (math bandwidth)، والأطول بينهما يبيّن ما يحدّ الأداء: math-limited إذا كان زمن الحساب أطول، وmemory-limited إذا كان زمن الذاكرة أطول. ونموذج الـ roofline لـ Williams وWaterman وPatterson (CACM 2009) يكتب الفكرة نفسها في صورة معدّل: attainable performance = min(peak compute, bandwidth x operational intensity). والمصطلحات التي تعتمدها هي compute-bound عندما يكون T_computation هو الأكبر، وmemory-bound عندما يكون T_memory هو الأكبر. تحذير واحد قبل استخدام أرقام ورقة البيانات (datasheet): القسمة على رقم OPS الأقصى تعطي حدًا أدنى لـ T_computation، لا تقديرًا له، لأن الـ kernels الحقيقية نادرًا ما تُبقي كل وحدات الضرب مشغولة. والزمن المقيس مقسومًا على هذا الحد الأدنى هو مقلوب نسبة الاستغلال (utilisation) التي حققها الـ runtime.

Worked example A: a toy model and two processorsالمثال المحلول A: نموذج مبسّط ومعالجان

Worked exampleمثال محلول

Toy numbers that show the regime flippingأرقام مبسّطة تُظهر انقلاب نظام التشغيل (regime)

  1. Start on a 100 GOPS processorابدأ على معالج 100 GOPS

    The model has 1 GOP of work, so T_computation = 1e9 / 1e11 = 10 ms. Weights are 50 MB and activations in plus out are 20 MB, over 10 GB/s: T_weights = 5 ms, T_activations = 2 ms, T_memory = 7 ms. Latency ≈ max(10, 7) = 10 ms, compute-bound.
    في النموذج 1 GOP من العمل، إذن T_computation = 1e9 / 1e11 = 10 ms. الأوزان 50 MB والـ activations الداخلة والخارجة معًا 20 MB، عبر 10 GB/s: T_weights = 5 ms، T_activations = 2 ms، T_memory = 7 ms. الـ Latency ≈ max(10, 7) = 10 ms، أي compute-bound.
  2. Buy a 200 GOPS processorاشترِ معالجًا بسرعة 200 GOPS

    T_computation halves to 5 ms, but T_memory is still 7 ms. Latency ≈ max(5, 7) = 7 ms, not 5 ms. The model became memory-bound and 2 ms of the new compute sits idle every inference.
    ينخفض T_computation إلى النصف ليصبح 5 ms، لكن T_memory ما زال 7 ms. الـ Latency ≈ max(5, 7) = 7 ms، لا 5 ms. أصبح النموذج memory-bound، و2 ms من قدرة الحساب الجديدة تبقى خاملة في كل استدلال.
  3. Quantize the weights to 8-bit insteadبدلًا من ذلك، كمّم الأوزان إلى 8-bit

    Model size drops to 12.5 MB (part 02 shows why), so T_weights = 1.25 ms and T_memory = 3.25 ms. On the fast processor latency is back to max(5, 3.25) = 5 ms: the hardware upgrade only paid off once the network side shrank too.
    ينخفض حجم النموذج إلى 12.5 MB (يبيّن الجزء 02 السبب)، إذن T_weights = 1.25 ms وT_memory = 3.25 ms. على المعالج السريع يعود الـ latency إلى max(5, 3.25) = 5 ms: لم تؤتِ ترقية العتاد ثمارها إلا بعد أن صغُر جانب الشبكة أيضًا.
  4. Three configurationsثلاثة إعدادات

    ConfigurationالإعدادT_computationT_computationT_memoryT_memoryLatencyLatencyRegimeنظام التشغيل (regime)
    100 GOPS, 32-bit weightsمعالج 100 GOPS، أوزان 32-bit10 ms10 ms5 + 2 = 7 ms5 + 2 = 7 ms10 ms10 msCompute-boundCompute-bound
    200 GOPS, 32-bit weightsمعالج 200 GOPS، أوزان 32-bit5 ms5 ms5 + 2 = 7 ms5 + 2 = 7 ms7 ms7 msMemory-boundMemory-bound
    200 GOPS, 8-bit weightsمعالج 200 GOPS، أوزان 8-bit5 ms5 ms1.25 + 2 = 3.25 ms1.25 + 2 = 3.25 ms5 ms5 msCompute-boundCompute-bound
ModelنموذجLatency as max(T_computation, T_memory)زمن الاستجابة بوصفه max(T_computation, T_memory)
light symbols are NN specification (numerators), teal symbols are hardware specification (denominators)الرموز الفاتحة هي مواصفات الشبكة العصبية (البسط)، والرموز الخضراء المزرقة هي مواصفات العتاد (المقام)
T_computation = N_ops / OPS10.0 ms
T_memory = T_weights + T_activations7.00 ms
T_weights = S_w / BW = 5.00 msT_activations = (S_in + S_out) / BW = 2.00 ms
Latency estimate10.0 msmax of the two barsالقيمة العظمى بين الشريطين
Regimecompute-bounda faster processor would helpالمعالج الأسرع سيفيد
Headroom1.43xhow much T_memory could grow before it becomes the bottleneckمقدار ما يمكن أن يزيده T_memory قبل أن يصبح هو عنق الزجاجة

The two Orin presets use 43 TFLOPS dense fp16 on the Tensor Cores and 204.8 GB/s from NVIDIA's Jetson AGX Orin page, MACs and parameters from the EfficientViT paper, and a 1024 × 2048 input with 19 output classes at 2 bytes each. Dividing by a peak rate gives a floor: measured latencies were 45.9 ms and 638 ms, 3.5x and 9.4x above it, and the gap shows what a first-order model leaves out.يستخدم إعدادا Orin المسبقان قيمة 43 TFLOPS بدقة fp16 الكثيفة على Tensor Cores وقيمة 204.8 GB/s من صفحةJetson AGX Orin لدى NVIDIA، ويأخذان عدد MACs والمعاملات من ورقة EfficientViT، مع مُدخل بحجم 1024 × 2048و19 فئة في المُخرج، بمقدار 2 بايت لكل قيمة. القسمة على معدل الذروة تعطي حدًا أدنى: كانت أزمنة الاستجابة المقيسة 45.9 msو638 ms، أي أعلى منه بمقدار 3.5x و9.4x، وتكشف هذه الفجوة ما يغفله نموذج الرتبة الأولى.

Worked example B: back to slide 5المثال المحلول B: عودة إلى الشريحة 5

Worked exampleمثال محلول

Predicting the Orin numbers from public specificationsالتنبؤ بأرقام Orin من المواصفات المنشورة

  1. EfficientViT-L1, computationEfficientViT-L1، الحساب

    282 GMACs is 564 GFLOPs at two FLOPs per MAC (part 04). TensorRT runs fp16 convolutions and matrix multiplies on the Tensor Cores, which the Orin page rates at 43 dense FP16 TFLOPS (the CUDA cores alone would give 10.6), so T_computation ≈ 564 / 43 000 ≈ 13.1 ms.
    282 GMACs تساوي 564 GFLOPs باعتبار أن كل MAC تساوي اثنتين من الـ FLOPs (الجزء 04). يشغّل TensorRT عمليات الـ convolution وضرب المصفوفات بدقة fp16 على الـ Tensor Cores، التي تقدّرها صفحة Orin بـ 43 dense FP16 TFLOPS (أنوية CUDA وحدها كانت ستعطي 10.6)، إذن T_computation ≈ 564 / 43 000 ≈ 13.1 ms.
  2. EfficientViT-L1, memoryEfficientViT-L1، الذاكرة

    Weights: 40M x 2 bytes = 80 MB, over 204.8 GB/s gives 0.39 ms. Activations: input 3 x 1024 x 2048 x 2 B = 12.6 MB, output 19 x 1024 x 2048 x 2 B = 79.7 MB, sum 92.3 MB, over the same bandwidth 0.45 ms. T_memory ≈ 0.84 ms.
    الأوزان: 40M x 2 bytes = 80 MB، وعبر 204.8 GB/s تعطي 0.39 ms. الـ activations: المُدخل 3 x 1024 x 2048 x 2 B = 12.6 MB، والمُخرج 19 x 1024 x 2048 x 2 B = 79.7 MB، والمجموع 92.3 MB، وعبر عرض النطاق نفسه 0.45 ms. T_memory ≈ 0.84 ms.
  3. Compare with measurementقارن بالقياس

    Prediction max(13.1, 0.84) ≈ 13.1 ms, strongly compute-bound. Measured: 45.9 ms, 3.5x above the floor, so the runtime achieved roughly 29% of the Tensor Core peak. That is a normal utilisation for a real network: kernel launches, layers too small to fill the GPU, and intermediate activations moving between layers all sit outside the formula.
    التنبؤ max(13.1, 0.84) ≈ 13.1 ms، أي compute-bound بوضوح. المقيس: 45.9 ms، أي 3.5x فوق الحد الأدنى، فالـ runtime حقق تقريبًا 29% من ذروة الـ Tensor Cores. هذه نسبة استغلال طبيعية لشبكة حقيقية: إطلاق الـ kernels، والطبقات الأصغر من أن تملأ الـ GPU، والـ activations الوسيطة المنتقلة بين الطبقات، كلها تقع خارج الصيغة.
  4. SegFormer-B5 by the same recipeSegFormer-B5 بالوصفة نفسها

    1460 GMACs = 2920 GFLOPs, so T_computation ≈ 2920 / 43 000 ≈ 68 ms. Weights 85M x 2 B = 170 MB give 0.83 ms; the activations are the same 0.45 ms. Prediction ≈ 68 ms. Measured: 638 ms, 9.4x above the floor, about 11% utilisation.
    1460 GMACs = 2920 GFLOPs، إذن T_computation ≈ 2920 / 43 000 ≈ 68 ms. الأوزان 85M x 2 B = 170 MB تعطي 0.83 ms؛ والـ activations هي نفسها 0.45 ms. التنبؤ ≈ 68 ms. المقيس: 638 ms، أي 9.4x فوق الحد الأدنى، ونسبة استغلال تقارب 11%.
  5. Reading the two missesقراءة الفجوتين

    Both models land above the floor, as every real model does, but SegFormer misses by almost three times as much. The crude model counts only input and output activations. SegFormer's softmax attention materializes large intermediate attention maps that the formula never sees, which is exactly the memory traffic the EfficientViT paper set out to remove. The model is a first-order floor; the size of the miss tells you which term you forgot.
    كلا النموذجين يقع فوق الحد الأدنى، كما يحدث لكل نموذج حقيقي، لكن فجوة SegFormer تقارب ثلاثة أضعاف فجوة الآخر. النموذج المبسّط لا يحسب إلا الـ activations الداخلة والخارجة. أما الـ softmax attention في SegFormer فيُنشئ خرائط attention وسيطة كبيرة في الذاكرة لا تراها الصيغة أبدًا، وهذه بالضبط حركة الذاكرة التي سعت ورقة EfficientViT إلى إزالتها. النموذج حد أدنى من الرتبة الأولى؛ وحجم الفجوة يخبرك أي حد نسيته.
  6. Floor versus measurementالحد الأدنى مقابل القياس

    ModelالنموذجT_computationT_computationT_memoryT_memoryFloorالحد الأدنىMeasuredالمقيسMiss, utilisationالفجوة، نسبة الاستغلال
    EfficientViT-L1EfficientViT-L1564 / 43 000 = 13.1 ms564 / 43 000 = 13.1 ms0.39 + 0.45 = 0.84 ms0.39 + 0.45 = 0.84 ms13.1 ms13.1 ms45.9 ms45.9 ms3.5x, about 29%3.5x، قرابة 29%
    SegFormer-B5SegFormer-B52920 / 43 000 = 68 ms2920 / 43 000 = 68 ms0.83 + 0.45 = 1.3 ms0.83 + 0.45 = 1.3 ms68 ms68 ms638 ms638 ms9.4x, about 11%9.4x، قرابة 11%

Quick checkاختبار سريع

A model is memory-bound on its current processor. Which change is guaranteed to reduce its latency under the max model?نموذج memory-bound على معالجه الحالي. أي تغيير مضمون أن يخفض الـ latency له وفق نموذج الـ max؟

Recall

Write the latency model with its sub-formulas and label every term NN or hardware.اكتب نموذج الـ latency مع صيغه الفرعية وصنّف كل حد على أنه NN أو hardware.

Latency ≈ max(T_computation, T_memory). T_computation ≈ operations in the model (NN) / operations per second (hardware). T_memory ≈ model size (NN) / bandwidth (hardware) + (input + output activation size) (NN) / bandwidth (hardware).
Latency ≈ max(T_computation, T_memory). T_computation ≈ عدد العمليات في النموذج (NN) / العمليات في الثانية (hardware). T_memory ≈ حجم النموذج (NN) / عرض النطاق (hardware) + (حجم الـ activation الداخلة + الخارجة) (NN) / عرض النطاق (hardware).

Recall

Why max and not plus?لماذا max وليس جمعًا؟

Data movement and computation overlap on real hardware: the next weights load while the current ones are being multiplied. The layer therefore finishes when the slower of the two streams finishes, which is the max.
نقل البيانات والحساب يتداخلان على العتاد الحقيقي: الأوزان التالية تُحمَّل بينما تُضرب الأوزان الحالية. لذلك تنتهي الطبقة عندما ينتهي الأبطأ من التيارين، وهذا هو الـ max.

Recall

In the SegFormer versus EfficientViT comparison, MACs drop 5.2x but latency drops 13.9x. What does that tell you?في مقارنة SegFormer مع EfficientViT تنخفض الـ MACs بمقدار 5.2x لكن الـ latency ينخفض بمقدار 13.9x. ماذا يخبرك ذلك؟

MACs are only the numerator of T_computation. SegFormer's attention moves large intermediate activations, so a memory term the simple model ignores inflates its latency, and operation count alone under-predicts it.
الـ MACs ليست إلا بسط T_computation. الـ attention في SegFormer ينقل activations وسيطة كبيرة، فيتضخم الـ latency بسبب حد ذاكرة يتجاهله النموذج المبسّط، ويصبح عدد العمليات وحده تنبؤًا أقل من الحقيقة.

The third cost is energy, and slide 9 settles where it goes with one table. In a 45 nm process at 0.9 V, a 32-bit integer add costs 0.1 pJ and a 32-bit integer multiply 3.1 pJ. Reading one 32-bit word from DRAM costs 640 pJ. The multiply is the most expensive arithmetic on the list, and the memory access is two hundred times dearer than it.

التكلفة الثالثة هي الطاقة، والشريحة 9 تحسم أين تذهب بجدول واحد. في تقنية تصنيع 45 nm عند 0.9 V، تكلف عملية جمع صحيحة بطول 32-bit مقدار 0.1 pJ، وعملية ضرب صحيحة بطول 32-bit مقدار 3.1 pJ. وقراءة كلمة واحدة بطول 32-bit من الـ DRAM تكلف 640 pJ. الضرب هو أغلى عملية حسابية في القائمة، والوصول إلى الذاكرة أغلى منه مئتي مرة.

Rough energy per operation, 45 nm, 0.9 V, 32-bit (slide 9, after Horowitz 2014 as tabulated by Han et al. 2015)الطاقة التقريبية لكل عملية، 45 nm، 0.9 V، 32-bit (الشريحة 9، عن Horowitz 2014 كما جدولها Han et al. 2015)

int ADD
0.1 pJ0.1 pJ
float ADD
0.9 pJ0.9 pJ
Register file accessالوصول إلى ملف السجلات (register file)
1 pJ1 pJ
int MULT
3.1 pJ3.1 pJ
float MULT
3.7 pJ3.7 pJ
SRAM cache accessالوصول إلى ذاكرة SRAM المخبئية (cache)
5 pJ5 pJ
DRAM memory accessالوصول إلى ذاكرة DRAM
640 pJ640 pJ
On a log axis each grid step is ten times more energy. The six arithmetic and on-chip bars fit in the first two decades; DRAM sits two more decades out from SRAM (640 / 5 = 128x) and almost four decades from the int ADD bar.على محور لوغاريتمي، كل خطوة في الشبكة تعني طاقة أكبر بعشرة أضعاف. الأعمدة الستة للحساب وللذاكرة داخل الشريحة تقع في أول مرتبتين عشريتين؛ أما DRAM فتبعد مرتبتين إضافيتين عن SRAM (640 / 5 = 128x) وقرابة أربع مراتب عن عمود int ADD.

Three ratios from that table are worth memorizing. DRAM over integer multiply is 640 / 3.1 ≈ 206, which the slide rounds to 200x. DRAM over SRAM is 640 / 5 = 128, so keeping data on-chip is worth two orders of magnitude on its own. And float add over integer add is 0.9 / 0.1 = 9, a seed for quantization: the same arithmetic in integers is nine times cheaper per add. Han et al. summarize the whole table in one line, that memory access is three orders of magnitude more energy expensive than simple arithmetic (640 / 0.1 = 6400).

ثلاث نسب من هذا الجدول تستحق الحفظ. الـ DRAM مقابل الضرب الصحيح هي 640 / 3.1 ≈ 206، وتقرّبها الشريحة إلى 200x. الـ DRAM مقابل SRAM هي 640 / 5 = 128، فإبقاء البيانات داخل الشريحة (on-chip) يساوي وحده مرتبتين عشريتين. والجمع العشري مقابل الجمع الصحيح هو 0.9 / 0.1 = 9، وهي بذرة للـ quantization: الحساب نفسه بالأعداد الصحيحة أرخص تسع مرات لكل عملية جمع. يلخص Han et al. الجدول كله في سطر واحد: الوصول إلى الذاكرة أغلى في الطاقة من الحساب البسيط بثلاث مراتب عشرية (640 / 0.1 = 6400).

The chain the slide writes across the top follows directly: data movement means more memory references, and more memory references mean more energy. Horowitz's own framing in the ISSCC 2014 talk is that a DRAM access at 1 to 2 nJ is a couple of orders of magnitude above a cache access or a functional operation at around 10 pJ, and that even with better I/O circuits DRAM will stay expensive, around 0.6 nJ per 8 bytes, because requests and data still have to travel a long physical distance. The slide's 640 pJ per 32-bit word is about half of the 1.3 nJ per 64-bit access in his Figure 1.1.9, as the provenance note below explains.

السلسلة التي تكتبها الشريحة في أعلاها تتبع مباشرة: data movement (نقل البيانات) يعني مراجع ذاكرة أكثر، ومراجع الذاكرة الأكثر تعني طاقة أكثر. إطار Horowitz نفسه في محاضرة ISSCC 2014 هو أن الوصول إلى الـ DRAM بتكلفة 1 إلى 2 nJ يزيد بمرتبتين عشريتين تقريبًا على الوصول إلى الـ cache أو على عملية وظيفية بتكلفة نحو 10 pJ، وأن الـ DRAM سيبقى مكلفًا حتى مع دوائر إدخال وإخراج (I/O) أفضل، بنحو 0.6 nJ لكل 8 بايتات، لأن الطلبات والبيانات ما زالت مضطرة لقطع مسافة فيزيائية طويلة. ورقم الشريحة 640 pJ لكل كلمة 32-bit يساوي تقريبًا نصف 1.3 nJ لكل وصول 64-bit في الشكل 1.1.9 عنده، كما تشرح ملاحظة المصدر أدناه.

The log axis of the slide's chart is not decoration either. On a linear axis the six small bars would be invisible next to DRAM; a 0.1 pJ bar next to a 640 pJ bar is a pixel next to a page. Only a logarithmic axis can show both, and it is the honest way to read any table whose entries span four decades.

المحور اللوغاريتمي في رسم الشريحة ليس زخرفة كذلك. على محور خطي ستختفي الأعمدة الستة الصغيرة بجانب الـ DRAM؛ فعمود 0.1 pJ بجانب عمود 640 pJ مثل بكسل بجانب صفحة. وحده المحور اللوغاريتمي يستطيع إظهار الاثنين، وهو الطريقة الأمينة لقراءة أي جدول تمتد قيمه عبر أربع مراتب عشرية.

Worked example: AlexNet's energy billمثال محلول: فاتورة الطاقة لـ AlexNet

Worked exampleمثال محلول

Arithmetic versus weight fetch for one AlexNet inferenceالحساب مقابل جلب الأوزان في استدلال واحد لـ AlexNet

  1. Arithmetic in 32-bit integersالحساب بأعداد صحيحة 32-bit

    AlexNet runs 724M MACs per image (part 04). Each is one multiply and one add: 724e6 x (3.1 + 0.1) pJ = 2.32 mJ.
    AlexNet ينفّذ 724M MACs لكل صورة (الجزء 04). كل واحدة منها ضرب واحد وجمع واحد: 724e6 x (3.1 + 0.1) pJ = 2.32 mJ.
  2. Weights read once from DRAMقراءة الأوزان مرة واحدة من DRAM

    AlexNet has 61M parameters (part 02). Reading each once as a 32-bit word: 61e6 x 640 pJ = 39.0 mJ. That is 16.8x the arithmetic, before a single activation has moved.
    لـ AlexNet 61M parameters (الجزء 02). قراءة كل منها مرة واحدة ككلمة 32-bit: 61e6 x 640 pJ = 39.0 mJ. أي 16.8x من الحساب، قبل أن تتحرك activation واحدة.
  3. Two alternativesبديلان

    Keep the same weights in SRAM: 61e6 x 5 pJ = 0.31 mJ, cheaper than the arithmetic. Or keep DRAM but use float arithmetic: 724e6 x (3.7 + 0.9) = 3.33 mJ, still twelve times below the DRAM bill.
    احتفظ بالأوزان نفسها في الـ SRAM: 61e6 x 5 pJ = 0.31 mJ، وهذا أرخص من الحساب. أو أبقِ الـ DRAM لكن استخدم الحساب العشري: 724e6 x (3.7 + 0.9) = 3.33 mJ، وما زال أقل من فاتورة الـ DRAM باثنتي عشرة مرة.
  4. Two orders of magnitude versus a factor of twoمرتبتان عشريتان مقابل عامل اثنين

    Changing where the weights live changes the total by two orders of magnitude; changing how the arithmetic is done changes it by less than a factor of two.
    تغيير مكان الأوزان يغيّر المجموع بمرتبتين عشريتين؛ أما تغيير طريقة إجراء الحساب فيغيّره بأقل من الضعف.
  5. The bill, line by lineالفاتورة، بندًا بندًا

    ItemالبندCountالعددEnergy eachالطاقة لكل عمليةTotalالمجموع
    Integer MACs (multiply + add)عمليات MAC صحيحة (ضرب + جمع)724M724M3.1 + 0.1 = 3.2 pJ3.1 + 0.1 = 3.2 pJ2.32 mJ2.32 mJ
    Weights read once from DRAMالأوزان مقروءة مرة واحدة من DRAM61M61M640 pJ640 pJ39.0 mJ39.0 mJ
    Same weights read from SRAMالأوزان نفسها مقروءة من SRAM61M61M5 pJ5 pJ0.31 mJ0.31 mJ
    Float MACs instead of integerعمليات MAC عشرية بدلًا من الصحيحة724M724M3.7 + 0.9 = 4.6 pJ3.7 + 0.9 = 4.6 pJ3.33 mJ3.33 mJ
CalculatorحاسبةEnergy of one inference, operation by operationطاقة استدلال واحد، عملية بعملية
1,000,000 × 0.1 pJ
100 nJ
0 × 0.9 pJ
0.0 pJ
0 × 1 pJ
0.0 pJ
1,000,000 × 3.1 pJ
3.10 µJ
0 × 3.7 pJ
0.0 pJ
100,000 × 5 pJ
500 nJ
10,000 × 640 pJ
6.40 µJ
bars use a log scale from 1 pJ to the largest row, so equal steps are ten times more energyتستخدم الأشرطة مقياسًا لوغاريتميًا من 1 pJ حتى أكبر صف، فكل خطوة متساوية تعني طاقة أكبر بعشر مرات
linear share of the total: light is arithmetic, teal is memory accessالحصة الخطية من المجموع: الفاتح هو العمليات الحسابية، والأخضر المزرق هو الوصول إلى الذاكرة
Total energy10.1 µJ
Arithmetic3.20 µJadds and multipliesعمليات الجمع والضرب
Memory access6.90 µJDRAM alone: 63% of totalDRAM وحدها: 63% من المجموع

Per-operation costs are the 45 nm, 0.9 V figures from slide 9 (Horowitz 2014, as tabulated by Han et al. 2015). The AlexNet presets use 724M MACs as one multiply plus one add each, and one fetch per weight for its 61M weights.تكاليف كل عملية هي أرقام 45 nm و0.9 V من الشريحة 9 (Horowitz 2014، كما جدولها Han et al. 2015). تستخدم إعداداتAlexNet المسبقة 724M عملية MAC، تُحسب كل منها عملية ضرب واحدة وعملية جمع واحدة، وجلبًا واحدًا لكل وزن من أوزانها البالغة 61M.

Every efficiency technique later in the course can be read as a way of cutting that memory line. Keep weights in on-chip SRAM, which is 128x cheaper per access than DRAM. Reuse each fetched value as many times as possible before it leaves the chip; Horowitz notes that efficient designs complete on the order of a thousand operations per DRAM fetch. And make the model small enough to fit on-chip in the first place, which is what model size in part 02, peak activations in part 03, and pruning and quantization later in the course are all about.

كل تقنية كفاءة لاحقة في المقرر يمكن قراءتها على أنها طريقة لخفض بند الذاكرة هذا. احتفظ بالأوزان في الـ SRAM داخل الشريحة، فهي أرخص بمقدار 128x لكل وصول من الـ DRAM. أعد استخدام كل قيمة مجلوبة أكبر عدد ممكن من المرات قبل أن تغادر الشريحة؛ ويذكر Horowitz أن التصاميم الكفؤة تنجز نحو ألف عملية لكل جلب من الـ DRAM. واجعل النموذج صغيرًا بما يكفي ليتسع داخل الشريحة من الأساس، وهذا هو موضوع model size في الجزء 02، وpeak activations في الجزء 03، والـ pruning والـ quantization لاحقًا في المقرر.

Quick checkاختبار سريع

In the 45 nm table, how does one 32-bit DRAM access compare with one 32-bit integer multiply?في جدول 45 nm، كيف يقارن وصول واحد بطول 32-bit إلى DRAM بعملية ضرب صحيحة واحدة بطول 32-bit؟

Recall

Quote the DRAM to integer multiply energy ratio, the numbers behind it, and the process conditions.اذكر نسبة طاقة DRAM إلى الضرب الصحيح، والأرقام التي خلفها، وظروف تقنية التصنيع.

640 pJ / 3.1 pJ ≈ 206, quoted as 200x. Conditions: 45 nm, 0.9 V, 32-bit operations, Horowitz ISSCC 2014 via Han et al. 2015.
640 pJ / 3.1 pJ ≈ 206، وتُذكر على أنها 200x. الظروف: 45 nm، و0.9 V، وعمليات 32-bit، من Horowitz ISSCC 2014 عبر Han et al. 2015.

Recall

For one AlexNet inference, how does the energy of fetching every weight once from DRAM compare with the energy of all its integer MACs?في استدلال واحد لـ AlexNet، كيف تقارن طاقة جلب كل وزن مرة واحدة من DRAM بطاقة كل عمليات MAC الصحيحة فيه؟

61M x 640 pJ = 39 mJ for the weights against 724M x 3.2 pJ = 2.3 mJ for the arithmetic, about 17x. Moving the weights to SRAM drops the fetch cost to 0.31 mJ.
61M x 640 pJ = 39 mJ للأوزان مقابل 724M x 3.2 pJ = 2.3 mJ للحساب، أي قرابة 17x. نقل الأوزان إلى الـ SRAM يخفض تكلفة الجلب إلى 0.31 mJ.

Recapالخلاصة

If you remember nothing elseإن لم تتذكر شيئاً آخر فتذكّر هذا

  • Three goals (smaller, faster, greener) map to three costs (storage, latency, energy). All three are driven by two resources, computation and memory, so the metrics split into memory-related and computation-related.ثلاثة أهداف (أصغر، أسرع، أكثر خضرة) تقابلها ثلاث تكاليف (التخزين، الـ latency، الطاقة). والثلاث كلها يحركها مَوردان فقط هما الحساب والذاكرة، لذلك تنقسم المقاييس إلى مقاييس متعلقة بالذاكرة ومقاييس متعلقة بالحساب.
  • Latency is the delay for one task. SegFormer-B5 takes 638 ms and EfficientViT-L1 takes 45.9 ms on Jetson AGX Orin with TensorRT, fp16, batch size 1: a 13.9x gap at equal or better mIoU.الـ latency هو التأخير لمهمة واحدة. يستغرق SegFormer-B5 مدة 638 ms ويستغرق EfficientViT-L1 مدة 45.9 ms على Jetson AGX Orin مع TensorRT وfp16 وbatch size يساوي 1: فارق 13.9x مع mIoU مساوٍ أو أفضل.
  • A latency number without hardware, runtime, precision and batch size is not comparable to any other.رقم latency لا يذكر العتاد والـ runtime والدقة العددية والـ batch size لا يمكن مقارنته بأي رقم آخر.
  • Throughput is items per second. Batching raises it (Design 2: 40 image/s) while raising latency (100 ms). Throughput equals 1 / latency only with batch size 1 and no parallelism.الـ throughput هو عدد العناصر في الثانية. الـ batching يرفعه (التصميم 2: 40 image/s) ويرفع معه الـ latency (100 ms). لا يساوي الـ throughput مقلوب الـ latency (1 / latency) إلا مع batch size يساوي 1 ومن دون أي توازي.
  • Latency ≈ max(T_computation, T_memory) because data movement and computation overlap. Numerators are NN specification, denominators are hardware specification.Latency ≈ max(T_computation, T_memory) لأن نقل البيانات والحساب يتداخلان زمنيًا. البسوط مواصفات الشبكة (NN)، والمقامات مواصفات العتاد.
  • A faster processor helps only when compute-bound. A memory-bound model needs smaller weights, smaller activations or more bandwidth.المعالج الأسرع يفيد فقط عندما يكون النموذج compute-bound. أما النموذج الـ memory-bound فيحتاج أوزانًا أصغر أو activations أصغر أو عرض نطاق (bandwidth) أكبر.
  • At 45 nm and 0.9 V: int ADD 0.1 pJ, int MULT 3.1 pJ, SRAM 5 pJ, DRAM 640 pJ. One DRAM access costs about 206 int multiplies, and a float ADD costs 9 int ADDs.عند 45 nm و0.9 V: int ADD تكلف 0.1 pJ، وint MULT تكلف 3.1 pJ، وSRAM تكلف 5 pJ، وDRAM تكلف 640 pJ. وصول واحد إلى DRAM يكلف قرابة 206 عملية ضرب صحيحة، وfloat ADD واحدة تكلف 9 أضعاف int ADD.
  • Fetching AlexNet's 61M weights once from DRAM (39 mJ) costs about 17 times its 724M MACs of integer arithmetic (2.3 mJ).جلب أوزان AlexNet البالغة 61M مرة واحدة من DRAM (39 mJ) يكلف قرابة 17 ضعف حساباتها الصحيحة البالغة 724M MACs (2.3 mJ).

Sourcesالمصادر