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

GC-GPU integration #169

Merged
merged 21 commits into from
Oct 15, 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
15 changes: 12 additions & 3 deletions cmake/graph-compiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ if (NOT DEFINED GRAPH_COMPILER_LIBS)
# versions, using find_package() first. If the package is not found, then using FetchContent.
if (CMAKE_VERSION VERSION_LESS "3.24")
find_package(GraphCompiler QUIET)
else ()
set(GC_FETCH_CONTENT_ARGS FIND_PACKAGE_ARGS NAMES GraphCompiler)
dchigarev marked this conversation as resolved.
Show resolved Hide resolved
endif ()

if (NOT GraphCompiler_FOUND)
Expand All @@ -13,12 +15,13 @@ if (NOT DEFINED GRAPH_COMPILER_LIBS)
GC
GIT_REPOSITORY https://github.com/intel/graph-compiler.git
GIT_TAG main
FIND_PACKAGE_ARGS NAMES GraphCompiler
${GC_FETCH_CONTENT_ARGS}
)

set(GC_ENABLE_OPT OFF)
set(GC_ENABLE_IMEX ${ENABLE_INTEL_GPU})
set(GC_ENABLE_TOOLS OFF)
set(GC_ENABLE_TEST OFF)
set(GC_ENABLE_DNNL OFF)
set(GC_ENABLE_DNNL_API OFF)
set(GC_ENABLE_LEGACY OFF)
set(GC_ENABLE_BINDINGS_PYTHON OFF)
set(OV_BUILD_SHARED_LIBS_TMP ${BUILD_SHARED_LIBS})
Expand All @@ -32,7 +35,13 @@ if (NOT DEFINED GRAPH_COMPILER_LIBS)
GcJitWrapper
GcCpuRuntime
)

if (ENABLE_INTEL_GPU)
list(APPEND GRAPH_COMPILER_LIBS GcGpuOclRuntime)
endif()

set_property(GLOBAL PROPERTY GRAPH_COMPILER_LIBS ${GRAPH_COMPILER_LIBS})
endif ()

get_target_property(GRAPH_COMPILER_INCLUDES GcInterface INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(GRAPH_COMPILER_COMPILE_OPTIONS GcInterface INTERFACE_COMPILE_OPTIONS)
1 change: 1 addition & 0 deletions src/common/transformations/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ target_include_directories(${TARGET_NAME}_obj PRIVATE "${PUBLIC_HEADERS_DIR}"
"${LLVM_INCLUDE_DIRS}"
"${GRAPH_COMPILER_INCLUDES}")

target_compile_options(${TARGET_NAME}_obj PUBLIC ${GRAPH_COMPILER_COMPILE_OPTIONS})
add_tpp_mlir_includes(${TARGET_NAME}_obj)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ namespace ov {

namespace pass {

void TRANSFORMATIONS_API transformMLIR(std::shared_ptr<ov::Model> model);
void TRANSFORMATIONS_API transformMLIR(std::shared_ptr<ov::Model> model,
std::shared_ptr<ov::EvaluationContext> loweringContext);
Copy link
Author

Choose a reason for hiding this comment

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

loweringContext stores ocl_context for mlir_op::gpu


}
}
41 changes: 31 additions & 10 deletions src/common/transformations/src/transformations/mlir/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ mlir::OwningOpRef<mlir::ModuleOp> ngraph_to_mlir(MLIRContext* context,


// This pass converts a group of nodes into a single MLIROp
NodePtr ngraph_to_mlir_op(MLIRContext* context, SubgraphPtr subgraph, MlirMode mode) {
NodePtr ngraph_to_mlir_op(MLIRContext* context,
SubgraphPtr subgraph,
MlirMode mode,
std::shared_ptr<ov::EvaluationContext> loweringContext) {
mlir::OwningOpRef<mlir::ModuleOp> module = ngraph_to_mlir(context, subgraph->inputs, subgraph->nodes, subgraph->outputs);

const auto& inputs = subgraph->inputs;
Expand Down Expand Up @@ -247,7 +250,7 @@ NodePtr ngraph_to_mlir_op(MLIRContext* context, SubgraphPtr subgraph, MlirMode m
}
return std::make_shared<MLIROp>(
subgraph->inputs,
std::make_shared<MLIREvaluate>(std::move(module), mode),
MLIREvaluate::create(std::move(module), mode, loweringContext),
output_types,
output_map
);
Expand All @@ -269,17 +272,19 @@ void replace_subgraph(SubgraphPtr subgraph, NodePtr node) {
class Partitioner : public ov::pass::ModelPass {
MLIRContext* context;
MlirMode mode;
std::shared_ptr<ov::EvaluationContext> loweringContext;
public:
OPENVINO_RTTI("Partitioner");

Partitioner(MLIRContext* context, MlirMode mode) :
Partitioner(MLIRContext* context, MlirMode mode, std::shared_ptr<ov::EvaluationContext> loweringContext) :
context(context),
mode(mode)
mode(mode),
loweringContext(loweringContext)
{}

bool run_on_model(const std::shared_ptr<ov::Model>& model) override {
SubgraphTracker tracker([this](SubgraphPtr subgraph) {
auto mlir_op = ngraph_to_mlir_op(context, subgraph, mode);
auto mlir_op = ngraph_to_mlir_op(context, subgraph, mode, loweringContext);
replace_subgraph(subgraph, mlir_op);
OPENVINO_MLIR_DEBUG_PRINT("Created MLIR op: " << mlir_op << "\n");
}
Expand All @@ -293,7 +298,10 @@ class Partitioner : public ov::pass::ModelPass {
};


void injectMLIR(std::shared_ptr<ov::Model> model, MLIRContext* context, MlirMode mode) {
void injectMLIR(std::shared_ptr<ov::Model> model,
MLIRContext* context,
MlirMode mode,
std::shared_ptr<ov::EvaluationContext> loweringContext) {
ov::pass::Manager manager;
using namespace ov::op;
manager.set_per_pass_validation(false);
Expand All @@ -304,7 +312,7 @@ void injectMLIR(std::shared_ptr<ov::Model> model, MLIRContext* context, MlirMode
manager.register_pass<BinaryEltwisePattern<v1::Divide, linalg::DivOp>>();
manager.register_pass<ReluPattern>();
manager.register_pass<MatMulPattern>();
manager.register_pass<Partitioner>(context, mode);
manager.register_pass<Partitioner>(context, mode, loweringContext);
manager.run_passes(model);
model->validate_nodes_and_infer_types();
}
Expand Down Expand Up @@ -335,7 +343,7 @@ MLIRContext* get_shared_mlir_context(MlirMode mode) {
}

#ifdef GRAPH_COMPILER
if (mode == MLIR_MODE_GC) {
if (mode == MLIR_MODE_GC || mode == MLIR_MODE_GC_GPU) {
OPENVINO_MLIR_DEBUG_PRINT("GC\n");
context = std::make_shared<MLIRContext>(gc::initCompilerAndGetDialects());
} else {
Expand Down Expand Up @@ -386,7 +394,8 @@ MLIRContext* get_shared_mlir_context(MlirMode mode) {

} // namespace

void ov::pass::transformMLIR(std::shared_ptr<ov::Model> model) {
void ov::pass::transformMLIR(std::shared_ptr<ov::Model> model,
std::shared_ptr<ov::EvaluationContext> loweringContext) {
if(util::getenv_bool("OV_MLIR", true)) {
const char *default_mode =
#ifdef TPP_MLIR
Expand Down Expand Up @@ -421,11 +430,23 @@ void ov::pass::transformMLIR(std::shared_ptr<ov::Model> model) {
"but OV_MLIR_MODE environment variable is set to GC.");
#endif
mode = MLIR_MODE_GC;
} else if (mode_str == "GC_GPU") {
#ifndef GRAPH_COMPILER
OPENVINO_THROW(
"[ ERROR ] OpenVINO wasn't compiled with GRAPH_COMPILER support, "
"but OV_MLIR_MODE environment variable is set to GC_GPU.");
#endif
#ifndef GC_USE_IMEX // GC_GPU requires IMEX support
OPENVINO_THROW(
"[ ERROR ] GraphCompiler wasn't compiled with IMEX support (-DGC_ENABLE_IMEX), "
"but OV_MLIR_MODE environment variable is set to GC_GPU.");
#endif
mode = MLIR_MODE_GC_GPU;
} else {
OPENVINO_ASSERT(mode_str == "DEFAULT");
mode = MLIR_MODE_DEFAULT;
}

injectMLIR(model, get_shared_mlir_context(mode), mode);
injectMLIR(model, get_shared_mlir_context(mode), mode, loweringContext);
}
}
Loading
Loading