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, // HWC used in most software layers
27 BFYX = 1, // CHW used if HW module is enabled
28 Any = 2, // doesn't really matter
32 VPU_DECLARE_ENUM(CustomParamType,
42 VPU_DECLARE_ENUM(CustomDimSource,
47 class CustomLayer final {
49 using Ptr = std::shared_ptr<CustomLayer>;
51 struct KernelParam final {
52 CustomParamType type = CustomParamType::Input;
53 CustomDataFormat format = CustomDataFormat::Any;
57 SmallVector<std::string> bufferSizeRules;
58 CustomDimSource dimSource;
62 static ie::details::caseless_map<std::string, std::vector<CustomLayer::Ptr>> loadFromFile(
63 const std::string& configFile,
64 bool canBeMissed = false);
66 const std::string& kernelBinary() const { return _kernelBinary; }
68 void setStageNumInputs(int id);
69 int stageNumInputs() const;
70 int kernelAddress(int idx = 1) const;
71 int maxShaves() const;
72 const std::map<std::string, std::string>& whereParams() const { return _whereParams; }
74 const SmallVector<KernelParam>& bindings() const { return _kernelParams; }
75 const SmallVector<std::string>& parameters() const { return _parameters; }
77 const SmallVector<std::string>& globalSizeRules() const { return _globalSizeRules; }
78 const SmallVector<std::string>& localSizeRules() const { return _localSizeRules; }
80 CustomDimSource dimSource() const { return _wgDimSource; }
81 int dimSourceIndex() const { return _wgDimIdx; }
84 explicit CustomLayer(const std::string& dirname) : _configDir(dirname) {}
86 void loadSingleLayer(const pugi::xml_node& node);
87 void processWhere(const pugi::xml_node& node);
88 void processKernelNode(const pugi::xml_node& node);
89 void processParametersNode(const pugi::xml_node& node);
90 void processWorkSizesNode(const pugi::xml_node& node);
92 static bool isLegalSizeRule(const std::string& rule);
93 static CustomDataFormat formatFromString(const std::string& str);
96 std::string _configDir;
97 std::string _layerName;
98 std::string _kernelEntry;
99 std::string _kernelBinary;
100 std::map<std::string, std::string> _whereParams;
103 int _stageNumInputs = -1;
105 SmallVector<KernelParam> _kernelParams;
106 SmallVector<std::string> _globalSizeRules;
107 SmallVector<std::string> _localSizeRules;
108 SmallVector<std::string> _parameters;
110 std::map<uint32_t, uint32_t, std::greater<uint32_t>> _kernelAddress;
112 CustomDimSource _wgDimSource = CustomDimSource::Input;