Defer static init to first API call.#235
Conversation
f4488fc to
30811a5
Compare
9d0038c to
9f0e017
Compare
There was a problem hiding this comment.
Pull request overview
This PR shifts hipFile’s AMD backend initialization from a global/static constructor pattern to explicit, first-API-call initialization, and updates stats plumbing to support that change while adding CI coverage for C++20 builds.
Changes:
- Replace global static initialization with
hipFileInit()invoked at the top of public C API entry points. - Introduce
IStatsServerand updateContext<>to allow an interface type to map to a concrete default implementation. - Add a C++ standard toggle (17/20) to CMake and CI, plus tests covering the deferred-init behavior.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/system/amd/io.cpp | Adds a regression test for multi-threaded first-use initialization behavior. |
| test/amd_detail/mstats.h | Updates mock stats server to implement the new IStatsServer interface. |
| test/amd_detail/fastpath.cpp | Adjusts expectations for configuration/stats interactions during IO paths. |
| test/amd_detail/fallback.cpp | Adds mocked stats server usage and expectations in fallback IO tests. |
| src/amd_detail/stats.h | Introduces IStatsServer and makes StatsServer implement it. |
| src/amd_detail/stats.cpp | Routes stats collection through Context<IStatsServer> instead of Context<StatsServer>. |
| src/amd_detail/hipfile.cpp | Calls hipFileInit() in many public API functions to defer initialization. |
| src/amd_detail/hip.cpp | Adjusts symbol lookup helpers (removes HIPFILE_STATIC caching in helper functions). |
| src/amd_detail/context.h | Adds default-implementation mapping for Context<> and replaces HipFileInit class with hipFileInit(). |
| src/amd_detail/context.cpp | Implements hipFileInit() and removes the global/static init object. |
| src/amd_detail/configuration.cpp | Removes cached env/symbol checks (previously HIPFILE_STATIC) for some configuration getters. |
| shared/hipfile-cpp20.h | Adds a portability macro for C++20 requires usage. |
| CMakeLists.txt | Adds AIS_CXX_STANDARD cache option (17/20). |
| cmake/AISAddLibraries.cmake | Uses AIS_CXX_STANDARD to set target C++ standard. |
| cmake/AISAddExecutable.cmake | Uses AIS_CXX_STANDARD to set target C++ standard. |
| .github/workflows/build-ais.yml | Adds cxx_standard and generate_coverage inputs; passes standard to CMake. |
| .github/workflows/ais-ci.yml | Adds a dedicated C++20 build/test job. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
05c0364 to
839cb5c
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 18 out of 18 changed files in this pull request and generated 8 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
005e409 to
bb49eea
Compare
bb49eea to
3206016
Compare
Adds ContextDefaultImpl, which has a type that defaults to the template type. Can be specialized to use different default type for a given template type.
Add an interface for StatsServer, so that a mock doesn't need to call StatsServer constructor. Adds specialization to ContextDefaultImpl so that StatsServer is used as default implementation for IStatsServer.
If multiple interfaces are being mocked, the standard implementation may end up calling mocked functions when constructing. Return the replacement first, so we only construct the standard implementation when it is actually needed.
3206016 to
90845dd
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ssize_t | ||
| hipFileIo(IoType type, hipFileHandle_t fh, const void *buffer_base, size_t size, hoff_t file_offset, | ||
| hoff_t buffer_offset, const vector<shared_ptr<Backend>> &backends) | ||
| try { | ||
| hipFileInit(); | ||
| auto [file, buffer] = Context<DriverState>::get()->getFileAndBuffer(fh, buffer_base); |
There was a problem hiding this comment.
hipFileInit() was moved into hipFileIo(), but hipFileRead()/hipFileWrite() pass getCachedBackends() as a function argument. The order of evaluation of function arguments is not guaranteed, so getCachedBackends() (and the underlying Context<DriverState>::get()->getBackends() static initialization) may run before hipFileInit(). That undermines the goal of deferring static initialization until after mocks are installed and can reintroduce startup/threading issues.
Consider fetching the cached backends inside hipFileIo() after calling hipFileInit() (or otherwise ensure hipFileInit() is sequenced before any context/backend initialization), rather than relying on argument-evaluation order.
|
|
||
| StrictMock<MHip> mhip{}; | ||
| StrictMock<MSys> msys{}; | ||
| StrictMock<MStatsServer> mserver{}; |
There was a problem hiding this comment.
In the change i'm working on, I've made the stats collections functions a mockable class which removes the need to mock the calls to statsLevel() and getStats()
Moves current static init to a hipFileInit function. It will be called from any public API function.
Allows use when compiled in C++20 for better type checking, but left out when compiled in C++17 mode.
90845dd to
7437235
Compare
|
Imported to ROCm/rocm-systems pull 4864 |
This PR moves static initialization of hipFile objects to the first API call. This allows mocking of static objects that call mockable functions, as we can now mock the calls before they are initialized.
Changes: