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"
29 using namespace ngraph;
31 static string s_manifest = "${MANIFEST}";
33 NGRAPH_TEST(${BACKEND_NAME}, validate_call_input_count)
35 auto backend = runtime::Backend::create("${BACKEND_NAME}");
39 auto A = make_shared<op::Parameter>(element::f32, shape);
40 auto B = make_shared<op::Parameter>(element::f32, shape);
41 auto f = make_shared<Function>(make_shared<op::Add>(A, B), ParameterVector{A, B});
43 auto a = backend->create_tensor(element::f32, shape);
44 auto b = backend->create_tensor(element::f32, shape);
45 auto c = backend->create_tensor(element::f32, shape);
47 EXPECT_ANY_THROW(auto handle = backend->compile(f); handle->call_with_validate({c}, {a}));
50 NGRAPH_TEST(${BACKEND_NAME}, validate_call_input_type)
52 auto backend = runtime::Backend::create("${BACKEND_NAME}");
56 auto A = make_shared<op::Parameter>(element::f32, shape);
57 auto B = make_shared<op::Parameter>(element::f32, shape);
58 auto f = make_shared<Function>(make_shared<op::Add>(A, B), ParameterVector{A, B});
60 auto a = backend->create_tensor(element::i32, shape);
61 auto b = backend->create_tensor(element::f32, shape);
62 auto c = backend->create_tensor(element::f32, shape);
64 EXPECT_ANY_THROW(auto handle = backend->compile(f); handle->call_with_validate({c}, {a, b}));
67 NGRAPH_TEST(${BACKEND_NAME}, validate_call_input_shape)
69 auto backend = runtime::Backend::create("${BACKEND_NAME}");
73 auto A = make_shared<op::Parameter>(element::f32, shape);
74 auto B = make_shared<op::Parameter>(element::f32, shape);
75 auto f = make_shared<Function>(make_shared<op::Add>(A, B), ParameterVector{A, B});
77 auto a = backend->create_tensor(element::f32, {2, 3});
78 auto b = backend->create_tensor(element::f32, shape);
79 auto c = backend->create_tensor(element::f32, shape);
81 EXPECT_ANY_THROW(auto handle = backend->compile(f); handle->call_with_validate({c}, {a, b}));
84 NGRAPH_TEST(${BACKEND_NAME}, validate_call_output_count)
86 auto backend = runtime::Backend::create("${BACKEND_NAME}");
90 auto A = make_shared<op::Parameter>(element::f32, shape);
91 auto B = make_shared<op::Parameter>(element::f32, shape);
92 auto f = make_shared<Function>(make_shared<op::Add>(A, B), ParameterVector{A, B});
94 auto a = backend->create_tensor(element::f32, shape);
95 auto b = backend->create_tensor(element::f32, shape);
96 auto c = backend->create_tensor(element::f32, shape);
97 auto d = backend->create_tensor(element::f32, shape);
99 EXPECT_ANY_THROW(auto handle = backend->compile(f); handle->call_with_validate({c, d}, {a, b}));
102 NGRAPH_TEST(${BACKEND_NAME}, validate_call_output_type)
104 auto backend = runtime::Backend::create("${BACKEND_NAME}");
108 auto A = make_shared<op::Parameter>(element::f32, shape);
109 auto B = make_shared<op::Parameter>(element::f32, shape);
110 auto f = make_shared<Function>(make_shared<op::Add>(A, B), ParameterVector{A, B});
112 auto a = backend->create_tensor(element::i32, shape);
113 auto b = backend->create_tensor(element::f32, shape);
114 auto c = backend->create_tensor(element::f32, shape);
116 EXPECT_ANY_THROW(auto handle = backend->compile(f); handle->call_with_validate({a}, {b, c}));
119 NGRAPH_TEST(${BACKEND_NAME}, validate_call_output_shape)
121 auto backend = runtime::Backend::create("${BACKEND_NAME}");
125 auto A = make_shared<op::Parameter>(element::f32, shape);
126 auto B = make_shared<op::Parameter>(element::f32, shape);
127 auto f = make_shared<Function>(make_shared<op::Add>(A, B), ParameterVector{A, B});
129 auto a = backend->create_tensor(element::f32, {2, 3});
130 auto b = backend->create_tensor(element::f32, shape);
131 auto c = backend->create_tensor(element::f32, shape);
133 EXPECT_ANY_THROW(auto handle = backend->compile(f); handle->call_with_validate({a}, {c, b}));