Deprecate nGraph v0 ops and builders (#1856)
[platform/upstream/dldt.git] / ngraph / test / backend / quantized_convolution.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}, quantized_conv_int32_output)
36 {
37     Shape shape_a{1, 1, 3, 4};
38     Shape shape_b{1, 1, 3, 3};
39     Shape shape_r{1, 1, 3, 4};
40     vector<uint8_t> a_data = {1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4};
41     vector<uint8_t> b_data = {1, 2, 3, 4, 5, 0, 0, 1, 2};
42     auto A = make_shared<op::Parameter>(element::u8, shape_a);
43     auto B = make_shared<op::Parameter>(element::u8, shape_b);
44     auto C = make_shared<op::Parameter>(element::f32, Shape{});
45     auto D = op::Constant::create(element::u8, Shape{}, {0});
46     auto E = make_shared<op::Parameter>(element::f32, Shape{});
47     auto F = op::Constant::create(element::u8, Shape{}, {0});
48     auto G = make_shared<op::Parameter>(element::f32, Shape{});
49     auto H = op::Constant::create(element::i32, Shape{}, {0});
50     auto CV = make_shared<op::QuantizedConvolution>(A,
51                                                     B,
52                                                     Strides{1, 1},
53                                                     Strides{1, 1},
54                                                     CoordinateDiff{1, 1},
55                                                     CoordinateDiff{1, 1},
56                                                     Strides{1, 1},
57                                                     C,
58                                                     D,
59                                                     E,
60                                                     F,
61                                                     G,
62                                                     H,
63                                                     element::i32);
64     auto f = make_shared<Function>(NodeVector{CV}, ParameterVector{A, B, C, E, G});
65
66     auto backend = runtime::Backend::create("${BACKEND_NAME}");
67     // Create some tensors for input/output
68     auto a = backend->create_tensor(element::u8, shape_a);
69     copy_data(a, a_data);
70     auto b = backend->create_tensor(element::u8, shape_b);
71     copy_data(b, b_data);
72     auto c = backend->create_tensor(element::f32, Shape{});
73     copy_data(c, vector<float>{1.0f});
74     auto d = backend->create_tensor(element::f32, Shape{});
75     copy_data(d, vector<float>{1.0f});
76     auto e = backend->create_tensor(element::f32, Shape{});
77     copy_data(e, vector<float>{1.0f});
78     auto result = backend->create_tensor(element::i32, shape_r);
79     auto handle = backend->compile(f);
80     handle->call_with_validate({result}, {a, b, c, d, e});
81     EXPECT_EQ((vector<int32_t>{22, 34, 30, 32, 38, 72, 90, 43, 33, 52, 43, 39}),
82               read_vector<int32_t>(result));
83 }