Skip to content

Commit 0d4249c

Browse files
authored
[UR] Allow urProgramGetFunctionPointer to return UNSUPPORTED (#19802)
This is primarily for liboffload which doesn't support it yet, and probably never will for AMD devices (which don't seem to have this functionality). In theory it will also affect level zero, at least according to a comment, but urProgramGetFunctionPointer seems to be implemented there.
1 parent 9e30d20 commit 0d4249c

File tree

7 files changed

+23
-12
lines changed

7 files changed

+23
-12
lines changed

unified-runtime/include/ur_api.h

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unified-runtime/scripts/core/program.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ returns:
323323
- "If `pFunctionName` couldn't be found in `hProgram`."
324324
- $X_RESULT_ERROR_FUNCTION_ADDRESS_NOT_AVAILABLE:
325325
- "If `pFunctionName` could be located, but its address couldn't be retrieved."
326+
- $X_RESULT_ERROR_UNSUPPORTED_FEATURE:
327+
- "If the backend does not support querying function pointers."
326328
--- #--------------------------------------------------------------------------
327329
type: function
328330
desc: "Retrieves a pointer to a device global variable."

unified-runtime/source/adapters/offload/program.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramGetGlobalVariablePointer(
293293

294294
return UR_RESULT_SUCCESS;
295295
}
296+
297+
UR_APIEXPORT ur_result_t UR_APICALL
298+
urProgramGetFunctionPointer([[maybe_unused]] ur_device_handle_t hDevice,
299+
[[maybe_unused]] ur_program_handle_t hProgram,
300+
[[maybe_unused]] const char *pFunctionName,
301+
[[maybe_unused]] void **ppFunctionPointer) {
302+
// liboffload doesn't support a representation of function pointers (yet)
303+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
304+
}

unified-runtime/source/adapters/offload/ur_interface_loader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetProgramProcAddrTable(
9191
pDdiTable->pfnCreateWithIL = urProgramCreateWithIL;
9292
pDdiTable->pfnCreateWithNativeHandle = urProgramCreateWithNativeHandle;
9393
pDdiTable->pfnGetBuildInfo = nullptr;
94-
pDdiTable->pfnGetFunctionPointer = nullptr;
94+
pDdiTable->pfnGetFunctionPointer = urProgramGetFunctionPointer;
9595
pDdiTable->pfnGetGlobalVariablePointer = urProgramGetGlobalVariablePointer;
9696
pDdiTable->pfnGetInfo = urProgramGetInfo;
9797
pDdiTable->pfnGetNativeHandle = urProgramGetNativeHandle;

unified-runtime/source/loader/ur_libapi.cpp

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unified-runtime/source/ur_api.cpp

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unified-runtime/test/conformance/program/urProgramGetFunctionPointer.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ TEST_P(urProgramGetFunctionPointerTest, Success) {
2424
void *function_pointer = nullptr;
2525
ur_result_t res = urProgramGetFunctionPointer(
2626
device, program, function_name.data(), &function_pointer);
27-
if (res == UR_RESULT_ERROR_FUNCTION_ADDRESS_NOT_AVAILABLE) {
27+
if (res == UR_RESULT_ERROR_FUNCTION_ADDRESS_NOT_AVAILABLE ||
28+
res == UR_RESULT_ERROR_UNSUPPORTED_FEATURE) {
2829
return;
2930
}
3031
ASSERT_SUCCESS(res);
@@ -36,17 +37,10 @@ TEST_P(urProgramGetFunctionPointerTest, InvalidKernelName) {
3637
std::string missing_function = "aFakeFunctionName";
3738
auto result = urProgramGetFunctionPointer(
3839
device, program, missing_function.data(), &function_pointer);
39-
ur_backend_t backend;
40-
ASSERT_SUCCESS(urPlatformGetInfo(platform, UR_PLATFORM_INFO_BACKEND,
41-
sizeof(backend), &backend, nullptr));
42-
// TODO: level zero backend incorrectly returns
43-
// UR_RESULT_ERROR_UNSUPPORTED_FEATURE
44-
if (backend == UR_BACKEND_LEVEL_ZERO) {
45-
ASSERT_EQ(UR_RESULT_ERROR_UNSUPPORTED_FEATURE, result);
46-
} else {
47-
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_KERNEL_NAME, result);
40+
if (result == UR_RESULT_ERROR_UNSUPPORTED_FEATURE) {
41+
return;
4842
}
49-
43+
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_KERNEL_NAME, result);
5044
ASSERT_EQ(function_pointer, nullptr);
5145
}
5246

0 commit comments

Comments
 (0)