summaryrefslogtreecommitdiff
path: root/compiler/tflite2circle/src/DataLookup.cpp
blob: a1b7806503b9d3c8b8a077f498d8a7d5b00b27f0 (plain)
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
105
106
107
108
109
110
111
112
113
/*
 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "DataLookup.h"
#include "BuildBuiltinOptions.h"

namespace tflite2circle
{

circle::BuiltinOperator get_circle_builtin_code(tflite::BuiltinOperator tfl_bop)
{
  switch (tfl_bop)
  {
#define TFL_OPERATOR(OP)             \
  case tflite::BuiltinOperator_##OP: \
    return circle::BuiltinOperator_##OP;
#include "TFLOperator.lst"
#undef TFL_OPERATOR
    default:
      throw std::runtime_error("tflite2circle: wrong op");
  }
}

circle::TensorType get_circle_tensortype(tflite::TensorType tfl_tt)
{
  switch (tfl_tt)
  {
#define TFL_TENSORTYPE(TENSORTYPE)      \
  case tflite::TensorType_##TENSORTYPE: \
    return circle::TensorType_##TENSORTYPE;
#include "TFLTensorType.lst"
#undef TFL_TENSORTYPE
    default:
      throw std::runtime_error("tflite2circle: wrong tensor type");
  }
}

circle::Padding get_circle_padding(tflite::Padding tfl_p)
{
  switch (tfl_p)
  {
    case tflite::Padding_SAME:
      return circle::Padding_SAME;
    case tflite::Padding_VALID:
      return circle::Padding_VALID;
    default:
      throw std::runtime_error("tflite2circle: wrong padding");
  }
}

circle::ActivationFunctionType
get_circle_activation_function_type(tflite::ActivationFunctionType tfl_aft)
{
  switch (tfl_aft)
  {
#define TFL_ACTIVATION_FUNCTION(TYPE)         \
  case tflite::ActivationFunctionType_##TYPE: \
    return circle::ActivationFunctionType_##TYPE;
#include "TFLActivationFunctionType.lst"
#undef TFL_ACTIVATION_FUNCTION
    default:
      throw std::runtime_error("tflite2circle: wrong activation function type.");
  }
}

flatbuffers::Offset<void> get_circle_builtin_options(flatbuffers::FlatBufferBuilder &fb,
                                                     const tflite::Operator *op)
{
  auto tflite_builtin_options_type = op->builtin_options_type();
  switch (tflite_builtin_options_type)
  {
    case tflite::BuiltinOptions_NONE:
      return flatbuffers::Offset<void>();
#define TFL_BUILTIN_OPTIONS(TYPE)     \
  case tflite::BuiltinOptions_##TYPE: \
    return build_circle_##TYPE(fb, op).Union();
#include "TFLBuiltinOptions.lst"
#undef TFL_BUILTIN_OPTIONS
    default:
      throw std::runtime_error("tflite2circle: wrong builtin options type.");
  }
}

circle::BuiltinOptions get_circle_builtin_options_type(const tflite::Operator *op)
{
  switch (op->builtin_options_type())
  {
    case tflite::BuiltinOptions_NONE:
      return circle::BuiltinOptions_NONE;
#define TFL_BUILTIN_OPTIONS(TYPE)     \
  case tflite::BuiltinOptions_##TYPE: \
    return circle::BuiltinOptions_##TYPE;
#include "TFLBuiltinOptions.lst"
#undef TFL_BUILTIN_OPTIONS
    default:
      throw std::runtime_error("tflite2circle: wrong builtin options type.");
  }
}

} // namespace tflite2circle