|
| 1 | +#=============================================================================== |
| 2 | +# Fetches Unified Runtime used by SYCL language runtime to abstract SYCL open |
| 3 | +# standard and vendor heterogeneous offload interfaces. |
| 4 | +# |
| 5 | +# This will in time be replaced by the new LLVM Offload interface. |
| 6 | +# |
| 7 | +# Unified Runtime is Apache 2.0 license with LLVM exceptions. |
| 8 | +# |
| 9 | +#=============================================================================== |
| 10 | + |
| 11 | +option(LIBSYCL_UR_BUILD_TESTS "Build tests for UR" OFF) |
| 12 | + |
| 13 | +set(UR_BUILD_TESTS "${LIBSYCL_UR_BUILD_TESTS}" CACHE BOOL "" FORCE) |
| 14 | +# UR tests require the examples to be built |
| 15 | +set(UR_BUILD_EXAMPLES "${LIBSYCL_UR_BUILD_TESTS}" CACHE BOOL "" FORCE) |
| 16 | + |
| 17 | +if("level_zero" IN_LIST LIBSYCL_ENABLE_BACKENDS) |
| 18 | + set(UR_BUILD_ADAPTER_L0 ON) |
| 19 | +endif() |
| 20 | +if("cuda" IN_LIST LIBSYCL_ENABLE_BACKENDS) |
| 21 | + set(UR_BUILD_ADAPTER_CUDA ON) |
| 22 | +endif() |
| 23 | +if("hip" IN_LIST LIBSYCL_ENABLE_BACKENDS) |
| 24 | + set(UR_BUILD_ADAPTER_HIP ON) |
| 25 | +endif() |
| 26 | +if("opencl" IN_LIST LIBSYCL_ENABLE_BACKENDS) |
| 27 | + set(UR_BUILD_ADAPTER_OPENCL ON) |
| 28 | +endif() |
| 29 | + |
| 30 | +# Disable errors from warnings while building the UR. |
| 31 | +# And remember the original flags before doing that. |
| 32 | +set(CMAKE_CXX_FLAGS_BAK "${CMAKE_CXX_FLAGS}") |
| 33 | +if(WIN32) |
| 34 | + append("/WX-" CMAKE_CXX_FLAGS) |
| 35 | + append("/WX-" CMAKE_C_FLAGS) |
| 36 | + # Unified runtime build fails with /DUNICODE |
| 37 | + append("/UUNICODE" CMAKE_CXX_FLAGS) |
| 38 | + append("/UUNICODE" CMAKE_C_FLAGS) |
| 39 | + append("/EHsc" CMAKE_CXX_FLAGS) |
| 40 | + append("/EHsc" CMAKE_C_FLAGS) |
| 41 | +else() |
| 42 | + append("-Wno-error" CMAKE_CXX_FLAGS) |
| 43 | + append("-Wno-error" CMAKE_C_FLAGS) |
| 44 | +endif() |
| 45 | + |
| 46 | +if(NOT FETCHCONTENT_SOURCE_DIR_UNIFIED-RUNTIME) |
| 47 | + find_package(unified-runtime) |
| 48 | + if(unified-runtime_FOUND) |
| 49 | + message (STATUS "Found system install of unified-runtime") |
| 50 | + return() |
| 51 | + endif() |
| 52 | +endif() |
| 53 | + |
| 54 | +include(FetchContent) |
| 55 | + |
| 56 | +set(UNIFIED_RUNTIME_REPO "https://github.com/oneapi-src/unified-runtime.git") |
| 57 | +set(UNIFIED_RUNTIME_TAG 8ee4da175c197d4dc5c9ec939e7e4d87d4edfa99) |
| 58 | + |
| 59 | +FetchContent_Declare(unified-runtime |
| 60 | + GIT_REPOSITORY ${UNIFIED_RUNTIME_REPO} |
| 61 | + GIT_TAG ${UNIFIED_RUNTIME_TAG} |
| 62 | +) |
| 63 | + |
| 64 | +FetchContent_GetProperties(unified-runtime) |
| 65 | +if(FETCHCONTENT_SOURCE_DIR_UNIFIED-RUNTIME) |
| 66 | + message(STATUS "Using specified Unified Runtime repo location at ${FETCHCONTENT_SOURCE_DIR_UNIFIED-RUNTIME}") |
| 67 | +else() |
| 68 | + message(STATUS "Cloning Unified Runtime from ${UNIFIED_RUNTIME_REPO}") |
| 69 | +endif() |
| 70 | +FetchContent_MakeAvailable(unified-runtime) |
| 71 | + |
| 72 | +set(UNIFIED_RUNTIME_SOURCE_DIR |
| 73 | + "${unified-runtime_SOURCE_DIR}" CACHE PATH |
| 74 | + "Path to Unified Runtime Headers" FORCE) |
| 75 | + |
| 76 | +set(UMF_BUILD_EXAMPLES OFF CACHE INTERNAL "UMF EXAMPLES") |
| 77 | +# Due to the use of dependentloadflag and no installer for UMF and hwloc we need |
| 78 | +# to link statically on windows |
| 79 | +if(WIN32) |
| 80 | + set(UMF_BUILD_SHARED_LIBRARY OFF CACHE INTERNAL "Build UMF shared library") |
| 81 | + set(UMF_LINK_HWLOC_STATICALLY ON CACHE INTERNAL "static HWLOC") |
| 82 | +endif() |
| 83 | + |
| 84 | +# Restore original flags |
| 85 | +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_BAK}") |
| 86 | + |
| 87 | +message(STATUS |
| 88 | + "Using Unified Runtime source directory: ${UNIFIED_RUNTIME_SOURCE_DIR}") |
| 89 | + |
| 90 | +set(UNIFIED_RUNTIME_INCLUDE_DIR "${UNIFIED_RUNTIME_SOURCE_DIR}/include") |
| 91 | +set(UNIFIED_RUNTIME_SRC_INCLUDE_DIR "${UNIFIED_RUNTIME_SOURCE_DIR}/source") |
| 92 | +set(UNIFIED_RUNTIME_COMMON_INCLUDE_DIR "${UNIFIED_RUNTIME_SOURCE_DIR}/source/common") |
| 93 | + |
| 94 | +add_library(UnifiedRuntimeLoader ALIAS ur_loader) |
| 95 | +add_library(UnifiedRuntime-Headers INTERFACE) |
| 96 | + |
| 97 | +target_include_directories(UnifiedRuntime-Headers |
| 98 | + INTERFACE |
| 99 | + "${UNIFIED_RUNTIME_INCLUDE_DIR}" |
| 100 | +) |
| 101 | + |
| 102 | +add_custom_target(UnifiedRuntimeAdapters) |
| 103 | + |
| 104 | +function(add_sycl_ur_adapter NAME) |
| 105 | + add_dependencies(UnifiedRuntimeAdapters ur_adapter_${NAME}) |
| 106 | +endfunction() |
| 107 | + |
| 108 | +if("level_zero" IN_LIST LIBSYCL_ENABLE_BACKENDS) |
| 109 | + add_sycl_ur_adapter(level_zero) |
| 110 | +endif() |
| 111 | + |
| 112 | +if("cuda" IN_LIST LIBSYCL_ENABLE_BACKENDS) |
| 113 | + add_sycl_ur_adapter(cuda) |
| 114 | +endif() |
| 115 | + |
| 116 | +if("hip" IN_LIST LIBSYCL_ENABLE_BACKENDS) |
| 117 | + add_sycl_ur_adapter(hip) |
| 118 | +endif() |
| 119 | + |
| 120 | +if("opencl" IN_LIST LIBSYCL_ENABLE_BACKENDS) |
| 121 | + add_sycl_ur_adapter(opencl) |
| 122 | +endif() |
0 commit comments