1
+ # Copyright (C) 2024 Intel Corporation
2
+ # Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
3
+ # See LICENSE.TXT
4
+ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5
+
6
+ set (UR_LEVEL_ZERO_LOADER_LIBRARY "" CACHE FILEPATH "Path of the Level Zero Loader library" )
7
+ set (UR_LEVEL_ZERO_INCLUDE_DIR "" CACHE FILEPATH "Directory containing the Level Zero Headers" )
8
+ set (UR_LEVEL_ZERO_LOADER_REPO "" CACHE STRING "Github repo to get the Level Zero loader sources from" )
9
+ set (UR_LEVEL_ZERO_LOADER_TAG "" CACHE STRING " GIT tag of the Level Loader taken from github repo" )
10
+
11
+ # Copy Level Zero loader/headers locally to the build to avoid leaking their path.
12
+ set (LEVEL_ZERO_COPY_DIR ${CMAKE_CURRENT_BINARY_DIR} /level_zero_loader )
13
+ if (NOT UR_LEVEL_ZERO_LOADER_LIBRARY STREQUAL "" )
14
+ get_filename_component (LEVEL_ZERO_LIB_NAME "${UR_LEVEL_ZERO_LOADER_LIBRARY} " NAME )
15
+ set (LEVEL_ZERO_LIBRARY ${LEVEL_ZERO_COPY_DIR} /${LEVEL_ZERO_LIB_NAME} )
16
+ message (STATUS "Level Zero Adapter: Copying Level Zero loader to local build tree" )
17
+ file (COPY ${UR_LEVEL_ZERO_LOADER_LIBRARY} DESTINATION ${LEVEL_ZERO_COPY_DIR} FOLLOW_SYMLINK_CHAIN )
18
+ endif ()
19
+ if (NOT UR_LEVEL_ZERO_INCLUDE_DIR STREQUAL "" )
20
+ set (LEVEL_ZERO_INCLUDE_DIR ${LEVEL_ZERO_COPY_DIR} )
21
+ message (STATUS "Level Zero Adapter: Copying Level Zero headers to local build tree" )
22
+ file (COPY ${UR_LEVEL_ZERO_INCLUDE_DIR} / DESTINATION ${LEVEL_ZERO_COPY_DIR} )
23
+ endif ()
24
+
25
+ if (NOT DEFINED LEVEL_ZERO_LIBRARY OR NOT DEFINED LEVEL_ZERO_INCLUDE_DIR )
26
+ message (STATUS "Level Zero Adapter: Download Level Zero loader and headers from github.com" )
27
+
28
+ # Workaround warnings/errors for Level Zero build
29
+ set (CMAKE_CXX_FLAGS_BAK "${CMAKE_CXX_FLAGS} " )
30
+ if (UNIX )
31
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-but-set-variable" )
32
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-pedantic" )
33
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-stringop-truncation" )
34
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter" )
35
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++98-compat-extra-semi" )
36
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-warning-option" )
37
+ endif ()
38
+
39
+ if (UR_LEVEL_ZERO_LOADER_REPO STREQUAL "" )
40
+ set (UR_LEVEL_ZERO_LOADER_REPO "https://github.com/oneapi-src/level-zero.git" )
41
+ endif ()
42
+ if (UR_LEVEL_ZERO_LOADER_TAG STREQUAL "" )
43
+ set (UR_LEVEL_ZERO_LOADER_TAG v1.17.6 )
44
+ endif ()
45
+
46
+ # Disable due to a bug https://github.com/oneapi-src/level-zero/issues/104
47
+ set (CMAKE_INCLUDE_CURRENT_DIR OFF )
48
+ # Prevent L0 loader from exporting extra symbols
49
+ set (CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS OFF )
50
+
51
+ message (STATUS "Level Zero Adapter: Will fetch Level Zero Loader from ${UR_LEVEL_ZERO_LOADER_REPO} " )
52
+ include (FetchContent )
53
+ FetchContent_Declare (level-zero-loader
54
+ GIT_REPOSITORY ${UR_LEVEL_ZERO_LOADER_REPO}
55
+ GIT_TAG ${UR_LEVEL_ZERO_LOADER_TAG}
56
+ )
57
+ if (MSVC )
58
+ set (USE_Z7 ON )
59
+ endif ()
60
+ FetchContent_MakeAvailable (level-zero-loader )
61
+ FetchContent_GetProperties (level-zero-loader )
62
+
63
+ # Restore original flags
64
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_BAK} " )
65
+
66
+ target_compile_options (ze_loader PRIVATE
67
+ $< $< IN_LIST:$< CXX_COMPILER_ID> ,GNU;Clang;Intel;IntelLLVM> :-Wno-error>
68
+ $< $< CXX_COMPILER_ID:MSVC> :/WX- /UUNICODE>
69
+ )
70
+
71
+ set (LEVEL_ZERO_LIBRARY ze_loader )
72
+ set (LEVEL_ZERO_INCLUDE_DIR
73
+ ${level-zero-loader_SOURCE_DIR}/include CACHE PATH "Path to Level Zero Headers" )
74
+ endif ()
75
+
76
+ add_library (LevelZeroLoader INTERFACE )
77
+ # The MSVC linker does not like / at the start of a path, so to work around this
78
+ # we split it into a link library and a library path, where the path is allowed
79
+ # to have leading /.
80
+ get_filename_component (LEVEL_ZERO_LIBRARY_SRC "${LEVEL_ZERO_LIBRARY} " DIRECTORY )
81
+ get_filename_component (LEVEL_ZERO_LIB_NAME "${LEVEL_ZERO_LIBRARY} " NAME )
82
+ target_link_directories (LevelZeroLoader
83
+ INTERFACE "${LEVEL_ZERO_LIBRARY_SRC} "
84
+ )
85
+ target_link_libraries (LevelZeroLoader
86
+ INTERFACE "${LEVEL_ZERO_LIB_NAME} "
87
+ )
88
+
89
+ add_library (LevelZeroLoader-Headers INTERFACE )
90
+ target_include_directories (LevelZeroLoader-Headers
91
+ INTERFACE "${LEVEL_ZERO_INCLUDE_DIR} "
92
+ )
0 commit comments