Skip to content

enh(pmc_l2_analyzer): support rocpd SQLite DB input (rocprofv3 >= ROCm 7.x)#658

Draft
Arist12 wants to merge 1 commit into
ROCm:mainfrom
Arist12:enh/pmc-rocpd-db
Draft

enh(pmc_l2_analyzer): support rocpd SQLite DB input (rocprofv3 >= ROCm 7.x)#658
Arist12 wants to merge 1 commit into
ROCm:mainfrom
Arist12:enh/pmc-rocpd-db

Conversation

@Arist12
Copy link
Copy Markdown
Contributor

@Arist12 Arist12 commented Jun 4, 2026

Problem

rocprofv3 --pmc on ROCm >= 7.x writes PMC counter results to a SQLite
database (pmc_*_results.db) rather than a flat CSV file. The previous
pmc_l2_analyzer.py only accepted CSV input, so any analysis on a ROCm 7.x
system required a manual intermediate step: open the DB, query the four rocpd
tables, export to a compatibility CSV, then run the analyzer.

Solution

Add native rocpd SQLite DB support alongside the existing CSV path.

New internal function _load_counters_from_db(path, kernel):

  • Opens the DB read-only via sqlite3.connect("file:...?mode=ro", uri=True).
  • Discovers the UUID-suffixed table set by scanning sqlite_master for
    rocpd_pmc_event_<uuid>. The UUID suffix is opaque and changes between
    runs, so table names cannot be hard-coded.
  • Joins the four required tables:
    rocpd_info_kernel_symbol_<uuid>  (id, name)
    rocpd_kernel_dispatch_<uuid>     (id, kernel_symbol_id)
    rocpd_info_pmc_<uuid>            (id, name)
    rocpd_pmc_event_<uuid>           (id, pmc_id, dispatch_id, value)
    
  • Filters dispatches by --kernel substring on the kernel symbol name.
  • Returns the same (agg, dispatches) pair as the CSV path so the rest of
    main() is unchanged.
  • Prints a warning if any required table is missing rather than crashing.

load_counters() dispatches on file extension:

  • .db → rocpd path
  • anything else → CSV path (unchanged behavior)

Multiple files of mixed types can be passed in one invocation (the typical
workflow: two separate --pmc runs produce two DBs):

python pmc_l2_analyzer.py pmc_l2_results.db pmc_ea_results.db \
    --kernel pa_mqa_logits_fp4_kernel_0

Also removes the pre-existing dead assignment req = agg.get("TCC_REQ_sum", 0)
that was never used.

Usage comparison

# ROCm < 7.x  (CSV output, unchanged)
python pmc_l2_analyzer.py pmc_l2_counter_collection.csv pmc_ea_counter_collection.csv \
    --kernel pa_mqa_logits_fp4_kernel_0

# ROCm >= 7.x  (rocpd DB output, new)
python pmc_l2_analyzer.py pmc_l2_results.db pmc_ea_results.db \
    --kernel pa_mqa_logits_fp4_kernel_0

# Mixed
python pmc_l2_analyzer.py pmc_l2_results.db pmc_ea_counter_collection.csv \
    --kernel pa_mqa_logits_fp4_kernel_0

Testing

Eight unit tests using tempfile mock DBs and CSVs:

  1. CSV path with kernel filter — unchanged behavior.
  2. CSV path with no filter — unchanged behavior.
  3. rocpd DB with kernel filter — correct counter aggregation.
  4. rocpd DB with no filter — returns all dispatches.
  5. Mixed DB + CSV in one call — counters are summed correctly.
  6. DB with non-trivial UUID suffix — UUID discovery works.
  7. Empty DB (no rocpd tables) — returns empty gracefully, no crash.
  8. Kernel name not found in DB — returns empty gracefully.

All eight pass.

…m 7.x)

rocprofv3 --pmc on ROCm >= 7.x writes SQLite databases (pmc_*_results.db)
instead of CSV files.  The previous version of pmc_l2_analyzer.py only
accepted CSV, requiring a manual export step to query the DB and produce a
compatibility CSV before any analysis could run.

Add native rocpd SQLite DB support:

  _load_counters_from_db(path, kernel):
    Discovers the UUID-suffixed table set (rocpd_pmc_event_<uuid>,
    rocpd_info_pmc_<uuid>, rocpd_kernel_dispatch_<uuid>,
    rocpd_info_kernel_symbol_<uuid>) by scanning sqlite_master.  Joins the
    four tables to aggregate counter values for dispatches whose kernel name
    matches the --kernel substring filter, then returns the same
    (agg, dispatches) pair as the CSV path.

  load_counters() dispatches on file extension:
    .db  → rocpd path
    anything else → existing CSV path (unchanged behavior)

  Multiple files of mixed types can be passed in a single invocation, which
  is the normal workflow: two separate --pmc runs (one for L2 counters, one
  for EA/bandwidth counters) produce two DBs that are analyzed together.

  Prints "Input format(s): rocpd" or "csv" so users can tell which path ran.

Also removes the dead req = agg.get("TCC_REQ_sum", 0) assignment that was
present in the original but never used.

Usage with DB input:
    python pmc_l2_analyzer.py pmc_l2_results.db pmc_ea_results.db \\
        --kernel pa_mqa_logits_fp4_kernel_0
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.

1 participant