← Back to Pull requests

[GPU][MLIR][2/3] Add 'request_input_order' mechanism to MLIR converters #39622

Merged
dchigarev merged 13 files (240 lines) on Nov 25, 2026 12:45 UTC
View on GitHub
dchigarev dchigarev commented on Nov 08, 2026 16:38 UTC
Author

The PR adds a mechanism for an mlir-converter to request an arbitrary physical memory order for a certain input via ConversionContext.

ConversionContext and GraphConverter got a new method request_input_order(ov::Input<ov::Node>& input, DimOrder order) that take an ov::Node's input (eventually becomes an input of op::MLIROp) and a requested order (e.g. {0, 2, 1} to transpose last two dimensions). GraphConverter records the requested order to apply it to the input mlir::memref later when the whole mlir.func is materialized. It's important to note, that _op-converters_ (that actually call request_input_order func) operate on the _mlir-tensor-level_ and thus generate an IR that is layout-agnostic. The generated IR should work properly regardless of whether the requested memory-order was honored by the graph-converter or not.

After all nodes in the subgraph are converted to mlir and the final mlir.func is materialized, the ngraph_to_mlir logic applies requested memory orders (apply_requested_orders):
1. Applying custom strided-layout to the input memref type: %arg0: memref<512x32xf16> -> %arg0: memref<512x32xf16, strided<[1, 512]>>. After the strided-layout was baked into memref it must be honored by cldnn::reorder_inputs, otherwise an assertion in execute_impl fails.
2. Pass the orders-map to MLIRGpuProgram constructor as keptInputOrders

Then in mlir-primitive's builder (CreateMLIROp) (that has access to MLIRGpuProgram via ov::op::MLIROp with keptInputOrders information) the input orders are converted to cldnn::formats and stored into primitive.required_input_fmts (that are then handled by cldnn-layouts propagation logic from #39423)

----

<b>Current limitations:</b>

1. An input we request custom memory-layout for must have static shapes. It's true for a case that we want to support in the first place (compressed grouped-matmul from qwen), so it's fine for now. It's not a fundamental limitation, memrefs with custom dynamic strides are just not supported by our graph-compiler pipeline yet.
2. There is no "bubble-up" propagation of the requested layout, meaning it will only be honored if requested for a producer that is located outside of the captured MLIROp. It's also not a problem for our compressed-grouped-matmul-qwen case, since we plan to use for scales/zp that are represented as constants/params that are never part of MLIR subgraph.
<details><summary>img example</summary>

<img width="1234" height="613" alt="image" src="https://github.com/user-attachments/assets/7bb50a1a-ca55-4474-bd85-35b8e74e1f67" />

</details>

----
<b>Follow-up PR</b>:

  • https://github.com/openvinotoolkit/openvino/pull/39624 - PR that uses introduced mechanism to request custom memory order for scales/zp in GroupedMatmulCompressed converter
  • Diff: 240 lines (+227 / -13) across 13 files Reviewer: v-Golubev Review duration: 24247m
    All Vouch review confidence checks passed
    Residual risk 0.05 = Change Risk (0.53) × (1 − Review Confidence (0.90)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.53 · 240 lines diff across 13 files
    0.53
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.89 · 5 substantive comment(s)
    0.89
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    90%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.328
    Real PR Conversation Timeline
    21 items
    Copilot Copilot commented on code on Nov 17, 2026 15:58 UTC
    Code Review
    src/plugins/intel_gpu/src/plugin/transformations/mlir/convert.cpp:1
    @@ -183,6 +238,8 @@ mlir::OwningOpRef<mlir::ModuleOp> ngraph_to_mlir(MLIRContext* context,
             graph_converter.convert(node);
         }
     
    +    auto runtime_orders = apply_requested_orders(func, runtime_inputs, graph_converter);

    The new request-to-layout path lacks regression coverage: mlir_primitive_layouts_test.cpp sets required_input_fmts directly, bypassing memref stride generation and input-order remapping. Add tests that request a static rank-3 order and verify the strides and propagated primitive format, index remapping after splat/unused inputs are removed, and fallback for conflicting or unsupported requests, including dynamic shapes. The Testing section of src/common/transformations/docs/writing_transformations.md requires coverage for behavioral changes; please check the remaining new branches against that requirement too.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 17, 2026 15:58 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🟡 Changes recommended

    The new request-to-layout path lacks regression coverage for stride generation, input-order remapping, and fallback behavior for conflicting or unsupported requests, including dynamic shapes.

    <details open>
    <summary><strong>1 open issue</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Add regression tests for request-to-layout behavior and fallback branches · New

  • </details>

    <details>
    <summary><strong>What changed in this PR</strong></summary>

    This PR lets GPU MLIR converters request physical input layouts while keeping their generated tensor operations layout-independent. It connects the layout enforcement from #39423 to the compressed grouped-matmul support planned in #39624.

    Changes:

  • Add input-order requests with conflict handling and fallback for unsupported layouts.

  • Apply supported orders as memref strides and preserve metadata when unused inputs are removed.

  • Propagate applied orders through MLIROp into required GPU primitive formats.
  • | File | Description |
    | ---- | ----------- |
    | src/​plugins/​intel_gpu/​src/​plugin/​transformations/​op/​mlir_op.cpp | Preserve input orders during construction and cloning. |
    | src/​plugins/​intel_gpu/​src/​plugin/​transformations/​mlir/​graph_converter.hpp | Declare order-request tracking and lookup. |
    | src/​plugins/​intel_gpu/​src/​plugin/​transformations/​mlir/​graph_converter.cpp | Record requests and discard conflicting orders. |
    | src/​plugins/​intel_gpu/​src/​plugin/​transformations/​mlir/​convert.cpp | Apply memref strides and remap retained input orders. |
    | src/​plugins/​intel_gpu/​src/​plugin/​transformations/​mlir/​common/​README.md | Document layout hints and driver responsibilities. |
    | src/​plugins/​intel_gpu/​src/​plugin/​transformations/​mlir/​common/​conversion_context.hpp | Expose the input-order callback to converters. |
    | src/​plugins/​intel_gpu/​src/​plugin/​transformations/​mlir/​common/​conversion_context.cpp | Initialize the new callback. |
    | src/​plugins/​intel_gpu/​src/​plugin/​ops/​mlir_op.cpp | Translate applied orders into required primitive formats. |
    | src/​plugins/​intel_gpu/​include/​intel_gpu/​primitives/​mlir_primitive.hpp | Map dimension orders to supported GPU formats. |
    | src/​plugins/​intel_gpu/​include/​intel_gpu/​op/​mlir_op.hpp | Define and expose input-order metadata. |
    </details>

    <sub>Review effort: Balanced</sub>

    dchigarev dchigarev commented on code on Nov 18, 2026 12:24 UTC
    Code Review
    src/plugins/intel_gpu/src/plugin/ops/mlir_op.cpp:1
    @@ -31,6 +31,13 @@ static void CreateMLIROp(ProgramBuilder& p, const std::shared_ptr<ov::op::intern
     
         cldnn::mlir_primitive primitive(layer_name, inputs, op, std::move(shape_infer_f), num_outputs, get_output_data_types(op));
     
    +    // Fill the required input formats from the input orders of the compiled program.
    +    for (const auto& [i, order] : op->get_input_orders()) {
    +        const auto fmt = cldnn::mlir_primitive::format_from_dim_order(order);
    +        OPENVINO_ASSERT(fmt.has_value(), "[GPU] MLIROp '", layer_name, "': no cldnn format for the physical order of input ", i);
    +        primitive.required_input_fmts.emplace(i, fmt.value());
    +    }
    +

    this is the place we propagate orders requested by request_input_order to mlir-primitive's input formats

    dchigarev dchigarev commented on code on Nov 18, 2026 12:47 UTC
    Code Review
    src/plugins/intel_gpu/src/plugin/transformations/mlir/convert.cpp:1
    @@ -109,11 +111,64 @@ void dropUnusedInputArgs(mlir::func::FuncOp func, size_t numInputs, SmallVector<
         assert(mlir::succeeded(result) && "Failed to erase unused function arguments");
     }
     
    +// Whether a function argument of `type` can be passed in the physical dimension `order`:
    +// a permutation of a plain static-shaped memref that has a matching cldnn format.
    +bool is_supported_order(MemRefType type, ArrayRef<int64_t> order) {
    +    // Static shapes only: a dynamic shape would need dynamic strides (strided<[?, 1, ?]>), which the current
    +    // graph-compiler pipeline can't handle yet. This is not a fundamental limitation.
    +    if (order.size() != static_cast<size_t>(type.getRank()) || !type.hasStaticShape() || !type.getLayout().isIdentity()) {
    +        return false;
    +    }
    +    if (!mlir::isPermutationVector(order)) {
    +        return false;
    +    }
    +    return cldnn::mlir_primitive::format_from_dim_order(std::vector<size_t>(order.begin(), order.end())).has_value();
    +}

    I was initially not sure if it's okay to call cldnn-primitives from the ov-model-level transformations, but then found one example where transpose_fusion does the same. Hope it's okay.

    We do it here to make sure that the requested order can be later satisfied at the primitive's level. If we would remove this check then instead of ignoring unsupported requested order we would propagate it to the primitives layer where it would fail at this assertion.

    Since we control ov->mlir converters there _shouldn't_ be a case where this check fails, so removing this check at ov-model-level is not critical, if we would decide to do so during the review

    dchigarev dchigarev commented on code on Nov 18, 2026 13:37 UTC
    Code Review
    src/plugins/intel_gpu/src/plugin/transformations/mlir/convert.cpp:1
    @@ -183,6 +238,8 @@ mlir::OwningOpRef<mlir::ModuleOp> ngraph_to_mlir(MLIRContext* context,
             graph_converter.convert(node);
         }
     
    +    auto runtime_orders = apply_requested_orders(func, runtime_inputs, graph_converter);

    Unfortunately we can't add a unit-test for the request_input_order mechanism without linking openvino_intel_gpu_mlir_obj/gc/llvm to ov_gpu_unit_tests and I wouldn't do it right now. This mechanism will be tested by e2e tests with new converters using this feature (starting from #39624). I've manually verified that the new grouped-mm-compressed tests from there work properly.

    As for this PR I've added a unit test to verify the format_from_dim_order` primitive's functionality. It doesn't cover the whole flow, but that's all we can test right now

    dchigarev dchigarev commented on code on Nov 18, 2026 13:42 UTC
    Code Review
    src/plugins/intel_gpu/tests/unit/mlir/mlir_primitive_layouts_test.cpp:1
    @@ -131,3 +132,23 @@ TEST(mlir_primitive_layouts, rank5_bzyxf_required_format_is_delivered) {
         EXPECT_TRUE(node.get_dependency(1).is_constant());
         EXPECT_EQ(node.get_output_layout().format, format::bfzyx);
     }
    +
    +TEST(mlir_primitive_layouts, format_from_dim_order) {

    I know it doesn't cover the whole flow, but that's all we can test in this PR

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 18, 2026 13:45 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🟢 Approval recommended

    No active review issues are recorded for the GPU MLIR input-order layout changes.

    No open issues 🎉

    <details>
    <summary><strong>1 resolved since last review</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Add regression tests for request-to-layout behavior and fallback branches

  • </details>

    <sub>Review effort: Balanced</sub>

    v-Golubev v-Golubev commented on code on Nov 23, 2026 15:32 UTC
    Code Review
    src/plugins/intel_gpu/src/plugin/transformations/mlir/convert.cpp:1
    @@ -109,11 +111,64 @@ void dropUnusedInputArgs(mlir::func::FuncOp func, size_t numInputs, SmallVector<
         assert(mlir::succeeded(result) && "Failed to erase unused function arguments");
     }
     
    +// Whether a function argument of `type` can be passed in the physical dimension `order`:
    +// a permutation of a plain static-shaped memref that has a matching cldnn format.
    +bool is_supported_order(MemRefType type, ArrayRef<int64_t> order) {
    +    // Static shapes only: a dynamic shape would need dynamic strides (strided<[?, 1, ?]>), which the current
    +    // graph-compiler pipeline can't handle yet. This is not a fundamental limitation.
    +    if (order.size() != static_cast<size_t>(type.getRank()) || !type.hasStaticShape() || !type.getLayout().isIdentity()) {

    isIdentity() is always true here (the arguments come from tensorsToMemRefs), so it can go. The rank and permutation checks can only fail on a malformed request from a converter: let's assert them in request_input_order instead of silently ignoring the hint, so such a bug fails right away. Only the static shape and the cldnn format availability are valid fallbacks

    v-Golubev v-Golubev commented on code on Nov 23, 2026 21:31 UTC
    Code Review
    src/plugins/intel_gpu/include/intel_gpu/primitives/mlir_primitive.hpp:1
    @@ -69,6 +70,22 @@ struct mlir_primitive : public primitive_base<mlir_primitive> {
             return it->second;
         }
     
    +    // Returns the cldnn format with the given physical dimension order (e.g. {0, 2, 1} -> byfx),
    +    // or nullopt if there is no such format. The order must not be empty (the rank comes from it).
    +    static std::optional<format::type> format_from_dim_order(std::vector<size_t> order) {
    +        OPENVINO_ASSERT(!order.empty(), "[GPU] mlir_primitive: empty physical dimension order");
    +        // Ranks below 4 are represented as 4D by cldnn: the missing trailing dimensions keep their place.
    +        for (size_t i = order.size(); i < 4; ++i) {
    +            order.push_back(i);
    +        }
    +        try {
    +            return static_cast<format::type>(format::find_format(order, {}));
    +        } catch (const ov::Exception&) {
    +            // find_format throws (OPENVINO_ASSERT) if no format or more than one format has this order.
    +            return std::nullopt;
    +        }
    +    }

    Can we simplify this helper? find_format throws only if there is no format for the order, and a converter requesting such an order is a bug that should fail right away (as the other converter asserts do) instead of silently falling back to the plain layout. Then is_supported_order doesn't need the format check, the has_value() assertion in CreateMLIROp goes away, and the order can be validated once in GraphConverter::request_input_order. The std::nullopt cases in the unit test become EXPECT_THROW

        // Returns the cldnn format with the given physical dimension order (e.g. {0, 2, 1} -> byfx).
        // Throws if there is no such format. The order must not be empty (the rank comes from it).
        static format::type format_from_dim_order(std::vector<size_t> order) {
            OPENVINO_ASSERT(!order.empty(), "[GPU] mlir_primitive: empty physical dimension order");
            // Ranks below 4 are represented as 4D by cldnn: the missing trailing dimensions keep their place.
            for (size_t i = order.size(); i < 4; ++i) {
                order.push_back(i);
            }
            return static_cast<format::type>(format::find_format(order, {}));
        }
    

    v-Golubev v-Golubev commented on code on Nov 23, 2026 21:32 UTC
    Code Review
    src/plugins/intel_gpu/src/plugin/transformations/mlir/common/conversion_context.hpp:1
    @@ -24,14 +24,24 @@ class ConversionContext {
     public:
         using getInputsFn = std::function<SmallVector<mlir::Value>(NodePtr)>;
         using getDimValueFn = std::function<Value(const Dimension&)>;
    +    // Physical dimension order of a tensor, e.g. {0, 2, 1} for a logical [E, N, G] tensor stored as [E, G, N].
    +    using DimOrder = SmallVector<int64_t>;
    +    using requestInputOrderFn = std::function<void(const ov::Input<ov::Node>&, DimOrder)>;
         using NodeOutputMap = std::map<ov::Output<ov::Node>, mlir::Value>;
     
         mlir::MLIRContext* context;
         mlir::OpBuilder* block_builder;
         getInputsFn getInputs;
         getDimValueFn getDimValue;
    -
    -    ConversionContext(mlir::MLIRContext* context, mlir::OpBuilder* block_builder, getInputsFn getInputs, getDimValueFn getDimValue);
    +    // Asks for the source of `input` to be passed in the given physical order. This is only a hint that
    +    // the driver may ignore, so the IR built by a converter must stay valid for any order.

    Minor: it's not clear from this comment what happens when the order is not honored (does the converter have to reorder the input itself?), and driver can be read as the GPU driver. Let's make it explicit

        // A hint to pass the source of `input` in the given physical order. The graph converter may ignore it, so the IR
        // must always be built on logical tensors, with no reordering of the input: only the function argument layout depends on it.
    

    v-Golubev v-Golubev commented on code on Nov 23, 2026 21:32 UTC
    Code Review
    src/plugins/intel_gpu/src/plugin/transformations/mlir/graph_converter.cpp:1
    @@ -28,8 +28,29 @@ GraphConverter::GraphConverter(mlir::MLIRContext* context, mlir::OpBuilder* bloc
               },
               [this](const Dimension& dim) {
                   return get_dimension_value(dim);
    +          },
    +          [this](const ov::Input<ov::Node>& input, DimOrder order) {
    +              request_input_order(input, std::move(order));
               }) {}
     
    +void GraphConverter::request_input_order(const ov::Input<ov::Node>& input, DimOrder order) {
    +    const auto source = input.get_source_output();
    +    if (conflicting_orders.count(source) != 0U) {
    +        return;
    +    }
    +    auto [it, inserted] = requested_orders.emplace(source, order);
    +    if (!inserted && it->second != order) {
    +        OPENVINO_MLIR_DEBUG_PRINT("Conflicting physical orders requested for " << source << ", keeping the default one");
    +        requested_orders.erase(it);
    +        conflicting_orders.insert(source);
    +    }
    +}

    Let's replace conflicting_orders with an assert: the real cases (GroupedMatMul) don't have conflicting requests, and silently dropping a request would only hide a converter bug. conflicting_orders and #include <set> can be removed from the header then

    void GraphConverter::request_input_order(const ov::Input<ov::Node>& input, DimOrder order) {
        const auto source = input.get_source_output();
        const auto [it, inserted] = requested_orders.emplace(source, order);
        OPENVINO_ASSERT(inserted || it->second == order, "Conflicting physical orders are requested for ", source);
    }
    

    v-Golubev v-Golubev commented on code on Nov 23, 2026 21:32 UTC
    Code Review
    src/plugins/intel_gpu/include/intel_gpu/op/mlir_op.hpp:1
    @@ -26,10 +27,16 @@ using OVOutputTypes = std::vector<std::tuple<ov::element::Type, ov::PartialShape
     // infer shapes for the entire subgraph.
     using DimensionsMap = std::vector<std::vector<std::tuple<size_t, size_t>>>;
     
    +// Physical dimension order the compiled program expects for some inputs (key == input_index).
    +// Inputs without an entry are plain (row-major). E.g.:
    +//   input_orders[1] = {0, 2, 1};  // input 1 is a logical [E, N, G] tensor stored in memory as [E, G, N]
    +using InputOrders = std::map<size_t, std::vector<size_t>>;
    +
     class MLIROp : public ov::op::Op {
         std::shared_ptr<mlir::MLIRGpuProgram> program;
         OVOutputTypes output_types;
         DimensionsMap dimensions_map;
    +    InputOrders input_orders;

    Do we need the orders on the node? This is a layout detail of the compiled function, which the program already bakes in, and here it is plumbed through the constructor, clone_with_new_inputs and a getter just to reach CreateMLIROp. Can we keep it in MLIRGpuProgram instead (passed to create_gpu_program, read in CreateMLIROp via op->get_program())? MLIROp would stay free from the layout info, and clone_with_new_inputs would be correct by construction since the program is shared. What do you think?

    dchigarev dchigarev commented on code on Nov 24, 2026 14:17 UTC
    Code Review
    src/plugins/intel_gpu/src/plugin/transformations/mlir/common/conversion_context.hpp:1
    @@ -24,14 +24,24 @@ class ConversionContext {
     public:
         using getInputsFn = std::function<SmallVector<mlir::Value>(NodePtr)>;
         using getDimValueFn = std::function<Value(const Dimension&)>;
    +    // Physical dimension order of a tensor, e.g. {0, 2, 1} for a logical [E, N, G] tensor stored as [E, G, N].
    +    using DimOrder = SmallVector<int64_t>;
    +    using requestInputOrderFn = std::function<void(const ov::Input<ov::Node>&, DimOrder)>;
         using NodeOutputMap = std::map<ov::Output<ov::Node>, mlir::Value>;
     
         mlir::MLIRContext* context;
         mlir::OpBuilder* block_builder;
         getInputsFn getInputs;
         getDimValueFn getDimValue;
    -
    -    ConversionContext(mlir::MLIRContext* context, mlir::OpBuilder* block_builder, getInputsFn getInputs, getDimValueFn getDimValue);
    +    // Asks for the source of `input` to be passed in the given physical order. This is only a hint that
    +    // the driver may ignore, so the IR built by a converter must stay valid for any order.

    applied in 3de687f5846a26ce2db17b556ed3d09124cef1e4

    dchigarev dchigarev commented on code on Nov 24, 2026 14:18 UTC
    Code Review
    src/plugins/intel_gpu/src/plugin/transformations/mlir/graph_converter.cpp:1
    @@ -28,8 +28,29 @@ GraphConverter::GraphConverter(mlir::MLIRContext* context, mlir::OpBuilder* bloc
               },
               [this](const Dimension& dim) {
                   return get_dimension_value(dim);
    +          },
    +          [this](const ov::Input<ov::Node>& input, DimOrder order) {
    +              request_input_order(input, std::move(order));
               }) {}
     
    +void GraphConverter::request_input_order(const ov::Input<ov::Node>& input, DimOrder order) {
    +    const auto source = input.get_source_output();
    +    if (conflicting_orders.count(source) != 0U) {
    +        return;
    +    }
    +    auto [it, inserted] = requested_orders.emplace(source, order);
    +    if (!inserted && it->second != order) {
    +        OPENVINO_MLIR_DEBUG_PRINT("Conflicting physical orders requested for " << source << ", keeping the default one");
    +        requested_orders.erase(it);
    +        conflicting_orders.insert(source);
    +    }
    +}

    agree, throw on conflicting orders since: 9eb15537eebb0e6f6c2be2308ab500ce9bbd81b1

    dchigarev dchigarev commented on code on Nov 24, 2026 14:19 UTC
    Code Review
    src/plugins/intel_gpu/include/intel_gpu/primitives/mlir_primitive.hpp:1
    @@ -69,6 +70,22 @@ struct mlir_primitive : public primitive_base<mlir_primitive> {
             return it->second;
         }
     
    +    // Returns the cldnn format with the given physical dimension order (e.g. {0, 2, 1} -> byfx),
    +    // or nullopt if there is no such format. The order must not be empty (the rank comes from it).
    +    static std::optional<format::type> format_from_dim_order(std::vector<size_t> order) {
    +        OPENVINO_ASSERT(!order.empty(), "[GPU] mlir_primitive: empty physical dimension order");
    +        // Ranks below 4 are represented as 4D by cldnn: the missing trailing dimensions keep their place.
    +        for (size_t i = order.size(); i < 4; ++i) {
    +            order.push_back(i);
    +        }
    +        try {
    +            return static_cast<format::type>(format::find_format(order, {}));
    +        } catch (const ov::Exception&) {
    +            // find_format throws (OPENVINO_ASSERT) if no format or more than one format has this order.
    +            return std::nullopt;
    +        }
    +    }

    Agree. Simplified the format_from_dim_order method and moved the 'cldnn-layout-check' to request_input_order function (inside of validate_requested_order): 3de687f5846a26ce2db17b556ed3d09124cef1e4

    dchigarev dchigarev commented on code on Nov 24, 2026 14:23 UTC
    Code Review
    src/plugins/intel_gpu/src/plugin/transformations/mlir/convert.cpp:1
    @@ -109,11 +111,64 @@ void dropUnusedInputArgs(mlir::func::FuncOp func, size_t numInputs, SmallVector<
         assert(mlir::succeeded(result) && "Failed to erase unused function arguments");
     }
     
    +// Whether a function argument of `type` can be passed in the physical dimension `order`:
    +// a permutation of a plain static-shaped memref that has a matching cldnn format.
    +bool is_supported_order(MemRefType type, ArrayRef<int64_t> order) {
    +    // Static shapes only: a dynamic shape would need dynamic strides (strided<[?, 1, ?]>), which the current
    +    // graph-compiler pipeline can't handle yet. This is not a fundamental limitation.
    +    if (order.size() != static_cast<size_t>(type.getRank()) || !type.hasStaticShape() || !type.getLayout().isIdentity()) {

    Added the 'order-validation' to request_input_order. The is_supported_order still check whether the order is valid for a <i>memref-type</i> (since in request_input_order we validate against ov-input) but now it throws an exception instead of ignoring an invalid order.

    0fddb024ada8734772f6a31a6c37ec40e435cfc0

    dchigarev dchigarev commented on code on Nov 24, 2026 14:24 UTC
    Code Review
    src/plugins/intel_gpu/include/intel_gpu/op/mlir_op.hpp:1
    @@ -26,10 +27,16 @@ using OVOutputTypes = std::vector<std::tuple<ov::element::Type, ov::PartialShape
     // infer shapes for the entire subgraph.
     using DimensionsMap = std::vector<std::vector<std::tuple<size_t, size_t>>>;
     
    +// Physical dimension order the compiled program expects for some inputs (key == input_index).
    +// Inputs without an entry are plain (row-major). E.g.:
    +//   input_orders[1] = {0, 2, 1};  // input 1 is a logical [E, N, G] tensor stored in memory as [E, G, N]
    +using InputOrders = std::map<size_t, std::vector<size_t>>;
    +
     class MLIROp : public ov::op::Op {
         std::shared_ptr<mlir::MLIRGpuProgram> program;
         OVOutputTypes output_types;
         DimensionsMap dimensions_map;
    +    InputOrders input_orders;

    Thanks, it's indeed a more clean approach that I haven't considered!

    Moved the input_order map to MLIRGpuProgram in ef6072968520857567de938eb1c1c4befbba8fd1

    v-Golubev v-Golubev commented on code on Nov 24, 2026 16:51 UTC
    Code Review
    src/plugins/intel_gpu/src/plugin/transformations/mlir/common/README.md:1
    @@ -35,9 +35,22 @@ In the GPU plugin this contract is spelled as the `GraphConverter::Convertor` al
     - `mlir::OpBuilder`
     - Mapping between `ov::Node` inputs and MLIR tensors
     - Mapping between dynamic-dimension symbols and their MLIR values
    +- A way to request a physical layout of an input (`requestInputOrder`)
     
    -For the exact declaration (constructor and the `getInputs` / `getDimValue` callbacks it expects) see
    -[`conversion_context.hpp`](conversion_context.hpp).
    +For the exact declaration (constructor and the `getInputs` / `getDimValue` / `requestInputOrder` callbacks it
    +expects) see [`conversion_context.hpp`](conversion_context.hpp).
    +
    +#### Requesting a physical input order
    +
    +A converter may call `requestInputOrder(input, order)` to ask for the source of `input` to be passed with its
    +dimensions stored in `order`, e.g. `{0, 2, 1}` for a logical `[E, N, G]` tensor stored as `[E, G, N]`.
    +
    +- It is an optional **hint**: calling it is never required, and the IR built by the converter must stay on logical
    +  tensors and be valid for any physical order.
    +- The graph-converter decides whether to honour it (e.g. it may only support some orders or only inputs coming from
    +  outside of the subgraph), and is responsible for providing the buffer in the chosen layout.

    This is not actual anymore: an order without a cldnn format and conflicting requests now throw instead of being ignored

    - The graph-converter honours it only for inputs coming from outside of the subgraph and with a static shape,
      otherwise the plain order is used, and is responsible for providing the buffer in the chosen layout. A malformed
      order, an order with no cldnn format and conflicting requests for the same input are converter bugs and throw.
    

    v-Golubev v-Golubev commented on code on Nov 24, 2026 17:30 UTC
    Code Review
    src/plugins/intel_gpu/src/plugin/transformations/mlir/common/convert_common.hpp:1
    @@ -24,7 +24,7 @@ namespace ov::intel_gpu::mlir {
     using namespace ::mlir;
     
     class MLIRGpuProgram;
    -std::shared_ptr<MLIRGpuProgram> create_gpu_program(::mlir::OwningOpRef<::mlir::ModuleOp> module, uint32_t device_id);
    +std::shared_ptr<MLIRGpuProgram> create_gpu_program(::mlir::OwningOpRef<::mlir::ModuleOp> module, uint32_t device_id, InputOrders input_orders = {});

    Can we remove the default value for input_orders here and in the MLIRGpuProgram constructor? The only caller (and GcGpuProgram) passes it explicitly, and a forgotten argument would silently make all inputs plain

    std::shared_ptr<MLIRGpuProgram> create_gpu_program(::mlir::OwningOpRef<::mlir::ModuleOp> module, uint32_t device_id, InputOrders input_orders);
    

    v-Golubev v-Golubev approved these changes on Nov 24, 2026 17:59 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    dchigarev dchigarev
    Labels
    risk: low confidence: 90.3% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 53.4% (MEDIUM) · Higher = larger blast radius
    53.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 90.3% · Lower = rushed or shallow review
    90.3%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 5.2% · Safe to merge
    5.2%