Skip to content

Commit 82d883b

Browse files
authored
Merge branch 'main' into memleak-fix
2 parents 59a9bdb + 4d19115 commit 82d883b

File tree

11 files changed

+61
-11
lines changed

11 files changed

+61
-11
lines changed

cmake/helpers.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ function(add_ur_target_compile_options name)
7070
)
7171
if (CMAKE_BUILD_TYPE STREQUAL "Release")
7272
target_compile_definitions(${name} PRIVATE -D_FORTIFY_SOURCE=2)
73+
target_compile_options(${name} PRIVATE -fvisibility=hidden)
7374
endif()
7475
if(UR_DEVELOPER_MODE)
7576
target_compile_options(${name} PRIVATE

examples/collector/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ target_link_libraries(${TARGET_NAME} PRIVATE ${TARGET_XPTI})
1717
target_include_directories(${TARGET_NAME} PRIVATE ${xpti_SOURCE_DIR}/include)
1818

1919
if(MSVC)
20-
target_compile_definitions(${TARGET_NAME} PRIVATE
21-
XPTI_STATIC_LIBRARY XPTI_CALLBACK_API_EXPORTS)
20+
target_compile_definitions(${TARGET_NAME} PRIVATE XPTI_STATIC_LIBRARY)
2221
endif()
22+
target_compile_definitions(${TARGET_NAME} PRIVATE XPTI_CALLBACK_API_EXPORTS)

include/ur_api.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,17 @@ typedef enum ur_structure_type_t {
332332
#if defined(_WIN32)
333333
/// @brief Microsoft-specific dllexport storage-class attribute
334334
#define UR_APIEXPORT __declspec(dllexport)
335+
#endif // defined(_WIN32)
336+
#endif // UR_APIEXPORT
337+
338+
///////////////////////////////////////////////////////////////////////////////
339+
#ifndef UR_APIEXPORT
340+
#if __GNUC__ >= 4
341+
/// @brief GCC-specific dllexport storage-class attribute
342+
#define UR_APIEXPORT __attribute__((visibility("default")))
335343
#else
336344
#define UR_APIEXPORT
337-
#endif // defined(_WIN32)
345+
#endif // __GNUC__ >= 4
338346
#endif // UR_APIEXPORT
339347

340348
///////////////////////////////////////////////////////////////////////////////

scripts/core/common.yml

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ desc: "Microsoft-specific dllexport storage-class attribute"
3939
condition: "defined(_WIN32)"
4040
name: $X_APIEXPORT
4141
value: __declspec(dllexport)
42+
--- #--------------------------------------------------------------------------
43+
type: macro
44+
desc: "GCC-specific dllexport storage-class attribute"
45+
condition: "__GNUC__ >= 4"
46+
name: $X_APIEXPORT
47+
value: __attribute__ ((visibility ("default")))
4248
altvalue: ""
4349
--- #--------------------------------------------------------------------------
4450
type: macro

source/adapters/level_zero/context.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,8 @@ ur_result_t ur_context_handle_t_::getFreeSlotInExistingOrNewPool(
530530
counterBasedExt.flags =
531531
ZE_EVENT_POOL_COUNTER_BASED_EXP_FLAG_NON_IMMEDIATE;
532532
}
533+
logger::debug("ze_event_pool_desc_t counter based flags set to: {}",
534+
counterBasedExt.flags);
533535
ZeEventPoolDesc.pNext = &counterBasedExt;
534536
}
535537

source/adapters/level_zero/event.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ ur_result_t urEnqueueEventsWaitWithBarrier(
196196
//
197197
if (Queue->isInOrderQueue() && InOrderBarrierBySignal &&
198198
!Queue->isProfilingEnabled()) {
199-
if (EventWaitList.Length) {
199+
// If we are using driver in order lists, then append wait on events
200+
// is unnecessary and we can signal the event created.
201+
if (EventWaitList.Length && !CmdList->second.IsInOrderList) {
200202
ZE2UR_CALL(zeCommandListAppendWaitOnEvents,
201203
(CmdList->first, EventWaitList.Length,
202204
EventWaitList.ZeEventList));
@@ -1546,8 +1548,13 @@ ur_result_t _ur_ze_event_list_t::createAndRetainUrZeEventList(
15461548

15471549
ZE2UR_CALL(zeCommandListAppendWaitOnEvents,
15481550
(ZeCommandList, 1u, &EventList[I]->ZeEvent));
1549-
if (!MultiDeviceEvent->CounterBasedEventsEnabled)
1551+
if (!MultiDeviceEvent->CounterBasedEventsEnabled) {
15501552
ZE2UR_CALL(zeEventHostSignal, (MultiDeviceZeEvent));
1553+
} else {
1554+
ZE2UR_CALL(zeCommandListAppendSignalEvent,
1555+
(ZeCommandList, MultiDeviceZeEvent));
1556+
}
1557+
MultiDeviceEvent->Completed = true;
15511558

15521559
UR_CALL(Queue->executeCommandList(CommandList, /* IsBlocking */ false,
15531560
/* OkToBatchCommand */ true));

source/adapters/level_zero/kernel.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,19 @@ ur_result_t urEnqueueDeviceGlobalVariableWrite(
494494
) {
495495
std::scoped_lock<ur_shared_mutex> lock(Queue->Mutex);
496496

497+
ze_module_handle_t ZeModule{};
498+
auto It = Program->ZeModuleMap.find(Queue->Device->ZeDevice);
499+
if (It != Program->ZeModuleMap.end()) {
500+
ZeModule = It->second;
501+
} else {
502+
ZeModule = Program->ZeModule;
503+
}
504+
497505
// Find global variable pointer
498506
size_t GlobalVarSize = 0;
499507
void *GlobalVarPtr = nullptr;
500508
ZE2UR_CALL(zeModuleGetGlobalPointer,
501-
(Program->ZeModule, Name, &GlobalVarSize, &GlobalVarPtr));
509+
(ZeModule, Name, &GlobalVarSize, &GlobalVarPtr));
502510
if (GlobalVarSize < Offset + Count) {
503511
setErrorMessage("Write device global variable is out of range.",
504512
UR_RESULT_ERROR_INVALID_VALUE,

source/adapters/level_zero/queue.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -2386,6 +2386,7 @@ ur_command_list_ptr_t &ur_queue_handle_t_::ur_queue_group_t::getImmCmdList() {
23862386
ZeCommandQueueDesc.ordinal = QueueOrdinal;
23872387
ZeCommandQueueDesc.index = QueueIndex;
23882388
ZeCommandQueueDesc.mode = ZE_COMMAND_QUEUE_MODE_ASYNCHRONOUS;
2389+
bool isInOrderList = false;
23892390
const char *Priority = "Normal";
23902391
if (Queue->isPriorityLow()) {
23912392
ZeCommandQueueDesc.priority = ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_LOW;
@@ -2401,6 +2402,7 @@ ur_command_list_ptr_t &ur_queue_handle_t_::ur_queue_group_t::getImmCmdList() {
24012402
}
24022403

24032404
if (Queue->Device->useDriverInOrderLists() && Queue->isInOrderQueue()) {
2405+
isInOrderList = true;
24042406
ZeCommandQueueDesc.flags |= ZE_COMMAND_QUEUE_FLAG_IN_ORDER;
24052407
}
24062408

@@ -2449,7 +2451,7 @@ ur_command_list_ptr_t &ur_queue_handle_t_::ur_queue_group_t::getImmCmdList() {
24492451
ZeCommandList,
24502452
ur_command_list_info_t(
24512453
nullptr, true, false, nullptr, ZeCommandQueueDesc,
2452-
Queue->useCompletionBatching(), true, false, true)})
2454+
Queue->useCompletionBatching(), true, isInOrderList, true)})
24532455
.first;
24542456

24552457
return ImmCmdLists[Index];

source/loader/ur_loader.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ namespace ur_loader {
1717
context_t *getContext() { return context_t::get_direct(); }
1818

1919
ur_result_t context_t::init() {
20+
#ifdef _WIN32
21+
// Suppress system errors.
22+
// Tells the system to not display the critical-error-handler message box.
23+
// Instead, the system sends the error to the calling process.
24+
// This is crucial for graceful handling of adapters that couldn't be
25+
// loaded, e.g. due to missing native run-times.
26+
// TODO: add reporting in case of an error.
27+
// NOTE: we restore the old mode to not affect user app behavior.
28+
// See https://github.com/intel/llvm/blob/sycl/sycl/ur_win_proxy_loader/ur_win_proxy_loader.cpp (preloadLibraries())
29+
UINT SavedMode = SetErrorMode(SEM_FAILCRITICALERRORS);
30+
#endif
31+
2032
#ifdef UR_STATIC_ADAPTER_LEVEL_ZERO
2133
// If the adapters were force loaded, it means the user wants to use
2234
// a specific adapter library. Don't load any static adapters.
@@ -35,6 +47,10 @@ ur_result_t context_t::init() {
3547
}
3648
}
3749
}
50+
#ifdef _WIN32
51+
// Restore system error handling.
52+
(void)SetErrorMode(SavedMode);
53+
#endif
3854

3955
forceIntercept = getenv_tobool("UR_ENABLE_LOADER_INTERCEPT");
4056

test/layers/tracing/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ target_link_libraries(test_collector PRIVATE ${TARGET_XPTI})
1515
target_include_directories(test_collector PRIVATE ${xpti_SOURCE_DIR}/include)
1616

1717
if(MSVC)
18-
target_compile_definitions(test_collector PRIVATE
19-
XPTI_STATIC_LIBRARY XPTI_CALLBACK_API_EXPORTS)
18+
target_compile_definitions(test_collector PRIVATE XPTI_STATIC_LIBRARY)
2019
endif()
20+
target_compile_definitions(test_collector PRIVATE XPTI_CALLBACK_API_EXPORTS)
2121

2222
function(set_tracing_test_props target_name collector_name)
2323
set_tests_properties(${target_name} PROPERTIES

tools/urtrace/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ target_link_libraries(${TARGET_NAME} PRIVATE ${TARGET_XPTI} ${PROJECT_NAME}::com
1717
target_include_directories(${TARGET_NAME} PRIVATE ${xpti_SOURCE_DIR}/include)
1818

1919
if(MSVC)
20-
target_compile_definitions(${TARGET_NAME} PRIVATE
21-
XPTI_STATIC_LIBRARY XPTI_CALLBACK_API_EXPORTS)
20+
target_compile_definitions(${TARGET_NAME} PRIVATE XPTI_STATIC_LIBRARY)
2221
endif()
22+
target_compile_definitions(${TARGET_NAME} PRIVATE XPTI_CALLBACK_API_EXPORTS)
2323

2424
set(UR_TRACE_CLI_BIN ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/urtrace)
2525

0 commit comments

Comments
 (0)