1 //*****************************************************************************
2 // Copyright 2017-2020 Intel Corporation
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.
15 //*****************************************************************************
17 #include "gtest/gtest.h"
18 #include "ngraph/ngraph.hpp"
19 #include "ngraph/runtime/tensor.hpp"
20 #include "runtime/backend.hpp"
21 #include "util/all_close.hpp"
22 #include "util/all_close_f.hpp"
23 #include "util/known_element_types.hpp"
24 #include "util/ndarray.hpp"
25 #include "util/test_control.hpp"
26 #include "util/test_tools.hpp"
28 NGRAPH_SUPPRESS_DEPRECATED_START
31 using namespace ngraph;
33 static string s_manifest = "${MANIFEST}";
35 template <typename OP>
36 void make_unary_empty_test(const string& backend_name)
40 ParameterVector params;
41 NodeVector result_list;
42 for (size_t i = 0; i < s_known_element_types.size(); i++)
44 shared_ptr<op::Parameter> p = make_shared<op::Parameter>(s_known_element_types[i], shape);
46 result_list.push_back(make_shared<OP>(p));
49 auto f = make_shared<Function>(result_list, params);
50 auto backend = runtime::Backend::create(backend_name);
52 vector<shared_ptr<runtime::Tensor>> inputs;
53 vector<shared_ptr<runtime::Tensor>> outputs;
54 for (size_t i = 0; i < s_known_element_types.size(); i++)
56 inputs.push_back(backend->create_tensor(s_known_element_types[i], shape));
57 outputs.push_back(backend->create_tensor(s_known_element_types[i], shape));
60 auto handle = backend->compile(f);
61 handle->call_with_validate(outputs, inputs);
63 EXPECT_EQ(read_vector<float>(inputs[0]).size(), 0);
64 EXPECT_EQ(read_vector<double>(inputs[1]).size(), 0);
65 EXPECT_EQ(read_vector<int8_t>(inputs[2]).size(), 0);
66 EXPECT_EQ(read_vector<int16_t>(inputs[3]).size(), 0);
67 EXPECT_EQ(read_vector<int32_t>(inputs[4]).size(), 0);
68 EXPECT_EQ(read_vector<int64_t>(inputs[5]).size(), 0);
69 EXPECT_EQ(read_vector<uint8_t>(inputs[6]).size(), 0);
70 EXPECT_EQ(read_vector<uint16_t>(inputs[7]).size(), 0);
71 EXPECT_EQ(read_vector<uint32_t>(inputs[8]).size(), 0);
72 EXPECT_EQ(read_vector<uint64_t>(inputs[9]).size(), 0);
74 EXPECT_EQ(read_vector<float>(outputs[0]).size(), 0);
75 EXPECT_EQ(read_vector<double>(outputs[1]).size(), 0);
76 EXPECT_EQ(read_vector<int8_t>(outputs[2]).size(), 0);
77 EXPECT_EQ(read_vector<int16_t>(outputs[3]).size(), 0);
78 EXPECT_EQ(read_vector<int32_t>(outputs[4]).size(), 0);
79 EXPECT_EQ(read_vector<int64_t>(outputs[5]).size(), 0);
80 EXPECT_EQ(read_vector<uint8_t>(outputs[6]).size(), 0);
81 EXPECT_EQ(read_vector<uint16_t>(outputs[7]).size(), 0);
82 EXPECT_EQ(read_vector<uint32_t>(outputs[8]).size(), 0);
83 EXPECT_EQ(read_vector<uint64_t>(outputs[9]).size(), 0);
86 template <typename OP>
87 void make_binary_empty_test(const string& backend_name, bool is_comparison = false)
91 for (size_t i = 0; i < s_known_element_types.size(); i++)
93 A.push_back(make_shared<op::Parameter>(s_known_element_types[i], shape));
96 NodeVector result_list;
97 for (shared_ptr<op::Parameter> p : A)
99 result_list.push_back(make_shared<OP>(p, p));
102 auto f = make_shared<Function>(result_list, A);
103 auto backend = runtime::Backend::create(backend_name);
105 vector<shared_ptr<runtime::Tensor>> inputs;
106 vector<shared_ptr<runtime::Tensor>> outputs;
107 for (size_t i = 0; i < s_known_element_types.size(); i++)
109 inputs.push_back(backend->create_tensor(s_known_element_types[i], shape));
112 outputs.push_back(backend->create_tensor(element::from<char>(), shape));
116 outputs.push_back(backend->create_tensor(s_known_element_types[i], shape));
120 auto handle = backend->compile(f);
121 handle->call_with_validate(outputs, inputs);
123 EXPECT_EQ(read_vector<float>(inputs[0]).size(), 0);
124 EXPECT_EQ(read_vector<double>(inputs[1]).size(), 0);
125 EXPECT_EQ(read_vector<int8_t>(inputs[2]).size(), 0);
126 EXPECT_EQ(read_vector<int16_t>(inputs[3]).size(), 0);
127 EXPECT_EQ(read_vector<int32_t>(inputs[4]).size(), 0);
128 EXPECT_EQ(read_vector<int64_t>(inputs[5]).size(), 0);
129 EXPECT_EQ(read_vector<uint8_t>(inputs[6]).size(), 0);
130 EXPECT_EQ(read_vector<uint16_t>(inputs[7]).size(), 0);
131 EXPECT_EQ(read_vector<uint32_t>(inputs[8]).size(), 0);
132 EXPECT_EQ(read_vector<uint64_t>(inputs[9]).size(), 0);
136 EXPECT_EQ(read_vector<char>(outputs[0]).size(), 0);
137 EXPECT_EQ(read_vector<char>(outputs[1]).size(), 0);
138 EXPECT_EQ(read_vector<char>(outputs[2]).size(), 0);
139 EXPECT_EQ(read_vector<char>(outputs[3]).size(), 0);
140 EXPECT_EQ(read_vector<char>(outputs[4]).size(), 0);
141 EXPECT_EQ(read_vector<char>(outputs[5]).size(), 0);
142 EXPECT_EQ(read_vector<char>(outputs[6]).size(), 0);
143 EXPECT_EQ(read_vector<char>(outputs[7]).size(), 0);
144 EXPECT_EQ(read_vector<char>(outputs[8]).size(), 0);
145 EXPECT_EQ(read_vector<char>(outputs[9]).size(), 0);
149 EXPECT_EQ(read_vector<float>(outputs[0]).size(), 0);
150 EXPECT_EQ(read_vector<double>(outputs[1]).size(), 0);
151 EXPECT_EQ(read_vector<int8_t>(outputs[2]).size(), 0);
152 EXPECT_EQ(read_vector<int16_t>(outputs[3]).size(), 0);
153 EXPECT_EQ(read_vector<int32_t>(outputs[4]).size(), 0);
154 EXPECT_EQ(read_vector<int64_t>(outputs[5]).size(), 0);
155 EXPECT_EQ(read_vector<uint8_t>(outputs[6]).size(), 0);
156 EXPECT_EQ(read_vector<uint16_t>(outputs[7]).size(), 0);
157 EXPECT_EQ(read_vector<uint32_t>(outputs[8]).size(), 0);
158 EXPECT_EQ(read_vector<uint64_t>(outputs[9]).size(), 0);
162 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_abs)
164 make_unary_empty_test<op::Abs>("${BACKEND_NAME}");
167 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_ceiling)
169 make_unary_empty_test<op::Ceiling>("${BACKEND_NAME}");
172 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_erf)
174 make_unary_empty_test<op::Erf>("${BACKEND_NAME}");
177 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_exp)
179 make_unary_empty_test<op::Exp>("${BACKEND_NAME}");
182 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_floor)
184 make_unary_empty_test<op::Floor>("${BACKEND_NAME}");
187 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_log)
189 make_unary_empty_test<op::Log>("${BACKEND_NAME}");
192 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_negative)
194 make_unary_empty_test<op::Negative>("${BACKEND_NAME}");
197 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_not)
200 auto A = make_shared<op::Parameter>(element::from<char>(), shape);
201 auto f = make_shared<Function>(make_shared<op::Not>(A), ParameterVector{A});
203 auto backend = runtime::Backend::create("${BACKEND_NAME}");
205 auto a = backend->create_tensor(element::from<char>(), shape);
206 auto result = backend->create_tensor(element::from<char>(), shape);
208 auto handle = backend->compile(f);
209 handle->call_with_validate({result}, {a});
211 auto in_vec = read_vector<char>(a);
212 auto out_vec = read_vector<char>(result);
214 EXPECT_EQ(in_vec.size(), 0);
215 EXPECT_EQ(out_vec.size(), 0);
218 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_sign)
220 make_unary_empty_test<op::Sign>("${BACKEND_NAME}");
223 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_sqrt)
225 make_unary_empty_test<op::Sqrt>("${BACKEND_NAME}");
228 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_sin)
230 make_unary_empty_test<op::Sin>("${BACKEND_NAME}");
233 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_sinh)
235 make_unary_empty_test<op::Sinh>("${BACKEND_NAME}");
238 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_cos)
240 make_unary_empty_test<op::Cos>("${BACKEND_NAME}");
243 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_cosh)
245 make_unary_empty_test<op::Cosh>("${BACKEND_NAME}");
248 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_tan)
250 make_unary_empty_test<op::Tan>("${BACKEND_NAME}");
253 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_tanh)
255 make_unary_empty_test<op::Tanh>("${BACKEND_NAME}");
258 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_asin)
260 make_unary_empty_test<op::Asin>("${BACKEND_NAME}");
263 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_acos)
265 make_unary_empty_test<op::Acos>("${BACKEND_NAME}");
268 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_atan)
270 make_unary_empty_test<op::Atan>("${BACKEND_NAME}");
273 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_add)
275 make_binary_empty_test<op::Add>("${BACKEND_NAME}");
278 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_divide)
280 make_binary_empty_test<op::Divide>("${BACKEND_NAME}");
283 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_eq)
285 make_binary_empty_test<op::Equal>("${BACKEND_NAME}", true);
288 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_greater)
290 make_binary_empty_test<op::Greater>("${BACKEND_NAME}", true);
293 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_greatereq)
295 make_binary_empty_test<op::GreaterEq>("${BACKEND_NAME}", true);
298 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_less)
300 make_binary_empty_test<op::Less>("${BACKEND_NAME}", true);
303 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_lesseq)
305 make_binary_empty_test<op::LessEq>("${BACKEND_NAME}", true);
308 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_maximum)
310 make_binary_empty_test<op::Maximum>("${BACKEND_NAME}");
313 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_minimum)
315 make_binary_empty_test<op::Minimum>("${BACKEND_NAME}");
318 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_multiply)
320 make_binary_empty_test<op::Multiply>("${BACKEND_NAME}");
323 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_not_equal)
325 make_binary_empty_test<op::NotEqual>("${BACKEND_NAME}", true);
328 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_power)
330 make_binary_empty_test<op::Power>("${BACKEND_NAME}");
333 NGRAPH_TEST(${BACKEND_NAME}, zero_sized_subtract)
335 make_binary_empty_test<op::Subtract>("${BACKEND_NAME}");