OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[GPU] Support CPU pointers on remote tensor (#36539)
Michal Miotkd64394f40b76
diff --git a/docs/articles_en/assets/snippets/gpu/remote_objects_creation.cpp b/docs/articles_en/assets/snippets/gpu/remote_objects_creation.cppindex b2a7cb4170e..b62af47e349 100644--- a/docs/articles_en/assets/snippets/gpu/remote_objects_creation.cpp+++ b/docs/articles_en/assets/snippets/gpu/remote_objects_creation.cpp@@ -5,6 +5,7 @@#include <openvino/runtime/core.hpp>#include <openvino/runtime/intel_gpu/properties.hpp>#include <openvino/runtime/intel_gpu/ocl/ocl.hpp>+#include <openvino/util/memory.hpp>#ifdef WIN32#include <openvino/runtime/intel_gpu/ocl/dx.hpp>@@ -18,7 +19,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();+ov::intel_gpu::SharedBufferHandle get_shared_handle();#ifdef WIN32@@ -46,6 +47,28 @@ int main() {//! [wrap_usm_pointer]}+{+ //! [wrap_cpu_pointer]+ // Allocation part - must be done with alignment(for OCL backend) - align the address to cache line size+ // and the allocation size must be a multiple of cache line size.+ // In case of size of tensor lower than cache line size, allocate at least one cache line size+ // and use ov::intel_gpu::VirtualAddressMemory(cpu_pointer, allocated_size)+ size_t size = input_size * in_element_type.size();+ const std::string target_device = "GPU";+ const uint32_t cacheline_size = core.get_property(target_device, ov::intel_gpu::cacheline_size);+ size = ov::util::align_size_up(size, cacheline_size); // ensure OCL runtime compatibility+ void* cpu_pointer = ov::util::aligned_alloc(size, cacheline_size);+ // end of Allocation part+ {+ // real wrapping cpu pointer to remote tensor+ auto remote_tensor = gpu_context.create_tensor(in_element_type,+ in_shape,+ ov::intel_gpu::VirtualAddressMemory(cpu_pointer, size));+ }+ ov::util::aligned_free(cpu_pointer);+ //! [wrap_cpu_pointer]+}+{//! [wrap_cl_mem]cl_mem shared_buffer = allocate_cl_mem(input_size);@@ -72,8 +95,7 @@ int main() {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);+ shared_handle);//! [wrap_shared_handle]}diff --git a/src/inference/include/openvino/runtime/intel_gpu/ocl/ocl.hpp b/src/inference/include/openvino/runtime/intel_gpu/ocl/ocl.hppindex a7e743d76f8..82dbc0f5c97 100644--- a/src/inference/include/openvino/runtime/intel_gpu/ocl/ocl.hpp+++ b/src/inference/include/openvino/runtime/intel_gpu/ocl/ocl.hpp@@ -41,15 +41,8 @@ namespace ocl {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+using SharedBufferHandle = ov::intel_gpu::SharedBufferHandle;+using VirtualAddressMemory = ov::intel_gpu::VirtualAddressMemory;/*** @brief This class represents an abstraction for GPU plugin remote tensor@@ -69,6 +62,7 @@ public:{{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::CPU_VA).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>()}}});}@@ -321,25 +315,34 @@ public:/*** @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+ * @param SharedBufferHandle External memory handle from another API (DX12 shared NT handle on Windows passed as+ * void*, DMA-BUF fd on Linux passed as int)* @return A remote tensor instance*/- ClBufferTensor create_tensor(const element::Type type,- const Shape& shape,- os_handle_param shared_buffer,- const MemType memory_type) {+ ClBufferTensor create_tensor(const element::Type type, const Shape& shape, SharedBufferHandle handle) {#ifndef __linux__- OPENVINO_ASSERT(shared_buffer != nullptr, "shared_buffer must not be nullptr for SHARED_BUF memory type");+ OPENVINO_ASSERT(handle.value != nullptr, "shared_buffer must not be nullptr for SHARED_BUF memory type");#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::os_handle.name(), shared_buffer}};+ {ov::intel_gpu::os_handle.name(), handle.value}};+ return create_tensor(type, shape, params).as<ClBufferTensor>();+ }++ /**+ * @brief This function is used to obtain a remote tensor object from a user-supplied VirtualAddressMemory+ * @param type Tensor element type+ * @param shape Tensor shape+ * @param buff A VirtualAddressMemory object that contains cpu pointer and size(optional)+ * @return A remote tensor instance+ */+ ClBufferTensor create_tensor(const element::Type type, const Shape& shape, VirtualAddressMemory buff) {+ OPENVINO_ASSERT(buff.ptr != nullptr, "host buffer must not be nullptr for CPU_VA memory type");++ AnyMap params = {{ov::intel_gpu::shared_mem_type.name(), ov::intel_gpu::SharedMemType::CPU_VA},+ {ov::intel_gpu::cpu_va.name(), static_cast<gpu_handle_param>(buff.ptr)},+ {ov::intel_gpu::cpu_va_size.name(), buff.size}}; // if -1 then use shape to get the sizereturn create_tensor(type, shape, params).as<ClBufferTensor>();}diff --git a/src/inference/include/openvino/runtime/intel_gpu/properties.hpp b/src/inference/include/openvino/runtime/intel_gpu/properties.hppindex e947ca59926..656a6b7d649 100644--- a/src/inference/include/openvino/runtime/intel_gpu/properties.hpp+++ b/src/inference/include/openvino/runtime/intel_gpu/properties.hpp@@ -50,6 +50,12 @@ static constexpr Property<std::string, PropertyMutability::RO> uarch_version{"GP*/static constexpr Property<int32_t, PropertyMutability::RO> execution_units_count{"GPU_EXECUTION_UNITS_COUNT"};+/**+ * @brief Read-only property to get cache line size for current GPU+ * @ingroup ov_runtime_ocl_gpu_prop_cpp_api+ */+static constexpr Property<uint32_t, PropertyMutability::RO> cacheline_size{"GPU_CACHELINE_SIZE"};+/*** @brief Read-only property to get statistics of GPU memory allocated by engine for each allocation type* It contains information about current memory usagediff --git a/src/inference/include/openvino/runtime/intel_gpu/remote_properties.hpp b/src/inference/include/openvino/runtime/intel_gpu/remote_properties.hppindex 1c35990cfef..c6cd21d1140 100644--- a/src/inference/include/openvino/runtime/intel_gpu/remote_properties.hpp+++ b/src/inference/include/openvino/runtime/intel_gpu/remote_properties.hpp@@ -118,6 +118,7 @@ enum class SharedMemType {DX_BUFFER = 6, //!< Shared D3D buffer blobBUFFER_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+ CPU_VA = 8, //!< Shared mmap-backed/aligned allocated host pointer mapped by plugin};/**@@ -126,6 +127,7 @@ enum class SharedMemType {*/enum class MemType {SHARED_BUF = 0, //!< Shared OpenCL buffer handle passed as void* or int+ CPU_VA = 1, //!< CPU Virtual Address buffer};/** @cond INTERNAL */@@ -141,6 +143,8 @@ inline std::ostream& operator<<(std::ostream& os, const SharedMemType& share_memreturn os << "USM_HOST_BUFFER";case SharedMemType::USM_DEVICE_BUFFER:return os << "USM_DEVICE_BUFFER";+ case SharedMemType::CPU_VA:+ return os << "CPU_VA";case SharedMemType::VA_SURFACE:return os << "VA_SURFACE";case SharedMemType::DX_BUFFER:@@ -165,6 +169,8 @@ inline std::istream& operator>>(std::istream& is, SharedMemType& share_mem_type)share_mem_type = SharedMemType::USM_HOST_BUFFER;} else if (str == "USM_DEVICE_BUFFER") {share_mem_type = SharedMemType::USM_DEVICE_BUFFER;+ } else if (str == "CPU_VA") {+ share_mem_type = SharedMemType::CPU_VA;} else if (str == "VA_SURFACE") {share_mem_type = SharedMemType::VA_SURFACE;} else if (str == "DX_BUFFER") {@@ -198,6 +204,18 @@ static constexpr Property<gpu_handle_param> mem_handle{"MEM_HANDLE"};*/static constexpr Property<os_handle_param> os_handle{"OS_HANDLE"};+/**+ * @brief This key identifies cpu pointer+ * @ingroup ov_runtime_ocl_gpu_cpp_api+ */+static constexpr Property<void*> cpu_va{"CPU_VA"};++/**+ * @brief This key identifies size of allocated memory of cpu pointer+ * @ingroup ov_runtime_ocl_gpu_cpp_api+ */+static constexpr Property<int64_t> cpu_va_size{"CPU_VA_SIZE"};+/*** @brief This key identifies video decoder surface handle* in a shared memory blob parameter map@@ -216,5 +234,31 @@ static constexpr Property<uint32_t> dev_object_handle{"DEV_OBJECT_HANDLE"};*/static constexpr Property<uint32_t> va_plane{"VA_PLANE"};+/**+ * @brief Platform OS memory handle for importing externally allocated memory into GPU plugin tensors.+ * On Linux this is a DMA-BUF file descriptor (int).+ * On Windows this is a DX12 shared NT HANDLE (void*).+ * @ingroup ov_runtime_ocl_gpu_cpp_api+ */+struct SharedBufferHandle {+#ifdef __linux__+ using value_type = int; ///< DMA-BUF file descriptor+#else+ using value_type = void*; ///< DX12 shared NT HANDLE+#endif+ value_type value{};+};++/**+ * @brief Host (CPU) memory descriptor for wrapping mmap-backed or aligned host buffers+ * as GPU plugin tensors without copying.+ * @ingroup ov_runtime_ocl_gpu_cpp_api+ */+struct VirtualAddressMemory {+ explicit VirtualAddressMemory(void* ptr_, int64_t size_ = -1) : ptr(ptr_), size(size_) {}++ void* ptr = nullptr;+ int64_t size = -1; ///< Buffer size in bytes; -1 means "derive from tensor shape"+};} // namespace intel_gpu} // namespace ovdiff --git a/src/plugins/intel_gpu/include/intel_gpu/plugin/common_utils.hpp b/src/plugins/intel_gpu/include/intel_gpu/plugin/common_utils.hppindex c6eed969959..515a526c5bf 100644--- a/src/plugins/intel_gpu/include/intel_gpu/plugin/common_utils.hpp+++ b/src/plugins/intel_gpu/include/intel_gpu/plugin/common_utils.hpp@@ -24,6 +24,7 @@ enum class TensorType {BT_BUF_INTERNAL,BT_BUF_SHARED,BT_BUF_SHARED_FROM_HANDLE,+ BT_CPU_VA,BT_USM_SHARED,BT_USM_HOST_INTERNAL,BT_USM_DEVICE_INTERNAL,diff --git a/src/plugins/intel_gpu/include/intel_gpu/plugin/remote_context.hpp b/src/plugins/intel_gpu/include/intel_gpu/plugin/remote_context.hppindex f0b7cd2e40e..52062ee4619 100644--- a/src/plugins/intel_gpu/include/intel_gpu/plugin/remote_context.hpp+++ b/src/plugins/intel_gpu/include/intel_gpu/plugin/remote_context.hpp@@ -83,7 +83,8 @@ private:std::string get_device_name(const std::map<std::string, RemoteContextImpl::Ptr>& known_contexts, const cldnn::device::ptr current_device) const;std::shared_ptr<ov::IRemoteTensor> reuse_surface(const ov::element::Type type, const ov::Shape& shape, const ov::AnyMap& params);std::shared_ptr<ov::IRemoteTensor> reuse_memory(const ov::element::Type type, const ov::Shape& shape, cldnn::shared_handle mem, TensorType tensor_type);- std::shared_ptr<ov::IRemoteTensor> reuse_memory_from_handle(const ov::element::Type type, const ov::Shape& shape, ov::intel_gpu::os_handle_param handle, TensorType tensor_type);+ std::shared_ptr<ov::IRemoteTensor> reuse_memory_from_cpu_va(const ov::element::Type type, const ov::Shape& shape, VirtualAddressMemory cpu_va, TensorType tensor_type);+ std::shared_ptr<ov::IRemoteTensor> reuse_memory_from_handle(const ov::element::Type type, const ov::Shape& shape, SharedBufferHandle handle, TensorType tensor_type);std::shared_ptr<ov::IRemoteTensor> create_buffer(const ov::element::Type type, const ov::Shape& shape);std::shared_ptr<ov::IRemoteTensor> create_usm(const ov::element::Type type, const ov::Shape& shape, TensorType alloc_type);void check_if_shared() const;diff --git a/src/plugins/intel_gpu/include/intel_gpu/plugin/remote_tensor.hpp b/src/plugins/intel_gpu/include/intel_gpu/plugin/remote_tensor.hppindex 1c5f64a4d91..cdbb460354c 100644--- a/src/plugins/intel_gpu/include/intel_gpu/plugin/remote_tensor.hpp+++ b/src/plugins/intel_gpu/include/intel_gpu/plugin/remote_tensor.hpp@@ -18,6 +18,7 @@#endif#endif#include "openvino/runtime/iremote_tensor.hpp"+#include "openvino/runtime/intel_gpu/remote_properties.hpp"#include "intel_gpu/runtime/memory_caps.hpp"#include "intel_gpu/runtime/memory.hpp"@@ -41,12 +42,8 @@ public:cldnn::shared_handle mem = nullptr,cldnn::shared_surface surf = 0,uint32_t plane = 0,-#ifdef __linux__- ov::intel_gpu::os_handle_param os_handle = -1-#else- ov::intel_gpu::os_handle_param os_handle = nullptr-#endif-);+ ov::intel_gpu::SharedBufferHandle shared_buffer_handle = {},+ ov::intel_gpu::VirtualAddressMemory va_mem = ov::intel_gpu::VirtualAddressMemory(nullptr));~RemoteTensorImpl() override;const AnyMap& get_properties() const override;@@ -87,9 +84,10 @@ private:TensorType m_mem_type;cldnn::shared_handle m_mem;- ov::intel_gpu::os_handle_param m_os_handle;cldnn::shared_surface m_surf;uint32_t m_plane;+ ov::intel_gpu::SharedBufferHandle m_shared_buffer_handle;+ ov::intel_gpu::VirtualAddressMemory m_va_mem;size_t m_hash = 0;bool supports_caching() const;diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/device_info.hpp b/src/plugins/intel_gpu/include/intel_gpu/runtime/device_info.hppindex 1a0b6014c65..150e4575c6e 100644--- a/src/plugins/intel_gpu/include/intel_gpu/runtime/device_info.hpp+++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/device_info.hpp@@ -144,6 +144,7 @@ struct device_info {uint32_t num_threads_per_eu; ///< Number of hardware threads per execution unituint32_t num_ccs; ///< Number of compute command streamersuint32_t sub_device_idx; ///< Index of sub-device+ int32_t cacheline_size;pci_bus_info pci_info; ///< PCI bus information for the devicediff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/engine.hpp b/src/plugins/intel_gpu/include/intel_gpu/runtime/engine.hppindex ebd5c51ebbd..bb5d83c4f86 100644--- a/src/plugins/intel_gpu/include/intel_gpu/runtime/engine.hpp+++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/engine.hpp@@ -64,8 +64,13 @@ public:/// Created subbuffer memory object from the other @p memory and reinterpred the data using specified @p new_layoutvirtual memory_ptr create_subbuffer(const memory& memory, const layout& new_layout, size_t byte_offset) = 0;- /// Created memory object by wrapping a host-allocated, memory-mapped layout region- virtual memory_ptr create_mmap_hostbuffer(const void* mmapped_address, size_t data_size, allocation_type _allocation_type, const layout output_layout) = 0;+ /// Created memory object by wrapping a writable host-allocated layout region.+ /// Backends that support access flags should use read-write permissions.+ virtual memory_ptr create_hostbuffer(void* cpu_address, size_t data_size, allocation_type _allocation_type, const layout output_layout) = 0;++ /// Created memory object by wrapping a read-only host-allocated layout region.+ /// Backends that support access flags should use read-only permissions.+ virtual memory_ptr create_hostbuffer(const void* cpu_address, size_t data_size, allocation_type _allocation_type, const layout output_layout) = 0;/// Created memory object from the other @p memory and reinterpred the data using specified @p new_layoutvirtual memory_ptr reinterpret_buffer(const memory& memory, const layout& new_layout) = 0;@@ -73,7 +78,7 @@ public:/// Create shared memory object using user-supplied memory buffer @p buf using specified @p layoutmemory_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+ // Create memory object from user-supplied shared handle e.g from system HANDLE created by DX12virtual memory_ptr import_buffer(const layout& layout, ov::intel_gpu::os_handle_param external_handle) = 0;/// Create shared memory object using user-supplied USM pointer @p usm_ptr using specified @p layoutdiff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/kernel.hpp b/src/plugins/intel_gpu/include/intel_gpu/runtime/kernel.hppindex f12f22173da..d68045d00cf 100644--- a/src/plugins/intel_gpu/include/intel_gpu/runtime/kernel.hpp+++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/kernel.hpp@@ -7,6 +7,7 @@#include <memory>#include <vector>#include <string>+#include <cstdint>namespace cldnn {diff --git a/src/plugins/intel_gpu/src/graph/program.cpp b/src/plugins/intel_gpu/src/graph/program.cppindex d466946d0cf..7706fe093b3 100644--- a/src/plugins/intel_gpu/src/graph/program.cpp+++ b/src/plugins/intel_gpu/src/graph/program.cpp@@ -2022,10 +2022,10 @@ void program::load(cldnn::BinaryInputBuffer& ib,memory_ptr model_tensor_base_ptr = nullptr;if (can_use_mmap_zero_copy) {model_tensor_base_ptr =- ib.get_engine().create_mmap_hostbuffer(ib.get_mmap_tensor(),- ib.get_stream_size(),- allocation_type::usm_host,- layout({{static_cast<tensor::value_type>(ib.get_stream_size()), 1, 1, 1}, data_types::u8, format::bfyx}));+ ib.get_engine().create_hostbuffer(ib.get_mmap_tensor(),+ ib.get_stream_size(),+ allocation_type::cl_mem,+ layout({{static_cast<tensor::value_type>(ib.get_stream_size()), 1, 1, 1}, data_types::u8, format::bfyx}));}size_t num_nodes;diff --git a/src/plugins/intel_gpu/src/plugin/plugin.cpp b/src/plugins/intel_gpu/src/plugin/plugin.cppindex 3320f62fb7d..2941627f49e 100644--- a/src/plugins/intel_gpu/src/plugin/plugin.cpp+++ b/src/plugins/intel_gpu/src/plugin/plugin.cpp@@ -624,6 +624,8 @@ ov::Any Plugin::get_metric(const std::string& name, const ov::AnyMap& options) cgops[element::f16] = device->get_gops(cldnn::data_types::f16);gops[element::f32] = device->get_gops(cldnn::data_types::f32);return decltype(ov::device::gops)::value_type {gops};+ } else if (name == ov::intel_gpu::cacheline_size) {+ return static_cast<decltype(ov::intel_gpu::cacheline_size)::value_type>(device_info.cacheline_size);} else if (name == ov::intel_gpu::execution_units_count) {return static_cast<decltype(ov::intel_gpu::execution_units_count)::value_type>(device_info.execution_units_count);} else if (name == ov::intel_gpu::uarch_version) {@@ -751,6 +753,7 @@ std::vector<ov::PropertyName> Plugin::get_supported_properties() const {ov::PropertyName{ov::intel_gpu::device_total_mem_size.name(), PropertyMutability::RO},ov::PropertyName{ov::intel_gpu::device_max_alloc_mem_size.name(), PropertyMutability::RO},ov::PropertyName{ov::intel_gpu::uarch_version.name(), PropertyMutability::RO},+ ov::PropertyName{ov::intel_gpu::cacheline_size.name(), PropertyMutability::RO},ov::PropertyName{ov::intel_gpu::execution_units_count.name(), PropertyMutability::RO},ov::PropertyName{ov::intel_gpu::memory_statistics.name(), PropertyMutability::RO},ov::PropertyName{ov::compatibility_check.name(), PropertyMutability::RO},diff --git a/src/plugins/intel_gpu/src/plugin/remote_context.cpp b/src/plugins/intel_gpu/src/plugin/remote_context.cppindex 86a121335b5..54b61e449b2 100644--- a/src/plugins/intel_gpu/src/plugin/remote_context.cpp+++ b/src/plugins/intel_gpu/src/plugin/remote_context.cpp@@ -182,6 +182,11 @@ ov::SoPtr<ov::IRemoteTensor> RemoteContextImpl::create_tensor(const ov::element:} else if (ov::intel_gpu::SharedMemType::USM_USER_BUFFER == mem_type) {tensor_type = TensorType::BT_USM_SHARED;mem = extract_object(params, ov::intel_gpu::mem_handle);+ } else if (ov::intel_gpu::SharedMemType::CPU_VA == mem_type) {+ tensor_type = TensorType::BT_CPU_VA;+ mem = extract_object(params, ov::intel_gpu::cpu_va);+ auto size = extract_object(params, ov::intel_gpu::cpu_va_size);+ return { reuse_memory_from_cpu_va(type, shape, VirtualAddressMemory{mem, size}, tensor_type), nullptr };} else if (ov::intel_gpu::SharedMemType::OCL_IMAGE2D == mem_type) {tensor_type = TensorType::BT_IMG_SHARED;mem = extract_object(params, ov::intel_gpu::mem_handle);@@ -193,7 +198,8 @@ ov::SoPtr<ov::IRemoteTensor> RemoteContextImpl::create_tensor(const ov::element:#endif} else if (ov::intel_gpu::SharedMemType::BUFFER_FROM_HANDLE == mem_type) {tensor_type = TensorType::BT_BUF_SHARED_FROM_HANDLE;- ov::intel_gpu::os_handle_param handle = extract_object(params, ov::intel_gpu::os_handle);+ const auto os_handle = extract_object(params, ov::intel_gpu::os_handle);+ SharedBufferHandle handle{os_handle};return { reuse_memory_from_handle(type, shape, handle, tensor_type), nullptr };} else {OPENVINO_THROW("[GPU] Unsupported shared object type ", mem_type);@@ -253,9 +259,16 @@ std::shared_ptr<ov::IRemoteTensor> RemoteContextImpl::reuse_memory(const ov::elereturn std::make_shared<RemoteTensorImpl>(get_this_shared_ptr(), shape, type, tensor_type, mem);}+std::shared_ptr<ov::IRemoteTensor> RemoteContextImpl::reuse_memory_from_cpu_va(const ov::element::Type type,+ const ov::Shape& shape,+ VirtualAddressMemory cpu_va,+ TensorType tensor_type) {+ return std::make_shared<RemoteTensorImpl>(get_this_shared_ptr(), shape, type, tensor_type, nullptr, 0, 0, ov::intel_gpu::SharedBufferHandle{}, cpu_va);+}+std::shared_ptr<ov::IRemoteTensor> RemoteContextImpl::reuse_memory_from_handle(const ov::element::Type type,const ov::Shape& shape,- ov::intel_gpu::os_handle_param handle,+ ov::intel_gpu::SharedBufferHandle handle,TensorType tensor_type) {return std::make_shared<RemoteTensorImpl>(get_this_shared_ptr(), shape, type, tensor_type, nullptr, 0, 0, handle);}diff --git a/src/plugins/intel_gpu/src/plugin/remote_tensor.cpp b/src/plugins/intel_gpu/src/plugin/remote_tensor.cppindex 795b9d6fc84..8751f2e6213 100644--- a/src/plugins/intel_gpu/src/plugin/remote_tensor.cpp+++ b/src/plugins/intel_gpu/src/plugin/remote_tensor.cpp@@ -8,9 +8,28 @@#include "intel_gpu/plugin/plugin.hpp"#include "intel_gpu/runtime/itt.hpp"#include "intel_gpu/runtime/memory_caps.hpp"+#include "openvino/runtime/intel_gpu/remote_properties.hpp"+#include <cstdint>#include <memory>+template <>+struct std::hash<ov::intel_gpu::SharedBufferHandle> {+ size_t operator()(const ov::intel_gpu::SharedBufferHandle& handle) const noexcept {+ return std::hash<ov::intel_gpu::SharedBufferHandle::value_type>{}(handle.value);+ }+};++template <>+struct std::hash<ov::intel_gpu::VirtualAddressMemory> {+ size_t operator()(const ov::intel_gpu::VirtualAddressMemory& mem) const noexcept {+ // Hash both pointer and size to distinguish different allocations+ size_t h1 = std::hash<const void*>{}(mem.ptr);+ size_t h2 = std::hash<int64_t>{}(mem.size);+ return h1 ^ (h2 << 1);+ }+};+namespace ov::intel_gpu {namespace {@@ -150,16 +169,18 @@ RemoteTensorImpl::RemoteTensorImpl(RemoteContextImpl::Ptr context,cldnn::shared_handle mem,cldnn::shared_surface surf,uint32_t plane,- ov::intel_gpu::os_handle_param os_handle)+ ov::intel_gpu::SharedBufferHandle shared_buffer_handle,+ ov::intel_gpu::VirtualAddressMemory va_mem): m_context(context), m_element_type(element_type), m_shape(shape), m_layout(cldnn::layout{ov::PartialShape{shape}, element_type, cldnn::format::get_default_format(shape.size())}), m_mem_type(mem_type), m_mem(mem)- , m_os_handle(os_handle), m_surf(surf)- , m_plane(plane) {+ , m_plane(plane)+ , m_shared_buffer_handle(shared_buffer_handle)+ , m_va_mem(va_mem) {update_hash();allocate();}@@ -344,13 +365,20 @@ void RemoteTensorImpl::allocate() {break;}case TensorType::BT_BUF_SHARED_FROM_HANDLE: {- m_memory_object = engine.import_buffer(m_layout, m_os_handle);+ m_memory_object = engine.import_buffer(m_layout, m_shared_buffer_handle.value);break;}case TensorType::BT_USM_SHARED: {m_memory_object = engine.share_usm(m_layout, m_mem);break;}+ case TensorType::BT_CPU_VA: {+ m_memory_object = engine.create_hostbuffer(m_va_mem.ptr,+ m_va_mem.size > -1 ? m_va_mem.size : m_layout.bytes_count(),+ cldnn::allocation_type::cl_mem,+ m_layout);+ break;+ }#ifdef _WIN32case TensorType::BT_SURF_SHARED: {m_memory_object = engine.share_surface(m_layout, m_mem, m_plane);@@ -388,6 +416,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_CPU_VA ||m_mem_type == TensorType::BT_USM_SHARED ||m_mem_type == TensorType::BT_IMG_SHARED ||m_mem_type == TensorType::BT_SURF_SHARED ||@@ -401,7 +430,8 @@ bool RemoteTensorImpl::supports_caching() const {void RemoteTensorImpl::update_hash() {if (supports_caching()) {m_hash = cldnn::hash_combine(0, m_mem);- m_hash = cldnn::hash_combine(m_hash, m_os_handle);+ m_hash = cldnn::hash_combine(m_hash, m_shared_buffer_handle);+ m_hash = cldnn::hash_combine(m_hash, m_va_mem);m_hash = cldnn::hash_combine(m_hash, m_surf);m_hash = cldnn::hash_combine(m_hash, m_plane);m_hash = cldnn::hash_combine(m_hash, m_shape.size());@@ -486,6 +516,14 @@ void RemoteTensorImpl::update_properties() {ov::intel_gpu::mem_handle(params.mem),};break;+ case TensorType::BT_CPU_VA:+ m_properties = {+ ov::intel_gpu::shared_mem_type(ov::intel_gpu::SharedMemType::CPU_VA),+ ov::intel_gpu::ocl_context(params.context),+ ov::intel_gpu::mem_handle(params.mem),+ ov::intel_gpu::cpu_va(m_va_mem.ptr),+ };+ break;case TensorType::BT_USM_HOST_INTERNAL:m_properties = {ov::intel_gpu::shared_mem_type(ov::intel_gpu::SharedMemType::USM_HOST_BUFFER),diff --git a/src/plugins/intel_gpu/src/runtime/ocl/ocl_device.cpp b/src/plugins/intel_gpu/src/runtime/ocl/ocl_device.cppindex f95df0fbf50..15d8f056fe7 100644--- a/src/plugins/intel_gpu/src/runtime/ocl/ocl_device.cpp+++ b/src/plugins/intel_gpu/src/runtime/ocl/ocl_device.cpp@@ -208,6 +208,7 @@ device_info init_device_info(const cl::Device& device, const cl::Context& contexinfo.dev_type = get_device_type(device);info.sub_device_idx = std::numeric_limits<uint32_t>::max();+ info.cacheline_size = device.getInfo<CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE>();info.execution_units_count = device.getInfo<CL_DEVICE_MAX_COMPUTE_UNITS>();info.gpu_frequency = static_cast<uint32_t>(device.getInfo<CL_DEVICE_MAX_CLOCK_FREQUENCY>());diff --git a/src/plugins/intel_gpu/src/runtime/ocl/ocl_engine.cpp b/src/plugins/intel_gpu/src/runtime/ocl/ocl_engine.cppindex f56d1f021c8..d7c458429f4 100644--- a/src/plugins/intel_gpu/src/runtime/ocl/ocl_engine.cpp+++ b/src/plugins/intel_gpu/src/runtime/ocl/ocl_engine.cpp@@ -17,6 +17,7 @@#include <vector>#include <memory>#include <stdexcept>+#include <cstdint>// NOTE: Due to buggy scope transition of warnings we need to disable warning in place of use/instantation// of some types (even though we already disabled them in scope of definition of these types).@@ -158,7 +159,8 @@ memory::ptr ocl_engine::import_buffer(const layout& layout, ov::intel_gpu::os_ha}clFinish(q);cl::Buffer buf(imported, true);- auto memory = std::make_shared<ocl::gpu_buffer_from_handle>(this, layout, buf, nullptr);+ auto mem_tracker = std::make_shared<MemoryTracker>(nullptr, buf.get(), byte_size, allocation_type::cl_mem);+ auto memory = std::make_shared<ocl::gpu_buffer_from_handle>(this, layout, buf, mem_tracker);clReleaseMemObject(imported);return memory;#endif@@ -208,6 +210,7 @@ memory::ptr ocl_engine::allocate_memory(const layout& layout, allocation_type ty}}}+memory::ptr ocl_engine::create_subbuffer(const memory& memory, const layout& new_layout, size_t byte_offset) {OPENVINO_ASSERT(memory.get_engine() == this, "[GPU] trying to create a subbuffer from a buffer allocated by a different engine");try {@@ -238,23 +241,15 @@ memory::ptr ocl_engine::create_subbuffer(const memory& memory, const layout& new}}-memory_ptr ocl_engine::create_mmap_hostbuffer(const void* mmapped_address, size_t data_size, allocation_type _allocation_type, const layout output_layout) {- auto tracker = std::make_shared<MemoryTracker>(this,- const_cast<void*>(mmapped_address), // Point directly to mmap'd memory- data_size,- _allocation_type);- std::uintptr_t mmap_address = reinterpret_cast<std::uintptr_t>(mmapped_address);- std::uintptr_t aligned_addr = mmap_address & ~(static_cast<std::uintptr_t>(cldnn::CACHE_PAGE_SIZE) - 1);- void* mmap_aligned_address = reinterpret_cast<void*>(aligned_addr);+memory_ptr ocl_engine::create_hostbuffer(void* cpu_address,+ size_t data_size,+ allocation_type _allocation_type,+ const layout output_layout) {+ return create_hostbuffer_impl(cpu_address, data_size, _allocation_type, output_layout, CL_MEM_READ_WRITE);+}- cl_int err = CL_SUCCESS;- cl_mem_flags flags = CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR;-#ifdef CL_MEM_FORCE_HOST_MEMORY_INTEL- flags |= CL_MEM_FORCE_HOST_MEMORY_INTEL;-#endif- cl::Buffer buffer(get_cl_context(), flags, data_size, mmap_aligned_address, &err);- OPENVINO_ASSERT(err == CL_SUCCESS, "clcreatebuffer with CL_MEM_USE_HOST_PTR and CL_MEM_FORCE_HOST_MEMORY_INTEL failed!");- return std::make_shared<ocl::gpu_buffer>(this, output_layout, buffer, tracker);+memory_ptr ocl_engine::create_hostbuffer(const void* cpu_address, size_t data_size, allocation_type _allocation_type, const layout output_layout) {+ return create_hostbuffer_impl(const_cast<void*>(cpu_address), data_size, _allocation_type, output_layout, CL_MEM_READ_ONLY);}memory::ptr ocl_engine::reinterpret_buffer(const memory& memory, const layout& new_layout) {@@ -379,13 +374,45 @@ std::shared_ptr<cldnn::engine> ocl_engine::create(const device::ptr device, runtreturn std::make_shared<ocl::ocl_engine>(device, runtime_type);}-std::shared_ptr<cldnn::engine> create_ocl_engine(const device::ptr device, runtime_types runtime_type) {- return ocl_engine::create(device, runtime_type);-}+memory_ptr ocl_engine::create_hostbuffer_impl(void* cpu_address, size_t data_size, allocation_type allocation, const layout& output_layout, cl_mem_flags access_flags) {+ cl_int err = CL_SUCCESS;+ cl_mem_flags flags = access_flags | CL_MEM_USE_HOST_PTR;-} // namespace ocl-} // namespace cldnn+#ifdef CL_MEM_FORCE_HOST_MEMORY_INTEL+ const size_t minimal_alignment = static_cast<size_t>(get_device_info().cacheline_size);+ OPENVINO_ASSERT(minimal_alignment > 0, "[GPU] cacheline_size must be > 0 for host pointer import");+ OPENVINO_ASSERT((reinterpret_cast<std::uintptr_t>(cpu_address) % minimal_alignment) == 0,+ "[GPU] shared buffer pointer must be ", minimal_alignment, "-byte aligned");+ OPENVINO_ASSERT((data_size % minimal_alignment) == 0,+ "[GPU] shared buffer size must be a multiple of ", minimal_alignment, " bytes");+ flags |= CL_MEM_FORCE_HOST_MEMORY_INTEL;+#endif+ cl::Buffer buffer(get_cl_context(), flags, data_size, cpu_address, &err);+#ifdef CL_MEM_FORCE_HOST_MEMORY_INTEL+ OPENVINO_ASSERT(err == CL_SUCCESS, "clCreateBuffer with CL_MEM_USE_HOST_PTR and CL_MEM_FORCE_HOST_MEMORY_INTEL failed!");+#else+ OPENVINO_ASSERT(err == CL_SUCCESS, "clCreateBuffer with CL_MEM_USE_HOST_PTR failed!");+#endif+ std::shared_ptr<MemoryTracker> tracker = nullptr;+#ifdef CL_MEM_FORCE_HOST_MEMORY_INTEL+ tracker = std::make_shared<MemoryTracker>(nullptr,+ cpu_address,+ data_size,+ allocation);+#else+ tracker = std::make_shared<MemoryTracker>(this,+ cpu_address,+ data_size,+ allocation);+#endif+ return std::make_shared<ocl::gpu_buffer>(this, output_layout, buffer, tracker);+}+std::shared_ptr<cldnn::engine> create_ocl_engine(const device::ptr device, runtime_types runtime_type) {+ return ocl_engine::create(device, runtime_type);+}+} // namespace ocl+} // namespace cldnndiff --git a/src/plugins/intel_gpu/src/runtime/ocl/ocl_engine.hpp b/src/plugins/intel_gpu/src/runtime/ocl/ocl_engine.hppindex 586a7fd02ff..2d39a5013a5 100644--- a/src/plugins/intel_gpu/src/runtime/ocl/ocl_engine.hpp+++ b/src/plugins/intel_gpu/src/runtime/ocl/ocl_engine.hpp@@ -26,7 +26,8 @@ public:memory_ptr allocate_memory(const layout& layout, allocation_type type, bool reset = true) override;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 create_mmap_hostbuffer(const void* mmapped_address, size_t data_size, allocation_type _allocation_type, const layout output_layout) override;+ memory_ptr create_hostbuffer(void* cpu_address, size_t data_size, allocation_type _allocation_type, const layout output_layout) override;+ memory_ptr create_hostbuffer(const void* cpu_address, size_t data_size, allocation_type _allocation_type, const layout output_layout) override;memory_ptr reinterpret_buffer(const memory& memory, const layout& new_layout) override;memory_ptr import_buffer(const layout&, ov::intel_gpu::os_handle_param external_handle) override;bool is_the_same_buffer(const memory& mem1, const memory& mem2) override;@@ -55,6 +56,7 @@ public:static std::shared_ptr<cldnn::engine> create(const device::ptr device, runtime_types runtime_type);private:+ memory_ptr create_hostbuffer_impl(void* cpu_address, size_t data_size, allocation_type allocation, const layout& output_layout, cl_mem_flags access_flags);std::string _extensions;};diff --git a/src/plugins/intel_gpu/src/runtime/sycl/sycl_device.cpp b/src/plugins/intel_gpu/src/runtime/sycl/sycl_device.cppindex 945e815e105..d8b9c6f70b8 100644--- a/src/plugins/intel_gpu/src/runtime/sycl/sycl_device.cpp+++ b/src/plugins/intel_gpu/src/runtime/sycl/sycl_device.cpp@@ -186,6 +186,8 @@ device_info init_device_info(const ::sycl::device& device, const ::sycl::contextinfo.driver_version = device.get_info<::sycl::info::device::driver_version>();info.dev_type = get_device_type(device);+ info.cacheline_size = device.get_info<::sycl::info::device::global_mem_cache_line_size>();+info.execution_units_count = device.get_info<::sycl::info::device::max_compute_units>();info.gpu_frequency = device.get_info<::sycl::info::device::max_clock_frequency>();diff --git a/src/plugins/intel_gpu/src/runtime/sycl/sycl_engine.cpp b/src/plugins/intel_gpu/src/runtime/sycl/sycl_engine.cppindex 7c7761e8c6f..d9ef60fe797 100644--- a/src/plugins/intel_gpu/src/runtime/sycl/sycl_engine.cpp+++ b/src/plugins/intel_gpu/src/runtime/sycl/sycl_engine.cpp@@ -151,7 +151,11 @@ memory::ptr sycl_engine::create_subbuffer(const memory& memory, const layout& ne}}-memory_ptr sycl_engine::create_mmap_hostbuffer(const void* mmapped_address, size_t data_size, allocation_type _allocation_type, const layout output_layout) {+memory_ptr sycl_engine::create_hostbuffer(void* cpu_address, size_t data_size, allocation_type _allocation_type, const layout output_layout) {+ OPENVINO_NOT_IMPLEMENTED;+}++memory_ptr sycl_engine::create_hostbuffer(const void* cpu_address, size_t data_size, allocation_type _allocation_type, const layout output_layout) {OPENVINO_NOT_IMPLEMENTED;}diff --git a/src/plugins/intel_gpu/src/runtime/sycl/sycl_engine.hpp b/src/plugins/intel_gpu/src/runtime/sycl/sycl_engine.hppindex 3165165fd65..a440d4a7c6a 100644--- a/src/plugins/intel_gpu/src/runtime/sycl/sycl_engine.hpp+++ b/src/plugins/intel_gpu/src/runtime/sycl/sycl_engine.hpp@@ -30,7 +30,8 @@ public:memory_ptr allocate_memory(const layout& layout, allocation_type type, bool reset = true) override;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 create_mmap_hostbuffer(const void* mmapped_address, size_t data_size, allocation_type _allocation_type, const layout output_layout) override;+ memory_ptr create_hostbuffer(void* cpu_address, size_t data_size, allocation_type _allocation_type, const layout output_layout) override;+ memory_ptr create_hostbuffer(const void* cpu_address, size_t data_size, allocation_type _allocation_type, const layout output_layout) override;memory_ptr reinterpret_buffer(const memory& memory, const layout& new_layout) override;memory_ptr import_buffer(const layout& layout, ov::intel_gpu::os_handle_param external_handle) override;bool is_the_same_buffer(const memory& mem1, const memory& mem2) override;diff --git a/src/plugins/intel_gpu/src/runtime/ze/ze_device.cpp b/src/plugins/intel_gpu/src/runtime/ze/ze_device.cppindex 384016409aa..d0253c30d84 100644--- a/src/plugins/intel_gpu/src/runtime/ze/ze_device.cpp+++ b/src/plugins/intel_gpu/src/runtime/ze/ze_device.cpp@@ -174,7 +174,15 @@ device_info init_device_info(ze_driver_handle_t driver, ze_device_handle_t devic// ZE returns drivers version in different format than OCLinfo.driver_version = std::to_string(driver_properties.driverVersion);info.dev_type = (device_properties.flags & ZE_DEVICE_PROPERTY_FLAG_INTEGRATED) ? device_type::integrated_gpu : device_type::discrete_gpu;-+ ze_device_cache_line_size_ext_t devCacheLineSize = {ZE_STRUCTURE_TYPE_DEVICE_CACHELINE_SIZE_EXT, nullptr};+ ze_device_cache_properties_t devCacheProps = {ZE_STRUCTURE_TYPE_DEVICE_CACHE_PROPERTIES, &devCacheLineSize};+ uint32_t count = 1;+ info.cacheline_size = 0;+ OV_ZE_EXPECT(ze::zeDeviceGetCacheProperties(device, &count, &devCacheProps));+ if (count > 0) {+ info.cacheline_size = static_cast<int32_t>(devCacheLineSize.cacheLineSize);+ }+info.execution_units_count = device_properties.numEUsPerSubslice * device_properties.numSubslicesPerSlice * device_properties.numSlices;info.gpu_frequency = device_properties.coreClockRate;diff --git a/src/plugins/intel_gpu/src/runtime/ze/ze_engine.cpp b/src/plugins/intel_gpu/src/runtime/ze/ze_engine.cppindex 08590b0ddb5..3047d902982 100644--- a/src/plugins/intel_gpu/src/runtime/ze/ze_engine.cpp+++ b/src/plugins/intel_gpu/src/runtime/ze/ze_engine.cpp@@ -171,7 +171,11 @@ memory_ptr ze_engine::create_subbuffer(const memory& memory, const layout& new_lmemory.get_mem_tracker());}-memory_ptr ze_engine::create_mmap_hostbuffer(const void* mmapped_address, size_t data_size, allocation_type _allocation_type, const layout output_layout) {+memory_ptr ze_engine::create_hostbuffer(void* cpu_address, size_t data_size, allocation_type _allocation_type, const layout output_layout) {+ OPENVINO_NOT_IMPLEMENTED;+}++memory_ptr ze_engine::create_hostbuffer(const void* cpu_address, size_t data_size, allocation_type _allocation_type, const layout output_layout) {OPENVINO_NOT_IMPLEMENTED;}diff --git a/src/plugins/intel_gpu/src/runtime/ze/ze_engine.hpp b/src/plugins/intel_gpu/src/runtime/ze/ze_engine.hppindex ebacf2a8719..51c2067b10c 100644--- a/src/plugins/intel_gpu/src/runtime/ze/ze_engine.hpp+++ b/src/plugins/intel_gpu/src/runtime/ze/ze_engine.hpp@@ -27,7 +27,8 @@ public:memory_ptr import_buffer(const layout& layout, ov::intel_gpu::os_handle_param external_handle) override;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 byte_offset) override;- memory_ptr create_mmap_hostbuffer(const void* mmapped_address, size_t data_size, allocation_type _allocation_type, const layout output_layout) override;+ memory_ptr create_hostbuffer(void* cpu_address, size_t data_size, allocation_type _allocation_type, const layout output_layout) override;+ memory_ptr create_hostbuffer(const void* cpu_address, size_t data_size, allocation_type _allocation_type, const layout output_layout) override;memory_ptr reinterpret_buffer(const memory& memory, const layout& new_layout) override;bool is_the_same_buffer(const memory& mem1, const memory& mem2) override;diff --git a/src/plugins/intel_gpu/tests/functional/remote_tensor_tests/dx11_nthandle.cpp b/src/plugins/intel_gpu/tests/functional/remote_tensor_tests/dx11_nthandle.cppindex 8d03463c6f6..5cb49115090 100644--- a/src/plugins/intel_gpu/tests/functional/remote_tensor_tests/dx11_nthandle.cpp+++ b/src/plugins/intel_gpu/tests/functional/remote_tensor_tests/dx11_nthandle.cpp@@ -25,6 +25,7 @@#include "openvino/op/constant.hpp"#include "openvino/op/parameter.hpp"#include "openvino/op/result.hpp"+#include "remote_tensor_tests/helpers.hpp"#include "common_test_utils/test_constants.hpp"namespace {@@ -51,16 +52,6 @@ bool get_context_device_luid(cl_context cl_ctx, std::array<unsigned char, CL_LUIreturn clGetDeviceInfo(cl_devices[0], CL_DEVICE_LUID_KHR, cl_luid.size(), cl_luid.data(), nullptr) == CL_SUCCESS;}-// Keep data unchanged while still forcing an explicit output tensor write path.-std::shared_ptr<ov::Model> make_copy_model(const ov::Shape& shape) {- auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, shape);- auto zero = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{1}, {0.0f});- auto add = std::make_shared<ov::op::v1::Add>(param, zero);- auto result = std::make_shared<ov::op::v0::Result>(add);- return std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{param});-}--struct Dx11TestContext {CComPtr<ID3D11Device> device;CComPtr<ID3D11DeviceContext> device_ctx;@@ -257,13 +248,11 @@ TEST(GpuSharedBufferRemoteTensor, smoke_Dx11RemoteInputToRemoteOutputCopyAndCompauto remote_input_tensor = ctx.create_tensor(ov::element::f32,- shape,- dx_input_shared.shared_handle,- ov::intel_gpu::MemType::SHARED_BUF);+ shape,+ ov::intel_gpu::SharedBufferHandle{dx_input_shared.shared_handle});auto remote_output_tensor = ctx.create_tensor(ov::element::f32,- shape,- dx_output_shared.shared_handle,- ov::intel_gpu::MemType::SHARED_BUF);+ shape,+ ov::intel_gpu::SharedBufferHandle{dx_output_shared.shared_handle});auto model = make_copy_model(shape);auto compiled = core.compile_model(model, ctx);diff --git a/src/plugins/intel_gpu/tests/functional/remote_tensor_tests/dx12_nthandle.cpp b/src/plugins/intel_gpu/tests/functional/remote_tensor_tests/dx12_nthandle.cppindex ea357e8cc75..a6fd3edb2c1 100644--- a/src/plugins/intel_gpu/tests/functional/remote_tensor_tests/dx12_nthandle.cpp+++ b/src/plugins/intel_gpu/tests/functional/remote_tensor_tests/dx12_nthandle.cpp@@ -21,6 +21,7 @@#undef NOMINMAX_DEFINED_SHARED_BUF_TEST#endif+#include "remote_tensor_tests/helpers.hpp"#include "openvino/runtime/core.hpp"#include "openvino/runtime/intel_gpu/ocl/ocl.hpp"#include "openvino/op/add.hpp"@@ -52,16 +53,6 @@ bool get_context_device_luid(cl_context cl_ctx, std::array<unsigned char, CL_LUIreturn clGetDeviceInfo(cl_devices[0], CL_DEVICE_LUID_KHR, cl_luid.size(), cl_luid.data(), nullptr) == CL_SUCCESS;}-// Keep data unchanged while still forcing an explicit output tensor write path.-std::shared_ptr<ov::Model> make_copy_model(const ov::Shape& shape) {- auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, shape);- auto zero = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{1}, {0.0f});- auto add = std::make_shared<ov::op::v1::Add>(param, zero);- auto result = std::make_shared<ov::op::v0::Result>(add);- return std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{param});-}--struct Dx12TestContext {CComPtr<IDXGIAdapter1> adapter;CComPtr<ID3D12Device> device;@@ -277,12 +268,12 @@ TEST(GpuSharedBufferRemoteTensor, smoke_Dx12RemoteInputToRemoteOutputCopyAndCompov::RemoteTensor remote_input_tensor;ov::RemoteTensor remote_output_tensor;- remote_input_tensor = candidate_ctx.create_tensor(ov::element::f32, shape,- dx_input_shared.shared_handle,- ov::intel_gpu::MemType::SHARED_BUF);- remote_output_tensor = candidate_ctx.create_tensor(ov::element::f32, shape,- dx_output_shared.shared_handle,- ov::intel_gpu::MemType::SHARED_BUF);+ remote_input_tensor = candidate_ctx.create_tensor(ov::element::f32,+ shape,+ ov::intel_gpu::SharedBufferHandle{dx_input_shared.shared_handle});+ remote_output_tensor = candidate_ctx.create_tensor(ov::element::f32,+ shape,+ ov::intel_gpu::SharedBufferHandle{dx_output_shared.shared_handle});auto model = make_copy_model(shape);auto compiled = core.compile_model(model, candidate_ctx);diff --git a/src/plugins/intel_gpu/tests/functional/remote_tensor_tests/dx12_remote_run.cpp b/src/plugins/intel_gpu/tests/functional/remote_tensor_tests/dx12_remote_run.cppindex 2417954077e..96c020adb56 100644--- a/src/plugins/intel_gpu/tests/functional/remote_tensor_tests/dx12_remote_run.cpp+++ b/src/plugins/intel_gpu/tests/functional/remote_tensor_tests/dx12_remote_run.cpp@@ -195,7 +195,7 @@ TEST_F(DX12RemoteRunTests, smoke_CheckRemoteTensorSharedBuf) {createHeap(byte_size);- auto remote_tensor = context.create_tensor(ov::element::f32, tensor.get_shape(), shared_mem, ov::intel_gpu::MemType::SHARED_BUF);+ auto remote_tensor = context.create_tensor(ov::element::f32, tensor.get_shape(), ov::intel_gpu::SharedBufferHandle{shared_mem});ov::Tensor check_remote_tensor;ASSERT_NO_THROW(check_remote_tensor = remote_tensor);@@ -216,7 +216,7 @@ TEST_F(DX12RemoteRunTests, smoke_CheckRemoteTensorSharedBuChangingTensors) {const auto byte_size = ov::util::get_memory_size(ov::element::f32, shape_size(tensor.get_shape()));auto context = core->get_default_context(target_device).as<ov::intel_gpu::ocl::ClContext>();;createHeap(byte_size);- auto remote_tensor = context.create_tensor(ov::element::f32, tensor.get_shape(), shared_mem, ov::intel_gpu::MemType::SHARED_BUF);+ auto remote_tensor = context.create_tensor(ov::element::f32, tensor.get_shape(), ov::intel_gpu::SharedBufferHandle{shared_mem});ov::Tensor check_remote_tensor;ASSERT_NO_THROW(check_remote_tensor = remote_tensor);ASSERT_THROW(check_remote_tensor.data(), ov::Exception);@@ -267,7 +267,7 @@ TEST_F(DX12RemoteRunTests, smoke_CheckOutputDataFromMultipleRuns) {std::vector<float> output_data_one(output_tensor.get_size());ov::Tensor output_data_tensor_one{ov::element::f32, output_tensor.get_shape(), output_data_one.data()};- auto remote_tensor = context.create_tensor(ov::element::f32, shape, shared_mem, ov::intel_gpu::MemType::SHARED_BUF);+ auto remote_tensor = context.create_tensor(ov::element::f32, shape, ov::intel_gpu::SharedBufferHandle{shared_mem});OV_ASSERT_NO_THROW(inference_request.set_input_tensor(remote_tensor));OV_ASSERT_NO_THROW(inference_request.set_output_tensor(output_data_tensor_one));OV_ASSERT_NO_THROW(inference_request.infer());diff --git a/src/plugins/intel_gpu/tests/functional/remote_tensor_tests/helpers.hpp b/src/plugins/intel_gpu/tests/functional/remote_tensor_tests/helpers.hppindex 71621c22305..4d6603ca4a4 100644--- a/src/plugins/intel_gpu/tests/functional/remote_tensor_tests/helpers.hpp+++ b/src/plugins/intel_gpu/tests/functional/remote_tensor_tests/helpers.hpp@@ -16,6 +16,11 @@#elif defined ENABLE_LIBVA# include "openvino/runtime/intel_gpu/ocl/va.hpp"#endif+#include "openvino/core/model.hpp"+#include "openvino/op/add.hpp"+#include "openvino/op/constant.hpp"+#include "openvino/op/parameter.hpp"+#include "openvino/op/result.hpp"#include "openvino/runtime/intel_gpu/ocl/ocl.hpp"namespace {@@ -186,3 +191,11 @@ struct OpenCL {return ret_val;}};++inline std::shared_ptr<ov::Model> make_copy_model(const ov::Shape& shape) {+ auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, shape);+ auto zero = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{1}, {0.0f});+ auto add = std::make_shared<ov::op::v1::Add>(param, zero);+ auto result = std::make_shared<ov::op::v0::Result>(add);+ return std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{param});+}diff --git a/src/plugins/intel_gpu/tests/functional/remote_tensor_tests/ocl_remote_tensor_tests.cpp b/src/plugins/intel_gpu/tests/functional/remote_tensor_tests/ocl_remote_tensor_tests.cppindex 71fa38993f0..82b6e1a33e7 100644--- a/src/plugins/intel_gpu/tests/functional/remote_tensor_tests/ocl_remote_tensor_tests.cpp+++ b/src/plugins/intel_gpu/tests/functional/remote_tensor_tests/ocl_remote_tensor_tests.cpp@@ -2,6 +2,10 @@// SPDX-License-Identifier: Apache-2.0//+#ifdef OV_GPU_WITH_OCL_RT++#include <algorithm>+#include "openvino/core/preprocess/pre_post_process.hpp"#include "openvino/op/add.hpp"#include "openvino/op/constant.hpp"@@ -10,6 +14,7 @@#include "openvino/runtime/intel_gpu/ocl/ocl.hpp"#include "openvino/runtime/intel_gpu/properties.hpp"#include "openvino/runtime/remote_tensor.hpp"+#include "openvino/util/memory.hpp"#include "remote_tensor_tests/helpers.hpp"#include "common_test_utils/ov_tensor_utils.hpp"@@ -2945,3 +2950,45 @@ INSTANTIATE_TEST_SUITE_P(smoke_RemoteTensorDataType, OVRemoteTensorDataType_Testov::element::Type_t::u16,ov::element::Type_t::u32)),OVRemoteTensorDataType_Test::getTestCaseName);++TEST(GpuRemoteTensorFromCpu, smoke_allocAlignedCPUMemory) {+ ov::Core core;+ std::string target_device = ov::test::utils::DEVICE_GPU;+ uint32_t cacheline_size = core.get_property(target_device, ov::intel_gpu::cacheline_size);+ ASSERT_GT(cacheline_size, 0u);+ const size_t float_size = sizeof(float);+ const ov::Shape shape{cacheline_size/float_size};+ const size_t element_count = ov::shape_size(shape);+ const size_t byte_size = element_count * sizeof(float);+ auto ctx = core.get_default_context(target_device).as<ov::intel_gpu::ocl::ClContext>();+ void* input_ptr = ov::util::aligned_alloc(byte_size, cacheline_size);+ void* output_ptr = ov::util::aligned_alloc(byte_size, cacheline_size);++ std::fill_n(static_cast<float*>(input_ptr), element_count, 2.0f);+ std::fill_n(static_cast<float*>(output_ptr), element_count, 0.0f);++ {+ auto remote_input_tensor = ctx.create_tensor(ov::element::f32,+ shape,+ ov::intel_gpu::VirtualAddressMemory(input_ptr));+ auto remote_output_tensor = ctx.create_tensor(ov::element::f32,+ shape,+ ov::intel_gpu::VirtualAddressMemory(output_ptr));++ auto model = make_copy_model(shape);+ auto compiled = core.compile_model(model, ctx);+ auto infer_req = compiled.create_infer_request();+ infer_req.set_tensor(compiled.input(), remote_input_tensor);+ infer_req.set_tensor(compiled.output(), remote_output_tensor);+ infer_req.infer();++ for (size_t i = 0; i < element_count; ++i) {+ EXPECT_FLOAT_EQ(static_cast<float*>(output_ptr)[i], 2.0f) << "Mismatch at index " << i;+ }+ }++ ov::util::aligned_free(input_ptr);+ ov::util::aligned_free(output_ptr);+}++#endif // OV_GPU_WITH_OCL_RT