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 TEST_F(GenModelTest, OneOp_Transpose_PermsToConst)
24 std::vector<int32_t> perms_data{2, 0, 1, 3};
25 uint32_t perms_buf = cgen.addBuffer(perms_data);
26 int perms = cgen.addTensor({{4}, circle::TensorType::TensorType_INT32, perms_buf});
27 int in = cgen.addTensor({{2, 3, 4, 5}, circle::TensorType::TensorType_FLOAT32});
28 int out = cgen.addTensor({{2, 3, 4, 5}, circle::TensorType::TensorType_FLOAT32});
29 cgen.addOperatorTranspose({{in, perms}, {out}});
30 cgen.setInputsAndOutputs({in}, {out});
32 _context = std::make_unique<GenModelTestContext>(cgen.finish());
33 _context->addTestCase(uniformTCD<float>(
34 {{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
35 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
37 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
38 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
39 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107,
40 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119}},
41 {{0, 1, 2, 3, 4, 20, 21, 22, 23, 24, 40, 41, 42, 43, 44, 60, 61, 62, 63, 64,
42 80, 81, 82, 83, 84, 100, 101, 102, 103, 104, 5, 6, 7, 8, 9, 25, 26, 27, 28, 29,
43 45, 46, 47, 48, 49, 65, 66, 67, 68, 69, 85, 86, 87, 88, 89, 105, 106, 107, 108, 109,
44 10, 11, 12, 13, 14, 30, 31, 32, 33, 34, 50, 51, 52, 53, 54, 70, 71, 72, 73, 74,
45 90, 91, 92, 93, 94, 110, 111, 112, 113, 114, 15, 16, 17, 18, 19, 35, 36, 37, 38, 39,
46 55, 56, 57, 58, 59, 75, 76, 77, 78, 79, 95, 96, 97, 98, 99, 115, 116, 117, 118, 119}}));
47 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
52 TEST_F(GenModelTest, OneOp_Transpose_PermsToVar)
55 int perms = cgen.addTensor({{4}, circle::TensorType::TensorType_INT32});
56 int in = cgen.addTensor({{1, 2, 3, 1}, circle::TensorType::TensorType_FLOAT32});
57 int out = cgen.addTensor({{1, 3, 2, 1}, circle::TensorType::TensorType_FLOAT32});
58 cgen.addOperatorTranspose({{in, perms}, {out}});
59 cgen.setInputsAndOutputs({in, perms}, {out});
61 _context = std::make_unique<GenModelTestContext>(cgen.finish());
62 _context->addTestCase(TestCaseData{}
63 .addInput<float>({1, 2, 3, 4, 5, 6})
64 .addInput<int32_t>({0, 2, 1, 3})
65 .addOutput<float>({1, 4, 2, 5, 3, 6}));
66 _context->setBackends({"cpu"});
71 TEST_F(GenModelTest, OneOp_Transpose_RegularTranspose)
74 int perms = cgen.addTensor({{0}, circle::TensorType::TensorType_INT32});
75 int in = cgen.addTensor({{1, 2, 3, 1}, circle::TensorType::TensorType_FLOAT32});
76 int out = cgen.addTensor({{1, 3, 2, 1}, circle::TensorType::TensorType_FLOAT32});
77 cgen.addOperatorTranspose({{in, perms}, {out}});
78 cgen.setInputsAndOutputs({in, perms}, {out});
80 _context = std::make_unique<GenModelTestContext>(cgen.finish());
81 _context->addTestCase(TestCaseData{}
82 .addInput<float>({1, 2, 3, 4, 5, 6})
83 .addInput<int32_t>({})
84 .addOutput<float>({1, 4, 2, 5, 3, 6}));
85 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
90 TEST_F(GenModelTest, neg_OneOp_Transpose_InvalidPermsSize)
93 std::vector<int32_t> perms_data{0, 1, 2};
94 uint32_t perms_buf = cgen.addBuffer(perms_data);
95 int perms = cgen.addTensor({{3}, circle::TensorType::TensorType_INT32, perms_buf});
96 int in = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
97 int out = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
98 cgen.addOperatorTranspose({{in, perms}, {out}});
99 cgen.setInputsAndOutputs({in}, {out});
101 _context = std::make_unique<GenModelTestContext>(cgen.finish());
102 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
103 _context->expectFailCompile();
108 TEST_F(GenModelTest, neg_OneOp_Transpose_InvalidPermsVal)
111 std::vector<int32_t> perms_data{-3, 3, 1, 2};
112 uint32_t perms_buf = cgen.addBuffer(perms_data);
113 int perms = cgen.addTensor({{4}, circle::TensorType::TensorType_INT32, perms_buf});
114 int in = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
115 int out = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
116 cgen.addOperatorTranspose({{in, perms}, {out}});
117 cgen.setInputsAndOutputs({in}, {out});
119 _context = std::make_unique<GenModelTestContext>(cgen.finish());
120 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
121 _context->expectFailCompile();
126 TEST_F(GenModelTest, neg_OneOp_Transpose_DuplicatedPermsVal)
129 std::vector<int32_t> perms_data{3, 3, 1, 2};
130 uint32_t perms_buf = cgen.addBuffer(perms_data);
131 int perms = cgen.addTensor({{4}, circle::TensorType::TensorType_INT32, perms_buf});
132 int in = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
133 int out = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
134 cgen.addOperatorTranspose({{in, perms}, {out}});
135 cgen.setInputsAndOutputs({in}, {out});
137 _context = std::make_unique<GenModelTestContext>(cgen.finish());
138 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
139 _context->expectFailCompile();