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 {}
void Release() noexcept override { delete this; }
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
This class is the main extension interface.
Definition: ie_iextension.h:149
std::shared_ptr< ILayerImpl > Ptr
A shared pointer to the ILayerImpl interface.
Definition: ie_iextension.h:92
Represents version information that describes plugins and the inference engine runtime library.
Definition: ie_version.hpp:24

The extension library should contain and export the InferenceEngine::CreateExtension method, which creates an Extension class:

// Exported function
try {
ext = new Extension();
return OK;
} catch (std::exception &ex) {
if (resp) {
std::string err = ((std::string) "Couldn't create extension: ") + ex.what();
err.copy(resp->msg, 255);
}
return InferenceEngine::GENERAL_ERROR;
}
}
StatusCode
This enum contains codes for all possible return values of the interface functions.
Definition: ie_common.h:224
StatusCode CreateExtension(IExtension *&ext, ResponseDesc *resp) noexcept
Creates the default instance of the extension.
Represents detailed information for an error.
Definition: ie_common.h:248

Also, an Extension object should implement the following methods:

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.