BookNotesSlidesP-sets Syllabusdraft · v0.2.49.1
◀▲⌂▶
💬Comments welcome. To leave a note, select any text and click the note / highlight button that pops up — or open the panel with the tab at the top-right (‹). Notes are visible only inside our private review group.
💡 In a hurry? Jump to this chapter’s 1 big lesson ↓

29.6 Hardware backends: GPU, NPU, DSP⧉

A camera can use several processors: an ISP for sensor-facing image stages, a CPU for control, a GPU for parallel image operations, and a neural accelerator or DSP for supported workloads. The assignment varies by device and software. A photograph does not follow one universal CPU–GPU–NPU sequence.

The useful question is where a stage runs efficiently in its surrounding pipeline. A CPU may finish a small filter sooner than an accelerator once dispatch and transfer costs are included. A slower kernel on the current device may beat a faster kernel elsewhere if moving the data costs more than it saves.

29.6.1 GPU: the data-parallel workhorse⧉

A GPU emphasizes throughput across many lightweight threads. It uses both memory hierarchy and concurrent execution: caches and local storage provide reuse, while ready groups of threads can execute when others wait. Neither mechanism guarantees that arithmetic units remain busy.

Many filters and warps have independent output pixels, even though those pixels read overlapping neighborhoods. Other stages, such as histograms and scans, have update dependencies that need a different decomposition. GPU performance depends on enough work, suitable memory access, and manageable synchronization.

SIMT groups threads for execution. NVIDIA calls a 32-thread group a warp; grouping and execution details differ across architectures. Coalescing combines nearby thread accesses into a small number of aligned memory transactions, not necessarily one transaction. Divergent control flow within a group can require execution of multiple paths with inactive lanes masked. Occupancy describes resident work relative to hardware capacity; more occupancy is useful only when it helps the workload, and can conflict with register use or tile storage. The CUDA best-practices guide gives the NVIDIA-specific details.

Programmer-managed shared memory can retain a tile for cooperative reuse. Loading it costs instructions and often synchronization, so use it when the reuse pays for those costs. A simple streaming kernel may work well through ordinary cached memory.

CUDA, Metal, OpenCL, and Vulkan compute provide different programming and deployment paths. Halide can target supported backends with an appropriate schedule and toolchain; availability and operator support must be checked for the actual release and device.

fig-cpu-vs-gpu
Figure 29.6.1. Latency cores versus throughput cores. Side-by-side floorplans of the same chip area. Left, a CPU: a few large cores, each dominated by deep caches (L1/L2/L3), branch predictors, and out-of-order machinery — silicon spent making one thread finish fast. Right, a GPU: thousands of small cores in regular arrays, little per-thread cache, fed by wide high-bandwidth memory — silicon spent running many threads at once, hiding memory latency by switching among them. Below each, the workload it wins: the CPU on branchy, serial, irregular code; the GPU on uniform, embarrassingly-parallel per-pixel work. (Schematic; a real annotated die shot of a CPU and a GPU would make a good companion — placeholder for a sourced public-domain die photo.)
fig-simt-warps
Figure 29.6.2. SIMT, coalescing, and divergence — the GPU's three facts. Top: a grid of pixel-threads grouped into warps of 32 that execute one instruction in lockstep (write the code for one pixel, launch a million). Middle: memory coalescing — when a warp's 32 threads read 32 adjacent addresses, the hardware fuses them into one wide transaction (fast); a scattered read needs many (slow) — the GPU's version of using a whole cache line. Bottom: branch divergence — when threads in one warp take different sides of an if, the hardware runs both sides and masks the idle threads, so the warp runs at a fraction of full speed. Locality and parallelism, with the knobs renamed. (Schematic.)

For a discrete GPU, account for host-device copies and synchronization. On an integrated GPU, shared physical memory can avoid some copies, but layout conversion, cache coherence, bandwidth contention, and ownership transitions still cost time. Keep useful work on the device across several stages where possible.

Consider neighboring GPU threads processing neighboring output pixels. If they read neighboring input samples, their requests can use a small set of memory transactions. If each thread follows a scattered index, the same number of useful samples can require more transactions. Loading a tile into a programmer-managed shared buffer can make neighborhood reuse explicit, but the buffer consumes resources that could otherwise support more resident work. A larger tile can therefore improve reuse while reducing occupancy. Measure the combined effect rather than optimizing either quantity in isolation.

29.6.2 The neural accelerator: NPU and TPU⧉

Neural accelerators specialize in tensor operations and their data reuse. A systolic array, such as the TPU architecture described by Jouppi and colleagues Jouppi et al. 2017, passes operands through multiply-accumulate units to reuse them efficiently. Other accelerators use different organizations; “NPU” does not imply one particular internal design. Google's Tensor is a system-on-chip family name, not a synonym for one neural execution unit.

Supported convolutions or matrix operations can run efficiently at low precision. The practical limits are operator coverage, tensor shapes, layout, precision, local storage, and compiler mapping. A network with unsupported operations can split into several subgraphs with transfers or CPU fallbacks between them.

Check the compiled graph and measure end-to-end execution. Reducing precision or fusing operators helps only if the target implements the resulting operations efficiently and image quality remains acceptable. Chapter 29.7, Efficient neural network inference and Chapter 29.9, 8-bit and fixed-point arithmetic develop these choices.

The systolic array in the TPU example illustrates how data reuse can be built into the hardware Jouppi et al. 2017. Matrix multiplication repeatedly multiplies each element by elements along another row or column. Passing operands through a grid of multiply-accumulate units lets neighboring units reuse them while partial sums accumulate locally. Fetching each operand anew from external memory for every multiplication would waste much of the potential throughput.

This is one accelerator design, not a description of every NPU. Its advantage depends on filling the array and expressing the workload in supported operations and precisions. Small matrices, irregular work, or unsupported stages can leave units idle or require transfers to another processor. The useful question for an imaging pipeline is how much of the whole computation can stay on the accelerator, including its intermediate data.

29.6.3 DSP: the real-time control loop⧉

Digital signal processors support repeated signal operations through combinations of efficient multiply-accumulate instructions, vector units, local memory, and execution mechanisms suited to streaming work. Depending on the system, a DSP may run image kernels, neural workloads, or parts of camera control.

Auto-exposure, autofocus, and auto white balance have latency and stability requirements, but they do not universally run on a DSP or update all settings before every next frame. The controller may use delayed statistics and run across several camera subsystems. For deadline-sensitive work, measure worst relevant latency and jitter as well as average throughput; see Chapter 8.10, Auto-exposure and auto white balance.

29.6.4 ISP, FPGA, and ASIC: the fixed-function end⧉

An ISP combines dedicated image-processing blocks with configuration and, in some designs, programmable components. Sensor correction, demosaicking, denoising, color, and tone operations can stream through line buffers at high efficiency. Its parameters and supported modes can change even when the hardware datapath cannot implement an arbitrary new algorithm. Part 8, Basic image processing and ISP describes the operations independently of this hardware assignment.

An FPGA implements reconfigurable logic and routing, allowing a custom datapath to be changed after manufacture. An ASIC is a chip designed for an application; it can contain fixed-function blocks, programmable cores, or both. An ISP or neural accelerator can itself be part of an ASIC, so these names are not mutually exclusive positions on one ladder.

Specialization can improve energy and area efficiency for a matched workload, at a cost in design effort and flexibility. Volume, latency requirements, available interfaces, and expected algorithm changes determine whether it is justified.

29.6.5 The heterogeneous SoC, and the spectrum to carry away⧉

A system-on-chip connects several processing blocks and memory interfaces. Shared memory makes cooperation easier, but it remains a resource that the blocks compete for. An implementation must coordinate buffer ownership, layout, synchronization, and execution order.

For a serial path, a useful accounting is

$$T_{\mathrm{path}}=\sum_j T_{\mathrm{compute},j} +T_{\mathrm{transfer}}+T_{\mathrm{convert}}+T_{\mathrm{sync}}.$$

Measure these contributions without double-counting overlap. With pipelining, frame throughput is governed by the bottleneck resource and dependencies, while one frame's latency follows its critical path. Higher throughput can coexist with higher latency if batching or queueing is introduced.

💡 Big lesson (L29.5) — specialization helps when the workload fits

Choose the unit that executes the required operations efficiently within the whole pipeline. Include movement and conversion costs. Flexibility and efficiency trade off, but CPU, GPU, DSP, NPU, and ISP do not have a universal ordering of performance per watt.

fig-heterogeneous-soc
Figure 29.6.3. The modern camera runs on all of them at once. A block diagram of a phone SoC: CPU (often big.LITTLE — a few fast cores plus efficient ones), GPU, NPU / Neural Engine, DSP, ISP, and video codec, all connected to one shared memory. Overlaid, the path of a single photograph: sensor → ISP (demosaic, base pipeline) → DSP (real-time 3A) → NPU (learned denoise, segmentation) → GPU (composite, preview) → CPU (orchestration). The arrows crossing between blocks are the data movement the engineering must minimize. (Schematic; a real annotated SoC die photo or development-board image would make a strong companion — placeholder for a sourced public-domain photo.)
fig-flexibility-efficiency
Figure 29.6.4. The flexibility–efficiency spectrum. A single horizontal axis with the processors placed along it: CPU (most flexible, least efficient) → GPU → NPU / DSP → ISP / FPGA / ASIC (least flexible, most efficient, in performance-per-watt). Annotations name what each gives up to move right (generality, then programmability) and the imaging stage that typically lands on each (glue/control, real-time pixel work, learned inference and 3A, the fixed base pipeline). One line that places every backend in this chapter. (Schematic.)

29.6.6 On-device ML runtimes, and why the work stays on the phone⧉

A deployment runtime maps supported parts of a trained model to available implementations. LiteRT provides accelerator integration; ONNX Runtime uses execution providers; Core ML exposes allowed compute-unit configurations. These are not a universal fallback order of NPU, then GPU, then CPU. Selection depends on runtime settings, backend support, model operations, shapes, and device. Consult LiteRT, ONNX Runtime execution providers, and Core ML compute units.

Inspect placement and conversion overhead after compilation. A model that loads successfully may still execute expensive parts on the CPU. Repeated boundaries between accelerators can outweigh the savings from individual accelerated layers.

Keeping processing local avoids network upload latency, supports offline use, and reduces exposure of image data to remote services. It does not by itself guarantee privacy; storage and application behavior still matter. Cloud processing remains useful for workloads that exceed local resources. HDR+ is a documented example of on-device burst processing Hasinoff et al. 2016, not evidence that all computational photography must remain on the phone.

Recap: big lessons of this chapter

💡 Big lesson (L29.5) — specialization helps when the workload fits

Choose the unit that executes the required operations efficiently within the whole pipeline. Include movement and conversion costs. Flexibility and efficiency trade off, but CPU, GPU, DSP, NPU, and ISP do not have a universal ordering of performance per watt.