← Back to Pull requests

TheRock : Code Coverage - enable per-project code coverage builds #8598

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Sep 29, 2026 15:48 UTC
Author

Motivation

GitHub issue: https://github.com/ROCm/TheRock/issues/6572

TheRock configures each rocm-libraries and rocm-systems project as a separate CMake subproject and passes it only the arguments TheRock declares.

Instrumenting a library for code coverage today means knowing that library's own option name and passing it through the per-subproject argument, for example -DhipDNN_CMAKE_ARGS=-DHIPDNN_ENABLE_COVERAGE=ON. RFC0014 asks for one option name for every project, -D<PROJECT>_ENABLE_COVERAGE=ON, and for group options that let a nightly build instrument every supported library at once. This PR adds both.

Design

Split out PR https://github.com/ROCm/TheRock/pull/7783 into six PRs, stacked in this order from the bottom: https://github.com/ROCm/TheRock/pull/9717, https://github.com/ROCm/TheRock/pull/8602, https://github.com/ROCm/TheRock/pull/10334, https://github.com/ROCm/TheRock/pull/8598, https://github.com/ROCm/TheRock/pull/10335 and https://github.com/ROCm/TheRock/pull/8605. This PR doesn't depend on the three below it; it sits on them only because a stack is a single chain.

Below is a modified design of what each PR will do.

PR https://github.com/ROCm/TheRock/pull/8598 - build instrumentation (following https://github.com/ROCm/TheRock/issues/6572)
cmake/therock_subproject.cmake passes -D<PROJECT_NAME>_ENABLE_COVERAGE unchanged to that subproject's configure. The project's own option then turns on instrumentation; a project that doesn't implement the option builds normally. Each project in rocm-libraries and rocm-systems has to implement <PROJECT_NAME>_ENABLE_COVERAGE in its own CMake files. That work is outside these PRs.
CMakeLists.txt adds three group options (THEROCK_COVERAGE_ROCM_LIBRARIES_ALL, THEROCK_COVERAGE_ROCM_SYSTEMS_ALL, THEROCK_COVERAGE_ALL), the project lists, and a loop that sets <PROJECT_NAME>_ENABLE_COVERAGE=ON for the listed projects unless it is already set, so an explicit -D<PROJECT_NAME>_ENABLE_COVERAGE=OFF wins. All three default to OFF, so a normal build is unchanged.

PR https://github.com/ROCm/TheRock/pull/8602 - report script
Adds merge_coverage_report.py, which merges the .profraw files and writes an lcov file, a text summary and an HTML report. The coverage test workflow (test_code_coverage_component.yml) and its installer (install_rocm_code_coverage_build.py) that produce those files already exist on main: the installer installs a baseline ROCm and replaces the project under test with its instrumented build, and the workflow runs the tests and uploads the .profraw files.

PR https://github.com/ROCm/TheRock/pull/9717 - stage build input
Adds an extra_cmake_options input to the Linux and Windows stage builds. The value goes through an environment variable, is split on whitespace, and is appended to the stage's cmake command. It is empty by default. For coverage, https://github.com/ROCm/TheRock/pull/8605 uses it to pass its coverage options to the math-libs build: -DHIPDNN_ENABLE_COVERAGE=ON today, plus any group options.

PR https://github.com/ROCm/TheRock/pull/10334 - test and report workflow
multi_arch_ci_coverage_report.yml runs the coverage test workflow for one project, split across parallel test jobs. It then merges the profiles with https://github.com/ROCm/TheRock/pull/8602's merge_coverage_report.py and uploads the report as a workflow artifact, and to Codecov when a token is configured.

PR https://github.com/ROCm/TheRock/pull/10335 - CI matrix script
configure_coverage_ci.py picks the projects (hipDNN for now) and their coverage options. Three workflow inputs, coverage_rocm_libraries_all, coverage_rocm_systems_all and coverage_all, add https://github.com/ROCm/TheRock/pull/8598's matching group options.

PR https://github.com/ROCm/TheRock/pull/8605 - CI entry workflow
multi_arch_ci_coverage_linux.yml is the entry point, started by a manual dispatch or called by another workflow, such as a nightly. It runs configure_coverage_ci.py, builds compiler-runtime, builds math-libs with the coverage options through https://github.com/ROCm/TheRock/pull/9717's input, and starts one report job per project and GPU family.

Note:-
rocm-libraries projects don't share one coverage option name. hipDNN and hipCCL use <PROJECT_NAME>_ENABLE_COVERAGE (for example HIPDNN_ENABLE_COVERAGE), but most others still use older names such as BUILD_CODE_COVERAGE (rocBLAS, rocSPARSE, rocSOLVER, rocFFT, ...) or CODE_COVERAGE (rocRAND). We plan to move every project to <PROJECT_NAME>_ENABLE_COVERAGE, where <PROJECT_NAME> is TheRock's subproject name in upper case, and we still need to estimate the effort for each project.

So for now, the workflows in all the PRs above are validated with hipDNN. hipCCL also reads HIPCCL_ENABLE_COVERAGE, but its instrumented build doesn't link on the CI build image yet (see Known limitation), so it stays in the group list and the coverage CI turns it off for now.

Technical Details

TheRock forwards the option and adds no compiler or linker flags of its own. Each project decides in its own CMake what instrumentation means.

  • cmake/therock_subproject.cmake: therock_cmake_subproject_activate() upper-cases the subproject's name, so hipDNN looks for HIPDNN_ENABLE_COVERAGE. If that variable is set in TheRock's configure, its value (ON or OFF) is added unchanged to hipDNN's configure command.

  • CMakeLists.txt: three options, all OFF by default, set <PROJECT>_ENABLE_COVERAGE=ON for the subprojects in a fixed list. THEROCK_COVERAGE_ROCM_LIBRARIES_ALL covers the 16 rocm-libraries subprojects in THEROCK_COVERAGE_ROCM_LIBRARIES_PROJECTS, THEROCK_COVERAGE_ROCM_SYSTEMS_ALL covers rccl and rocshmem (THEROCK_COVERAGE_ROCM_SYSTEMS_PROJECTS), and THEROCK_COVERAGE_ALL covers both lists. hipBLASLt and hipTensor are left out until their instrumented builds link, and test subprojects aren't listed because they read their library's option. An explicit -D<PROJECT>_ENABLE_COVERAGE=OFF wins over a group option.

  • Docs: a new docs/development/code_coverage.md covers local builds, the group options and what a project's option must do; #8605 adds its CI sections and how to add a project. development_guide.md gets a {PROJECT}_ENABLE_COVERAGE entry, and the docs index links the new page.
  • Known limitation

    THEROCK_COVERAGE_ROCM_LIBRARIES_ALL currently breaks the math-libs build unless hipCCL is turned off. hipCCL's option makes its bundled rocPRIM add -Xarch_host -fprofile-instr-generate to the link of every target that uses it. That flag links LLVM's profiling runtime, which needs libdl and libpthread on the CI build image (glibc 2.28), and hipCCL doesn't add them. In a trial run of this change with all three group options, hipCCL_tests (16 programs) and libhipcxx (3 programs) failed to link. The hipCCL code involved is unchanged at 6b5f0a1.

    hipCCL needs to link ${CMAKE_DL_LIBS} and Threads::Threads when coverage is on, as code_coverage.md requires. Until it does, -DHIPCCL_ENABLE_COVERAGE=OFF keeps hipCCL out of a group build, and the coverage CI (#10335) passes it whenever the rocm-libraries or all group is on. hipBLASLt and hipTensor are left out of the rocm-libraries list until their instrumented builds link.

    Changes since the last review

    Earlier revisions translated <PROJECT>_ENABLE_COVERAGE into each project's own option inside TheRock (cmake/therock_coverage.cmake), using a project registry that CMake ran from build_tools/github_actions/configure_coverage_ci.py. The open design questions from review were about that layer: the link flags, the device-code flags, CMake depending on build_tools/github_actions/, and the registry's scope. This revision removes it. configure_coverage_ci.py and its tests leave this PR; they are now in #10335, and only #8605's entry workflow calls the script.

    Risk

    Low (2/5). With no coverage option set, no subproject's configure command changes: the pass-through adds an argument only when <PROJECT>_ENABLE_COVERAGE is set, and the group options default to OFF.

    Test Plan

  • pre-commit run on the changed files, and cmake/tests/therock_subproject_prebuilt_test.py, which loads therock_subproject.cmake outside the super-project.

  • An instrumented hipDNN build in TheRock's CI build image, using the compiler and runtime artifacts from CI run 42980689088. It is configured with -DTHEROCK_ENABLE_ALL=OFF -DTHEROCK_ENABLE_HIPDNN=ON -DHIPDNN_ENABLE_COVERAGE=ON and built with ninja hipDNN+build. hipDNN's tests then run on a GPU, and TheRock's llvm-profdata and llvm-cov merge and report the profiles.

  • The group options in CI, through the coverage workflows in this stack, run end to end on draft #10016.

  • Multi-Arch CI on this PR, which builds with no coverage options.
  • Test Result

    Testing locally

  • pre-commit passes, and therock_subproject_prebuilt_test.py passes 6 of 6.

  • The hipDNN build ran with this pass-through at an earlier base (8f76580), on AlmaLinux 8 with glibc 2.28. The only coverage argument TheRock passed to hipDNN was -DHIPDNN_ENABLE_COVERAGE=ON, and hipDNN's cache shows HIPDNN_ENABLE_COVERAGE:BOOL=ON.

  • 697 of 697 compile steps carry -fprofile-instr-generate -fcoverage-mapping, and 59 of 59 link steps carry -fprofile-instr-generate. The build and link succeed.

  • On an MI325X, hipDNN's 8 test programs ran 12,687 tests, all passing, and wrote 97 .profraw files. Using hipDNN's own object list, llvm-cov reports 88.2% line coverage.
  • Testing in CI

  • Run 45937528507 on #10016, with all three group options: the math-libs configure received -DHIPDNN_ENABLE_COVERAGE=ON, the three group options and -DHIPCCL_ENABLE_COVERAGE=OFF, and logged Coverage: enabling <PROJECT>_ENABLE_COVERAGE for the other 16 listed projects. The instrumented build passed, and hipDNN's tests and coverage report (83.80% of lines) ran on it.

  • An earlier trial with all three group options and no hipCCL override (run 43937869712) failed to link hipCCL's consumers, as described under Known limitation.

  • On this PR: pre-commit, Unit Tests (Linux and Windows), the security scan and the Consumer Graph Drift Check pass. Multi-Arch CI: in progress (run 46054382227).
  • No Windows coverage build has run.

    Submission Checklist

  • Look over the contributing guidelines at https://github.com/ROCm/TheRock/blob/main/CONTRIBUTING.md.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: endurthiabhilash Review duration: 90819m
    All Vouch review confidence checks passed
    Residual risk 0.33 = Change Risk (0.59) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.59 · 650 lines diff across 8 files
    0.59
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #8598"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 59% (MEDIUM) · Higher = larger blast radius
    59%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 44.7% · Lower = rushed or shallow review
    44.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 32.6% · Safe to merge
    32.6%
    Repository