Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#pragma once
 
#include "core/common/inlined_containers.h"
#include "core/framework/max_shape_override.h"
#include "core/framework/workspace_input_shape.h"
 
namespace onnxruntime {
 
/// Resolves the input shapes for a node using a max-shape shadow-inference result.
/// For each explicit input:
///   - Preserve its position and mark an omitted optional input as Missing.
///   - Use the concrete shape propagated through the shadow graph when available.
///   - Otherwise preserve the rank and dimensions from the executable graph's shape proto,
///     representing each symbolic, absent, or negative dimension as -1. Multiple -1 dimensions
///     are independent unknowns and do not imply symbolic equality.
///   - Mark a present input without rank or dimension metadata as PresentWithoutShape.
/// Shapes propagated from max-shape overrides are estimation hints, not proven upper bounds.
///
/// @param node             The node whose input shapes to resolve.
/// @param graph_identity   Address of the node's containing graph.
/// @param inferred_shapes  Shapes propagated from maximum graph inputs.
/// @return                 One presence-aware shape entry per Node::InputDefs() element. Implicit
///                         inputs are excluded, matching OpKernelContext::Input(i).
template <typename TNode>
inline InlinedVector<WorkspaceInputShape> ResolveNodeInputShapes(
    const TNode& node,
    const void* graph_identity,
    const MaxShapeInferenceResult& inferred_shapes) {
  InlinedVector<WorkspaceInputShape> result;
  result.reserve(node.InputDefs().size());
 
  for (const auto* input_def : node.InputDefs()) {
    if (!input_def || !input_def->Exists()) {
      result.emplace_back();
      continue;
    }
 
    if (const TensorShape* inferred_shape = inferred_shapes.GetShape(graph_identity, input_def->Name())) {
      result.push_back(WorkspaceInputShape::PresentWithShape(*inferred_shape));
      continue;
    }
 
    const auto* shape_proto = input_def->Shape();
    if (!shape_proto) {
      result.push_back(WorkspaceInputShape::PresentWithoutShape());
      continue;
    }
 
    TensorShapeVector dims;
    dims.reserve(shape_proto->dim_size());
 
    for (const auto& dim : shape_proto->dim()) {
      dims.push_back(dim.has_dim_value() && dim.dim_value() >= 0 ? dim.dim_value() : -1);
    }
 
    result.push_back(WorkspaceInputShape::PresentWithShape(TensorShape{dims}));
  }
 
  return result;
}
 
}  // namespace onnxruntime