diff --git a/unified-runtime/source/adapters/offload/program.cpp b/unified-runtime/source/adapters/offload/program.cpp index dde21a20b2c24..cf497c571f1b0 100644 --- a/unified-runtime/source/adapters/offload/program.cpp +++ b/unified-runtime/source/adapters/offload/program.cpp @@ -108,7 +108,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithBinary( phProgram); } - ur_program_handle_t Program = new ur_program_handle_t_(); + ur_program_handle_t Program = new ur_program_handle_t_{}; + Program->URContext = hContext; + Program->Binary = RealBinary; + Program->BinarySizeInBytes = RealLength; auto Res = olCreateProgram(hContext->Device->OffloadDevice, RealBinary, RealLength, &Program->OffloadProgram); @@ -137,6 +140,19 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramBuildExp(ur_program_handle_t, return UR_RESULT_SUCCESS; } +UR_APIEXPORT ur_result_t UR_APICALL urProgramCompile(ur_context_handle_t, + ur_program_handle_t, + const char *) { + // Do nothing, program is built upon creation + return UR_RESULT_SUCCESS; +} + +UR_APIEXPORT ur_result_t UR_APICALL +urProgramCreateWithIL(ur_context_handle_t, const void *, size_t, + const ur_program_properties_t *, ur_program_handle_t *) { + return UR_RESULT_ERROR_COMPILER_NOT_AVAILABLE; +} + UR_APIEXPORT ur_result_t UR_APICALL urProgramGetInfo(ur_program_handle_t hProgram, ur_program_info_t propName, size_t propSize, void *pPropValue, size_t *pPropSizeRet) { @@ -145,8 +161,42 @@ urProgramGetInfo(ur_program_handle_t hProgram, ur_program_info_t propName, switch (propName) { case UR_PROGRAM_INFO_REFERENCE_COUNT: return ReturnValue(hProgram->RefCount.load()); - default: + case UR_PROGRAM_INFO_CONTEXT: + return ReturnValue(hProgram->URContext); + case UR_PROGRAM_INFO_NUM_DEVICES: + return ReturnValue(1); + case UR_PROGRAM_INFO_DEVICES: + return ReturnValue(&hProgram->URContext->Device, 1); + case UR_PROGRAM_INFO_IL: + return ReturnValue(reinterpret_cast(0), 0); + case UR_PROGRAM_INFO_BINARY_SIZES: + return ReturnValue(&hProgram->BinarySizeInBytes, 1); + case UR_PROGRAM_INFO_BINARIES: { + if (!pPropValue && !pPropSizeRet) { + return UR_RESULT_ERROR_INVALID_NULL_POINTER; + } + + if (pPropValue != nullptr) { + if (propSize < sizeof(void *)) { + return UR_RESULT_ERROR_INVALID_SIZE; + } + + std::memcpy(*reinterpret_cast(pPropValue), hProgram->Binary, + hProgram->BinarySizeInBytes); + } + + if (pPropSizeRet != nullptr) { + *pPropSizeRet = sizeof(void *); + } + break; + } + case UR_PROGRAM_INFO_NUM_KERNELS: + case UR_PROGRAM_INFO_KERNEL_NAMES: + // Program introspection is not available for liboffload (or generally, + // amdgpu/cuda) return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION; + default: + return UR_RESULT_ERROR_INVALID_ENUMERATION; } return UR_RESULT_SUCCESS; diff --git a/unified-runtime/source/adapters/offload/program.hpp b/unified-runtime/source/adapters/offload/program.hpp index 1d0263aad2998..abd0f41c18ba9 100644 --- a/unified-runtime/source/adapters/offload/program.hpp +++ b/unified-runtime/source/adapters/offload/program.hpp @@ -17,4 +17,7 @@ struct ur_program_handle_t_ : RefCounted { ol_program_handle_t OffloadProgram; + ur_context_handle_t URContext; + const uint8_t *Binary; + size_t BinarySizeInBytes; }; diff --git a/unified-runtime/source/adapters/offload/ur_interface_loader.cpp b/unified-runtime/source/adapters/offload/ur_interface_loader.cpp index ef3902e0b006c..3c6a9a86d4def 100644 --- a/unified-runtime/source/adapters/offload/ur_interface_loader.cpp +++ b/unified-runtime/source/adapters/offload/ur_interface_loader.cpp @@ -86,9 +86,9 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetProgramProcAddrTable( return result; } pDdiTable->pfnBuild = urProgramBuild; - pDdiTable->pfnCompile = nullptr; + pDdiTable->pfnCompile = urProgramCompile; pDdiTable->pfnCreateWithBinary = urProgramCreateWithBinary; - pDdiTable->pfnCreateWithIL = nullptr; + pDdiTable->pfnCreateWithIL = urProgramCreateWithIL; pDdiTable->pfnCreateWithNativeHandle = urProgramCreateWithNativeHandle; pDdiTable->pfnGetBuildInfo = nullptr; pDdiTable->pfnGetFunctionPointer = nullptr; diff --git a/unified-runtime/test/conformance/testing/include/uur/checks.h b/unified-runtime/test/conformance/testing/include/uur/checks.h index 9bcbc6a8afae2..d5ad05af97cfb 100644 --- a/unified-runtime/test/conformance/testing/include/uur/checks.h +++ b/unified-runtime/test/conformance/testing/include/uur/checks.h @@ -41,7 +41,8 @@ inline std::ostream &operator<<(std::ostream &out, const Result &result) { do { \ auto status = ret; \ if (status == UR_RESULT_ERROR_UNSUPPORTED_FEATURE || \ - status == UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION) { \ + status == UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION || \ + status == UR_RESULT_ERROR_COMPILER_NOT_AVAILABLE) { \ GTEST_SKIP(); \ } else { \ ASSERT_EQ(status, UR_RESULT_SUCCESS); \