hipFile: Ensure HIP Runtime is initialized before calling into hipAmdFileRead/hipAmdFileWrite#223
Open
kurtmcmillan wants to merge 4 commits intodevelopfrom
Open
hipFile: Ensure HIP Runtime is initialized before calling into hipAmdFileRead/hipAmdFileWrite#223kurtmcmillan wants to merge 4 commits intodevelopfrom
kurtmcmillan wants to merge 4 commits intodevelopfrom
Conversation
hipFileRead & hipFileWrite use private/hidden HIP Runtime APIs which, initially, did not ensure that the HIP Runtime was initialized which resulted in a SEGFAULT. This change ensures that the HIP Runtime is initialized when hipFileRead/hipFileWrite are the first HIP API calls of a thread.
ae22184 to
5457f1d
Compare
derobins
approved these changes
Mar 17, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds an explicit HIP runtime initialization step to the Fastpath backend before calling the private hipAmdFileRead/hipAmdFileWrite APIs, to avoid a HIP runtime segfault when those are the first HIP calls on a newly created thread.
Changes:
- Add a
Hip::hipInit()wrapper method and a correspondingMHipmock method. - Add a per-thread initialization guard in
Fastpath::io()that callshipInit()once per thread. - Update Fastpath unit tests to expect an initialization call.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/amd_detail/backend/fastpath.cpp |
Adds per-thread HIP runtime init guard in Fastpath::io() |
src/amd_detail/hip.h |
Extends Hip interface with hipInit() |
src/amd_detail/hip.cpp |
Implements Hip::hipInit() via ::hipInit(0) |
test/amd_detail/mhip.h |
Adds hipInit() mock to MHip |
test/amd_detail/fastpath.cpp |
Updates Fastpath IO tests to expect hipInit() |
CHANGELOG.md |
Documents the Fastpath initialization safeguard |
Comments suppressed due to low confidence (1)
test/amd_detail/fastpath.cpp:346
- The new
EXPECT_CALL(mhip, hipInit);expectation is set in everyexpect_io()call, but the production code uses athread_localguard and will only callhipInit()once per thread for the whole test process. Since gtest typically runs these parametrized tests sequentially on the same thread, after the firstFastpath().io(...)callhipInit()will no longer be invoked and later tests will fail due to an unsatisfied expectation. Adjust the tests to allowhipInit()to be called 0 or 1 times (or restructure to run the IO on a fresh thread / reset the per-thread init state in a test-only way).
struct FastpathIoParam : public FastpathTestBase, public TestWithParam<IoType> {
StrictMock<MHip> mhip;
void expect_io()
{
EXPECT_CALL(mhip, hipInit);
EXPECT_CALL(*mbuffer, getBuffer).WillOnce(Return(DEFAULT_BUFFER_ADDR));
EXPECT_CALL(*mbuffer, getLength).WillOnce(Return(DEFAULT_BUFFER_LENGTH));
EXPECT_CALL(*mfile, getUnbufferedFd).WillOnce(Return(DEFAULT_UNBUFFERED_FD));
}
void expect_io(optional<int> fd, void *bufptr, size_t buflen)
{
EXPECT_CALL(mhip, hipInit);
EXPECT_CALL(*mbuffer, getBuffer).WillOnce(Return(bufptr));
EXPECT_CALL(*mbuffer, getLength).WillOnce(Return(buflen));
EXPECT_CALL(*mfile, getUnbufferedFd).WillOnce(Return(fd));
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
riley-dixon
approved these changes
Mar 18, 2026
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.
Motivation
Avoid causing a SEGFAULT in the HIP Runtime.
AIHIPFILE-157
Technical Details
A storage partner recently hit a SEGFAULT when testing hipFile with vllm. vllm performs IO within a thread and the first call into the HIP Runtime is hipAmdFileRead/hipAmdFileWrite through the fastpath backend. Since these HIP Runtime APIs are private, it wasn't anticipated that they would need to perform any initialization. Library initialization checks are being added to hipAmdFileRead/hipAmdFileWrite (ROCm/rocm-systems#4068) This change is a temporary while there is the possibility that hipFile will run with an unpatched HIP Runtime.