-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[GPU][MLIR] MLIR Graph compiler integration #35336
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
base: master
Are you sure you want to change the base?
Changes from 130 commits
fbd17fb
f6555b9
2d1955b
6f554c9
560a659
08e601d
e30e919
754e385
b5370bd
1e1d807
a4dbd98
6f038fc
ff4d018
863f139
d44f7c9
c72dc8a
3707523
3e1871b
f8bbb6a
e6241fd
ea8e4a3
acbd925
df9b3e0
1f9a555
80dd502
77f5ea3
e93f1a6
aa86cfb
ee1d2b4
21c61af
966634e
acedae2
0988860
da56c3c
34b7817
a48c9f1
fc319c4
0b3feca
932ed83
a7fe844
cc4d614
af561ef
b05ab45
27ae57d
0f05a42
1f39cba
01f7f22
cafa32d
8d3267d
5b3b9b1
38e0a79
d983076
6b8e115
89f6242
d1ebc65
92e9bbb
27f8b35
57845f3
98ae86d
058ee2a
992694e
cb252b1
d305154
79935c3
51ede59
c457001
9b1a407
7addf0f
c83e1b5
7f9c511
747c5df
d15d7b9
e94b479
8cd1c89
050230c
e1c4464
d7ee462
0ccc31d
a7069d0
1fa75d8
e7de9c5
6980e12
5c03ce5
3ffdd72
eec19f7
c2de20b
f322e7c
32c9ee5
a338296
cede3e3
94903a4
93fa790
0685a31
51b598a
5ad5590
f70d938
03c0a8a
802f390
d93ef3d
5e7ba78
6f8aceb
3b48113
723fc65
8d27aa4
172569b
4235cd4
cb11e23
a296719
a87821c
151ac18
091b97b
33cc8e9
3d7e337
108c3ae
cd9c2ae
e90607f
462dad2
35032f1
9f93c4f
d7c52a1
f0ef4c6
cb19ebd
5a49854
2336f5e
d8b9b32
585ff3d
c27479d
cb92724
d4ec2b3
e4b3cc5
b94dc3f
c565fff
f55a50d
a53e9e5
07761bb
1dc5942
1c9c6eb
e03250c
cbf4429
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| pr-37010 | ||
| pr-35336 |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| name: Graph Compiler GPU Backend | ||
|
|
||
| on: | ||
| push: | ||
| pull_request: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| env: | ||
| GC_REPO: https://x-access-token:${{ secrets.GC_TOKEN }}@github.com/intel-sandbox/graph-compiler | ||
| GC_TAG: main | ||
| BUILD_DIR: ${{ github.workspace }}-gc-build | ||
| OUTPUT_DIR: ${{ github.workspace }}-gc-bin | ||
|
|
||
| jobs: | ||
| ci: | ||
| runs-on: ${{ vars.RUNNER }} | ||
|
|
||
|
Comment on lines
+3
to
+19
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This workflow is only used in our internal OV-fork's CI. It's not launched in the main ov-repo and will be removed just before the merge |
||
| steps: | ||
| - uses: actions/checkout@v7 | ||
| with: | ||
| submodules: recursive | ||
|
|
||
| - name: Build | ||
| run: | | ||
| mkdir -p $BUILD_DIR | ||
| run_build() { | ||
| [ "$1" = '-c' ] && rm -rf $BUILD_DIR | ||
| mkdir -p $BUILD_DIR | ||
| cmake -G Ninja -S "$GITHUB_WORKSPACE" -B "$BUILD_DIR" \ | ||
| -DOUTPUT_ROOT="$OUTPUT_DIR" \ | ||
| -DGRAPH_COMPILER_REPO="$GC_REPO" \ | ||
| -DGRAPH_COMPILER_TAG="$GC_TAG" \ | ||
| -DENABLE_INTEL_GPU=ON \ | ||
| -DENABLE_GRAPH_COMPILER=ON \ | ||
| -DENABLE_TESTS=ON \ | ||
| -DENABLE_ONEDNN_FOR_GPU=OFF \ | ||
| -DENABLE_INTEL_CPU=OFF \ | ||
| -DENABLE_INTEL_NPU=OFF \ | ||
| -DCMAKE_CXX_FLAGS="-DOV_GPU_OPENCL_HPP_HAS_UUID -DOV_GPU_OPENCL_HPP_HAS_BUS_INFO" \ | ||
| -DOpenCL_HPP_INCLUDE_DIR="$GITHUB_WORKSPACE/thirdparty/ocl/clhpp_headers/include" \ | ||
| -DOpenCL_HPP="$GITHUB_WORKSPACE/thirdparty/ocl/clhpp_headers/include/CL/opencl.hpp" | ||
| cmake --build "$BUILD_DIR" --parallel | ||
| } | ||
|
|
||
| if [ -d "$BUILD_DIR" ]; then | ||
| # Reuse build artifacts from previous build. If the build fails, clean and rebuild. | ||
| run_build || run_build -c | ||
| else | ||
| run_build | ||
| fi | ||
|
|
||
| - name: Test | ||
| run: | | ||
| # These tests require MLIR patches: | ||
| # https://github.com/llvm/llvm-project/pull/208932 | ||
| # https://github.com/llvm/llvm-project/pull/197281 | ||
| exclude='.*ScaledAttnLayerGPUMlirTest.CompareWithRefs.*|mlir_Transpose.*|mlir_ReshapeAndTranspose.*' | ||
|
|
||
| export OV_GPU_ENABLE_MLIR=1 | ||
| export OV_GPU_QUEUE_TYPE=out-of-order | ||
| func_tests="$OUTPUT_DIR/bin/intel64/Release/ov_gpu_func_tests" | ||
| filter=$(printf '%s:' \ | ||
| 'MLIRExecution.SimpleMatmulf16' \ | ||
| 'MLIRExecution.SDPABasic' \ | ||
| '*ScaledAttnLayerGPUMlirTest*' \ | ||
| 'mlir_*' \ | ||
| ) | ||
| tests=$("$func_tests" --gtest_list_tests --gtest_filter="${filter%:}" \ | ||
| | awk -v exclude="$exclude" '/^ /{print suite $1} /^[^ ]/{suite=$1}' \ | ||
| | grep -v -E "$exclude") | ||
| start=$SECONDS | ||
| echo "$tests" | xargs -P 32 -I{} "$func_tests" --gtest_filter='{}' | ||
| echo "Run $(echo "$tests" | wc -l) tests in $((SECONDS - start))s" | ||
|
|
||
| OV_MLIR_PATTERNS='mart=MatMul,Add,Reshape,Transpose;rms=Power,ReduceMean,Add,Sqrt,Divide' \ | ||
| OV_MLIR_DEBUG=1 "$func_tests" --gtest_filter=mlir_MatMulRmsnormConcatTest* 2>&1 \ | ||
| | grep -E 'func.func @(mart|rms)' | wc -l | xargs test 4 -eq || { echo "MLIR patterns test failed" && exit 1; } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,14 +31,15 @@ endif() | |
| # [SOURCES <sources>] | ||
| # [OBJECT_LIBRARIES <object_libs>] | ||
| # [VERSION_DEFINES_FOR <source>] | ||
| # [LINKABLE] Build as a shared library so tests can link it | ||
| # [SKIP_INSTALL] | ||
| # [SKIP_REGISTRATION] Skip creation of <device>.xml | ||
| # [ADD_CLANG_FORMAT] | ||
| # [ADD_CLANG_TIDY] | ||
| # ) | ||
| # | ||
| function(ov_add_plugin) | ||
| set(options SKIP_INSTALL PSEUDO_DEVICE ADD_CLANG_FORMAT ADD_CLANG_TIDY AS_EXTENSION SKIP_REGISTRATION) | ||
| set(options SKIP_INSTALL PSEUDO_DEVICE ADD_CLANG_FORMAT ADD_CLANG_TIDY AS_EXTENSION SKIP_REGISTRATION LINKABLE) | ||
| set(oneValueArgs NAME DEVICE_NAME VERSION_DEFINES_FOR PSEUDO_PLUGIN_FOR) | ||
| set(multiValueArgs DEFAULT_CONFIG SOURCES OBJECT_LIBRARIES) | ||
| cmake_parse_arguments(OV_PLUGIN "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | ||
|
|
@@ -60,7 +61,11 @@ function(ov_add_plugin) | |
| endforeach() | ||
|
|
||
| if(BUILD_SHARED_LIBS) | ||
| set(library_type MODULE) | ||
| if(OV_PLUGIN_LINKABLE) | ||
| set(library_type SHARED) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MLIR GPU unit tests require LLVM/MLIR runtime and link the plugin directly. |
||
| else() | ||
| set(library_type MODULE) | ||
| endif() | ||
| else() | ||
| set(library_type STATIC) | ||
| endif() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| include_guard() | ||
| include("${CMAKE_CURRENT_LIST_DIR}/llvm.cmake") | ||
|
|
||
| find_package(GraphCompiler QUIET CONFIG) | ||
|
|
||
| if (NOT GraphCompiler_FOUND) | ||
| option(GRAPH_COMPILER_DYLINK "Use dynamic linking with GraphCompiler" OFF) | ||
| set(GRAPH_COMPILER_REPO "https://github.com/dchigarev/graph-compiler" CACHE STRING "GraphCompiler repository URL") | ||
| set(GRAPH_COMPILER_TAG "ov_pin/0.1.0" CACHE STRING "GraphCompiler git tag/branch") | ||
| message(STATUS "GraphCompiler not found, fetching from: ${GRAPH_COMPILER_REPO}") | ||
| include(FetchContent) | ||
| FetchContent_Declare( | ||
| GraphCompiler | ||
| GIT_REPOSITORY ${GRAPH_COMPILER_REPO} | ||
| GIT_TAG ${GRAPH_COMPILER_TAG} | ||
| GIT_SHALLOW TRUE | ||
| ) | ||
| set(GC_ENABLE_TEST OFF CACHE BOOL "" FORCE) | ||
| set(GC_ENABLE_TOOLS OFF CACHE BOOL "" FORCE) | ||
| set(GC_ENABLE_PYTHON_BINDINGS OFF CACHE BOOL "" FORCE) | ||
| set(GC_DYLINK ${GRAPH_COMPILER_DYLINK} CACHE BOOL "" FORCE) | ||
| set(_ov_build_shared_libs ${BUILD_SHARED_LIBS}) | ||
| set(BUILD_SHARED_LIBS ${GRAPH_COMPILER_DYLINK}) | ||
| FetchContent_MakeAvailable(GraphCompiler) | ||
| set(BUILD_SHARED_LIBS ${_ov_build_shared_libs}) | ||
| endif() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| include_guard() | ||
|
|
||
| set(SUPPORTED_LLVM_VERSION "23" CACHE STRING "") | ||
|
|
||
| find_package(LLVM CONFIG QUIET) | ||
| if (NOT LLVM_FOUND) | ||
| set(LLVM_DIR "/usr/lib/llvm-${SUPPORTED_LLVM_VERSION}/lib/cmake/llvm" CACHE PATH "" FORCE) | ||
| find_package(LLVM REQUIRED CONFIG) | ||
| endif() | ||
|
|
||
| find_package(MLIR CONFIG QUIET) | ||
| if (NOT MLIR_FOUND) | ||
| get_filename_component(llvm_cmake_path "${LLVM_DIR}" REALPATH) | ||
| get_filename_component(llvm_cmake_dir "${llvm_cmake_path}" DIRECTORY) | ||
| set(MLIR_DIR "${llvm_cmake_dir}/mlir" CACHE PATH "" FORCE) | ||
| find_package(MLIR REQUIRED CONFIG) | ||
| endif() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // Copyright (C) 2018-2026 Intel Corporation | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <memory> | ||
| #include <tuple> | ||
| #include <vector> | ||
|
|
||
| #include "openvino/core/any.hpp" | ||
| #include "openvino/core/partial_shape.hpp" | ||
| #include "openvino/core/type/element_type.hpp" | ||
| #include "openvino/op/op.hpp" | ||
| #include "openvino/runtime/tensor.hpp" | ||
|
|
||
| namespace ov::intel_gpu { | ||
| namespace mlir { | ||
| class MLIREvaluateBase; | ||
| } // namespace mlir | ||
| namespace op { | ||
|
|
||
| using OVOutputTypes = std::vector<std::tuple<ov::element::Type, ov::PartialShape>>; | ||
|
|
||
| // Maps [output index][dimension index] -> [input index][dimension index] to | ||
| // infer shapes for the entire subgraph. | ||
| using DimensionsMap = std::vector<std::vector<std::tuple<size_t, size_t>>>; | ||
|
|
||
| class MLIROp : public ov::op::Op { | ||
| std::shared_ptr<mlir::MLIREvaluateBase> engine; | ||
| OVOutputTypes output_types; | ||
| DimensionsMap dimensions_map; | ||
|
|
||
| public: | ||
| OPENVINO_OP("MLIROp"); | ||
|
|
||
| MLIROp() = default; | ||
|
|
||
| MLIROp(const ov::OutputVector& args, | ||
| std::shared_ptr<mlir::MLIREvaluateBase> engine, | ||
| const OVOutputTypes& output_types, | ||
| const DimensionsMap& dimensions_map); | ||
|
|
||
| void validate_and_infer_types() override; | ||
| std::shared_ptr<ov::Node> clone_with_new_inputs(const ov::OutputVector& new_args) const override; | ||
| bool evaluate(ov::TensorVector& outputs, const ov::TensorVector& inputs) const override; | ||
| bool evaluate(ov::TensorVector& outputs, | ||
| const ov::TensorVector& inputs, | ||
| const ov::EvaluationContext& evaluationContext) const override; | ||
| bool has_evaluate() const override; | ||
| std::vector<ov::PartialShape> shape_infer(const std::vector<ov::PartialShape>& input_shapes) const; | ||
| }; | ||
|
|
||
| } // namespace op | ||
| } // namespace ov::intel_gpu |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Copyright (C) 2018-2026 Intel Corporation | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <functional> | ||
| #include <memory> | ||
| #include <vector> | ||
|
|
||
| #include "openvino/core/partial_shape.hpp" | ||
| #include "primitive.hpp" | ||
|
|
||
| namespace ov { | ||
| class Node; // forward-decl — the underlying op is ov::intel_gpu::op::MLIROp | ||
| } | ||
|
|
||
| namespace cldnn { | ||
|
|
||
| /// @brief Primitive that wraps an ov::intel_gpu::op::MLIROp node. Its execute_impl | ||
| /// (see impls/common/mlir_primitive.cpp) forwards to MLIROp::evaluate(). | ||
| struct mlir_primitive : public primitive_base<mlir_primitive> { | ||
| CLDNN_DECLARE_PRIMITIVE(mlir_primitive) | ||
|
|
||
| using shape_infer_function = | ||
| std::function<std::vector<ov::PartialShape>(const std::vector<ov::PartialShape>&)>; | ||
|
|
||
| mlir_primitive() : primitive_base("", {}) {} | ||
|
|
||
| mlir_primitive(const primitive_id& id, | ||
| const std::vector<input_info>& inputs, | ||
| std::shared_ptr<ov::Node> op, | ||
| shape_infer_function shape_infer_f, | ||
| size_t num_outputs, | ||
| const std::vector<optional_data_type>& out_types) | ||
| : primitive_base(id, inputs, num_outputs, out_types), | ||
| op(std::move(op)), | ||
| shape_infer_f(std::move(shape_infer_f)) {} | ||
|
|
||
| std::shared_ptr<ov::Node> op; | ||
| shape_infer_function shape_infer_f; | ||
|
dchigarev marked this conversation as resolved.
|
||
| }; | ||
|
|
||
| } // namespace cldnn | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is for internal CI in our fork. We'll remove this just before the merge.