Heterogeneous Compute: From Sensor to Display
A large chip gives the same steps on much data to an engine built for them. The engine has a cost of its own, the engines share one memory, and every buffer has one owner at a time.
You Will Be Able To
- Say when a job belongs on an engine, by the whole cost from the request to the result.
- Count the bytes of a frame at the memory port, in the format of each crossing.
- Say who owns a buffer at each moment, and when a writer may use it again.
- Lesson
- S10.6
- Time
- 25 min
- Runs on
- Your browser
- Check
- 5 questions
You wave at the camera, and on the screen your hand stops halfway. The cores of the phone are almost idle.
The frame was never theirs to draw. Another block had that job, and it was waiting for something.
Before You Start
You need From Microcontroller to Application Processor: ap_phone, its camera, and the compute engine.
You need High-Speed I/O Subsystems: registers for the core, data written to memory by DMA, and one interrupt at the end.
You need A Bus in Six Wires: the handshake of valid and ready.
It helps to know The Memory Subsystem: the memory of ap_phone carries 4,800,000,000 useful bytes each second.
| Question | |
|---|---|
| 1 | When does a job belong on an engine and not on a core? |
| 2 | An engine does a job in 5 microseconds, after 400 for waking and hand-off. A core takes 50. Who should do it? |
| 3 | A frame is written to memory once and read once. How many bytes cross the memory port each second? |
| 4 | When may a writer use a buffer again? |
| 5 | The camera runs at 60 frames a second. What does the lab print last? |
The Idea: Give One Pixel a Job
Pick one grey pixel on your sleeve and follow it. The camera sends 2 bytes for it: one for brightness and one for colour. A grey preview needs only the brightness. It must go into three fields of a display pixel: red, green and blue.
The next pixel needs exactly the same steps. So do all 2,073,600 pixels of the frame, 30 times each second. A core would fetch and decode the same few instructions for every one of them.
So the chip gives the job to a circuit that does only this. Wires carry the brightness bits straight into the three fields. Such a block is a compute engine. A chip with cores and several kinds of engine is called heterogeneous.
An engine is not free. It must be woken, the job must be handed over, and somebody must be told at the end. For a large job that cost is small. For a small job it can be the whole bill.
The engines also share one memory. Every write of a frame and every read of it counts against one budget. And the block that writes a buffer must agree with the block that reads it on the moment it changes hands.
New Words
| Word | Meaning |
|---|---|
| Heterogeneous chip | A chip with cores and several kinds of compute engine, each built for one kind of job. |
| ISP | Image signal processor: the engine for camera pixels. It corrects and converts them. |
| GPU | Graphics processing unit: the engine that draws. It applies the same steps to very many pixels. |
| NPU | Neural processing unit: the engine for the sums of a trained model, such as finding a face in a picture. |
| DSP | Digital signal processor: the engine for streams of samples, such as sound. |
| Display engine | The block that reads a finished frame from memory and sends it to the screen. |
| Display pixel | One pixel in the format of the screen. Here it is 2 bytes: 5 bits of red, 6 of green and 5 of blue. |
| Wake time | The time until a sleeping engine can work. |
| Hand-off time | The time to pass a job and its data to an engine, and to learn that it has finished. |
| Frame slot | The time for one frame. At 30 frames a second it is 33,333 microseconds. |
| Memory crossing | One passage of a frame through the memory port: one write of it, or one read of it. |
| Raw frame | The frame as the camera sent it, before any engine changed it. |
| Owner of a buffer | The one block that may use a buffer at this moment. |
| Visible write | A write is visible to a reader once a read of that address returns the new value. A write that still waits in a queue is not. |
One Picture: One Frame, from the Camera to the Screen
- External
- Peripheral
- Memory
- Processor
- One pixel, one job
The camera sends 2 bytes for a pixel. The ISP takes the brightness byte and makes one display pixel of it. No instruction is fetched.
- The first crossing
The ISP writes the finished frame to memory by itself. At 2 bytes a pixel that is 124,416,000 bytes each second.
- The second crossing
The display engine reads the same bytes back, once for each frame. The memory port now carries the frame twice.
- The part of the core
The core writes a few registers of the ISP to start a frame, and an interrupt tells it the end. It never touches a pixel.
- Who owns the buffer
While the ISP writes, the buffer is its own. After the last write it passes to the display engine. Only one of them may use it at a time.
Read the diagram as text
- Camera: 2 bytes for each pixel: brightness and colour
- ISP: the engine for camera pixels
- Frame buffer: one finished frame in memory: 4,147,200 bytes
- Core: starts the job and is told the end
- Display engine: reads the finished frame
- Screen: outside the chip
- Camera → ISP: camera pixels
- ISP → Frame buffer: write
- Frame buffer → Display engine: read
- Display engine → Screen: display pixels
- Core → ISP: registers
The preview path of ap_phone, at box level. The GPU, the NPU and the DSP are attached to the core and to memory in the same way.
The Smallest Example, Worked by Hand
No simulator yet. First, who should do a job. Add the three parts of the cost, in microseconds: millionths of a second. The times are exercise values.
| Job | Done by | Wake | Hand-off | Work | Total |
|---|---|---|---|---|---|
| One frame to grey | A core | 0 | 0 | 20,000 | 20,000 |
| One frame to grey | The ISP | 300 | 100 | 2,000 | 2,400 |
| One small icon to grey | A core | 0 | 0 | 50 | 50 |
| One small icon to grey | The ISP | 300 | 100 | 5 | 405 |
A frame slot is 33,333 microseconds. A core would spend more than half of every slot on the frame. The ISP needs 2,400. For the icon the answer turns round: the engine works ten times faster and still finishes eight times later.
Second, the bytes. The frame has 2,073,600 pixels, so 62,208,000 pixels pass each second. Count each crossing of the memory port in its own format.
| Crossing | Format | Bytes each second |
|---|---|---|
| The ISP writes the preview | 2 bytes for a display pixel | 124,416,000 |
| The display engine reads it | 2 bytes for a display pixel | 124,416,000 |
| Total | 248,832,000 |
Inside the ISP the brightness is a stream of 1 byte for each pixel, 62,208,000 bytes each second. It never touches memory, so it is not in the table.
The Rules
Rule 1: A job of the same steps on much data belongs on an engine.
The engine does the steps with wires. A core fetches instructions for every item.
Rule 2: Compare whole costs: wake time, hand-off time and work.
An engine pays only when the time it saves is more than the time it takes to reach it.
Rule 3: An engine is attached like a fast port.
The core writes its registers. The engine moves its data by itself. One interrupt ends the job.
Rule 4: Count every memory crossing, in the format of that crossing.
A read costs as much as a write. A stream that goes from block to block costs nothing here.
Rule 5: A buffer has one owner at a time, and it changes hands only after the last write is visible.
The interrupt of the writer is the earliest moment. The reader must not start before it.
Rule 6: A writer may use a buffer again only after the last reader has released it.
Until then the reader may still be in the middle of the old frame.
Sources for These Rules
Engines for the same steps on much data, and a memory built for bytes each second: Patterson and Hennessy, Computer Organization and Design, ARM edition, section 6.6.
Rules 2, 5 and 6 are common practice of drivers for cameras and displays. No document for them is in the library of this site.
Rule 3 repeats the three paths of the lesson on fast ports. Rule 4 is arithmetic.
Now Run It
The lab at the end of this page prints the two hand tables. Between them it sends the grey pixel of your sleeve, brightness 84 in hex, through a small stage of the ISP.
job=frame on=core wake_us=0 handoff_us=0 work_us=20000 total_us=20000
job=frame on=isp wake_us=300 handoff_us=100 work_us=2000 total_us=2400
job=icon on=core wake_us=0 handoff_us=0 work_us=50 total_us=50
job=icon on=isp wake_us=300 handoff_us=100 work_us=5 total_us=405
hold valid=1 ready=0 rgb=8430
take valid=1 ready=1 rgb=8430
stream B/s camera=124416000 brightness=62208000 preview=124416000
memory B/s write=124416000 read=124416000 total=248832000
raw_spill B/s total=497664000
frame bytes=4147200Rule 2 at work, in the first four rows. For the frame the ISP wins with total_us=2400. For the icon it loses with total_us=405 against 50.
Rule 5 in small, in the hold row. The stage has made the display pixel 8430 and says valid=1. The next block says ready=0, so the pixel waits, unchanged. In the take row ready is 1, and the same 8430 moves on. Nothing was lost, and nothing was written twice.
Rule 4, in the stream row and the memory row. The brightness stream of 62208000 stays inside the ISP. The preview is written once and read once: total=248832000. The raw_spill row is the quick check: two more crossings, 497664000.
This lab leaves things out. It hands over one pixel, and a real driver hands over whole buffers. It has no memory controller, so no write ever waits in a queue. Rules 5 and 6 at the size of a frame are not run here.
Why It Is Built This Way
| Choice | The alternative | Its cost |
|---|---|---|
| Engines beside the cores | More cores | A core fetches and decodes for every pixel. The frame job alone would take more than half of one core. |
| One memory for all engines | A private memory for each engine | Every hand-over would be a copy of 4,147,200 bytes. Shared memory passes an address. |
| A stream from block to block | Every step through memory | Each step through memory is a write and a read. The raw spill doubles the load for the same picture. |
The second row has a price. Shared memory is why a buffer needs an owner. With private memories nobody could read a frame that is half written.
The Trap: A Sleeve from Two Frames
The ISP finishes frame 2 and its interrupt arrives. The driver starts frame 3 in the same buffer at once. The display engine is still halfway down frame 2. The top of your sleeve comes from one frame and the cuff from the next.
Rule 6 was broken: the reader had not released the buffer. The usual cure is a second buffer, so that the two blocks swap.
The second trap is the idle core. The picture freezes and every core is idle, so the cores are blamed for nothing. Look at the engine: it was asleep, and the frame waited for its wake time.
The third trap counts only what is on the screen. The display reads 124,416,000 bytes each second. The memory port carried twice that, or four times with the raw spill.
At Scale
This section looks ahead, to many engines at once and to the cost of waking them.
One budget for all
The preview takes 248,832,000 of 4,800,000,000 useful bytes each second, about a twentieth. A face detector on the NPU and a game on the GPU draw on the same budget.
Three engines for one picture
To draw a box round a face, the ISP converts, the NPU finds the face and the GPU draws the box. Each hand-over is a buffer that changes its owner.
Asleep to save power
An idle engine is switched off, and that is where its wake time comes from. The system must wake it before the frame that needs it.
A late frame
Mark one frame and follow it from the camera to the screen. Measure each wait: for power, for a place in a queue, for a buffer. An engine that works faster does not shorten a wait.
The cost of waking continues in Power Domains at Scale.
Try It
Run the lab. Find the two rows of the frame job, and read which engine is faster and by how much.
Change the wake time of the ISP in the icon row to 0. Predict the new total, and say who should do the icon now.
Change FPS to 60. Predict which rows double and which stay.
Change the brightness byte to ff. Follow the value through the hold row and the take row.
Names Printed by the Lab
| Name | Meaning |
|---|---|
| job, on | The job, and the block that does it: a core or the ISP. |
| wake_us, handoff_us, work_us | The three parts of the cost, in microseconds. The lab writes us. |
| total_us | Their sum: the time from the request to the result. |
| hold, take | The stage holds one finished pixel. In the take row the next block accepts it. |
| valid, ready | The handshake between the stage and the next block. A pixel moves on when both are 1 at a clock edge. |
| rgb | The display pixel, in hex: 5 bits of red, 6 of green, 5 of blue. |
| B/s | Bytes each second. |
| camera, brightness, preview | The stream from the camera, the stream of brightness bytes inside the ISP, and the stream of display pixels. |
| write, read, total | What crosses the memory port: the ISP writes the preview, and the display engine reads it. |
| raw_spill | The total when the frame of the camera is also stored in memory and read back. |
| frame bytes | The size of one finished frame. |
Sources and What the Lab Leaves Out
The stage is a small circuit, preview_gray. The rows of costs and of bytes are sums of test code. The lab has no GPU, no memory controller and no screen.
Every number is an exercise value of ap_phone. That holds for the camera, for the times of the core and the ISP, and for the display pixel.
job=frame on=core wake_us=0 handoff_us=0 work_us=20000 total_us=20000 job=frame on=isp wake_us=300 handoff_us=100 work_us=2000 total_us=2400 job=icon on=core wake_us=0 handoff_us=0 work_us=50 total_us=50 job=icon on=isp wake_us=300 handoff_us=100 work_us=5 total_us=405 hold valid=1 ready=0 rgb=8430 take valid=1 ready=1 rgb=8430 stream B/s camera=124416000 brightness=62208000 preview=124416000 memory B/s write=124416000 read=124416000 total=248832000 raw_spill B/s total=497664000 frame bytes=4147200Read included file: preview_gray.sv
// Teaching fixture for the stream attachment. One unsigned luma sample per beat.
// The registered output holds its pixel while the consumer applies backpressure.
module preview_gray (
input logic clk, reset_n,
input logic in_valid,
output logic in_ready,
input logic [7:0] luma,
output logic out_valid,
input logic out_ready,
output logic [15:0] rgb565
);
assign in_ready = !out_valid || out_ready;
always_ff @(posedge clk) begin
if (!reset_n) begin
out_valid <= 0;
rgb565 <= 0;
end else if (in_ready) begin
out_valid <= in_valid;
if (in_valid)
rgb565 <= {luma[7:3], luma[7:2], luma[7:3]};
end
end
endmodule
Check Yourself
Common Mistakes
Wrong Count only the reads of the display.
The frame was written to memory first.
Fix Count every crossing, reads and writes.
Wrong Choose an engine by its work time alone.
Wake time and hand-off time can be larger than the work.
Fix Compare the whole time from the request to the result.
Wrong Use the old buffer again when the writer has finished.
The reader may still be in the middle of it.
Fix Wait until the last reader has released it.
Remember
- An engine does the same steps on much data with wires, where a core fetches instructions.
- Compare whole costs: wake time, hand-off time and work.
- Count every memory crossing, in its own format.
- A buffer has one owner at a time. It changes hands after the last visible write, and returns after the last reader.