Publishing 2019 R3 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / src / quantize.cpp
1 /*
2 // Copyright (c) 2019 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 "quantize_inst.h"
18 #include "binary_convolution_inst.h"
19 #include "primitive_type_base.h"
20 #include "memory_impl.h"
21 #include "error_handler.h"
22 #include "json_object.h"
23 #include "data_inst.h"
24 #include <string>
25
26 namespace cldnn {
27 primitive_type_id quantize::type_id() {
28     static primitive_type_base<quantize> instance;
29     return &instance;
30 }
31
32 layout quantize_inst::calc_output_layout(quantize_node const& node) {
33     auto desc = node.get_primitive();
34
35     auto input_layout = node.input().get_output_layout();
36     auto output_format = input_layout.format;
37     auto out_dt = input_layout.data_type;
38     if (node.get_primitive()->output_data_type)
39         out_dt = *node.get_primitive()->output_data_type;
40
41     if (out_dt == data_types::bin) {
42         output_format = format::b_fs_yx_32fp;
43     }
44
45     return layout{out_dt, output_format, input_layout.size};
46 }
47
48 std::string quantize_inst::to_string(quantize_node const& node) {
49     auto desc = node.get_primitive();
50     auto node_info = node.desc_to_json();
51     auto& input = node.input(0);
52     auto& input_low = node.input(1);
53     auto& input_high = node.input(2);
54     auto& output_low = node.input(3);
55     auto& output_high = node.input(4);
56
57     std::stringstream primitive_description;
58
59     json_composite quantize_info;
60     quantize_info.add("input id", input.id());
61     quantize_info.add("input low id", input_low.id());
62     quantize_info.add("input high id", input_high.id());
63     quantize_info.add("output low id", output_low.id());
64     quantize_info.add("output high id", output_high.id());
65     quantize_info.add("levels", desc->levels);
66
67     node_info->add("quantize info", quantize_info);
68     node_info->dump(primitive_description);
69
70     return primitive_description.str();
71 }
72
73 quantize_inst::typed_primitive_inst(network_impl& network, quantize_node const& node) : parent(network, node) {}
74
75 }  // namespace cldnn