リモート・コンテキスト#

ov::RemoteContext クラスの機能:

  • デバイス固有の推論コンテキストを表します。

  • リモートデバイス固有のテンソルを作成できるようにします。

プラグインが独自のリモート・コンテキストのパブリック API を提供する場合、その API はヘッダーのみであり、プラグイン・ライブラリーに依存しません。

RemoteContext クラス#

OpenVINO プラグイン API は、プラグイン固有のリモート・コンテキストの基本クラスとして使用するインターフェイス ov::IRemoteContext を提供します。これに基づいて、コンパイルされたモデルクラスの宣言は次のようになります:

class RemoteContext : public ov::IRemoteContext { 
public:     RemoteContext(); 
    const std::string& get_device_name() const override; 
    const ov::AnyMap& get_property() const override; 
    ov::SoPtr<IRemoteTensor> create_tensor(const ov::element::Type& type, 
                                           const ov::Shape& shape, 
                                           const ov::AnyMap& params = {}) override; 

private: 
    std::string m_name; 
    ov::AnyMap m_property; 
};

クラスフィールド#

サンプルクラスにはいくつかのフィールドがあります:

  • m_name - デバイス名。

  • m_property - デバイス固有のコンテキスト・プロパティー。これを使用して、RemoteContext をデバイス固有のタイプにキャストできます。

RemoteContext コンストラクター#

このコンストラクターは、リモート・コンテキスト・デバイス名とプロパティーを初期化する必要があります。

RemoteContext::RemoteContext() : m_name("TEMPLATE") {}

get_device_name()#

この関数はリモート・コンテキストからデバイス名を返します。

const std::string& RemoteContext::get_device_name() const { 
    return m_name; 
}

get_property()#

実装はリモート・コンテキストのプロパティーを返します。

const ov::AnyMap& RemoteContext::get_property() const { 
    return m_property; 
}

create_tensor()#

このメソッドは、デバイス固有のリモートテンソルを作成します。

ov::SoPtr<ov::IRemoteTensor> RemoteContext::create_tensor(const ov::element::Type& type, 
                                                        const ov::Shape& shape, 
                                                        const ov::AnyMap& params) { 

    std::shared_ptr<ov::IRemoteTensor> tensor; 

    switch (type) { 
    case ov::element::boolean: 
        tensor = 
std::make_shared<VectorTensorImpl<ov::element_type_traits<ov::element::boolean>::value_type>>(type, shape); 
        break; 
    case ov::element::bf16: 
        tensor = 
std::make_shared<VectorTensorImpl<ov::element_type_traits<ov::element::bf16>::value_type>>(type, shape); 
        break; 
    case ov::element::f16: 
        tensor = 
std::make_shared<VectorTensorImpl<ov::element_type_traits<ov::element::f16>::value_type>>(type, shape); 
        break; 
    case ov::element::f32: 
        tensor = 
std::make_shared<VectorTensorImpl<ov::element_type_traits<ov::element::f32>::value_type>>(type, shape); 
        break; 
    case ov::element::f64: 
        tensor = 
std::make_shared<VectorTensorImpl<ov::element_type_traits<ov::element::f64>::value_type>>(type, shape); 
        break; 
    case ov::element::i8: 
        tensor = 
std::make_shared<VectorTensorImpl<ov::element_type_traits<ov::element::i8>::value_type>>(type, shape); 
        break; 
    case ov::element::i16: 
        tensor = 
std::make_shared<VectorTensorImpl<ov::element_type_traits<ov::element::i16>::value_type>>(type, shape); 
        break; 
    case ov::element::i32: 
        tensor = 
std::make_shared<VectorTensorImpl<ov::element_type_traits<ov::element::i32>::value_type>>(type, shape); 
        break; 
    case ov::element::i64: 
        tensor = 
std::make_shared<VectorTensorImpl<ov::element_type_traits<ov::element::i64>::value_type>>(type, shape); 
        break; 
    case ov::element::u8: 
        tensor = 
std::make_shared<VectorTensorImpl<ov::element_type_traits<ov::element::u8>::value_type>>(type, shape); 
        break; 
    case ov::element::u16: 
        tensor = 
std::make_shared<VectorTensorImpl<ov::element_type_traits<ov::element::u16>::value_type>>(type, shape); 
        break; 
    case ov::element::u32: 
        tensor = 
std::make_shared<VectorTensorImpl<ov::element_type_traits<ov::element::u32>::value_type>>(type, shape); 
        break; 
    case ov::element::u64: 
        tensor = 
std::make_shared<VectorTensorImpl<ov::element_type_traits<ov::element::u64>::value_type>>(type, shape); 
        break; 
    default: 
        OPENVINO_THROW("Cannot create remote tensor for unsupported type: ", type); 
    } 
    return std::make_shared<VectorImpl>(tensor); 
}

デバイス固有のテンソルをサポートする次のステップは、デバイス固有の Remote Tensor クラスの作成することです。