Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TPP-MLIR as out-of-tree dependency #142

Merged
merged 13 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
43 changes: 43 additions & 0 deletions cmake/tpp-mlir.cmake
Original file line number Diff line number Diff line change
@@ -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
slyalin marked this conversation as resolved.
Show resolved Hide resolved
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()
16 changes: 16 additions & 0 deletions scripts/build_mlir.sh
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions scripts/build_tpp_mlir.sh
Original file line number Diff line number Diff line change
@@ -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 \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

-DLLVM_EXTERNAL_LIT=$CUSTOM_LLVM_ROOT/bin/llvm-lit \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

Comment on lines +8 to +9

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shellcheck (suggestion)] reported by reviewdog 🐶

Suggested change
-DMLIR_DIR=$CUSTOM_LLVM_ROOT/lib/cmake/mlir \
-DLLVM_EXTERNAL_LIT=$CUSTOM_LLVM_ROOT/bin/llvm-lit \
-DMLIR_DIR="$CUSTOM_LLVM_ROOT"/lib/cmake/mlir \
-DLLVM_EXTERNAL_LIT="$CUSTOM_LLVM_ROOT"/bin/llvm-lit \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

Comment on lines +8 to +9

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shellcheck (suggestion)] reported by reviewdog 🐶

Suggested change
-DMLIR_DIR=$CUSTOM_LLVM_ROOT/lib/cmake/mlir \
-DLLVM_EXTERNAL_LIT=$CUSTOM_LLVM_ROOT/bin/llvm-lit \
-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
22 changes: 5 additions & 17 deletions src/cmake/openvino.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})

slyalin marked this conversation as resolved.
Show resolved Hide resolved

if (TBBBIND_2_5_FOUND)
target_link_libraries(${TARGET_NAME} PRIVATE ${TBBBIND_2_5_IMPORTED_TARGETS})
Expand Down
3 changes: 3 additions & 0 deletions src/common/transformations/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 21 additions & 5 deletions src/common/transformations/src/transformations/mlir/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<mlir::xsmm::XsmmDialect>();
// registry.insert<mlir::check::CheckDialect>();
// registry.insert<mlir::perf::PerfDialect>();
#if TPP_MLIR
registry.insert<mlir::xsmm::XsmmDialect>();
registry.insert<mlir::check::CheckDialect>();
registry.insert<mlir::perf::PerfDialect>();
#endif

registerAllDialects(registry);
registerAllExtensions(registry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
slyalin marked this conversation as resolved.
Show resolved Hide resolved
#endif

namespace {

using namespace mlir;
Expand All @@ -64,9 +69,9 @@ void prepareMLIRKernelWithoutWrapper(mlir::OwningOpRef<mlir::ModuleOp>& 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
Expand Down
1 change: 1 addition & 0 deletions src/plugins/intel_npu/tools/compile_tool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR OV_COMPILER_IS_CLANG)
ov_add_compiler_flags(-Wno-missing-declarations)
endif()


#
# Install
#
Expand Down
Loading