brintos

brintos / llvm-project-archived public Read only

0
0
Text · 14.6 KiB · a615352 Raw
520 lines · plain
1# Exclude these from libMLIR.so because the JIT infrastructure2# is a big dependency which most don't need.3 4set(LLVM_OPTIONAL_SOURCES5  APFloatWrappers.cpp6  ArmRunnerUtils.cpp7  ArmSMEStubs.cpp8  AsyncRuntime.cpp9  CRunnerUtils.cpp10  CudaRuntimeWrappers.cpp11  SparseTensorRuntime.cpp12  ExecutionEngine.cpp13  Float16bits.cpp14  RocmRuntimeWrappers.cpp15  RunnerUtils.cpp16  OptUtils.cpp17  JitRunner.cpp18  LevelZeroRuntimeWrappers.cpp19  SpirvCpuRuntimeWrappers.cpp20  SyclRuntimeWrappers.cpp21  VulkanRuntimeWrappers.cpp22  VulkanRuntime.cpp23  VulkanRuntime.h24  )25 26# Use a separate library for OptUtils, to avoid pulling in the entire JIT and27# codegen infrastructure. Unlike MLIRExecutionEngine, this is part of28# libMLIR.so.29add_mlir_library(MLIRExecutionEngineUtils30  OptUtils.cpp31 32  ADDITIONAL_HEADER_DIRS33  ${MLIR_MAIN_INCLUDE_DIR}/mlir/ExecutionEngine34 35  DEPENDS36  intrinsics_gen37 38  LINK_COMPONENTS39  Analysis40  Core41  Coroutines42  AggressiveInstCombine43  InstCombine44  ScalarOpts45  Vectorize46  TransformUtils47  IPO48  Passes49  TargetParser50  )51 52if(NOT MLIR_ENABLE_EXECUTION_ENGINE)53  return()54endif()55 56if(LLVM_USE_INTEL_JITEVENTS)57  set(LLVM_JIT_LISTENER_LIB58      IntelJITEvents)59endif(LLVM_USE_INTEL_JITEVENTS)60 61if(LLVM_USE_PERF)62  set(LLVM_JIT_LISTENER_LIB63      PerfJITEvents)64endif(LLVM_USE_PERF)65 66add_mlir_library(MLIRExecutionEngine67  ExecutionEngine.cpp68 69  EXCLUDE_FROM_LIBMLIR70 71  ADDITIONAL_HEADER_DIRS72  ${MLIR_MAIN_INCLUDE_DIR}/mlir/ExecutionEngine73 74  DEPENDS75  intrinsics_gen76 77  LINK_COMPONENTS78  Core79  Coroutines80  ExecutionEngine81  Object82  OrcJIT83  JITLink84  Analysis85  AggressiveInstCombine86  InstCombine87  MC88  ScalarOpts89  Target90  Vectorize91  TransformUtils92  nativecodegen93  IPO94  Passes95  ${LLVM_JIT_LISTENER_LIB}96  )97 98mlir_target_link_libraries(MLIRExecutionEngine PUBLIC99  MLIRBuiltinToLLVMIRTranslation100  MLIRExecutionEngineUtils101  MLIRLLVMDialect102  MLIRLLVMToLLVMIRTranslation103  MLIROpenMPToLLVMIRTranslation104  MLIRTargetLLVMIRExport105  )106 107if(LLVM_BUILD_LLVM_DYLIB AND NOT (WIN32 OR MINGW OR CYGWIN)) # Does not build on windows currently, see #106859108  # Build a shared library for the execution engine. Some downstream projects109  # use this library to build their own CPU runners while preserving dynamic110  # linkage.111  add_mlir_library(MLIRExecutionEngineShared112    ExecutionEngine.cpp113    SHARED114 115    EXCLUDE_FROM_LIBMLIR116 117    ADDITIONAL_HEADER_DIRS118    ${MLIR_MAIN_INCLUDE_DIR}/mlir/ExecutionEngine119 120    # Ensures that all necessary dependencies are resolved.121    DEPENDS122    MLIRExecutionEngine123 124    LINK_LIBS PUBLIC125    LLVM126    MLIR127    )128endif()129 130get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)131add_mlir_library(MLIRJitRunner132  JitRunner.cpp133 134  EXCLUDE_FROM_LIBMLIR135 136  DEPENDS137  intrinsics_gen138 139  LINK_COMPONENTS140  Core141  OrcJIT142  JITLink143 144  LINK_LIBS PUBLIC145  MLIRExecutionEngine146)147mlir_target_link_libraries(MLIRJitRunner PUBLIC148  ${dialect_libs}149  MLIRFuncDialect150  MLIRFuncToLLVM151  MLIRIR152  MLIRParser153  MLIRLLVMToLLVMIRTranslation154  MLIRTargetLLVMIRExport155  MLIRTransforms156  MLIRSupport157)158 159# When -fPIC is not provided, shared libraries cannot be built if it links against160# non-PIC code.161if(LLVM_ENABLE_PIC)162  add_mlir_library(mlir_float16_utils163    SHARED164    Float16bits.cpp165 166    EXCLUDE_FROM_LIBMLIR167    )168  set_property(TARGET mlir_float16_utils PROPERTY CXX_STANDARD 17)169  target_compile_definitions(mlir_float16_utils PRIVATE mlir_float16_utils_EXPORTS)170 171  if(CMAKE_SYSTEM_NAME STREQUAL "Linux")172    # TODO: This support library is only used on Linux builds until we figure173    # out how to hide LLVM symbols in a way that works for all platforms.174    add_mlir_library(mlir_apfloat_wrappers175      SHARED176      APFloatWrappers.cpp177 178      EXCLUDE_FROM_LIBMLIR179      )180    set_target_properties(181      mlir_apfloat_wrappers182      PROPERTIES CXX_STANDARD 17183                CXX_VISIBILITY_PRESET hidden184                VISIBILITY_INLINES_HIDDEN ON185    )186    target_compile_definitions(mlir_apfloat_wrappers PRIVATE mlir_apfloat_wrappers_EXPORTS)187    # Hide LLVM symbols to avoid ODR violations.188    target_link_options(mlir_apfloat_wrappers PRIVATE "-Wl,--exclude-libs,ALL")189  endif()190 191  add_subdirectory(SparseTensor)192 193  add_mlir_library(mlir_c_runner_utils194    SHARED195    CRunnerUtils.cpp196    SparseTensorRuntime.cpp197 198    EXCLUDE_FROM_LIBMLIR199 200    LINK_LIBS PUBLIC201    mlir_float16_utils202    MLIRSparseTensorEnums203    MLIRSparseTensorRuntime204    )205  set_property(TARGET mlir_c_runner_utils PROPERTY CXX_STANDARD 17)206  target_compile_definitions(mlir_c_runner_utils PRIVATE mlir_c_runner_utils_EXPORTS)207 208  # Conditionally link apfloat wrappers only on Linux.209  if(CMAKE_SYSTEM_NAME STREQUAL "Linux")210    target_link_libraries(mlir_c_runner_utils PUBLIC mlir_apfloat_wrappers)211  endif()212 213  add_mlir_library(mlir_runner_utils214    SHARED215    RunnerUtils.cpp216 217    EXCLUDE_FROM_LIBMLIR218 219    LINK_LIBS PUBLIC220    mlir_float16_utils221  )222  target_compile_definitions(mlir_runner_utils PRIVATE mlir_runner_utils_EXPORTS)223 224    # Conditionally link apfloat wrappers only on Linux.225  if(CMAKE_SYSTEM_NAME STREQUAL "Linux")226    target_link_libraries(mlir_runner_utils PUBLIC mlir_apfloat_wrappers)227  endif()228 229  add_mlir_library(mlir_async_runtime230    SHARED231    AsyncRuntime.cpp232 233    EXCLUDE_FROM_LIBMLIR234 235    LINK_LIBS PUBLIC236    ${LLVM_PTHREAD_LIB}237  )238  set_property(TARGET mlir_async_runtime PROPERTY CXX_VISIBILITY_PRESET hidden)239  target_compile_definitions(mlir_async_runtime PRIVATE mlir_async_runtime_EXPORTS)240  if(CMAKE_SYSTEM_NAME STREQUAL "Linux")241    # Don't export symbols from link-time dependencies, these are internal242    # implementation details.243    # FIXME: Add a similar fix for Windows.244    target_link_options(mlir_async_runtime PRIVATE "-Wl,-exclude-libs,ALL")245  endif()246 247  add_mlir_library(mlir_arm_sme_abi_stubs248    SHARED249    ArmSMEStubs.cpp)250  target_compile_definitions(mlir_arm_sme_abi_stubs PRIVATE mlir_arm_sme_abi_stubs_EXPORTS)251 252  add_mlir_library(mlir_arm_runner_utils253    SHARED254    ArmRunnerUtils.cpp)255 256  if(MLIR_ENABLE_CUDA_RUNNER)257    # Configure CUDA support. Using check_language first allows us to give a258    # custom error message.259    include(CheckLanguage)260    check_language(CUDA)261    if (CMAKE_CUDA_COMPILER)262      enable_language(CUDA)263    else()264      message(SEND_ERROR265        "Building the mlir cuda runner requires a working CUDA install")266    endif()267 268    # We need the libcuda.so library.269    find_library(CUDA_RUNTIME_LIBRARY cuda HINTS ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES} REQUIRED)270 271    add_mlir_library(mlir_cuda_runtime272      SHARED273      CudaRuntimeWrappers.cpp274 275      EXCLUDE_FROM_LIBMLIR276    )277    set_property(TARGET mlir_cuda_runtime PROPERTY CXX_STANDARD 14)278 279    target_include_directories(mlir_cuda_runtime280      PRIVATE281      ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}282    )283    target_link_libraries(mlir_cuda_runtime284      PRIVATE285      ${CUDA_RUNTIME_LIBRARY}286    )287 288    if(MLIR_ENABLE_CUDA_CUSPARSE)289      # Find the libcusparse.so library if CUSPARSE build is requested.290      find_library(CUDA_CUSPARSE_LIBRARY cusparse HINTS ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES} REQUIRED)291 292      target_link_libraries(mlir_cuda_runtime293        PRIVATE294        ${CUDA_CUSPARSE_LIBRARY}295      )296      target_compile_definitions(mlir_cuda_runtime297        PRIVATE298        MLIR_ENABLE_CUDA_CUSPARSE=1299      )300 301      if(MLIR_ENABLE_CUDA_CUSPARSELT)302        # Find the libcusparseLt.so library in package manager default path if303        # CUSPARSELT build is requested. libcusparseLt.so provides sm80+ tensor304        # core support for 2:4 sparsity acceleration.305        find_library(CUDA_CUSPARSELT_LIBRARY cusparseLt HINTS ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES} REQUIRED)306        find_path(CUDA_CUSPARSELT_HEADER cusparseLt.h HINTS ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES} REQUIRED)307        target_include_directories(mlir_cuda_runtime308          PRIVATE309          ${CUDA_CUSPARSELT_HEADER}310        )311        target_link_libraries(mlir_cuda_runtime312          PRIVATE313          ${CUDA_CUSPARSELT_LIBRARY}314        )315        target_compile_definitions(mlir_cuda_runtime316          PRIVATE317          MLIR_ENABLE_CUDA_CUSPARSELT=1318        )319      endif()320    endif()321  endif()322 323  if(MLIR_ENABLE_ROCM_RUNNER)324    # Configure ROCm support.325    if (NOT DEFINED ROCM_PATH)326      if (NOT DEFINED ENV{ROCM_PATH})327        set(ROCM_PATH "/opt/rocm" CACHE PATH "Path to which ROCm has been installed")328      else()329        set(ROCM_PATH $ENV{ROCM_PATH} CACHE PATH "Path to which ROCm has been installed")330      endif()331    endif()332    # A lot of the ROCm CMake files expect to find their own dependencies in333    # CMAKE_PREFIX_PATH and don't respect PATHS or HINTS :( .334    # Therefore, temporarily add the ROCm path to CMAKE_PREFIX_PATH so we can335    # load HIP, then remove it336    set(REAL_CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH}")337    list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH} "${ROCM_PATH}/hip")338    find_package(hip REQUIRED)339    set(CMAKE_PREFIX_PATH "${REAL_CMAKE_PREFIX_PATH}")340 341    if (NOT DEFINED ROCM_TEST_CHIPSET)342      find_program(ROCM_AGENT_ENUMERATOR rocm_agent_enumerator "${ROCM_PATH}/bin" /usr/bin /usr/local/bin)343      if(ROCM_AGENT_ENUMERATOR)344          execute_process(COMMAND "${ROCM_AGENT_ENUMERATOR}"345          OUTPUT_VARIABLE AGENTS_STRING346          ERROR_VARIABLE AGENTS_STRING347          RESULT_VARIABLE AGENT_ENUMERATOR_RESULT)348      else()349        message(SEND_ERROR "Could not find rocm_agent_enumerator")350      endif()351      if (NOT AGENT_ENUMERATOR_RESULT EQUAL 0)352        message(SEND_ERROR "Could not run rocm_agent_enumerator and ROCM_TEST_CHIPSET is not defined")353        set(AGENTS_STRING "")354      endif()355      string(STRIP AGENTS_STRING ${AGENTS_STRING})356      string(REPLACE "\n" ";" AGENTS_LIST ${AGENTS_STRING})357      if (AGENTS_LIST STREQUAL "")358        message(SEND_ERROR "No non-CPU ROCm agents found on the system, and ROCM_TEST_CHIPSET is not defined")359      else()360        list(GET AGENTS_LIST 0 FIRST_AGENT)361        set(ROCM_TEST_CHIPSET ${FIRST_AGENT} CACHE STRING "Chipset for which to compile ROCm integration tests")362        message(STATUS "Compiling integration tests for ${ROCM_TEST_CHIPSET}")363      endif()364    endif()365 366    add_mlir_library(mlir_rocm_runtime367      SHARED368      RocmRuntimeWrappers.cpp369 370      EXCLUDE_FROM_LIBMLIR371    )372 373    # Supress compiler warnings from HIP headers374    check_cxx_compiler_flag(-Wno-c++98-compat-extra-semi375      CXX_SUPPORTS_NO_CXX98_COMPAT_EXTRA_SEMI_FLAG)376    if (CXX_SUPPORTS_CXX98_COMPAT_EXTRA_SEMI_FLAG)377      target_compile_options(mlir_rocm_runtime PRIVATE378        "-Wno-c++98-compat-extra-semi")379    endif()380    check_cxx_compiler_flag(-Wno-return-type-c-linkage381        CXX_SUPPORTS_WNO_RETURN_TYPE_C_LINKAGE_FLAG)382    if (CXX_SUPPORTS_WNO_RETURN_TYPE_C_LINKAGE_FLAG)383      target_compile_options(mlir_rocm_runtime PRIVATE384        "-Wno-return-type-c-linkage")385    endif()386    check_cxx_compiler_flag(-Wno-nested-anon-types387      CXX_SUPPORTS_WNO_NESTED_ANON_TYPES_FLAG)388    if (CXX_SUPPORTS_WNO_NESTED_ANON_TYPES_FLAG)389      target_compile_options(mlir_rocm_runtime PRIVATE390        "-Wno-nested-anon-types")391    endif()392    check_cxx_compiler_flag(-Wno-gnu-anonymous-struct393      CXX_SUPPORTS_WNO_GNU_ANONYMOUS_STRUCT_FLAG)394    if (CXX_SUPPORTS_WNO_GNU_ANONYMOUS_STRUCT_FLAG)395      target_compile_options(mlir_rocm_runtime PRIVATE396      "-Wno-gnu-anonymous-struct")397    endif()398 399    set_property(TARGET mlir_rocm_runtime400      PROPERTY INSTALL_RPATH_USE_LINK_PATH ON)401 402    target_link_libraries(mlir_rocm_runtime403      PUBLIC404      hip::host hip::amdhip64405    )406  endif()407 408  if(MLIR_ENABLE_SYCL_RUNNER OR MLIR_ENABLE_LEVELZERO_RUNNER)409    # Both runtimes require LevelZero, so we can find it once.410    find_package(LevelZeroRuntime)411 412    if(NOT LevelZeroRuntime_FOUND)413      message(FATAL_ERROR "LevelZero not found. Please set LEVEL_ZERO_DIR.")414    endif()415  endif()416 417  if(MLIR_ENABLE_SYCL_RUNNER)418    find_package(SyclRuntime)419 420    if(NOT SyclRuntime_FOUND)421      message(FATAL_ERROR "syclRuntime not found. Please set check oneapi installation and run setvars.sh.")422    endif()423 424    add_mlir_library(mlir_sycl_runtime425      SHARED426      SyclRuntimeWrappers.cpp427 428      EXCLUDE_FROM_LIBMLIR429    )430 431    check_cxx_compiler_flag("-frtti" CXX_HAS_FRTTI_FLAG)432    if(NOT CXX_HAS_FRTTI_FLAG)433      message(FATAL_ERROR "CXX compiler does not accept flag -frtti")434    endif()435    target_compile_options (mlir_sycl_runtime PUBLIC -fexceptions -frtti)436 437    target_include_directories(mlir_sycl_runtime PRIVATE438      ${MLIR_INCLUDE_DIRS}439    )440 441    target_link_libraries(mlir_sycl_runtime PRIVATE LevelZeroRuntime::LevelZeroRuntime SyclRuntime::SyclRuntime)442 443    set_property(TARGET mlir_sycl_runtime APPEND PROPERTY BUILD_RPATH "${LevelZeroRuntime_LIBRARIES_DIR}" "${SyclRuntime_LIBRARIES_DIR}")444  endif()445 446  if(MLIR_ENABLE_LEVELZERO_RUNNER)447    add_mlir_library(mlir_levelzero_runtime448      SHARED449      LevelZeroRuntimeWrappers.cpp450 451      EXCLUDE_FROM_LIBMLIR452    )453 454    target_compile_options(mlir_levelzero_runtime PUBLIC -fexceptions -frtti)455 456    target_include_directories(mlir_levelzero_runtime PRIVATE457      ${MLIR_INCLUDE_DIRS}458    )459 460    target_link_libraries(mlir_levelzero_runtime PRIVATE LevelZeroRuntime::LevelZeroRuntime)461 462    set_property(TARGET mlir_levelzero_runtime APPEND PROPERTY BUILD_RPATH "${LevelZeroRuntime_LIBRARIES_DIR}")463  endif()464 465  if(MLIR_ENABLE_SPIRV_CPU_RUNNER)466    add_mlir_library(mlir_spirv_cpu_runtime467      SHARED468      SpirvCpuRuntimeWrappers.cpp469 470      EXCLUDE_FROM_LIBMLIR471    )472 473    target_compile_definitions(mlir_spirv_cpu_runtime474      PRIVATE475      mlir_spirv_cpu_runtime_EXPORTS)476  endif()477 478  if (MLIR_ENABLE_VULKAN_RUNNER)479    find_package(Vulkan)480 481    # If Vulkan is not found try a path specified by VULKAN_SDK.482    if (NOT Vulkan_FOUND)483      if ("$ENV{VULKAN_SDK}" STREQUAL "")484        message(FATAL_ERROR "Vulkan not found through CMake; please provide "485                            "VULKAN_SDK path as an environment variable")486      endif()487 488      find_library(Vulkan_LIBRARY vulkan HINTS "$ENV{VULKAN_SDK}/lib" REQUIRED)489      if (Vulkan_LIBRARY)490        set(Vulkan_FOUND ON)491        set(Vulkan_INCLUDE_DIR "$ENV{VULKAN_SDK}/include")492        message(STATUS "Found Vulkan: " ${Vulkan_LIBRARY})493      endif()494    endif()495 496    if (NOT Vulkan_FOUND)497      message(FATAL_ERROR "Cannot find Vulkan library")498    endif()499 500    add_llvm_library(mlir_vulkan_runtime SHARED501      VulkanRuntimeWrappers.cpp502      VulkanRuntime.cpp503    )504 505    target_include_directories(mlir_vulkan_runtime506      PUBLIC507      ${Vulkan_INCLUDE_DIR}508    )509 510    # *IMPORTANT*: This library cannot depend on LLVM libraries. Otherwise,511    # it may cause LLVM version conflict when used together with other shared512    # libraries depending on LLVM. Notably, Mesa, who implements Vulkan513    # drivers on Linux, depends on the system libLLVM.so.514    target_link_libraries(mlir_vulkan_runtime515      PUBLIC516      ${Vulkan_LIBRARY}517    )518  endif()519endif()520