2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "GenModelTest.h"
21 CircleGen genSimpleCastModel(circle::TensorType from_t, circle::TensorType to_t)
24 int in = cgen.addTensor({{1, 2, 2, 1}, from_t});
25 int out = cgen.addTensor({{1, 2, 2, 1}, to_t});
26 cgen.addOperatorCast({{in}, {out}}, from_t, to_t);
27 cgen.setInputsAndOutputs({in}, {out});
31 TEST_F(GenModelTest, OneOp_Cast_Int32ToFloat32)
33 CircleGen cgen = genSimpleCastModel(circle::TensorType_INT32, circle::TensorType_FLOAT32);
35 _context = std::make_unique<GenModelTestContext>(cgen.finish());
36 _context->addTestCase(
37 TestCaseData{}.addInput<int32_t>({1, 2, 3, 4}).addOutput<float>({1, 2, 3, 4}));
38 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
43 TEST_F(GenModelTest, OneOp_Cast_Float32ToInt32)
45 CircleGen cgen = genSimpleCastModel(circle::TensorType_FLOAT32, circle::TensorType_INT32);
47 _context = std::make_unique<GenModelTestContext>(cgen.finish());
48 _context->addTestCase(
49 TestCaseData{}.addInput<float>({1, 2, 3, 4}).addOutput<int32_t>({1, 2, 3, 4}));
50 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
55 TEST_F(GenModelTest, OneOp_Cast_BoolToFloat32)
57 CircleGen cgen = genSimpleCastModel(circle::TensorType_BOOL, circle::TensorType_FLOAT32);
59 _context = std::make_unique<GenModelTestContext>(cgen.finish());
60 _context->addTestCase(
61 TestCaseData{}.addInput<bool>({true, false, true, true}).addOutput<float>({1, 0, 1, 1}));
62 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
67 TEST_F(GenModelTest, OneOp_Cast_BoolToUInt8)
69 CircleGen cgen = genSimpleCastModel(circle::TensorType_BOOL, circle::TensorType_UINT8);
71 _context = std::make_unique<GenModelTestContext>(cgen.finish());
72 _context->addTestCase(TestCaseData{}
73 .addInput<bool>({true, false, true, true})
74 .addOutput(std::vector<uint8_t>{1, 0, 1, 1}));
75 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
80 TEST_F(GenModelTest, OneOp_Cast_BoolToInt32)
82 CircleGen cgen = genSimpleCastModel(circle::TensorType_BOOL, circle::TensorType_INT32);
84 _context = std::make_unique<GenModelTestContext>(cgen.finish());
85 _context->addTestCase(
86 TestCaseData{}.addInput<bool>({true, false, true, true}).addOutput<int32_t>({1, 0, 1, 1}));
87 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
92 TEST_F(GenModelTest, OneOp_Cast_AfterEqual)
95 int lhs = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
96 int rhs = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
97 int equal_out = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_BOOL});
98 int out = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
99 cgen.addOperatorEqual({{lhs, rhs}, {equal_out}});
100 cgen.addOperatorCast({{equal_out}, {out}}, circle::TensorType::TensorType_BOOL,
101 circle::TensorType::TensorType_FLOAT32);
102 cgen.setInputsAndOutputs({lhs, rhs}, {out});
104 _context = std::make_unique<GenModelTestContext>(cgen.finish());
105 _context->addTestCase(uniformTCD<float>({{1, 3, 2, 4}, {2, 3, 1, 4}}, {{0, 1, 0, 1}}));
106 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
111 TEST_F(GenModelTest, neg_OneOp_Cast_InvalidInputCount0)
114 int out = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_INT32});
115 cgen.addOperatorCast({{}, {out}}, circle::TensorType::TensorType_FLOAT32,
116 circle::TensorType::TensorType_INT32);
117 cgen.setInputsAndOutputs({}, {out});
119 _context = std::make_unique<GenModelTestContext>(cgen.finish());
120 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
121 _context->expectFailModelLoad();
126 TEST_F(GenModelTest, neg_OneOp_Cast_InvalidInputCount2)
129 int lhs = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_INT32});
130 int rhs = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_INT32});
131 int out = cgen.addTensor({{1, 2, 2, 3}, circle::TensorType::TensorType_FLOAT32});
132 cgen.addOperatorCast({{lhs, rhs}, {out}}, circle::TensorType::TensorType_INT32,
133 circle::TensorType::TensorType_FLOAT32);
134 cgen.setInputsAndOutputs({lhs, rhs}, {out});
136 _context = std::make_unique<GenModelTestContext>(cgen.finish());
137 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
138 _context->expectFailModelLoad();
143 TEST_F(GenModelTest, neg_OneOp_Cast_InvalidOutputCount0)
146 int in = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_INT32});
147 cgen.addOperatorCast({{in}, {}}, circle::TensorType::TensorType_INT32,
148 circle::TensorType::TensorType_FLOAT32);
149 cgen.setInputsAndOutputs({in}, {});
151 _context = std::make_unique<GenModelTestContext>(cgen.finish());
152 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
153 _context->expectFailModelLoad();
158 TEST_F(GenModelTest, neg_OneOp_Cast_InvalidOutputCount2)
161 int in = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_INT32});
162 int out1 = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
163 int out2 = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_INT32});
164 cgen.addOperatorCast({{in}, {out1, out2}}, circle::TensorType::TensorType_INT32,
165 circle::TensorType::TensorType_FLOAT32);
166 cgen.setInputsAndOutputs({in}, {out1, out2});
168 _context = std::make_unique<GenModelTestContext>(cgen.finish());
169 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
170 _context->expectFailModelLoad();