Extension Library

Inference Engine provides an InferenceEngine::IExtension interface, which defines the interface for Inference Engine Extension libraries. All extension libraries should be inherited from this interface.

Based on that, 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:21

The extension library should contain and export the method InferenceEngine::CreateExtension, 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:222
StatusCode CreateExtension(IExtension *&ext, ResponseDesc *resp) noexcept
Creates the default instance of the extension.
Represents detailed information for an error.
Definition: ie_common.h:245

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 the guide about custom operations for more information.

To understand how integrate execution kernels to the extension library, read the guide about development of custom CPU kernels. To understand how to register custom ONNX operator to the extension library, read the guide about custom ONNX operators.