Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#pragma once
 
#include <variant>
 
#include "core/common/common.h"
#include "core/framework/tensor_shape.h"
#include "core/common/float16.h"
#include "core/framework/framework_common.h"
#include "core/framework/ort_value.h"
#include "test/unittest_util/framework_test_utils.h"
 
namespace onnxruntime {
namespace test {
 
/**
 * @brief Class represent a input data (dimensions, data type and value).
 */
struct TestInputData {
  template <typename T>
  TestInputData(const std::string& name, const TensorShapeVector& dims, const std::vector<T>& values)
      : name_(name), dims_(dims), values_(values) {}
 
  OrtValue ToOrtValue() {
    OrtValue ortvalue;
    std::vector<int64_t> dims;
    dims.reserve(dims_.size());
    dims.insert(dims.end(), dims_.begin(), dims_.end());
    std::visit([&ortvalue, &dims](auto&& arg) {
      using T = std::decay_t<decltype(arg)>;
      if constexpr (std::is_same_v<T, std::vector<int64_t>> ||
                    std::is_same_v<T, std::vector<float>> ||
                    std::is_same_v<T, std::vector<MLFloat16>>)
        CreateMLValue<typename T::value_type>(
            TestCPUExecutionProvider()->CreatePreferredAllocators()[0], dims, arg, &ortvalue);
      else
        static_assert("Unspported types!");
    },
               values_);
 
    return ortvalue;
  }
 
  std::string GetName() const {
    return name_;
  }
 
 private:
  std::string name_;
  TensorShapeVector dims_;
  std::variant<std::vector<float>, std::vector<MLFloat16>, std::vector<int64_t>> values_;
};
 
/**
 * @brief A container for all input data.
 *
 */
struct InputContainer {
  InputContainer() = default;
 
  template <typename T>
  TestInputData& AddInput(const std::string& name, const TensorShapeVector dims, const std::vector<T>& values) {
    inputs_.emplace_back(TestInputData(name, dims, values));
    return inputs_.back();
  }
 
  template <typename T>
  TestInputData& AddInput(const std::string& name, TensorShapeVector dims,
                          std::function<
                              void(const TensorShapeVector& shape, std::vector<T>& data)>
                              func = nullptr) {
    std::vector<T> values(TensorShape(dims).Size());
    if (func) {
      func(dims, values);
    }
 
    inputs_.emplace_back(TestInputData(name, dims, values));
    return inputs_.back();
  }
 
  void ToInputMap(NameMLValMap& feeds) const {
    for (auto input : inputs_) {
      feeds.insert({input.GetName(), input.ToOrtValue()});
    }
  }
 
 private:
  std::vector<TestInputData> inputs_;
};
 
void RandomFillFloatVector(const TensorShapeVector& shape, std::vector<float>& data);
 
void RandomFillHalfVector(const TensorShapeVector& shape, std::vector<MLFloat16>& data);
 
void RandomMasks(int64_t batch, int64_t sequence_length, std::vector<int64_t>& data);
 
void RunModelWithData(const PathString& model_uri, const std::string session_log_id,
                      const std::string& provider_type, const InputContainer& input_container,
                      const std::vector<std::string>& output_names,
                      std::vector<OrtValue>& run_results);
}  // namespace test
}  // namespace onnxruntime