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 SyclRuntimeWrappers.cpp
20 # Use a separate library for OptUtils, to avoid pulling in the entire JIT and
21 # codegen infrastructure. Unlike MLIRExecutionEngine, this is part of
23 add_mlir_library(MLIRExecutionEngineUtils
26 ADDITIONAL_HEADER_DIRS
27 ${MLIR_MAIN_INCLUDE_DIR}/mlir/ExecutionEngine
46 if(NOT MLIR_ENABLE_EXECUTION_ENGINE)
50 if(LLVM_USE_INTEL_JITEVENTS)
51 set(LLVM_JIT_LISTENER_LIB
53 endif(LLVM_USE_INTEL_JITEVENTS)
56 set(LLVM_JIT_LISTENER_LIB
60 add_mlir_library(MLIRExecutionEngine
65 ADDITIONAL_HEADER_DIRS
66 ${MLIR_MAIN_INCLUDE_DIR}/mlir/ExecutionEngine
89 ${LLVM_JIT_LISTENER_LIB}
92 MLIRBuiltinToLLVMIRTranslation
93 MLIRExecutionEngineUtils
95 MLIRLLVMToLLVMIRTranslation
96 MLIROpenMPToLLVMIRTranslation
97 MLIRTargetLLVMIRExport
100 if(LLVM_BUILD_LLVM_DYLIB)
101 # Build a shared library for the execution engine. Some downstream projects
102 # use this library to build their own CPU runners while preserving dynamic
104 add_mlir_library(MLIRExecutionEngineShared
110 ADDITIONAL_HEADER_DIRS
111 ${MLIR_MAIN_INCLUDE_DIR}/mlir/ExecutionEngine
113 # Ensures that all necessary dependencies are resolved.
123 get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
124 add_mlir_library(MLIRJitRunner
144 MLIRLLVMToLLVMIRTranslation
145 MLIRTargetLLVMIRExport
150 # When -fPIC is not provided, shared libraries cannot be built if it links against
153 add_mlir_library(mlir_float16_utils
159 set_property(TARGET mlir_float16_utils PROPERTY CXX_STANDARD 17)
160 target_compile_definitions(mlir_float16_utils PRIVATE mlir_float16_utils_EXPORTS)
162 add_subdirectory(SparseTensor)
164 add_mlir_library(mlir_c_runner_utils
167 SparseTensorRuntime.cpp
173 MLIRSparseTensorEnums
174 MLIRSparseTensorRuntime
176 set_property(TARGET mlir_c_runner_utils PROPERTY CXX_STANDARD 17)
177 target_compile_definitions(mlir_c_runner_utils PRIVATE mlir_c_runner_utils_EXPORTS)
179 add_mlir_library(mlir_runner_utils
188 target_compile_definitions(mlir_runner_utils PRIVATE mlir_runner_utils_EXPORTS)
190 add_mlir_library(mlir_async_runtime
199 set_property(TARGET mlir_async_runtime PROPERTY CXX_VISIBILITY_PRESET hidden)
200 target_compile_definitions(mlir_async_runtime PRIVATE mlir_async_runtime_EXPORTS)
201 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
202 # Don't export symbols from link-time dependencies, these are internal
203 # implementation details.
204 # FIXME: Add a similar fix for Windows.
205 target_link_options(mlir_async_runtime PRIVATE "-Wl,-exclude-libs,ALL")
208 add_mlir_library(mlir_arm_sme_abi_stubs
211 target_compile_definitions(mlir_arm_sme_abi_stubs PRIVATE mlir_arm_sme_abi_stubs_EXPORTS)
213 add_mlir_library(mlir_arm_runner_utils
217 if(MLIR_ENABLE_CUDA_RUNNER)
218 # Configure CUDA support. Using check_language first allows us to give a
219 # custom error message.
220 include(CheckLanguage)
222 if (CMAKE_CUDA_COMPILER)
223 enable_language(CUDA)
226 "Building the mlir cuda runner requires a working CUDA install")
229 # We need the libcuda.so library.
230 find_library(CUDA_RUNTIME_LIBRARY cuda HINTS ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES} REQUIRED)
232 add_mlir_library(mlir_cuda_runtime
234 CudaRuntimeWrappers.cpp
238 set_property(TARGET mlir_cuda_runtime PROPERTY CXX_STANDARD 14)
240 target_include_directories(mlir_cuda_runtime
242 ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
244 target_link_libraries(mlir_cuda_runtime
246 ${CUDA_RUNTIME_LIBRARY}
249 if(MLIR_ENABLE_CUDA_CUSPARSE)
250 # Find the libcusparse.so library if CUSPARSE build is requested.
251 find_library(CUDA_CUSPARSE_LIBRARY cusparse HINTS ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES} REQUIRED)
253 target_link_libraries(mlir_cuda_runtime
255 ${CUDA_CUSPARSE_LIBRARY}
257 target_compile_definitions(mlir_cuda_runtime
259 MLIR_ENABLE_CUDA_CUSPARSE=1
262 if(MLIR_ENABLE_CUDA_CUSPARSELT)
263 # Find the libcusparseLt.so library in package manager default path if
264 # CUSPARSELT build is requested. libcusparseLt.so provides sm80+ tensor
265 # core support for 2:4 sparsity acceleration.
266 find_library(CUDA_CUSPARSELT_LIBRARY cusparseLt HINTS ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES} REQUIRED)
267 find_path(CUDA_CUSPARSELT_HEADER cusparseLt.h HINTS ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES} REQUIRED)
268 target_include_directories(mlir_cuda_runtime
270 ${CUDA_CUSPARSELT_HEADER}
272 target_link_libraries(mlir_cuda_runtime
274 ${CUDA_CUSPARSELT_LIBRARY}
276 target_compile_definitions(mlir_cuda_runtime
278 MLIR_ENABLE_CUDA_CUSPARSELT=1
284 if(MLIR_ENABLE_ROCM_RUNNER)
285 # Configure ROCm support.
286 if (NOT DEFINED ROCM_PATH)
287 if (NOT DEFINED ENV{ROCM_PATH})
288 set(ROCM_PATH "/opt/rocm" CACHE PATH "Path to which ROCm has been installed")
290 set(ROCM_PATH $ENV{ROCM_PATH} CACHE PATH "Path to which ROCm has been installed")
293 # A lot of the ROCm CMake files expect to find their own dependencies in
294 # CMAKE_PREFIX_PATH and don't respect PATHS or HINTS :( .
295 # Therefore, temporarily add the ROCm path to CMAKE_PREFIX_PATH so we can
296 # load HIP, then remove it
297 set(REAL_CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH}")
298 list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH} "${ROCM_PATH}/hip")
299 find_package(hip REQUIRED)
300 set(CMAKE_PREFIX_PATH "${REAL_CMAKE_PREFIX_PATH}")
302 if (NOT DEFINED ROCM_TEST_CHIPSET)
303 find_program(ROCM_AGENT_ENUMERATOR rocm_agent_enumerator "${ROCM_PATH}/bin" /usr/bin /usr/local/bin)
304 if(ROCM_AGENT_ENUMERATOR)
305 execute_process(COMMAND "${ROCM_AGENT_ENUMERATOR}"
306 OUTPUT_VARIABLE AGENTS_STRING
307 ERROR_VARIABLE AGENTS_STRING
308 RESULT_VARIABLE AGENT_ENUMERATOR_RESULT)
310 message(SEND_ERROR "Could not find rocm_agent_enumerator")
312 if (NOT AGENT_ENUMERATOR_RESULT EQUAL 0)
313 message(SEND_ERROR "Could not run rocm_agent_enumerator and ROCM_TEST_CHIPSET is not defined")
314 set(AGENTS_STRING "")
316 string(STRIP AGENTS_STRING ${AGENTS_STRING})
317 string(REPLACE "\n" ";" AGENTS_LIST ${AGENTS_STRING})
318 list(FILTER AGENTS_LIST EXCLUDE REGEX "gfx000")
319 if (AGENTS_LIST STREQUAL "")
320 message(SEND_ERROR "No non-CPU ROCm agents found on the system, and ROCM_TEST_CHIPSET is not defined")
322 list(GET AGENTS_LIST 0 FIRST_AGENT)
323 set(ROCM_TEST_CHIPSET ${FIRST_AGENT} CACHE STRING "Chipset for which to compile ROCm integration tests")
324 message(STATUS "Compiling integration tests for ${ROCM_TEST_CHIPSET}")
328 add_mlir_library(mlir_rocm_runtime
330 RocmRuntimeWrappers.cpp
335 # Supress compiler warnings from HIP headers
336 check_cxx_compiler_flag(-Wno-c++98-compat-extra-semi
337 CXX_SUPPORTS_NO_CXX98_COMPAT_EXTRA_SEMI_FLAG)
338 if (CXX_SUPPORTS_CXX98_COMPAT_EXTRA_SEMI_FLAG)
339 target_compile_options(mlir_rocm_runtime PRIVATE
340 "-Wno-c++98-compat-extra-semi")
342 check_cxx_compiler_flag(-Wno-return-type-c-linkage
343 CXX_SUPPORTS_WNO_RETURN_TYPE_C_LINKAGE_FLAG)
344 if (CXX_SUPPORTS_WNO_RETURN_TYPE_C_LINKAGE_FLAG)
345 target_compile_options(mlir_rocm_runtime PRIVATE
346 "-Wno-return-type-c-linkage")
348 check_cxx_compiler_flag(-Wno-nested-anon-types
349 CXX_SUPPORTS_WNO_NESTED_ANON_TYPES_FLAG)
350 if (CXX_SUPPORTS_WNO_NESTED_ANON_TYPES_FLAG)
351 target_compile_options(mlir_rocm_runtime PRIVATE
352 "-Wno-nested-anon-types")
354 check_cxx_compiler_flag(-Wno-gnu-anonymous-struct
355 CXX_SUPPORTS_WNO_GNU_ANONYMOUS_STRUCT_FLAG)
356 if (CXX_SUPPORTS_WNO_GNU_ANONYMOUS_STRUCT_FLAG)
357 target_compile_options(mlir_rocm_runtime PRIVATE
358 "-Wno-gnu-anonymous-struct")
361 set_property(TARGET mlir_rocm_runtime
362 PROPERTY INSTALL_RPATH_USE_LINK_PATH ON)
364 target_link_libraries(mlir_rocm_runtime
366 hip::host hip::amdhip64
370 if(MLIR_ENABLE_SYCL_RUNNER)
371 find_package(SyclRuntime)
373 if(NOT SyclRuntime_FOUND)
374 message(FATAL_ERROR "syclRuntime not found. Please set check oneapi installation and run setvars.sh.")
377 find_package(LevelZero)
379 if(NOT LevelZero_FOUND)
380 message(FATAL_ERROR "LevelZero not found. Please set LEVEL_ZERO_DIR.")
383 add_mlir_library(mlir_sycl_runtime
385 SyclRuntimeWrappers.cpp
390 check_cxx_compiler_flag("-frtti" CXX_HAS_FRTTI_FLAG)
391 if(NOT CXX_HAS_FRTTI_FLAG)
392 message(FATAL_ERROR "CXX compiler does not accept flag -frtti")
394 target_compile_options (mlir_sycl_runtime PUBLIC -fexceptions -frtti)
396 target_include_directories(mlir_sycl_runtime PRIVATE
400 target_link_libraries(mlir_sycl_runtime PRIVATE LevelZero::LevelZero SyclRuntime::SyclRuntime)
402 set_property(TARGET mlir_sycl_runtime APPEND PROPERTY BUILD_RPATH "${LevelZero_LIBRARIES_DIR}" "${SyclRuntime_LIBRARIES_DIR}")