1# 2# Copyright (C) 2019 The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16 17import collections 18 19Operand = collections.namedtuple( 20 "Operand", [ 21 "name", "as_input", "as_output", "data", 22 "supports_relaxation", "introduced_in" 23 ], 24 defaults=[False, None]) 25operands = [ 26 Operand( 27 name="float16", 28 as_input=Input("input0", "TENSOR_FLOAT16", "{2, 3}"), 29 as_output=Output("output0", "TENSOR_FLOAT16", "{2, 3}"), 30 data=[1, 2, 3, 4, 5, 6], 31 supports_relaxation=False, 32 introduced_in="V1_2"), 33 Operand( 34 name="float32", 35 as_input=Input("input0", "TENSOR_FLOAT32", "{2, 3}"), 36 as_output=Output("output0", "TENSOR_FLOAT32", "{2, 3}"), 37 data=[1, 2, 3, 4, 5, 6], 38 supports_relaxation=True, 39 introduced_in="V1_2"), 40 Operand( 41 name="int32", 42 as_input=Input("input0", "TENSOR_INT32", "{2, 3}"), 43 as_output=Output("output0", "TENSOR_INT32", "{2, 3}"), 44 data=[1, 2, 3, 4, 5, 6], 45 supports_relaxation=False, 46 introduced_in="V1_2"), 47 Operand( 48 name="bool8", 49 as_input=Input("input0", "TENSOR_BOOL8", "{2, 3}"), 50 as_output=Output("output0", "TENSOR_BOOL8", "{2, 3}"), 51 data=[1, 0, 1, 0, 0, 1]), 52 Operand( 53 name="quant8_asymm", 54 as_input=Input("input0", "TENSOR_QUANT8_ASYMM", "{2, 3}, 4.0, 100"), 55 as_output=Output("output0", "TENSOR_QUANT8_ASYMM", "{2, 3}, 4.0, 100"), 56 data=[1, 2, 3, 4, 5, 6], 57 supports_relaxation=False, 58 introduced_in="V1_2"), 59 Operand( 60 name="quant8_symm", 61 as_input=Input("input0", "TENSOR_QUANT8_SYMM", "{2, 3}, 4.0, 0"), 62 as_output=Output("output0", "TENSOR_QUANT8_SYMM", "{2, 3}, 4.0, 0"), 63 data=[1, 2, 3, 4, 5, 6]), 64 Operand( 65 name="quant16_asymm", 66 as_input=Input("input0", "TENSOR_QUANT16_ASYMM", "{2, 3}, 4.0, 100"), 67 as_output=Output("output0", "TENSOR_QUANT16_ASYMM", "{2, 3}, 4.0, 100"), 68 data=[1, 2, 3, 4, 5, 6]), 69 Operand( 70 name="quant16_symm", 71 as_input=Input("input0", "TENSOR_QUANT16_SYMM", "{2, 3}, 4.0, 0"), 72 as_output=Output("output0", "TENSOR_QUANT16_SYMM", "{2, 3}, 4.0, 0"), 73 data=[1, 2, 3, 4, 5, 6]), 74] 75 76for operand in operands: 77 input0 = operand.as_input 78 output0 = operand.as_output 79 80 model = Model().Operation("CAST", input0).To(output0) 81 82 if operand.introduced_in: 83 model.IntroducedIn(operand.introduced_in) 84 85 example = Example({ 86 input0: operand.data, 87 output0: operand.data, 88 }, model=model, name=operand.name) 89 90 if operand.supports_relaxation: 91 example.AddRelaxed() 92