What a timed phase is
A Waveflow simulation is loosely timed: it does not step every clock edge. A transfer on a port – a burst of words on a stream – is one simulated transaction, and what the simulation knows about its timing is two moments: its first beat and its last beat. Those two moments are the only things a module’s timing can be stated against.
So a module states its timing as timed phases. A phase names one or more spans, each the time between two of those events on the module’s own ports, and the features the span depends on. A timing model – one per span – predicts the span’s duration from the features.
A phase, on a real trace
This is the polynomial kernel at RTL, one 8-sample command, beat by beat on its two ports (a cycle-accurate co-simulation; each box is one word accepted). Poly declares two phases, and its three spans are drawn where the trace puts them:
resp_time– from the last beat of the command header ons_into the first beat of the response onm_out: 4 cycles. The kernel decodes the header and answers.latency– from the first beat of the samples ons_into the first beat of the results onm_out: 34 cycles, the depth of the evaluation pipeline.fill_time– from the first to the last beat of the results: 7 cycles for 8 words, one word a cycle.
The picture also shows what a phase does not have to model. The samples arrive with a gap – the
kernel was still handling the header – and the results leave long after the last sample came in.
Neither is a separate number: the gap falls inside latency, which is measured from the samples’
first beat, and the transfers themselves are timed by the simulation already.
The two rules
A span can be calibrated only if two things hold:
- Its duration is a deterministic function of features known before its first event. Poly’s
fill_timedepends on the number of words, which the header announced before the first result word; itslatencyon nothing at all. The model learns that function: its targets are the observable durations, and its parameters – a latency, a rate – stay inside it. They never appear in the module’s code. - Every event is measurable. An event is an endpoint’s first or last beat – a handshake any RTL
trace shows – and the simulation’s own transfer primitive logs the same event. On a
stream-of-blocks endpoint a transfer is one block:
firstis its acquire (the task’s first access to it),lastits release (the lock’s release pulse). A task inside a composite kernel – whose endpoints are the kernel’s internal channels, not its ports – is measured the same way, its events read by name from the kernel top’s trace manifest at the kernel’s scope (the systolic engine’s core is the example: itspanelphase spans aBblock’s acquire and release).
A duration is deterministic only while the environment does not hold the module up inside the span (a full output queue, an input that is late), so every measurement also says whether it was held – a held measurement tests a prediction but is not used to fit one.
Two shapes
Most module bodies are one of two shapes, and each is one kind of phase:
- Sequential – the whole input arrives, then the compute, then the output: one span, from the
input’s last beat to the output’s first (poly’s
resp_time). See Sequential bodies. - Pipelined – a loop that reads a word, computes, writes a word: the output starts a latency
after the input’s first beat and then fills at the loop’s rate – two spans (poly’s
latencyandfill_time). See Pipelined bodies.
The difference between them is only which event the span starts at.
What follows from a declaration
A phase is declared once, beside the module’s endpoints (Declaring a timed phase). Everything a calibration needs follows from it, with nothing written by hand:
- what to observe – every endpoint a phase names, which is a port of the generated kernel;
- what pysim logs – each of those endpoints’ transfers, and each occurrence of each span with its features;
- what the RTL shows – the same transfers, read off a trace of those ports;
- how they pair – pysim says which transfers each span started and ended on, and with which features; the RTL supplies the times.
Calibrating a timed phase is those steps. The figure above is drawn from the very trace poly’s phases were fitted from.
See also
- LT vs CT models – why a transfer is one event and not one per cycle.
- Declaring a timed phase – the API:
TimedPhase,add_timing_phase. - The form of a span’s model – what a span’s model is, for a pipelined loop.
plans/pipelined_ops.md– the design and its record.