15219ae3c6babd2e12c6b610370187a67f4f7e9d
[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 using namespace std;
29 using namespace ngraph;
30
31 static string s_manifest = "${MANIFEST}";
32
33 NGRAPH_TEST(${BACKEND_NAME}, validate_call_input_count)
34 {
35     auto backend = runtime::Backend::create("${BACKEND_NAME}");
36
37     Shape shape{2, 2};
38
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});
42
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);
46
47     EXPECT_ANY_THROW(auto handle = backend->compile(f); handle->call_with_validate({c}, {a}));
48 }
49
50 NGRAPH_TEST(${BACKEND_NAME}, validate_call_input_type)
51 {
52     auto backend = runtime::Backend::create("${BACKEND_NAME}");
53
54     Shape shape{2, 2};
55
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});
59
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);
63
64     EXPECT_ANY_THROW(auto handle = backend->compile(f); handle->call_with_validate({c}, {a, b}));
65 }
66
67 NGRAPH_TEST(${BACKEND_NAME}, validate_call_input_shape)
68 {
69     auto backend = runtime::Backend::create("${BACKEND_NAME}");
70
71     Shape shape{2, 2};
72
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});
76
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);
80
81     EXPECT_ANY_THROW(auto handle = backend->compile(f); handle->call_with_validate({c}, {a, b}));
82 }
83
84 NGRAPH_TEST(${BACKEND_NAME}, validate_call_output_count)
85 {
86     auto backend = runtime::Backend::create("${BACKEND_NAME}");
87
88     Shape shape{2, 2};
89
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});
93
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);
98
99     EXPECT_ANY_THROW(auto handle = backend->compile(f); handle->call_with_validate({c, d}, {a, b}));
100 }
101
102 NGRAPH_TEST(${BACKEND_NAME}, validate_call_output_type)
103 {
104     auto backend = runtime::Backend::create("${BACKEND_NAME}");
105
106     Shape shape{2, 2};
107
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});
111
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);
115
116     EXPECT_ANY_THROW(auto handle = backend->compile(f); handle->call_with_validate({a}, {b, c}));
117 }
118
119 NGRAPH_TEST(${BACKEND_NAME}, validate_call_output_shape)
120 {
121     auto backend = runtime::Backend::create("${BACKEND_NAME}");
122
123     Shape shape{2, 2};
124
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});
128
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);
132
133     EXPECT_ANY_THROW(auto handle = backend->compile(f); handle->call_with_validate({a}, {c, b}));
134 }