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
9 CudaRuntimeWrappers.cpp
10 SparseTensorRuntime.cpp
13 RocmRuntimeWrappers.cpp
17 SpirvCpuRuntimeWrappers.cpp
18 SyclRuntimeWrappers.cpp
21 # Use a separate library for OptUtils, to avoid pulling in the entire JIT and
22 # codegen infrastructure. Unlike MLIRExecutionEngine, this is part of
24 add_mlir_library(MLIRExecutionEngineUtils
27 ADDITIONAL_HEADER_DIRS
28 ${MLIR_MAIN_INCLUDE_DIR}/mlir/ExecutionEngine
47 if(NOT MLIR_ENABLE_EXECUTION_ENGINE)
51 if(LLVM_USE_INTEL_JITEVENTS)
52 set(LLVM_JIT_LISTENER_LIB
54 endif(LLVM_USE_INTEL_JITEVENTS)
57 set(LLVM_JIT_LISTENER_LIB
61 add_mlir_library(MLIRExecutionEngine
66 ADDITIONAL_HEADER_DIRS
67 ${MLIR_MAIN_INCLUDE_DIR}/mlir/ExecutionEngine
90 ${LLVM_JIT_LISTENER_LIB}
93 MLIRBuiltinToLLVMIRTranslation
94 MLIRExecutionEngineUtils
96 MLIRLLVMToLLVMIRTranslation
97 MLIROpenMPToLLVMIRTranslation
98 MLIRTargetLLVMIRExport
101 if(LLVM_BUILD_LLVM_DYLIB AND NOT (WIN32 OR MINGW OR CYGWIN)) # Does not build on windows currently, see #106859
102 # Build a shared library for the execution engine. Some downstream projects
103 # use this library to build their own CPU runners while preserving dynamic
105 add_mlir_library(MLIRExecutionEngineShared
111 ADDITIONAL_HEADER_DIRS
112 ${MLIR_MAIN_INCLUDE_DIR}/mlir/ExecutionEngine
114 # Ensures that all necessary dependencies are resolved.
124 get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
125 add_mlir_library(MLIRJitRunner
145 MLIRLLVMToLLVMIRTranslation
146 MLIRTargetLLVMIRExport
151 # When -fPIC is not provided, shared libraries cannot be built if it links against
154 add_mlir_library(mlir_float16_utils
160 set_property(TARGET mlir_float16_utils PROPERTY CXX_STANDARD 17)
161 target_compile_definitions(mlir_float16_utils PRIVATE mlir_float16_utils_EXPORTS)
163 add_subdirectory(SparseTensor)
165 add_mlir_library(mlir_c_runner_utils
168 SparseTensorRuntime.cpp
174 MLIRSparseTensorEnums
175 MLIRSparseTensorRuntime
177 set_property(TARGET mlir_c_runner_utils PROPERTY CXX_STANDARD 17)
178 target_compile_definitions(mlir_c_runner_utils PRIVATE mlir_c_runner_utils_EXPORTS)
180 add_mlir_library(mlir_runner_utils
189 target_compile_definitions(mlir_runner_utils PRIVATE mlir_runner_utils_EXPORTS)
191 add_mlir_library(mlir_async_runtime
200 set_property(TARGET mlir_async_runtime PROPERTY CXX_VISIBILITY_PRESET hidden)
201 target_compile_definitions(mlir_async_runtime PRIVATE mlir_async_runtime_EXPORTS)
202 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
203 # Don't export symbols from link-time dependencies, these are internal
204 # implementation details.
205 # FIXME: Add a similar fix for Windows.
206 target_link_options(mlir_async_runtime PRIVATE "-Wl,-exclude-libs,ALL")
209 add_mlir_library(mlir_arm_sme_abi_stubs
212 target_compile_definitions(mlir_arm_sme_abi_stubs PRIVATE mlir_arm_sme_abi_stubs_EXPORTS)
214 add_mlir_library(mlir_arm_runner_utils
218 if(MLIR_ENABLE_CUDA_RUNNER)
219 # Configure CUDA support. Using check_language first allows us to give a
220 # custom error message.
221 include(CheckLanguage)
223 if (CMAKE_CUDA_COMPILER)
224 enable_language(CUDA)
227 "Building the mlir cuda runner requires a working CUDA install")
230 # We need the libcuda.so library.
231 find_library(CUDA_RUNTIME_LIBRARY cuda HINTS ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES} REQUIRED)
233 add_mlir_library(mlir_cuda_runtime
235 CudaRuntimeWrappers.cpp
239 set_property(TARGET mlir_cuda_runtime PROPERTY CXX_STANDARD 14)
241 target_include_directories(mlir_cuda_runtime
243 ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
245 target_link_libraries(mlir_cuda_runtime
247 ${CUDA_RUNTIME_LIBRARY}
250 if(MLIR_ENABLE_CUDA_CUSPARSE)
251 # Find the libcusparse.so library if CUSPARSE build is requested.
252 find_library(CUDA_CUSPARSE_LIBRARY cusparse HINTS ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES} REQUIRED)
254 target_link_libraries(mlir_cuda_runtime
256 ${CUDA_CUSPARSE_LIBRARY}
258 target_compile_definitions(mlir_cuda_runtime
260 MLIR_ENABLE_CUDA_CUSPARSE=1
263 if(MLIR_ENABLE_CUDA_CUSPARSELT)
264 # Find the libcusparseLt.so library in package manager default path if
265 # CUSPARSELT build is requested. libcusparseLt.so provides sm80+ tensor
266 # core support for 2:4 sparsity acceleration.
267 find_library(CUDA_CUSPARSELT_LIBRARY cusparseLt HINTS ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES} REQUIRED)
268 find_path(CUDA_CUSPARSELT_HEADER cusparseLt.h HINTS ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES} REQUIRED)
269 target_include_directories(mlir_cuda_runtime
271 ${CUDA_CUSPARSELT_HEADER}
273 target_link_libraries(mlir_cuda_runtime
275 ${CUDA_CUSPARSELT_LIBRARY}
277 target_compile_definitions(mlir_cuda_runtime
279 MLIR_ENABLE_CUDA_CUSPARSELT=1
285 if(MLIR_ENABLE_ROCM_RUNNER)
286 # Configure ROCm support.
287 if (NOT DEFINED ROCM_PATH)
288 if (NOT DEFINED ENV{ROCM_PATH})
289 set(ROCM_PATH "/opt/rocm" CACHE PATH "Path to which ROCm has been installed")
291 set(ROCM_PATH $ENV{ROCM_PATH} CACHE PATH "Path to which ROCm has been installed")
294 # A lot of the ROCm CMake files expect to find their own dependencies in
295 # CMAKE_PREFIX_PATH and don't respect PATHS or HINTS :( .
296 # Therefore, temporarily add the ROCm path to CMAKE_PREFIX_PATH so we can
297 # load HIP, then remove it
298 set(REAL_CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH}")
299 list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH} "${ROCM_PATH}/hip")
300 find_package(hip REQUIRED)
301 set(CMAKE_PREFIX_PATH "${REAL_CMAKE_PREFIX_PATH}")
303 if (NOT DEFINED ROCM_TEST_CHIPSET)
304 find_program(ROCM_AGENT_ENUMERATOR rocm_agent_enumerator "${ROCM_PATH}/bin" /usr/bin /usr/local/bin)
305 if(ROCM_AGENT_ENUMERATOR)
306 execute_process(COMMAND "${ROCM_AGENT_ENUMERATOR}"
307 OUTPUT_VARIABLE AGENTS_STRING
308 ERROR_VARIABLE AGENTS_STRING
309 RESULT_VARIABLE AGENT_ENUMERATOR_RESULT)
311 message(SEND_ERROR "Could not find rocm_agent_enumerator")
313 if (NOT AGENT_ENUMERATOR_RESULT EQUAL 0)
314 message(SEND_ERROR "Could not run rocm_agent_enumerator and ROCM_TEST_CHIPSET is not defined")
315 set(AGENTS_STRING "")
317 string(STRIP AGENTS_STRING ${AGENTS_STRING})
318 string(REPLACE "\n" ";" AGENTS_LIST ${AGENTS_STRING})
319 list(FILTER AGENTS_LIST EXCLUDE REGEX "gfx000")
320 if (AGENTS_LIST STREQUAL "")
321 message(SEND_ERROR "No non-CPU ROCm agents found on the system, and ROCM_TEST_CHIPSET is not defined")
323 list(GET AGENTS_LIST 0 FIRST_AGENT)
324 set(ROCM_TEST_CHIPSET ${FIRST_AGENT} CACHE STRING "Chipset for which to compile ROCm integration tests")
325 message(STATUS "Compiling integration tests for ${ROCM_TEST_CHIPSET}")
329 add_mlir_library(mlir_rocm_runtime
331 RocmRuntimeWrappers.cpp
336 # Supress compiler warnings from HIP headers
337 check_cxx_compiler_flag(-Wno-c++98-compat-extra-semi
338 CXX_SUPPORTS_NO_CXX98_COMPAT_EXTRA_SEMI_FLAG)
339 if (CXX_SUPPORTS_CXX98_COMPAT_EXTRA_SEMI_FLAG)
340 target_compile_options(mlir_rocm_runtime PRIVATE
341 "-Wno-c++98-compat-extra-semi")
343 check_cxx_compiler_flag(-Wno-return-type-c-linkage
344 CXX_SUPPORTS_WNO_RETURN_TYPE_C_LINKAGE_FLAG)
345 if (CXX_SUPPORTS_WNO_RETURN_TYPE_C_LINKAGE_FLAG)
346 target_compile_options(mlir_rocm_runtime PRIVATE
347 "-Wno-return-type-c-linkage")
349 check_cxx_compiler_flag(-Wno-nested-anon-types
350 CXX_SUPPORTS_WNO_NESTED_ANON_TYPES_FLAG)
351 if (CXX_SUPPORTS_WNO_NESTED_ANON_TYPES_FLAG)
352 target_compile_options(mlir_rocm_runtime PRIVATE
353 "-Wno-nested-anon-types")
355 check_cxx_compiler_flag(-Wno-gnu-anonymous-struct
356 CXX_SUPPORTS_WNO_GNU_ANONYMOUS_STRUCT_FLAG)
357 if (CXX_SUPPORTS_WNO_GNU_ANONYMOUS_STRUCT_FLAG)
358 target_compile_options(mlir_rocm_runtime PRIVATE
359 "-Wno-gnu-anonymous-struct")
362 set_property(TARGET mlir_rocm_runtime
363 PROPERTY INSTALL_RPATH_USE_LINK_PATH ON)
365 target_link_libraries(mlir_rocm_runtime
367 hip::host hip::amdhip64
371 if(MLIR_ENABLE_SYCL_RUNNER)
372 find_package(SyclRuntime)
374 if(NOT SyclRuntime_FOUND)
375 message(FATAL_ERROR "syclRuntime not found. Please set check oneapi installation and run setvars.sh.")
378 find_package(LevelZero)
380 if(NOT LevelZero_FOUND)
381 message(FATAL_ERROR "LevelZero not found. Please set LEVEL_ZERO_DIR.")
384 add_mlir_library(mlir_sycl_runtime
386 SyclRuntimeWrappers.cpp
391 check_cxx_compiler_flag("-frtti" CXX_HAS_FRTTI_FLAG)
392 if(NOT CXX_HAS_FRTTI_FLAG)
393 message(FATAL_ERROR "CXX compiler does not accept flag -frtti")
395 target_compile_options (mlir_sycl_runtime PUBLIC -fexceptions -frtti)
397 target_include_directories(mlir_sycl_runtime PRIVATE
401 target_link_libraries(mlir_sycl_runtime PRIVATE LevelZero::LevelZero SyclRuntime::SyclRuntime)
403 set_property(TARGET mlir_sycl_runtime APPEND PROPERTY BUILD_RPATH "${LevelZero_LIBRARIES_DIR}" "${SyclRuntime_LIBRARIES_DIR}")
406 if(MLIR_ENABLE_SPIRV_CPU_RUNNER)
407 add_mlir_library(mlir_spirv_cpu_runtime
409 SpirvCpuRuntimeWrappers.cpp
414 target_compile_definitions(mlir_spirv_cpu_runtime
416 mlir_spirv_cpu_runtime_EXPORTS)