Repository navigation
refactor(miopen): Layering refactor Phase 1: common_utils - #8813
Closed
NolanHannaAMD wants to merge 12 commits into
Closed
NolanHannaAMD wants to merge 12 commits into
NolanHannaAMD wants to merge 12 commits into
Conversation
… to depend on anything.
Adds script/check_layering.sh: a grep-based, per-phase guard framework that enforces the layered architecture from the MIOpen layering refactor plan. The Phase 1 check rejects any non-commented `#include <miopen/...>` under common_utils/include, keeping the Core Utilities layer free of MIOpen deps. Phases 2-5 are documented stubs to be wired on in their own PRs. Wired in as a `local` pre-commit hook (layering-guard-miopen), mirroring the existing gtest-format-miopen hook, so it runs in CI via the existing pre-commit workflow. The check is pure bash/grep (~12ms, no GPU/build required). Intentional exceptions (src/kernels RTC headers, the common_utils errors/float8 helpers) are whitelisted in-script with one-line reasons.
✅ All Checks Passed — Ready for Review
📖 Need help? See the Policy FAQ for details on every check and how to fix failures. |
|
🎉 All checks passed! This PR is ready for review. |
….com:ROCm/rocm-libraries into users/nhanna/miopen-layering-refactor-phase1
The layering refactor moved bfloat16 into the build-only common_utils layer, breaking two CI jobs: - Tuna Fin (builds against the installed package) failed with 'miopen/bfloat16.hpp' file not found. Add a src/include/miopen/bfloat16.hpp forwarding shim to common_utils/bfloat16.hpp, install that header under include/common_utils (gated on MIOPEN_INSTALL_CXX_HEADERS), and pull miopen/config.h in the shim so external consumers that don't link MIOpen::common_utils still get MIOPEN_USE_RNE_BFLOAT16. - Hip Package gtest failed with undeclared 'env' in bn.hpp: the env alias it relied on was leaked transitively via driver/random.hpp, which is now gone. Fully-qualify the call site as miopen::env::value.
…n-layering-refactor-phase1
Contributor
|
This pull request has been inactive for 25 days and will be marked as stale. If you would like to keep this PR open, please:
This PR will be automatically closed in 5 days if no further activity occurs. |
Contributor
|
This pull request has been automatically closed due to inactivity (30 days with no updates). If you'd like to continue working on this, feel free to reopen the PR or create a new one. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
JIRA ID : ALMIOPEN-2228
Summary
This is Phase 1 of the MIOpen layering refactor, which reorganizes the codebase into clean, enforced layers with no internal-symbol leakage across boundaries (full plan: MIOpenLayeringRefactorPlan.md). It introduces
common_utils/— a header-onlyINTERFACElibrary forming the bottom "Core Utilities" layer — and moves pure utility headers out of MIOpen internals into it, so the library, driver, tests, and speedtests share them through an explicit build edge rather than reaching intosrc/include/miopen/. The change is intended to be functionally equivalent with one documented diagnostic-only concession (see Technical Changes).Risk Assessment
Medium risk. Each step is a behavior-preserving code-move + include-rewrite, but the blast radius is broad: ~209 files change and the moved headers (
bfloat16,stringutils,ford,float_equal) are used pervasively inside the library itself, not just in driver/tests. Build wiring spans the top-level,src/,driver/,test/,test/gtest/, andspeedtests/CMake. A full GPU build andctesthave not been run locally (blocked by a pre-existing unrelated missinglibsqlite3.so), so PR CI is the primary functional gate.randomdecoupling (additional consideration). The one place this PR is not strictly behavior-preserving is common_utils/random.hpp. The seeding value is unchanged - it reads the same MIOPEN_DEBUG_DRIVER_PRNG_SEED variable, keeps the same 12345678 default, and still maps 0 → std::random_device - so PRNG sequences (and therefore driver/test data generation and verification across the ~30 driver consumers and the test helpers) are identical. The risk is twofold and bounded: (1) an observability regression - the IsPerformanceLoggingEnabled() branch that emitted the seed as JSON ({"prng_seed":N}) is dropped, leaving only the plain PRNG seed: N line, so any tooling that scrapes performance logs for the JSON seed field would no longer find it; and (2) an env-read semantics change - the MIOpen env::value(...) UINT64 wrapper is replaced with std::getenv + std::strtoull, which is a different parse path for the same variable (the common case is equivalent, but malformed/edge-case values could parse differently).Note: After speaking with Jason Campbell, it should not be a problem removing the performance logging for PRNG seed. But we should have deeper discussion if any other performance logging would need to change, but that isn't necessary for this work.
ASIC Coverage
ASIC-independent. This is build-layering plumbing and include-path rewrites with no change to kernel selection, support surface, or default runtime behavior; the
bfloat16rounding scheme is preserved (theMIOPEN_USE_RNE_BFLOAT16value is forwarded unchanged via an INTERFACE compile definition, now guarded by#errorif undefined). Standard PR CI is sufficient; no dedicated multi-arch sweep is required.Testing Summary
common_utils/has zeromiopen/includes and that all oldsrc/include/miopen/paths were removed with no stray references.common_utilsheaders compile standalone withg++ -std=c++17 -fsyntax-only; thebfloat16#errorguard was confirmed to fire when the define is absent.driver/driver.cpp,test/gtest/cache.cpp) compile clean with-fsyntax-only.$<BUILD_INTERFACE:...>so it stays out of MIOpen's export set).ctestare pending a working build environment.Testing Checklist
grep -rn '#include' common_utils/ | grep miopen→ empty) - Status: Passedg++ -std=c++17 -fsyntax-only(all common_utils headers) - Status: Passed#ifndef MIOPEN_USE_RNE_BFLOAT16guard fires when undefined - Status: Passeddriver/driver.cpp,test/gtest/cache.cpp- Status: PassedMIOpen,MIOpenDriver, test suite, speedtests - Status: Not runMIOpenDriver conv/bnorm/pool -V 1- Status: Not runctest- Status: Not runTechnical Changes
common_utils/as a header-onlyINTERFACElibrary (miopen_common_utils/MIOpen::common_utils),BUILD_INTERFACE-only andEXCLUDE_FROM_ALL— not installed, not exported, not part of the public API.src/include/miopen/intocommon_utils/include/common_utils/:algorithm,each_args,float_equal,par_for,rank,returns,type_name,functional,ford(Tier A/B);bfloat16,reduce_common(Tier C);stringutils,tensor_layout(Tier D). Rewrites ~166 consumer include sites acrosssrc,driver,test,test/gtest, andspeedtests.bfloat16.hppfrommiopen/config.h: theMIOPEN_USE_RNE_BFLOAT16option is now propagated as an INTERFACE compile definition, with an#ifndef … #errorguard so the rounding scheme can never silently flip; the option declaration was moved earlier in the top-level CMake so its value exists whencommon_utilsconfigures.common_utils/errors.hppwith a lightweightCOMMON_THROW(std::runtime_error) — deliberately not a move of the heavymiopen/errors.hpp.stringutilsandtensor_layoutswap their 3MIOPEN_THROWsites onto it. Verified behavior-preserving at the C-API boundary: bothMIOPEN_THROW(defaultmiopenStatusUnknownError) and a caughtstd::exceptionmap to the same returned status; the only observable difference is the absence of the hostname prefix in the diagnostic string.common_utils/random.hpp(decoupled fromdriver/random.hpp), replacingenv::value(MIOPEN_DEBUG_DRIVER_PRNG_SEED)withstd::getenv, deletesdriver/random.hpp, and repoints its consumers. Behavior concession: drops theIsPerformanceLoggingEnabled()JSON-seed log line, leaving only the plainPRNG seed: Noutput.<cstdint>inbfloat16,<numeric>intensor_layout), previously supplied transitively viamiopen/config.h/miopen/errors.hpp.miopen/errors.hpp, and thefloat8impl. The CI layering guard (grep-based boundary enforcement + whitelist) is planned for this PR before merge and tracked as a TODO in the testing checklist above.External Impact
Moving the files into the build-only common_utils layer surfaced two consumer breakages:
What this means for the refactor: internal utilities must stay internal, and installed-package consumers need explicit, auditable seams (forwarding shims + targeted installs) rather than accidental transitive availability. The forwarding shims are a temporary bridge — the follow-up is to update MIFin to include the common_utils ones directly and bump the submodule, after which the shim and its install can potentially be removed, though we should verify that no other external sources are using them in the same way.