diff --git a/CMakeLists.txt b/CMakeLists.txt index 494a3e4ce21d61..9935a6e7aa17e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -138,6 +138,15 @@ function(ov_developer_package_export_targets) "A list of OpenVINO Developer Package exported targets" FORCE) endfunction() + +# +# TPP-MLIR +# + +# enables tpp-mlir for temporary MLIR lowering CPU pipeline +# FIXME: Move to all-upsteram lowering into XSMM/DNN/MKL +include(cmake/tpp-mlir.cmake) + # # Build # diff --git a/cmake/tpp-mlir.cmake b/cmake/tpp-mlir.cmake new file mode 100644 index 00000000000000..444ba7b546a84c --- /dev/null +++ b/cmake/tpp-mlir.cmake @@ -0,0 +1,43 @@ +# If TPP-MLIR is in library path, add it to the dependencies +# This should be the build directory, not the source or the 'lib' +# FIXME: Make this an actual CMake discovery +if (TPP_MLIR_DIR) + message(STATUS "TPP-MLIR at ${TPP_MLIR_DIR}") + add_compile_definitions(TPP_MLIR) + set(TPP_MLIR_LIBS + # Keep the next two libs at the top of the list to avoid undefined references at link time + TPPPipeline + TPPPassBundles + TPPCheckDialect + TPPCheckToLoops + TPPGPU + TPPIR + TPPLinalgToFunc + TPPLinalgToXSMM + TPPPerfDialect + TPPPerfToFunc + TPPPerfToLoop + TPPRunner + TPPTestLib + TPPTransforms + TPPTransformsUtils + TPPXsmmDialect + TPPXsmmToFunc + xsmm + tpp_xsmm_runner_utils + ) + function(add_tpp_mlir_includes target) + target_include_directories(${target} PRIVATE ${TPP_MLIR_DIR}/../include ${TPP_MLIR_DIR}/include) + endfunction() + function(add_tpp_mlir_libs target) + target_link_directories(${target} PRIVATE ${TPP_MLIR_DIR}/lib) + target_link_libraries(${target} PRIVATE ${TPP_MLIR_LIBS}) + endfunction() +else() + function(add_tpp_mlir_includes target) + message(DEBUG "TPP-MLIR not enabled, skipping ${target}") + endfunction() + function(add_tpp_mlir_libs target) + message(DEBUG "TPP-MLIR not enabled, skipping ${target}") + endfunction() +endif() diff --git a/scripts/build_mlir.sh b/scripts/build_mlir.sh new file mode 100755 index 00000000000000..4315efd0ca3758 --- /dev/null +++ b/scripts/build_mlir.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# Run it in llvm-project/build directory + +cmake -G Ninja ../llvm \ + -DLLVM_ENABLE_PROJECTS="mlir" \ + -DLLVM_BUILD_EXAMPLES=ON \ + -DLLVM_INSTALL_UTILS=ON \ + -DLLVM_TARGETS_TO_BUILD="host" \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DLLVM_ENABLE_ASSERTIONS=ON \ + -DCMAKE_C_COMPILER=clang \ + -DCMAKE_CXX_COMPILER=clang++ \ + -DLLVM_USE_LINKER=lld + +ninja \ No newline at end of file diff --git a/scripts/build_tpp_mlir.sh b/scripts/build_tpp_mlir.sh new file mode 100755 index 00000000000000..52e5d6b05d1181 --- /dev/null +++ b/scripts/build_tpp_mlir.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# Run it in tpp-mlir/build subdirectory +# Set CUSTOM_LLVM_ROOT to llvm-project/build directory + +cmake -G Ninja .. \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DMLIR_DIR=$CUSTOM_LLVM_ROOT/lib/cmake/mlir \ + -DLLVM_EXTERNAL_LIT=$CUSTOM_LLVM_ROOT/bin/llvm-lit \ + -DCMAKE_C_COMPILER=clang \ + -DCMAKE_CXX_COMPILER=clang++ \ + -DLLVM_USE_LINKER=lld + +cmake --build . --target check-tpp \ No newline at end of file diff --git a/src/cmake/openvino.cmake b/src/cmake/openvino.cmake index 7ce80dd063a0dc..d9b9067a2f7134 100644 --- a/src/cmake/openvino.cmake +++ b/src/cmake/openvino.cmake @@ -41,29 +41,17 @@ target_include_directories(${TARGET_NAME} PUBLIC find_package(MLIR REQUIRED CONFIG) -set(MLIR_OPENVINO_LIBS - MLIRAnalysis - MLIRExecutionEngine - MLIRIR - MLIRJitRunner - MLIRLLVMDialect - MLIRLLVMToLLVMIRTranslation - MLIRToLLVMIRTranslationRegistration - MLIRParser - MLIRTargetLLVMIRExport - MLIRSupport - MLIROptLib - LLVMX86AsmParser - MLIRFuncDialect - MLIRFuncAllExtensions - MLIRUBToLLVM) +get_property(MLIR_ALL_LIBS GLOBAL PROPERTY MLIR_ALL_LIBS) target_link_libraries(${TARGET_NAME} PRIVATE openvino::reference openvino::shape_inference openvino::pugixml ${CMAKE_DL_LIBS} Threads::Threads - ${MLIR_OPENVINO_LIBS}) + ${MLIR_ALL_LIBS}) + +add_tpp_mlir_libs(${TARGET_NAME}) + if (TBBBIND_2_5_FOUND) target_link_libraries(${TARGET_NAME} PRIVATE ${TBBBIND_2_5_IMPORTED_TARGETS}) diff --git a/src/common/transformations/CMakeLists.txt b/src/common/transformations/CMakeLists.txt index 1b40dc534b9db2..d6cb265c0a04b6 100644 --- a/src/common/transformations/CMakeLists.txt +++ b/src/common/transformations/CMakeLists.txt @@ -39,6 +39,9 @@ target_include_directories(${TARGET_NAME}_obj PRIVATE "${PUBLIC_HEADERS_DIR}" "${MLIR_INCLUDE_DIRS}" "${LLVM_INCLUDE_DIRS}") +add_tpp_mlir_includes(${TARGET_NAME}_obj) + + ov_add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME}_obj) ov_mark_target_as_cc(${TARGET_NAME}_obj) diff --git a/src/common/transformations/src/transformations/mlir/convert.cpp b/src/common/transformations/src/transformations/mlir/convert.cpp index a755b033cb6264..af3f7ca1cac227 100644 --- a/src/common/transformations/src/transformations/mlir/convert.cpp +++ b/src/common/transformations/src/transformations/mlir/convert.cpp @@ -57,6 +57,14 @@ #include "mlir/Target/LLVMIR/Dialect/All.h" #include "mlir/Target/LLVMIR/Export.h" #include "mlir/Target/LLVMIR/ModuleTranslation.h" + +#ifdef TPP_MLIR // If TPP is available +#include "TPP/Dialect/Check/CheckDialect.h" +#include "TPP/Dialect/Perf/PerfDialect.h" +#include "TPP/Dialect/Xsmm/XsmmDialect.h" +#include "TPP/GPU/Utils.h" +#endif + #include "mlir_op.hpp" #include "op/matmul.hpp" #include "op/relu.hpp" @@ -302,16 +310,24 @@ MLIRContext* get_shared_mlir_context() { llvm::InitializeNativeTarget(); llvm::InitializeNativeTargetAsmPrinter(); - // Initialize GPU-related LLVM machinery - // tpp::initializeGpuTargets(); + std::cerr << "[ DEBUG ] Using TPP_MLIR: "; + #if TPP_MLIR + // Initialize GPU-related LLVM machinery + tpp::initializeGpuTargets(); + std::cerr << "YES\n"; + #else + std::cerr << "NO\n"; + #endif // Add the following to include *all* MLIR Core dialects, or selectively // include what you need like above. You only need to register dialects that // will be *parsed* by the tool, not the one generated DialectRegistry registry; - // registry.insert(); - // registry.insert(); - // registry.insert(); + #if TPP_MLIR + registry.insert(); + registry.insert(); + registry.insert(); + #endif registerAllDialects(registry); registerAllExtensions(registry); diff --git a/src/common/transformations/src/transformations/mlir/mlir_op.cpp b/src/common/transformations/src/transformations/mlir/mlir_op.cpp index 51a7a8598f7c88..eea1019f60db91 100644 --- a/src/common/transformations/src/transformations/mlir/mlir_op.cpp +++ b/src/common/transformations/src/transformations/mlir/mlir_op.cpp @@ -53,6 +53,11 @@ #include "mlir/Target/LLVMIR/Export.h" #include "mlir/Target/LLVMIR/ModuleTranslation.h" +#ifdef TPP_MLIR // If TPP is available +#include "TPP/PassBundles.h" +#include "TPP/Passes.h" +#endif + namespace { using namespace mlir; @@ -64,9 +69,9 @@ void prepareMLIRKernelWithoutWrapper(mlir::OwningOpRef& module) // A set of default passes that lower any input IR to LLVM PassManager pm(module->getContext()); -#if 0 // TODO: if TPP is available +#if TPP_MLIR - tpp::DefaultPipelineOptions defPipelineOpts{defGpuBackend}; + tpp::DefaultPipelineOptions defPipelineOpts; pm.addPass(tpp::createDefaultPipeline(defPipelineOpts)); #else // Simplified default lowering to LLVM from LLVM tests diff --git a/src/plugins/intel_npu/tools/compile_tool/CMakeLists.txt b/src/plugins/intel_npu/tools/compile_tool/CMakeLists.txt index 9d1e1d38b48188..bf66ef41d1a237 100644 --- a/src/plugins/intel_npu/tools/compile_tool/CMakeLists.txt +++ b/src/plugins/intel_npu/tools/compile_tool/CMakeLists.txt @@ -39,6 +39,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR OV_COMPILER_IS_CLANG) ov_add_compiler_flags(-Wno-missing-declarations) endif() + # # Install #