Skip to content

Commit 6a35427

Browse files
authored
Merge pull request #2832 from oneapi-src/mirror-commits-
Mirror intel/llvm commits
2 parents 2b671ac + e4ae6f9 commit 6a35427

File tree

10 files changed

+116
-37
lines changed

10 files changed

+116
-37
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
84518c193adb9d8b03ae449345d892c6c9984846
1+
cbea6003f58953ebf25e1ed353d3d7ac37191e8c

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.

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."

source/adapters/level_zero/v2/command_list_manager.cpp

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -907,19 +907,66 @@ ur_result_t ur_command_list_manager::bindlessImagesImageCopyExp(
907907
}
908908

909909
ur_result_t ur_command_list_manager::bindlessImagesWaitExternalSemaphoreExp(
910-
ur_exp_external_semaphore_handle_t /*hSemaphore*/, bool /*hasWaitValue*/,
911-
uint64_t /*waitValue*/, uint32_t /*numEventsInWaitList*/,
912-
const ur_event_handle_t * /*phEventWaitList*/,
913-
ur_event_handle_t /*phEvent*/) {
914-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
910+
ur_exp_external_semaphore_handle_t hSemaphore, bool hasWaitValue,
911+
uint64_t waitValue, uint32_t numEventsInWaitList,
912+
const ur_event_handle_t *phEventWaitList, ur_event_handle_t phEvent) {
913+
auto hPlatform = hContext->getPlatform();
914+
if (!hPlatform->ZeExternalSemaphoreExt.Supported == false ||
915+
!hPlatform->ZeExternalSemaphoreExt.LoaderExtension) {
916+
UR_LOG_LEGACY(ERR,
917+
logger::LegacyMessage("[UR][L0] {} function not supported!"),
918+
"{} function not supported!", __FUNCTION__);
919+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
920+
}
921+
922+
auto zeSignalEvent =
923+
getSignalEvent(phEvent, UR_COMMAND_EXTERNAL_SEMAPHORE_WAIT_EXP);
924+
auto [pWaitEvents, numWaitEvents] =
925+
getWaitListView(phEventWaitList, numEventsInWaitList);
926+
927+
ze_external_semaphore_wait_params_ext_t waitParams = {
928+
ZE_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_WAIT_PARAMS_EXT, nullptr, 0};
929+
waitParams.value = hasWaitValue ? waitValue : 0;
930+
ze_external_semaphore_ext_handle_t hExtSemaphore =
931+
reinterpret_cast<ze_external_semaphore_ext_handle_t>(hSemaphore);
932+
ZE2UR_CALL(hPlatform->ZeExternalSemaphoreExt
933+
.zexCommandListAppendWaitExternalSemaphoresExp,
934+
(zeCommandList.get(), 1, &hExtSemaphore, &waitParams,
935+
zeSignalEvent, numWaitEvents, pWaitEvents));
936+
937+
return UR_RESULT_SUCCESS;
915938
}
916939

917940
ur_result_t ur_command_list_manager::bindlessImagesSignalExternalSemaphoreExp(
918-
ur_exp_external_semaphore_handle_t /*hSemaphore*/, bool /*hasSignalValue*/,
919-
uint64_t /*signalValue*/, uint32_t /*numEventsInWaitList*/,
920-
const ur_event_handle_t * /*phEventWaitList*/,
921-
ur_event_handle_t /*phEvent*/) {
922-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
941+
ur_exp_external_semaphore_handle_t hSemaphore, bool hasSignalValue,
942+
uint64_t signalValue, uint32_t numEventsInWaitList,
943+
const ur_event_handle_t *phEventWaitList, ur_event_handle_t phEvent) {
944+
auto hPlatform = hContext->getPlatform();
945+
if (!hPlatform->ZeExternalSemaphoreExt.Supported == false ||
946+
!hPlatform->ZeExternalSemaphoreExt.LoaderExtension) {
947+
UR_LOG_LEGACY(ERR,
948+
logger::LegacyMessage("[UR][L0] {} function not supported!"),
949+
"{} function not supported!", __FUNCTION__);
950+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
951+
}
952+
953+
auto zeSignalEvent =
954+
getSignalEvent(phEvent, UR_COMMAND_EXTERNAL_SEMAPHORE_SIGNAL_EXP);
955+
auto [pWaitEvents, numWaitEvents] =
956+
getWaitListView(phEventWaitList, numEventsInWaitList);
957+
958+
ze_external_semaphore_signal_params_ext_t signalParams = {
959+
ZE_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_SIGNAL_PARAMS_EXT, nullptr, 0};
960+
signalParams.value = hasSignalValue ? signalValue : 0;
961+
ze_external_semaphore_ext_handle_t hExtSemaphore =
962+
reinterpret_cast<ze_external_semaphore_ext_handle_t>(hSemaphore);
963+
964+
ZE2UR_CALL(hPlatform->ZeExternalSemaphoreExt
965+
.zexCommandListAppendSignalExternalSemaphoresExp,
966+
(zeCommandList.get(), 1, &hExtSemaphore, &signalParams,
967+
zeSignalEvent, numWaitEvents, pWaitEvents));
968+
969+
return UR_RESULT_SUCCESS;
923970
}
924971

925972
ur_result_t ur_command_list_manager::appendNativeCommandExp(

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+
}

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;

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.

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.

test/conformance/event/urEventSetCallback.cpp

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,24 @@
66

77
#include "fixtures.h"
88
#include "uur/known_failure.h"
9+
using namespace std::chrono_literals;
910

1011
/* Using urEventReferenceTest to be able to release the event during the test */
11-
using urEventSetCallbackTest = uur::event::urEventReferenceTest;
12+
struct urEventSetCallbackTest : uur::event::urEventReferenceTest {
13+
std::mutex m;
14+
std::condition_variable cv;
15+
int flag = 0;
16+
17+
void WaitForFlag(int Target = 1) {
18+
std::unique_lock lk(m);
19+
cv.wait_for(lk, 1000ms, [&] { return flag == Target; });
20+
}
21+
22+
void SetFlag() {
23+
flag++;
24+
cv.notify_one();
25+
}
26+
};
1227

1328
/**
1429
* Checks that the callback function is called.
@@ -22,19 +37,19 @@ TEST_P(urEventSetCallbackTest, Success) {
2237
[[maybe_unused]] ur_execution_info_t execStatus,
2338
void *pUserData) {
2439

25-
auto status = reinterpret_cast<bool *>(pUserData);
26-
*status = true;
40+
auto that = reinterpret_cast<urEventSetCallbackTest *>(pUserData);
41+
that->SetFlag();
2742
}
2843
};
2944

30-
bool didRun = false;
3145
ASSERT_SUCCESS(
3246
urEventSetCallback(event, ur_execution_info_t::UR_EXECUTION_INFO_COMPLETE,
33-
Callback::callback, &didRun));
47+
Callback::callback, this));
3448

3549
ASSERT_SUCCESS(urEventWait(1, &event));
3650
ASSERT_SUCCESS(urEventRelease(event));
37-
ASSERT_TRUE(didRun);
51+
WaitForFlag();
52+
ASSERT_EQ(flag, 1);
3853
}
3954

4055
/**
@@ -45,6 +60,7 @@ TEST_P(urEventSetCallbackTest, ValidateParameters) {
4560
uur::LevelZeroV2{}, uur::NativeCPU{});
4661

4762
struct CallbackParameters {
63+
urEventSetCallbackTest *test;
4864
ur_event_handle_t event;
4965
ur_execution_info_t execStatus;
5066
};
@@ -56,17 +72,19 @@ TEST_P(urEventSetCallbackTest, ValidateParameters) {
5672
auto parameters = reinterpret_cast<CallbackParameters *>(pUserData);
5773
parameters->event = hEvent;
5874
parameters->execStatus = execStatus;
75+
parameters->test->SetFlag();
5976
}
6077
};
6178

62-
CallbackParameters parameters{};
79+
CallbackParameters parameters{this, nullptr, UR_EXECUTION_INFO_QUEUED};
6380

6481
ASSERT_SUCCESS(
6582
urEventSetCallback(event, ur_execution_info_t::UR_EXECUTION_INFO_COMPLETE,
6683
Callback::callback, &parameters));
6784

6885
ASSERT_SUCCESS(urEventWait(1, &event));
6986
ASSERT_SUCCESS(urEventRelease(event));
87+
WaitForFlag();
7088
ASSERT_EQ(event, parameters.event);
7189
ASSERT_EQ(ur_execution_info_t::UR_EXECUTION_INFO_COMPLETE,
7290
parameters.execStatus);
@@ -80,6 +98,7 @@ TEST_P(urEventSetCallbackTest, AllStates) {
8098
uur::LevelZeroV2{}, uur::NativeCPU{});
8199

82100
struct CallbackStatus {
101+
urEventSetCallbackTest *test = nullptr;
83102
bool submitted = false;
84103
bool running = false;
85104
bool complete = false;
@@ -107,10 +126,12 @@ TEST_P(urEventSetCallbackTest, AllStates) {
107126
FAIL() << "Invalid execution info enumeration";
108127
}
109128
}
129+
130+
status->test->SetFlag();
110131
}
111132
};
112133

113-
CallbackStatus status{};
134+
CallbackStatus status{this};
114135

115136
ASSERT_SUCCESS(urEventSetCallback(
116137
event, ur_execution_info_t::UR_EXECUTION_INFO_SUBMITTED,
@@ -124,6 +145,7 @@ TEST_P(urEventSetCallbackTest, AllStates) {
124145

125146
ASSERT_SUCCESS(urEventWait(1, &event));
126147
ASSERT_SUCCESS(urEventRelease(event));
148+
WaitForFlag(3);
127149

128150
ASSERT_TRUE(status.submitted);
129151
ASSERT_TRUE(status.running);
@@ -145,19 +167,18 @@ TEST_P(urEventSetCallbackTest, EventAlreadyCompleted) {
145167
[[maybe_unused]] ur_execution_info_t execStatus,
146168
void *pUserData) {
147169

148-
auto status = reinterpret_cast<bool *>(pUserData);
149-
*status = true;
170+
auto that = reinterpret_cast<urEventSetCallbackTest *>(pUserData);
171+
that->SetFlag();
150172
}
151173
};
152174

153-
bool didRun = false;
154-
155175
ASSERT_SUCCESS(
156176
urEventSetCallback(event, ur_execution_info_t::UR_EXECUTION_INFO_COMPLETE,
157-
Callback::callback, &didRun));
177+
Callback::callback, this));
158178

159179
ASSERT_SUCCESS(urEventRelease(event));
160-
ASSERT_TRUE(didRun);
180+
WaitForFlag();
181+
ASSERT_EQ(flag, 1);
161182
}
162183

163184
UUR_INSTANTIATE_DEVICE_TEST_SUITE(urEventSetCallbackTest);

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)