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 // Input shape: {1, 2, 2, 1}
20 // Padding: {0, 0, 1, 1, 1, 1, 0, 0}
21 // Output shape: {1, 4, 4, 1}
25 circle::TensorType data_type = circle::TensorType::TensorType_FLOAT32;
27 int64_t zero_point = 0;
30 class PadVariation : public GenModelTest, public ::testing::WithParamInterface<PadParam>
34 // Test with different value type
35 INSTANTIATE_TEST_CASE_P(
36 GenModelTest, PadVariation,
39 PadParam{uniformTCD<float>({{1, 2, 3, 4}}, {{0, 0, 0, 0, 0, 1, 2, 0, 0, 3, 4, 0, 0, 0, 0, 0}})},
42 uniformTCD<uint8_t>({{1, 2, 3, 4}}, {{8, 8, 8, 8, 8, 1, 2, 8, 8, 3, 4, 8, 8, 8, 8, 8}}),
43 circle::TensorType::TensorType_UINT8, 1.0, 8},
45 PadParam{uniformTCD<int8_t>({{-2, -1, 1, 2}},
46 {{-5, -5, -5, -5, -5, -2, -1, -5, -5, 1, 2, -5, -5, -5, -5, -5}}),
47 circle::TensorType::TensorType_INT8, 1.0, -5}));
49 TEST_P(PadVariation, Test)
51 auto ¶m = GetParam();
54 int in = cgen.addTensor({{1, 2, 2, 1}, param.data_type}, param.scale, param.zero_point);
55 std::vector<int32_t> padding_data{0, 0, 1, 1, 1, 1, 0, 0};
56 uint32_t padding_buf = cgen.addBuffer(padding_data);
57 int padding = cgen.addTensor({{4, 2}, circle::TensorType::TensorType_INT32, padding_buf});
58 int out = cgen.addTensor({{1, 4, 4, 1}, param.data_type}, param.scale, param.zero_point);
60 cgen.addOperatorPad({{in, padding}, {out}});
61 cgen.setInputsAndOutputs({in}, {out});
62 _context = std::make_unique<GenModelTestContext>(cgen.finish());
63 _context->addTestCase(param.tcd);
64 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
69 TEST_P(PadVariation, neg_InvalidPadRank)
71 auto ¶m = GetParam();
74 int in = cgen.addTensor({{1, 2, 2, 1}, param.data_type}, param.scale, param.zero_point);
75 std::vector<int32_t> padding_data{1, 1, 1, 1};
76 uint32_t padding_buf = cgen.addBuffer(padding_data);
77 int padding = cgen.addTensor({{4}, circle::TensorType::TensorType_INT32, padding_buf});
78 int out = cgen.addTensor({{1, 4, 4, 1}, param.data_type}, param.scale, param.zero_point);
80 cgen.addOperatorPad({{in, padding}, {out}});
81 cgen.setInputsAndOutputs({in}, {out});
83 _context = std::make_unique<GenModelTestContext>(cgen.finish());
84 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
85 _context->expectFailCompile();
90 TEST_P(PadVariation, neg_InvalidPadDim0)
92 auto ¶m = GetParam();
95 int in = cgen.addTensor({{1, 2, 2, 1}, param.data_type}, param.scale, param.zero_point);
96 std::vector<int32_t> padding_data{1, 1, 1, 1};
97 uint32_t padding_buf = cgen.addBuffer(padding_data);
98 int padding = cgen.addTensor({{2, 2}, circle::TensorType::TensorType_INT32, padding_buf});
99 int out = cgen.addTensor({{1, 4, 4, 1}, param.data_type}, param.scale, param.zero_point);
101 cgen.addOperatorPad({{in, padding}, {out}});
102 cgen.setInputsAndOutputs({in}, {out});
104 _context = std::make_unique<GenModelTestContext>(cgen.finish());
105 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
106 _context->expectFailCompile();
111 TEST_P(PadVariation, neg_InvalidPadDim1)
113 auto ¶m = GetParam();
116 int in = cgen.addTensor({{1, 2, 2, 1}, param.data_type}, param.scale, param.zero_point);
117 std::vector<int32_t> padding_data{1, 1, 1, 1};
118 uint32_t padding_buf = cgen.addBuffer(padding_data);
119 int padding = cgen.addTensor({{4, 1}, circle::TensorType::TensorType_INT32, padding_buf});
120 int out = cgen.addTensor({{1, 4, 4, 1}, param.data_type}, param.scale, param.zero_point);
122 cgen.addOperatorPad({{in, padding}, {out}});
123 cgen.setInputsAndOutputs({in}, {out});
125 _context = std::make_unique<GenModelTestContext>(cgen.finish());
126 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
127 _context->expectFailCompile();
132 TEST_P(PadVariation, neg_Type)
134 auto ¶m = GetParam();
136 const circle::TensorType output_type = ((param.data_type == circle::TensorType::TensorType_UINT8)
137 ? circle::TensorType::TensorType_INT8
138 : circle::TensorType::TensorType_UINT8);
141 int in = cgen.addTensor({{1, 2, 2, 1}, param.data_type}, param.scale, param.zero_point);
142 std::vector<int32_t> padding_data{0, 0, 1, 1, 1, 1, 0, 0};
143 uint32_t padding_buf = cgen.addBuffer(padding_data);
144 int padding = cgen.addTensor({{4, 2}, circle::TensorType::TensorType_INT32, padding_buf});
145 int out = cgen.addTensor({{1, 4, 4, 1}, output_type}, 1.0, 0);
147 cgen.addOperatorPad({{in, padding}, {out}});
148 cgen.setInputsAndOutputs({in}, {out});
150 _context = std::make_unique<GenModelTestContext>(cgen.finish());
151 _context->expectFailModelLoad();
156 TEST_F(GenModelTest, neg_OneOp_Pad_QuantParam)
159 int in = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_UINT8}, 1.0, 1);
160 std::vector<int32_t> padding_data{0, 0, 1, 1, 1, 1, 0, 0};
161 uint32_t padding_buf = cgen.addBuffer(padding_data);
162 int padding = cgen.addTensor({{4, 2}, circle::TensorType::TensorType_INT32, padding_buf});
163 int out = cgen.addTensor({{1, 4, 4, 1}, circle::TensorType::TensorType_UINT8}, 1.0, 3);
165 cgen.addOperatorPad({{in, padding}, {out}});
166 cgen.setInputsAndOutputs({in}, {out});
168 _context = std::make_unique<GenModelTestContext>(cgen.finish());
169 _context->expectFailModelLoad();