1 # Exclude these from libMLIR.so because the JIT infrastructure
2 # is a big dependency which most don't need.
4 set(LLVM_OPTIONAL_SOURCES
7 CudaRuntimeWrappers.cpp
8 SparseTensorRuntime.cpp
11 RocmRuntimeWrappers.cpp
15 SyclRuntimeWrappers.cpp
18 # Use a separate library for OptUtils, to avoid pulling in the entire JIT and
19 # codegen infrastructure. Unlike MLIRExecutionEngine, this is part of
21 add_mlir_library(MLIRExecutionEngineUtils
24 ADDITIONAL_HEADER_DIRS
25 ${MLIR_MAIN_INCLUDE_DIR}/mlir/ExecutionEngine
44 if(NOT MLIR_ENABLE_EXECUTION_ENGINE)
48 if(LLVM_USE_INTEL_JITEVENTS)
49 set(LLVM_JIT_LISTENER_LIB
51 endif(LLVM_USE_INTEL_JITEVENTS)
54 set(LLVM_JIT_LISTENER_LIB
58 add_mlir_library(MLIRExecutionEngine
63 ADDITIONAL_HEADER_DIRS
64 ${MLIR_MAIN_INCLUDE_DIR}/mlir/ExecutionEngine
87 ${LLVM_JIT_LISTENER_LIB}
90 MLIRBuiltinToLLVMIRTranslation
91 MLIRExecutionEngineUtils
93 MLIRLLVMToLLVMIRTranslation
94 MLIROpenMPToLLVMIRTranslation
95 MLIRTargetLLVMIRExport
98 get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
99 add_mlir_library(MLIRJitRunner
119 MLIRLLVMToLLVMIRTranslation
120 MLIRTargetLLVMIRExport
125 # When -fPIC is not provided, shared libraries cannot be built if it links against
128 add_mlir_library(mlir_float16_utils
134 set_property(TARGET mlir_float16_utils PROPERTY CXX_STANDARD 17)
135 target_compile_definitions(mlir_float16_utils PRIVATE mlir_float16_utils_EXPORTS)
137 add_subdirectory(SparseTensor)
139 add_mlir_library(mlir_c_runner_utils
142 SparseTensorRuntime.cpp
148 MLIRSparseTensorEnums
149 MLIRSparseTensorRuntime
151 set_property(TARGET mlir_c_runner_utils PROPERTY CXX_STANDARD 17)
152 target_compile_definitions(mlir_c_runner_utils PRIVATE mlir_c_runner_utils_EXPORTS)
154 add_mlir_library(mlir_runner_utils
160 target_compile_definitions(mlir_runner_utils PRIVATE mlir_runner_utils_EXPORTS)
162 add_mlir_library(mlir_async_runtime
171 set_property(TARGET mlir_async_runtime PROPERTY CXX_VISIBILITY_PRESET hidden)
172 target_compile_definitions(mlir_async_runtime PRIVATE mlir_async_runtime_EXPORTS)
173 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
174 # Don't export symbols from link-time dependencies, these are internal
175 # implementation details.
176 # FIXME: Add a similar fix for Windows.
177 target_link_options(mlir_async_runtime PRIVATE "-Wl,-exclude-libs,ALL")
180 if(MLIR_ENABLE_CUDA_RUNNER)
181 # Configure CUDA support. Using check_language first allows us to give a
182 # custom error message.
183 include(CheckLanguage)
185 if (CMAKE_CUDA_COMPILER)
186 enable_language(CUDA)
189 "Building the mlir cuda runner requires a working CUDA install")
192 # We need the libcuda.so library.
193 find_library(CUDA_RUNTIME_LIBRARY cuda HINTS ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES} REQUIRED)
195 add_mlir_library(mlir_cuda_runtime
197 CudaRuntimeWrappers.cpp
201 set_property(TARGET mlir_cuda_runtime PROPERTY CXX_STANDARD 14)
203 target_include_directories(mlir_cuda_runtime
205 ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
207 target_link_libraries(mlir_cuda_runtime
209 ${CUDA_RUNTIME_LIBRARY}
212 if(MLIR_ENABLE_CUDA_CUSPARSE)
213 # Find the libcusparse.so library if CUSPARSE build is requested.
214 find_library(CUDA_CUSPARSE_LIBRARY cusparse HINTS ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES} REQUIRED)
216 target_link_libraries(mlir_cuda_runtime
218 ${CUDA_CUSPARSE_LIBRARY}
220 target_compile_definitions(mlir_cuda_runtime
222 MLIR_ENABLE_CUDA_CUSPARSE=1
225 if(MLIR_ENABLE_CUDA_CUSPARSELT)
226 # Find the libcusparseLt.so library in package manager default path if
227 # CUSPARSELT build is requested. libcusparseLt.so provides sm80+ tensor
228 # core support for 2:4 sparsity acceleration.
229 find_library(CUDA_CUSPARSELT_LIBRARY cusparseLt HINTS ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES} REQUIRED)
230 find_path(CUDA_CUSPARSELT_HEADER cusparseLt.h HINTS ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES} REQUIRED)
231 target_include_directories(mlir_cuda_runtime
233 ${CUDA_CUSPARSELT_HEADER}
235 target_link_libraries(mlir_cuda_runtime
237 ${CUDA_CUSPARSELT_LIBRARY}
239 target_compile_definitions(mlir_cuda_runtime
241 MLIR_ENABLE_CUDA_CUSPARSELT=1
247 if(MLIR_ENABLE_ROCM_RUNNER)
248 # Configure ROCm support.
249 if (NOT DEFINED ROCM_PATH)
250 if (NOT DEFINED ENV{ROCM_PATH})
251 set(ROCM_PATH "/opt/rocm" CACHE PATH "Path to which ROCm has been installed")
253 set(ROCM_PATH $ENV{ROCM_PATH} CACHE PATH "Path to which ROCm has been installed")
256 # A lot of the ROCm CMake files expect to find their own dependencies in
257 # CMAKE_PREFIX_PATH and don't respect PATHS or HINTS :( .
258 # Therefore, temporarily add the ROCm path to CMAKE_PREFIX_PATH so we can
259 # load HIP, then remove it
260 set(REAL_CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH}")
261 list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH} "${ROCM_PATH}/hip")
262 find_package(hip REQUIRED)
263 set(CMAKE_PREFIX_PATH "${REAL_CMAKE_PREFIX_PATH}")
265 if (NOT DEFINED ROCM_TEST_CHIPSET)
266 find_program(ROCM_AGENT_ENUMERATOR rocm_agent_enumerator "${ROCM_PATH}/bin" /usr/bin /usr/local/bin)
267 if(ROCM_AGENT_ENUMERATOR)
268 execute_process(COMMAND "${ROCM_AGENT_ENUMERATOR}"
269 OUTPUT_VARIABLE AGENTS_STRING
270 ERROR_VARIABLE AGENTS_STRING
271 RESULT_VARIABLE AGENT_ENUMERATOR_RESULT)
273 message(SEND_ERROR "Could not find rocm_agent_enumerator")
275 if (NOT AGENT_ENUMERATOR_RESULT EQUAL 0)
276 message(SEND_ERROR "Could not run rocm_agent_enumerator and ROCM_TEST_CHIPSET is not defined")
277 set(AGENTS_STRING "")
279 string(STRIP AGENTS_STRING ${AGENTS_STRING})
280 string(REPLACE "\n" ";" AGENTS_LIST ${AGENTS_STRING})
281 list(FILTER AGENTS_LIST EXCLUDE REGEX "gfx000")
282 if (AGENTS_LIST STREQUAL "")
283 message(SEND_ERROR "No non-CPU ROCm agents found on the system, and ROCM_TEST_CHIPSET is not defined")
285 list(GET AGENTS_LIST 0 FIRST_AGENT)
286 set(ROCM_TEST_CHIPSET ${FIRST_AGENT} CACHE STRING "Chipset for which to compile ROCm integration tests")
287 message(STATUS "Compiling integration tests for ${ROCM_TEST_CHIPSET}")
291 add_mlir_library(mlir_rocm_runtime
293 RocmRuntimeWrappers.cpp
298 # Supress compiler warnings from HIP headers
299 check_cxx_compiler_flag(-Wno-c++98-compat-extra-semi
300 CXX_SUPPORTS_NO_CXX98_COMPAT_EXTRA_SEMI_FLAG)
301 if (CXX_SUPPORTS_CXX98_COMPAT_EXTRA_SEMI_FLAG)
302 target_compile_options(mlir_rocm_runtime PRIVATE
303 "-Wno-c++98-compat-extra-semi")
305 check_cxx_compiler_flag(-Wno-return-type-c-linkage
306 CXX_SUPPORTS_WNO_RETURN_TYPE_C_LINKAGE_FLAG)
307 if (CXX_SUPPORTS_WNO_RETURN_TYPE_C_LINKAGE_FLAG)
308 target_compile_options(mlir_rocm_runtime PRIVATE
309 "-Wno-return-type-c-linkage")
311 check_cxx_compiler_flag(-Wno-nested-anon-types
312 CXX_SUPPORTS_WNO_NESTED_ANON_TYPES_FLAG)
313 if (CXX_SUPPORTS_WNO_NESTED_ANON_TYPES_FLAG)
314 target_compile_options(mlir_rocm_runtime PRIVATE
315 "-Wno-nested-anon-types")
317 check_cxx_compiler_flag(-Wno-gnu-anonymous-struct
318 CXX_SUPPORTS_WNO_GNU_ANONYMOUS_STRUCT_FLAG)
319 if (CXX_SUPPORTS_WNO_GNU_ANONYMOUS_STRUCT_FLAG)
320 target_compile_options(mlir_rocm_runtime PRIVATE
321 "-Wno-gnu-anonymous-struct")
324 set_property(TARGET mlir_rocm_runtime
325 PROPERTY INSTALL_RPATH_USE_LINK_PATH ON)
327 target_link_libraries(mlir_rocm_runtime
329 hip::host hip::amdhip64
333 if(MLIR_ENABLE_SYCL_RUNNER)
334 find_package(SyclRuntime)
336 if(NOT SyclRuntime_FOUND)
337 message(FATAL_ERROR "syclRuntime not found. Please set check oneapi installation and run setvars.sh.")
340 find_package(LevelZero)
342 if(NOT LevelZero_FOUND)
343 message(FATAL_ERROR "LevelZero not found. Please set LEVEL_ZERO_DIR.")
346 add_mlir_library(mlir_sycl_runtime
348 SyclRuntimeWrappers.cpp
353 check_cxx_compiler_flag("-frtti" CXX_HAS_FRTTI_FLAG)
354 if(NOT CXX_HAS_FRTTI_FLAG)
355 message(FATAL_ERROR "CXX compiler does not accept flag -frtti")
357 target_compile_options (mlir_sycl_runtime PUBLIC -fexceptions -frtti)
359 target_include_directories(mlir_sycl_runtime PRIVATE
363 target_link_libraries(mlir_sycl_runtime PRIVATE LevelZero::LevelZero SyclRuntime::SyclRuntime)
365 set_property(TARGET mlir_sycl_runtime APPEND PROPERTY BUILD_RPATH "${LevelZero_LIBRARIES_DIR}" "${SyclRuntime_LIBRARIES_DIR}")