Deprecate nGraph v0 ops and builders (#1856)
[platform/upstream/dldt.git] / ngraph / test / backend_debug_api.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 <random>
18 #include <sstream>
19 #include <string>
20 #include <vector>
21
22 #include "gtest/gtest.h"
23 #include "ngraph/log.hpp"
24 #include "ngraph/ngraph.hpp"
25 #include "runtime/interpreter/int_executable.hpp"
26 #include "util/test_tools.hpp"
27
28 NGRAPH_SUPPRESS_DEPRECATED_START
29
30 using namespace std;
31 using namespace ngraph;
32
33 TEST(INTERPRETER, nan_check_input)
34 {
35     Shape shape{4};
36     auto A = make_shared<op::Parameter>(element::f32, shape);
37     auto B = make_shared<op::Parameter>(element::f32, shape);
38     auto f = make_shared<Function>(make_shared<op::Divide>(A, B), ParameterVector{A, B});
39
40     shared_ptr<runtime::Backend> backend = runtime::Backend::create("INTERPRETER");
41
42     // Create some tensors for input/output
43     auto a = backend->create_tensor(element::f32, shape);
44     copy_data(a, vector<float>{2, 4, NAN, 16});
45     auto b = backend->create_tensor(element::f32, shape);
46     copy_data(b, vector<float>{1, 2, 1, 8});
47     auto result = backend->create_tensor(element::f32, shape);
48
49     shared_ptr<runtime::Executable> handle = backend->compile(f);
50
51     shared_ptr<runtime::interpreter::INTExecutable> ihandle =
52         static_pointer_cast<runtime::interpreter::INTExecutable>(handle);
53     ihandle->set_nan_check(true);
54     EXPECT_ANY_THROW(handle->call_with_validate({result}, {a, b}));
55 }
56
57 TEST(INTERPRETER, nan_check_output)
58 {
59     Shape shape{4};
60     auto A = make_shared<op::Parameter>(element::f32, shape);
61     auto B = make_shared<op::Parameter>(element::f32, shape);
62     auto f = make_shared<Function>(make_shared<op::Divide>(A, B), ParameterVector{A, B});
63
64     shared_ptr<runtime::Backend> backend = runtime::Backend::create("INTERPRETER");
65
66     // Create some tensors for input/output
67     auto a = backend->create_tensor(element::f32, shape);
68     copy_data(a, vector<float>{2, 4, 0, 16});
69     auto b = backend->create_tensor(element::f32, shape);
70     copy_data(b, vector<float>{1, 2, 0, 8});
71     auto result = backend->create_tensor(element::f32, shape);
72
73     shared_ptr<runtime::Executable> handle = backend->compile(f);
74     shared_ptr<runtime::interpreter::INTExecutable> ihandle =
75         static_pointer_cast<runtime::interpreter::INTExecutable>(handle);
76     ihandle->set_nan_check(true);
77     EXPECT_ANY_THROW(handle->call_with_validate({result}, {a, b}));
78 }