EfficientML.ai Lecture 11 - TinyEngine and Parallel Processing (MIT 6.5940 Fall 2026)
Overview
The lecture connects TinyEngine's MCU inference work to parallel-processing techniques that improve neural-network execution without changing model outputs. It covers loop ordering, tiling and unrolling; SIMD, pthreads, OpenMP and CUDA; and convolution methods including im2col, in-place depthwise convolution, layout selection and Winograd, with examples reporting speedups of roughly 12x, 20x, 3x and 100x for different optimizations.
Key takeaways
- Changing row-major matrix multiplication from i-j-k to i-k-j improves sequential access to B; the lecture's example reports about 12x faster execution.
- Cache tiling reduces the active working set so matrix blocks can be reused before eviction; nested tiles can target L1 and L2, with one example improving runtime from 24 seconds to 1.2 seconds.
- SIMD, CPU multithreading and CUDA expose parallelism at different levels: vector lanes process multiple values, CPU threads split work across cores, and CUDA threads map work across GPU blocks.
- CUDA performance depends on data movement as well as computation: block threads can cooperatively stage matrix tiles in shared memory, but host-device transfers and kernel launches add end-to-end overhead.
- In-place depthwise convolution can reduce activation storage from about 2 × C × H × W to approximately one output-channel buffer plus the retained activations, a substantial saving for SRAM-limited devices.
- Convolution optimizations target different bottlenecks: implicit GEMM avoids im2col's duplicated intermediate storage, layout selection improves locality, and Winograd reduces multiplication counts for small filters.
Chapters
- MCUNet addresses model size and activation compression for microcontrollers with only hundreds of kilobytes of on-device memory; TinyEngine focuses on the inference engine.
- Edge inference can reduce latency, preserve privacy and avoid the energy and communication costs of sending data to the cloud.
- Microcontrollers have far fewer cores, lower clock rates and less SRAM than laptop processors, often without a GPU or operating system, making deliberate resource management essential.
- For row-major matrices, the conventional i-j-k loop order accesses matrix B by columns, creating poor cache locality.
- Changing the iteration order to i-k-j makes accesses to A and B more sequential, while accepting less locality for output matrix C.
- The lecture reports roughly a 12x speedup from loop reordering in its matrix-multiplication example.
- Loop tiling divides a large matrix-multiplication iteration space into smaller blocks so reused data can remain in cache.
- Tiling the output-column and reduction dimensions reduces the active A, B and C regions; tile sizes should be chosen to fit the target cache.
- Nested tiling can map different block sizes to L1 and L2 caches, and the example reduces runtime from about 24 seconds to 1.2 seconds, roughly 20x.
- Unrolling a loop by four replicates its body, reducing index updates and loop-bound checks to about one quarter as often while increasing code size.
- The lecture notes that non-divisible loop lengths require a separate remainder path, and that useful unroll factors depend on measurement and whether a loop is performance-critical.
- Unrolling the J and K loops in the matrix-multiplication example yields roughly a 3x speedup without other optimizations.
- An instruction set architecture defines the software-hardware interface, including arithmetic, comparison, branching, load/store and I/O operations.
- The lecture contrasts complex instruction set architectures such as x86 with reduced instruction set architectures such as ARM and RISC-V.
- SIMD processes multiple values with one instruction; the examples use x86 SSE and ARM vector instructions to handle four 32-bit floating-point values at once.
- For SIMD matrix multiplication, transposing B supports contiguous vector loads and preserves favorable memory access.
- CPU threads share process code and data but maintain separate registers, stacks and program counters, allowing work to run concurrently on multiple cores.
- The pthreads matrix-multiplication example assigns each thread a range of rows of A and the corresponding rows of C.
- Pthreads uses explicit thread creation and joining, with each worker calculating its row range independently.
- OpenMP uses compiler directives to express parallel work while handling much of the thread management and synchronization.
- Adding a parallel-for directive to the outer i loop distributes matrix rows across workers.
- The example sets a four-thread team and parallelizes the same independent row workload that required more manual management with pthreads.
- CUDA extends a C-like programming model to NVIDIA GPUs, calling the CPU the host and the GPU the device.
- CUDA organizes execution as threads within blocks and blocks within grids, with one-, two- or three-dimensional indexing.
- For adding two 12-by-6 matrices, the example maps 72 GPU threads to the 72 output elements using block and thread indices.
- Host and device use distinct address spaces; CUDA allocation and copy operations move data between CPU and GPU memory.
- CUDA distinguishes global memory shared across the GPU, shared memory visible within a block, and thread-private registers.
- In tiled matrix multiplication, threads cooperatively load A and B tiles into shared memory, synchronize, compute partial dot products and write outputs.
- The simple GPU implementation is reported as roughly 100x faster than the CPU example, though launch and transfer overhead make end-to-end latency longer than kernel time.
- NVIDIA Tensor Cores use matrix-multiply-accumulate instructions to perform small matrix tiles at much higher throughput than ordinary CUDA cores.
- The lecture compares about 67 TFLOPS for CUDA cores with roughly 4,000 TFLOPS for a sparse Tensor Core configuration on an H100, noting that the figures depend on workload and mode.
- An MMA operation such as a 16-by-16-by-8 tile produces a partial output tile; multiple tile products accumulate to form larger matrix results.
- Im2col flattens each convolution receptive field, such as a k-by-k-by-C patch, into a row and reshapes filters into a matrix.
- The transformed operation can reuse highly optimized matrix-multiplication kernels.
- Overlapping receptive fields duplicate input values and consume extra memory; implicit GEMM avoids materializing the full im2col matrix by reading from the original tensors.
- MobileNetV2's inverted residual block expands channels, applies depthwise convolution and then projects back, so expanded activations can drive peak SRAM use.
- A conventional depthwise implementation keeps separate input and output maps, requiring about 2 × C × H × W activation storage.
- An in-place method uses one H-by-W temporary buffer and writes each completed output channel back to its input channel, reducing peak activation storage by roughly half.
- NHWC stores channels contiguously, making it suitable for pointwise 1-by-1 convolution, which combines channels at each spatial position.
- NCHW keeps each channel's spatial map together, supporting depthwise convolution that processes channels independently.
- The TinyEngine and MCUNet approach selects NHWC for pointwise convolution and NCHW for depthwise convolution to improve locality.
- A direct 3-by-3 convolution requires nine filter multiplications per output position per input channel; computing four outputs takes 36 such multiplications per channel.
- Winograd transforms the input tile and filter, multiplies transformed elements, then transforms the result back, reducing the multiplication count for small convolution tiles.
- The described transforms use simple coefficients such as 0, 1 and one-half, allowing much of the transform work to use additions and subtractions rather than general matrix multiplication.
- TinyEngine combines inference optimizations to support on-device vision workloads for MCUNet; TinyChatEngine applies related system optimizations to local language-model inference.
- The lecture points learners to open-source implementations and a parallel-computing tutorial for hands-on practice.
- The closing principle is that these transformations aim to preserve mathematically equivalent model outputs while reducing execution time or memory use.
Transcript excerpt
0:01 Okay. All right everyone let's get started with today's lecture. So today we are going to talk about uh tiny engine and the parallel processing. So if you'll still remember last week we discussed uh MCNET which is about you know compress uh uh deploying models uh compress both weights and activations to fit in into very age devices like microcontrollers with uh hundreds of kilobytes of ondevice memory and so that's mainly about the model part like how do we optimize the model architectures how do we pruning how do we compress the model and do uh new architecture search. So today we are going to talk about the uh inference engine part of the MCUNET the tiny
0:49 engine and we will also cover uh something related to parallel computing such as uh mod thread computing and a brief introduction to the uh GPU uh GPU and CUDA coding. So uh this is the overview of today's lecture. uh we will begin with edge AI and the constraints of microcontrollers. So you can uh regard it as a very brief recap of the last lectures contents and the main focus for today's parallel computing include you know loop optimizations uh SIMD computing and multi- threading and CUDA as well. So we will cover inference optimizations such as uh image to column uh which you
1:37 are already very familiar with it in deep learning course and we will also talk about in place steps wise convolution uh memory layout and uh another optimization named the window convolution. So let's get started with a brief introduction uh to the edge AI and some motivation of running neuronet networks directly on resource constraint devices. So as we all know edge devices are almost everywhere. Uh it can be used in smartphones, vehicles, robots, uh your
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, MIT HAN Lab.