|
| 1 | +# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 2 | +# See https://llvm.org/LICENSE.txt for license information. |
| 3 | +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 4 | +# Copyright (c) 2025. |
| 5 | + |
| 6 | +cmake_minimum_required(VERSION 3.29) |
| 7 | +project(eudsl-tile LANGUAGES CXX C) |
| 8 | + |
| 9 | +set(CMAKE_CXX_STANDARD 17) |
| 10 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 11 | +set(CMAKE_CXX_EXTENSIONS OFF) |
| 12 | + |
| 13 | +if(POLICY CMP0068) |
| 14 | + cmake_policy(SET CMP0068 NEW) |
| 15 | + set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON) |
| 16 | +endif() |
| 17 | + |
| 18 | +if(POLICY CMP0075) |
| 19 | + cmake_policy(SET CMP0075 NEW) |
| 20 | +endif() |
| 21 | + |
| 22 | +if(POLICY CMP0077) |
| 23 | + cmake_policy(SET CMP0077 NEW) |
| 24 | +endif() |
| 25 | + |
| 26 | +if(POLICY CMP0091) |
| 27 | + cmake_policy(SET CMP0091 NEW) |
| 28 | +endif() |
| 29 | + |
| 30 | +if(POLICY CMP0116) |
| 31 | + cmake_policy(SET CMP0116 NEW) |
| 32 | +endif() |
| 33 | + |
| 34 | +if(POLICY CMP0135) |
| 35 | + cmake_policy(SET CMP0116 OLD) |
| 36 | +endif() |
| 37 | + |
| 38 | +if(MSVC OR WIN32) |
| 39 | + add_compile_options( |
| 40 | + $<$<CONFIG:>:/MT> # ---------| |
| 41 | + $<$<CONFIG:Debug>:/MTd> # ---|-- Statically link the runtime libraries |
| 42 | + $<$<CONFIG:Release>:/MT> # --| |
| 43 | + ) |
| 44 | +endif() |
| 45 | + |
| 46 | +set(CMAKE_C_VISIBILITY_PRESET "hidden") |
| 47 | +set(CMAKE_CXX_VISIBILITY_PRESET "hidden") |
| 48 | +set(CMAKE_VISIBILITY_INLINES_HIDDEN ON) |
| 49 | + |
| 50 | +find_package(MLIR REQUIRED CONFIG) |
| 51 | + |
| 52 | +message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}") |
| 53 | +message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") |
| 54 | + |
| 55 | +set(MLIR_BINDINGS_PYTHON_NB_DOMAIN "eudsl_tile" CACHE STRING "") |
| 56 | +set(MLIR_PYTHON_PACKAGE_PREFIX "eudsl_tile" CACHE STRING "") |
| 57 | + |
| 58 | +set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/bin) |
| 59 | +set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/lib) |
| 60 | + |
| 61 | +list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}") |
| 62 | +list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") |
| 63 | +include(TableGen) |
| 64 | +include(AddLLVM) |
| 65 | +include(AddMLIR) |
| 66 | +include(AddMLIRPython) |
| 67 | +include(MLIRDetectPythonEnv) |
| 68 | +include(HandleLLVMOptions) |
| 69 | + |
| 70 | +include_directories(${LLVM_INCLUDE_DIRS}) |
| 71 | +include_directories(${MLIR_INCLUDE_DIRS}) |
| 72 | +link_directories(${LLVM_BUILD_LIBRARY_DIR}) |
| 73 | +add_definitions(${LLVM_DEFINITIONS}) |
| 74 | + |
| 75 | +add_compile_definitions("MLIR_PYTHON_PACKAGE_PREFIX=${MLIR_PYTHON_PACKAGE_PREFIX}.") |
| 76 | + |
| 77 | +mlir_configure_python_dev_packages() |
| 78 | + |
| 79 | +add_mlir_python_common_capi_library(EUDSLTilePythonCAPI |
| 80 | + INSTALL_COMPONENT EUDSLTilePythonModules |
| 81 | + INSTALL_DESTINATION eudsl_tile/_mlir_libs |
| 82 | + OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/eudsl_tile/_mlir_libs" |
| 83 | + RELATIVE_INSTALL_ROOT "../../../.." |
| 84 | + DECLARED_SOURCES |
| 85 | + # this needs to be here so that _mlir is linked against the CAPI |
| 86 | + MLIRPythonSources.Core |
| 87 | + # we register everything even though we don't use all the dialects |
| 88 | + # because currently RegisterEverything isn't factored (and probably won't ever be...) |
| 89 | + MLIRPythonExtension.RegisterEverything |
| 90 | +) |
| 91 | + |
| 92 | +# ############################################################################## |
| 93 | +# The fully assembled package of modules. This must come last. |
| 94 | +# ############################################################################## |
| 95 | + |
| 96 | +set(_declared_sources |
| 97 | + MLIRPythonExtension.RegisterEverything |
| 98 | + # not MLIRPythonExtension.Core, which doesn't depend on MLIRPythonSupport and etc. |
| 99 | + MLIRPythonSources.Core |
| 100 | + # other extensions |
| 101 | + MLIRPythonExtension.Dialects.GPU.Nanobind |
| 102 | + MLIRPythonExtension.Dialects.LLVM.Nanobind |
| 103 | + MLIRPythonExtension.Dialects.Linalg.Nanobind |
| 104 | + MLIRPythonExtension.Dialects.Transform.Nanobind |
| 105 | + MLIRPythonExtension.ExecutionEngine |
| 106 | + MLIRPythonExtension.GPUDialectPasses |
| 107 | + MLIRPythonExtension.LinalgPasses |
| 108 | + MLIRPythonExtension.TransformInterpreter |
| 109 | + # dialects |
| 110 | + MLIRPythonSources.Dialects.arith |
| 111 | + MLIRPythonSources.Dialects.bufferization |
| 112 | + MLIRPythonSources.Dialects.bufferization_transform |
| 113 | + MLIRPythonSources.Dialects.builtin |
| 114 | + MLIRPythonSources.Dialects.cf |
| 115 | + MLIRPythonSources.Dialects.func |
| 116 | + MLIRPythonSources.Dialects.gpu |
| 117 | + MLIRPythonSources.Dialects.gpu_transform |
| 118 | + MLIRPythonSources.Dialects.index |
| 119 | + MLIRPythonSources.Dialects.linalg |
| 120 | + MLIRPythonSources.Dialects.llvm |
| 121 | + MLIRPythonSources.Dialects.math |
| 122 | + MLIRPythonSources.Dialects.memref |
| 123 | + MLIRPythonSources.Dialects.memref_transform |
| 124 | + MLIRPythonSources.Dialects.scf |
| 125 | + MLIRPythonSources.Dialects.spirv |
| 126 | + MLIRPythonSources.Dialects.tensor |
| 127 | + MLIRPythonSources.Dialects.tensor_transform |
| 128 | + MLIRPythonSources.Dialects.transform |
| 129 | + MLIRPythonSources.Dialects.transform.extras |
| 130 | + MLIRPythonSources.Dialects.transform.interpreter |
| 131 | + MLIRPythonSources.Dialects.vector |
| 132 | + MLIRPythonSources.Dialects.vector_transform |
| 133 | + # other sources |
| 134 | + MLIRPythonSources.ExecutionEngine |
| 135 | +) |
| 136 | +if(NOT CMAKE_CROSSCOMPILING) |
| 137 | + list(APPEND _declared_sources MLIRPythonExtension.Core.type_stub_gen) |
| 138 | +endif() |
| 139 | + |
| 140 | +add_mlir_python_modules(EUDSLTilePythonModules |
| 141 | + ROOT_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/eudsl_tile" |
| 142 | + INSTALL_PREFIX "eudsl_tile" |
| 143 | + MLIR_BINDINGS_PYTHON_NB_DOMAIN ${MLIR_BINDINGS_PYTHON_NB_DOMAIN} |
| 144 | + DECLARED_SOURCES |
| 145 | + ${_declared_sources} |
| 146 | + COMMON_CAPI_LINK_LIBS |
| 147 | + EUDSLTilePythonCAPI |
| 148 | +) |
| 149 | + |
| 150 | +set(_runtimes |
| 151 | + mlir_async_runtime |
| 152 | + mlir_c_runner_utils |
| 153 | + mlir_float16_utils |
| 154 | + mlir_runner_utils |
| 155 | +) |
| 156 | + |
| 157 | +if (TARGET mlir_apfloat_wrappers) |
| 158 | + list(APPEND _runtimes mlir_apfloat_wrappers) |
| 159 | +endif() |
| 160 | + |
| 161 | +if (TARGET mlir_rocm_runtime) |
| 162 | + list(APPEND _runtimes mlir_rocm_runtime) |
| 163 | +endif() |
| 164 | + |
| 165 | +if (TARGET mlir_cuda_runtime) |
| 166 | + list(APPEND _runtimes mlir_cuda_runtime) |
| 167 | +endif() |
| 168 | + |
| 169 | +if (TARGET omp) |
| 170 | + list(APPEND _runtimes omp) |
| 171 | +endif() |
| 172 | + |
| 173 | +if (TARGET vulkan-runtime-wrappers) |
| 174 | + list(APPEND _runtimes vulkan-runtime-wrappers) |
| 175 | +endif() |
| 176 | + |
| 177 | +foreach(r ${_runtimes}) |
| 178 | + add_custom_command( |
| 179 | + TARGET EUDSLTilePythonModules |
| 180 | + PRE_BUILD |
| 181 | + COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${r}> |
| 182 | + ${CMAKE_CURRENT_BINARY_DIR}/eudsl_tile/_mlir_libs) |
| 183 | +endforeach() |
| 184 | + |
| 185 | +install( |
| 186 | + IMPORTED_RUNTIME_ARTIFACTS ${_runtimes} |
| 187 | + LIBRARY DESTINATION "eudsl_tile/_mlir_libs" |
| 188 | + COMPONENT EUDSLTilePythonModules |
| 189 | +) |
0 commit comments