From f62270d673db2c3b9a92f165cc1d50712ad9d0ac Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 27 May 2026 08:52:45 +0000 Subject: [PATCH 1/7] Initial plan From e32bacdede5305572776096c4c7698cda902e747 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 27 May 2026 09:05:40 +0000 Subject: [PATCH 2/7] fix(ur): locate LLVMOffload in multiarch install dirs --- .../source/adapters/offload/CMakeLists.txt | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/unified-runtime/source/adapters/offload/CMakeLists.txt b/unified-runtime/source/adapters/offload/CMakeLists.txt index a60b5ef78eb09..cf869b8df7bb2 100644 --- a/unified-runtime/source/adapters/offload/CMakeLists.txt +++ b/unified-runtime/source/adapters/offload/CMakeLists.txt @@ -25,7 +25,9 @@ add_ur_adapter(${TARGET_NAME} set(UR_OFFLOAD_INSTALL_DIR "" CACHE PATH "Path to the directory containing libomptarget.so etc") set(UR_OFFLOAD_INCLUDE_DIR "" CACHE PATH "Path to the directory containing LLVM headers") +set(UR_OFFLOAD_BUILD_FROM_SOURCE OFF) if (UR_OFFLOAD_INSTALL_DIR STREQUAL "" OR UR_OFFLOAD_INCLUDE_DIR STREQUAL "") + set(UR_OFFLOAD_BUILD_FROM_SOURCE ON) include(ExternalProject) set(LLVM_PROJECT_SOURCE_DIR ${CMAKE_BINARY_DIR}/llvm-src-offload) set(LLVM_PROJECT_TAG 32beea0605f37ea7a6429375d41b19ee78ddfe7d) @@ -132,12 +134,30 @@ if (CUDA_cuda_driver_LIBRARY) target_compile_definitions(${TARGET_NAME} PRIVATE UR_CUDA_ENABLED) endif() +if(UR_OFFLOAD_BUILD_FROM_SOURCE) + set(UR_OFFLOAD_LLVMOFFLOAD_LIBRARY + "${UR_OFFLOAD_INSTALL_DIR}/lib/libLLVMOffload${CMAKE_SHARED_LIBRARY_SUFFIX}") +else() + find_library(UR_OFFLOAD_LLVMOFFLOAD_LIBRARY + NAMES LLVMOffload + HINTS "${UR_OFFLOAD_INSTALL_DIR}" + PATH_SUFFIXES + "${CMAKE_INSTALL_LIBDIR}" + lib + lib64 + "lib/${LLVM_HOST_TRIPLE}" + "lib/${LLVM_DEFAULT_TARGET_TRIPLE}" + NO_DEFAULT_PATH + REQUIRED + ) +endif() + target_link_libraries(${TARGET_NAME} PRIVATE ${PROJECT_NAME}::headers ${PROJECT_NAME}::common ${PROJECT_NAME}::umf ur_common - ${UR_OFFLOAD_INSTALL_DIR}/lib/libLLVMOffload.so + ${UR_OFFLOAD_LLVMOFFLOAD_LIBRARY} ${ADDITIONAL_LINK_LIBS} ) From 3621aa0959b628aba679ece47203aec0e0a66b36 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 27 May 2026 09:08:14 +0000 Subject: [PATCH 3/7] fix(ur): support multiarch LLVMOffload library lookup --- .../source/adapters/offload/CMakeLists.txt | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/unified-runtime/source/adapters/offload/CMakeLists.txt b/unified-runtime/source/adapters/offload/CMakeLists.txt index cf869b8df7bb2..f790bf802759a 100644 --- a/unified-runtime/source/adapters/offload/CMakeLists.txt +++ b/unified-runtime/source/adapters/offload/CMakeLists.txt @@ -145,11 +145,22 @@ else() "${CMAKE_INSTALL_LIBDIR}" lib lib64 - "lib/${LLVM_HOST_TRIPLE}" - "lib/${LLVM_DEFAULT_TARGET_TRIPLE}" NO_DEFAULT_PATH - REQUIRED ) + if(NOT UR_OFFLOAD_LLVMOFFLOAD_LIBRARY) + file(GLOB UR_OFFLOAD_LLVMOFFLOAD_LIBRARY_CANDIDATES + "${UR_OFFLOAD_INSTALL_DIR}/lib*/libLLVMOffload${CMAKE_SHARED_LIBRARY_SUFFIX}" + "${UR_OFFLOAD_INSTALL_DIR}/lib*/*/libLLVMOffload${CMAKE_SHARED_LIBRARY_SUFFIX}" + ) + if(UR_OFFLOAD_LLVMOFFLOAD_LIBRARY_CANDIDATES) + list(SORT UR_OFFLOAD_LLVMOFFLOAD_LIBRARY_CANDIDATES) + list(GET UR_OFFLOAD_LLVMOFFLOAD_LIBRARY_CANDIDATES 0 UR_OFFLOAD_LLVMOFFLOAD_LIBRARY) + endif() + endif() + if(NOT UR_OFFLOAD_LLVMOFFLOAD_LIBRARY) + message(FATAL_ERROR + "Failed to find libLLVMOffload in ${UR_OFFLOAD_INSTALL_DIR}") + endif() endif() target_link_libraries(${TARGET_NAME} PRIVATE From 70628d4f077efb41f8fbdfd20d1d73c6e8b34f1a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 27 May 2026 10:13:27 +0000 Subject: [PATCH 4/7] fix(ur): update offload enqueue calls for new OffloadAPI signatures --- unified-runtime/source/adapters/offload/enqueue.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/unified-runtime/source/adapters/offload/enqueue.cpp b/unified-runtime/source/adapters/offload/enqueue.cpp index 4405e21cc2918..b0b2312b2c125 100644 --- a/unified-runtime/source/adapters/offload/enqueue.cpp +++ b/unified-runtime/source/adapters/offload/enqueue.cpp @@ -41,7 +41,8 @@ ol_result_t makeEvent(ur_command_t Type, ol_queue_handle_t OlQueue, ur_queue_handle_t UrQueue, ur_event_handle_t *UrEvent) { if (UrEvent) { auto *Event = new ur_event_handle_t_(Type, UrQueue); - if (auto Res = olCreateEvent(OlQueue, &Event->OffloadEvent)) { + if (auto Res = olCreateEvent(OlQueue, static_cast(0), + &Event->OffloadEvent)) { delete Event; return Res; }; @@ -84,7 +85,8 @@ ur_result_t doWait(ur_queue_handle_t hQueue, uint32_t numEventsInWaitList, if (Q == TargetQueue) { continue; } - OL_RETURN_ON_ERR(olCreateEvent(Q, &OffloadHandles.emplace_back())); + OL_RETURN_ON_ERR(olCreateEvent(Q, static_cast(0), + &OffloadHandles.emplace_back())); } OL_RETURN_ON_ERR(olWaitEvents(TargetQueue, OffloadHandles.data(), OffloadHandles.size())); @@ -202,7 +204,8 @@ static ur_result_t urEnqueueKernelLaunch( OL_RETURN_ON_ERR(olLaunchKernel( Queue, hQueue->OffloadDevice, hKernel->OffloadKernel, - hKernel->Args.getStorage(), hKernel->Args.getStorageSize(), &LaunchArgs)); + hKernel->Args.getStorage(), hKernel->Args.getStorageSize(), &LaunchArgs, + nullptr)); OL_RETURN_ON_ERR(makeEvent(UR_COMMAND_KERNEL_LAUNCH, Queue, hQueue, phEvent)); return UR_RESULT_SUCCESS; @@ -261,7 +264,8 @@ ur_result_t doMemcpy(ur_command_t Command, ur_queue_handle_t hQueue, olMemcpy(Queue, DestPtr, DestDevice, SrcPtr, SrcDevice, size)); if (phEvent) { auto *Event = new ur_event_handle_t_(Command, hQueue); - if (auto Res = olCreateEvent(Queue, &Event->OffloadEvent)) { + if (auto Res = olCreateEvent(Queue, static_cast(0), + &Event->OffloadEvent)) { delete Event; return offloadResultToUR(Res); }; From 482d663f96b505fb7d885be311b5eb582d8010b2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 27 May 2026 10:14:30 +0000 Subject: [PATCH 5/7] refactor(ur): use named default offload event flags constant --- unified-runtime/source/adapters/offload/enqueue.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/unified-runtime/source/adapters/offload/enqueue.cpp b/unified-runtime/source/adapters/offload/enqueue.cpp index b0b2312b2c125..6b8a984ee13ec 100644 --- a/unified-runtime/source/adapters/offload/enqueue.cpp +++ b/unified-runtime/source/adapters/offload/enqueue.cpp @@ -19,6 +19,8 @@ #include "ur2offload.hpp" namespace { +constexpr ol_event_flags_t DefaultEventFlags = static_cast(0); + ol_result_t waitOnEvents(ol_queue_handle_t Queue, const ur_event_handle_t *UrEvents, size_t NumEvents) { if (NumEvents) { @@ -41,7 +43,7 @@ ol_result_t makeEvent(ur_command_t Type, ol_queue_handle_t OlQueue, ur_queue_handle_t UrQueue, ur_event_handle_t *UrEvent) { if (UrEvent) { auto *Event = new ur_event_handle_t_(Type, UrQueue); - if (auto Res = olCreateEvent(OlQueue, static_cast(0), + if (auto Res = olCreateEvent(OlQueue, DefaultEventFlags, &Event->OffloadEvent)) { delete Event; return Res; @@ -85,7 +87,7 @@ ur_result_t doWait(ur_queue_handle_t hQueue, uint32_t numEventsInWaitList, if (Q == TargetQueue) { continue; } - OL_RETURN_ON_ERR(olCreateEvent(Q, static_cast(0), + OL_RETURN_ON_ERR(olCreateEvent(Q, DefaultEventFlags, &OffloadHandles.emplace_back())); } OL_RETURN_ON_ERR(olWaitEvents(TargetQueue, OffloadHandles.data(), @@ -264,7 +266,7 @@ ur_result_t doMemcpy(ur_command_t Command, ur_queue_handle_t hQueue, olMemcpy(Queue, DestPtr, DestDevice, SrcPtr, SrcDevice, size)); if (phEvent) { auto *Event = new ur_event_handle_t_(Command, hQueue); - if (auto Res = olCreateEvent(Queue, static_cast(0), + if (auto Res = olCreateEvent(Queue, DefaultEventFlags, &Event->OffloadEvent)) { delete Event; return offloadResultToUR(Res); From 77defdf778b67eb53e39cbacc688f897fa8bbc87 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 27 May 2026 10:15:09 +0000 Subject: [PATCH 6/7] style(ur): align offload event flag constant naming --- unified-runtime/source/adapters/offload/enqueue.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/unified-runtime/source/adapters/offload/enqueue.cpp b/unified-runtime/source/adapters/offload/enqueue.cpp index 6b8a984ee13ec..a4b06beb62303 100644 --- a/unified-runtime/source/adapters/offload/enqueue.cpp +++ b/unified-runtime/source/adapters/offload/enqueue.cpp @@ -19,7 +19,8 @@ #include "ur2offload.hpp" namespace { -constexpr ol_event_flags_t DefaultEventFlags = static_cast(0); +constexpr ol_event_flags_t OL_DEFAULT_EVENT_FLAGS = + static_cast(0); ol_result_t waitOnEvents(ol_queue_handle_t Queue, const ur_event_handle_t *UrEvents, size_t NumEvents) { @@ -43,7 +44,7 @@ ol_result_t makeEvent(ur_command_t Type, ol_queue_handle_t OlQueue, ur_queue_handle_t UrQueue, ur_event_handle_t *UrEvent) { if (UrEvent) { auto *Event = new ur_event_handle_t_(Type, UrQueue); - if (auto Res = olCreateEvent(OlQueue, DefaultEventFlags, + if (auto Res = olCreateEvent(OlQueue, OL_DEFAULT_EVENT_FLAGS, &Event->OffloadEvent)) { delete Event; return Res; @@ -87,7 +88,7 @@ ur_result_t doWait(ur_queue_handle_t hQueue, uint32_t numEventsInWaitList, if (Q == TargetQueue) { continue; } - OL_RETURN_ON_ERR(olCreateEvent(Q, DefaultEventFlags, + OL_RETURN_ON_ERR(olCreateEvent(Q, OL_DEFAULT_EVENT_FLAGS, &OffloadHandles.emplace_back())); } OL_RETURN_ON_ERR(olWaitEvents(TargetQueue, OffloadHandles.data(), @@ -266,7 +267,7 @@ ur_result_t doMemcpy(ur_command_t Command, ur_queue_handle_t hQueue, olMemcpy(Queue, DestPtr, DestDevice, SrcPtr, SrcDevice, size)); if (phEvent) { auto *Event = new ur_event_handle_t_(Command, hQueue); - if (auto Res = olCreateEvent(Queue, DefaultEventFlags, + if (auto Res = olCreateEvent(Queue, OL_DEFAULT_EVENT_FLAGS, &Event->OffloadEvent)) { delete Event; return offloadResultToUR(Res); From 9bc04e1321fe2a69b7ddf4dd000607a1f65adcd1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 27 May 2026 10:15:47 +0000 Subject: [PATCH 7/7] cleanup(ur): simplify default offload event flag constant --- unified-runtime/source/adapters/offload/enqueue.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/unified-runtime/source/adapters/offload/enqueue.cpp b/unified-runtime/source/adapters/offload/enqueue.cpp index a4b06beb62303..540bc2b515f82 100644 --- a/unified-runtime/source/adapters/offload/enqueue.cpp +++ b/unified-runtime/source/adapters/offload/enqueue.cpp @@ -19,8 +19,7 @@ #include "ur2offload.hpp" namespace { -constexpr ol_event_flags_t OL_DEFAULT_EVENT_FLAGS = - static_cast(0); +constexpr ol_event_flags_t OL_DEFAULT_EVENT_FLAGS = 0; ol_result_t waitOnEvents(ol_queue_handle_t Queue, const ur_event_handle_t *UrEvents, size_t NumEvents) {