1# 2# Copyright (C) 2020 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 17# Model: given n <= 1.0, never returns. 18# Expected result: execution aborted after a timeout. 19# 20# i = 1.0 21# while i >= n: 22# i = i + 1.0 23 24CounterType = ["TENSOR_FLOAT32", [1]] 25BoolType = ["TENSOR_BOOL8", [1]] 26 27def MakeConditionModel(): 28 i = Input("i", CounterType) 29 n = Input("n", CounterType) 30 out = Output("out", BoolType) 31 model = Model() 32 model.IdentifyInputs(i, n) 33 model.IdentifyOutputs(out) 34 model.Operation("GREATER_EQUAL", i, n).To(out) 35 return model 36 37def MakeBodyModel(): 38 i = Input("i", CounterType) 39 n = Input("n", CounterType) 40 i_out = Output("i_out", CounterType) 41 model = Model() 42 model.IdentifyInputs(i, n) 43 model.IdentifyOutputs(i_out) 44 model.Operation("ADD", i, [1.0], 0).To(i_out) 45 return model 46 47n = Input("n", CounterType) 48i_out = Output("i_out", CounterType) 49cond = MakeConditionModel() 50body = MakeBodyModel() 51i_init = [1.0] 52model = Model().Operation("WHILE", cond, body, i_init, n).To(i_out) 53 54quant8 = DataTypeConverter("quant8", scale=1.0, zeroPoint=127) 55quant8_signed = DataTypeConverter("quant8_signed", scale=1.0, zeroPoint=0) 56 57example = Example({n: [0.0], i_out: [0.0]}, model=model) 58example.AddVariations("relaxed", "float16", quant8, quant8_signed) 59example.DisableLifeTimeVariation() 60example.ExpectFailure() 61