# Attention compiler flamegraph

Interactive outputs:

* `attention-compiler-functions.svg`: compact function-level view.
* `attention-compiler.svg`: full view including inlined Rust frames.

Both use the same recording, saved as `perf.data`. The profiled package is
byte-identical to the prior compiler benchmark package.

This profiles the host compiler for batch-one SigLIP attention, with automatic
attention/product planning and 16 Rayon workers. It does not execute the IPU.
Frame width represents CPU samples across threads, not wall-clock latency.
Click a frame to zoom, use Reset Zoom to return, and Search to highlight names.

The optimized profiling build has debug symbols, frame pointers, and native CPU
instructions. It is isolated in `target/flamegraph` from the normal release build.

After sourcing the local Poplar SDK's `enable.sh`, run from the repository root:

```bash
CARGO_TARGET_DIR=target/flamegraph \
CARGO_PROFILE_RELEASE_DEBUG=true \
CARGO_BUILD_JOBS=16 \
RUSTFLAGS='-C target-cpu=native -C force-frame-pointers=yes' \
RAYON_NUM_THREADS=16 \
cargo flamegraph -p ipu-tests --bin ipu-trivial-test \
  --deterministic --image-width 1800 --min-width 0.2 \
  --notes 'SigLIP attention compiler; batch 1; automatic plans; 16 Rayon workers; CPU samples, not IPU execution' \
  -c 'record -F 99 --call-graph fp' \
  -o artifacts/compiler-perf/flamegraph/attention-compiler.svg -- \
  c600-init.ipucfg --device-lock artifacts/layout-sweep/device.lock \
  --package artifacts/compiler-perf/flamegraph/model.ipuexe \
  --workload siglip-attention-benchmark --attention-strategy auto \
  --attention-batch 1 --attention-products auto --inspect-exchanges \
  > artifacts/compiler-perf/flamegraph/run.log 2>&1
```

Render the compact view from the same recording:

```bash
flamegraph --perfdata artifacts/compiler-perf/flamegraph/perf.data \
  --no-inline --deterministic --image-width 1800 --min-width 0.2 \
  -o artifacts/compiler-perf/flamegraph/attention-compiler-functions.svg
```
