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 NGRAPH_TEST(${BACKEND_NAME}, validate_call_input_count)
37 auto backend = runtime::Backend::create("${BACKEND_NAME}");
41 auto A = make_shared<op::Parameter>(element::f32, shape);
42 auto B = make_shared<op::Parameter>(element::f32, shape);
43 auto f = make_shared<Function>(make_shared<op::Add>(A, B), ParameterVector{A, B});
45 auto a = backend->create_tensor(element::f32, shape);
46 auto b = backend->create_tensor(element::f32, shape);
47 auto c = backend->create_tensor(element::f32, shape);
49 EXPECT_ANY_THROW(auto handle = backend->compile(f); handle->call_with_validate({c}, {a}));
52 NGRAPH_TEST(${BACKEND_NAME}, validate_call_input_type)
54 auto backend = runtime::Backend::create("${BACKEND_NAME}");
58 auto A = make_shared<op::Parameter>(element::f32, shape);
59 auto B = make_shared<op::Parameter>(element::f32, shape);
60 auto f = make_shared<Function>(make_shared<op::Add>(A, B), ParameterVector{A, B});
62 auto a = backend->create_tensor(element::i32, shape);
63 auto b = backend->create_tensor(element::f32, shape);
64 auto c = backend->create_tensor(element::f32, shape);
66 EXPECT_ANY_THROW(auto handle = backend->compile(f); handle->call_with_validate({c}, {a, b}));
69 NGRAPH_TEST(${BACKEND_NAME}, validate_call_input_shape)
71 auto backend = runtime::Backend::create("${BACKEND_NAME}");
75 auto A = make_shared<op::Parameter>(element::f32, shape);
76 auto B = make_shared<op::Parameter>(element::f32, shape);
77 auto f = make_shared<Function>(make_shared<op::Add>(A, B), ParameterVector{A, B});
79 auto a = backend->create_tensor(element::f32, {2, 3});
80 auto b = backend->create_tensor(element::f32, shape);
81 auto c = backend->create_tensor(element::f32, shape);
83 EXPECT_ANY_THROW(auto handle = backend->compile(f); handle->call_with_validate({c}, {a, b}));
86 NGRAPH_TEST(${BACKEND_NAME}, validate_call_output_count)
88 auto backend = runtime::Backend::create("${BACKEND_NAME}");
92 auto A = make_shared<op::Parameter>(element::f32, shape);
93 auto B = make_shared<op::Parameter>(element::f32, shape);
94 auto f = make_shared<Function>(make_shared<op::Add>(A, B), ParameterVector{A, B});
96 auto a = backend->create_tensor(element::f32, shape);
97 auto b = backend->create_tensor(element::f32, shape);
98 auto c = backend->create_tensor(element::f32, shape);
99 auto d = backend->create_tensor(element::f32, shape);
101 EXPECT_ANY_THROW(auto handle = backend->compile(f); handle->call_with_validate({c, d}, {a, b}));
104 NGRAPH_TEST(${BACKEND_NAME}, validate_call_output_type)
106 auto backend = runtime::Backend::create("${BACKEND_NAME}");
110 auto A = make_shared<op::Parameter>(element::f32, shape);
111 auto B = make_shared<op::Parameter>(element::f32, shape);
112 auto f = make_shared<Function>(make_shared<op::Add>(A, B), ParameterVector{A, B});
114 auto a = backend->create_tensor(element::i32, shape);
115 auto b = backend->create_tensor(element::f32, shape);
116 auto c = backend->create_tensor(element::f32, shape);
118 EXPECT_ANY_THROW(auto handle = backend->compile(f); handle->call_with_validate({a}, {b, c}));
121 NGRAPH_TEST(${BACKEND_NAME}, validate_call_output_shape)
123 auto backend = runtime::Backend::create("${BACKEND_NAME}");
127 auto A = make_shared<op::Parameter>(element::f32, shape);
128 auto B = make_shared<op::Parameter>(element::f32, shape);
129 auto f = make_shared<Function>(make_shared<op::Add>(A, B), ParameterVector{A, B});
131 auto a = backend->create_tensor(element::f32, {2, 3});
132 auto b = backend->create_tensor(element::f32, shape);
133 auto c = backend->create_tensor(element::f32, shape);
135 EXPECT_ANY_THROW(auto handle = backend->compile(f); handle->call_with_validate({a}, {c, b}));