Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[GPU] adding get_onednn_grouped_memory API (#35212)

Eddy Kimba576276b6fa
diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/memory.hpp b/src/plugins/intel_gpu/include/intel_gpu/runtime/memory.hpp
index ee7dfa1f0c4..1e9ef900a14 100644
--- a/src/plugins/intel_gpu/include/intel_gpu/runtime/memory.hpp
+++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/memory.hpp
@@ -124,6 +124,10 @@ struct memory {
virtual dnnl::memory get_onednn_memory(dnnl::memory::desc /* desc */, int64_t offset = 0) const {
throw std::runtime_error("[CLDNN] Can't convert memory object to onednn");
}
+
+ virtual dnnl::memory get_onednn_grouped_memory(dnnl::memory::desc /* desc */, const memory& offsets) const {
+ throw std::runtime_error("[CLDNN] Can't convert memory object to onednn");
+ }
#endif
std::shared_ptr<MemoryTracker> get_mem_tracker() const { return m_mem_tracker; }
diff --git a/src/plugins/intel_gpu/src/graph/impls/onednn/moe_gemm_onednn.cpp b/src/plugins/intel_gpu/src/graph/impls/onednn/moe_gemm_onednn.cpp
index 31b94ee223f..cd1a70b7e00 100644
--- a/src/plugins/intel_gpu/src/graph/impls/onednn/moe_gemm_onednn.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/onednn/moe_gemm_onednn.cpp
@@ -7,7 +7,6 @@
#include "primitive_onednn_base.h"
#include <oneapi/dnnl/dnnl.hpp>
-#include <oneapi/dnnl/dnnl_ocl.hpp>
#include <algorithm>
#include <memory>
@@ -28,34 +27,25 @@ protected:
std::unordered_map<int, dnnl::memory> get_arguments(moe_gemm_inst& instance) const override {
std::unordered_map<int, dnnl::memory> args;
- auto& engine = instance.get_network().get_engine();
- auto& onednn_engine = engine.get_onednn_engine();
auto moe_cfg = MoEGemmImplementationManager::get_moe_cfg(*instance.get_impl_params());
{
auto& input = instance.input_memory(moe_gemm::MoEGemmInputIdx::INPUT);
auto& offsets = instance.input_memory(moe_gemm::MoEGemmInputIdx::INPUT_OFFSET_PER_EXPERT);
- OPENVINO_ASSERT(input.get_allocation_type() >= allocation_type::usm_host, "[GPU] oneDNN MOE GEMM implementation supports only USM input memory");
- dnnl::memory input_mem = dnnl::ocl_interop::make_memory(_pd.src_desc(0), onednn_engine, dnnl::ocl_interop::memory_kind::usm,
- {reinterpret_cast<uint8_t*>(input.buffer_ptr()), reinterpret_cast<uint8_t*>(offsets.buffer_ptr())});
-
+ dnnl::memory input_mem = input.get_onednn_grouped_memory(_pd.src_desc(0), offsets);
args.insert({DNNL_ARG_SRC, input_mem});
}
{
auto& output = instance.output_memory(0);
auto& offsets = instance.input_memory(moe_gemm::MoEGemmInputIdx::INPUT_OFFSET_PER_EXPERT);
- OPENVINO_ASSERT(output.get_allocation_type() >= allocation_type::usm_host, "[GPU] oneDNN MOE GEMM implementation supports only USM output memory");
- dnnl::memory output_mem = dnnl::ocl_interop::make_memory(_pd.dst_desc(0), onednn_engine, dnnl::ocl_interop::memory_kind::usm,
- {reinterpret_cast<uint8_t*>(output.buffer_ptr()), reinterpret_cast<uint8_t*>(offsets.buffer_ptr())});
-
+ dnnl::memory output_mem = output.get_onednn_grouped_memory(_pd.dst_desc(0), offsets);
args.insert({DNNL_ARG_DST, output_mem});
}
{
auto& weights = instance.input_memory(moe_gemm::MoEGemmInputIdx::WEIGHT);
- dnnl::memory weights_mem = dnnl::ocl_interop::make_memory(_pd.weights_desc(0), onednn_engine, dnnl::ocl_interop::memory_kind::usm,
- reinterpret_cast<uint8_t*>(weights.buffer_ptr()));
+ dnnl::memory weights_mem = weights.get_onednn_memory(_pd.weights_desc(0), 0);
args.insert({DNNL_ARG_WEIGHTS, weights_mem});
}
@@ -69,24 +59,21 @@ protected:
dnnl::memory::format_tag wei_scales_fmt = (moe_cfg.weight_group_size == -1) ? dnnl::memory::format_tag::ab : dnnl::memory::format_tag::abc;
dnnl::memory::desc wei_scales_md(
wei_scales_dims, convert_data_type(wei_scales.get_layout().data_type), wei_scales_fmt);
- dnnl::memory wei_scales_mem = dnnl::ocl_interop::make_memory(wei_scales_md, onednn_engine, dnnl::ocl_interop::memory_kind::usm,
- reinterpret_cast<uint8_t*>(wei_scales.buffer_ptr()));
+ dnnl::memory wei_scales_mem = wei_scales.get_onednn_memory(wei_scales_md, 0);
args.insert({DNNL_ARG_ATTR_SCALES | DNNL_ARG_WEIGHTS, wei_scales_mem});
if (!moe_cfg.is_weight_symmetric_quantized) {
auto& wei_zp = instance.input_memory(moe_cfg.weight_zp_idx);
dnnl::memory::desc wei_zp_md(
wei_scales_dims, convert_data_type(wei_zp.get_layout().data_type), wei_scales_fmt);
- dnnl::memory wei_zp_mem = dnnl::ocl_interop::make_memory(wei_zp_md, onednn_engine, dnnl::ocl_interop::memory_kind::usm,
- reinterpret_cast<uint8_t*>(wei_zp.buffer_ptr()));
+ dnnl::memory wei_zp_mem = wei_zp.get_onednn_memory(wei_zp_md, 0);
args.insert({DNNL_ARG_ATTR_ZERO_POINTS | DNNL_ARG_WEIGHTS, wei_zp_mem});
}
}
if (moe_cfg.has_bias) {
auto& bias = instance.input_memory(moe_gemm::MoEGemmInputIdx::BIAS);
- dnnl::memory bias_mem = dnnl::ocl_interop::make_memory(_pd.weights_desc(1), onednn_engine, dnnl::ocl_interop::memory_kind::usm,
- reinterpret_cast<uint8_t*>(bias.buffer_ptr()));
+ dnnl::memory bias_mem = bias.get_onednn_memory(_pd.weights_desc(1), 0);
args.insert({DNNL_ARG_BIAS, bias_mem});
}
diff --git a/src/plugins/intel_gpu/src/runtime/ocl/ocl_memory.cpp b/src/plugins/intel_gpu/src/runtime/ocl/ocl_memory.cpp
index eae064e9249..1a8aaf808dc 100644
--- a/src/plugins/intel_gpu/src/runtime/ocl/ocl_memory.cpp
+++ b/src/plugins/intel_gpu/src/runtime/ocl/ocl_memory.cpp
@@ -213,6 +213,10 @@ dnnl::memory gpu_buffer::get_onednn_memory(dnnl::memory::desc desc, int64_t offs
#endif
return dnnl_mem;
}
+
+dnnl::memory gpu_buffer::get_onednn_grouped_memory(dnnl::memory::desc desc, const memory& offsets) const {
+ OPENVINO_THROW("[GPU] Grouped memory is not supported for gpu_buffer.");
+}
#endif
gpu_image2d::gpu_image2d(ocl_engine* engine, const layout& layout)
@@ -650,6 +654,19 @@ dnnl::memory gpu_usm::get_onednn_memory(dnnl::memory::desc desc, int64_t offset)
return dnnl_mem;
#endif
}
+
+dnnl::memory gpu_usm::get_onednn_grouped_memory(dnnl::memory::desc desc, const memory& offsets) const {
+ auto onednn_engine = _engine->get_onednn_engine();
+#ifdef OV_GPU_WITH_ZE_RT
+ OPENVINO_THROW("[GPU] Using OCL OneDNN API with L0 runtime");
+#else
+ OPENVINO_ASSERT(memory_capabilities::is_usm_type(offsets.get_allocation_type()));
+ OPENVINO_ASSERT(offsets.get_engine() == this->_engine);
+ dnnl::memory dnnl_mem = dnnl::ocl_interop::make_memory(desc, onednn_engine, dnnl::ocl_interop::memory_kind::usm,
+ {reinterpret_cast<uint8_t*>(_buffer.get()), reinterpret_cast<uint8_t*>(offsets.buffer_ptr())});
+ return dnnl_mem;
+#endif
+}
#endif
shared_mem_params gpu_usm::get_internal_params() const {
diff --git a/src/plugins/intel_gpu/src/runtime/ocl/ocl_memory.hpp b/src/plugins/intel_gpu/src/runtime/ocl/ocl_memory.hpp
index aaf10dc55f5..5e003f4867c 100644
--- a/src/plugins/intel_gpu/src/runtime/ocl/ocl_memory.hpp
+++ b/src/plugins/intel_gpu/src/runtime/ocl/ocl_memory.hpp
@@ -49,6 +49,7 @@ struct gpu_buffer : public lockable_gpu_mem, public memory {
#ifdef ENABLE_ONEDNN_FOR_GPU
dnnl::memory get_onednn_memory(dnnl::memory::desc /* desc */, int64_t offset = 0) const override;
+ dnnl::memory get_onednn_grouped_memory(dnnl::memory::desc /* desc */, const memory& offsets) const override;
#endif
protected:
@@ -125,6 +126,7 @@ struct gpu_usm : public lockable_gpu_mem, public memory {
#ifdef ENABLE_ONEDNN_FOR_GPU
dnnl::memory get_onednn_memory(dnnl::memory::desc /* desc */, int64_t offset = 0) const override;
+ dnnl::memory get_onednn_grouped_memory(dnnl::memory::desc /* desc */, const memory& offsets) const override;
#endif
static allocation_type detect_allocation_type(const ocl_engine* engine, const void* mem_ptr);
diff --git a/src/plugins/intel_gpu/src/runtime/ze/ze_memory.cpp b/src/plugins/intel_gpu/src/runtime/ze/ze_memory.cpp
index 688c3f7b20c..36c9f5d0658 100644
--- a/src/plugins/intel_gpu/src/runtime/ze/ze_memory.cpp
+++ b/src/plugins/intel_gpu/src/runtime/ze/ze_memory.cpp
@@ -254,6 +254,15 @@ dnnl::memory gpu_usm::get_onednn_memory(dnnl::memory::desc desc, int64_t offset)
reinterpret_cast<uint8_t*>(_buffer.get()) + offset);
return dnnl_mem;
}
+
+dnnl::memory gpu_usm::get_onednn_grouped_memory(dnnl::memory::desc desc, const memory& offsets) const {
+ auto onednn_engine = _engine->get_onednn_engine();
+ OPENVINO_ASSERT(memory_capabilities::is_usm_type(offsets.get_allocation_type()));
+ OPENVINO_ASSERT(offsets.get_engine() == this->_engine);
+ dnnl::memory dnnl_mem = dnnl::ze_interop::make_memory(desc, onednn_engine,
+ {reinterpret_cast<uint8_t*>(_buffer.get()), reinterpret_cast<uint8_t*>(offsets.buffer_ptr())});
+ return dnnl_mem;
+}
#endif
shared_mem_params gpu_usm::get_internal_params() const {
diff --git a/src/plugins/intel_gpu/src/runtime/ze/ze_memory.hpp b/src/plugins/intel_gpu/src/runtime/ze/ze_memory.hpp
index 36a2b61323e..1804f84422a 100644
--- a/src/plugins/intel_gpu/src/runtime/ze/ze_memory.hpp
+++ b/src/plugins/intel_gpu/src/runtime/ze/ze_memory.hpp
@@ -137,6 +137,7 @@ struct gpu_usm : public lockable_gpu_mem, public memory {
event::ptr copy_to(stream& stream, void* data_ptr, size_t src_offset, size_t dst_offset, size_t size, bool blocking) const override;
#ifdef ENABLE_ONEDNN_FOR_GPU
dnnl::memory get_onednn_memory(dnnl::memory::desc desc, int64_t offset) const override;
+ dnnl::memory get_onednn_grouped_memory(dnnl::memory::desc desc, const memory& offsets) const override;
#endif
static allocation_type detect_allocation_type(const ze_engine* engine, const void* mem_ptr);