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] Update eltwise_blocked_opt to zero out last data block that not align (#32247)
Chon Ming Leedaa5d148e4c1
diff --git a/src/plugins/intel_gpu/src/graph/primitive_inst.cpp b/src/plugins/intel_gpu/src/graph/primitive_inst.cppindex b45813329c9..8ce35d4597c 100644--- a/src/plugins/intel_gpu/src/graph/primitive_inst.cpp+++ b/src/plugins/intel_gpu/src/graph/primitive_inst.cpp@@ -2037,30 +2037,21 @@ void primitive_inst::prepare_primitive() {// After all dependencies are configured, check if the current primitive instance requires its output memory to be reset (e.g., when its user// is a convolution that requires zeroed-out data paddings)- auto skip_reset = true;if (is_dynamic() && need_reset_output_memory() && !can_be_optimized() && !get_node().is_type<input_layout>()) {const auto& users = get_user_insts();const auto skip_concat = users.size() == 1 && users.front()->get_node().is_type<concatenation>() && users.front()->get_node().is_runtime_skippable() &&users.front()->_allocation_done_by_other;- skip_reset = skip_concat;- }- // Need to reset crop's output to zeros, if followed by onednn concatenation that requires zero-padding for blocked format memory- if (get_node().is_type<crop>() && get_node().can_share_buffer() && _impl_params->get_output_layout(0).format.is_blocked() &&- get_node().get_users().size() == 1 && get_node().get_users().front()->is_type<concatenation>() &&- get_node().get_users().front()->get_selected_impl() && get_node().get_users().front()->get_selected_impl()->is_onednn()) {- if (get_node().get_selected_impl()->get_kernel_name().find("eltwise_blocked_opt") == std::string::npos || is_dynamic()) {- skip_reset = false;- }- }-- if (!skip_reset) {- for (const auto& output : _outputs) {- if (output != nullptr) {- GPU_DEBUG_TRACE_DETAIL << id() << " : Resetting output memory (" << output->buffer_ptr() << ")" << std::endl;- // Use marker to ensure proper synchronization for both events and barriers- auto dep_events = out_of_order_queue ? std::vector<event::ptr>{get_network().get_stream().enqueue_marker(_impl_params->dep_events)}- : std::vector<event::ptr>{};- add_dep_event(output->fill(get_network().get_stream(), dep_events));+ const auto skip_reset = skip_concat;++ if (!skip_reset) {+ for (const auto& output : _outputs) {+ if (output != nullptr) {+ GPU_DEBUG_TRACE_DETAIL << id() << " : Resetting output memory (" << output->buffer_ptr() << ")" << std::endl;+ // Use marker to ensure proper synchronization for both events and barriers+ auto dep_events = out_of_order_queue ? std::vector<event::ptr>{get_network().get_stream().enqueue_marker(_impl_params->dep_events)}+ : std::vector<event::ptr>{};+ add_dep_event(output->fill(get_network().get_stream(), dep_events));+ }}}}diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/eltwise_blocked_opt.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/eltwise_blocked_opt.clindex f5e4cc1ef80..7880928eaaf 100644--- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/eltwise_blocked_opt.cl+++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/eltwise_blocked_opt.cl@@ -61,13 +61,16 @@ KERNEL(eltwise_blocked_opt)(INPUTS_DECLSconst uint f_block = (inner_f + outer_f * F_BLOCK_COUNT);// Feature axis of input tensor is smaller than inner block size : No need to calculate this block- if ((f_block*VEC_SIZE) >= OUTPUT_FEATURE_NUM || b > OUTPUT_BATCH_NUM) {+ if ((f_block*VEC_SIZE) > OUTPUT_FEATURE_NUM || b > OUTPUT_BATCH_NUM) {return;}MAKE_VECTOR_TYPE(ACCUMULATOR_TYPE, VEC_SIZE) res;-- DO_ELTWISE+ if ((OUT_F_BLOCK * 2 > OUT_F_BLOCK_VEC_SIZE) && (OUT_F_BLOCK_VEC_SIZE == f_block)) {+ res = TO_OUTPUT_TYPE(0);+ } else {+ DO_ELTWISE+ }#if HAS_FUSED_OPSFUSED_OPS;diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/eltwise/eltwise_kernel_blocked_opt.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/eltwise/eltwise_kernel_blocked_opt.cppindex f4aa3d984c4..8923b2df677 100644--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/eltwise/eltwise_kernel_blocked_opt.cpp+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/eltwise/eltwise_kernel_blocked_opt.cpp@@ -303,6 +303,7 @@ JitConstants EltwiseKernel_blocked_opt::GetJitConstants(const eltwise_params& pajit.AddConstant(MakeJitConstant("OUTPUT_SIZE_XY", params.outputs[0].X().v * params.outputs[0].Y().v));// To calculate batch, define outer block size of feature axis (divided by the inner feature-block size)jit.AddConstant(MakeJitConstant("OUT_F_BLOCK", CeilDiv(params.outputs[0].Feature().v, inner_feature_blk_size)));+ jit.AddConstant(MakeJitConstant("OUT_F_BLOCK_VEC_SIZE", CeilDiv(params.outputs[0].Feature().v, vec_size)));bool use_vload = false;jit.Merge(MakeInputDeclsJitConstants(params, use_vload));