This document is relevant for: Inf2, Trn1, Trn2, Trn3
Dependency Chain Viewer#
When a model runs slower than expected, the trace view shows where the time went, but not why. An engine that sits idle or an event that starts late is usually waiting on something else. That something is often on another engine or in another layer of the stack, and it can be far from where the delay appears, so finding it by scanning the timeline is slow and easy to get wrong.
Click an instruction or a system profile event, and the Dependency Chain Viewer shows what it was waiting on and what was waiting on it. You can trace a delay back to the event that caused it, which points to what to optimize.
The Dependency Chain Viewer works at two levels:
Device — follow an instruction back through the instructions it waited on, across engines, to find what kept an engine idle.
System — follow a system event across the framework, the Neuron Runtime, and the hardware to find which layer a slow step came from.
The Dependency Chain Viewer appears by default in the device and system profile layouts. To use it in a different layout, click Add Widget and select Dependency Chain Viewer.
Instruction dependencies#
Click an instruction in the Device Trace Viewer or the Unified Trace Viewer to load it into the Dependency Chain Viewer. The clicked instruction appears in the Clicked column. The instructions it depends on appear in the Upstream column, and the instructions that depend on it appear in the Downstream column. Only direct dependencies are shown. Curves connect each card to the clicked instruction, and the color of each curve shows the dependency type.
Each card shows the instruction’s engine, PC, opcode, and stall. The stall is the gap between the end of the instruction that is depended on and the start of the instruction that depends on it. A negative stall means the two instructions overlapped.
Click a card to see the fields selected in Settings > Hover Options and to copy the instruction as JSON. Use Filter to hide cards by dependency type, engine, or opcode, and use ▲ / ▼ to sort a column by time. Dependencies between cards in the same column aren’t drawn by default. To draw them, select the dependency types to show under Within-hop dependencies drawn.
Dependency types#
Every dependency in the Dependency Chain Viewer has a type, which tells you why one instruction had to wait for another. The color of the curve between two cards shows the type. Dependencies come from two sources:
Compiler dependencies — the compiler records flow, order, anti, and output dependencies when it compiles the model. They show the order the program requires: which instructions must wait for others because they share data or memory locations, or because the compiler ordered them.
Derived dependencies — Neuron Explorer finds the other types when it processes the profile, from what happened at run time, such as semaphore updates, DMA transfers, PSUM bank use, and contention for SBUF ports. They show waits and contention that come from shared hardware and from coordination between engines, which the compiler’s dependencies don’t capture.
The stall on a card helps you find the dependency that held an instruction up.
A small stall means the instruction started soon after that dependency finished, so the dependency may have held it up.
A large stall means the instruction was already free of that dependency and was waiting on something else.
The type of the dependency that held it up tells you where the wait came from: the program’s data or ordering for a compiler dependency, or a hardware resource, a transfer, or another engine for a derived one.
For the dependency_type values, see the Flow table.
Type |
Meaning |
|---|---|
Flow Dependency |
An instruction reads a value that an earlier instruction wrote (read after write). |
Order Dependency |
The compiler requires the two instructions to run in order. |
Anti Dependency |
An instruction writes a location that an earlier instruction reads (write after read). |
Output Dependency |
Two instructions write the same location (write after write). |
Same PSUM Bank |
Two instructions used the same PSUM bank. See Same PSUM Bank dependencies. |
Semaphore Wait |
A semaphore update, from a DMA transfer or another engine, released an instruction that was waiting on the semaphore. |
Trigger Dependency |
An instruction starts a DMA transfer or a collective, a DMA transfer completes for the instruction waiting on it, or a DMA transfer writes a semaphore update. |
SBUF Read Port Contention, SBUF Write Port Contention |
Overlapping Vector and GpSimd instructions need the SBUF read or write port that the two engines share. |
Default |
Any other dependency. |
Build a chain#
A single instruction’s dependencies tell you what it waited on. A chain follows those waits back step by step until you reach the instruction that started the delay. When you click an instruction on the timeline, it becomes the first instruction in a chain and appears in the Clicked column.
To add an instruction by hand, expand a card and click Add above ↑ on an upstream card or Add below ↓ on a downstream card. Neuron Explorer adds that instruction to the chain and selects it on the timeline. If a card is already on the chain, click Go to to return to that instruction.
To build the chain automatically, click Trace ▲ or ▼.
At each step, Trace adds the linked instruction with the smallest stall, and it stops after 50 instructions by default.
With Stop at idle, which is on by default, Trace stops earlier, at the first instruction whose engine sat idle for at least 500 ns.
That card shows what the engine was waiting on, for example GpSimd idle 600 ns, waiting on S[45] (qSyncIO0).
Click Annotate to mark the chain on the timeline as an annotation region. Neuron Explorer saves up to 20 chains per profile in your browser. To return to an earlier chain, select it from the chain list.
You can also walk and build a chain from the keyboard:
Key |
Action |
|---|---|
Arrow keys, or |
Move between the columns (left and right) and between the cards in a column (up and down). Click the Dependency Chain Viewer first. |
Space / Enter |
Expand or collapse the card / press its button. |
Shift+left or right arrow, or Shift+``H`` / |
Add the closest upstream or downstream instruction, the one across the smallest stall, to the chain. |
Esc |
Return to the clicked card. |
Alt+left or right arrow, or Alt+``H`` / |
In the Device Trace Viewer or the Unified Trace Viewer, add the closest upstream or downstream instruction to the chain and go to it. The Dependency Chain Viewer must be open. |
System event dependencies#
A framework operation in your model causes Neuron Runtime calls, and those calls turn into hardware work. When a step is slow, system profile dependencies let you follow it through these layers to see where the time went.
Events that belong to the same piece of work share a flow_id.
The flow_id links a framework operation to the Neuron Runtime calls it makes, and links those calls to the hardware events (neuron_hw) that run them.
Framework links are available for PyTorch profiles captured as described in Capture PyTorch profiles with Neuron Explorer.
Links between Neuron Runtime calls and hardware events are available for any framework.
To see an event’s dependencies, click an event that has a flow_id in the System Trace Viewer or the Unified Trace Viewer.
Arrows on the timeline point to the events linked directly to it.
The Dependency Chain Viewer lists those events as cards and in the Upstream Events and Downstream Events tables.
To move the timeline to a linked event, click Go to on its card or click its name in a table.
Chains, traces, and annotations are available only for device instructions, not for system profile events.
Host-device transfers#
Copying data between the host and the device can take a large share of a step’s time, and the transfer events on the timeline don’t say which part of your model caused them.
In the System Trace Viewer, a host-to-device or device-to-host transfer that PyTorch starts is linked to the framework operation that started it, for example a PyTorch tensor copy such as aten::to or aten::copy_.
These links let you find the line of model code behind an expensive transfer.
Click a transfer event to draw an arrow back to the framework operation that started it. Click a framework operation to see the transfers it started.
Dependencies on the timeline#
The timeline also shows dependencies: when you click an event, the events linked to it light up, including DMA transfers and semaphore updates, which the Dependency Chain Viewer doesn’t list. When you click an event in the Device Trace Viewer or the Unified Trace Viewer, the timeline outlines it and fills the events linked directly to it, including DMA transfers and semaphore updates, with the colors of their dependency types. Clicking an instruction that waited on a semaphore highlights the semaphore updates that released it on the core’s Semaphore track, and clicking a semaphore update highlights the instructions it released. The Dependency and Dependent Color Types legend in the Device Trace Viewer and Unified Trace Viewer help lists the colors.
DMA dependencies#
An engine that waits on a DMA transfer sits idle until the transfer finishes, so slow or late transfers often explain gaps on the timeline. DMA dependencies connect a transfer to the instructions around it, so you can see which instruction started a transfer and which instruction waited for it.
Click a DMA transfer to highlight the instruction that started it and the semaphore updates the transfer wrote. Click an instruction to highlight the DMA transfers it started. When the profile records which instruction waits for a transfer, these clicks also highlight the waiting instruction and the transfers an instruction waits for. Otherwise, click a semaphore update to highlight the instruction it released.
The instruction that starts a transfer depends on how the transfer’s DMA descriptors are generated (see Descriptor Generation Engine (DGE) Reference):
Pre-computed descriptors — a
WRITEinstruction that corresponds to aPSEUDO_DMA_TRIGGER.Software or hardware DGE — the DMA instruction that issued the transfer, such as
DMA_DIRECT2D.
The instruction that waits for a transfer is often an EVENT_SEMAPHORE, but any instruction can wait.
Dynamic (DGE) transfers are linked only in profiles captured with DGE notifications turned on.
To turn them on, use --enable-dge-notifs or set NEURON_RT_ENABLE_DGE_NOTIFICATIONS=1 (see Neuron Explorer Environment Variables).
A transfer usually writes 16 semaphore updates, one from each DMA engine that moved part of it, when that engine’s share completes. Clicking a semaphore update that a DMA engine wrote highlights the transfer that produced it: its bar when DMA Aggregation is set to Aggregated, and otherwise all of its packets. The link identifies the transfer, not the DMA engine that wrote each update, because the hardware doesn’t record which engine sent an update. With DGE notifications on, some semaphore notifications can be lost, so a transfer can show fewer updates than engines.
Same PSUM Bank dependencies#
Two instructions that use the same PSUM bank must run in order, even when the compiler records no dependency between them. For example, a matrix multiplication that starts a new accumulation in a bank has to wait until an instruction on another engine finishes reading the previous result from that bank. These waits don’t appear among the compiler’s dependencies. Same PSUM Bank dependencies show them, so you can see when contention for a PSUM bank is what’s holding up an engine.
Neuron Explorer derives these dependencies from the PSUM addresses that instructions accessed and the order the instructions ran in. It links two instructions only when all of the following are true:
Both instructions used the same PSUM bank on the same NeuronCore, and no other instruction accessed that bank between them.
At least one of the two instructions wrote to the bank.
The later instruction doesn’t continue an accumulation that the earlier instruction is part of.
When you click an instruction that uses PSUM, Neuron Explorer highlights, in brown, the previous and next instructions that used the same bank.
To see which bank they share, compare their Symbolic Operands in the hover, for example PSUM(partition=0,bank=6,offset=0).
In the profile data, the psum_read_banks and psum_write_banks fields of the Instruction table list the banks that each instruction reads and writes.
Note
An instruction pair can have both a Same PSUM Bank dependency and a dependency recorded by the compiler. In that case, the timeline highlights only one of them.
Limitations#
The Dependency Chain Viewer follows dependencies between instructions only. DMA transfers, collectives, and semaphore updates appear only as timeline highlights.
In a system profile, a Device Trace Viewer opened for one of its device profiles does not update the Dependency Chain Viewer. Use the Unified Trace Viewer instead.
The System Trace Viewer finds linked events only within the time range it loaded for the current view. To find more, zoom out and click the event again.
This document is relevant for: Inf2, Trn1, Trn2, Trn3