Исходный код СУБД 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#include <vector>
 
#include "gtest/gtest.h"
#include "test/unittest_util/graph_transform_test_builder.h"
 
#include "core/graph/graph.h"
 
namespace onnxruntime {
namespace test {
 
#ifndef DISABLE_CONTRIB_OPS
 
void TestConvPath(const std::vector<int64_t>& input_shape, const std::vector<int64_t>& weights_shape,
                  const std::vector<int64_t>& output_shape, int64_t group) {
  auto build_test_case = [&](ModelTestBuilder& builder) {
    auto* input_arg = builder.MakeInput<float>(input_shape, -31, 31);
    auto* output_arg = builder.MakeOutput();
    auto* bias_arg = builder.MakeInitializer<float>({weights_shape[0]}, -20.f, 20.f);
    auto* add_arg = builder.MakeInput<float>(output_shape, -20.f, 20.f);
    auto* weight_arg = builder.MakeInitializer<float>(weights_shape, -2.f, 2.f);
    auto* conv_out_arg = builder.MakeIntermediate();
 
    auto& conv_node = builder.AddNode("Conv", {input_arg, weight_arg, bias_arg}, {conv_out_arg});
    conv_node.AddAttribute("group", group);
    builder.AddNode("Add", {conv_out_arg, add_arg}, {output_arg});
  };
 
  auto check_graph = [&](InferenceSessionWrapper& session) {
    auto op_to_count = CountOpsInGraph(session.GetGraph());
    EXPECT_EQ(op_to_count["com.microsoft.FusedConv"], 1);
    EXPECT_EQ(op_to_count["com.microsoft.NhwcFusedConv"], 0);
  };
  InlinedHashSet<std::string> disabled_optimizers = {"NchwcTransformer", "NhwcTransformer"};
  TransformerTester(build_test_case,
                    check_graph,
                    TransformerLevel::Default,
                    TransformerLevel::Level3, {12, 22}, 0.0001, 0.000001,
                    nullptr, {}, disabled_optimizers);
}
 
TEST(ConvAddActivationFusionTests, ConvExpandThenGemm) {
  // hit MlasConvAlgorithmExpandThenGemm
  TestConvPath({1, 16, 5, 5}, {16, 16, 3, 3}, {1, 16, 3, 3}, 1);
}
 
TEST(ConvAddActivationFusionTests, ConvDepthwise) {
  // MlasConvAlgorithmDepthwise or MlasConvAlgorithmExpandThenGemmSegmented
  TestConvPath({1, 16, 5, 5}, {16, 1, 3, 3}, {1, 16, 3, 3}, 16);
}
 
TEST(ConvAddActivationFusionTests, ConvGemmDirect) {
  // MlasConvAlgorithmGemmDirect
  TestConvPath({1, 16, 5, 5}, {16, 16, 1, 1}, {1, 16, 5, 5}, 1);
  // MlasConvAlgorithmGemmDirect
  TestConvPath({1, 16, 5, 5}, {16, 1, 5, 5}, {1, 16, 1, 1}, 16);
}
 
#endif  // DISABLE_CONTRIB_OPS
 
}  // namespace test
}  // namespace onnxruntime