blob: f1e8f28fead16652b278728e088e729bc94da7a8 [file] [log] [blame]
Louis Verhaardfa2f92a2020-09-21 11:56:18 +02001# 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.
16#
17# Description:
18# Unit tests for support_operators
Michael McGeagh37ded342020-10-01 15:37:44 +010019import numpy as np
20
Louis Verhaardfa2f92a2020-09-21 11:56:18 +020021from ethosu.vela.data_type import DataType
Louis Verhaarde8a5a782020-11-02 18:04:27 +010022from ethosu.vela.operation import ActivationFunction
Louis Verhaardaee5d752020-09-30 09:01:52 +020023from ethosu.vela.operation import Op
Michael McGeagh16895482020-12-14 15:51:20 +000024from ethosu.vela.operation import Padding
Louis Verhaardfa2f92a2020-09-21 11:56:18 +020025from ethosu.vela.supported_operators import SupportedOperators
26from ethosu.vela.tensor import create_const_tensor
Michael McGeagh37ded342020-10-01 15:37:44 +010027from ethosu.vela.tensor import QuantizationParameters
Louis Verhaardfa2f92a2020-09-21 11:56:18 +020028from ethosu.vela.tensor import Tensor
29from ethosu.vela.test import testutil
30
31support = SupportedOperators()
32
33
Michael McGeagh65fd9982020-10-20 11:49:28 +010034def test_constraint_tens_no_dynamic():
35 # Tensors cannot be dynamic (no shape, not a scalar)
36 op = testutil.create_op_with_quant_tensors(Op.Relu, [1, 8, 8, 8], [])
Louis Verhaardfa2f92a2020-09-21 11:56:18 +020037 assert not support.is_operator_supported(op)
Michael McGeagh37ded342020-10-01 15:37:44 +010038
39
40def test_constraint_tens_defined_shape():
41 # Tensors cannot have None in them
Michael McGeagh1f951fc2020-10-14 09:30:02 +010042 op = testutil.create_op_with_quant_tensors(Op.Relu, [1, 8, None, 8], [1, 8, 8, 8])
Michael McGeagh37ded342020-10-01 15:37:44 +010043 assert not support.is_operator_supported(op)
44
45
Michael McGeagh65fd9982020-10-20 11:49:28 +010046def test_constraint_tens_output_scalar():
47 # Scalar output is not allowed at all:
Michael McGeagh1f951fc2020-10-14 09:30:02 +010048 op = testutil.create_elemwise_op(Op.Mul, "op", [1, 8, 8, 8], [1, 8, 8, 8], [])
Michael McGeagh65fd9982020-10-20 11:49:28 +010049 op.ofm.values = 0.5
Michael McGeagh37ded342020-10-01 15:37:44 +010050 assert not support.is_operator_supported(op)
Michael McGeagh184b2502020-10-09 17:19:52 +010051
52
Michael McGeagh65fd9982020-10-20 11:49:28 +010053def test_constraint_tens_input_scalar():
Michael McGeagh184b2502020-10-09 17:19:52 +010054 # Shapeless input is allowed if its of a certain type:
Michael McGeagh1f951fc2020-10-14 09:30:02 +010055 op = testutil.create_elemwise_op(Op.Mul, "op", [1, 8, 8, 8], [], [1, 8, 8, 8])
Michael McGeagh184b2502020-10-09 17:19:52 +010056 assert support.is_operator_supported(op)
Michael McGeagh37ded342020-10-01 15:37:44 +010057 # Invalid shapeless input due to op type:
Michael McGeagh1f951fc2020-10-14 09:30:02 +010058 op = testutil.create_op_with_quant_tensors(Op.Relu, [], [1, 8, 8, 8])
Michael McGeagh65fd9982020-10-20 11:49:28 +010059 op.ifm.values = 0.5
Michael McGeagh37ded342020-10-01 15:37:44 +010060 assert not support.is_operator_supported(op)
61
62
63def test_constraint_tens_shape_size():
64 # Tensors cannot be > 4D
patrik.gustavssoneeb85152020-12-21 17:10:40 +000065 op = testutil.create_op_with_quant_tensors(Op.Relu, [1, 1, 8, 8, 8], [1, 1, 8, 8, 8], set_ifm_ofm_shapes=False)
Michael McGeagh37ded342020-10-01 15:37:44 +010066 assert not support.is_operator_supported(op)
67
68
69def test_constraint_tens_dtype():
Michael McGeagh184b2502020-10-09 17:19:52 +010070 # Tensors can only be of type uint8, int8, int16 and int32
Michael McGeagh1f951fc2020-10-14 09:30:02 +010071 op = testutil.create_op_with_quant_tensors(Op.Relu, [1, 8, 8, 8], [1, 8, 8, 8], datatype=DataType.float32)
Michael McGeagh37ded342020-10-01 15:37:44 +010072 assert not support.is_operator_supported(op)
Michael McGeagh184b2502020-10-09 17:19:52 +010073
74
75def test_constraint_tens_int32_ops():
Michael McGeagh37ded342020-10-01 15:37:44 +010076 # For int32, only select op types are allowed:
Michael McGeagh1f951fc2020-10-14 09:30:02 +010077 op = testutil.create_elemwise_op(Op.Mul, "op", [1, 8, 8, 8], [], [1, 8, 8, 8], datatype=DataType.int32)
Michael McGeagh37ded342020-10-01 15:37:44 +010078 assert support.is_operator_supported(op)
Michael McGeagh1f951fc2020-10-14 09:30:02 +010079 op = testutil.create_op_with_quant_tensors(Op.Relu, [1, 8, 8, 8], [1, 8, 8, 8], datatype=DataType.int32)
Michael McGeagh37ded342020-10-01 15:37:44 +010080 assert not support.is_operator_supported(op)
81
82
83def test_constraint_tens_dimension():
84 # Tensors can only have values in the inclusive range of 1-65535
Michael McGeagh1f951fc2020-10-14 09:30:02 +010085 op = testutil.create_op_with_quant_tensors(Op.Relu, [1, 8, 8, 0], [1, 8, 8, 65536])
Michael McGeagh37ded342020-10-01 15:37:44 +010086 assert not support.is_operator_supported(op)
87
88
Michael McGeagh184b2502020-10-09 17:19:52 +010089def test_constraint_tens_quant_none_check():
90 # Tensors must have quantization parameters
Michael McGeagh1f951fc2020-10-14 09:30:02 +010091 op = testutil.create_elemwise_op(Op.Mul, "op", [1, 8, 8, 8], [], [1, 8, 8, 8], ifm2_quant=None)
Michael McGeagh184b2502020-10-09 17:19:52 +010092 assert not support.is_operator_supported(op)
93
94
95def test_constraint_tens_quant_scale():
96 # Quantization scale cannot be infinit
97 qp = QuantizationParameters()
Michael McGeagh65fd9982020-10-20 11:49:28 +010098 qp.zero_point = 0
Michael McGeagh184b2502020-10-09 17:19:52 +010099 qp.scale_f32 = np.inf
Michael McGeagh1f951fc2020-10-14 09:30:02 +0100100 op = testutil.create_elemwise_op(Op.Mul, "op", [1, 8, 8, 8], [], [1, 8, 8, 8], ifm_quant=qp)
Michael McGeagh184b2502020-10-09 17:19:52 +0100101 assert not support.is_operator_supported(op)
102
103
Dwight Lidmanc7187432020-11-16 17:40:46 +0100104def test_constraint_tens_quant_per_axis_not_supp():
105 # Quantization scale cannot be array-valued for elemwise ops
106 qp = QuantizationParameters()
107 qp.zero_point = np.zeros((1, 3))
108 qp.scale_f32 = np.ones((1, 3))
109 op = testutil.create_elemwise_op(Op.Mul, "op", [1, 8, 8, 8], [], [1, 8, 8, 8], ifm_quant=qp)
110 assert not support.is_operator_supported(op)
111
112
113def test_constraint_tens_quant_per_axis_is_supp():
114 op = testutil.create_op_with_quant_tensors(
115 Op.Conv2DBias, [1, 1, 1, 3], [1, 1, 1, 3], weights_shape=[1, 1, 1, 3], bias_shape=[1, 1, 1, 3]
116 )
117 op.attrs = {"stride_w": 1, "stride_h": 1}
118 assert support.is_operator_supported(op)
119 qp = QuantizationParameters()
120 qp.zero_point = np.zeros((1, 3))
121 qp.scale_f32 = np.ones((1, 3))
122 op.bias.quantization = qp
123 assert support.is_operator_supported(op)
124
125
Dwight Lidman0dd21c72020-11-24 13:45:50 +0100126def test_constraint_fc_output_2d_not_supp():
127 op = testutil.create_op_with_quant_tensors(Op.FullyConnected, [12, 1], [3, 2, 2, 1], weights_shape=[12, 1, 1, 1])
128 assert not support.is_operator_supported(op)
129 op = testutil.create_op_with_quant_tensors(Op.FullyConnected, [12, 1, 1, 1], [1, 3, 4], weights_shape=[12, 1, 1, 1])
130 assert not support.is_operator_supported(op)
131 op = testutil.create_op_with_quant_tensors(Op.FullyConnected, [1, 1, 1, 1], [1], weights_shape=[1, 1, 1, 1])
132 assert not support.is_operator_supported(op)
133
134
135def test_constraint_fc_output_2d_is_supp():
136 op = testutil.create_op_with_quant_tensors(Op.FullyConnected, [4, 8, 8, 4], [32, 32], weights_shape=[4, 8, 8, 4])
137 assert support.is_operator_supported(op)
138 op = testutil.create_op_with_quant_tensors(Op.FullyConnected, [1, 1024], [16, 64], weights_shape=[1, 1024])
139 assert support.is_operator_supported(op)
140
141
Michael McGeagh37ded342020-10-01 15:37:44 +0100142def test_constraint_faf():
143 # Fused activation functions, if set, must be a valid op type
Michael McGeagh1f951fc2020-10-14 09:30:02 +0100144 op = testutil.create_op_with_quant_tensors(Op.Relu, [1, 8, 8, 8], [1, 8, 8, 8])
Louis Verhaarde8a5a782020-11-02 18:04:27 +0100145 op.activation = ActivationFunction(Op.Conv2D)
Michael McGeagh37ded342020-10-01 15:37:44 +0100146 assert not support.is_operator_supported(op)
Michael McGeagh1f951fc2020-10-14 09:30:02 +0100147
148
149def test_constraint_conv_pass():
150 # First test a simple conv passes
151 op = testutil.create_op_with_quant_tensors(Op.Conv2D, [1, 1, 1, 1], [1, 1, 1, 1], weights_shape=[1, 1, 1, 1])
152 op.attrs = {"stride_w": 1, "stride_h": 1}
153 assert support.is_operator_supported(op)
154
155
156def test_constraint_stride_type():
157 # Stride width and height must be integer types
158 op = testutil.create_op_with_quant_tensors(Op.Conv2D, [1, 8, 8, 8], [1, 8, 8, 8])
159 op.attrs = {"stride_w": 1.5, "stride_h": "1"}
160 assert not support.is_operator_supported(op)
161
162
163def test_constraint_stride_range():
164 # Stride width and height must lie within a certain range
165 op = testutil.create_op_with_quant_tensors(Op.Conv2D, [1, 8, 8, 8], [1, 8, 8, 8])
166 op.attrs = {"stride_w": 0, "stride_h": 20}
167 assert not support.is_operator_supported(op)
168
169
170def test_constraint_dilation_type():
171 # Dilation width and height must be integer types
172 op = testutil.create_op_with_quant_tensors(Op.Conv2D, [1, 8, 8, 8], [1, 8, 8, 8])
173 op.attrs = {"stride_w": 1, "stride_h": 1, "dilation_w_factor": 1.5, "dilation_h_factor": "1"}
174 assert not support.is_operator_supported(op)
175
176
177def test_constraint_dilation_range():
178 # Dilation width and height must lie within a certain range
179 op = testutil.create_op_with_quant_tensors(Op.Conv2D, [1, 8, 8, 8], [1, 8, 8, 8])
180 op.attrs = {"stride_w": 1, "stride_h": 1, "dilation_w_factor": 0, "dilation_h_factor": 20}
181 assert not support.is_operator_supported(op)
182
183
184def test_constraint_dilated_height_range():
185 # Dilated kernel height must lie within a certain range
186 op = testutil.create_op_with_quant_tensors(Op.Conv2D, [1, 8, 8, 8], [1, 8, 8, 8], weights_shape=[65, 64, 1, 1])
187 op.attrs = {"stride_w": 1, "stride_h": 1}
188 assert not support.is_operator_supported(op)
189
190
191def test_constraint_dilated_product_range():
192 # Dilated kernel width x height must lie within a certain range
193 op = testutil.create_op_with_quant_tensors(Op.Conv2D, [1, 8, 8, 8], [1, 8, 8, 8], weights_shape=[64, 65, 1, 1])
194 op.attrs = {"stride_w": 1, "stride_h": 1}
195 assert not support.is_operator_supported(op)
196
197
198def test_constraint_weights_type():
199 # Weight tensor must be 8-bit
200 op = testutil.create_op_with_quant_tensors(
201 Op.Conv2D, [1, 8, 8, 8], [1, 8, 8, 8], weights_shape=[1, 1, 1, 1], datatype=DataType.int16
202 )
203 op.attrs = {"stride_w": 1, "stride_h": 1}
204 assert not support.is_operator_supported(op)
205
206
Michael McGeagh65fd9982020-10-20 11:49:28 +0100207def test_constraint_weights_const():
Michael McGeagh1f951fc2020-10-14 09:30:02 +0100208 # Weight tensor cannot be non-const tensors
209 op = testutil.create_op_with_quant_tensors(Op.Conv2D, [1, 8, 8, 8], [1, 8, 8, 8])
210 op.attrs = {"stride_w": 1, "stride_h": 1}
211 weights = Tensor([64, 64, 1, 1], DataType.uint8, "weights")
Michael McGeagh65fd9982020-10-20 11:49:28 +0100212 weights.quantization = testutil.default_quant_params()
Michael McGeagh1f951fc2020-10-14 09:30:02 +0100213 op.add_input_tensor(weights)
214 assert not support.is_operator_supported(op)
215
216
217def test_constraint_weights_limit():
218 # Sum of weights has a limit
219 op = testutil.create_op_with_quant_tensors(Op.Conv2D, [1, 8, 8, 8], [1, 8, 8, 8], weights_shape=[1, 1, 1, 1])
220 op.attrs = {"stride_w": 1, "stride_h": 1}
221 op.weights.quantization.zero_point = np.array([[[[(127 * 65536) + 1]]]])
222 assert not support.is_operator_supported(op)
223
224
225def test_constraint_bias_type():
226 # Bias must have a certain datatype
227 op = testutil.create_op_with_quant_tensors(Op.Conv2DBias, [1, 8, 8, 8], [1, 8, 8, 8], weights_shape=[1, 1, 1, 1])
228 op.attrs = {"stride_w": 1, "stride_h": 1}
229 bias = Tensor([1, 8, 8, 8], DataType.uint8, "bias")
230 op.add_input_tensor(bias)
231 assert not support.is_operator_supported(op)
232
233
234def test_constraint_bias_40bit():
235 # Bias must not exceed 40-bit
236 op = testutil.create_op_with_quant_tensors(Op.Conv2DBias, [1, 1, 1, 1], [1, 1, 1, 1], weights_shape=[1, 1, 1, 1])
237 op.attrs = {"stride_w": 1, "stride_h": 1}
238 bias = Tensor([1, 1, 1, 1], DataType.int64, "bias")
Michael McGeagh65fd9982020-10-20 11:49:28 +0100239 bias.quant_values = np.array([0x01FF_FFFF_FFFF])
Michael McGeagh1f951fc2020-10-14 09:30:02 +0100240 op.add_input_tensor(bias)
241 assert not support.is_operator_supported(op)
242
243
244def test_constraint_batch_size():
245 op = testutil.create_op_with_quant_tensors(Op.Conv2D, [2, 8, 8, 8], [1, 8, 8, 8], weights_shape=[1, 1, 1, 1])
246 op.attrs = {"stride_w": 1, "stride_h": 1}
247 assert not support.is_operator_supported(op)
Michael McGeagh65fd9982020-10-20 11:49:28 +0100248
249
250def test_constraint_quant_scale_inf():
251 op = testutil.create_op_with_quant_tensors(Op.Relu, [1, 8, 8, 8], [1, 8, 8, 8])
252 op.ofm.quantization.scale_f32 = np.float32(1e-39)
253 assert not support.is_operator_supported(op)
254
255
256def test_constraint_depth_multiplier():
257 # Valid. Depth multiplier is 1 so no further constraints
258 op = testutil.create_op_with_quant_tensors(
259 Op.DepthwiseConv2DBias, [1, 1, 1, 1], [1, 1, 1, 2], weights_shape=[1, 1, 1, 1]
260 )
261 op.attrs = {"stride_w": 1, "stride_h": 1, "depth_multiplier": 1}
262 assert support.is_operator_supported(op)
263 # Invalid. Depth multiplier doesnt equal ofm channel
264 op = testutil.create_op_with_quant_tensors(
265 Op.DepthwiseConv2DBias, [1, 1, 1, 1], [1, 1, 1, 1], weights_shape=[1, 1, 1, 1]
266 )
267 op.attrs = {"stride_w": 1, "stride_h": 1, "depth_multiplier": 2}
268 assert not support.is_operator_supported(op)
269 # Valid. Depth multiplier is equal to ofm channel
270 op = testutil.create_op_with_quant_tensors(
271 Op.DepthwiseConv2DBias, [1, 1, 1, 1], [1, 1, 1, 2], weights_shape=[1, 1, 1, 1]
272 )
273 op.attrs = {"stride_w": 1, "stride_h": 1, "depth_multiplier": 2}
274 assert support.is_operator_supported(op)
275
276
277def test_constraint_tconv_stride():
278 # Strides must be 2
279 op = testutil.create_op_with_quant_tensors(Op.Conv2DBackpropInput, [0], [1, 2, 2, 1], weights_shape=[1, 1, 1, 1])
Michael McGeagh16895482020-12-14 15:51:20 +0000280 op.attrs = {"stride_w": 1, "stride_h": 1, "padding": Padding.SAME}
Michael McGeagh65fd9982020-10-20 11:49:28 +0100281 ifm = Tensor([1, 1, 1, 1], DataType.uint8, "ifm")
282 ifm.quantization = testutil.default_quant_params()
283 op.add_input_tensor(ifm)
284 assert not support.is_operator_supported(op)
285
286
287def test_constraint_tconv_same():
288 # Valid
289 op = testutil.create_op_with_quant_tensors(Op.Conv2DBackpropInput, [0], [1, 2, 2, 1], weights_shape=[1, 1, 1, 1])
Michael McGeagh16895482020-12-14 15:51:20 +0000290 op.attrs = {"stride_w": 2, "stride_h": 2, "padding": Padding.SAME}
Michael McGeagh65fd9982020-10-20 11:49:28 +0100291 ifm = Tensor([1, 1, 1, 1], DataType.uint8, "ifm")
292 ifm.quantization = testutil.default_quant_params()
293 op.add_input_tensor(ifm)
294 assert support.is_operator_supported(op)
295 # Invalid
296 op = testutil.create_op_with_quant_tensors(Op.Conv2DBackpropInput, [0], [1, 4, 4, 1], weights_shape=[1, 1, 1, 1])
Michael McGeagh16895482020-12-14 15:51:20 +0000297 op.attrs = {"stride_w": 2, "stride_h": 2, "padding": Padding.SAME}
Michael McGeagh65fd9982020-10-20 11:49:28 +0100298 ifm = Tensor([1, 1, 1, 1], DataType.uint8, "ifm")
299 ifm.quantization = testutil.default_quant_params()
300 op.add_input_tensor(ifm)
301 assert not support.is_operator_supported(op)
302
303
304def test_constraint_tconv_valid():
305 # Valid
306 op = testutil.create_op_with_quant_tensors(Op.Conv2DBackpropInput, [0], [1, 4, 4, 1], weights_shape=[4, 4, 1, 1])
Michael McGeagh16895482020-12-14 15:51:20 +0000307 op.attrs = {"stride_w": 2, "stride_h": 2, "padding": Padding.VALID}
Michael McGeagh65fd9982020-10-20 11:49:28 +0100308 ifm = Tensor([1, 1, 1, 1], DataType.uint8, "ifm")
309 ifm.quantization = testutil.default_quant_params()
310 op.add_input_tensor(ifm)
311 assert support.is_operator_supported(op)
312 # Invalid
313 op = testutil.create_op_with_quant_tensors(Op.Conv2DBackpropInput, [0], [1, 4, 4, 1], weights_shape=[2, 2, 1, 1])
Michael McGeagh16895482020-12-14 15:51:20 +0000314 op.attrs = {"stride_w": 2, "stride_h": 2, "padding": Padding.VALID}
Michael McGeagh65fd9982020-10-20 11:49:28 +0100315 ifm = Tensor([1, 1, 1, 1], DataType.uint8, "ifm")
316 ifm.quantization = testutil.default_quant_params()
317 op.add_input_tensor(ifm)
318 assert not support.is_operator_supported(op)
319
320
321def test_constraint_matching_in_out_types():
322 # Valid
323 op = testutil.create_op_with_quant_tensors(Op.AvgPool, [1, 8, 8, 8], [1, 8, 8, 8])
Michael McGeagh16895482020-12-14 15:51:20 +0000324 op.attrs = {"stride_w": 2, "stride_h": 2, "filter_width": 2, "filter_height": 2, "padding": Padding.SAME}
Michael McGeagh65fd9982020-10-20 11:49:28 +0100325 assert support.is_operator_supported(op)
326 # Invalid. datatypes for ifm and ofm must match (default uint8)
327 op.ifm.dtype = DataType.int8
328 assert not support.is_operator_supported(op)
329
330
331def test_constraint_filter_type():
332 # Filter width/height must be integers
333 op = testutil.create_op_with_quant_tensors(Op.AvgPool, [1, 8, 8, 8], [1, 8, 8, 8])
Michael McGeagh16895482020-12-14 15:51:20 +0000334 op.attrs = {"stride_w": 2, "stride_h": 2, "filter_width": 2.5, "filter_height": "2", "padding": Padding.SAME}
Michael McGeagh65fd9982020-10-20 11:49:28 +0100335 assert not support.is_operator_supported(op)
336
337
338def test_constraint_filter_range():
339 # Avg pool restrictions are dependent on padding:
340 # SAME padding restricts both W and H to max 8
341 op = testutil.create_op_with_quant_tensors(Op.AvgPool, [1, 8, 8, 8], [1, 8, 8, 8])
Michael McGeagh16895482020-12-14 15:51:20 +0000342 op.attrs = {"stride_w": 2, "stride_h": 2, "filter_width": 20, "filter_height": 20, "padding": Padding.SAME}
Michael McGeagh65fd9982020-10-20 11:49:28 +0100343 assert not support.is_operator_supported(op)
344 # VALID padding limits are much larger
Michael McGeagh16895482020-12-14 15:51:20 +0000345 op.attrs["padding"] = Padding.VALID
Michael McGeagh65fd9982020-10-20 11:49:28 +0100346 assert support.is_operator_supported(op)
347
348
349def test_constraint_filter_height_range_valid_pad():
350 # Avg pool restrictions are dependent on padding:
351 op = testutil.create_op_with_quant_tensors(Op.AvgPool, [1, 8, 8, 8], [1, 8, 8, 8])
Michael McGeagh16895482020-12-14 15:51:20 +0000352 op.attrs = {"stride_w": 2, "stride_h": 2, "filter_width": 2, "filter_height": 256, "padding": Padding.VALID}
Michael McGeagh65fd9982020-10-20 11:49:28 +0100353 assert support.is_operator_supported(op)
354 # VALID padding restricts to 256 in filter height
355 op.attrs["filter_height"] = 257
356 assert not support.is_operator_supported(op)
357
358
359def test_constraint_filter_product_height_range_valid_pad():
360 # Avg pool restrictions are dependent on padding:
361 op = testutil.create_op_with_quant_tensors(Op.AvgPool, [1, 8, 8, 8], [1, 8, 8, 8])
Michael McGeagh16895482020-12-14 15:51:20 +0000362 op.attrs = {"stride_w": 2, "stride_h": 2, "filter_width": 256, "filter_height": 256, "padding": Padding.VALID}
Michael McGeagh65fd9982020-10-20 11:49:28 +0100363 assert support.is_operator_supported(op)
364 # VALID padding restricts filter W x H to 256x256
365 op.attrs["filter_width"] = 257
366 assert not support.is_operator_supported(op)
367
368
369def test_constraint_filter_height_range():
370 # Max pool restrictions arent dependent on padding
371 op = testutil.create_op_with_quant_tensors(Op.MaxPool, [1, 8, 8, 8], [1, 8, 8, 8])
Michael McGeagh16895482020-12-14 15:51:20 +0000372 op.attrs = {"stride_w": 2, "stride_h": 2, "filter_width": 2, "filter_height": 256, "padding": Padding.SAME}
Michael McGeagh65fd9982020-10-20 11:49:28 +0100373 assert support.is_operator_supported(op)
374 # Restricts to 256 in filter height
375 op.attrs["filter_height"] = 257
376 assert not support.is_operator_supported(op)
377 # Doesnt matter if SAME or VALID
Michael McGeagh16895482020-12-14 15:51:20 +0000378 op.attrs["padding"] = Padding.VALID
Michael McGeagh65fd9982020-10-20 11:49:28 +0100379 assert not support.is_operator_supported(op)
380
381
382def test_constraint_filter_product_height_range():
383 # Max pool restrictions arent dependent on padding
384 op = testutil.create_op_with_quant_tensors(Op.MaxPool, [1, 8, 8, 8], [1, 8, 8, 8])
Michael McGeagh16895482020-12-14 15:51:20 +0000385 op.attrs = {"stride_w": 2, "stride_h": 2, "filter_width": 256, "filter_height": 256, "padding": Padding.SAME}
Michael McGeagh65fd9982020-10-20 11:49:28 +0100386 assert support.is_operator_supported(op)
387 # Restricts filter W x H to 256x256
388 op.attrs["filter_width"] = 257
389 assert not support.is_operator_supported(op)
390 # Doesnt matter if SAME or VALID
Michael McGeagh16895482020-12-14 15:51:20 +0000391 op.attrs["padding"] = Padding.VALID
Michael McGeagh65fd9982020-10-20 11:49:28 +0100392 assert not support.is_operator_supported(op)
393
394
395def test_constraint_resize():
396 # IFM W and H == 1
397 op = testutil.create_op_with_quant_tensors(Op.ResizeBilinear, [1, 1, 1, 8], [1, 8, 8, 8])
398 assert support.is_operator_supported(op)
399 # IFM == OFM
400 op = testutil.create_op_with_quant_tensors(Op.ResizeBilinear, [1, 8, 8, 8], [1, 8, 8, 8])
401 assert support.is_operator_supported(op)
402 # IFM x2 == OFM ; align_corners = False
403 op = testutil.create_op_with_quant_tensors(Op.ResizeBilinear, [1, 4, 4, 8], [1, 8, 8, 8])
404 assert support.is_operator_supported(op)
405 # IFM x2 -1 == OFM ; align_corners = True
406 op = testutil.create_op_with_quant_tensors(Op.ResizeBilinear, [1, 4, 4, 8], [1, 7, 7, 8])
407 op.attrs["align_corners"] = True
408 assert support.is_operator_supported(op)
409 # Invalid cases
410 op = testutil.create_op_with_quant_tensors(Op.ResizeBilinear, [1, 4, 4, 8], [1, 20, 20, 8])
411 assert not support.is_operator_supported(op)
412 op.attrs["align_corners"] = True
413 assert not support.is_operator_supported(op)
414
415
416def test_constraint_matching_shapes():
417 # Softmax requires the ifm and ofm shapes to match
418 op = testutil.create_op_with_quant_tensors(Op.Softmax, [1, 1, 1, 8], [1, 2, 2, 4])
419 assert not support.is_operator_supported(op)
420 op = testutil.create_op_with_quant_tensors(Op.Softmax, [1, 1, 1, 8], [1, 1, 1, 8])
421 assert support.is_operator_supported(op)
422
423
Patrik Gustavsson2fa15882020-11-13 09:02:31 +0100424def test_constraint_beta_value_range():
425 # beta must be positive
426 op = testutil.create_op_with_quant_tensors(Op.Softmax, [1, 1, 1, 8], [1, 1, 1, 8])
427 op.attrs["beta"] = -1.0
428 assert not support.is_operator_supported(op)
429 op.attrs["beta"] = 0.0
430 assert support.is_operator_supported(op)
431
432
Michael McGeagh65fd9982020-10-20 11:49:28 +0100433def test_constraint_splitv_inferred():
434 # SplitV requires a maximum of one inferred shape (-1)
435 qp = testutil.default_quant_params()
436 op = testutil.create_op_with_quant_tensors(Op.SplitV, [1, 1, 1, 8], [1, 1, 1, 8])
437 sizes = create_const_tensor("sizes", [1, 1, 1, 4], DataType.int16, [[[[0, -1, 2, -1]]]], np.int16, quantization=qp)
438 op.add_input_tensor(sizes)
439 assert not support.is_operator_supported(op)
440 op = testutil.create_op_with_quant_tensors(Op.SplitV, [1, 1, 1, 8], [1, 1, 1, 8])
441 sizes = create_const_tensor("sizes", [1, 1, 1, 4], DataType.int16, [[[[0, 1, 2, -1]]]], np.int16, quantization=qp)
442 op.add_input_tensor(sizes)
443 assert support.is_operator_supported(op)
444
445
446def test_constraint_concat_pass():
447 # A working concat
448 op = testutil.create_op_with_quant_tensors(Op.Concat, [1, 1, 1, 4], [1, 1, 1, 8])
449 ifm2 = Tensor([1, 1, 1, 4], DataType.uint8, "in2")
450 ifm2.quantization = testutil.default_quant_params()
451 op.add_input_tensor(ifm2)
452 op.attrs["axis"] = 3
453 assert support.is_operator_supported(op)
454
455
456def test_constraint_axis_exists():
457 # Missing axis attribute
458 op = testutil.create_op_with_quant_tensors(Op.Concat, [1, 1, 1, 4], [1, 1, 1, 8])
459 ifm2 = Tensor([1, 1, 1, 4], DataType.uint8, "in2")
460 ifm2.quantization = testutil.default_quant_params()
461 op.add_input_tensor(ifm2)
462 assert not support.is_operator_supported(op)
463
464
465def test_constraint_axis_valid():
466 # Invalid axis attribute
467 op = testutil.create_op_with_quant_tensors(Op.Concat, [1, 1, 1, 4], [1, 1, 1, 8])
468 ifm2 = Tensor([1, 1, 1, 4], DataType.uint8, "in2")
469 ifm2.quantization = testutil.default_quant_params()
470 op.add_input_tensor(ifm2)
471 op.attrs["axis"] = 7
472 assert not support.is_operator_supported(op)
473
474
475def test_constraint_matching_dimensionality():
476 # Mismatching dimensionality: 4D+2D=4D
477 op = testutil.create_op_with_quant_tensors(Op.Concat, [1, 1, 1, 4], [1, 1, 1, 8])
478 ifm2 = Tensor([1, 4], DataType.uint8, "in2")
479 ifm2.quantization = testutil.default_quant_params()
480 op.add_input_tensor(ifm2)
481 op.attrs["axis"] = 3
482 assert not support.is_operator_supported(op)
483
484
485def test_constraint_valid_dimensions():
486 # Mismatching dimension value:
487 # ifm2 has w and h as 2, which is not the axis to concat and doesnt match ifm1 or ofm
488 op = testutil.create_op_with_quant_tensors(Op.Concat, [1, 1, 1, 4], [1, 1, 1, 8])
489 ifm2 = Tensor([1, 2, 2, 4], DataType.uint8, "in2")
490 ifm2.quantization = testutil.default_quant_params()
491 op.add_input_tensor(ifm2)
492 op.attrs["axis"] = 3
493 assert not support.is_operator_supported(op)
494
495
496def create_strided_slice_op(in_shape, out_shape, start_offsets, end_offsets):
497 qp = testutil.default_quant_params()
498 in0 = Tensor(in_shape, DataType.uint8, "in")
499 in0.quantization = qp
500 in1 = create_const_tensor("begin", [len(start_offsets)], DataType.uint8, start_offsets, quantization=qp)
501 in2 = create_const_tensor("end", [len(end_offsets)], DataType.uint8, end_offsets, quantization=qp)
502 in3 = create_const_tensor("strides", [len(end_offsets)], DataType.uint8, len(end_offsets) * [1], quantization=qp)
503 out = Tensor(out_shape, DataType.uint8, "out")
504 out.quantization = qp
505 attrs = {"ellipsis_mask": 0, "new_axis_mask": 0, "shrink_axis_mask": 0, "begin_mask": 0, "end_mask": 0}
506 return testutil.create_op(Op.StridedSlice, [in0, in1, in2, in3], out, attrs=attrs)
507
508
Erik Anderssonf27a8b62020-12-10 14:58:23 +0100509def create_pad_op(
510 in_shape, out_shape, padding, in_dtype=DataType.int8, out_dtype=DataType.int8, pad_dtype=DataType.int32
511):
512 qp = testutil.default_quant_params()
513 in0 = Tensor(in_shape, in_dtype, "in")
514 in0.quantization = qp
515 pad_tensor = create_const_tensor(name="pad", shape=list(np.shape(padding)), values=padding, dtype=pad_dtype)
516 out = Tensor(out_shape, out_dtype, "out")
517 out.quantization = qp.clone()
518 op = testutil.create_op(Op.Pad, [in0, pad_tensor], out)
519
520 conv_out_tens = Tensor(in_shape, in_dtype, "output")
521 conv_out_tens.quantization = qp.clone()
522 weight_tens = Tensor(in_shape, in_dtype, "weights")
523 weight_tens.values = np.zeros(weight_tens.shape)
524 weight_tens.quant_values = np.zeros(weight_tens.shape, np.int8)
525 weight_tens.quantization = qp.clone()
526 bias_tens = Tensor([in_shape[-1]], pad_dtype, "biases")
527 attrs = {"padding": Padding.VALID, "stride_w": 2, "stride_h": 2, "dilation_w_factor": 1, "dilation_h_factor": 1}
528 attrs["strides"] = (1, attrs["stride_h"], attrs["stride_w"], 1)
529 conv2d_op = testutil.create_op(Op.Conv2D, [out, weight_tens, bias_tens], conv_out_tens, attrs)
530 conv2d_op.add_input_tensor(out)
531 conv2d_op.set_ifm_ofm_shapes()
532 return op
533
534
535def test_constraint_pad_input_count():
536 # Incorrect number of input tensors (2)
537 op = create_pad_op(in_shape=[1, 1, 1, 1], out_shape=[1, 3, 3, 1], padding=[[0, 0], [1, 1], [1, 1], [0, 0]],)
538 assert support.is_operator_supported(op)
539 op.add_input_tensor(op.inputs[0].clone())
540 assert not support.is_operator_supported(op)
541
542
543def test_constraint_padded_dimensions():
544 # Incorrect padding dimensions, can only pad width and height
545 op = create_pad_op(in_shape=[1, 1, 1, 1], out_shape=[1, 3, 3, 1], padding=[[1, 1], [1, 1], [1, 1], [0, 0]],)
546 assert not support.is_operator_supported(op)
547
548
549def test_constraint_pad_shape():
550 # PAD operator must be of shape (4,2)
551 op = create_pad_op(in_shape=[1, 1, 1, 1], out_shape=[1, 3, 3, 1], padding=[[0, 0], [1, 1], [1, 1], [0, 0], [0, 0]],)
552 assert not support.is_operator_supported(op)
553
554
555def test_constraint_pad_none():
556 op = create_pad_op(in_shape=[1, 1, 1, 1], out_shape=[1, 3, 3, 1], padding=[],)
557 assert not support.is_operator_supported(op)
558
559
560def test_constraint_pad_dtype():
561 # PAD operator dtype should be int32 or int64
562 op = create_pad_op(
563 in_shape=[1, 1, 1, 1],
564 out_shape=[1, 3, 3, 1],
565 padding=[[0, 0], [1, 1], [1, 1], [0, 0], [0, 0]],
566 pad_dtype=DataType.int16,
567 )
568 assert not support.is_operator_supported(op)
569
570
571def test_constraint_pad_consumer():
572 # PAD operator must be followed by a valid consumer with Padding.VALID attribute
573 op = create_pad_op(in_shape=[1, 1, 1, 1], out_shape=[1, 3, 3, 1], padding=[[0, 0], [1, 1], [1, 1], [0, 0], [0, 0]],)
574 conv_op = op.ofm.consumers()[0]
575 conv_op.attrs["Padding"] = Padding.SAME
576 assert not support.is_operator_supported(op)
577 op_consumer = testutil.create_op_with_quant_tensors(Op.Concat, [1, 1, 1, 4], [1, 1, 1, 8])
578 op.ofm.consumer_list = [op_consumer]
579 assert not support.is_operator_supported(op)
580 op_consumer = testutil.create_op_with_quant_tensors(Op.AvgPool, [1, 8, 8, 8], [1, 8, 8, 8])
581 op_consumer.attrs = {
582 "stride_w": 2,
583 "stride_h": 2,
584 "filter_width": 2,
585 "filter_height": 2,
586 "padding": Padding.VALID,
587 }
588 op.ofm.consumer_list = [op_consumer]
589 assert not support.is_operator_supported(op)
590
591
Michael McGeagh65fd9982020-10-20 11:49:28 +0100592def create_strided_slice():
593 # Creates a valid strided slice operator with some valid inputs/outputs
594 op = create_strided_slice_op([1, 10, 10, 10], [1, 5, 5, 10], [127, 2, 2, 0], [0, 7, -3, 0])
595 op.attrs["begin_mask"] = 1
596 op.attrs["end_mask"] = 9
597 assert support.is_operator_supported(op)
598 return op
599
600
601def test_constraint_stridedslice_input_count():
602 # Wrong number of input tensors
603 op = create_strided_slice()
604 op.add_input_tensor(op.inputs[0].clone())
605 assert not support.is_operator_supported(op)
606
607
608def test_constraint_stridedslice_inputs_const():
609 # begin, end, stride values must not be None
610 op = create_strided_slice()
611 op.inputs[1].values = None
612 assert not support.is_operator_supported(op)
613 op = create_strided_slice()
614 op.inputs[2].values = None
615 assert not support.is_operator_supported(op)
616 op = create_strided_slice()
617 op.inputs[3].values = None
618 assert not support.is_operator_supported(op)
619
620
Michael McGeagh65fd9982020-10-20 11:49:28 +0100621def test_constraint_stridedslice_stride_values():
622 # Unsupported strides
623 op = create_strided_slice()
624 op.inputs[3].values = [1, 1, 2, 1]
625 assert not support.is_operator_supported(op)
626
627
628def test_constraint_ellipsis_mask():
629 # Unsupported ellipsis mask
630 op = create_strided_slice()
631 op.attrs["ellipsis_mask"] = 1
632 assert not support.is_operator_supported(op)
633
634
635def test_constraint_axis_masks():
636 op = create_strided_slice()
637 # Setting one of new_axis_mask/shrink_axis_mask to non-zero is ok
638 op.attrs["new_axis_mask"] = 2
639 assert support.is_operator_supported(op)
640 op = create_strided_slice()
641 op.attrs["shrink_axis_mask"] = 3
642 assert support.is_operator_supported(op)
643 # But setting both to non-zero is not supported
644 op.attrs["new_axis_mask"] = 2
645 assert not support.is_operator_supported(op)
646
647
648def test_constraint_slice_ranges():
649 # Examples where end offset <= begin offset
650 op = create_strided_slice()
651 op.inputs[1].values = [0, 7, 2, 0]
652 assert not support.is_operator_supported(op)
653 op = create_strided_slice()
654 op.inputs[2].values = [0, 7, 2, 0]
655 assert not support.is_operator_supported(op)
656 op = create_strided_slice()
657 op.attrs["begin_mask"] = 0
658 assert not support.is_operator_supported(op)
659 op = create_strided_slice()
660 op.attrs["end_mask"] = 0
661 assert not support.is_operator_supported(op)
662
663
664def test_constraint_matching_inputs_types():
665 # input data types must match (default is uint8)
666 op = testutil.create_elemwise_op(Op.Mul, "op", [1, 8, 8, 8], [1, 8, 8, 8], [1, 8, 8, 8])
667 op.ifm2.dtype = DataType.int8
668 assert not support.is_operator_supported(op)
669
670
671def test_constraint_matching_signed():
672 # signed inputs require output to also be signed
673 op = testutil.create_elemwise_op(Op.Mul, "op", [1, 8, 8, 8], [1, 8, 8, 8], [1, 8, 8, 8], datatype=DataType.int8)
674 op.ofm.dtype = DataType.uint8
675 assert not support.is_operator_supported(op)
676
677
678def test_constraint_unsigned_valid():
679 # unsigned inputs require output to be either:
680 op = testutil.create_elemwise_op(Op.Mul, "op", [1, 8, 8, 8], [1, 8, 8, 8], [1, 8, 8, 8])
681 # the same (default uint8)
682 assert support.is_operator_supported(op)
683 op.ofm.dtype = DataType.int8
684 assert not support.is_operator_supported(op)
685 op.ofm.dtype = DataType.int16
686 assert not support.is_operator_supported(op)
687 # or int32
688 op.ofm.dtype = DataType.int32
689 assert support.is_operator_supported(op)
690
691
692def test_constraint_inputs_int32():
693 # both inputs must be type int32
694 op = testutil.create_elemwise_op(Op.SHL, "op", [1, 8, 8, 8], [1, 8, 8, 8], [1, 8, 8, 8])
695 assert not support.is_operator_supported(op)
696 op = testutil.create_elemwise_op(Op.SHL, "op", [1, 8, 8, 8], [1, 8, 8, 8], [1, 8, 8, 8], datatype=DataType.int32)
697 assert support.is_operator_supported(op)
698 op.ifm2.dtype = DataType.int16
699 assert not support.is_operator_supported(op)
700
701
702def test_constraint_output_int32():
703 # output must be type int32
704 op = testutil.create_elemwise_op(Op.SHL, "op", [1, 8, 8, 8], [1, 8, 8, 8], [1, 8, 8, 8], datatype=DataType.int32)
705 assert support.is_operator_supported(op)
706 op.ofm.dtype = DataType.int16
707 assert not support.is_operator_supported(op)
708
709
710def test_constraint_matching_quantization_parameters():
711 qp = QuantizationParameters()
712 qp.scale_f32 = np.float32(1.5)
713 qp.zero_point = 128
714 # valid - all matching (uses default quant params)
715 op = testutil.create_elemwise_op(Op.Minimum, "op", [1, 8, 8, 8], [1, 8, 8, 8], [1, 8, 8, 8])
716 assert support.is_operator_supported(op)
717 # invalid - ifm mismatch ofm
718 op.ifm.quantization = qp
719 assert not support.is_operator_supported(op)
720 # invalid - ifm2 mismatch ofm
721 op = testutil.create_elemwise_op(Op.Minimum, "op", [1, 8, 8, 8], [1, 8, 8, 8], [1, 8, 8, 8])
722 op.ifm2.quantization = qp
723 assert not support.is_operator_supported(op)
724 # invalid - both ifm and ifm2 mismatch ofm
725 op = testutil.create_elemwise_op(Op.Minimum, "op", [1, 8, 8, 8], [1, 8, 8, 8], [1, 8, 8, 8])
726 op.ifm.quantization = qp
727 op.ifm2.quantization = qp
728 assert not support.is_operator_supported(op)
729 # valid - all matching
730 op.ofm.quantization = qp
731 assert support.is_operator_supported(op)
Erik Anderssonf27a8b62020-12-10 14:58:23 +0100732 op = testutil.create_elemwise_op(Op.Minimum, "op", [1, 8, 8, 8], None, [1, 8, 8, 8])
733 assert support.is_operator_supported(op)
Michael McGeagh65fd9982020-10-20 11:49:28 +0100734
735
736def test_constraint_elemwise_batch_size():
737 # BINARY CASE
738 # Batch can be >1 if dims is <=2D
739 op = testutil.create_elemwise_op(Op.Add, "op", [2, 2], [2, 2], [2, 2])
740 assert support.is_operator_supported(op)
741 # For dims >2D, batch must be 1
742 op = testutil.create_elemwise_op(Op.Add, "op", [1, 2, 2], [1, 2, 2], [1, 2, 2])
743 assert support.is_operator_supported(op)
744 # invalid case
745 op = testutil.create_elemwise_op(Op.Add, "op", [2, 2, 2], [2, 2, 2], [2, 2, 2])
746 assert not support.is_operator_supported(op)
747
748 # UNARY CASE
749 # Batch can be >1 if dims is <=2D
750 op = testutil.create_elemwise_op(Op.CLZ, "op", [2, 2], None, [2, 2], datatype=DataType.int32)
751 assert support.is_operator_supported(op)
752 # For dims >2D, batch must be 1
753 op = testutil.create_elemwise_op(Op.CLZ, "op", [1, 2, 2], None, [1, 2, 2], datatype=DataType.int32)
754 assert support.is_operator_supported(op)
755 # invalid case
756 op = testutil.create_elemwise_op(Op.CLZ, "op", [2, 2, 2], None, [2, 2, 2], datatype=DataType.int32)
757 assert not support.is_operator_supported(op)
758
759
760def test_constraint_matching_either_shapes():
761 # BINARY CASE
762 # At least one ifm shape must match ofm's shape
Andreas Nevalainend059d8b2020-11-19 14:40:35 +0100763 op = testutil.create_elemwise_op(Op.Add, "op", [1, 4], [4, 4], [4, 4])
Michael McGeagh65fd9982020-10-20 11:49:28 +0100764 assert support.is_operator_supported(op)
Andreas Nevalainend059d8b2020-11-19 14:40:35 +0100765 op = testutil.create_elemwise_op(Op.Add, "op", [4, 4], [1, 4], [4, 4])
Michael McGeagh65fd9982020-10-20 11:49:28 +0100766 assert support.is_operator_supported(op)
767 op = testutil.create_elemwise_op(Op.Add, "op", [4, 4], [4, 4], [2, 2])
768 assert not support.is_operator_supported(op)
Andreas Nevalainend059d8b2020-11-19 14:40:35 +0100769 op = testutil.create_elemwise_op(Op.Add, "op", [1, 4, 1, 16], [1, 1, 4, 1], [1, 4, 4, 16])
770 assert not support.is_operator_supported(op)
771 op = testutil.create_elemwise_op(Op.Add, "op", [1, 1, 4, 1], [1, 4, 1, 16], [1, 4, 4, 16])
772 assert not support.is_operator_supported(op)
Michael McGeagh65fd9982020-10-20 11:49:28 +0100773
774 # UNARY CASE
775 # No second input so this is treated the same as requiring ifm shape to match ofm shape
776 op = testutil.create_elemwise_op(Op.CLZ, "op", [2, 2], None, [2, 2], datatype=DataType.int32)
777 assert support.is_operator_supported(op)
778 op = testutil.create_elemwise_op(Op.CLZ, "op", [4, 4], None, [2, 2], datatype=DataType.int32)
779 assert not support.is_operator_supported(op)
780
781
Andreas Nevalainend059d8b2020-11-19 14:40:35 +0100782def test_constraint_broadcast_shapes():
783 # BINARY CASE
784 # Only allow broadcast to 1 dim, for 1 rank index
785 op = testutil.create_elemwise_op(Op.Add, "op", [1, 1, 4], [1, 2, 4], [1, 2, 4])
786 assert support.is_operator_supported(op)
787 op = testutil.create_elemwise_op(Op.Add, "op", [1, 2, 4], [1, 1, 4], [1, 2, 4])
788 assert support.is_operator_supported(op)
789 # Only allow broadcast to 1 dim, for 3 rank indexes
790 op = testutil.create_elemwise_op(Op.Add, "op", [1, 1, 1, 1], [1, 4, 8, 16], [1, 4, 8, 16])
791 assert support.is_operator_supported(op)
792 op = testutil.create_elemwise_op(Op.Add, "op", [1, 4, 8, 16], [1, 1, 1, 1], [1, 4, 8, 16])
793 assert support.is_operator_supported(op)
794 # One broadcast dim not 1
795 op = testutil.create_elemwise_op(Op.Add, "op", [1, 2, 4], [1, 4, 4], [1, 4, 4])
796 assert not support.is_operator_supported(op)
797 op = testutil.create_elemwise_op(Op.Add, "op", [1, 4, 4], [1, 2, 4], [1, 4, 4])
798 assert not support.is_operator_supported(op)
799 # OFM shape dim largest ifm/ifm2 shape dim
800 op = testutil.create_elemwise_op(Op.Add, "op", [1, 4], [4, 4], [1, 4])
801 assert not support.is_operator_supported(op)
802 op = testutil.create_elemwise_op(Op.Add, "op", [1, 4], [4, 4], [1, 4])
803 assert not support.is_operator_supported(op)
804 op = testutil.create_elemwise_op(Op.Add, "op", [1, 4, 1, 16], [1, 1, 4, 1], [1, 4, 1, 16])
805 assert not support.is_operator_supported(op)
806 op = testutil.create_elemwise_op(Op.Add, "op", [1, 1, 4, 1], [1, 4, 1, 16], [1, 4, 1, 16])
807 assert not support.is_operator_supported(op)
808
809
Michael McGeagh65fd9982020-10-20 11:49:28 +0100810def test_constraint_alpha_valid():
811 # Alpha cannot be negative
812 op = testutil.create_elemwise_op(Op.LeakyRelu, "op", [2, 2], None, [2, 2])
813 op.attrs["alpha"] = 0
814 assert support.is_operator_supported(op)
815 op.attrs["alpha"] = -1
816 assert not support.is_operator_supported(op)