diff --git a/offload/liboffload/CMakeLists.txt b/offload/liboffload/CMakeLists.txt index 62480dad1cac8..fa013417972d7 100644 --- a/offload/liboffload/CMakeLists.txt +++ b/offload/liboffload/CMakeLists.txt @@ -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) diff --git a/sycl/CMakeLists.txt b/sycl/CMakeLists.txt index f39639641c316..b02ee08d3c341 100644 --- a/sycl/CMakeLists.txt +++ b/sycl/CMakeLists.txt @@ -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) diff --git a/sycl/cmake/modules/BuildUnifiedRuntime.cmake b/sycl/cmake/modules/BuildUnifiedRuntime.cmake index c1a942c9de9e2..7d017f020a713 100644 --- a/sycl/cmake/modules/BuildUnifiedRuntime.cmake +++ b/sycl/cmake/modules/BuildUnifiedRuntime.cmake @@ -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. @@ -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) @@ -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} @@ -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) diff --git a/sycl/source/detail/program_manager/program_manager.cpp b/sycl/source/detail/program_manager/program_manager.cpp index e700905812343..8b7602582efe7 100644 --- a/sycl/source/detail/program_manager/program_manager.cpp +++ b/sycl/source/detail/program_manager/program_manager.cpp @@ -1465,14 +1465,16 @@ Managed ProgramManager::build( Managed LinkedProg{Adapter}; auto doLink = [&] { + const char *LinkOptsPtr = + LinkOptions.empty() ? nullptr : LinkOptions.c_str(); auto Res = Adapter.call_nocheck( 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( Context.getHandleRef(), LinkPrograms.size(), LinkPrograms.data(), - LinkOptions.c_str(), &LinkedProg); + LinkOptsPtr, &LinkedProg); } return Res; }; diff --git a/unified-runtime/source/adapters/offload/CMakeLists.txt b/unified-runtime/source/adapters/offload/CMakeLists.txt index d9c3eee222490..bcd8f6c25d530 100644 --- a/unified-runtime/source/adapters/offload/CMakeLists.txt +++ b/unified-runtime/source/adapters/offload/CMakeLists.txt @@ -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) @@ -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 @@ -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} ) diff --git a/unified-runtime/source/adapters/offload/program.cpp b/unified-runtime/source/adapters/offload/program.cpp index 6556741c29b95..22d77e4cd5521 100644 --- a/unified-runtime/source/adapters/offload/program.cpp +++ b/unified-runtime/source/adapters/offload/program.cpp @@ -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; @@ -175,10 +174,9 @@ 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; @@ -186,10 +184,9 @@ urProgramBuildExp(ur_program_handle_t hProgram, uint32_t, ur_device_handle_t *, 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; @@ -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