Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / src / softmax.cpp
1 /*
2 // Copyright (c) 2016 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 "softmax_inst.h"
18 #include "primitive_type_base.h"
19 #include "json_object.h"
20
21 namespace cldnn
22 {
23 primitive_type_id softmax_type_id()
24 {
25     static primitive_type_base<softmax> instance;
26     return &instance;
27 }
28
29 layout softmax_inst::calc_output_layout(softmax_node const& node)
30 {
31     assert((bool)node.get_primitive()->output_data_type == false
32            && "Output data type forcing is not supported for softmax_node!");
33     return node.input().get_output_layout();
34 }
35
36 std::string softmax_inst::to_string(softmax_node const& node)
37 {
38     auto desc      = node.get_primitive();
39     auto node_info = node.desc_to_json();
40
41     std::stringstream primitive_description;
42
43     node_info->dump(primitive_description);
44
45     return primitive_description.str();
46 }
47
48 softmax_inst::typed_primitive_inst(network_impl& network, softmax_node const& node)
49     : parent(network, node)
50 {
51     //    auto& input_offset  = arg.input_offset;
52     //    auto& output_offset = arg.output_offset;
53     //    auto& output_size   = arg.output_size;
54     //
55     //    auto& input_inst  = arg.input[0].primitive().as<const memory&>().argument;
56     //    auto& output_inst = arg.output[0].as<const memory&>().argument;
57     //    for (auto &x : input_offset.raw) if (x < 0) throw std::runtime_error("Softmax negative input offset.");
58     //
59     //    for(size_t i = 0; i < input_inst.size.raw.size(); ++i) {
60     //        if( input_inst.size.raw[i] < output_size.raw[i] +  input_offset.raw[i]) throw std::runtime_error("Softmax input/output size does not match.");
61     //        if(output_inst.size.raw[i] < output_size.raw[i] + output_offset.raw[i]) throw std::runtime_error("Softmax sizes too small.");
62     //    }
63
64     //auto& input_inst = network.get_topology()->get_primitives().at(desc->input()[0]);
65     //if (input_inst->output_layout->size.format == cldnn::format::bfyx)
66     //    if (input_inst->output_layout->size.spatial[0] != 1 || input_inst->output_layout->size.spatial[1] != 1)
67     //        throw std::runtime_error("Softmax input has more than one dimension per batch");
68 }
69 }