Исходный код СУБД 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#pragma once
#include <string>
#include <vector>
#include <type_traits>
namespace onnxruntime {
 
struct GraphTransformerConfiguration {
  struct PropagateCastOpsConfiguration {
    // Propagate FP16 Cast operations up and FP32 operations down
    /*
     * Cast propagation strategy.
     * One strategy is to insert casts around all the nodes with the allowed opcodes
     * and reduce, by removing redundant-casts and back-to-back-casts etc., and
     * the other is to propagate casts using flood-fill approach, expanding float16 regions in the graph
     * traversing the graph up/down.
     */
    enum class Strategy {
      None = 0,
      InsertAndReduce = 1,
      FloodFill = 2, /* Propagate FP16 Cast operations up and FP32 operations down */
    };
    using Strategy_t = std::underlying_type<Strategy>::type;
    friend constexpr Strategy operator|(const Strategy s1, const Strategy s2) {
      return static_cast<Strategy>(static_cast<Strategy_t>(s1) | static_cast<Strategy_t>(s2));
    }
 
    friend Strategy& operator|=(Strategy& s1, Strategy s2) {
      s1 = s1 | s2;
      return s1;
    }
 
    friend constexpr Strategy operator&(const Strategy s1, const Strategy s2) {
      return static_cast<Strategy>(static_cast<Strategy_t>(s1) & static_cast<Strategy_t>(s2));
    }
 
    friend constexpr Strategy& operator&=(Strategy& s1, Strategy s2) {
      s1 = s1 & s2;
      return s1;
    }
 
    friend constexpr bool operator==(Strategy s1, Strategy s2) {
      return static_cast<Strategy_t>(s1) == static_cast<Strategy_t>(s2);
    }
 
    friend constexpr bool operator!=(Strategy s1, Strategy s2) {
      return (s1 == s2) == false;
    }
 
    int level{1}; /* -1 => no cast propagation,
                       0 => use user specified list of opcodes to allow moving cast operations,
                       1 => use ORT predefined list of level 1 opcodes in addition to the user specified allow opcodes
                       2 => use ORT predefined list of level 2 opcodes in addition to the user specified allow opcodes
                    */
    Strategy strategy = Strategy::FloodFill;
    // List of allowed opcodes to consider as safe to execute in float16, while moving cast operations
    std::vector<std::string> allow;
  };
 
  PropagateCastOpsConfiguration propagate_cast_ops_config;
};
 
// The following declarations are required to refer to these operators in pybind11.
constexpr GraphTransformerConfiguration::PropagateCastOpsConfiguration::Strategy operator|(GraphTransformerConfiguration::PropagateCastOpsConfiguration::Strategy,
                                                                                           GraphTransformerConfiguration::PropagateCastOpsConfiguration::Strategy);
constexpr GraphTransformerConfiguration::PropagateCastOpsConfiguration::Strategy operator&(GraphTransformerConfiguration::PropagateCastOpsConfiguration::Strategy,
                                                                                           GraphTransformerConfiguration::PropagateCastOpsConfiguration::Strategy);
constexpr bool operator==(GraphTransformerConfiguration::PropagateCastOpsConfiguration::Strategy, GraphTransformerConfiguration::PropagateCastOpsConfiguration::Strategy);
constexpr bool operator!=(GraphTransformerConfiguration::PropagateCastOpsConfiguration::Strategy, GraphTransformerConfiguration::PropagateCastOpsConfiguration::Strategy);
 
}  // namespace onnxruntime