blob: 567c05cac96febccaef11faccd524e55144f6cd5 [file] [log] [blame]
Tim Hall79d07d22020-04-27 18:20:16 +01001# Copyright (C) 2020 Arm Limited or its affiliates. All rights reserved.
2#
3# SPDX-License-Identifier: Apache-2.0
4#
5# Licensed under the Apache License, Version 2.0 (the License); you may
6# not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an AS IS BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
Tim Hall79d07d22020-04-27 18:20:16 +010016# Description:
17# The SupportedOperators class which is a collection of all supported operators and parameter checks.
Charles Xu87c13502020-08-06 12:17:26 +020018import numpy as np
19
Tim Hallc30f4952020-06-15 20:47:35 +010020from .data_type import BaseType
21from .data_type import DataType
Tim Hall79d07d22020-04-27 18:20:16 +010022
23
24class SupportedOperators:
Fredrik Svedberga0c36242020-06-03 15:43:31 +020025 def __init__(self, softmax_support):
26 self.softmax_support = softmax_support
Tim Hall79d07d22020-04-27 18:20:16 +010027 # Categorised lists of supported operators
Fredrik Svedberga0c36242020-06-03 15:43:31 +020028 self.npu_pre_ops = set(("QuantizedResizeBilinear", "SplitSliceRead",))
29 self.convolution_ops = set(("Conv2DBiasAct", "Conv2D", "QuantizedConv2D",))
Tim Hall79d07d22020-04-27 18:20:16 +010030 self.depthwise_convolution_ops = set(
Fredrik Svedberga0c36242020-06-03 15:43:31 +020031 ("DepthwiseConv2dBiasAct", "DepthwiseConv2dNative", "QuantizedDepthwiseConv2D,")
Tim Hall79d07d22020-04-27 18:20:16 +010032 )
Jacob Bohlincf7da102020-05-20 09:03:40 +020033 self.transpose_convolution_ops = set(("Conv2DBackpropInput",))
Fredrik Svedberga0c36242020-06-03 15:43:31 +020034 self.max_pooling_ops = set(("QuantizedMaxPool", "MaxPool", "MaxPoolAct",))
35 self.avg_pooling_ops = set(("QuantizedAvgPool", "AvgPool", "AvgPoolAct",))
36 self.pooling_ops = set(("ReduceSum",)) | self.max_pooling_ops | self.avg_pooling_ops
Dwight Lidman42fed942020-05-29 09:37:03 +020037 self.resizing_ops = set(("ResizeBilinear",))
Fredrik Svedberga0c36242020-06-03 15:43:31 +020038 self.fc_vector_products = set(("QuantizedMatMul", "MatMul", "FullyConnectedAct",))
Tim Hall79d07d22020-04-27 18:20:16 +010039 self.mac_main_ops = (
40 # convolutions
41 self.convolution_ops
42 # depth-wise convolutions
43 | self.depthwise_convolution_ops
Jacob Bohlincf7da102020-05-20 09:03:40 +020044 # transpose convolutions
45 | self.transpose_convolution_ops
Tim Hall79d07d22020-04-27 18:20:16 +010046 # pooling
47 | self.pooling_ops
Dwight Lidman42fed942020-05-29 09:37:03 +020048 # resizing/upscaling
49 | self.resizing_ops
Tim Hall79d07d22020-04-27 18:20:16 +010050 # FC layers
51 | self.fc_vector_products
52 # RNN/LSTM/GRU
Fredrik Svedberga0c36242020-06-03 15:43:31 +020053 | set(("BlockLSTM",))
Tim Hall79d07d22020-04-27 18:20:16 +010054 )
Fredrik Svedberga0c36242020-06-03 15:43:31 +020055 self.unary_elem_wise_main_ops = set(("LeakyRelu", "Abs", "CLZ",))
56 self.binary_elem_wise_min_max_ops = set(("Minimum", "Maximum",))
Fredrik Svedberg597fd3f2020-08-13 10:02:53 +020057 self.binary_elem_wise_shift_ops = set(("SHL", "SHR",))
Fredrik Svedberg388e9c22020-05-25 16:32:00 +020058 self.binary_elem_wise_add_mul_sub = set(
Fredrik Svedberg1575b942020-08-18 13:19:18 +020059 ("AddAct", "MulAct", "SubAct", "QuantizedAdd", "QuantizedSub", "QuantizedMul", "Mul", "Add", "Sub",)
Tim Hall79d07d22020-04-27 18:20:16 +010060 )
Fredrik Svedberg1575b942020-08-18 13:19:18 +020061 self.binary_elem_wise_main_ops = (
62 self.binary_elem_wise_min_max_ops | self.binary_elem_wise_add_mul_sub | self.binary_elem_wise_shift_ops
63 )
Dwight Lidmanf995db72020-04-27 11:15:12 +020064 self.elem_wise_main_ops = self.binary_elem_wise_main_ops | self.unary_elem_wise_main_ops
Tim Hall79d07d22020-04-27 18:20:16 +010065 self.activation_ops = set(
Fredrik Svedberga0c36242020-06-03 15:43:31 +020066 (
67 "QuantizedRelu",
68 "QuantizedRelu1",
69 "QuantizedRelu6",
70 "Relu",
71 "Relu6",
72 "ReluN1To1",
73 "Sigmoid",
74 "Tanh",
75 "Softmax",
76 )
Tim Hall79d07d22020-04-27 18:20:16 +010077 )
78 self.npu_post_ops = (
79 # activation functions
80 self.activation_ops
81 # concatenation write direction
Fredrik Svedberga0c36242020-06-03 15:43:31 +020082 | set(("ConcatSliceWrite",))
Tim Hall79d07d22020-04-27 18:20:16 +010083 # bias add and batch norm
Fredrik Svedberga0c36242020-06-03 15:43:31 +020084 | set(("QuantizedBiasAdd", "Requantize", "QuantizedBatchNorm", "BiasAdd", "FusedBatchNorm",))
Jacob Bohlin9fbc4912020-06-29 11:58:50 +020085 # Quantization
86 | set(("Quantize",))
Tim Hall79d07d22020-04-27 18:20:16 +010087 )
Fredrik Svedberga0c36242020-06-03 15:43:31 +020088 self.split_ops = set(("Split", "SplitV", "StridedSlice", "Slice", "UnpackReshaped", "Unpack",))
89 self.concat_ops = set(("Concat", "ConcatV2", "QuantizedConcat", "ConcatTFLite", "PackReshaped", "Pack",))
Tim Hall79d07d22020-04-27 18:20:16 +010090 self.memory_only_ops = (
Fredrik Svedberga0c36242020-06-03 15:43:31 +020091 set(("Squeeze", "Reshape", "QuantizedReshape", "ExpandDims",)) | self.concat_ops | self.split_ops
Tim Hall79d07d22020-04-27 18:20:16 +010092 )
Dwight Lidman7579c752020-08-24 16:05:47 +020093 self.shapeless_input_ops = self.binary_elem_wise_main_ops | set(("Split", "SplitV",))
Fredrik Svedberga0c36242020-06-03 15:43:31 +020094 self.supported_fused_activations = set(("Relu", "Relu6", "ReluN1To1", "Tanh", "Sigmoid", "LUT",))
Tim Hall79d07d22020-04-27 18:20:16 +010095 self.supported_operators = (
96 self.npu_pre_ops | self.mac_main_ops | self.elem_wise_main_ops | self.npu_post_ops | self.memory_only_ops
97 )
98 # Setup supported operator restriction checkers
99 self.supported_operator_restrictions = {}
100 self.supported_operator_restrictions.update(
101 {op: self.check_convolution_restrictions for op in self.convolution_ops}
102 )
103 self.supported_operator_restrictions.update(
104 {op: self.check_depthwise_convolution_restrictions for op in self.depthwise_convolution_ops}
105 )
Jacob Bohlincf7da102020-05-20 09:03:40 +0200106 self.supported_operator_restrictions.update(
107 {op: self.check_transpose_convolution_restrictions for op in self.transpose_convolution_ops}
108 )
Tim Hall79d07d22020-04-27 18:20:16 +0100109 self.supported_operator_restrictions.update({op: self.check_pooling_restrictions for op in self.pooling_ops})
Dwight Lidman42fed942020-05-29 09:37:03 +0200110 self.supported_operator_restrictions.update({op: self.check_resize_restrictions for op in self.resizing_ops})
Tim Hall79d07d22020-04-27 18:20:16 +0100111 self.supported_operator_restrictions.update(
112 {op: self.check_vector_product_restrictions for op in self.fc_vector_products}
113 )
114 self.supported_operator_restrictions.update(
115 {op: self.check_element_wise_restrictions for op in self.elem_wise_main_ops}
116 )
117 self.supported_operator_restrictions.update(
118 {op: self.check_memory_only_restrictions for op in self.memory_only_ops}
119 )
Dwight Lidmanebe26c72020-06-09 11:40:54 +0200120 self.supported_operator_restrictions.update(
Tim Halle3786ac2020-07-28 17:40:50 +0100121 {op: self.check_quantization_restrictions_binary_elem_wise for op in self.binary_elem_wise_min_max_ops}
Dwight Lidmanebe26c72020-06-09 11:40:54 +0200122 )
Fredrik Svedberga0c36242020-06-03 15:43:31 +0200123 self.supported_operator_restrictions.update({op: self.check_activation_ops for op in self.activation_ops})
Tim Hall79d07d22020-04-27 18:20:16 +0100124
125 def is_operator_supported(self, op):
126 if op.type not in self.supported_operators:
127 return False
128 if not self.check_generic_restrictions(op):
129 return False
130 if op.type in self.supported_operator_restrictions:
131 return self.supported_operator_restrictions[op.type](op)
132 return True
133
134 def check_generic_restrictions(self, op):
135 # check fully defined shapes
Dwight Lidman25733112020-08-17 11:56:10 +0200136 for t in op.inputs:
Jacob Bohlin67e0d8f2020-08-20 10:53:02 +0200137 if not t:
138 continue
Tim Hall79d07d22020-04-27 18:20:16 +0100139 if not t.has_fully_defined_shape():
Dwight Lidman25733112020-08-17 11:56:10 +0200140 print("Warning:", op.type, "has input(s) of undefined shape, placing on CPU")
141 return False
Dwight Lidman7579c752020-08-24 16:05:47 +0200142 if t.shape == [] and op.type not in self.shapeless_input_ops:
Jacob Bohlin67e0d8f2020-08-20 10:53:02 +0200143 print(
144 "Warning:",
145 op.type,
146 "has input(s) of shape [].",
147 "Scalar input or broadcasting is not supported for this operator,",
148 "placing on CPU",
149 )
Dwight Lidman25733112020-08-17 11:56:10 +0200150 return False
151 for t in op.outputs:
152 if not t.has_fully_defined_shape():
153 print("Warning:", op.type, "has output(s) of undefined shape, placing on CPU")
154 return False
155 if t.shape == []:
Jacob Bohlin67e0d8f2020-08-20 10:53:02 +0200156 print(
157 "Warning:",
158 op.type,
159 "has output(s) of shape [].",
160 "Scalar input or broadcasting is not supported for this operator,",
161 "placing on CPU",
162 )
Tim Hall79d07d22020-04-27 18:20:16 +0100163 return False
164
165 # check data type
166 tensors = [t for t in op.get_ifm_ifm2_weights_ofm() if t is not None]
167 if not tensors:
168 tensors = op.inputs
169 for t in tensors:
170 if not (t.dtype.type & BaseType.Int):
171 return False
Fredrik Svedberga0c36242020-06-03 15:43:31 +0200172 if (
173 t.element_size() > 2
Fredrik Svedberg1575b942020-08-18 13:19:18 +0200174 and op.type
175 not in set(("Requantize", "ReduceSum", "CLZ",))
176 | self.binary_elem_wise_add_mul_sub
177 | self.binary_elem_wise_shift_ops
Fredrik Svedberga0c36242020-06-03 15:43:31 +0200178 ):
Tim Hall79d07d22020-04-27 18:20:16 +0100179 return False
180 # check size
181 if any(dim > 65536 for dim in t.shape):
182 return False
183
184 # check fused activations
185 if (
186 "fused_activation_function" in op.attrs
187 and op.attrs["fused_activation_function"] is not None
188 and op.attrs["fused_activation_function"] not in self.supported_fused_activations
189 ):
190 return False
191 return True
192
193 def check_convolution_restrictions(self, op):
194 # check stride
Dwight Lidman0538a772020-05-06 14:09:17 +0200195 if op.attrs["stride_w"] > 3 or op.attrs["stride_h"] > 3:
Tim Hall79d07d22020-04-27 18:20:16 +0100196 return False
197
198 # check dilation
199 dilation_w_factor = op.attrs.get("dilation_w_factor", 1)
200 dilation_h_factor = op.attrs.get("dilation_h_factor", 1)
201 if dilation_w_factor > 2 or dilation_h_factor > 2:
202 return False
203
204 # check data type
205 ifm_tensor, _, weight_tensor, _ = op.get_ifm_ifm2_weights_ofm()
206 if weight_tensor.element_size() > 1:
207 return False
208
Andreas Nevalainenf0c59bf2020-08-26 10:56:23 +0200209 # check kernel size [HWIO]
210 dilated_weight_w = weight_tensor.shape[1] + (weight_tensor.shape[1] - 1) * (dilation_w_factor - 1)
211 dilated_weight_h = weight_tensor.shape[0] + (weight_tensor.shape[0] - 1) * (dilation_h_factor - 1)
212
213 if dilated_weight_w > 64 or dilated_weight_h > 64:
214 return False
215
216 # check weight sums over [HWI]
217 zero_point = weight_tensor.quantization.zero_point
218 quant_weights = weight_tensor.quant_values.astype(np.int64)
219 weights = quant_weights - zero_point
220 totals = np.sum(np.absolute(weights), axis=(0, 1, 2))
221
222 if np.amax(totals) > 127 * 65536:
Tim Hall79d07d22020-04-27 18:20:16 +0100223 return False
224
225 # check batch size
226 if ifm_tensor.shape[0] != 1:
227 return False
228 return True
229
230 def check_depthwise_convolution_restrictions(self, op):
231 # check depth
232 ifm_tensor, _, _, ofm_tensor = op.get_ifm_ifm2_weights_ofm()
233 if op.attrs["depth_multiplier"] > 1 and not (
234 (ifm_tensor.shape[3] == 1) and (ofm_tensor.shape[3] == op.attrs["depth_multiplier"])
235 ):
236 return False
237 return self.check_convolution_restrictions(op)
238
Jacob Bohlincf7da102020-05-20 09:03:40 +0200239 def check_transpose_convolution_restrictions(self, op):
240 # check stride
241 stride_h, stride_w = op.attrs["stride_h"], op.attrs["stride_w"]
242 if stride_h != stride_w != 2:
243 return False
244
245 # check output dimensions
246 ifm_tensor, weight_tensor, _, ofm_tensor = op.get_ifm_weights_biases_ofm()
247 ifm_h, ifm_w = ifm_tensor.shape[1], ifm_tensor.shape[2]
248 ofm_h, ofm_w = ofm_tensor.shape[1], ofm_tensor.shape[2]
249 if op.attrs["padding"] == b"SAME":
250 if (ofm_h != ifm_h * stride_h) or (ofm_w != ifm_w * stride_w):
251 return False
252 elif op.attrs["padding"] == b"VALID":
253 kernel_h, kernel_w = weight_tensor.shape[0], weight_tensor.shape[1]
Tim Hallc30f4952020-06-15 20:47:35 +0100254 if (ofm_h != (ifm_h) * stride_h + max(kernel_h - stride_h, 0)) or (
255 ofm_w != (ifm_w) * stride_w + max(kernel_w - stride_w, 0)
256 ):
Jacob Bohlincf7da102020-05-20 09:03:40 +0200257 return False
258
259 return self.check_convolution_restrictions(op)
260
Tim Hall79d07d22020-04-27 18:20:16 +0100261 def check_pooling_restrictions(self, op):
262 # check stride
Dwight Lidman0538a772020-05-06 14:09:17 +0200263 if op.attrs["stride_w"] > 3 or op.attrs["stride_h"] > 3:
Tim Hall79d07d22020-04-27 18:20:16 +0100264 return False
265
266 # check data type
267 ifm_tensor, _, _, ofm_tensor = op.get_ifm_ifm2_weights_ofm()
268 if ifm_tensor.dtype != ofm_tensor.dtype:
Fredrik Svedberga0c36242020-06-03 15:43:31 +0200269 if op.type != "ReduceSum":
270 return False
271 # TODO: else check ReduceSum restrictions.
Tim Hall79d07d22020-04-27 18:20:16 +0100272
273 # check batch size
274 if ifm_tensor.shape[0] != 1:
275 return False
276
277 if op.type in self.avg_pooling_ops:
278 # check kernel size
279 if op.attrs["padding"] == b"SAME" and (op.attrs["filter_width"] > 8 or op.attrs["filter_height"] > 8):
280 return False
Tim Hallc30f4952020-06-15 20:47:35 +0100281 if op.attrs["padding"] == b"VALID" and (
282 op.attrs["filter_width"] * op.attrs["filter_height"] > 256 * 256 or op.attrs["filter_height"] > 256
283 ):
Tim Hall79d07d22020-04-27 18:20:16 +0100284 return False
285
286 if op.type in self.max_pooling_ops:
Fredrik Svedberg388e9c22020-05-25 16:32:00 +0200287 # check kernel size (any padding)
288 if op.attrs["filter_width"] * op.attrs["filter_height"] > 256 * 256 or op.attrs["filter_height"] > 256:
Tim Hall79d07d22020-04-27 18:20:16 +0100289 return False
290 return True
291
Dwight Lidman42fed942020-05-29 09:37:03 +0200292 def check_resize_restrictions(self, op):
293 # check unsupported upscaling factor
294 if op.type == "ResizeBilinear":
Charles Xu9a03fdf2020-07-02 15:12:40 +0200295 if op.inputs[0].shape[1] == 1 and op.inputs[0].shape[2] == 1:
296 return True
Charles Xu36ffaf32020-08-05 15:40:44 +0200297 if op.inputs[0].shape == op.outputs[0].shape:
298 return True
Charles Xu87c13502020-08-06 12:17:26 +0200299 upscaled_shape = np.array(op.inputs[0].shape[1:3])
300 out_shape = np.array(op.outputs[0].shape[1:3])
301 while (upscaled_shape < out_shape).all():
302 upscaled_shape *= 2
303 if op.attrs["align_corners"]:
304 upscaled_shape -= 1
305 if np.array_equal(out_shape, upscaled_shape):
306 return True
307 return False
Dwight Lidman42fed942020-05-29 09:37:03 +0200308
Tim Hall79d07d22020-04-27 18:20:16 +0100309 def check_vector_product_restrictions(self, op):
310 # check data type
311 ifm_tensor, _, weight_tensor, _ = op.get_ifm_ifm2_weights_ofm()
312 if weight_tensor.element_size() > 1:
313 return False
314
315 return True
316
317 def check_element_wise_restrictions(self, op):
318 # check data type
319 ifm_tensor, ifm2_tensor, _, ofm_tensor = op.get_ifm_ifm2_weights_ofm()
Fredrik Svedberg388e9c22020-05-25 16:32:00 +0200320 # input and output datatype must match for these operators
Tim Hallc30f4952020-06-15 20:47:35 +0100321 if (
322 op.type in self.binary_elem_wise_min_max_ops | self.unary_elem_wise_main_ops
323 and ifm_tensor.dtype != ofm_tensor.dtype
324 ):
Tim Hall79d07d22020-04-27 18:20:16 +0100325 return False
Tim Hallc30f4952020-06-15 20:47:35 +0100326 if op.type in self.binary_elem_wise_add_mul_sub:
Fredrik Svedberg388e9c22020-05-25 16:32:00 +0200327 # both inputs must have same type
Tim Hallc30f4952020-06-15 20:47:35 +0100328 if ifm_tensor.dtype != ifm2_tensor.dtype:
Fredrik Svedberg388e9c22020-05-25 16:32:00 +0200329 return False
330 # signed input check
Tim Hallc30f4952020-06-15 20:47:35 +0100331 if ifm_tensor.dtype.type & BaseType.Signed:
Fredrik Svedberg388e9c22020-05-25 16:32:00 +0200332 # output must be signed
Tim Hallc30f4952020-06-15 20:47:35 +0100333 if ofm_tensor.dtype.type & BaseType.Unsigned:
Fredrik Svedberg388e9c22020-05-25 16:32:00 +0200334 return False
335 # and 8, 16 or 32-bit
Tim Hallc30f4952020-06-15 20:47:35 +0100336 if ofm_tensor.element_size() not in (1, 2, 4):
Fredrik Svedberg388e9c22020-05-25 16:32:00 +0200337 return False
338 # unsigned input check, output must be same type or int32
Tim Hallc30f4952020-06-15 20:47:35 +0100339 if ifm_tensor.dtype.type & BaseType.Unsigned and not (
340 ifm_tensor.dtype == ofm_tensor.dtype or ofm_tensor.dtype == DataType.int32
341 ):
Fredrik Svedberg388e9c22020-05-25 16:32:00 +0200342 return False
Fredrik Svedberg597fd3f2020-08-13 10:02:53 +0200343 elif op.type in self.binary_elem_wise_shift_ops | set(("CLZ")):
344 if ifm_tensor.dtype != DataType.int32 or ifm2_tensor.dtype != DataType.int32:
345 return False
346 if op.type in ("CLZ", "SHL") and ofm_tensor.dtype != DataType.int32:
347 return False
Tim Hall79d07d22020-04-27 18:20:16 +0100348
349 # check batch size
Dwight Lidmanf995db72020-04-27 11:15:12 +0200350 if len(ifm_tensor.shape) > 2 and ifm_tensor.shape[0] != 1:
Tim Hallc30f4952020-06-15 20:47:35 +0100351 return False
352 if op.type in self.binary_elem_wise_main_ops: # if op type is unary, ifm2_tensor is None
Dwight Lidmanf995db72020-04-27 11:15:12 +0200353 if len(ifm2_tensor.shape) > 2 and ifm2_tensor.shape[0] != 1:
354 return False
Dwight Lidman332a7042020-06-11 15:32:42 +0200355
356 # negative alpha values are not supported
357 if op.type == "LeakyRelu" and op.attrs["alpha"] < 0:
358 return False
359
Tim Hall79d07d22020-04-27 18:20:16 +0100360 return True
361
362 def check_memory_only_restrictions(self, op):
Tim Hall79d07d22020-04-27 18:20:16 +0100363 if op.type == "StridedSlice":
Patrik Gustavssoncf728902020-04-30 08:57:23 +0200364 # check stride size
Tim Hall79d07d22020-04-27 18:20:16 +0100365 if len(op.inputs) > 3 and any(stride != 1 for stride in op.inputs[3].values):
366 return False
Michael McGeaghecd20522020-07-31 16:59:45 +0100367 # check "end - begin" doesnt result in any zero or negative elements
368 if any((end - begin) <= 0 for begin, end in zip(op.inputs[1].values, op.inputs[2].values)):
369 return False
Patrik Gustavssoncf728902020-04-30 08:57:23 +0200370 # check ellipsis_mask
371 if op.attrs["ellipsis_mask"] != 0:
372 return False
373 # check if both new_axis_mask and shrink_axis_mask have bit set
374 if op.attrs["new_axis_mask"] != 0 and op.attrs["shrink_axis_mask"] != 0:
375 return False
Tim Hall79d07d22020-04-27 18:20:16 +0100376 return True
Dwight Lidmanebe26c72020-06-09 11:40:54 +0200377
Tim Halle3786ac2020-07-28 17:40:50 +0100378 def check_quantization_restrictions_binary_elem_wise(self, op):
Dwight Lidmanebe26c72020-06-09 11:40:54 +0200379 # makes sure IFM1, IFM2 and OFM quantization are equal for binary ops
Tim Halle3786ac2020-07-28 17:40:50 +0100380 assert len(op.inputs) >= 2 and len(op.outputs) == 1
381
Fredrik Svedberga0c36242020-06-03 15:43:31 +0200382 if (
Tim Halle3786ac2020-07-28 17:40:50 +0100383 op.inputs[0].quantization is None
384 or not op.inputs[0].quantization.is_scaling_equal(op.inputs[1].quantization)
385 or not op.inputs[0].quantization.is_scaling_equal(op.outputs[0].quantization)
Fredrik Svedberga0c36242020-06-03 15:43:31 +0200386 ):
387 print(
388 "Warning: Input/output tensors with different quantization is unsupported for the", op.type, "operator"
389 )
Dwight Lidmanebe26c72020-06-09 11:40:54 +0200390 return False
Tim Halle3786ac2020-07-28 17:40:50 +0100391
Fredrik Svedberga0c36242020-06-03 15:43:31 +0200392 return True
393
394 def check_activation_ops(self, op):
395 if op.type == "Softmax":
396 if not self.softmax_support:
397 return False
398
399 ifm_tensor = op.inputs[0]
400 ofm_tensor = op.outputs[0]
401
402 # check data type
403 if ifm_tensor.dtype != ofm_tensor.dtype:
404 return False
405
Fredrik Svedberg597fd3f2020-08-13 10:02:53 +0200406 if ifm_tensor.dtype not in (DataType.uint8, DataType.int8, DataType.int16):
407 return False
Fredrik Svedberga0c36242020-06-03 15:43:31 +0200408
409 # check batch size
410 if len(ifm_tensor.shape) in (2, 4) and ifm_tensor.shape[0] != 1:
411 return False
412
413 return True