Skip to content

Commit

Permalink
Static link all targets and tools (#949)
Browse files Browse the repository at this point in the history
We cannot mix static and dynamic linking when building targets. We 
need to manually enforce that all cmake targets are statically linked,
i.e. don't use target MLIR, the only exception being the SharedLibrary
target.
  • Loading branch information
nsmithtt authored Oct 22, 2024
1 parent 0142a5c commit 5267166
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 19 deletions.
1 change: 0 additions & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ if (TTMLIR_ENABLE_RUNTIME)
endif()

set(link_libs
MLIR
MLIRTTDialect
MLIRTTIRDialect
MLIRTTIRTransforms
Expand Down
3 changes: 2 additions & 1 deletion lib/Conversion/StableHLOToTTIR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ add_mlir_library(TTMLIRStableHLOToTTIR
TTMLIRConversionPassIncGen

LINK_LIBS PUBLIC
MLIR
MLIRIR
MLIRPass
)
3 changes: 2 additions & 1 deletion lib/Conversion/TTIRToTTMetal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ add_mlir_library(TTMLIRTTIRToTTMetal
TTMLIRConversionPassIncGen

LINK_LIBS PUBLIC
MLIR
MLIRIR
MLIRPass
)
3 changes: 2 additions & 1 deletion lib/Conversion/TTIRToTTNN/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ add_mlir_library(TTMLIRTTIRToTTNN
TTMLIRConversionPassIncGen

LINK_LIBS PUBLIC
MLIR
MLIRIR
MLIRPass
)
6 changes: 5 additions & 1 deletion lib/Conversion/TTKernelToEmitC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ add_mlir_library(TTMLIRTTKernelToEmitC
TTMLIRConversionPassIncGen

LINK_LIBS PUBLIC
MLIR
MLIRIR
MLIRPass
MLIRArithToEmitC
MLIREmitCDialect
MLIRTransformUtils
)
6 changes: 5 additions & 1 deletion lib/Conversion/TTNNToEmitC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ add_mlir_library(TTMLIRTTNNToEmitC
TTMLIRConversionPassIncGen

LINK_LIBS PUBLIC
MLIR
MLIRIR
MLIRPass
MLIRSCFToEmitC
MLIREmitCDialect
MLIRFuncTransforms
)
3 changes: 2 additions & 1 deletion lib/Conversion/TosaToTTIR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ add_mlir_library(TTMLIRTosaToTTIR
TTMLIRConversionPassIncGen

LINK_LIBS PUBLIC
MLIR
MLIRIR
MLIRPass
)
3 changes: 3 additions & 0 deletions lib/Dialect/TTNN/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ add_mlir_dialect_library(MLIRTTNNDialect

LINK_LIBS PUBLIC
TTMLIRTTNNUtils
MLIRSCFToEmitC
MLIRLinalgDialect
MLIRMLProgramDialect
)
4 changes: 2 additions & 2 deletions lib/RegisterAll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ void mlir::tt::registerAllDialects(mlir::DialectRegistry &registry) {
registry
.insert<mlir::tt::TTDialect, mlir::tt::ttir::TTIRDialect,
mlir::tt::ttnn::TTNNDialect, mlir::tt::ttmetal::TTMetalDialect,
mlir::tt::ttkernel::TTKernelDialect, mlir::arith::ArithDialect,
mlir::func::FuncDialect, mlir::ml_program::MLProgramDialect,
mlir::tt::ttkernel::TTKernelDialect, mlir::func::FuncDialect,
mlir::arith::ArithDialect, mlir::ml_program::MLProgramDialect,
mlir::tensor::TensorDialect, mlir::linalg::LinalgDialect,
mlir::scf::SCFDialect, mlir::cf::ControlFlowDialect,
mlir::tosa::TosaDialect, mlir::vector::VectorDialect,
Expand Down
3 changes: 2 additions & 1 deletion lib/Scheduler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ add_mlir_library(MLIRScheduler
${PROJECT_SOURCE_DIR}/include/ttmlir/Scheduler

LINK_LIBS PUBLIC
MLIR
MLIRIR
MLIRPass
)
2 changes: 2 additions & 0 deletions lib/Target/TTNN/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ add_mlir_translation_library(TTNNTargetFlatbuffer
MLIRTTIRDialect
MLIRTTDialect
MLIRTTKernelDialect
MLIRTTNNTransforms
TTMLIRTTNNToEmitC
)

target_include_directories(TTNNTargetFlatbuffer PUBLIC ${PROJECT_BINARY_DIR}/include/ttmlir/Target/Common)
3 changes: 2 additions & 1 deletion python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ add_compile_definitions("MLIR_PYTHON_PACKAGE_PREFIX=ttmlir.")

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(translation_libs GLOBAL PROPERTY MLIR_TRANSLATION_LIBS)

declare_mlir_python_sources(TTMLIRPythonSources)
Expand Down Expand Up @@ -80,8 +81,8 @@ declare_mlir_python_extension(TTMLIRPythonExtensions.Main
LLVMSupport
${dialect_libs}
${conversion_libs}
${extension_libs}
${translation_libs}
MLIR
TTMLIRStatic
)

Expand Down
7 changes: 5 additions & 2 deletions tools/ttmlir-opt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
set(LIBS ${dialect_libs} ${conversion_libs} MLIROptLib MLIRTargetCpp TTMLIRStatic)
add_llvm_executable(ttmlir-opt ttmlir-opt.cpp)
get_property(extension_libs GLOBAL PROPERTY MLIR_EXTENSION_LIBS)

set(LIBS ${dialect_libs} ${conversion_libs} ${extension_libs} MLIROptLib MLIRTargetCpp TTMLIRStatic)

add_llvm_executable(ttmlir-opt ttmlir-opt.cpp DISABLE_LLVM_LINK_LLVM_DYLIB)

llvm_update_compile_flags(ttmlir-opt)
target_link_libraries(ttmlir-opt PRIVATE ${LIBS})
Expand Down
19 changes: 13 additions & 6 deletions tools/ttmlir-translate/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
add_llvm_executable(ttmlir-translate ttmlir-translate.cpp)
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(translation_libs GLOBAL PROPERTY MLIR_TRANSLATION_LIBS)

add_llvm_executable(ttmlir-translate ttmlir-translate.cpp DISABLE_LLVM_LINK_LLVM_DYLIB)

llvm_update_compile_flags(ttmlir-translate)
target_link_libraries(ttmlir-translate PRIVATE
TTNNTargetFlatbuffer
TTMetalTargetFlatbuffer
MLIRTTNNTransforms
TTMLIRTTNNToEmitC
TTMLIRTTKernelToEmitC
${dialect_libs}
${conversion_libs}
${translation_libs}
${extension_libs}
MLIRIR
MLIRSupport
MLIRTranslateLib
)

mlir_check_link_libraries(ttmlir-translate)
Expand Down

0 comments on commit 5267166

Please sign in to comment.