forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ie_remote_context.hpp
144 lines (128 loc) · 5.56 KB
/
ie_remote_context.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
/**
* @brief This is a header file for the IE RemoteContext and RemoteBlob classes
*
* @file ie_remote_context.hpp
*/
#pragma once
#include <map>
#include <memory>
#include <string>
#include "ie_parameter.hpp"
#include "ie_remote_blob.hpp"
namespace InferenceEngine {
/**
* @brief This class represents an Inference Engine abstraction
* for remote (non-CPU) accelerator device-specific execution context.
* Such context represents a scope on the device within which executable
* networks and remote memory blobs can exist, function and exchange data.
*/
class INFERENCE_ENGINE_API_CLASS(RemoteContext) : public std::enable_shared_from_this<RemoteContext> {
public:
/**
* @brief A smart pointer to the RemoteContext object
*/
using Ptr = std::shared_ptr<RemoteContext>;
/**
* @brief A smart pointer to the const RemoteContext object
*/
using CPtr = std::shared_ptr<const RemoteContext>;
/**
* @brief RemoteContext virtual destructor
*/
virtual ~RemoteContext() = default;
/**
* @brief Checks if the RemoteContext object can be cast to the type T*
*
* @tparam T Type to be checked. Must represent a class derived from the RemoteContext
* @return true if this object can be dynamically cast to the type T*. Otherwise, false
*/
template <typename T,
typename std::enable_if<!std::is_pointer<T>::value && !std::is_reference<T>::value, int>::type = 0,
typename std::enable_if<std::is_base_of<RemoteContext, T>::value, int>::type = 0>
bool is() noexcept {
return dynamic_cast<T*>(this) != nullptr;
}
/**
* @brief Checks if the RemoteContext object can be cast to the type const T*
*
* @tparam T Type to be checked. Must represent a class derived from the RemoteContext
* @return true if this object can be dynamically cast to the type const T*. Otherwise, false
*/
template <typename T,
typename std::enable_if<!std::is_pointer<T>::value && !std::is_reference<T>::value, int>::type = 0,
typename std::enable_if<std::is_base_of<RemoteContext, T>::value, int>::type = 0>
bool is() const noexcept {
return dynamic_cast<const T*>(this) != nullptr;
}
/**
* @brief Casts this RemoteContext object to the type T*.
*
* @tparam T Type to cast to. Must represent a class derived from the RemoteContext
* @return Raw pointer to the object of the type T or nullptr on error
*/
template <typename T,
typename std::enable_if<!std::is_pointer<T>::value && !std::is_reference<T>::value, int>::type = 0,
typename std::enable_if<std::is_base_of<RemoteContext, T>::value, int>::type = 0>
T* as() noexcept {
return dynamic_cast<T*>(this);
}
/**
* @brief Casts this RemoteContext object to the type const T*.
*
* @tparam T Type to cast to. Must represent a class derived from the RemoteContext
* @return Raw pointer to the object of the type const T or nullptr on error
*/
template <typename T,
typename std::enable_if<!std::is_pointer<T>::value && !std::is_reference<T>::value, int>::type = 0,
typename std::enable_if<std::is_base_of<RemoteContext, T>::value, int>::type = 0>
const T* as() const noexcept {
return dynamic_cast<const T*>(this);
}
/**
* @brief Returns name of the device on which underlying object is allocated.
* Abstract method.
* @return A device name string in the same format as that in plugin metric.
*/
virtual std::string getDeviceName() const noexcept = 0;
/**
* @brief Allocates memory blob in device memory or wraps user-supplied memory handle
* using the specified tensor description and low-level device-specific parameters.
* Returns a pointer to the object which implements RemoteBlob interface.
* @param tensorDesc Defines the layout and dims of the blob
* @param params Map of the low-level blob object parameters.
* Abstract method.
* @return A pointer to plugin object that implements RemoteBlob interface.
*/
virtual RemoteBlob::Ptr CreateBlob(const TensorDesc& tensorDesc, const ParamMap& params = {}) = 0;
/**
* @brief Allocates host accessible memory blob friendly for the device in current context
* Returns a pointer to the object which implements MemoryBlob interface.
* @param tensorDesc Defines the layout and dims of the blob
* @return A pointer to host accessible MemoryBlob object
*/
virtual MemoryBlob::Ptr CreateHostBlob(const TensorDesc& tensorDesc);
/**
* @brief Returns a map of device-specific parameters required for low-level
* operations with underlying object.
* Parameters include device/context handles, access flags,
* etc. Contents of the map returned depend on remote execution context that is
* currently set on the device (working scenario).
* Abstract method.
* @return A map of name/parameter elements.
*/
virtual ParamMap getParams() const = 0;
};
/**
* @brief A wrapper of CreateBlob method of RemoteContext to keep consistency with
* plugin-specific wrappers.
* @param desc Defines the layout and dims of the blob
* @param ctx Pointer to the plugin object derived from RemoteContext.
* @return A pointer to plugin object that implements RemoteBlob interface.
*/
inline RemoteBlob::Ptr make_shared_blob(const TensorDesc& desc, RemoteContext::Ptr ctx) {
return ctx->CreateBlob(desc);
}
} // namespace InferenceEngine