Correlate events before subtracting timestamps from different clocks
Separate CPU enqueue timing, device execution timing, causal identifiers, and uncertainty in cross-domain clock alignment.
On this page
The question for today
What you’ll understand
- Explain why an asynchronous launch interval is not completed device duration.
- Map local timestamps into a reference domain with a stated calibration error.
- Distinguish chronological evidence from a demonstrated dependency.
A host can enqueue a long device computation and return quickly. Meanwhile, another rank may report timestamps from an unrelated clock origin. Both traces can be individually correct while a naive subtraction produces a misleading duration or event order. Performance analysis needs correlated identities, appropriate timing boundaries, and a documented clock mapping. A timeline's visual alignment is evidence only within its calibration accuracy. A launch association also does not by itself describe every dependency that delays the launched work.
Identify what each timing interval measures
A host interval around an asynchronous API call often measures enqueue and runtime overhead rather than the device operation's finish. A device event records progress in the stream and context covered by its contract. To time a region, place events so required work lies between them and wait for completion before reading the elapsed result. Independent-stream work may fall outside that interval unless explicit dependencies bring it inside. Synchronizing after every operator changes execution and can destroy the overlap the experiment was supposed to measure.
Keep CPU thread, process, device, stream, rank, and step identity with each event. A correlation identifier can connect a host API call with resulting device work even when their durations differ greatly. A range annotation describes a chosen logical region; it is not automatically a device synchronization boundary. Tool support varies by version and collection mode, so inspect the captured metadata rather than assuming every operation has a complete cross-layer link. Missing correlation can also follow a capture window that begins after an API call but includes the resulting execution.
Carry clock uncertainty into event-order claims
Two hosts can have different offsets and slightly different clock rates. Converting units alone removes neither effect. A collector may estimate offsets, correlate clocks, or use an external synchronization service; each method has residual error that can change with network conditions and elapsed time. If two mapped events are only a few microseconds apart while their joint uncertainty is larger, their timestamps cannot establish a strict order. State the interval of possible differences instead of reporting the midpoint as exact causal evidence.
Dependencies can establish order even when clock uncertainty prevents a timestamp proof. For example, a consumer that waits on a correctly identified producer event cannot consume that result before the producer's required completion. Conversely, merely observing one event earlier than another does not prove that it caused the second. Combine clock alignment with stream ordering, data dependencies, event waits, and matching collective identities. Do not subtract unrelated devices' raw event timestamps as if one shared stopwatch generated them; use the timing and correlation mechanisms the tool actually supports.
Use a common capture protocol and preserve its limits
Record tool and driver versions, clock-correlation settings, capture start and end, warmup, and which ranks were observed. Check that the region includes both correlation-producing calls and their resulting activities. Compare an uninstrumented completed interval with the instrumented run to expose added waits. For device-event measurements, document stream placement and any synchronization used only at the region boundary. For cross-host analysis, preserve the measured correlation error; a clean-looking joined timeline does not eliminate uncertainty or guarantee that a short apparent gap is real.
The wave lab offers a simple phase comparison rather than a clock-calibration tool. Reset, set both phase difference 0° and amplitude ratio 1, predict sum zero at x=0 and time zero, then Step once: after 0.5 seconds the sum is −2 sin(0.5), about −0.959. Reset and set both phase 90° and ratio 1 to predict initial sum one. Its two waves share one simulation clock and use a chosen phase offset. It measures no clock drift, launch interval, device event, or causal correlation; the comparison only makes a changed alignment visually concrete.
Work it through
A nominal thirty-microsecond gap is not an established order
Event A maps to reference time 1000 µs with error at most 20 µs. Event B's local timestamp is 1230 µs; its clock is ahead of the reference by 200 µs, and the mapped B timestamp has error at most 20 µs. No dependency is otherwise known.
Subtract B's calibrated positive offset: its mapped reference timestamp is 1230−200=1030 µs. The nominal B-minus-A difference is 30 µs, not the 230 µs difference between the uncorrected numbers.
The worst-case difference uncertainty is 20+20=40 µs. The supported difference interval is [30−40,30+40]=[−10,70] µs, which includes zero and both possible orders.
The timestamps therefore do not establish that A preceded B. A matching producer-consumer dependency could supply additional ordering evidence, while a correlation identifier alone would need its actual semantic meaning checked.
A clock-corrected midpoint is still uncertain. Keep the difference interval and the independent dependency evidence with the timeline interpretation.
The living notebook
Explore the model
Interactive lab · waves
A phase offset is visible; clock calibration is a separate problem
Reset, set both phase difference 0° and amplitude ratio 1, predict initial sum zero at x=0, then Step once to time 0.5: the sum is −2 sin(0.5)≈−0.959. Reset and re-enter both phase 90° and ratio 1 for initial sum one. The fixed waves are sin(2x−t) and r sin(2x−t+φ), sharing one clock. They do not simulate clock drift, device events, or timestamp uncertainty.
- Sum at x = 0
- 0.866
- Resultant amplitude
- 1.732
- Phase difference
- 60°
Two waves share the same frequency and wave number. Playback advances t in sin(2x − t) + a sin(2x − t + phase). Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forDocument the alignment mechanism and its error before using a real timeline to infer short event gaps.
Pause & reason
Check your understanding
Your turn
Try it yourself
After calibration, B is nominally 25 µs later than A. Each mapped timestamp has absolute error at most 5 µs. Compute the difference interval and state whether it proves chronological order or causality.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Add the two error bounds, then distinguish a positive interval from a producer-consumer relationship.
Compare with the solution
The interval is [25−10,25+10]=[15,35] µs. Its positive lower endpoint supports A preceding B under the stated calibration bounds. It does not prove that A caused B; stream waits, data flow, or another actual dependency must establish that separate claim.
Keep the idea
Take it with you
- Host enqueue time and device completion time measure different intervals.
- Clock offsets, drift, and calibration error belong in cross-domain timestamp analysis.
- Chronological order, correlation identity, and causality require distinct evidence.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.