[rtsan] Remove mkfifoat interceptor (#116997)
[llvm-project.git] / mlir / lib / ExecutionEngine / CMakeLists.txt
blobcf44a02cf5cb941becfebbc351028cec996a8dfc
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
5   ArmRunnerUtils.cpp
6   ArmSMEStubs.cpp
7   AsyncRuntime.cpp
8   CRunnerUtils.cpp
9   CudaRuntimeWrappers.cpp
10   SparseTensorRuntime.cpp
11   ExecutionEngine.cpp
12   Float16bits.cpp
13   RocmRuntimeWrappers.cpp
14   RunnerUtils.cpp
15   OptUtils.cpp
16   JitRunner.cpp
17   SpirvCpuRuntimeWrappers.cpp
18   SyclRuntimeWrappers.cpp
19   )
21 # Use a separate library for OptUtils, to avoid pulling in the entire JIT and
22 # codegen infrastructure. Unlike MLIRExecutionEngine, this is part of
23 # libMLIR.so.
24 add_mlir_library(MLIRExecutionEngineUtils
25   OptUtils.cpp
27   ADDITIONAL_HEADER_DIRS
28   ${MLIR_MAIN_INCLUDE_DIR}/mlir/ExecutionEngine
30   DEPENDS
31   intrinsics_gen
33   LINK_COMPONENTS
34   Analysis
35   Core
36   Coroutines
37   AggressiveInstCombine
38   InstCombine
39   ScalarOpts
40   Vectorize
41   TransformUtils
42   IPO
43   Passes
44   TargetParser
45   )
47 if(NOT MLIR_ENABLE_EXECUTION_ENGINE)
48   return()
49 endif()
51 if(LLVM_USE_INTEL_JITEVENTS)
52   set(LLVM_JIT_LISTENER_LIB
53       IntelJITEvents)
54 endif(LLVM_USE_INTEL_JITEVENTS)
56 if(LLVM_USE_PERF)
57   set(LLVM_JIT_LISTENER_LIB
58       PerfJITEvents)
59 endif(LLVM_USE_PERF)
61 add_mlir_library(MLIRExecutionEngine
62   ExecutionEngine.cpp
64   EXCLUDE_FROM_LIBMLIR
66   ADDITIONAL_HEADER_DIRS
67   ${MLIR_MAIN_INCLUDE_DIR}/mlir/ExecutionEngine
69   DEPENDS
70   intrinsics_gen
72   LINK_COMPONENTS
73   Core
74   Coroutines
75   ExecutionEngine
76   Object
77   OrcJIT
78   JITLink
79   Analysis
80   AggressiveInstCombine
81   InstCombine
82   MC
83   ScalarOpts
84   Target
85   Vectorize
86   TransformUtils
87   nativecodegen
88   IPO
89   Passes
90   ${LLVM_JIT_LISTENER_LIB}
92   LINK_LIBS PUBLIC
93   MLIRBuiltinToLLVMIRTranslation
94   MLIRExecutionEngineUtils
95   MLIRLLVMDialect
96   MLIRLLVMToLLVMIRTranslation
97   MLIROpenMPToLLVMIRTranslation
98   MLIRTargetLLVMIRExport
99   )
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
104   # linkage.
105   add_mlir_library(MLIRExecutionEngineShared
106     ExecutionEngine.cpp
107     SHARED
109     EXCLUDE_FROM_LIBMLIR
111     ADDITIONAL_HEADER_DIRS
112     ${MLIR_MAIN_INCLUDE_DIR}/mlir/ExecutionEngine
114     # Ensures that all necessary dependencies are resolved.
115     DEPENDS
116     MLIRExecutionEngine
118     LINK_LIBS PUBLIC
119     LLVM
120     MLIR
121     )
122 endif()
124 get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
125 add_mlir_library(MLIRJitRunner
126   JitRunner.cpp
128   EXCLUDE_FROM_LIBMLIR
130   DEPENDS
131   intrinsics_gen
133   LINK_COMPONENTS
134   Core
135   OrcJIT
136   JITLink
138   LINK_LIBS PUBLIC
139   ${dialect_libs}
140   MLIRExecutionEngine
141   MLIRFuncDialect
142   MLIRFuncToLLVM
143   MLIRIR
144   MLIRParser
145   MLIRLLVMToLLVMIRTranslation
146   MLIRTargetLLVMIRExport
147   MLIRTransforms
148   MLIRSupport
151 # When -fPIC is not provided, shared libraries cannot be built if it links against
152 # non-PIC code.
153 if(LLVM_ENABLE_PIC)
154   add_mlir_library(mlir_float16_utils
155     SHARED
156     Float16bits.cpp
158     EXCLUDE_FROM_LIBMLIR
159     )
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
166     SHARED
167     CRunnerUtils.cpp
168     SparseTensorRuntime.cpp
170     EXCLUDE_FROM_LIBMLIR
172     LINK_LIBS PUBLIC
173     mlir_float16_utils
174     MLIRSparseTensorEnums
175     MLIRSparseTensorRuntime
176     )
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
181     SHARED
182     RunnerUtils.cpp
184     EXCLUDE_FROM_LIBMLIR
186     LINK_LIBS PUBLIC
187     mlir_float16_utils
188   )
189   target_compile_definitions(mlir_runner_utils PRIVATE mlir_runner_utils_EXPORTS)
191   add_mlir_library(mlir_async_runtime
192     SHARED
193     AsyncRuntime.cpp
195     EXCLUDE_FROM_LIBMLIR
197     LINK_LIBS PUBLIC
198     ${LLVM_PTHREAD_LIB}
199   )
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")
207   endif()
209   add_mlir_library(mlir_arm_sme_abi_stubs
210     SHARED
211     ArmSMEStubs.cpp)
212   target_compile_definitions(mlir_arm_sme_abi_stubs PRIVATE mlir_arm_sme_abi_stubs_EXPORTS)
214   add_mlir_library(mlir_arm_runner_utils
215     SHARED
216     ArmRunnerUtils.cpp)
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)
222     check_language(CUDA)
223     if (CMAKE_CUDA_COMPILER)
224       enable_language(CUDA)
225     else()
226       message(SEND_ERROR
227         "Building the mlir cuda runner requires a working CUDA install")
228     endif()
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
234       SHARED
235       CudaRuntimeWrappers.cpp
237       EXCLUDE_FROM_LIBMLIR
238     )
239     set_property(TARGET mlir_cuda_runtime PROPERTY CXX_STANDARD 14)
241     target_include_directories(mlir_cuda_runtime
242       PRIVATE
243       ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
244     )
245     target_link_libraries(mlir_cuda_runtime
246       PRIVATE
247       ${CUDA_RUNTIME_LIBRARY}
248     )
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
255         PRIVATE
256         ${CUDA_CUSPARSE_LIBRARY}
257       )
258       target_compile_definitions(mlir_cuda_runtime
259         PRIVATE
260         MLIR_ENABLE_CUDA_CUSPARSE=1
261       )
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
270           PRIVATE
271           ${CUDA_CUSPARSELT_HEADER}
272         )
273         target_link_libraries(mlir_cuda_runtime
274           PRIVATE
275           ${CUDA_CUSPARSELT_LIBRARY}
276         )
277         target_compile_definitions(mlir_cuda_runtime
278           PRIVATE
279           MLIR_ENABLE_CUDA_CUSPARSELT=1
280         )
281       endif()
282     endif()
283   endif()
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")
290       else()
291         set(ROCM_PATH $ENV{ROCM_PATH} CACHE PATH "Path to which ROCm has been installed")
292       endif()
293     endif()
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)
310       else()
311         message(SEND_ERROR "Could not find rocm_agent_enumerator")
312       endif()
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 "")
316       endif()
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")
322       else()
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}")
326       endif()
327     endif()
329     add_mlir_library(mlir_rocm_runtime
330       SHARED
331       RocmRuntimeWrappers.cpp
333       EXCLUDE_FROM_LIBMLIR
334     )
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")
342     endif()
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")
348     endif()
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")
354     endif()
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")
360     endif()
362     set_property(TARGET mlir_rocm_runtime
363       PROPERTY INSTALL_RPATH_USE_LINK_PATH ON)
365     target_link_libraries(mlir_rocm_runtime
366       PUBLIC
367       hip::host hip::amdhip64
368     )
369   endif()
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.")
376     endif()
378     find_package(LevelZero)
380     if(NOT LevelZero_FOUND)
381       message(FATAL_ERROR "LevelZero not found. Please set LEVEL_ZERO_DIR.")
382     endif()
384     add_mlir_library(mlir_sycl_runtime
385       SHARED
386       SyclRuntimeWrappers.cpp
388       EXCLUDE_FROM_LIBMLIR
389     )
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")
394     endif()
395     target_compile_options (mlir_sycl_runtime PUBLIC -fexceptions -frtti)
397     target_include_directories(mlir_sycl_runtime PRIVATE
398       ${MLIR_INCLUDE_DIRS}
399     )
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}")
404   endif()
406   if(MLIR_ENABLE_SPIRV_CPU_RUNNER)
407     add_mlir_library(mlir_spirv_cpu_runtime
408       SHARED
409       SpirvCpuRuntimeWrappers.cpp
411       EXCLUDE_FROM_LIBMLIR
412     )
414     target_compile_definitions(mlir_spirv_cpu_runtime
415       PRIVATE
416       mlir_spirv_cpu_runtime_EXPORTS)
417   endif()
418 endif()