[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / mlir / lib / ExecutionEngine / CMakeLists.txt
blobfdc797763ae3a416f0f5efddea859695f8328a6c
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   AsyncRuntime.cpp
6   CRunnerUtils.cpp
7   CudaRuntimeWrappers.cpp
8   SparseTensorRuntime.cpp
9   ExecutionEngine.cpp
10   Float16bits.cpp
11   RocmRuntimeWrappers.cpp
12   RunnerUtils.cpp
13   OptUtils.cpp
14   JitRunner.cpp
15   SyclRuntimeWrappers.cpp
16   )
18 # Use a separate library for OptUtils, to avoid pulling in the entire JIT and
19 # codegen infrastructure. Unlike MLIRExecutionEngine, this is part of
20 # libMLIR.so.
21 add_mlir_library(MLIRExecutionEngineUtils
22   OptUtils.cpp
24   ADDITIONAL_HEADER_DIRS
25   ${MLIR_MAIN_INCLUDE_DIR}/mlir/ExecutionEngine
27   DEPENDS
28   intrinsics_gen
30   LINK_COMPONENTS
31   Analysis
32   Core
33   Coroutines
34   AggressiveInstCombine
35   InstCombine
36   ScalarOpts
37   Vectorize
38   TransformUtils
39   IPO
40   Passes
41   TargetParser
42   )
44 if(NOT MLIR_ENABLE_EXECUTION_ENGINE)
45   return()
46 endif()
48 if(LLVM_USE_INTEL_JITEVENTS)
49   set(LLVM_JIT_LISTENER_LIB
50       IntelJITEvents)
51 endif(LLVM_USE_INTEL_JITEVENTS)
53 if(LLVM_USE_PERF)
54   set(LLVM_JIT_LISTENER_LIB
55       PerfJITEvents)
56 endif(LLVM_USE_PERF)
58 add_mlir_library(MLIRExecutionEngine
59   ExecutionEngine.cpp
61   EXCLUDE_FROM_LIBMLIR
63   ADDITIONAL_HEADER_DIRS
64   ${MLIR_MAIN_INCLUDE_DIR}/mlir/ExecutionEngine
66   DEPENDS
67   intrinsics_gen
69   LINK_COMPONENTS
70   Core
71   Coroutines
72   ExecutionEngine
73   Object
74   OrcJIT
75   JITLink
76   Analysis
77   AggressiveInstCombine
78   InstCombine
79   MC
80   ScalarOpts
81   Target
82   Vectorize
83   TransformUtils
84   nativecodegen
85   IPO
86   Passes
87   ${LLVM_JIT_LISTENER_LIB}
89   LINK_LIBS PUBLIC
90   MLIRBuiltinToLLVMIRTranslation
91   MLIRExecutionEngineUtils
92   MLIRLLVMDialect
93   MLIRLLVMToLLVMIRTranslation
94   MLIROpenMPToLLVMIRTranslation
95   MLIRTargetLLVMIRExport
96   )
98 get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
99 add_mlir_library(MLIRJitRunner
100   JitRunner.cpp
102   EXCLUDE_FROM_LIBMLIR
104   DEPENDS
105   intrinsics_gen
107   LINK_COMPONENTS
108   Core
109   OrcJIT
110   JITLink
112   LINK_LIBS PUBLIC
113   ${dialect_libs}
114   MLIRExecutionEngine
115   MLIRFuncDialect
116   MLIRFuncToLLVM
117   MLIRIR
118   MLIRParser
119   MLIRLLVMToLLVMIRTranslation
120   MLIRTargetLLVMIRExport
121   MLIRTransforms
122   MLIRSupport
125 # When -fPIC is not provided, shared libraries cannot be built if it links against
126 # non-PIC code.
127 if(LLVM_ENABLE_PIC)
128   add_mlir_library(mlir_float16_utils
129     SHARED
130     Float16bits.cpp
132     EXCLUDE_FROM_LIBMLIR
133     )
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
140     SHARED
141     CRunnerUtils.cpp
142     SparseTensorRuntime.cpp
144     EXCLUDE_FROM_LIBMLIR
146     LINK_LIBS PUBLIC
147     mlir_float16_utils
148     MLIRSparseTensorEnums
149     MLIRSparseTensorRuntime
150     )
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
155     SHARED
156     RunnerUtils.cpp
158     EXCLUDE_FROM_LIBMLIR
159   )
160   target_compile_definitions(mlir_runner_utils PRIVATE mlir_runner_utils_EXPORTS)
162   add_mlir_library(mlir_async_runtime
163     SHARED
164     AsyncRuntime.cpp
166     EXCLUDE_FROM_LIBMLIR
168     LINK_LIBS PUBLIC
169     ${LLVM_PTHREAD_LIB}
170   )
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")
178   endif()
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)
184     check_language(CUDA)
185     if (CMAKE_CUDA_COMPILER)
186       enable_language(CUDA)
187     else()
188       message(SEND_ERROR
189         "Building the mlir cuda runner requires a working CUDA install")
190     endif()
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
196       SHARED
197       CudaRuntimeWrappers.cpp
199       EXCLUDE_FROM_LIBMLIR
200     )
201     set_property(TARGET mlir_cuda_runtime PROPERTY CXX_STANDARD 14)
203     target_include_directories(mlir_cuda_runtime
204       PRIVATE
205       ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
206     )
207     target_link_libraries(mlir_cuda_runtime
208       PRIVATE
209       ${CUDA_RUNTIME_LIBRARY}
210     )
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
217         PRIVATE
218         ${CUDA_CUSPARSE_LIBRARY}
219       )
220       target_compile_definitions(mlir_cuda_runtime
221         PRIVATE
222         MLIR_ENABLE_CUDA_CUSPARSE=1
223       )
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
232           PRIVATE
233           ${CUDA_CUSPARSELT_HEADER}
234         )
235         target_link_libraries(mlir_cuda_runtime
236           PRIVATE
237           ${CUDA_CUSPARSELT_LIBRARY}
238         )
239         target_compile_definitions(mlir_cuda_runtime
240           PRIVATE
241           MLIR_ENABLE_CUDA_CUSPARSELT=1
242         )
243       endif()
244     endif()
245   endif()
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")
252       else()
253         set(ROCM_PATH $ENV{ROCM_PATH} CACHE PATH "Path to which ROCm has been installed")
254       endif()
255     endif()
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)
272       else()
273         message(SEND_ERROR "Could not find rocm_agent_enumerator")
274       endif()
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 "")
278       endif()
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")
284       else()
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}")
288       endif()
289     endif()
291     add_mlir_library(mlir_rocm_runtime
292       SHARED
293       RocmRuntimeWrappers.cpp
295       EXCLUDE_FROM_LIBMLIR
296     )
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")
304     endif()
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")
310     endif()
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")
316     endif()
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")
322     endif()
324     set_property(TARGET mlir_rocm_runtime
325       PROPERTY INSTALL_RPATH_USE_LINK_PATH ON)
327     target_link_libraries(mlir_rocm_runtime
328       PUBLIC
329       hip::host hip::amdhip64
330     )
331   endif()
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.")
338     endif()
340     find_package(LevelZero)
342     if(NOT LevelZero_FOUND)
343       message(FATAL_ERROR "LevelZero not found. Please set LEVEL_ZERO_DIR.")
344     endif()
346     add_mlir_library(mlir_sycl_runtime
347       SHARED
348       SyclRuntimeWrappers.cpp
350       EXCLUDE_FROM_LIBMLIR
351     )
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")
356     endif()
357     target_compile_options (mlir_sycl_runtime PUBLIC -fexceptions -frtti)
359     target_include_directories(mlir_sycl_runtime PRIVATE
360       ${MLIR_INCLUDE_DIRS}
361     )
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}")
366   endif()
367 endif()