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"
19 TEST_F(GenModelTest, OneOp_Tile_ConstMul)
22 std::vector<int32_t> mul_data{1, 2};
23 uint32_t mul_buf = cgen.addBuffer(mul_data);
24 int in = cgen.addTensor({{2, 3}, circle::TensorType::TensorType_FLOAT32});
25 int mul = cgen.addTensor({{2}, circle::TensorType::TensorType_INT32, mul_buf});
26 int out = cgen.addTensor({{2, 6}, circle::TensorType::TensorType_FLOAT32});
27 cgen.addOperatorTile({{in, mul}, {out}});
28 cgen.setInputsAndOutputs({in}, {out});
30 _context = std::make_unique<GenModelTestContext>(cgen.finish());
31 _context->addTestCase(
32 uniformTCD<float>({{1, 2, 3, 4, 5, 6}}, {{1, 2, 3, 1, 2, 3, 4, 5, 6, 4, 5, 6}}));
33 _context->setBackends({"cpu"});
38 TEST_F(GenModelTest, OneOp_Tile_MulToConst)
41 std::vector<int32_t> multiplies_data{2, 3, 1};
42 uint32_t multiplies_buf = cgen.addBuffer(multiplies_data);
43 int multiplies = cgen.addTensor({{3}, circle::TensorType::TensorType_INT32, multiplies_buf});
44 int in = cgen.addTensor({{1, 2, 3}, circle::TensorType::TensorType_FLOAT32});
45 int out = cgen.addTensor({{2, 6, 3}, circle::TensorType::TensorType_FLOAT32});
46 cgen.addOperatorTile({{in, multiplies}, {out}});
47 cgen.setInputsAndOutputs({in}, {out});
49 _context = std::make_unique<GenModelTestContext>(cgen.finish());
50 _context->addTestCase(
51 uniformTCD<float>({{11, 12, 13, 21, 22, 23}},
52 {{11, 12, 13, 21, 22, 23, 11, 12, 13, 21, 22, 23, 11, 12, 13, 21, 22, 23,
53 11, 12, 13, 21, 22, 23, 11, 12, 13, 21, 22, 23, 11, 12, 13, 21, 22, 23}}));
54 _context->setBackends({"cpu"});
59 TEST_F(GenModelTest, OneOp_Tile_MulToVar)
62 int multiplies = cgen.addTensor({{3}, circle::TensorType::TensorType_INT32});
63 int in = cgen.addTensor({{1, 2, 3}, circle::TensorType::TensorType_FLOAT32});
64 int out = cgen.addTensor({{2, 6, 3}, circle::TensorType::TensorType_FLOAT32});
65 cgen.addOperatorTile({{in, multiplies}, {out}});
66 cgen.setInputsAndOutputs({in, multiplies}, {out});
68 _context = std::make_unique<GenModelTestContext>(cgen.finish());
69 _context->addTestCase(
71 .addInput<float>({11, 12, 13, 21, 22, 23})
72 .addInput<int32_t>({2, 3, 1})
73 .addOutput<float>({11, 12, 13, 21, 22, 23, 11, 12, 13, 21, 22, 23, 11, 12, 13, 21, 22, 23,
74 11, 12, 13, 21, 22, 23, 11, 12, 13, 21, 22, 23, 11, 12, 13, 21, 22, 23}));
75 _context->setBackends({"cpu"});
80 TEST_F(GenModelTest, OneOp_Tile_VarMul)
83 int in = cgen.addTensor({{2, 3}, circle::TensorType::TensorType_FLOAT32});
84 int mul = cgen.addTensor({{2}, circle::TensorType::TensorType_INT32});
85 int out = cgen.addTensor({{2, 6}, circle::TensorType::TensorType_FLOAT32});
86 cgen.addOperatorTile({{in, mul}, {out}});
87 cgen.setInputsAndOutputs({in, mul}, {out});
89 _context = std::make_unique<GenModelTestContext>(cgen.finish());
90 _context->addTestCase(TestCaseData{}
91 .addInput<float>({1, 2, 3, 4, 5, 6})
92 .addInput<int32_t>({1, 2})
93 .addOutput<float>({1, 2, 3, 1, 2, 3, 4, 5, 6, 4, 5, 6}));
94 _context->setBackends({"cpu"});
99 TEST_F(GenModelTest, neg_OneOp_Tile)
102 std::vector<int32_t> mul_data{1, 2, 1, 2};
103 uint32_t mul_buf = cgen.addBuffer(mul_data);
104 int in = cgen.addTensor({{2, 3}, circle::TensorType::TensorType_FLOAT32});
105 // 2D multiples input is not supported
106 int mul = cgen.addTensor({{2, 2}, circle::TensorType::TensorType_INT32, mul_buf});
107 int out = cgen.addTensor({{2, 6}, circle::TensorType::TensorType_FLOAT32});
108 cgen.addOperatorTile({{in, mul}, {out}});
109 cgen.setInputsAndOutputs({in}, {out});
111 _context = std::make_unique<GenModelTestContext>(cgen.finish());
112 _context->setBackends({"cpu"});
113 _context->expectFailCompile();
118 TEST_F(GenModelTest, neg_OneOp_Tile_InvalidMulSize)
121 std::vector<int32_t> multiplies_data{2, 6};
122 uint32_t multiplies_buf = cgen.addBuffer(multiplies_data);
123 int multiplies = cgen.addTensor({{2}, circle::TensorType::TensorType_INT32, multiplies_buf});
124 int in = cgen.addTensor({{1, 2, 3}, circle::TensorType::TensorType_FLOAT32});
125 int out = cgen.addTensor({{2, 6, 3}, circle::TensorType::TensorType_FLOAT32});
126 cgen.addOperatorTile({{in, multiplies}, {out}});
127 cgen.setInputsAndOutputs({in}, {out});
129 _context = std::make_unique<GenModelTestContext>(cgen.finish());
130 _context->setBackends({"cpu"});
131 _context->expectFailCompile();