mirror of https://github.com/llvm/torch-mlir
Core C++ code build fixup.
parent
94ddfa6e32
commit
5322c925e5
|
@ -36,31 +36,24 @@ macro(torch_mlir_add_llvm_external_project name identifier location)
|
|||
set(LLVM_EXTERNAL_PROJECTS ${LLVM_EXTERNAL_PROJECTS} CACHE STRING "" FORCE)
|
||||
endmacro()
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Project options
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
option(TORCH_MLIR_ENABLE_REFBACKEND "Enable reference backend" ON)
|
||||
if(TORCH_MLIR_ENABLE_REFBACKEND)
|
||||
add_definitions(-DTORCH_MLIR_ENABLE_REFBACKEND)
|
||||
endif()
|
||||
|
||||
option(TORCH_MLIR_ENABLE_STABLEHLO "Add stablehlo dialect" ON)
|
||||
if(TORCH_MLIR_ENABLE_STABLEHLO)
|
||||
add_definitions(-DTORCH_MLIR_ENABLE_STABLEHLO)
|
||||
endif()
|
||||
|
||||
option(TORCH_MLIR_ENABLE_JIT_IR_IMPORTER "Enables JIT IR Importer" ON)
|
||||
option(TORCH_MLIR_ENABLE_LTC "Enables LTC backend" OFF)
|
||||
option(TORCH_MLIR_ENABLE_ONLY_MLIR_PYTHON_BINDINGS "Build Torch dialect MLIR Python bindings but neither JIT IR Importer nor LTC backend" OFF)
|
||||
if(TORCH_MLIR_ENABLE_ONLY_MLIR_PYTHON_BINDINGS)
|
||||
set(TORCH_MLIR_ENABLE_JIT_IR_IMPORTER OFF)
|
||||
set(TORCH_MLIR_ENABLE_LTC OFF)
|
||||
endif()
|
||||
|
||||
if(TORCH_MLIR_ENABLE_LTC)
|
||||
set(ENV{TORCH_MLIR_ENABLE_LTC} 1)
|
||||
message(STATUS "LTC Backend build is enabled")
|
||||
else()
|
||||
set(ENV{TORCH_MLIR_ENABLE_LTC} 0)
|
||||
message(STATUS "LTC Backend build is disabled")
|
||||
endif()
|
||||
|
||||
torch_mlir_add_llvm_external_project(
|
||||
torch-mlir-dialects
|
||||
TORCH_MLIR_DIALECTS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/externals/llvm-external-projects/torch-mlir-dialects)
|
||||
# torch_mlir_add_llvm_external_project(
|
||||
# torch-mlir-dialects
|
||||
# TORCH_MLIR_DIALECTS
|
||||
# ${CMAKE_CURRENT_SOURCE_DIR}/externals/llvm-external-projects/torch-mlir-dialects)
|
||||
|
||||
option(TORCH_MLIR_OUT_OF_TREE_BUILD "Specifies an out of tree build" OFF)
|
||||
|
||||
|
@ -99,9 +92,9 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR TORCH_MLIR_OUT_OF_TREE_
|
|||
|
||||
# Don't try to compile the python extensions at the moment. We need
|
||||
# to import lots of dependencies from AddMLIRPython to make this work.
|
||||
set(MLIR_ENABLE_BINDINGS_PYTHON 1)
|
||||
set(MLIR_ENABLE_BINDINGS_PYTHON ON)
|
||||
|
||||
set(TORCH-MLIR_BUILT_STANDALONE 1)
|
||||
set(TORCH-MLIR_BUILT_STANDALONE ON)
|
||||
set(BACKEND_PACKAGE_STRING "LLVM ${LLVM_PACKAGE_VERSION}")
|
||||
add_subdirectory(externals/llvm-external-projects/torch-mlir-dialects)
|
||||
else()
|
||||
|
@ -181,10 +174,9 @@ if(MLIR_ENABLE_BINDINGS_PYTHON)
|
|||
if(NOT TORCH_MLIR_PYTHON_PACKAGES_DIR)
|
||||
set(TORCH_MLIR_PYTHON_PACKAGES_DIR "${CMAKE_CURRENT_BINARY_DIR}/python_packages")
|
||||
endif()
|
||||
add_dependencies(check-torch-mlir-all
|
||||
check-torch-mlir-python
|
||||
)
|
||||
add_subdirectory(python)
|
||||
#add_subdirectory(python)
|
||||
# TODO: Remove
|
||||
add_custom_target(TorchMLIRPythonModules)
|
||||
else()
|
||||
add_custom_target(TorchMLIRPythonModules)
|
||||
endif()
|
||||
|
|
|
@ -15,7 +15,13 @@
|
|||
namespace mlir {
|
||||
namespace torch {
|
||||
|
||||
// Registers all dialects that this project produces and any dependencies.
|
||||
void registerAllDialects(mlir::DialectRegistry ®istry);
|
||||
|
||||
// Registers dialects that may be needed to parse torch-mlir inputs and
|
||||
// test cases.
|
||||
void registerOptionalInputDialects(mlir::DialectRegistry ®istry);
|
||||
|
||||
void registerAllPasses();
|
||||
|
||||
} // namespace torch
|
||||
|
|
|
@ -9,8 +9,6 @@ add_mlir_public_c_api_library(TorchMLIRCAPI
|
|||
${PROJECT_SOURCE_DIR}/include/torch-mlir-c/
|
||||
|
||||
ENABLE_AGGREGATION
|
||||
LINK_COMPONENTS
|
||||
Core
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
MLIRIR
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
add_subdirectory(CAPI)
|
||||
add_subdirectory(Conversion)
|
||||
add_subdirectory(Dialect)
|
||||
add_subdirectory(RefBackend)
|
||||
|
||||
get_property(extension_libs GLOBAL PROPERTY MLIR_EXTENSION_LIBS)
|
||||
set(LinkedLibs
|
||||
MLIRComplexDialect
|
||||
MLIRFuncDialect
|
||||
MLIRFuncInlinerExtension
|
||||
MLIRIR
|
||||
MLIRMLProgramDialect
|
||||
MLIRMemRefDialect
|
||||
MLIRSCFDialect
|
||||
MLIRTensorDialect
|
||||
MLIRTosaDialect
|
||||
MLIRSupport
|
||||
${extension_libs}
|
||||
|
||||
TorchMLIRTorchPasses
|
||||
TorchMLIRTorchConversionDialect
|
||||
|
@ -20,15 +24,16 @@ set(LinkedLibs
|
|||
TorchMLIRTMTensorDialect
|
||||
|
||||
TorchMLIRConversionPasses
|
||||
TorchMLIRRefBackend
|
||||
)
|
||||
|
||||
if(TORCH_MLIR_ENABLE_REFBACKEND)
|
||||
add_subdirectory(RefBackend)
|
||||
list(APPEND LinkedLibs TorchMLIRRefBackend)
|
||||
endif()
|
||||
|
||||
add_mlir_library(TorchMLIRInitAll
|
||||
InitAll.cpp
|
||||
|
||||
LINK_COMPONENTS
|
||||
Core
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
${LinkedLibs}
|
||||
)
|
||||
|
|
|
@ -27,10 +27,6 @@ add_mlir_library(TorchMLIRConversionPasses
|
|||
DEPENDS
|
||||
TorchMLIRConversionPassIncGen
|
||||
|
||||
LINK_COMPONENTS
|
||||
Core
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
${linked_libs}
|
||||
#${torch_mlir_conversion_libs}
|
||||
)
|
||||
|
|
|
@ -7,9 +7,6 @@ add_mlir_conversion_library(TorchMLIRTorchConversionToMLProgram
|
|||
DEPENDS
|
||||
TorchMLIRConversionPassIncGen
|
||||
|
||||
LINK_COMPONENTS
|
||||
Core
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
MLIRIR
|
||||
MLIRLinalgDialect
|
||||
|
|
|
@ -7,9 +7,6 @@ add_mlir_conversion_library(TorchMLIRTorchToArith
|
|||
DEPENDS
|
||||
TorchMLIRConversionPassIncGen
|
||||
|
||||
LINK_COMPONENTS
|
||||
Core
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
MLIRIR
|
||||
MLIRPass
|
||||
|
|
|
@ -17,9 +17,6 @@ add_mlir_conversion_library(TorchMLIRTorchToLinalg
|
|||
DEPENDS
|
||||
TorchMLIRConversionPassIncGen
|
||||
|
||||
LINK_COMPONENTS
|
||||
Core
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
MLIRIR
|
||||
MLIRPass
|
||||
|
|
|
@ -7,9 +7,6 @@ add_mlir_conversion_library(TorchMLIRTorchToSCF
|
|||
DEPENDS
|
||||
TorchMLIRConversionPassIncGen
|
||||
|
||||
LINK_COMPONENTS
|
||||
Core
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
MLIRIR
|
||||
MLIRPass
|
||||
|
|
|
@ -14,9 +14,6 @@ add_mlir_conversion_library(TorchMLIRTorchToStablehlo
|
|||
DEPENDS
|
||||
TorchMLIRConversionPassIncGen
|
||||
|
||||
LINK_COMPONENTS
|
||||
Core
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
MLIRIR
|
||||
MLIRPass
|
||||
|
|
|
@ -7,9 +7,6 @@ TorchToTMTensor.cpp
|
|||
DEPENDS
|
||||
TorchMLIRConversionPassIncGen
|
||||
|
||||
LINK_COMPONENTS
|
||||
Core
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
MLIRIR
|
||||
MLIRPass
|
||||
|
|
|
@ -9,9 +9,6 @@ add_mlir_conversion_library(TorchMLIRTorchToTosa
|
|||
DEPENDS
|
||||
TorchMLIRConversionPassIncGen
|
||||
|
||||
LINK_COMPONENTS
|
||||
Core
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
MLIRIR
|
||||
MLIRPass
|
||||
|
|
|
@ -12,9 +12,6 @@ add_mlir_library(TorchMLIRTorchDialect
|
|||
MLIRTorchOpsIncGen
|
||||
MLIRTorchTypesIncGen
|
||||
|
||||
LINK_COMPONENTS
|
||||
Core
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
MLIRBytecodeOpInterface
|
||||
MLIRBytecodeReader
|
||||
|
|
|
@ -26,9 +26,6 @@ add_mlir_library(TorchMLIRTorchPasses
|
|||
DEPENDS
|
||||
TorchMLIRTorchPassIncGen
|
||||
|
||||
LINK_COMPONENTS
|
||||
Core
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
MLIRIR
|
||||
MLIRPass
|
||||
|
|
|
@ -9,9 +9,6 @@ add_mlir_dialect_library(TorchMLIRTorchConversionDialect
|
|||
MLIRTorchConversionOpsIncGen
|
||||
MLIRTorchTypesIncGen
|
||||
|
||||
LINK_COMPONENTS
|
||||
Core
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
MLIRIR
|
||||
MLIRSupport
|
||||
|
|
|
@ -39,9 +39,6 @@ add_mlir_library(TorchMLIRTorchConversionPasses
|
|||
DEPENDS
|
||||
TorchMLIRTorchConversionPassIncGen
|
||||
|
||||
LINK_COMPONENTS
|
||||
Core
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
${LinkedLibs}
|
||||
)
|
||||
|
|
|
@ -9,8 +9,15 @@
|
|||
|
||||
#include "torch-mlir/InitAll.h"
|
||||
|
||||
#include "mlir/Dialect/Complex/IR/Complex.h"
|
||||
#include "mlir/Dialect/Func/Extensions/InlinerExtension.h"
|
||||
#include "mlir/Dialect/Func/IR/FuncOps.h"
|
||||
#include "mlir/Dialect/Linalg/IR/Linalg.h"
|
||||
#include "mlir/Dialect/MLProgram/IR/MLProgram.h"
|
||||
#include "mlir/Dialect/MemRef/IR/MemRef.h"
|
||||
#include "mlir/Dialect/SCF/IR/SCF.h"
|
||||
#include "mlir/Dialect/Tensor/IR/Tensor.h"
|
||||
#include "mlir/Dialect/Tosa/IR/TosaOps.h"
|
||||
#include "mlir/IR/Dialect.h"
|
||||
#include "torch-mlir-dialects/Dialect/TMTensor/IR/TMTensorDialect.h"
|
||||
#include "torch-mlir-dialects/Dialect/TMTensor/Transforms/Passes.h"
|
||||
|
@ -29,11 +36,22 @@ void mlir::torch::registerAllDialects(mlir::DialectRegistry ®istry) {
|
|||
mlir::func::registerInlinerExtension(registry);
|
||||
}
|
||||
|
||||
// TODO: Break this up when backends are separated.
|
||||
void mlir::torch::registerOptionalInputDialects(
|
||||
mlir::DialectRegistry ®istry) {
|
||||
registry.insert<complex::ComplexDialect, linalg::LinalgDialect,
|
||||
memref::MemRefDialect, ml_program::MLProgramDialect,
|
||||
scf::SCFDialect, tensor::TensorDialect, tosa::TosaDialect>();
|
||||
}
|
||||
|
||||
void mlir::torch::registerAllPasses() {
|
||||
mlir::torch::registerTorchPasses();
|
||||
mlir::torch::registerTorchConversionPasses();
|
||||
|
||||
mlir::torch::registerConversionPasses();
|
||||
mlir::torch::RefBackend::registerRefBackendPasses();
|
||||
mlir::torch::TMTensor::registerPasses();
|
||||
|
||||
#ifdef TORCH_MLIR_ENABLE_REFBACKEND
|
||||
mlir::torch::RefBackend::registerRefBackendPasses();
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
llvm_canonicalize_cmake_booleans(
|
||||
MLIR_ENABLE_BINDINGS_PYTHON
|
||||
TORCH_MLIR_ENABLE_JIT_IR_IMPORTER
|
||||
TORCH_MLIR_ENABLE_REFBACKEND
|
||||
TORCH_MLIR_ENABLE_STABLEHLO
|
||||
)
|
||||
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
if not config.torch_mlir_enable_refbackend:
|
||||
config.unsupported = True
|
|
@ -5,6 +5,7 @@ import sys
|
|||
config.enable_bindings_python = @MLIR_ENABLE_BINDINGS_PYTHON@
|
||||
config.torch_mlir_obj_root = "@TORCH_MLIR_BINARY_DIR@"
|
||||
config.torch_mlir_python_packages_dir = "@TORCH_MLIR_PYTHON_PACKAGES_DIR@"
|
||||
config.torch_mlir_enable_refbackend = @TORCH_MLIR_ENABLE_REFBACKEND@
|
||||
config.host_os = "@HOST_OS@"
|
||||
config.llvm_src_root = "@LLVM_SOURCE_DIR@"
|
||||
config.llvm_obj_root = "@LLVM_BINARY_DIR@"
|
||||
|
@ -16,7 +17,6 @@ config.llvm_shlib_ext = "@SHLIBEXT@"
|
|||
config.llvm_exe_ext = "@EXEEXT@"
|
||||
config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@"
|
||||
config.python_executable = "@Python3_EXECUTABLE@"
|
||||
config.enable_jit_ir_importer = @TORCH_MLIR_ENABLE_JIT_IR_IMPORTER@
|
||||
config.enable_stablehlo = @TORCH_MLIR_ENABLE_STABLEHLO@
|
||||
|
||||
import lit.llvm
|
||||
|
|
|
@ -7,18 +7,18 @@ EXPORT TorchMLIRTargets
|
|||
RUNTIME DESTINATION ${LLVM_TOOLS_INSTALL_DIR}
|
||||
COMPONENT torch-mlir-lsp-server)
|
||||
|
||||
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
|
||||
get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
|
||||
get_property(extension_libs GLOBAL PROPERTY MLIR_EXTENSION_LIBS)
|
||||
# get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
|
||||
# get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
|
||||
# get_property(extension_libs GLOBAL PROPERTY MLIR_EXTENSION_LIBS)
|
||||
|
||||
target_link_libraries(torch-mlir-lsp-server PRIVATE
|
||||
MLIRLspServerLib
|
||||
TorchMLIRInitAll
|
||||
|
||||
# TODO: Remove these in favor of interface deps.
|
||||
${dialect_libs}
|
||||
${conversion_libs}
|
||||
${extension_libs}
|
||||
# # TODO: Remove these in favor of interface deps.
|
||||
# ${dialect_libs}
|
||||
# ${conversion_libs}
|
||||
# ${extension_libs}
|
||||
)
|
||||
|
||||
mlir_check_all_link_libraries(torch-mlir-lsp-server)
|
||||
|
|
|
@ -9,8 +9,6 @@
|
|||
|
||||
#include "mlir/IR/Dialect.h"
|
||||
#include "mlir/IR/MLIRContext.h"
|
||||
#include "mlir/InitAllDialects.h"
|
||||
#include "mlir/InitAllExtensions.h"
|
||||
#include "mlir/Tools/mlir-lsp-server/MlirLspServerMain.h"
|
||||
#include "torch-mlir/InitAll.h"
|
||||
|
||||
|
@ -18,8 +16,7 @@ using namespace mlir;
|
|||
|
||||
int main(int argc, char **argv) {
|
||||
DialectRegistry registry;
|
||||
registerAllDialects(registry);
|
||||
registerAllExtensions(registry);
|
||||
mlir::torch::registerAllDialects(registry);
|
||||
mlir::torch::registerOptionalInputDialects(registry);
|
||||
return failed(MlirLspServerMain(argc, argv, registry));
|
||||
}
|
||||
|
|
|
@ -5,10 +5,6 @@ EXPORT TorchMLIRTargets
|
|||
RUNTIME DESTINATION ${LLVM_TOOLS_INSTALL_DIR}
|
||||
COMPONENT torch-mlir-opt)
|
||||
|
||||
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
|
||||
get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
|
||||
get_property(extension_libs GLOBAL PROPERTY MLIR_EXTENSION_LIBS)
|
||||
|
||||
set(dependency_libraries)
|
||||
if(TORCH_MLIR_ENABLE_STABLEHLO)
|
||||
list(APPEND dependency_libraries StablehloRegister)
|
||||
|
@ -16,11 +12,9 @@ endif()
|
|||
|
||||
target_link_libraries(torch-mlir-opt PRIVATE
|
||||
MLIROptLib
|
||||
MLIRTransforms
|
||||
TorchMLIRInitAll
|
||||
TorchMLIRTorchDialect
|
||||
TorchMLIRTorchPasses
|
||||
${dialect_libs}
|
||||
${conversion_libs}
|
||||
${extension_libs}
|
||||
${dependency_libraries}
|
||||
)
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "mlir/InitAllDialects.h"
|
||||
#include "mlir/InitAllExtensions.h"
|
||||
#include "mlir/InitAllPasses.h"
|
||||
#include "mlir/Dialect/SCF/IR/SCF.h"
|
||||
#include "mlir/Dialect/Tensor/IR/Tensor.h"
|
||||
#include "mlir/Tools/mlir-opt/MlirOptMain.h"
|
||||
#include "mlir/Transforms/Passes.h"
|
||||
#include "torch-mlir/InitAll.h"
|
||||
|
||||
#ifdef TORCH_MLIR_ENABLE_STABLEHLO
|
||||
|
@ -20,14 +20,23 @@
|
|||
using namespace mlir;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
registerAllPasses();
|
||||
mlir::torch::registerAllPasses();
|
||||
|
||||
// Core Transforms
|
||||
registerCanonicalizerPass();
|
||||
registerCSEPass();
|
||||
registerInlinerPass();
|
||||
registerLocationSnapshotPass();
|
||||
registerLoopInvariantCodeMotionPass();
|
||||
registerPrintOpStatsPass();
|
||||
registerViewOpGraphPass();
|
||||
registerStripDebugInfoPass();
|
||||
registerSymbolDCEPass();
|
||||
|
||||
DialectRegistry registry;
|
||||
registerAllDialects(registry);
|
||||
registerAllExtensions(registry);
|
||||
mlir::torch::registerAllDialects(registry);
|
||||
|
||||
mlir::torch::registerOptionalInputDialects(registry);
|
||||
|
||||
#ifdef TORCH_MLIR_ENABLE_STABLEHLO
|
||||
mlir::stablehlo::registerAllDialects(registry);
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue