Debian Codegraph @

tensilelite/Tensile/cmake/TensileConfig.cmake

raw
1 ################################################################################
2 #
3 # Copyright (C) 2022-2025 Advanced Micro Devices, Inc. All rights reserved.
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining a copy
6 # of this software and associated documentation files (the "Software"), to deal
7 # in the Software without restriction, including without limitation the rights
8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 # copies of the Software, and to permit persons to whom the Software is
10 # furnished to do so, subject to the following conditions:
11 #
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 # SOFTWARE.
22 #
23 ################################################################################
24
25 include(CMakeParseArguments)
26
27 if(NOT DEFINED Tensile_ROOT)
28 # Compute the installation prefix relative to this file.
29 get_filename_component(Tensile_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
30 get_filename_component(Tensile_PREFIX "${Tensile_PREFIX}" PATH)
31
32 if (WIN32)
33 execute_process(COMMAND "${Tensile_PREFIX}/bin/TensileGetPath.exe" OUTPUT_VARIABLE Tensile_ROOT)
34 else()
35 execute_process(COMMAND "${Tensile_PREFIX}/bin/TensileGetPath" OUTPUT_VARIABLE Tensile_ROOT)
36 endif()
37 endif()
38 list(APPEND CMAKE_MODULE_PATH "${Tensile_ROOT}/Source/cmake/")
39 list(APPEND CMAKE_MODULE_PATH "${Tensile_ROOT}/Source/")
40
41 if("HIP" IN_LIST Tensile_FIND_COMPONENTS)
42 set(TENSILE_USE_HIP ON CACHE BOOL "Use HIP")
43 else()
44 set(TENSILE_USE_HIP OFF CACHE BOOL "Use HIP")
45 endif()
46
47 if("LLVM" IN_LIST Tensile_FIND_COMPONENTS)
48 set(TENSILE_USE_LLVM ON CACHE BOOL "Use LLVM")
49 else()
50 set(TENSILE_USE_LLVM OFF CACHE BOOL "Use LLVM")
51 endif()
52
53 if("Client" IN_LIST Tensile_FIND_COMPONENTS)
54 if(TENSILE_USE_HIP AND TENSILE_USE_LLVM)
55 set(TENSILE_BUILD_CLIENT ON CACHE BOOL "Build Client")
56 elseif(Tensile_FIND_REQUIRED_Client)
57 message("Tensile client requires both Hip and LLVM.")
58 set(Tensile_FOUND false)
59 else()
60 set(TENSILE_BUILD_CLIENT OFF CACHE BOOL "Build Client")
61 endif()
62 else()
63 set(TENSILE_BUILD_CLIENT OFF CACHE BOOL "Build Client")
64 endif()
65
66 if("STATIC_ONLY" IN_LIST Tensile_FIND_COMPONENTS)
67 set(TENSILE_STATIC_ONLY ON CACHE BOOL "Disable exporting symbols from shared library.")
68 else()
69 set(TENSILE_STATIC_ONLY OFF CACHE BOOL "Disable exporting symbols from shared library.")
70 endif()
71
72 add_subdirectory("${Tensile_ROOT}/Source" "Tensile")
73 include("${Tensile_ROOT}/Source/TensileCreateLibrary.cmake")
74
75 function(TensileCreateLibraryFiles
76 Tensile_LOGIC_PATH
77 Tensile_OUTPUT_PATH
78 Tensile_LIBRARY_TARGET
79 )
80
81 # Boolean options
82 set(options
83 SHORT_FILE_NAMES
84 PRINT_DEBUG
85 GENERATE_PACKAGE
86 SEPARATE_ARCHITECTURES
87 NO_LAZY_LIBRARY_LOADING
88 ASAN_BUILD
89 KEEP_BUILD_TMP
90 NO_COMPRESS
91 EXPERIMENTAL
92 ENABLE_MAKRER
93 )
94
95 # Single value settings
96 set(oneValueArgs
97 CODE_OBJECT_VERSION
98 COMPILER
99 COMPILER_PATH
100 EMBED_KEY
101 EMBED_LIBRARY
102 LIBRARY_FORMAT
103 TENSILE_ROOT
104 VAR_PREFIX
105 CPU_THREADS
106 VERBOSE
107 )
108
109 # Multi value settings
110 set(multiValueArgs
111 ARCHITECTURE
112 )
113
114 cmake_parse_arguments(Tensile "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
115
116 if(Tensile_UNPARSED_ARGUMENTS)
117 message(WARNING "Unrecognized arguments: ${Tensile_UNPARSED_ARGUMENTS}")
118 endif()
119 if(Tensile_KEYWORDS_MISSING_VALUES)
120 message(WARNING "Malformed arguments: ${Tensile_KEYWORDS_MISSING_VALUES}")
121 endif()
122
123 # Parse incoming options
124 if(Tensile_TENSILE_ROOT)
125 set(Script "${Tensile_TENSILE_ROOT}/bin/TensileCreateLibrary")
126 else()
127 set(Script "${Tensile_ROOT}/bin/TensileCreateLibrary")
128 endif()
129
130 message(STATUS "Tensile script: ${Script}")
131
132 if(Tensile_NO_LAZY_LIBRARY_LOADING)
133 set(Options ${Options} "--no-lazy-library-loading")
134 endif()
135
136 if(Tensile_ENABLE_MARKER)
137 set(Options ${Options} "--enable-marker")
138 endif()
139
140 if(Tensile_KEEP_BUILD_TMP)
141 set(Options ${Options} "--keep-build-tmp")
142 endif()
143
144 if(Tensile_NO_COMPRESS)
145 set(Options ${Options} "--no-compress")
146 endif()
147
148 if(Tensile_EXPERIMENTAL)
149 set(Options ${Options} "--experimental")
150 endif()
151
152 if(Tensile_ASAN_BUILD)
153 set(Options ${Options} "--address-sanitizer")
154 endif()
155
156 if(Tensile_GENERATE_PACKAGE)
157 set(Options ${Options} "--package-library")
158 endif()
159
160 if(Tensile_SHORT_FILE_NAMES)
161 set(Options ${Options} "--short-file-names")
162 endif()
163
164 if(Tensile_EMBED_LIBRARY)
165 set(Options ${Options} "--embed-library=${Tensile_EMBED_LIBRARY}")
166 endif()
167
168 if(Tensile_EMBED_KEY)
169 set(Options ${Options} "--embed-library-key=${Tensile_EMBED_KEY}")
170 endif()
171
172 if(Tensile_CODE_OBJECT_VERSION)
173 set(Options ${Options} "--code-object-version=${Tensile_CODE_OBJECT_VERSION}")
174 endif()
175
176 if(Tensile_COMPILER)
177 set(Options ${Options} "--cxx-compiler=${Tensile_COMPILER}")
178 endif()
179
180 if(Tensile_COMPILER_PATH)
181 set(Options ${Options} "--cmake-cxx-compiler=${Tensile_COMPILER_PATH}")
182 endif()
183
184 if(Tensile_CPU_THREADS)
185 set(Options ${Options} "--jobs=${Tensile_CPU_THREADS}")
186 endif()
187
188 if(Tensile_VERBOSE)
189 set(Options ${Options} "--verbose=${Tensile_VERBOSE}")
190 endif()
191
192 if(Tensile_ASM_DEBUG)
193 set(Options ${Options} "--asm-debug")
194 endif()
195
196 if(Tensile_LOGIC_FILTER)
197 set(Options ${Options} "--logic-filter=${Tensile_LOGIC_FILTER}")
198 endif()
199
200 if(Tensile_LIBRARY_FORMAT)
201 set(Options ${Options} "--library-format=${Tensile_LIBRARY_FORMAT}")
202 if(Tensile_LIBRARY_FORMAT MATCHES "yaml")
203 target_compile_definitions( TensileHost PUBLIC -DTENSILE_YAML=1)
204 endif()
205 endif()
206
207 if(Tensile_ARCHITECTURE)
208 string (REPLACE ";" "_" archString "${Tensile_ARCHITECTURE}")
209 # uses _ separator to avoid cmake ; list interpretation, either ; or _ decoded in TensileCreateLibrary
210 set(Options ${Options} "--architecture=${archString}")
211 endif()
212
213 if(Tensile_BUILD_ID)
214 set(Options ${Options} "--build-id=${Tensile_BUILD_ID}")
215 endif()
216
217 set(CommandLine ${CMAKE_COMMAND} -E env PYTHONPATH=${PROJECT_BINARY_DIR}/lib -- ${VIRTUALENV_BIN_DIR}/${VIRTUALENV_PYTHON_EXENAME} ${Script} ${Options} ${Tensile_LOGIC_PATH} ${Tensile_OUTPUT_PATH} HIP)
218 message(STATUS "Tensile_CREATE_COMMAND: ${CommandLine}")
219
220 if(Tensile_EMBED_LIBRARY)
221 set(Tensile_EMBED_LIBRARY_SOURCE "${Tensile_OUTPUT_PATH}/library/${Tensile_EMBED_LIBRARY}.cpp")
222 endif()
223
224 if(Tensile_SKIP_BUILD)
225 message(STATUS "Skipping build of ${Tensile_OUTPUT_PATH}")
226 else()
227 if($ENV{ENABLE_ADDRESS_SANITIZER})
228 # Must populate LD_PRELOAD with ASAN runtime if ASAN is being used.
229 # Find the ASAN RT with compiler and update env for Tensile call.
230 execute_process(
231 COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=libclang_rt.asan-x86_64.so
232 OUTPUT_VARIABLE ASAN_LIB_PATH
233 COMMAND_ECHO STDOUT)
234 string(STRIP ${ASAN_LIB_PATH} ASAN_LIB_PATH)
235 set(CommandLine env LD_PRELOAD=${ASAN_LIB_PATH} ${CommandLine})
236 endif()
237
238 add_custom_command(
239 COMMENT "Generating Tensile Libraries"
240 USES_TERMINAL
241 OUTPUT ${Tensile_OUTPUT_PATH}/library
242 COMMAND ${CommandLine}
243 )
244
245 add_custom_target(
246 ${Tensile_LIBRARY_TARGET} ALL
247 COMMENT "${Tensile_LIBRARY_TARGET}"
248 DEPENDS ${Tensile_OUTPUT_PATH}/library
249 )
250
251 endif()
252
253 if(Tensile_EMBED_LIBRARY)
254
255 add_library(${Tensile_EMBED_LIBRARY} ${Tensile_EMBED_LIBRARY_SOURCE})
256 target_link_libraries(${Tensile_EMBED_LIBRARY} PUBLIC TensileHost)
257
258 endif()
259
260 endfunction()