1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
14 #include <details/caseless.hpp>
16 #include <pugixml.hpp>
18 #include <vpu/utils/enums.hpp>
19 #include <vpu/utils/containers.hpp>
23 namespace ie = InferenceEngine;
25 VPU_DECLARE_ENUM(CustomDataFormat,
26 BYXF = 0, // NHWC used in most software layers
27 BFYX = 1, // NCHW used if HW module is enabled
28 YXF = 2, // HWC used in most software layers
29 FYX = 3, // CHW used if HW module is enabled
30 Any = 4, // doesn't really matter
34 VPU_DECLARE_ENUM(CustomParamType,
44 VPU_DECLARE_ENUM(CustomDimSource,
49 class CustomLayer final {
51 using Ptr = std::shared_ptr<CustomLayer>;
53 struct KernelParam final {
54 CustomParamType type = CustomParamType::Input;
55 CustomDataFormat format = CustomDataFormat::Any;
59 SmallVector<std::string> bufferSizeRules;
60 CustomDimSource dimSource;
64 static ie::details::caseless_map<std::string, std::vector<CustomLayer::Ptr>> loadFromFile(
65 const std::string& configFile,
66 bool canBeMissed = false);
68 const std::string& kernelBinary() const { return _kernelBinary; }
70 void setStageNumInputs(int id);
71 int stageNumInputs() const;
72 int kernelAddress(int idx = 1) const;
73 int maxShaves() const;
74 const std::map<std::string, std::string>& whereParams() const { return _whereParams; }
76 const SmallVector<KernelParam>& bindings() const { return _kernelParams; }
77 const SmallVector<std::string>& parameters() const { return _parameters; }
79 const SmallVector<std::string>& globalSizeRules() const { return _globalSizeRules; }
80 const SmallVector<std::string>& localSizeRules() const { return _localSizeRules; }
82 CustomDimSource dimSource() const { return _wgDimSource; }
83 int dimSourceIndex() const { return _wgDimIdx; }
86 explicit CustomLayer(const std::string& dirname) : _configDir(dirname) {}
88 void loadSingleLayer(const pugi::xml_node& node);
89 void processWhere(const pugi::xml_node& node);
90 void processKernelNode(const pugi::xml_node& node);
91 void processParametersNode(const pugi::xml_node& node);
92 void processWorkSizesNode(const pugi::xml_node& node);
94 static bool isLegalSizeRule(const std::string& rule);
95 static CustomDataFormat formatFromString(const std::string& str);
98 std::string _configDir;
99 std::string _layerName;
100 std::string _kernelEntry;
101 std::string _kernelBinary;
102 std::map<std::string, std::string> _whereParams;
105 int _stageNumInputs = -1;
107 SmallVector<KernelParam> _kernelParams;
108 SmallVector<std::string> _globalSizeRules;
109 SmallVector<std::string> _localSizeRules;
110 SmallVector<std::string> _parameters;
112 std::map<uint32_t, uint32_t, std::greater<uint32_t>> _kernelAddress;
114 CustomDimSource _wgDimSource = CustomDimSource::Input;