Publishing R3
[platform/upstream/dldt.git] / inference-engine / src / cldnn_engine / cldnn_custom_layer.h
1 // Copyright (C) 2018 Intel Corporation
2 //
3 // SPDX-License-Identifier: Apache-2.0
4 //
5
6 #pragma once
7 #include <memory>
8 #include <string>
9 #include <sstream>
10 #include <vector>
11 #include <map>
12 #include <ie_common.h>
13 #include "pugixml.hpp"
14 #include "CPP/tensor.hpp"
15
16 namespace CLDNNPlugin {
17
18 using CLDNNCustomLayerPtr = std::shared_ptr<class CLDNNCustomLayer>;
19 using CLDNNCustomLayerMap = std::map<std::string, CLDNNCustomLayerPtr>;
20 class CLDNNCustomLayer{
21 public:
22     static void LoadFromFile(
23         const std::string configFile,
24         CLDNNCustomLayerMap& customLayers,
25         bool can_be_missed = false);
26
27     typedef enum {
28         Input,
29         Output,
30         Data,
31     } ParamType;
32     struct KerenlParam {
33         KerenlParam() :type(Input), paramIndex(-1), portIndex(-1),
34                        format(cldnn::format::any) {}
35         ParamType type;
36         int paramIndex;
37         int portIndex;
38         std::string blobName;
39         cldnn::format format;
40     };
41
42     struct KernelDefine {
43         std::string name;
44         std::string param;
45         std::string default_value;
46         std::string prefix;
47         std::string postfix;
48     };
49
50     const std::string& Name()const { return m_layerName; }
51     const std::string& KernelSource()const { return m_kernelSource; }
52     const std::string& KernelEntry()const { return m_kernelEntry; }
53     const std::vector<KernelDefine>& Defines()const { return m_defines; }
54     const std::string& CompilerOptions()const { return m_compilerOptions; }
55     const std::vector<std::string>& GlobalSizeRules()const { return m_globalSizeRules; }
56     const std::vector<std::string>& LocalSizeRules()const { return m_localSizeRules; }
57     const std::vector<KerenlParam>& KernelParams()const { return m_kernelParams; }
58     const int InputDimSourceIndex() { return m_wgDimInputIdx; }
59
60 protected:
61     CLDNNCustomLayer() {}
62     explicit CLDNNCustomLayer(const std::string dirname) : m_configDir(dirname) {}
63
64     bool Error() const { return m_ErrorMessage.length() > 0; }
65     void LoadSingleLayer(const pugi::xml_node& node);
66     void ProcessKernelNode(const pugi::xml_node& node);
67     void ProcessBuffersNode(const pugi::xml_node& node);
68     void ProcessCompilerOptionsNode(const pugi::xml_node& node);
69     void ProcessWorkSizesNode(const pugi::xml_node& node);
70     static bool IsLegalSizeRule(const std::string& rule);
71     static cldnn::format FormatFromString(const std::string& str);
72
73     std::string m_configDir;
74     std::string m_layerName;
75     std::string m_kernelSource;
76     std::string m_kernelEntry;
77     std::vector<KernelDefine> m_defines;  // <name , take value from> <x,y> --> #define x value_of
78     std::string m_compilerOptions;
79     int m_wgDimInputIdx;
80     std::vector<std::string> m_globalSizeRules;
81     std::vector<std::string> m_localSizeRules;
82     std::vector<KerenlParam> m_kernelParams;
83     std::string m_ErrorMessage;
84 };
85
86 };  // namespace CLDNNPlugin