Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
68d68c1
wip
michal-miotk Mar 30, 2026
3a92b0c
wip
michal-miotk Mar 30, 2026
17b5f13
wip
michal-miotk Mar 31, 2026
603c4fa
wip
michal-miotk Mar 31, 2026
2ebfdd3
wip
michal-miotk Mar 31, 2026
58ad113
wip
michal-miotk Apr 1, 2026
70604fb
works dx11
michal-miotk Apr 3, 2026
e3025dc
pass dx12
michal-miotk Apr 3, 2026
fb20b2c
x
michal-miotk Apr 23, 2026
526e80e
dx12 works
michal-miotk Apr 23, 2026
c962e4b
works dx11
michal-miotk Apr 24, 2026
903fc7d
better dx12 test, closing handles in dx11 test
michal-miotk Apr 24, 2026
68e500b
added vulkan test
michal-miotk Apr 24, 2026
ad3e5f6
fix vulkan
michal-miotk Apr 24, 2026
434293f
compilation only on windows
michal-miotk Apr 24, 2026
1b3dec9
delete unnecesssary things
michal-miotk Apr 24, 2026
d6af4b9
delete unnecessary things
michal-miotk Apr 27, 2026
7ca34c8
delete unneccessary things v2
michal-miotk Apr 27, 2026
eed1327
fix formating
michal-miotk Apr 28, 2026
ec48e76
fix copyright
michal-miotk Apr 28, 2026
629c5d2
added dx12 test based on npu test
michal-miotk Apr 28, 2026
1b98154
wip linux
michal-miotk Apr 28, 2026
20c11a2
works on linux
michal-miotk Apr 29, 2026
c239ab5
wip memo print
michal-miotk Apr 30, 2026
5462dec
FIX Ocl skip tests, added ram and gpu prints, fix vulkan test on windows
michal-miotk Apr 30, 2026
56c2108
fix reviewer insights
michal-miotk May 4, 2026
9e6bdff
NIT
michal-miotk May 4, 2026
b5f52f1
delete file added by mistake
michal-miotk May 4, 2026
060f076
fix format
michal-miotk May 4, 2026
3d6f997
fix vulkan fetch
michal-miotk May 4, 2026
47fd2d0
shorter path to not exceed 260 chars on windows
michal-miotk May 5, 2026
7ace878
Merge branch 'master' into remoteNT
michal-miotk May 5, 2026
1991726
refactor
michal-miotk May 5, 2026
0833756
fix format
michal-miotk May 5, 2026
3a35dd0
Merge branch 'master' into remoteNT
michal-miotk May 5, 2026
56248c2
little clean ocl.hpp, memory info defined in separated file
michal-miotk May 5, 2026
67c5f96
delete mem usage log
michal-miotk May 5, 2026
b4b57e0
delete ram diagnostic
michal-miotk May 5, 2026
a7eb0b5
wip
michal-miotk May 5, 2026
7152ce6
fix linux build
michal-miotk May 6, 2026
d402d76
fix build linux
michal-miotk May 6, 2026
94f33d4
lowering vulkan version to be compatible with older cmake
michal-miotk May 6, 2026
0ff1e89
fix build on non ocl 3_0 machines
michal-miotk May 6, 2026
0add3e3
repair fix for opencl lower than 3_0
michal-miotk May 6, 2026
0c7eff6
workaround also on windows
michal-miotk May 6, 2026
ee6533f
WA for windows debug
michal-miotk May 6, 2026
0cf9f43
delete changes in snippets
michal-miotk May 7, 2026
802c5ee
diagnostic for 22
michal-miotk May 7, 2026
18a7c18
Revert "delete changes in snippets"
michal-miotk May 7, 2026
806e501
Revert "diagnostic for 22"
michal-miotk May 7, 2026
082175a
fix 22, lowering version of vulkan to be able work without pkg config
michal-miotk May 7, 2026
744f6d3
set cache
michal-miotk May 7, 2026
30e5bb5
lowering further vulkan version, mod to install vulkan
michal-miotk May 7, 2026
cb070a9
changed path of vulkan in setupvars
michal-miotk May 8, 2026
2609a52
fix compilation on windows and linux
michal-miotk May 8, 2026
55ee151
apply 4/5 AI review comments
michal-miotk May 11, 2026
8bf92fe
Merge branch 'master' into remoteNT
michal-miotk May 11, 2026
79b1a12
exclude vulkand from win tests
michal-miotk May 11, 2026
4a68bd3
vulkan now in 3rd party
michal-miotk May 11, 2026
ecd3967
added aliases
michal-miotk May 11, 2026
94d9819
skip vulkan test
michal-miotk May 12, 2026
f93a237
delete change in docs
michal-miotk May 13, 2026
2b1130e
wip
michal-miotk May 14, 2026
f814f50
apply part of review
michal-miotk May 15, 2026
a5453ca
small texture (due to swizzle) instead buffer
michal-miotk May 15, 2026
83c675e
delete unnecessary includes
michal-miotk May 15, 2026
2ad311a
try to fix compilation
michal-miotk May 18, 2026
850f127
acquire and release
michal-miotk May 19, 2026
8c1af47
better include in tests, delete unnecessary things in tests
michal-miotk May 19, 2026
9b64a51
minor updates
michal-miotk May 19, 2026
19f8fcb
skip driver code
michal-miotk May 19, 2026
ed41e78
fix compilation
michal-miotk May 20, 2026
f20aaf2
fix compilation
michal-miotk May 20, 2026
7e87eb8
fix
michal-miotk May 20, 2026
1cd0009
delete fix for winpath too long
michal-miotk May 20, 2026
0046453
apply linux part of review
michal-miotk May 21, 2026
bfcfa60
add windows prt of review
michal-miotk May 21, 2026
db6d80c
added missing changes, renamed vulkan test file
michal-miotk May 21, 2026
39aa251
update version of minimal working driver on vulkan test, added smoke …
michal-miotk May 21, 2026
7447945
symlinks
michal-miotk May 21, 2026
41c91f9
Merge branch 'master' into remoteNT
michal-miotk May 21, 2026
d37555d
minor cleaning
michal-miotk May 22, 2026
0e8fff7
delete misleading dx context
michal-miotk May 22, 2026
9685a7d
applied review comments, renamed OCL_BUFFER_FROM_HANDLE to BUFFER_FRO…
michal-miotk May 28, 2026
568e042
fix format
michal-miotk May 28, 2026
825024d
fix format
michal-miotk May 28, 2026
e1df435
delete vulkan test
michal-miotk Jun 1, 2026
99b0578
apply review comments
michal-miotk Jun 3, 2026
4f5cc5f
fix bad macro and code style
michal-miotk Jun 3, 2026
4fe5523
fix format
michal-miotk Jun 3, 2026
e541e85
fix copyright
michal-miotk Jun 3, 2026
23edd7c
fix linux
michal-miotk Jun 3, 2026
6e37a77
apply review comments
michal-miotk Jun 3, 2026
7a1c41c
changed name
michal-miotk Jun 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright (C) 2018-2026 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include <openvino/runtime/core.hpp>
#include <openvino/runtime/intel_gpu/properties.hpp>
#include <openvino/runtime/intel_gpu/ocl/ocl.hpp>
Expand All @@ -14,6 +18,7 @@ cl_context get_cl_context();
cl_command_queue get_cl_queue();
cl::Buffer allocate_buffer(size_t size);
cl::Image2D allocate_image(size_t size);
ov::intel_gpu::ocl::os_handle_param get_shared_handle();


#ifdef WIN32
Expand Down Expand Up @@ -62,6 +67,16 @@ int main() {
//! [wrap_cl_image]
}

{
//! [wrap_shared_handle]
auto shared_handle = get_shared_handle();
auto remote_tensor = gpu_context.create_tensor(in_element_type,
in_shape,
shared_handle,
ov::intel_gpu::MemType::SHARED_BUF);
//! [wrap_shared_handle]
}

{
//! [allocate_usm_device]
auto remote_tensor = gpu_context.create_usm_device_tensor(in_element_type, in_shape);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,19 @@ For more details, see the code snippets below:
:language: cpp
:fragment: [wrap_cl_image]

.. tab-item:: external shared handle
:sync: external-shared-handle

Use this overload when your application already owns an OS-level shared memory handle
(for example, DX12 NT handle on Windows or DMA-BUF file descriptor on Linux).

.. doxygensnippet:: docs/articles_en/assets/snippets/gpu/remote_objects_creation.cpp
:language: cpp
:fragment: [wrap_shared_handle]

The ``shape`` and ``element type`` must describe the same memory layout as the external buffer.
The handle must remain valid for the whole lifetime of the created remote tensor.

.. tab-item:: biplanar NV12 surface
:sync: biplanar-nv12-surface

Expand Down
36 changes: 36 additions & 0 deletions src/inference/include/openvino/runtime/intel_gpu/ocl/ocl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,19 @@ namespace ocl {
* @brief Shortcut for defining a handle parameter
* @ingroup ov_runtime_ocl_gpu_cpp_api
*/

using gpu_handle_param = void*;

/**
* @brief Shortcut for defining a HANDLE on windows or file descriptor on linux
* @ingroup ov_runtime_ocl_gpu_cpp_api
*/
#ifdef __linux__
using os_handle_param = int;
#else
using os_handle_param = void*;
#endif

/**
* @brief This class represents an abstraction for GPU plugin remote tensor
* which can be shared with user-supplied OpenCL buffer.
Expand All @@ -58,6 +69,7 @@ class ClBufferTensor : public RemoteTensor {
{{std::string(ov::intel_gpu::mem_handle.name()), {}},
{std::string(ov::intel_gpu::shared_mem_type.name()),
{ov::Any(ov::intel_gpu::SharedMemType::OCL_BUFFER).as<std::string>(),
ov::Any(ov::intel_gpu::SharedMemType::BUFFER_FROM_HANDLE).as<std::string>(),
ov::Any(ov::intel_gpu::SharedMemType::DX_BUFFER).as<std::string>()}}});
}

Expand Down Expand Up @@ -307,6 +319,30 @@ class ClContext : public RemoteContext {
return create_tensor(type, shape, params).as<ClImage2DTensor>();
}

/**
* @brief This function is used to obtain a remote tensor object from a user-supplied external memory handle
* The API mirrors the NPU pointer-based create_tensor form.
* @param type Tensor element type
* @param shape Tensor shape
* @param shared_buffer External memory handle from another API (DX12 shared NT handle on Windows passed as void*,
* DMA-BUF fd on Linux passed as int)
* @param memory_type Memory type to use; only MemType::SHARED_BUF is currently supported
* @return A remote tensor instance
*/
ClBufferTensor create_tensor(const element::Type type,
const Shape& shape,
os_handle_param shared_buffer,
const MemType memory_type) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should support importing usm as well. It is identical with usm-version for first three arguments.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that at least at windows creating handles supports only allocation on gpu

#ifndef __linux__
OPENVINO_ASSERT(shared_buffer != nullptr, "shared_buffer must not be nullptr for SHARED_BUF memory type");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
OPENVINO_ASSERT(shared_buffer != nullptr, "shared_buffer must not be nullptr for SHARED_BUF memory type");
OPENVINO_ASSERT(shared_buffer != nullptr, "shared_buffer must not be nullptr for SHARED_BUF memory type");
OPENVINO_ASSERT(memory_type == MemType::SHARED_BUF, "Only SHARED_BUF memory type is supported for raw buffer pointer or NT handle")

At first glance this check is useless as MemType contains only one record, but MemType may be extended independently, and in that case this check becomes meaningful.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you update documentation as well? docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/gpu-device/remote-tensor-api-gpu-plugin.rst

#endif
OPENVINO_ASSERT(memory_type == MemType::SHARED_BUF,
"Only SHARED_BUF memory type is supported for raw buffer pointer or NT handle");
AnyMap params = {{ov::intel_gpu::shared_mem_type.name(), ov::intel_gpu::SharedMemType::BUFFER_FROM_HANDLE},
{ov::intel_gpu::mem_handle.name(), reinterpret_cast<void*>(shared_buffer)}};
return create_tensor(type, shape, params).as<ClBufferTensor>();
}

/**
* @brief This function is used to obtain remote tensor object from user-supplied USM pointer
* @param type Tensor element type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,23 @@ static constexpr Property<gpu_handle_param> va_device{"VA_DEVICE"};
* @ingroup ov_runtime_ocl_gpu_cpp_api
*/
enum class SharedMemType {
OCL_BUFFER = 0, //!< Shared OpenCL buffer blob
OCL_IMAGE2D = 1, //!< Shared OpenCL 2D image blob
USM_USER_BUFFER = 2, //!< Shared USM pointer allocated by user
USM_HOST_BUFFER = 3, //!< Shared USM pointer type with host allocation type allocated by plugin
USM_DEVICE_BUFFER = 4, //!< Shared USM pointer type with device allocation type allocated by plugin
VA_SURFACE = 5, //!< Shared video decoder surface or D3D 2D texture blob
DX_BUFFER = 6 //!< Shared D3D buffer blob
OCL_BUFFER = 0, //!< Shared OpenCL buffer blob
OCL_IMAGE2D = 1, //!< Shared OpenCL 2D image blob
USM_USER_BUFFER = 2, //!< Shared USM pointer allocated by user
USM_HOST_BUFFER = 3, //!< Shared USM pointer type with host allocation type allocated by plugin
USM_DEVICE_BUFFER = 4, //!< Shared USM pointer type with device allocation type allocated by plugin
VA_SURFACE = 5, //!< Shared video decoder surface or D3D 2D texture blob
DX_BUFFER = 6, //!< Shared D3D buffer blob
BUFFER_FROM_HANDLE = 7, //!< OS-level external memory handle (e.g. DX12 NT handle on Windows,
//!< DMA-BUF fd on Linux) imported by the plugin into a cl_mem
};

/**
* @brief Enum to define memory type for pointer-based tensor sharing API.
* @ingroup ov_runtime_ocl_gpu_cpp_api
*/
enum class MemType {
SHARED_BUF = 0, //!< Shared OpenCL buffer handle passed as void*
};

/** @cond INTERNAL */
Expand All @@ -129,6 +139,8 @@ inline std::ostream& operator<<(std::ostream& os, const SharedMemType& share_mem
return os << "VA_SURFACE";
case SharedMemType::DX_BUFFER:
return os << "DX_BUFFER";
case SharedMemType::BUFFER_FROM_HANDLE:
return os << "BUFFER_FROM_HANDLE";
default:
OPENVINO_THROW("Unsupported memory type");
}
Expand All @@ -151,6 +163,8 @@ inline std::istream& operator>>(std::istream& is, SharedMemType& share_mem_type)
share_mem_type = SharedMemType::VA_SURFACE;
} else if (str == "DX_BUFFER") {
share_mem_type = SharedMemType::DX_BUFFER;
} else if (str == "BUFFER_FROM_HANDLE") {
share_mem_type = SharedMemType::BUFFER_FROM_HANDLE;
} else {
OPENVINO_THROW("Unsupported memory type: ", str);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum class TensorType {
BT_EMPTY,
BT_BUF_INTERNAL,
BT_BUF_SHARED,
BT_BUF_SHARED_FROM_HANDLE,
BT_USM_SHARED,
BT_USM_HOST_INTERNAL,
BT_USM_DEVICE_INTERNAL,
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/intel_gpu/include/intel_gpu/runtime/engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ class engine {
/// Create shared memory object using user-supplied memory buffer @p buf using specified @p layout
memory_ptr share_buffer(const layout& layout, shared_handle buf);

//Create memory object from user-supplied shared handle e.g from system HANDLE created by DX12
virtual memory_ptr import_buffer(const layout& layout, shared_handle external_handle) = 0;

/// Create shared memory object using user-supplied USM pointer @p usm_ptr using specified @p layout
memory_ptr share_usm(const layout& layout, shared_handle usm_ptr);

Expand Down
3 changes: 3 additions & 0 deletions src/plugins/intel_gpu/src/plugin/remote_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ ov::SoPtr<ov::IRemoteTensor> RemoteContextImpl::create_tensor(const ov::element:
mem = extract_object(params, ov::intel_gpu::dev_object_handle);
check_if_shared();
#endif
} else if (ov::intel_gpu::SharedMemType::BUFFER_FROM_HANDLE == mem_type) {
tensor_type = TensorType::BT_BUF_SHARED_FROM_HANDLE;
mem = extract_object(params, ov::intel_gpu::mem_handle);
} else {
OPENVINO_THROW("[GPU] Unsupported shared object type ", mem_type);
}
Expand Down
12 changes: 12 additions & 0 deletions src/plugins/intel_gpu/src/plugin/remote_tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ void RemoteTensorImpl::allocate() {
m_memory_object = engine.share_buffer(m_layout, m_mem);
break;
}
case TensorType::BT_BUF_SHARED_FROM_HANDLE: {
m_memory_object = engine.import_buffer(m_layout, m_mem);
break;
}
case TensorType::BT_USM_SHARED: {
m_memory_object = engine.share_usm(m_layout, m_mem);
break;
Expand Down Expand Up @@ -380,6 +384,7 @@ const std::string& RemoteTensorImpl::get_device_name() const {

bool RemoteTensorImpl::is_shared() const noexcept {
return m_mem_type == TensorType::BT_BUF_SHARED ||
m_mem_type == TensorType::BT_BUF_SHARED_FROM_HANDLE ||
m_mem_type == TensorType::BT_USM_SHARED ||
m_mem_type == TensorType::BT_IMG_SHARED ||
m_mem_type == TensorType::BT_SURF_SHARED ||
Expand Down Expand Up @@ -451,6 +456,13 @@ void RemoteTensorImpl::update_properties() {
ov::intel_gpu::mem_handle(params.mem),
};
break;
case TensorType::BT_BUF_SHARED_FROM_HANDLE:
m_properties = {
ov::intel_gpu::shared_mem_type(ov::intel_gpu::SharedMemType::BUFFER_FROM_HANDLE),
ov::intel_gpu::ocl_context(params.context),
ov::intel_gpu::mem_handle(params.mem),
};
break;
case TensorType::BT_USM_SHARED:
m_properties = {
ov::intel_gpu::shared_mem_type(ov::intel_gpu::SharedMemType::USM_USER_BUFFER),
Expand Down
68 changes: 67 additions & 1 deletion src/plugins/intel_gpu/src/runtime/ocl/ocl_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <string>
#include <vector>
#include <memory>
#include <set>
#include <stdexcept>

// NOTE: Due to buggy scope transition of warnings we need to disable warning in place of use/instantation
Expand Down Expand Up @@ -46,6 +45,16 @@ ocl_error::ocl_error(cl::Error const& err)
: ov::Exception("[GPU] " + std::string(err.what()) + std::string(", error code: ") + std::to_string(err.err())) {}
OPENVINO_SUPPRESS_DEPRECATED_END

namespace {
cl_platform_id get_platform_id_for_device(const cl::Device& device) {
cl_platform_id platform = nullptr;
cl_int err = clGetDeviceInfo(device.get(), CL_DEVICE_PLATFORM, sizeof(platform), &platform, nullptr);
OPENVINO_ASSERT(err == CL_SUCCESS && platform != nullptr,
"[GPU] Failed to retrieve CL_DEVICE_PLATFORM, error: ", err);
return platform;
}
} // namespace

ocl_engine::ocl_engine(const device::ptr dev, runtime_types runtime_type)
: engine(dev) {
OPENVINO_ASSERT(runtime_type == runtime_types::ocl, "[GPU] Invalid runtime type specified for OCL engine. Only OCL runtime is supported");
Expand Down Expand Up @@ -96,6 +105,63 @@ allocation_type ocl_engine::detect_usm_allocation_type(const void* memory) const
: allocation_type::unknown;
}

memory::ptr ocl_engine::import_buffer(const layout& layout, shared_handle external_handle) {
OPENVINO_ASSERT(external_handle != nullptr, "[GPU] External memory handle must not be null");
OPENVINO_ASSERT(extension_supported("cl_khr_external_memory"),
"[GPU] Selected OpenCL device does not advertise cl_khr_external_memory; "
"external memory import is not supported");

#ifndef CL_VERSION_3_0
OPENVINO_THROW("[GPU] External memory import is not supported on this platform");
#else
#ifdef _WIN32
constexpr auto handle_type_token = CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR;
#elif defined(__linux__)
constexpr auto handle_type_token = CL_EXTERNAL_MEMORY_HANDLE_DMA_BUF_KHR;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this PR support dmabuf as well? if not, I think we need to add an assert, instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supports but tests from vulkan was deleted

#else
OPENVINO_THROW("[GPU] External memory import is not supported on this platform");
#endif

cl_mem_properties props[] = {
static_cast<cl_mem_properties>(handle_type_token),
static_cast<cl_mem_properties>(reinterpret_cast<intptr_t>(external_handle)),
0,
};

cl_int errcode = CL_SUCCESS;
auto cl_ctx = static_cast<cl_context>(get_user_context());
OPENVINO_ASSERT(cl_ctx != nullptr, "[GPU] OpenCL context is null while importing external buffer");
const auto byte_size = layout.bytes_count();
cl_mem imported = clCreateBufferWithProperties(cl_ctx, props, CL_MEM_READ_WRITE, byte_size, nullptr, &errcode);
Comment thread
Lyamin-Roman marked this conversation as resolved.
OPENVINO_ASSERT(errcode == CL_SUCCESS && imported != nullptr,
"[GPU] Failed to import external memory handle via clCreateBufferWithProperties, error: ",
errcode);

cl_platform_id platform = get_platform_id_for_device(get_cl_device());
auto& svc_stream = downcast<ocl_stream>(get_service_stream());
cl_command_queue q = svc_stream.get_cl_queue().get();
cl_int acquire_err = cl::ExternalMemoryHelper::acquire(platform, q, imported);
if (acquire_err != CL_SUCCESS) {
clReleaseMemObject(imported);
OPENVINO_THROW("[GPU] clEnqueueAcquireExternalMemObjectsKHR failed or unavailable, error: ", acquire_err);
}
clFinish(q);
cl::Buffer buf(imported, true);
auto memory = std::make_shared<ocl::gpu_buffer_from_handle>(this, layout, buf, nullptr);
clReleaseMemObject(imported);
return memory;
#endif
}

void ocl_engine::release_external_memory(cl_mem mem) const {
cl_platform_id platform = get_platform_id_for_device(get_cl_device());
auto& opencl_stream = downcast<ocl_stream>(get_service_stream());
cl_command_queue q = opencl_stream.get_cl_queue().get();
// If the extension entrypoint is missing, the cl_mem refcount drop on dtor will still proceed.
cl::ExternalMemoryHelper::release(platform, q, mem);
clFinish(q);
}

memory::ptr ocl_engine::allocate_memory(const layout& layout, allocation_type type, bool reset) {
OPENVINO_ASSERT(!layout.is_dynamic() || layout.has_upper_bound(), "[GPU] Can't allocate memory for dynamic layout");

Expand Down
5 changes: 3 additions & 2 deletions src/plugins/intel_gpu/src/runtime/ocl/ocl_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include "ocl_device.hpp"

#include <memory>
#include <set>
#include <vector>
#include <utility>
#include <string>

Expand All @@ -28,8 +26,11 @@ class ocl_engine : public engine {
memory_ptr reinterpret_handle(const layout& new_layout, shared_mem_params params) override;
memory_ptr create_subbuffer(const memory& memory, const layout& new_layout, size_t offset) override;
memory_ptr reinterpret_buffer(const memory& memory, const layout& new_layout) override;
memory_ptr import_buffer(const layout&, shared_handle external_handle) override;
bool is_the_same_buffer(const memory& mem1, const memory& mem2) override;

void release_external_memory(cl_mem) const;

void* get_user_context() const override;

allocation_type get_default_allocation_type() const override { return allocation_type::cl_mem; }
Expand Down
50 changes: 50 additions & 0 deletions src/plugins/intel_gpu/src/runtime/ocl/ocl_ext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,56 @@ class BufferDX : public Buffer {
};
#endif

class ExternalMemoryHelper {
typedef CL_API_ENTRY cl_int(CL_API_CALL * PFN_clEnqueueAcquireExternalMemObjectsKHR)(
cl_command_queue /* command_queue */,
cl_uint /* num_mem_objects */,
const cl_mem* /* mem_objects */,
cl_uint /* num_events_in_wait_list */,
const cl_event* /* event_wait_list */,
cl_event* /* event */);

typedef CL_API_ENTRY cl_int(CL_API_CALL * PFN_clEnqueueReleaseExternalMemObjectsKHR)(
cl_command_queue /* command_queue */,
cl_uint /* num_mem_objects */,
const cl_mem* /* mem_objects */,
cl_uint /* num_events_in_wait_list */,
const cl_event* /* event_wait_list */,
cl_event* /* event */);
public:

static cl_int acquire(cl_platform_id platform, cl_command_queue queue, const cl_mem& mem) {
auto pfn = get_acquire(platform);
if (pfn == nullptr)
return CL_INVALID_OPERATION;
return pfn(queue, 1, &mem, 0, nullptr, nullptr);
}

static cl_int release(cl_platform_id platform, cl_command_queue queue, const cl_mem& mem) {
auto pfn = get_release(platform);
if (pfn == nullptr)
return CL_INVALID_OPERATION;
return pfn(queue, 1, &mem, 0, nullptr, nullptr);
}
private:
static PFN_clEnqueueAcquireExternalMemObjectsKHR get_acquire(cl_platform_id platform) {
static PFN_clEnqueueAcquireExternalMemObjectsKHR fn = nullptr;
if (!fn) {
fn = try_load_entrypoint<PFN_clEnqueueAcquireExternalMemObjectsKHR>(platform, "clEnqueueAcquireExternalMemObjectsKHR");
}
return fn;
}

static PFN_clEnqueueReleaseExternalMemObjectsKHR get_release(cl_platform_id platform) {
static PFN_clEnqueueReleaseExternalMemObjectsKHR fn = nullptr;
if (!fn) {
fn = try_load_entrypoint<PFN_clEnqueueReleaseExternalMemObjectsKHR>(platform, "clEnqueueReleaseExternalMemObjectsKHR");
}
return fn;
}

};

class PlatformVA : public Platform {
public:
//! \brief Default constructor - initializes to NULL.
Expand Down
Loading
Loading