Исходный код СУБД 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#pragma once
 
#include <cstddef>
#include <utility>
 
#include <gsl/span>
 
#include "core/framework/tensor_shape.h"
 
namespace onnxruntime {
 
// Shape metadata for one positional node input used when declaring workspace requirements.
enum class WorkspaceInputShapeState {
  // The optional input is omitted at this position.
  Missing,
  // The input is present and rank/dimension metadata is available. This includes rank-0 scalars,
  // zero extents, and partial shapes. Unknown dimensions are encoded as -1; multiple -1 dimensions
  // are independent unknowns and do not imply symbolic equality. TensorShape::Size() returns -1
  // for a partial shape, so consumers must inspect dimensions rather than convert Size() to an
  // unsigned byte/count value.
  PresentWithShape,
  // The input is present, but no rank or dimension metadata is available.
  PresentWithoutShape,
};
 
// A PresentWithShape value may come from executable-graph metadata or max-shape inference. The
// latter is an estimation hint, not a proven upper bound, so consumers must retain runtime checks
// and allocation fallbacks. This Phase-A type intentionally carries no provenance state; deciding
// whether Phase-B allocation planning needs it is deferred until that runtime fallback contract is
// designed.
class WorkspaceInputShape {
 public:
  WorkspaceInputShape() = default;
 
  static WorkspaceInputShape PresentWithShape(const TensorShape& shape) {
    // TensorShape can be a non-owning view created by FromExistingBuffer(). Always copy the
    // dimensions so this value remains valid independently of the caller's storage.
    return WorkspaceInputShape{
        WorkspaceInputShapeState::PresentWithShape, TensorShape{shape.GetDims()}};
  }
 
  static WorkspaceInputShape PresentWithoutShape() {
    return WorkspaceInputShape{WorkspaceInputShapeState::PresentWithoutShape, TensorShape{}};
  }
 
  WorkspaceInputShapeState GetState() const noexcept {
    return state_;
  }
 
  const TensorShape* GetShape() const& noexcept {
    return state_ == WorkspaceInputShapeState::PresentWithShape ? &shape_ : nullptr;
  }
 
  // A pointer into a temporary WorkspaceInputShape would dangle immediately.
  const TensorShape* GetShape() const&& = delete;
 
 private:
  WorkspaceInputShape(WorkspaceInputShapeState state, TensorShape shape)
      : state_{state}, shape_{std::move(shape)} {
  }
 
  WorkspaceInputShapeState state_{WorkspaceInputShapeState::Missing};
  TensorShape shape_;
};
 
// Node inputs are positional. A caller may omit trailing optional inputs from the span; querying one
// of those positions has the same meaning as an explicit Missing entry.
inline const WorkspaceInputShape& GetWorkspaceInputShape(
    gsl::span<const WorkspaceInputShape> input_shapes, size_t input_index) {
  if (input_index < input_shapes.size()) {
    return input_shapes[input_index];
  }
 
  static const WorkspaceInputShape missing_input;
  return missing_input;
}
 
}  // namespace onnxruntime