Skip to content

Commit 47fe50c

Browse files
[GPU] 2.0 plugin api impl (openvinotoolkit#18920)
1 parent 8e0d8dd commit 47fe50c

File tree

90 files changed

+3416
-6316
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+3416
-6316
lines changed

src/bindings/c/tests/ov_remote_context_test.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,9 @@ TEST_P(ov_remote_context_ocl, create_remote_tensor_nv12_from_ocl_image2D) {
360360
const int height = 480;
361361
const int width = 640;
362362
ov_shape_t shape_y = {0, nullptr};
363-
int64_t dims_y[4] = {1, 1, height, width};
363+
int64_t dims_y[4] = {1, height, width, 1};
364364
ov_shape_t shape_uv = {0, nullptr};
365-
int64_t dims_uv[4] = {1, 2, height / 2, width / 2};
365+
int64_t dims_uv[4] = {1, height / 2, width / 2, 2};
366366

367367
cl_int err;
368368
cl_image_format image_format;
@@ -555,9 +555,9 @@ TEST_P(ov_remote_context_ocl, remote_tensor_nv12_inference) {
555555
EXPECT_NE(nullptr, context);
556556

557557
ov_shape_t shape_y = {0, nullptr};
558-
int64_t dims_y[4] = {1, 1, height, width};
558+
int64_t dims_y[4] = {1, height, width, 1};
559559
ov_shape_t shape_uv = {0, nullptr};
560-
int64_t dims_uv[4] = {1, 2, height / 2, width / 2};
560+
int64_t dims_uv[4] = {1, height / 2, width / 2, 2};
561561

562562
cl_int err;
563563
cl_image_format image_format;

src/inference/dev_api/openvino/runtime/isync_infer_request.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,12 @@ class OPENVINO_RUNTIME_API ISyncInferRequest : public IInferRequest {
151151
const std::function<void(ov::SoPtr<ov::ITensor>& tensor)>& allocate_callback);
152152

153153
std::unordered_map<std::shared_ptr<ov::descriptor::Tensor>, std::vector<ov::SoPtr<ov::ITensor>>> m_batched_tensors;
154+
ov::SoPtr<ov::ITensor>& get_tensor_ptr(const ov::Output<const ov::Node>& port) const;
154155

155156
private:
156157
std::shared_ptr<const ov::ICompiledModel> m_compiled_model;
157158
// Mutable to return reference to ov::Tensor
158159
mutable std::unordered_map<std::shared_ptr<ov::descriptor::Tensor>, ov::SoPtr<ov::ITensor>> m_tensors;
159-
ov::SoPtr<ov::ITensor>& get_tensor_ptr(const ov::Output<const ov::Node>& port) const;
160160

161161
/**
162162
* @brief Finds input or output port

src/inference/dev_api/openvino/runtime/make_tensor.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ OPENVINO_RUNTIME_API ov::SoPtr<ov::ITensor> get_tensor_impl(const ov::Tensor& te
6767

6868
IE_SUPPRESS_DEPRECATED_START
6969
/** @cond INTERNAL */
70-
ov::SoPtr<ITensor> make_tensor(const std::shared_ptr<InferenceEngine::Blob>& tensor);
70+
ov::SoPtr<ITensor> make_tensor(const std::shared_ptr<InferenceEngine::Blob>& tensor, bool unwrap = false);
7171
const InferenceEngine::Blob* get_hardware_blob(const InferenceEngine::Blob* blob);
7272
InferenceEngine::Blob* get_hardware_blob(InferenceEngine::Blob* blob);
7373

+184
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
// Copyright (C) 2018-2023 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
5+
#pragma once
6+
7+
#include "ie_ngraph_utils.hpp"
8+
#include "ie_remote_blob.hpp"
9+
#include "ie_remote_context.hpp"
10+
#include "openvino/runtime/iremote_context.hpp"
11+
12+
namespace ov {
13+
namespace legacy_convert {
14+
15+
INFERENCE_ENGINE_API_CPP(ov::SoPtr<ov::IRemoteContext>)
16+
convert_remote_context(const std::shared_ptr<InferenceEngine::RemoteContext>& context);
17+
INFERENCE_ENGINE_API_CPP(ie::Blob*) get_hardware_blob(ie::Blob* blob);
18+
19+
class INFERENCE_ENGINE_API_CLASS(TensorHolder) {
20+
public:
21+
TensorHolder(ov::SoPtr<ov::ITensor> tensor) : _tensor(tensor) {}
22+
23+
const ov::SoPtr<ov::ITensor>& get_tensor() const {
24+
return _tensor;
25+
}
26+
27+
private:
28+
ov::SoPtr<ov::ITensor> _tensor;
29+
};
30+
31+
} // namespace legacy_convert
32+
33+
/**
34+
* @brief Tensor what contains InferenceEngine::RemoteBlob inside
35+
* Blob owns the memory
36+
*/
37+
class INFERENCE_ENGINE_API_CLASS(RemoteBlobTensor) : public IRemoteTensor {
38+
mutable element::Type m_type;
39+
mutable Shape m_shape;
40+
mutable Strides m_strides;
41+
mutable ov::AnyMap m_properties;
42+
mutable std::string m_dev_name;
43+
44+
public:
45+
std::shared_ptr<ie::RemoteBlob> blob;
46+
47+
RemoteBlobTensor(const InferenceEngine::RemoteBlob::Ptr& blob) : blob{blob} {
48+
OPENVINO_ASSERT(blob);
49+
m_shape = blob->getTensorDesc().getBlockingDesc().getBlockDims();
50+
}
51+
52+
const element::Type& get_element_type() const override {
53+
m_type = InferenceEngine::details::convertPrecision(blob->getTensorDesc().getPrecision());
54+
return m_type;
55+
}
56+
57+
void set_shape(ov::Shape shape) override {
58+
blob->setShape({shape.begin(), shape.end()});
59+
}
60+
61+
const Shape& get_shape() const override {
62+
m_shape = blob->getTensorDesc().getBlockingDesc().getBlockDims();
63+
return m_shape;
64+
}
65+
66+
const Strides& get_strides() const override {
67+
OPENVINO_ASSERT(get_element_type().bitwidth() >= 8,
68+
"Could not get strides for types with bitwidths less then 8 bit. Tensor type: ",
69+
get_element_type());
70+
const auto& element_strides = blob->getTensorDesc().getBlockingDesc().getStrides();
71+
const size_t elem_size = get_element_type().size();
72+
m_strides.clear();
73+
m_strides.resize(element_strides.size());
74+
std::transform(element_strides.begin(), element_strides.end(), m_strides.begin(), [&elem_size](size_t stride) {
75+
return stride * elem_size;
76+
});
77+
return m_strides;
78+
}
79+
80+
size_t get_size() const override {
81+
return blob->size();
82+
}
83+
84+
size_t get_byte_size() const override {
85+
return blob->byteSize();
86+
}
87+
88+
const AnyMap& get_properties() const override {
89+
m_properties = blob->getParams();
90+
return m_properties;
91+
}
92+
93+
const std::string& get_device_name() const override {
94+
m_dev_name = blob->getDeviceName();
95+
return m_dev_name;
96+
}
97+
};
98+
99+
/**
100+
* @brief Create InferenceEngine::RemoteBlob from the Tensor
101+
*/
102+
class INFERENCE_ENGINE_API_CLASS(TensorRemoteBlob) : public ie::RemoteBlob, public ov::legacy_convert::TensorHolder {
103+
public:
104+
TensorRemoteBlob(const ov::SoPtr<ITensor>& tensor, ie::TensorDesc desc)
105+
: ie::RemoteBlob{desc},
106+
ov::legacy_convert::TensorHolder(tensor) {
107+
OPENVINO_ASSERT(this->get_tensor());
108+
}
109+
std::shared_ptr<ov::IRemoteTensor> cast_tensor() const {
110+
auto remote = std::dynamic_pointer_cast<ov::IRemoteTensor>(get_tensor()._ptr);
111+
OPENVINO_ASSERT(remote);
112+
return remote;
113+
}
114+
AnyMap getParams() const override {
115+
return cast_tensor()->get_properties();
116+
}
117+
std::string getDeviceName() const noexcept override {
118+
try {
119+
return cast_tensor()->get_device_name();
120+
} catch (...) {
121+
return {};
122+
}
123+
}
124+
std::shared_ptr<ie::RemoteContext> getContext() const noexcept override {
125+
return {};
126+
}
127+
128+
void allocate() noexcept override {}
129+
bool deallocate() noexcept override {
130+
return true;
131+
}
132+
ie::LockedMemory<void> buffer() noexcept override {
133+
return {nullptr, nullptr, 0};
134+
}
135+
ie::LockedMemory<const void> cbuffer() const noexcept override {
136+
return {nullptr, nullptr, 0};
137+
}
138+
ie::LockedMemory<void> rwmap() noexcept override {
139+
return {nullptr, nullptr, 0};
140+
}
141+
ie::LockedMemory<const void> rmap() const noexcept override {
142+
return {nullptr, nullptr, 0};
143+
}
144+
ie::LockedMemory<void> wmap() noexcept override {
145+
return {nullptr, nullptr, 0};
146+
}
147+
const std::shared_ptr<ie::IAllocator>& getAllocator() const noexcept override {
148+
return m_allocator;
149+
}
150+
void* getHandle() const noexcept override {
151+
return nullptr;
152+
}
153+
154+
using TensorHolder::get_tensor;
155+
156+
private:
157+
std::shared_ptr<ie::IAllocator> m_allocator;
158+
};
159+
160+
} // namespace ov
161+
162+
namespace InferenceEngine {
163+
164+
class INFERENCE_ENGINE_API_CLASS(IRemoteContextWrapper) : public ov::IRemoteContext {
165+
private:
166+
std::shared_ptr<InferenceEngine::RemoteContext> m_context;
167+
mutable std::string m_name;
168+
mutable ov::AnyMap m_params;
169+
170+
public:
171+
IRemoteContextWrapper(const std::shared_ptr<InferenceEngine::RemoteContext>& context) : m_context(context) {}
172+
virtual ~IRemoteContextWrapper() = default;
173+
const std::shared_ptr<InferenceEngine::RemoteContext>& get_context();
174+
const std::string& get_device_name() const override;
175+
176+
const ov::AnyMap& get_property() const override;
177+
178+
ov::SoPtr<ov::IRemoteTensor> create_tensor(const ov::element::Type& type,
179+
const ov::Shape& shape,
180+
const ov::AnyMap& params = {}) override;
181+
ov::SoPtr<ov::ITensor> create_host_tensor(const ov::element::Type type, const ov::Shape& shape) override;
182+
};
183+
184+
} // namespace InferenceEngine

src/inference/include/openvino/runtime/intel_gpu/ocl/dx.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class D3DContext : public ClContext {
139139
* @param target_tile_id Desired tile id within given context for multi-tile system. Default value (-1) means
140140
* that root device should be used
141141
*/
142-
D3DContext(Core& core, ID3D11Device* device, int target_tile_id = -1) : ClContext(core, (cl_context) nullptr) {
142+
D3DContext(Core& core, ID3D11Device* device, int target_tile_id = -1) : ClContext() {
143143
// clang-format off
144144
AnyMap context_params = {
145145
{ov::intel_gpu::context_type.name(), ov::intel_gpu::ContextType::VA_SHARED},

src/inference/include/openvino/runtime/intel_gpu/ocl/ocl.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ class ClContext : public RemoteContext {
177177
*/
178178
static constexpr const char* device_name = "GPU";
179179

180+
/**
181+
* @brief Default constructor which can be used in derived classes to avoid multiple create_context() calls
182+
*/
183+
ClContext() = default;
184+
180185
public:
181186
// Needed to make create_tensor overloads from base class visible for user
182187
using RemoteContext::create_tensor;

src/inference/include/openvino/runtime/intel_gpu/ocl/va.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class VAContext : public ClContext {
104104
* @param target_tile_id Desired tile id within given context for multi-tile system. Default value (-1) means
105105
* that root device should be used
106106
*/
107-
VAContext(Core& core, VADisplay device, int target_tile_id = -1) : ClContext(core, (cl_context) nullptr) {
107+
VAContext(Core& core, VADisplay device, int target_tile_id = -1) : ClContext() {
108108
AnyMap context_params = {{ov::intel_gpu::context_type.name(), ov::intel_gpu::ContextType::VA_SHARED},
109109
{ov::intel_gpu::va_device.name(), static_cast<gpu_handle_param>(device)},
110110
{ov::intel_gpu::tile_id.name(), target_tile_id}};

src/inference/src/dev/converter_utils.cpp

+33-43
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class IVariableStateInternalWrapper : public InferenceEngine::IVariableStateInte
215215
}
216216

217217
void SetState(const InferenceEngine::Blob::Ptr& newState) override {
218-
m_state->set_state(ov::make_tensor(newState));
218+
m_state->set_state(ov::make_tensor(newState, true));
219219
}
220220

221221
InferenceEngine::Blob::CPtr GetState() const override {
@@ -542,7 +542,7 @@ class IInferRequestInternalWrapper : public InferenceEngine::IInferRequestIntern
542542

543543
void SetBlob(const std::string& name, const InferenceEngine::Blob::Ptr& data) override {
544544
try {
545-
m_request->set_tensor(find_port(name), ov::make_tensor(data));
545+
m_request->set_tensor(find_port(name), ov::make_tensor(data, true));
546546
} catch (const ov::Exception& ex) {
547547
const std::string what = ex.what();
548548
if (what.find("Failed to set tensor") != std::string::npos) {
@@ -556,7 +556,7 @@ class IInferRequestInternalWrapper : public InferenceEngine::IInferRequestIntern
556556
try {
557557
std::vector<ov::SoPtr<ov::ITensor>> tensors;
558558
for (const auto& blob : blobs) {
559-
tensors.emplace_back(ov::make_tensor(blob));
559+
tensors.emplace_back(ov::make_tensor(blob, true));
560560
}
561561
m_request->set_tensors(find_port(name), tensors);
562562
} catch (const ov::Exception& ex) {
@@ -860,50 +860,40 @@ ov::SoPtr<::ov::IAsyncInferRequest> ov::legacy_convert::convert_infer_request(
860860
}
861861

862862
namespace InferenceEngine {
863+
const std::shared_ptr<InferenceEngine::RemoteContext>& IRemoteContextWrapper::get_context() {
864+
return m_context;
865+
}
863866

864-
class IRemoteContextWrapper : public ov::IRemoteContext {
865-
private:
866-
std::shared_ptr<InferenceEngine::RemoteContext> m_context;
867-
mutable std::string m_name;
868-
mutable ov::AnyMap m_params;
869-
870-
public:
871-
IRemoteContextWrapper(const std::shared_ptr<InferenceEngine::RemoteContext>& context) : m_context(context) {}
872-
virtual ~IRemoteContextWrapper() = default;
873-
const std::shared_ptr<InferenceEngine::RemoteContext>& get_context() {
874-
return m_context;
875-
}
876-
const std::string& get_device_name() const override {
877-
m_name = m_context->getDeviceName();
878-
return m_name;
879-
}
867+
const std::string& IRemoteContextWrapper::get_device_name() const {
868+
m_name = m_context->getDeviceName();
869+
return m_name;
870+
}
880871

881-
const ov::AnyMap& get_property() const override {
882-
m_params = m_context->getParams();
883-
return m_params;
884-
}
872+
const ov::AnyMap& IRemoteContextWrapper::get_property() const {
873+
m_params = m_context->getParams();
874+
return m_params;
875+
}
885876

886-
ov::SoPtr<ov::IRemoteTensor> create_tensor(const ov::element::Type& type,
887-
const ov::Shape& shape,
888-
const ov::AnyMap& params = {}) override {
889-
InferenceEngine::TensorDesc desc(InferenceEngine::details::convertPrecision(type),
890-
shape,
891-
InferenceEngine::TensorDesc::getLayoutByDims(shape));
892-
auto blob = m_context->CreateBlob(desc, params);
893-
blob->allocate();
894-
auto tensor = ov::make_tensor(blob);
895-
return {std::dynamic_pointer_cast<ov::IRemoteTensor>(tensor._ptr), tensor._so};
896-
}
877+
ov::SoPtr<ov::IRemoteTensor> IRemoteContextWrapper::create_tensor(const ov::element::Type& type,
878+
const ov::Shape& shape,
879+
const ov::AnyMap& params) {
880+
InferenceEngine::TensorDesc desc(InferenceEngine::details::convertPrecision(type),
881+
shape,
882+
InferenceEngine::TensorDesc::getLayoutByDims(shape));
883+
auto blob = m_context->CreateBlob(desc, params);
884+
blob->allocate();
885+
auto tensor = ov::make_tensor(blob);
886+
return {std::dynamic_pointer_cast<ov::IRemoteTensor>(tensor._ptr), tensor._so};
887+
}
897888

898-
ov::SoPtr<ov::ITensor> create_host_tensor(const ov::element::Type type, const ov::Shape& shape) override {
899-
InferenceEngine::TensorDesc desc(InferenceEngine::details::convertPrecision(type),
900-
shape,
901-
InferenceEngine::TensorDesc::getLayoutByDims(shape));
902-
auto blob = m_context->CreateHostBlob(desc);
903-
blob->allocate();
904-
return ov::make_tensor(blob);
905-
}
906-
};
889+
ov::SoPtr<ov::ITensor> IRemoteContextWrapper::create_host_tensor(const ov::element::Type type, const ov::Shape& shape) {
890+
InferenceEngine::TensorDesc desc(InferenceEngine::details::convertPrecision(type),
891+
shape,
892+
InferenceEngine::TensorDesc::getLayoutByDims(shape));
893+
auto blob = m_context->CreateHostBlob(desc);
894+
blob->allocate();
895+
return ov::make_tensor(blob);
896+
}
907897

908898
} // namespace InferenceEngine
909899

src/inference/src/dev/converter_utils.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "openvino/runtime/icompiled_model.hpp"
1616
#include "openvino/runtime/iplugin.hpp"
1717
#include "openvino/runtime/iremote_context.hpp"
18+
#include "remote_utils.hpp"
1819

1920
namespace ov {
2021
namespace legacy_convert {
@@ -40,11 +41,9 @@ ov::SoPtr<::ov::IAsyncInferRequest> convert_infer_request(
4041
const std::string& plugin_name = "");
4142

4243
std::shared_ptr<InferenceEngine::RemoteContext> convert_remote_context(const ov::SoPtr<ov::IRemoteContext>& context);
43-
ov::SoPtr<ov::IRemoteContext> convert_remote_context(const std::shared_ptr<InferenceEngine::RemoteContext>& context);
4444

4545
std::vector<ov::Extension::Ptr> convert_extension(const std::vector<InferenceEngine::IExtensionPtr>& exts);
4646
std::vector<InferenceEngine::IExtensionPtr> convert_extension(const std::vector<ov::Extension::Ptr>& exts);
4747

4848
} // namespace legacy_convert
4949
} // namespace ov
50-

0 commit comments

Comments
 (0)