Skip to content

Commit

Permalink
Merge pull request oneapi-src#1661 from frasercrmck/fix-hip-program-i…
Browse files Browse the repository at this point in the history
…nfo-build-type

[HIP] Add support for querying program binary type
  • Loading branch information
kbenzie authored Jun 13, 2024
2 parents 15c789d + db05ea4 commit 94e8395
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
13 changes: 10 additions & 3 deletions source/adapters/hip/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ urProgramCreateWithIL(ur_context_handle_t, const void *, size_t,
UR_APIEXPORT ur_result_t UR_APICALL
urProgramCompile(ur_context_handle_t hContext, ur_program_handle_t hProgram,
const char *pOptions) {
return urProgramBuild(hContext, hProgram, pOptions);
UR_CHECK_ERROR(urProgramBuild(hContext, hProgram, pOptions));
// urProgramBuild sets the BinaryType to UR_PROGRAM_BINARY_TYPE_EXECUTABLE, so
// set it to the correct value for urProgramCompile post-hoc.
hProgram->BinaryType = UR_PROGRAM_BINARY_TYPE_COMPILED_OBJECT;
return UR_RESULT_SUCCESS;
}

UR_APIEXPORT ur_result_t UR_APICALL urProgramCompileExp(ur_program_handle_t,
Expand Down Expand Up @@ -312,6 +316,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramBuild(ur_context_handle_t,
ScopedContext Active(hProgram->getDevice());

hProgram->buildProgram(pOptions);
hProgram->BinaryType = UR_PROGRAM_BINARY_TYPE_EXECUTABLE;

} catch (ur_result_t Err) {
Result = Err;
Expand Down Expand Up @@ -355,13 +360,14 @@ urProgramGetBuildInfo(ur_program_handle_t hProgram, ur_device_handle_t,
UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);

switch (propName) {
case UR_PROGRAM_BUILD_INFO_STATUS: {
case UR_PROGRAM_BUILD_INFO_STATUS:
return ReturnValue(hProgram->BuildStatus);
}
case UR_PROGRAM_BUILD_INFO_OPTIONS:
return ReturnValue(hProgram->BuildOptions.c_str());
case UR_PROGRAM_BUILD_INFO_LOG:
return ReturnValue(hProgram->InfoLog, hProgram->MAX_LOG_SIZE);
case UR_PROGRAM_BUILD_INFO_BINARY_TYPE:
return ReturnValue(hProgram->BinaryType);
default:
break;
}
Expand Down Expand Up @@ -494,6 +500,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithBinary(
UR_ASSERT(Result == UR_RESULT_SUCCESS, Result);

*phProgram = RetProgram.release();
(*phProgram)->BinaryType = UR_PROGRAM_BINARY_TYPE_COMPILED_OBJECT;

return Result;
}
Expand Down
6 changes: 6 additions & 0 deletions source/adapters/hip/program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ struct ur_program_handle_t_ {
ur_device_handle_t Device;
std::string ExecutableCache;

// The ur_program_binary_type_t property is defined individually for every
// device in a program. However, since the HIP adapter only has 1 device per
// program, there is no need to keep track of its value for each
// device.
ur_program_binary_type_t BinaryType = UR_PROGRAM_BINARY_TYPE_NONE;

// Metadata
bool IsRelocatable = false;

Expand Down
1 change: 0 additions & 1 deletion test/conformance/program/program_adapter_hip.match
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
urProgramBuildTest.BuildFailure/AMD_HIP_BACKEND___{{.*}}_
# HIP hasn't implemented urProgramCreateWithNativeHandleTest
{{OPT}}urProgramCreateWithNativeHandleTest.Success/AMD_HIP_BACKEND___{{.*}}_
urProgramGetBuildInfoTest.Success/AMD_HIP_BACKEND___{{.*}}___UR_PROGRAM_BUILD_INFO_BINARY_TYPE
# This test flakily fails
{{OPT}}urProgramGetBuildInfoSingleTest.LogIsNullTerminated/AMD_HIP_BACKEND___{{.*}}_
# HIP doesn't expose kernel numbers or names
Expand Down

0 comments on commit 94e8395

Please sign in to comment.