Extension Library¶
Inference Engine provides an InferenceEngine::IExtension interface, which defines the interface for Inference Engine Extension libraries. Inherit all extension libraries from this interface. The example below contains an implementation of two operations: Template
used as an example in this document and FFT
used as a more complex example from the Custom Operations Guide.
Note
FFT
operation is implemented using the OpenCV library functions cv::dft
and cv::idft
.
Based on that, the declaration of an extension class can look as follows:
namespace TemplateExtension {
class Extension : public InferenceEngine::IExtension {
public:
Extension();
~Extension();
void GetVersion(const InferenceEngine::Version*& versionInfo) const noexcept override;
void Unload() noexcept override {}
std::map<std::string, ngraph::OpSet> getOpSets() override;
std::vector<std::string> getImplTypes(const std::shared_ptr<ngraph::Node>& node) override;
InferenceEngine::ILayerImpl::Ptr getImplementation(const std::shared_ptr<ngraph::Node>& node, const std::string& implType) override;
};
} // namespace TemplateExtension
The extension library should contain and export the InferenceEngine::CreateExtension method, which creates an Extension
class:
// Generate exported function
IE_DEFINE_EXTENSION_CREATE_FUNCTION(Extension)
Also, an Extension
object should implement the following methods:
InferenceEngine::IExtension::Release deletes an extension object.
InferenceEngine::IExtension::GetVersion returns information about the version of the library.
void Extension::GetVersion(const InferenceEngine::Version*& versionInfo) const noexcept {
static InferenceEngine::Version ExtensionDescription = {
{1, 0}, // extension API version
"1.0",
"template_ext" // extension description message
};
versionInfo = &ExtensionDescription;
}
Implement the InferenceEngine::IExtension::getOpSets method if the extension contains custom layers. Read Custom nGraph Operation for more information.
To integrate execution kernels to the extension library, read How to Implement Custom CPU Operations. To register a custom ONNX* operator to the extension library, read Custom ONNX Operators.