Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion offload/liboffload/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ set_target_properties(LLVMOffload PROPERTIES
POSITION_INDEPENDENT_CODE ON
INSTALL_RPATH "$ORIGIN"
BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/..")
install(TARGETS LLVMOffload LIBRARY COMPONENT LLVMOffload DESTINATION "${OFFLOAD_INSTALL_LIBDIR}")
install(TARGETS LLVMOffload
LIBRARY COMPONENT LLVMOffload DESTINATION "${OFFLOAD_INSTALL_LIBDIR}"
RUNTIME COMPONENT LLVMOffload DESTINATION "${OFFLOAD_INSTALL_LIBDIR}"
ARCHIVE COMPONENT LLVMOffload DESTINATION "${OFFLOAD_INSTALL_LIBDIR}")

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/API/OffloadAPI.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/offload)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/API/OffloadPrint.hpp DESTINATION ${CMAKE_INSTALL_PREFIX}/include/offload)
6 changes: 5 additions & 1 deletion sycl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,11 @@ add_custom_target( sycl-toolchain ALL
)

if (WIN32)
add_dependencies(sycl-toolchain ur_win_proxy_loader unified-runtimed-build)
if(SYCL_BUILD_UR_DEBUG_LIBRARIES)
add_dependencies(sycl-toolchain ur_win_proxy_loader unified-runtimed-build)
else()
add_dependencies(sycl-toolchain ur_win_proxy_loader)
endif()
endif()

if("cuda" IN_LIST SYCL_ENABLE_BACKENDS)
Expand Down
20 changes: 15 additions & 5 deletions sycl/cmake/modules/BuildUnifiedRuntime.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ endif()
if("native_cpu" IN_LIST SYCL_ENABLE_BACKENDS)
set(UR_BUILD_ADAPTER_NATIVE_CPU ON)
endif()
if("offload" IN_LIST SYCL_ENABLE_BACKENDS)
set(UR_BUILD_ADAPTER_OFFLOAD ON)
endif()

# Disable errors from warnings while building the UR.
# And remember origin flags before doing that.
Expand Down Expand Up @@ -186,7 +189,9 @@ if("offload" IN_LIST SYCL_ENABLE_BACKENDS)
add_sycl_ur_adapter(offload)
endif()

if(CMAKE_SYSTEM_NAME STREQUAL Windows)
option(SYCL_BUILD_UR_DEBUG_LIBRARIES "Build debug versions of UR libraries on Windows" ON)

if(CMAKE_SYSTEM_NAME STREQUAL Windows AND SYCL_BUILD_UR_DEBUG_LIBRARIES)
# On Windows, also build/install debug libraries with the d suffix that are
# compiled with /MDd so users can link against these in debug builds.
include(ExternalProject)
Expand Down Expand Up @@ -223,6 +228,9 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows)
-DUR_BUILD_ADAPTER_CUDA:BOOL=${UR_BUILD_ADAPTER_CUDA}
-DUR_BUILD_ADAPTER_HIP:BOOL=${UR_BUILD_ADAPTER_HIP}
-DUR_BUILD_ADAPTER_NATIVE_CPU:BOOL=${UR_BUILD_ADAPTER_NATIVE_CPU}
-DUR_BUILD_ADAPTER_OFFLOAD:BOOL=${UR_BUILD_ADAPTER_OFFLOAD}
-DUR_OFFLOAD_INSTALL_DIR:PATH=${UR_OFFLOAD_INSTALL_DIR}
-DUR_OFFLOAD_INCLUDE_DIR:PATH=${UR_OFFLOAD_INCLUDE_DIR}
-DUMF_BUILD_EXAMPLES:BOOL=${UMF_BUILD_EXAMPLES}
-DUMF_BUILD_SHARED_LIBRARY:BOOL=${UMF_BUILD_SHARED_LIBRARY}
-DUMF_LINK_HWLOC_STATICALLY:BOOL=${UMF_LINK_HWLOC_STATICALLY}
Expand Down Expand Up @@ -261,16 +269,18 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows)
endmacro()

urd_copy_library_to_build(ur_loaderd "NOT;${UR_STATIC_LOADER}")
foreach(adatper ${SYCL_ENABLE_BACKENDS})
foreach(adapter ${SYCL_ENABLE_BACKENDS})
if(adapter MATCHES "level_zero")
set(shared "NOT;${UR_STATIC_ADAPTER_L0}")
else()
set(shared TRUE)
endif()
urd_copy_library_to_build(ur_adapter_${adatper}d "${shared}")
urd_copy_library_to_build(ur_adapter_${adapter}d "${shared}")
endforeach()
# Also copy umfd.dll/umfd.lib
urd_copy_library_to_build(umfd ${UMF_BUILD_SHARED_LIBRARY})
# Also copy umfd.dll/umfd.lib when UMF is built as a shared library
if(UMF_BUILD_SHARED_LIBRARY)
urd_copy_library_to_build(umfd ${UMF_BUILD_SHARED_LIBRARY})
endif()

add_custom_target(unified-runtimed-build ALL DEPENDS ${URD_COPY_FILES})
add_dependencies(unified-runtimed-build unified-runtimed)
Expand Down
6 changes: 4 additions & 2 deletions sycl/source/detail/program_manager/program_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1465,14 +1465,16 @@ Managed<ur_program_handle_t> ProgramManager::build(

Managed<ur_program_handle_t> LinkedProg{Adapter};
auto doLink = [&] {
const char *LinkOptsPtr =
LinkOptions.empty() ? nullptr : LinkOptions.c_str();
auto Res = Adapter.call_nocheck<UrApiKind::urProgramLinkExp>(
Context.getHandleRef(), Devices.size(), Devices.data(),
ur_exp_program_flags_t{}, LinkPrograms.size(), LinkPrograms.data(),
LinkOptions.c_str(), &LinkedProg);
LinkOptsPtr, &LinkedProg);
if (Res == UR_RESULT_ERROR_UNSUPPORTED_FEATURE) {
Res = Adapter.call_nocheck<UrApiKind::urProgramLink>(
Context.getHandleRef(), LinkPrograms.size(), LinkPrograms.data(),
LinkOptions.c_str(), &LinkedProg);
LinkOptsPtr, &LinkedProg);
}
return Res;
};
Expand Down
21 changes: 20 additions & 1 deletion unified-runtime/source/adapters/offload/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ 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 the correct library name based on platform
if(WIN32)
set(LLVM_OFFLOAD_LIBRARY "${UR_OFFLOAD_INSTALL_DIR}/lib/LLVMOffload.lib")
else()
set(LLVM_OFFLOAD_LIBRARY "${UR_OFFLOAD_INSTALL_DIR}/lib/libLLVMOffload.so")
endif()

if (UR_OFFLOAD_INSTALL_DIR STREQUAL "" OR UR_OFFLOAD_INCLUDE_DIR STREQUAL "")
include(ExternalProject)
set(LLVM_PROJECT_SOURCE_DIR ${CMAKE_BINARY_DIR}/llvm-src-offload)
Expand Down Expand Up @@ -104,6 +112,17 @@ if (UR_OFFLOAD_INSTALL_DIR STREQUAL "" OR UR_OFFLOAD_INCLUDE_DIR STREQUAL "")
install(DIRECTORY "${UR_OFFLOAD_INSTALL_DIR}/"
DESTINATION "${CMAKE_INSTALL_PREFIX}"
COMPONENT ur_adapter_offload)
else()
# When using user-provided liboffload, install the runtime library
if(WIN32)
install(FILES "${UR_OFFLOAD_INSTALL_DIR}/bin/LLVMOffload.dll"
DESTINATION "${CMAKE_INSTALL_PREFIX}/bin"
COMPONENT ur_adapter_offload)
else()
install(FILES "${UR_OFFLOAD_INSTALL_DIR}/lib/libLLVMOffload.so"
DESTINATION "${CMAKE_INSTALL_PREFIX}/lib"
COMPONENT ur_adapter_offload)
endif()
endif()

# When targetting CUDA devices, we need a workaround to avoid sending PTX to
Expand Down Expand Up @@ -138,7 +157,7 @@ target_link_libraries(${TARGET_NAME} PRIVATE
${PROJECT_NAME}::common
${PROJECT_NAME}::umf
ur_common
${UR_OFFLOAD_INSTALL_DIR}/lib/libLLVMOffload.so
${LLVM_OFFLOAD_LIBRARY}
${ADDITIONAL_LINK_LIBS}
)

Expand Down
24 changes: 10 additions & 14 deletions unified-runtime/source/adapters/offload/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,9 @@ urProgramCreateWithIL(ur_context_handle_t hContext, const void *pIL,
UR_APIEXPORT ur_result_t UR_APICALL urProgramBuild(ur_context_handle_t,
ur_program_handle_t hProgram,
const char *pOptions) {
// Do nothing, program is built upon creation
// Do nothing, program is built upon creation. Options are ignored.
if (pOptions && *pOptions) {
hProgram->Error = "Liboffload doesn't support link options";
return UR_RESULT_ERROR_PROGRAM_LINK_FAILURE;
UR_LOG(WARN, "urProgramBuild: ignoring options '{}'", pOptions);
}
hProgram->BinaryType = UR_PROGRAM_BINARY_TYPE_EXECUTABLE;
return UR_RESULT_SUCCESS;
Expand All @@ -175,21 +174,19 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramBuild(ur_context_handle_t,
UR_APIEXPORT ur_result_t UR_APICALL
urProgramBuildExp(ur_program_handle_t hProgram, uint32_t, ur_device_handle_t *,
ur_exp_program_flags_t, const char *pOptions) {
// Do nothing, program is built upon creation
// Do nothing, program is built upon creation. Options are ignored.
if (pOptions && *pOptions) {
hProgram->Error = "Liboffload doesn't support link options";
return UR_RESULT_ERROR_PROGRAM_LINK_FAILURE;
UR_LOG(WARN, "urProgramBuildExp: ignoring options '{}'", pOptions);
}
hProgram->BinaryType = UR_PROGRAM_BINARY_TYPE_EXECUTABLE;
return UR_RESULT_SUCCESS;
}

UR_APIEXPORT ur_result_t UR_APICALL urProgramCompile(
ur_context_handle_t, ur_program_handle_t hProgram, const char *pOptions) {
// Do nothing, program is built upon creation
// Do nothing, program is built upon creation. Options are ignored.
if (pOptions && *pOptions) {
hProgram->Error = "Liboffload doesn't support link options";
return UR_RESULT_ERROR_PROGRAM_LINK_FAILURE;
UR_LOG(WARN, "urProgramCompile: ignoring options '{}'", pOptions);
}
hProgram->BinaryType = UR_PROGRAM_BINARY_TYPE_COMPILED_OBJECT;
return UR_RESULT_SUCCESS;
Expand All @@ -199,17 +196,16 @@ UR_APIEXPORT ur_result_t UR_APICALL
urProgramLink(ur_context_handle_t hContext, uint32_t count,
const ur_program_handle_t *phPrograms, const char *pOptions,
ur_program_handle_t *phProgram) {
// Do nothing, program is built upon creation. Options are ignored.
if (pOptions && *pOptions) {
UR_LOG(WARN, "urProgramLink: ignoring options '{}'", pOptions);
}
if (count > 1) {
*phProgram = ur_program_handle_t_::newErrorProgram(
hContext, nullptr, 0,
"Liboffload does not support linking multiple binaries");
return UR_RESULT_ERROR_PROGRAM_LINK_FAILURE;
}
if (pOptions) {
*phProgram = ur_program_handle_t_::newErrorProgram(
hContext, nullptr, 0, "Liboffload does not support linker options");
return UR_RESULT_ERROR_PROGRAM_LINK_FAILURE;
}
assert(count == 1);

// Offload programs are already fully linked on creation, just create a new
Expand Down
Loading