[SampleProfileLoader] Fix integer overflow in generateMDProfMetadata (#90217)
[llvm-project.git] / mlir / lib / ExecutionEngine / CMakeLists.txt
bloba091944b9ee7df912c4e60fec482548269ee6b81
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   SyclRuntimeWrappers.cpp
18   )
20 # Use a separate library for OptUtils, to avoid pulling in the entire JIT and
21 # codegen infrastructure. Unlike MLIRExecutionEngine, this is part of
22 # libMLIR.so.
23 add_mlir_library(MLIRExecutionEngineUtils
24   OptUtils.cpp
26   ADDITIONAL_HEADER_DIRS
27   ${MLIR_MAIN_INCLUDE_DIR}/mlir/ExecutionEngine
29   DEPENDS
30   intrinsics_gen
32   LINK_COMPONENTS
33   Analysis
34   Core
35   Coroutines
36   AggressiveInstCombine
37   InstCombine
38   ScalarOpts
39   Vectorize
40   TransformUtils
41   IPO
42   Passes
43   TargetParser
44   )
46 if(NOT MLIR_ENABLE_EXECUTION_ENGINE)
47   return()
48 endif()
50 if(LLVM_USE_INTEL_JITEVENTS)
51   set(LLVM_JIT_LISTENER_LIB
52       IntelJITEvents)
53 endif(LLVM_USE_INTEL_JITEVENTS)
55 if(LLVM_USE_PERF)
56   set(LLVM_JIT_LISTENER_LIB
57       PerfJITEvents)
58 endif(LLVM_USE_PERF)
60 add_mlir_library(MLIRExecutionEngine
61   ExecutionEngine.cpp
63   EXCLUDE_FROM_LIBMLIR
65   ADDITIONAL_HEADER_DIRS
66   ${MLIR_MAIN_INCLUDE_DIR}/mlir/ExecutionEngine
68   DEPENDS
69   intrinsics_gen
71   LINK_COMPONENTS
72   Core
73   Coroutines
74   ExecutionEngine
75   Object
76   OrcJIT
77   JITLink
78   Analysis
79   AggressiveInstCombine
80   InstCombine
81   MC
82   ScalarOpts
83   Target
84   Vectorize
85   TransformUtils
86   nativecodegen
87   IPO
88   Passes
89   ${LLVM_JIT_LISTENER_LIB}
91   LINK_LIBS PUBLIC
92   MLIRBuiltinToLLVMIRTranslation
93   MLIRExecutionEngineUtils
94   MLIRLLVMDialect
95   MLIRLLVMToLLVMIRTranslation
96   MLIROpenMPToLLVMIRTranslation
97   MLIRTargetLLVMIRExport
98   )
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
103   # linkage.
104   add_mlir_library(MLIRExecutionEngineShared
105     ExecutionEngine.cpp
106     SHARED
108     EXCLUDE_FROM_LIBMLIR
110     ADDITIONAL_HEADER_DIRS
111     ${MLIR_MAIN_INCLUDE_DIR}/mlir/ExecutionEngine
113     # Ensures that all necessary dependencies are resolved.
114     DEPENDS
115     MLIRExecutionEngine
117     LINK_LIBS PUBLIC
118     LLVM
119     MLIR
120     )
121 endif()
123 get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
124 add_mlir_library(MLIRJitRunner
125   JitRunner.cpp
127   EXCLUDE_FROM_LIBMLIR
129   DEPENDS
130   intrinsics_gen
132   LINK_COMPONENTS
133   Core
134   OrcJIT
135   JITLink
137   LINK_LIBS PUBLIC
138   ${dialect_libs}
139   MLIRExecutionEngine
140   MLIRFuncDialect
141   MLIRFuncToLLVM
142   MLIRIR
143   MLIRParser
144   MLIRLLVMToLLVMIRTranslation
145   MLIRTargetLLVMIRExport
146   MLIRTransforms
147   MLIRSupport
150 # When -fPIC is not provided, shared libraries cannot be built if it links against
151 # non-PIC code.
152 if(LLVM_ENABLE_PIC)
153   add_mlir_library(mlir_float16_utils
154     SHARED
155     Float16bits.cpp
157     EXCLUDE_FROM_LIBMLIR
158     )
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
165     SHARED
166     CRunnerUtils.cpp
167     SparseTensorRuntime.cpp
169     EXCLUDE_FROM_LIBMLIR
171     LINK_LIBS PUBLIC
172     mlir_float16_utils
173     MLIRSparseTensorEnums
174     MLIRSparseTensorRuntime
175     )
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
180     SHARED
181     RunnerUtils.cpp
183     EXCLUDE_FROM_LIBMLIR
185     LINK_LIBS PUBLIC
186     mlir_float16_utils
187   )
188   target_compile_definitions(mlir_runner_utils PRIVATE mlir_runner_utils_EXPORTS)
190   add_mlir_library(mlir_async_runtime
191     SHARED
192     AsyncRuntime.cpp
194     EXCLUDE_FROM_LIBMLIR
196     LINK_LIBS PUBLIC
197     ${LLVM_PTHREAD_LIB}
198   )
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")
206   endif()
208   add_mlir_library(mlir_arm_sme_abi_stubs
209     SHARED
210     ArmSMEStubs.cpp)
211   target_compile_definitions(mlir_arm_sme_abi_stubs PRIVATE mlir_arm_sme_abi_stubs_EXPORTS)
213   add_mlir_library(mlir_arm_runner_utils
214     SHARED
215     ArmRunnerUtils.cpp)
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)
221     check_language(CUDA)
222     if (CMAKE_CUDA_COMPILER)
223       enable_language(CUDA)
224     else()
225       message(SEND_ERROR
226         "Building the mlir cuda runner requires a working CUDA install")
227     endif()
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
233       SHARED
234       CudaRuntimeWrappers.cpp
236       EXCLUDE_FROM_LIBMLIR
237     )
238     set_property(TARGET mlir_cuda_runtime PROPERTY CXX_STANDARD 14)
240     target_include_directories(mlir_cuda_runtime
241       PRIVATE
242       ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
243     )
244     target_link_libraries(mlir_cuda_runtime
245       PRIVATE
246       ${CUDA_RUNTIME_LIBRARY}
247     )
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
254         PRIVATE
255         ${CUDA_CUSPARSE_LIBRARY}
256       )
257       target_compile_definitions(mlir_cuda_runtime
258         PRIVATE
259         MLIR_ENABLE_CUDA_CUSPARSE=1
260       )
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
269           PRIVATE
270           ${CUDA_CUSPARSELT_HEADER}
271         )
272         target_link_libraries(mlir_cuda_runtime
273           PRIVATE
274           ${CUDA_CUSPARSELT_LIBRARY}
275         )
276         target_compile_definitions(mlir_cuda_runtime
277           PRIVATE
278           MLIR_ENABLE_CUDA_CUSPARSELT=1
279         )
280       endif()
281     endif()
282   endif()
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")
289       else()
290         set(ROCM_PATH $ENV{ROCM_PATH} CACHE PATH "Path to which ROCm has been installed")
291       endif()
292     endif()
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)
309       else()
310         message(SEND_ERROR "Could not find rocm_agent_enumerator")
311       endif()
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 "")
315       endif()
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")
321       else()
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}")
325       endif()
326     endif()
328     add_mlir_library(mlir_rocm_runtime
329       SHARED
330       RocmRuntimeWrappers.cpp
332       EXCLUDE_FROM_LIBMLIR
333     )
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")
341     endif()
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")
347     endif()
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")
353     endif()
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")
359     endif()
361     set_property(TARGET mlir_rocm_runtime
362       PROPERTY INSTALL_RPATH_USE_LINK_PATH ON)
364     target_link_libraries(mlir_rocm_runtime
365       PUBLIC
366       hip::host hip::amdhip64
367     )
368   endif()
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.")
375     endif()
377     find_package(LevelZero)
379     if(NOT LevelZero_FOUND)
380       message(FATAL_ERROR "LevelZero not found. Please set LEVEL_ZERO_DIR.")
381     endif()
383     add_mlir_library(mlir_sycl_runtime
384       SHARED
385       SyclRuntimeWrappers.cpp
387       EXCLUDE_FROM_LIBMLIR
388     )
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")
393     endif()
394     target_compile_options (mlir_sycl_runtime PUBLIC -fexceptions -frtti)
396     target_include_directories(mlir_sycl_runtime PRIVATE
397       ${MLIR_INCLUDE_DIRS}
398     )
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}")
403   endif()
404 endif()