//***************************************************************************** // Copyright 2017-2020 Intel Corporation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. //***************************************************************************** #include "gtest/gtest.h" #include "ngraph/ngraph.hpp" #include "ngraph/runtime/tensor.hpp" #include "runtime/backend.hpp" #include "util/all_close.hpp" #include "util/all_close_f.hpp" #include "util/known_element_types.hpp" #include "util/ndarray.hpp" #include "util/test_control.hpp" #include "util/test_tools.hpp" NGRAPH_SUPPRESS_DEPRECATED_START using namespace std; using namespace ngraph; static string s_manifest = "${MANIFEST}"; template void make_unary_empty_test(const string& backend_name) { Shape shape{0}; ParameterVector params; NodeVector result_list; for (size_t i = 0; i < s_known_element_types.size(); i++) { shared_ptr p = make_shared(s_known_element_types[i], shape); params.push_back(p); result_list.push_back(make_shared(p)); } auto f = make_shared(result_list, params); auto backend = runtime::Backend::create(backend_name); vector> inputs; vector> outputs; for (size_t i = 0; i < s_known_element_types.size(); i++) { inputs.push_back(backend->create_tensor(s_known_element_types[i], shape)); outputs.push_back(backend->create_tensor(s_known_element_types[i], shape)); } auto handle = backend->compile(f); handle->call_with_validate(outputs, inputs); EXPECT_EQ(read_vector(inputs[0]).size(), 0); EXPECT_EQ(read_vector(inputs[1]).size(), 0); EXPECT_EQ(read_vector(inputs[2]).size(), 0); EXPECT_EQ(read_vector(inputs[3]).size(), 0); EXPECT_EQ(read_vector(inputs[4]).size(), 0); EXPECT_EQ(read_vector(inputs[5]).size(), 0); EXPECT_EQ(read_vector(inputs[6]).size(), 0); EXPECT_EQ(read_vector(inputs[7]).size(), 0); EXPECT_EQ(read_vector(inputs[8]).size(), 0); EXPECT_EQ(read_vector(inputs[9]).size(), 0); EXPECT_EQ(read_vector(outputs[0]).size(), 0); EXPECT_EQ(read_vector(outputs[1]).size(), 0); EXPECT_EQ(read_vector(outputs[2]).size(), 0); EXPECT_EQ(read_vector(outputs[3]).size(), 0); EXPECT_EQ(read_vector(outputs[4]).size(), 0); EXPECT_EQ(read_vector(outputs[5]).size(), 0); EXPECT_EQ(read_vector(outputs[6]).size(), 0); EXPECT_EQ(read_vector(outputs[7]).size(), 0); EXPECT_EQ(read_vector(outputs[8]).size(), 0); EXPECT_EQ(read_vector(outputs[9]).size(), 0); } template void make_binary_empty_test(const string& backend_name, bool is_comparison = false) { Shape shape{0}; ParameterVector A; for (size_t i = 0; i < s_known_element_types.size(); i++) { A.push_back(make_shared(s_known_element_types[i], shape)); } NodeVector result_list; for (shared_ptr p : A) { result_list.push_back(make_shared(p, p)); } auto f = make_shared(result_list, A); auto backend = runtime::Backend::create(backend_name); vector> inputs; vector> outputs; for (size_t i = 0; i < s_known_element_types.size(); i++) { inputs.push_back(backend->create_tensor(s_known_element_types[i], shape)); if (is_comparison) { outputs.push_back(backend->create_tensor(element::from(), shape)); } else { outputs.push_back(backend->create_tensor(s_known_element_types[i], shape)); } } auto handle = backend->compile(f); handle->call_with_validate(outputs, inputs); EXPECT_EQ(read_vector(inputs[0]).size(), 0); EXPECT_EQ(read_vector(inputs[1]).size(), 0); EXPECT_EQ(read_vector(inputs[2]).size(), 0); EXPECT_EQ(read_vector(inputs[3]).size(), 0); EXPECT_EQ(read_vector(inputs[4]).size(), 0); EXPECT_EQ(read_vector(inputs[5]).size(), 0); EXPECT_EQ(read_vector(inputs[6]).size(), 0); EXPECT_EQ(read_vector(inputs[7]).size(), 0); EXPECT_EQ(read_vector(inputs[8]).size(), 0); EXPECT_EQ(read_vector(inputs[9]).size(), 0); if (is_comparison) { EXPECT_EQ(read_vector(outputs[0]).size(), 0); EXPECT_EQ(read_vector(outputs[1]).size(), 0); EXPECT_EQ(read_vector(outputs[2]).size(), 0); EXPECT_EQ(read_vector(outputs[3]).size(), 0); EXPECT_EQ(read_vector(outputs[4]).size(), 0); EXPECT_EQ(read_vector(outputs[5]).size(), 0); EXPECT_EQ(read_vector(outputs[6]).size(), 0); EXPECT_EQ(read_vector(outputs[7]).size(), 0); EXPECT_EQ(read_vector(outputs[8]).size(), 0); EXPECT_EQ(read_vector(outputs[9]).size(), 0); } else { EXPECT_EQ(read_vector(outputs[0]).size(), 0); EXPECT_EQ(read_vector(outputs[1]).size(), 0); EXPECT_EQ(read_vector(outputs[2]).size(), 0); EXPECT_EQ(read_vector(outputs[3]).size(), 0); EXPECT_EQ(read_vector(outputs[4]).size(), 0); EXPECT_EQ(read_vector(outputs[5]).size(), 0); EXPECT_EQ(read_vector(outputs[6]).size(), 0); EXPECT_EQ(read_vector(outputs[7]).size(), 0); EXPECT_EQ(read_vector(outputs[8]).size(), 0); EXPECT_EQ(read_vector(outputs[9]).size(), 0); } } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_abs) { make_unary_empty_test("${BACKEND_NAME}"); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_ceiling) { make_unary_empty_test("${BACKEND_NAME}"); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_erf) { make_unary_empty_test("${BACKEND_NAME}"); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_exp) { make_unary_empty_test("${BACKEND_NAME}"); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_floor) { make_unary_empty_test("${BACKEND_NAME}"); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_log) { make_unary_empty_test("${BACKEND_NAME}"); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_negative) { make_unary_empty_test("${BACKEND_NAME}"); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_not) { Shape shape{0}; auto A = make_shared(element::from(), shape); auto f = make_shared(make_shared(A), ParameterVector{A}); auto backend = runtime::Backend::create("${BACKEND_NAME}"); auto a = backend->create_tensor(element::from(), shape); auto result = backend->create_tensor(element::from(), shape); auto handle = backend->compile(f); handle->call_with_validate({result}, {a}); auto in_vec = read_vector(a); auto out_vec = read_vector(result); EXPECT_EQ(in_vec.size(), 0); EXPECT_EQ(out_vec.size(), 0); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_sign) { make_unary_empty_test("${BACKEND_NAME}"); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_sqrt) { make_unary_empty_test("${BACKEND_NAME}"); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_sin) { make_unary_empty_test("${BACKEND_NAME}"); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_sinh) { make_unary_empty_test("${BACKEND_NAME}"); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_cos) { make_unary_empty_test("${BACKEND_NAME}"); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_cosh) { make_unary_empty_test("${BACKEND_NAME}"); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_tan) { make_unary_empty_test("${BACKEND_NAME}"); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_tanh) { make_unary_empty_test("${BACKEND_NAME}"); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_asin) { make_unary_empty_test("${BACKEND_NAME}"); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_acos) { make_unary_empty_test("${BACKEND_NAME}"); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_atan) { make_unary_empty_test("${BACKEND_NAME}"); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_add) { make_binary_empty_test("${BACKEND_NAME}"); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_divide) { make_binary_empty_test("${BACKEND_NAME}"); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_eq) { make_binary_empty_test("${BACKEND_NAME}", true); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_greater) { make_binary_empty_test("${BACKEND_NAME}", true); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_greatereq) { make_binary_empty_test("${BACKEND_NAME}", true); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_less) { make_binary_empty_test("${BACKEND_NAME}", true); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_lesseq) { make_binary_empty_test("${BACKEND_NAME}", true); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_maximum) { make_binary_empty_test("${BACKEND_NAME}"); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_minimum) { make_binary_empty_test("${BACKEND_NAME}"); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_multiply) { make_binary_empty_test("${BACKEND_NAME}"); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_not_equal) { make_binary_empty_test("${BACKEND_NAME}", true); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_power) { make_binary_empty_test("${BACKEND_NAME}"); } NGRAPH_TEST(${BACKEND_NAME}, zero_sized_subtract) { make_binary_empty_test("${BACKEND_NAME}"); }