Skip to content

Commit 3a593df

Browse files
author
Chuquan Chen
committed
Extend MOE support to more GPUs
- Update the `m_use_onednn` in `execution_config.cpp` to trigger for the new `ov::op::internal::MOE` and `ov::intel_gpu::op::MoERouterFused` types - Update `transformations_pipeline.cpp` to guard router transformations (`FuseMoERouter`, `FuseMoERouterScale`) alongside the existing MoE optimizations under the `ENABLE_ONEDNN_FOR_GPU` block for `xe_lp` architecture and above. Signed-off-by: Peter Chen <peter.chen@intel.com>
1 parent 7cf8606 commit 3a593df

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,12 +567,13 @@ void TransformationsPipeline::apply(std::shared_ptr<ov::Model> func) {
567567
return false;
568568
}();
569569

570+
#ifdef ENABLE_ONEDNN_FOR_GPU
570571
const bool disable_moe_opt = GPU_DEBUG_VALUE_OR(config.get_disable_moe_opt(), false);
571572

572573
// MOE: TiledMoeBlock -> GatherMatmuls(compressed) -> MoeOp(compressed) -> MoeOpWithRouting(compressed).
573-
// Gated on supports_immad (systolic-only) and oneDNN (required for expert GEMM dispatch).
574-
// Note: even though we are already inside `if (supports_immad)`, oneDNN can still be explicitly disabled by the user.
575-
if (device_info.supports_immad && config.get_use_onednn()) {
574+
// Gated on oneDNN supports platforms.
575+
// Note: device_info.arch >= cldnn::gpu_arch::xe_lp are `oneDNN supports platforms`, register all MOE3GEMM related pass-es.
576+
if (device_info.arch >= cldnn::gpu_arch::xe_lp) {
576577
manager.register_pass<ov::pass::ConvertTiledMoeBlockToGatherMatmuls>();
577578

578579
// f32 listed because this pass runs before ConvertPrecision (line ~588);
@@ -595,6 +596,7 @@ void TransformationsPipeline::apply(std::shared_ptr<ov::Model> func) {
595596
manager.register_pass<ov::intel_gpu::FuseMOESharedExpert>();
596597
}
597598
}
599+
#endif // ENABLE_ONEDNN_FOR_GPU
598600
manager.register_pass<ov::pass::GatedDeltaNetFusion>();
599601
manager.register_pass<ov::pass::InitNodeInfo>();
600602
manager.register_pass<EinsumDecomposition>();

src/plugins/intel_gpu/src/runtime/execution_config.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
#include "intel_gpu/op/indirect_sdpa.hpp"
99
#include "intel_gpu/op/kv_cache.hpp"
10+
#ifdef ENABLE_ONEDNN_FOR_GPU
11+
#include "ov_ops/moe_compressed.hpp"
12+
#include "intel_gpu/op/moe_router_fused.hpp"
13+
#endif // ENABLE_ONEDNN_FOR_GPU
1014
#include "intel_gpu/op/sdpa.hpp"
1115
#include "intel_gpu/plugin/remote_context.hpp"
1216
#include "intel_gpu/primitives/paged_attention.hpp"
@@ -224,6 +228,21 @@ void ExecutionConfig::apply_model_specific_options(const IRemoteContext* context
224228
m_use_onednn = true;
225229
}
226230

231+
#ifdef ENABLE_ONEDNN_FOR_GPU
232+
// MOE and MoERouterFused uses oneDNN internally for matrix multiplications
233+
// (onednn_linear wrappers in moe_3gemm_swiglu_opt.cpp), which requires:
234+
// 1. use_onednn=true so create_onednn_engine() is called during program build
235+
// (see program.cpp: lo.enable_onednn_for<lstm_seq/gru_seq> path which makes
236+
// onednn_impls_optimization_attribute non-empty, triggering engine init).
237+
// 2. in-order OCL command queue (finalize_impl sets this when use_onednn=true).
238+
// Auto-enable this only on architectures with oneDNN support, consistent with
239+
// the LSTM/GRU path above, to avoid initializing oneDNN on unsupported devices.
240+
if ((ov::is_type<ov::op::internal::MOE>(op) || ov::is_type<ov::intel_gpu::op::MoERouterFused>(op)) &&
241+
info.arch >= cldnn::gpu_arch::xe_lp) {
242+
m_use_onednn = true;
243+
}
244+
#endif //ENABLE_ONEDNN_FOR_GPU
245+
227246
if (auto multi_subgraph_op = ov::as_type_ptr<ov::op::util::MultiSubGraphOp>(op)) {
228247
for (const auto& sub_graph : multi_subgraph_op->get_functions()) {
229248
for (auto& sub_op : sub_graph->get_ops()) {

0 commit comments

Comments
 (0)