97e908caa84ad599c4fdeee2836bbf5de9924a73
[platform/upstream/dldt.git] / ngraph / test / backend / validate_call.in.cpp
1 //*****************************************************************************
2 // Copyright 2017-2020 Intel Corporation
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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 //*****************************************************************************
16
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"
27
28 NGRAPH_SUPPRESS_DEPRECATED_START
29
30 using namespace std;
31 using namespace ngraph;
32
33 static string s_manifest = "${MANIFEST}";
34
35 NGRAPH_TEST(${BACKEND_NAME}, validate_call_input_count)
36 {
37     auto backend = runtime::Backend::create("${BACKEND_NAME}");
38
39     Shape shape{2, 2};
40
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});
44
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);
48
49     EXPECT_ANY_THROW(auto handle = backend->compile(f); handle->call_with_validate({c}, {a}));
50 }
51
52 NGRAPH_TEST(${BACKEND_NAME}, validate_call_input_type)
53 {
54     auto backend = runtime::Backend::create("${BACKEND_NAME}");
55
56     Shape shape{2, 2};
57
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});
61
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);
65
66     EXPECT_ANY_THROW(auto handle = backend->compile(f); handle->call_with_validate({c}, {a, b}));
67 }
68
69 NGRAPH_TEST(${BACKEND_NAME}, validate_call_input_shape)
70 {
71     auto backend = runtime::Backend::create("${BACKEND_NAME}");
72
73     Shape shape{2, 2};
74
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});
78
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);
82
83     EXPECT_ANY_THROW(auto handle = backend->compile(f); handle->call_with_validate({c}, {a, b}));
84 }
85
86 NGRAPH_TEST(${BACKEND_NAME}, validate_call_output_count)
87 {
88     auto backend = runtime::Backend::create("${BACKEND_NAME}");
89
90     Shape shape{2, 2};
91
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});
95
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);
100
101     EXPECT_ANY_THROW(auto handle = backend->compile(f); handle->call_with_validate({c, d}, {a, b}));
102 }
103
104 NGRAPH_TEST(${BACKEND_NAME}, validate_call_output_type)
105 {
106     auto backend = runtime::Backend::create("${BACKEND_NAME}");
107
108     Shape shape{2, 2};
109
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});
113
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);
117
118     EXPECT_ANY_THROW(auto handle = backend->compile(f); handle->call_with_validate({a}, {b, c}));
119 }
120
121 NGRAPH_TEST(${BACKEND_NAME}, validate_call_output_shape)
122 {
123     auto backend = runtime::Backend::create("${BACKEND_NAME}");
124
125     Shape shape{2, 2};
126
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});
130
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);
134
135     EXPECT_ANY_THROW(auto handle = backend->compile(f); handle->call_with_validate({a}, {c, b}));
136 }