Skip to content

roofline: emit raw per-tensor data for DDR byte accounting (single + fused)#48

Open
roberteg16 wants to merge 5 commits into
gfx11from
rogarcia.roofline-fused-raw-facts
Open

roofline: emit raw per-tensor data for DDR byte accounting (single + fused)#48
roberteg16 wants to merge 5 commits into
gfx11from
rogarcia.roofline-fused-raw-facts

Conversation

@roberteg16

@roberteg16 roberteg16 commented Jul 13, 2026

Copy link
Copy Markdown

What

The HIP roofline profiler emits raw per-tensor facts instead of computing HBM byte totals in-tree. For every tensor — on fused nodes and on the top-level (single-op) row — it reports: byte count, a storage id (the view_src root, so the consumer sees which tensors alias the same buffer), and a source tensor id. The consumer (rocm-scripts tools/roofline) computes external in/out from those facts.

Improvements

  • Correct bytes, one policy for single and fused kernels. With the storage ids the consumer can exclude what never crosses HBM: no-op views (VIEW/RESHAPE), in-place copy/scatter destinations (CPY/SET_ROWS pass their own output buffer in as a source — written, not read), and internal tensors. This fixes real double-counts — the KV-cache write was counted twice, in both fused and standalone SET_ROWS/CPY.
  • Cleaner separation. Producer reports facts; consumer owns policy — the model non-fused rows already used. Removes the in-tree fused byte computation.

Two commits: (1) raw facts for fused nodes + drop the in-tree fused computation; (2) emit the same ids on non-fused rows so single kernels get the same treatment.

Companion consumer PR: FaaSApps/rocm-scripts#682.

A/B on Qwen2.5-3B / gemma-3-12B / Qwen3.6-35B: only view / in-place-destination cases change (e.g. SET_ROWS −49%, standalone CPY −33%); every other row is byte-identical.

@roberteg16 roberteg16 changed the title roofline: emit raw per-tensor facts for fused ops roofline: emit raw per-tensor facts for HBM byte accounting (single + fused) Jul 13, 2026
@roberteg16 roberteg16 changed the title roofline: emit raw per-tensor facts for HBM byte accounting (single + fused) roofline: emit raw per-tensor facts for DDR byte accounting (single + fused) Jul 13, 2026
@roberteg16 roberteg16 marked this pull request as ready for review July 14, 2026 07:40
@roberteg16 roberteg16 requested a review from mgehre-amd July 14, 2026 07:41
// consumer can sum exact FLOPs across the whole fused group. FLOPs are additive under
// fusion (only memory traffic is saved), so per-node geometry is all it needs; byte
// fields on the sub-records are left unused (the group total below is authoritative).
// Record every fused node's geometry plus its raw per-tensor byte/storage facts (captured by

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the word "facts" confusing in this PR.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if it is clearer now

int64_t src_bytes[GGML_MAX_SRC] = {}; // ggml_nbytes(source)
uint64_t dst_sid = 0; // storage id (view_src root) of destination
uint64_t src_ids[GGML_MAX_SRC] = {}; // source tensor id (dedup key)
uint64_t src_sids[GGML_MAX_SRC] = {}; // source storage id (view_src root)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The definition of storage id and tensor id are not clear to me

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if it is clearer now

@roberteg16 roberteg16 changed the title roofline: emit raw per-tensor facts for DDR byte accounting (single + fused) roofline: emit raw per-tensor data for DDR byte accounting (single + fused) Jul 14, 2026
roberteg16 and others added 4 commits July 14, 2026 05:08
Fused rows previously carried a group HBM byte total computed in-tree. Instead,
emit raw per-fused-node facts -- each tensor's byte count, a storage id
(view_src root, so aliasing is visible) and a source tensor id -- and let the
consumer (rocm-scripts tools/roofline) compute external in/out.

This lets the consumer apply the exclusion policy it owns: skip no-op views
(VIEW/RESHAPE), drop in-place destinations (e.g. SET_ROWS/CPY writing their own
dst), exclude internal tensors, and dedup reads by source. It also matches how
non-fused rows already work (producer reports facts, consumer sums).

Co-Authored-By: Claude Opus 4 (1M context) <noreply@anthropic.com>
Non-fused rows already emit dst/src byte counts; also emit the dst storage id,
per-source ids and per-source storage ids (all already captured by
fill_head_record). This lets the consumer apply the same in-place-destination
rule to single kernels as to fused ones -- e.g. a standalone CPY or SET_ROWS no
longer has its write target (dst passed in as a source) double-counted.

Co-Authored-By: Claude Opus 4 (1M context) <noreply@anthropic.com>
Address review: define "tensor id" (a ggml_tensor's address, dedup key) and
"storage id" (the view_src-root buffer address, shared by aliasing tensors) at
the op_record fields, and drop the vague word "facts" from the surrounding
comments in favour of concrete wording.

Co-Authored-By: Claude Opus 4 (1M context) <noreply@anthropic.com>
Address review: the emitted keys and op_record members used cryptic names.
Rename dst_sid -> dst_storage_id, src_ids -> src_tensor_ids, src_sids ->
src_storage_ids (both the C++ members and the JSON keys). No behavior change.

Co-Authored-By: Claude Opus 4 (1M context) <noreply@anthropic.com>
@roberteg16 roberteg16 force-pushed the rogarcia.roofline-fused-raw-facts branch from 7928cfe to 43efae8 Compare July 14, 2026 12:09
@roberteg16 roberteg16 changed the base branch from rogarcia.roofline to gfx11 July 14, 2026 12:09
@roberteg16 roberteg16 requested a review from mgehre-amd July 14, 2026 13:19
Extend the op_record comment: the storage id alone is not enough. The storage id
(buffer identity) drives the view/in-place/internal exclusions; the tensor id
drives read dedup. They diverge when distinct sources alias one buffer (e.g. two
ops reading the two halves of a tensor: one storage id, two tensor ids) --
deduping by storage id would undercount, so dedup keys on the tensor id.

Co-Authored-By: Claude Opus 4 (1M context) <noreply@anthropic.com>
@roberteg16 roberteg16 requested a review from marcusr-amd July 14, 2026 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants