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] Add implicit GEMM convolution kernel for 1D large-tap small-IC shapes (#37273)
Jade Cho8ec6567ee886
diff --git a/src/plugins/intel_gpu/src/graph/layout_optimizer.cpp b/src/plugins/intel_gpu/src/graph/layout_optimizer.cppindex 921acd2447f..e8aef9b3ecf 100644--- a/src/plugins/intel_gpu/src/graph/layout_optimizer.cpp+++ b/src/plugins/intel_gpu/src/graph/layout_optimizer.cpp@@ -1108,6 +1108,13 @@ format layout_optimizer::get_expected_format(convolution_node const& node) {bool onednn_valid_post_ops = get_post_ops_count(node) <= 32;bool use_onednn_impls = contains_onednn_impls_optimization_attribute(&node) && input_layout.data_type != data_types::f32;+ // convolution_gpu_1d_small_ic_gemm declares no fused ops, but a single+ // dependency-free activation still reaches it through convolution_params::activations+ // (see use_legacy_fused_ops()). Anything else fused would make it reject the node.+ const auto& fused_prims = node.get_fused_primitives();+ const bool activation_only_fusion = fused_prims.empty() ||+ (fused_prims.size() == 1 && fused_prims[0].is_type<activation>() && fused_prims[0].deps.empty());+// Use planar bfyx format for dynamic convolutions with explicit padding in clDNNif (node.is_dynamic() && output_layout.get_partial_shape().size() == 4 && node.use_explicit_padding() && !i8_u8_input &&(!use_onednn_impls || !onednn_valid_post_ops || node.has_padded_dependency())) {@@ -1135,6 +1142,11 @@ format layout_optimizer::get_expected_format(convolution_node const& node) {expected_format = cldnn::format::b_fs_yx_fsv32;elseexpected_format = cldnn::format::b_fs_zyx_fsv32;+ } else if (input_layout.get_rank() == 4 && input_layout.feature() == 1 &&+ input_layout.spatial(0) == 1 && weights_layout.spatial(0) == 1 &&+ weights_layout.spatial(1) >= 256 && activation_only_fusion) {+ // Use bfyx format for 1d conv with feature size 1 and 1d kernel size >= 256+ expected_format = cldnn::format::bfyx;} else if (i8_u8_input) {if (((_optimization_attributes.b_fs_yx_fsv16_network != 0) &&convolution_b_fs_yx_fsv16_opt(input_layout, output_layout, weights_layout, prim))) {diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/convolution_gpu_1d_small_ic_gemm.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/convolution_gpu_1d_small_ic_gemm.clnew file mode 100644index 00000000000..f51b90c0af8--- /dev/null+++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/convolution_gpu_1d_small_ic_gemm.cl@@ -0,0 +1,235 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "include/batch_headers/fetch_data.cl"+#include "include/batch_headers/fetch_weights.cl"++// Implicit-GEMM 1D convolution, C = A * B with+//+// A: weights, M x K, M = OC, K = IC * FILTER_LEN+// B: im2col, K x N, N = BATCH * OUT_LEN+//+// Neither is reordered or materialized: a K index decomposes into+// (input feature, filter position) and an N index into (batch, output position),+// so the input element a (k, n) pair refers to is+//+// input[batch][ic][n_pos * STRIDE + fpos * DILATION - PAD_BEGIN]+//+// resolved while staging tiles. Out-of-range positions are zero-filled there, so+// the accumulation loop is branch-free. See convolution_kernel_1d_small_ic_gemm.h.++// The host picks the long spatial axis and sets LONG_AXIS_IS_X, so these stay+// correct whether or not the plugin's XY swap applied.+#if LONG_AXIS_IS_X+ #define INPUT_AT(b, ic, pos) INPUT0_GET_INDEX(b, ic, 0, pos)+ #define OUTPUT_AT(b, oc, pos) OUTPUT_GET_INDEX(b, oc, 0, pos)+ #define WEIGHTS_AT(oc, ic, fpos) GET_FILTER_INDEX(FILTER, 0, oc, ic, 0, fpos)+#else+ #define INPUT_AT(b, ic, pos) INPUT0_GET_INDEX(b, ic, pos, 0)+ #define OUTPUT_AT(b, oc, pos) OUTPUT_GET_INDEX(b, oc, pos, 0)+ #define WEIGHTS_AT(oc, ic, fpos) GET_FILTER_INDEX(FILTER, 0, oc, ic, fpos, 0)+#endif++// A work-group computes a TILE_M x TILE_N tile but is only one sub-group wide:+// each lane owns N_PER_LANE columns and all TILE_M rows in registers.+#define WG_SIZE (SIMD)++// Vector load of B_VEC consecutive input elements, only valid on the B_IN_BOUNDS+// path where the host has proved a run of filter positions is contiguous.+#define B_VEC_TYPE MAKE_VECTOR_TYPE(INPUT0_TYPE, B_VEC)+#define B_VLOAD(ptr) CAT(vload, B_VEC)(0, ptr)++REQD_SUB_GROUP_SIZE(SIMD)+__attribute__((reqd_work_group_size(WG_SIZE, 1, 1)))+KERNEL(convolution_gpu_1d_small_ic_gemm)(+ OPTIONAL_SHAPE_INFO_ARG+ const __global INPUT0_TYPE *conv_input,+ __global OUTPUT_TYPE *output,+ const __global FILTER_TYPE *weights+#if BIAS_TERM+ , const __global BIAS_TYPE *biases+#endif+#if ASYMMETRIC_WEIGHTS_QUANTIZATION+ , const __global WEIGHTS_ZERO_POINTS_TYPE *weights_zp+#endif+#if ASYMMETRIC_DATA_QUANTIZATION+ , const __global ACTIVATIONS_ZERO_POINTS_TYPE *activations_zp+#endif+#if COMPENSATION_TERM+ , const __global COMPENSATION_TYPE *comp+#endif+)+{+ const uint lid = get_local_id(0);++ // Tile origin in the GEMM index space.+ const uint n_base = (uint)get_group_id(0) * TILE_N;+ const uint m_base = (uint)get_group_id(1) * TILE_M;++ // One K slice of A. B is per-lane and stays in registers.+ __local ACCUMULATOR_TYPE a_tile[TILE_M][TILE_K];++ // Both extents are compile-time constants and every access below is at a+ // constant index, so this stays in registers instead of spilling.+ ACCUMULATOR_TYPE acc[N_PER_LANE][TILE_M];+ __attribute__((opencl_unroll_hint))+ for (uint j = 0; j < N_PER_LANE; ++j)+ __attribute__((opencl_unroll_hint))+ for (uint i = 0; i < TILE_M; ++i)+ acc[j][i] = (ACCUMULATOR_TYPE)0;++ // This lane's output columns. SIMD apart rather than adjacent, so that at a+ // given j the sub-group covers consecutive columns and stays coalesced.+ uint n_batch[N_PER_LANE];+ uint n_pos[N_PER_LANE];+ bool n_valid[N_PER_LANE];+ __attribute__((opencl_unroll_hint))+ for (uint j = 0; j < N_PER_LANE; ++j) {+ const uint n = n_base + j * SIMD + lid;+ n_batch[j] = n / OUT_LEN;+ n_pos[j] = n % OUT_LEN;+ n_valid[j] = (n < GEMM_N);+ }++ for (uint k_base = 0; k_base < GEMM_K; k_base += TILE_K) {+ barrier(CLK_LOCAL_MEM_FENCE);++ // --- Stage A (weights): TILE_M x TILE_K, strided over the WG. ---+ for (uint idx = lid; idx < TILE_M * TILE_K; idx += WG_SIZE) {+ const uint am = idx / TILE_K;+ const uint ak = idx % TILE_K;+ const uint m = m_base + am;+ const uint k = k_base + ak;++ ACCUMULATOR_TYPE w = (ACCUMULATOR_TYPE)0;+ if (m < GEMM_M && k < GEMM_K) {+ // k -> (input feature, filter position)+ const uint k_ic = k / FILTER_LEN;+ const uint k_fpos = k % FILTER_LEN;+ const uint w_idx = WEIGHTS_AT(m, k_ic, k_fpos);+ w = TO_ACCUMULATOR_TYPE(weights[w_idx]);+#if ASYMMETRIC_WEIGHTS_QUANTIZATION+ w -= TO_ACCUMULATOR_TYPE(weights_zp[m]);+#endif+ }+ a_tile[am][ak] = w;+ }++ barrier(CLK_LOCAL_MEM_FENCE);++ // --- Stage B (im2col column block) and accumulate. ---+ // Staging and accumulation are fused so B lives in a few registers rather+ // than a dynamically indexed TILE_K array, which would spill. Loop order is+ // (k outer, column inner) so each SLM read of A is reused by all N_PER_LANE+ // columns - the whole reason for the 2D tile.+#if B_IN_BOUNDS+ // Fast path: every position is in range and a K run is contiguous, so+ // TILE_K scalar gathers become a handful of wide loads. The host proves this+ // for the whole iteration space; see GetJitConstants.+ {+ const uint k_ic = k_base / FILTER_LEN;+ const uint k_fpos = k_base % FILTER_LEN;++ const __global INPUT0_TYPE* src[N_PER_LANE];+ __attribute__((opencl_unroll_hint))+ for (uint j = 0; j < N_PER_LANE; ++j) {+ const uint pos = n_pos[j] * STRIDE_L + k_fpos * DILATION_L - PAD_BEGIN_L;+ src[j] = conv_input + INPUT_AT(n_batch[j], k_ic, pos);+ }+#if ASYMMETRIC_DATA_QUANTIZATION+ const ACCUMULATOR_TYPE azp = TO_ACCUMULATOR_TYPE(activations_zp[k_ic]);+#endif+ for (uint bk = 0; bk < TILE_K; bk += B_VEC) {+ B_VEC_TYPE raw[N_PER_LANE];+ __attribute__((opencl_unroll_hint))+ for (uint j = 0; j < N_PER_LANE; ++j)+ raw[j] = B_VLOAD(src[j] + bk);++ __attribute__((opencl_unroll_hint))+ for (uint e = 0; e < B_VEC; ++e) {+ ACCUMULATOR_TYPE bv[N_PER_LANE];+ __attribute__((opencl_unroll_hint))+ for (uint j = 0; j < N_PER_LANE; ++j) {+ bv[j] = TO_ACCUMULATOR_TYPE(raw[j][e]);+#if ASYMMETRIC_DATA_QUANTIZATION+ bv[j] -= azp;+#endif+ }++ __attribute__((opencl_unroll_hint))+ for (uint i = 0; i < TILE_M; ++i) {+ const ACCUMULATOR_TYPE av = a_tile[i][bk + e];+ __attribute__((opencl_unroll_hint))+ for (uint j = 0; j < N_PER_LANE; ++j)+ acc[j][i] = fma(av, bv[j], acc[j][i]);+ }+ }+ }+ }+#else+ // General path: guard every element. Used when padding, dilation or a ragged+ // tile can put a position out of range.+ for (uint bk = 0; bk < TILE_K; ++bk) {+ const uint k = k_base + bk;++ ACCUMULATOR_TYPE bv[N_PER_LANE];+ __attribute__((opencl_unroll_hint))+ for (uint j = 0; j < N_PER_LANE; ++j) {+ bv[j] = (ACCUMULATOR_TYPE)0;+ if (n_valid[j] && k < GEMM_K) {+ const uint k_ic = k / FILTER_LEN;+ const uint k_fpos = k % FILTER_LEN;+ const int pos = (int)(n_pos[j] * STRIDE_L + k_fpos * DILATION_L) - (int)PAD_BEGIN_L;+ if (pos >= 0 && pos < (int)IN_LEN) {+ const uint in_idx = INPUT_AT(n_batch[j], k_ic, (uint)pos);+ bv[j] = TO_ACCUMULATOR_TYPE(conv_input[in_idx]);+#if ASYMMETRIC_DATA_QUANTIZATION+ bv[j] -= TO_ACCUMULATOR_TYPE(activations_zp[k_ic]);+#endif+ }+ }+ }++ __attribute__((opencl_unroll_hint))+ for (uint i = 0; i < TILE_M; ++i) {+ const ACCUMULATOR_TYPE av = a_tile[i][bk];+ __attribute__((opencl_unroll_hint))+ for (uint j = 0; j < N_PER_LANE; ++j)+ acc[j][i] = fma(av, bv[j], acc[j][i]);+ }+ }+#endif+ }++ // --- Epilogue: bias, activation, store. ---+ // M outermost so that, for a fixed i, the lanes at a given j write consecutive+ // output elements.+ __attribute__((opencl_unroll_hint))+ for (uint i = 0; i < TILE_M; ++i) {+ const uint m = m_base + i;+ if (m >= GEMM_M)+ continue;++ __attribute__((opencl_unroll_hint))+ for (uint j = 0; j < N_PER_LANE; ++j) {+ if (!n_valid[j])+ continue;++ ACTIVATION_TYPE res = TO_ACTIVATION_TYPE(acc[j][i]);+ // No compensation term on purpose: this kernel already subtracted the+ // activation zero point per element while staging B, so applying the+ // precomputed -sum(azp * w) would double-count.+#if BIAS_TERM+ res += TO_ACTIVATION_TYPE(biases[m]);+#endif+ const uint dst = OUTPUT_AT(n_batch[j], m, n_pos[j]);+ output[dst] = TO_OUTPUT_TYPE(ACTIVATION_TYPED(res, ACTIVATION_PARAMS_TYPED));+ }+ }+}++#undef WG_SIZE+#undef INPUT_AT+#undef OUTPUT_AT+#undef WEIGHTS_ATdiff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/convolution/convolution_kernel_1d_small_ic_gemm.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/convolution/convolution_kernel_1d_small_ic_gemm.cppnew file mode 100644index 00000000000..97516427a07--- /dev/null+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/convolution/convolution_kernel_1d_small_ic_gemm.cpp@@ -0,0 +1,227 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "convolution_kernel_1d_small_ic_gemm.h"+#include "kernel_selector_utils.h"+#include "common_tools.h"+#include <algorithm>+#include <string>+#include <vector>++namespace kernel_selector {+namespace {++// Tile shape of the implicit GEMM. A lane owns n_per_lane output columns, so one+// SLM read of A feeds n_per_lane FMAs. n_per_lane is 2, not 4: TILE_N=64 covers+// fewer shapes on the B_IN_BOUNDS path and doubles the accumulator.+constexpr size_t simd = 16;+constexpr size_t n_per_lane = 2;+constexpr size_t tile_m = 16;+constexpr size_t tile_n = simd * n_per_lane;+constexpr size_t tile_k = 32;++// SLM per work-group: the A staging buffer only, B stays in registers. 4 bytes+// because the accumulator is fp32 for every dtype (see GetJitConstants).+constexpr size_t slm_bytes_per_wg = tile_m * tile_k * 4;++// Width of the vector load used to stage B. OpenCL only defines vloadN for N in+// {2,3,4,8,16}.+constexpr size_t b_vec = 8;+static_assert(tile_k % b_vec == 0, "B_VEC must divide TILE_K");++} // namespace++ParamsKey ConvolutionKernel_1d_small_ic_gemm::GetSupportedKey() const {+ ParamsKey k;+ k.EnableInputDataType(Datatype::F16);+ k.EnableInputDataType(Datatype::F32);+ k.EnableInputDataType(Datatype::INT8);+ k.EnableInputDataType(Datatype::UINT8);++ k.EnableOutputDataType(Datatype::F16);+ k.EnableOutputDataType(Datatype::F32);+ k.EnableOutputDataType(Datatype::INT8);+ k.EnableOutputDataType(Datatype::UINT8);++ k.EnableInputWeightsType(WeightsType::F16);+ k.EnableInputWeightsType(WeightsType::F32);+ k.EnableInputWeightsType(WeightsType::INT8);+ k.EnableInputWeightsType(WeightsType::UINT8);++ k.EnableDifferentTypes();+ k.EnableDifferentInputWeightsTypes();++ k.EnableInputLayout(DataLayout::bfyx);+ k.EnableOutputLayout(DataLayout::bfyx);++ k.EnableTensorOffset();+ k.EnableTensorPitches();+ k.EnableDilation();+ k.EnableBiasPerFeature();+ k.EnableNonBiasTerm();+ k.EnableBatching();++ k.EnableQuantization(QuantizationType::SYMMETRIC);+ k.EnableQuantization(QuantizationType::ASYMMETRIC_DATA);+ k.EnableQuantization(QuantizationType::ASYMMETRIC_WEIGHTS);+ k.EnableQuantization(QuantizationType::ASYMMETRIC_DATA_AND_WEIGHTS);++ // Deliberately no EnableDynamicShapesSupport(): see Validate().+ return k;+}++DeviceFeaturesKey ConvolutionKernel_1d_small_ic_gemm::get_required_device_features_key(const Params& params) const {+ return get_common_subgroups_device_features_key(params);+}++WeightsLayout ConvolutionKernel_1d_small_ic_gemm::GetPreferredWeightsLayout(const convolution_params&) const {+ // Already contiguous as [OC][IC * filter length], i.e. the A matrix, so no+ // weights reorder is needed.+ return WeightsLayout::oiyx;+}++bool ConvolutionKernel_1d_small_ic_gemm::Validate(const Params& p) const {+ if (!Parent::Validate(p)) {+ DO_NOT_USE_THIS_KERNEL(p.layerID);+ }++ const auto& params = static_cast<const convolution_params&>(p);++ // Static shapes only: the shape is folded into the jit constants below.+ if (params.is_shape_agnostic || params.has_dynamic_tensors()) {+ DO_NOT_USE_THIS_KERNEL(p.layerID);+ }++ if (params.groups != 1 || params.transposed || params.deformable_mode) {+ DO_NOT_USE_THIS_KERNEL(p.layerID);+ }++ const auto& in = params.inputs[0];+ const auto& out = params.outputs[0];++ if (in.Feature().v > max_input_features) {+ DO_NOT_USE_THIS_KERNEL(p.layerID);+ }++ if (get_filter_len(params) < min_filter_len) {+ DO_NOT_USE_THIS_KERNEL(p.layerID);+ }++ // 1D only: the kernel indexes every tensor through a single LONG_AXIS_IS_X+ // switch, so all axes but the long one must be degenerate and unpadded.+ // padding_end is not checked - the XY swap leaves it referring to the other axis+ // (see convolution_impl::get_kernel_params) and this kernel never reads it.+ const bool long_x = long_axis_is_x(params);+ const size_t short_filter = long_x ? params.filterSize.y : params.filterSize.x;+ const size_t short_in = long_x ? in.Y().v : in.X().v;+ const size_t short_out = long_x ? out.Y().v : out.X().v;+ const size_t short_pad_begin = long_x ? params.padding_begin.y : params.padding_begin.x;++ const bool is_1d = short_filter == 1 && short_in == 1 && short_out == 1 && short_pad_begin == 0 &&+ params.filterSize.z == 1 && in.Z().v == 1 && out.Z().v == 1;+ if (!is_1d) {+ DO_NOT_USE_THIS_KERNEL(p.layerID);+ }++ // The staging buffers must fit in the device's SLM budget.+ if (slm_bytes_per_wg > params.engineInfo.maxLocalMemSize) {+ DO_NOT_USE_THIS_KERNEL(p.layerID);+ }++ if (!IsSIMDSizeSupported(params.engineInfo, simd)) {+ DO_NOT_USE_THIS_KERNEL(p.layerID);+ }++ return true;+}++JitConstants ConvolutionKernel_1d_small_ic_gemm::GetJitConstants(const convolution_params& params,+ const DispatchData& dispatchData) const {+ JitConstants jit = Parent::GetJitConstants(params, dispatchData);++ const auto& in = params.inputs[0];+ const auto& out = params.outputs[0];++ // Read every value off the long axis, so the XY swap does not matter.+ const bool long_x = long_axis_is_x(params);+ const size_t filter_len = get_filter_len(params);+ const size_t in_len = long_x ? in.X().v : in.Y().v;+ const size_t out_len = long_x ? out.X().v : out.Y().v;+ const size_t stride_l = long_x ? params.stride.x : params.stride.y;+ const size_t dilation_l = long_x ? params.dilation.x : params.dilation.y;+ const size_t pad_begin_l = long_x ? params.padding_begin.x : params.padding_begin.y;++ const size_t gemm_m = out.Feature().v;+ const size_t gemm_n = out.Batch().v * out_len;+ const size_t gemm_k = in.Feature().v * filter_len;++ // The unguarded vector loads for B have no per-element fallback, so every+ // position must be provably in range (no left padding, last read inside the+ // input) and a K run contiguous (dilation 1, unit pitch), with tile_k and tile_n+ // dividing the filter length and gemm_n so no tile is ragged. last_pos avoids+ // subtraction so it cannot wrap.+ const size_t last_pos = (out_len - 1) * stride_l + (filter_len - 1) * dilation_l;+ const size_t long_pitch = long_x ? in.X().pitch : in.Y().pitch;+ const bool b_in_bounds = pad_begin_l == 0 && dilation_l == 1 && long_pitch == 1 && last_pos < in_len &&+ filter_len % tile_k == 0 && gemm_n % tile_n == 0 && tile_k % b_vec == 0;++ jit.AddConstants({+ MakeJitConstant("B_IN_BOUNDS", b_in_bounds),+ MakeJitConstant("B_VEC", b_vec),+ MakeJitConstant("N_PER_LANE", n_per_lane),+ MakeJitConstant("FILTER_LEN", filter_len),+ MakeJitConstant("IN_LEN", in_len),+ MakeJitConstant("OUT_LEN", out_len),+ MakeJitConstant("STRIDE_L", stride_l),+ MakeJitConstant("DILATION_L", dilation_l),+ MakeJitConstant("PAD_BEGIN_L", pad_begin_l),+ MakeJitConstant("GEMM_M", gemm_m),+ MakeJitConstant("GEMM_N", gemm_n),+ MakeJitConstant("GEMM_K", gemm_k),+ MakeJitConstant("TILE_M", tile_m),+ MakeJitConstant("TILE_N", tile_n),+ MakeJitConstant("TILE_K", tile_k),+ MakeJitConstant("SIMD", simd),+ MakeJitConstant("LONG_AXIS_IS_X", long_x),+ });++ // fp32 accumulation for every dtype, including int8, to keep one code path.+ const Datatype accumulator_dt = Datatype::F32;+ const Datatype activation_dt = Datatype::F32;++ jit.Merge(MakeTypeJitConstants(accumulator_dt, "ACCUMULATOR"));+ jit.Merge(MakeTypeJitConstants(activation_dt, "ACTIVATION"));+ jit.Merge(MakeActivationJitConstants(params.activations, activation_dt, "_TYPED"));++ return jit;+}++ConvolutionKernel_1d_small_ic_gemm::Parent::DispatchData ConvolutionKernel_1d_small_ic_gemm::SetDefault(+ const convolution_params& params,+ int autoTuneIndex) const {+ DispatchData dispatchData = Parent::SetDefault(params, autoTuneIndex);++ const auto& out = params.outputs[0];+ const size_t out_len = long_axis_is_x(params) ? out.X().v : out.Y().v;++ const size_t gemm_m = out.Feature().v;+ const size_t gemm_n = out.Batch().v * out_len;++ dispatchData.gws = {CeilDiv(gemm_n, tile_n) * simd, CeilDiv(gemm_m, tile_m), 1};+ dispatchData.lws = {simd, 1, 1};++ return dispatchData;+}++KernelsPriority ConvolutionKernel_1d_small_ic_gemm::GetKernelsPriority(const Params& /*params*/) const {+ // Must beat convolution_gpu_bfyx_os_iyx_osv16, which is picked for these shapes+ // today and reaches only a few percent of peak.+ return FORCE_PRIORITY_2;+}++KernelsData ConvolutionKernel_1d_small_ic_gemm::GetKernelsData(const Params& params) const {+ return GetTunedKernelsDataByIndex(params);+}++} // namespace kernel_selectordiff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/convolution/convolution_kernel_1d_small_ic_gemm.h b/src/plugins/intel_gpu/src/kernel_selector/kernels/convolution/convolution_kernel_1d_small_ic_gemm.hnew file mode 100644index 00000000000..a27d80b416e--- /dev/null+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/convolution/convolution_kernel_1d_small_ic_gemm.h@@ -0,0 +1,54 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "convolution_kernel_base.h"+#include <algorithm>+#include <string>+#include <vector>++namespace kernel_selector {++// Implicit-GEMM convolution for a 1D convolution with a single input feature and a+// large filter, e.g. IC=1, filter length 2048, OC=1025. IC and the filter are+// merged into one reduction axis - M = OC, N = batch * output length,+// K = IC * filter length - so the feature dimension is not padded up to a blocked+// block size. The im2col matrix is never materialized.+class ConvolutionKernel_1d_small_ic_gemm : public ConvolutionKernelBase {+public:+ using Parent = ConvolutionKernelBase;+ ConvolutionKernel_1d_small_ic_gemm() : Parent("convolution_gpu_1d_small_ic_gemm") {}+ ~ConvolutionKernel_1d_small_ic_gemm() override = default;++ KernelsData GetKernelsData(const Params& params) const override;+ KernelsPriority GetKernelsPriority(const Params& params) const override;+ ParamsKey GetSupportedKey() const override;+ DeviceFeaturesKey get_required_device_features_key(const Params& params) const override;++ // The formulation is correct for any IC; 1 is the only value measured. Widening+ // needs a benchmark against ConvolutionKernel_bfyx_to_bfyx_f16.+ static constexpr size_t max_input_features = 1;+ // K = IC * filter length has to be large enough that loading a K tile pays off.+ static constexpr size_t min_filter_len = 256;++protected:+ WeightsLayout GetPreferredWeightsLayout(const convolution_params&) const override;+ // The tile loads handle boundaries, so the input needs no pre-padded buffer.+ bool NeedPaddedInput() const override { return false; }+ JitConstants GetJitConstants(const convolution_params& params, const DispatchData& dispatchData) const override;+ bool Validate(const Params& p) const override;+ DispatchData SetDefault(const convolution_params& arg, int autoTuneIndex = -1) const override;++ // The plugin may swap X and Y (see convolution_impl::get_kernel_params), so pick+ // the axis by filter extent rather than assuming one.+ static bool long_axis_is_x(const convolution_params& params) {+ return params.filterSize.x >= params.filterSize.y;+ }+ static size_t get_filter_len(const convolution_params& params) {+ return long_axis_is_x(params) ? params.filterSize.x : params.filterSize.y;+ }+};++} // namespace kernel_selectordiff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/convolution/convolution_kernel_selector.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/convolution/convolution_kernel_selector.cppindex 2b771276f2b..7ca8959552e 100644--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/convolution/convolution_kernel_selector.cpp+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/convolution/convolution_kernel_selector.cpp@@ -6,6 +6,7 @@#include "convolution_kernel_ref.h"#include "convolution_kernel_bfyx_1x1_opt.h"#include "convolution_kernel_bfyx_gemm_like.h"+#include "convolution_kernel_1d_small_ic_gemm.h"#include "convolution_kernel_bfyx_direct_10_12_16.h"#include "convolution_kernel_bfyx_os_iyx_osv16.h"#include "convolution_kernel_bfyx_os_iyx_osv32.h"@@ -76,6 +77,7 @@ convolution_kernel_selector::convolution_kernel_selector() {// bfyx fpAttach<convolution_kernel_bfyx_1x1_opt>();+ Attach<ConvolutionKernel_1d_small_ic_gemm>();Attach<ConvolutionKernel_bfyx_GEMMLike>();Attach<ConvolutionKernel_bfyx_Direct_10_10_12>();Attach<ConvolutionKernel_bfyx_os_iyx_osv16>();diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/convolution_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/convolution_gpu_test.cppindex 667c0ab2018..f3f642e3654 100644--- a/src/plugins/intel_gpu/tests/unit/test_cases/convolution_gpu_test.cpp+++ b/src/plugins/intel_gpu/tests/unit/test_cases/convolution_gpu_test.cpp@@ -13299,3 +13299,175 @@ TEST(convolution_gpu_bfyx_f16, dynamic_fused_input_scalar_and_non_scalar_fp32) {ASSERT_NE(std::find(conv_info->c_fused_ids.begin(), conv_info->c_fused_ids.end(), "add"), conv_info->c_fused_ids.end());ASSERT_NE(conv_info->kernel_id.find("convolution_gpu_bfyx_f16_1x1"), std::string::npos);}++// ---------------------------------------------------------------------------+// convolution_gpu_1d_small_ic_gemm+// Each case runs the same topology twice - once forced onto this kernel, once onto+// convolution_gpu_ref - and compares, so no reference values live here.+// ---------------------------------------------------------------------------++// Laid out as bfyx with the long axis on Y (x == 1), as the plugin canonicalizes 3D conv.+struct conv_1d_case {+ const char* name;+ data_types dt; // input dtype; weights are i8 when this is u8/i8+ size_t batch;+ size_t in_features;+ size_t in_length;+ size_t out_features;+ size_t filter_len;+ size_t stride;+ size_t dilation;+ size_t pad_begin;+ size_t pad_end;+ bool with_bias;+ bool with_zp; // int8 only: asymmetric data and weights zero points+};++static bool conv_1d_is_int8(data_types dt) { return dt == data_types::u8 || dt == data_types::i8; }++template <typename T>+static void conv_1d_set(memory::ptr mem, const std::vector<float>& src) {+ std::vector<T> dst(src.size());+ std::transform(src.begin(), src.end(), dst.begin(), [](float v) { return static_cast<T>(v); });+ set_values(mem, dst);+}++static void conv_1d_set_values(memory::ptr mem, const std::vector<float>& src) {+ const auto dt = mem->get_layout().data_type;+ if (dt == data_types::f32) conv_1d_set<float>(mem, src);+ else if (dt == data_types::f16) conv_1d_set<ov::float16>(mem, src);+ else if (dt == data_types::u8) conv_1d_set<uint8_t>(mem, src);+ else conv_1d_set<int8_t>(mem, src);+}++// Runs the case with dt for input and weights, forced onto forced_kernel. Seeded from+// the case name, so two calls for one case see identical data.+static std::vector<float> run_conv_1d(const conv_1d_case& c, data_types dt, const char* forced_kernel) {+ auto& engine = get_test_engine();+ tests::random_generator rg(std::string(c.name));++ const bool int8 = conv_1d_is_int8(dt);+ const int lo = (dt == data_types::u8) ? 0 : -8;+ // Multiples of 1/8 in [-1, 1]: exact in f16 and their products exact in f32, so an+ // f32 accumulation over K is exact. int8 values are integers, exact either way.+ auto gen = [&](size_t n, int int_lo, int int_hi) {+ if (!int8)+ return rg.generate_random_1d<float>(n, -1, 1, 8);+ const auto v = rg.generate_random_1d<int>(n, int_lo, int_hi, 1);+ return std::vector<float>(v.begin(), v.end());+ };+ auto i32 = [](size_t v) { return static_cast<int32_t>(v); };+ auto make_layout = [&](data_types t, size_t b, size_t f, size_t y) {+ return layout{t, format::bfyx, tensor(i32(b), i32(f), 1, i32(y))};+ };+ auto add_data = [&](topology& t, const std::string& id, const layout& l, const std::vector<float>& v) {+ auto mem = engine.allocate_memory(l);+ conv_1d_set_values(mem, v);+ t.add(data(id, mem));+ };++ auto input_mem = engine.allocate_memory(make_layout(dt, c.batch, c.in_features, c.in_length));+ conv_1d_set_values(input_mem, gen(c.batch * c.in_features * c.in_length, lo, (dt == data_types::u8) ? 15 : 7));+ topology topo;+ topo.add(input_layout("input", input_mem->get_layout()));+ add_data(topo, "weights", make_layout(int8 ? data_types::i8 : dt, c.out_features, c.in_features, c.filter_len),+ gen(c.out_features * c.in_features * c.filter_len, -4, 4));+ std::string bias_id, a_zp_id, w_zp_id;+ if (c.with_bias) {+ bias_id = "bias";+ add_data(topo, bias_id, make_layout(int8 ? data_types::f32 : dt, 1, c.out_features, 1),+ gen(c.out_features, -8, 8));+ }+ if (c.with_zp) {+ a_zp_id = "a_zp";+ add_data(topo, a_zp_id, make_layout(dt, 1, c.in_features, 1), gen(c.in_features, lo, lo + 4));+ w_zp_id = "w_zp";+ add_data(topo, w_zp_id, make_layout(data_types::i8, c.out_features, 1, 1), gen(c.out_features, -2, 2));+ }+ const ov::Strides stride{c.stride, 1}, dilation{c.dilation, 1};+ const ov::CoordinateDiff pad_begin{static_cast<std::ptrdiff_t>(c.pad_begin), 0},+ pad_end{static_cast<std::ptrdiff_t>(c.pad_end), 0};+ if (int8) {+ topo.add(convolution("conv", input_info("input"), "weights", bias_id, w_zp_id, a_zp_id, "", 1, stride,+ dilation, pad_begin, pad_end, false, data_types::f32));+ } else {+ topo.add(convolution("conv", input_info("input"), "weights", bias_id, 1, stride, dilation, pad_begin,+ pad_end, false));+ }+ topo.add(reorder("out", input_info("conv"), format::bfyx, data_types::f32));++ ov::intel_gpu::ImplementationDesc conv_impl = {format::bfyx, forced_kernel, impl_types::ocl};+ ExecutionConfig config = get_test_default_config(engine);+ config.set_property(ov::intel_gpu::force_implementations(ov::intel_gpu::ImplForcingMap{{"conv", conv_impl}}));+ config.set_property(ov::intel_gpu::optimize_data(true));+ config.set_property(ov::intel_gpu::custom_outputs(std::vector<std::string>{"out"}));++ network net(engine, topo, config);+ net.set_input_data("input", input_mem);+ auto out_mem = net.execute().at("out").get_memory();+ cldnn::mem_lock<float, mem_lock_type::read> ptr(out_mem, get_test_stream());+ return std::vector<float>(ptr.data(), ptr.data() + ptr.size());+}++// One entry per code path, in conv_1d_case field order.+const std::vector<conv_1d_case> conv_1d_cases = {+ // Filter length at min_filter_len, OC 3 and out_length 23 below their tiles: every leftover path at once.+ {"min_filter_len", data_types::f32, 1, 1, 300, 3, 256, 2, 1, 0, 0, true, false},+ // K = 2048 at the model layer's stride, so a K tile never straddles a filter boundary.+ {"large_k", data_types::f32, 1, 1, 3742, 17, 2048, 242, 1, 0, 0, true, false},+ // OC 273 = 17 * TILE_M + 1: M ragged over many tiles.+ {"oc_leftover", data_types::f32, 1, 1, 300, 273, 256, 2, 1, 0, 0, true, false},+ // Dilation and padding on the guarded path; dilated extent 511.+ {"dilation_and_padding", data_types::f32, 2, 1, 800, 17, 256, 32, 2, 13, 5, true, false},+ // Maximum overlap, and the one stride where a dropped stride still lands in range.+ {"stride_1", data_types::f32, 2, 1, 300, 17, 256, 1, 1, 0, 0, true, false},+ // Unguarded vector loads: no padding, dilation 1, TILE_K | filter_len, TILE_N | batch * out_length (2 * 32).+ {"fast", data_types::f32, 2, 1, 318, 17, 256, 2, 1, 0, 0, true, false},+ // out_length 33 vs TILE_N 32: the second tile has one valid column, so j = 0 is partially valid. No bias too.+ {"ragged_n_no_bias", data_types::f32, 1, 1, 320, 17, 256, 2, 1, 0, 0, false, false},+ // K = 2048, where an f16 accumulator would fail well outside tolerance.+ {"f16_large_k", data_types::f16, 1, 1, 3742, 17, 2048, 242, 1, 0, 0, true, false},+ // f16 on the fast path, which stages B through f16 vector loads.+ {"f16_fast", data_types::f16, 2, 1, 318, 17, 256, 2, 1, 0, 0, true, false},+ // Zero points are subtracted while staging, so the compensation term is ignored - these catch a double-count.+ {"u8_zp", data_types::u8, 2, 1, 300, 17, 256, 32, 1, 0, 0, true, true},+ {"i8_fast_zp", data_types::i8, 2, 1, 318, 17, 256, 2, 1, 0, 0, true, true},+};++class convolution_1d_small_ic_gemm : public ::testing::TestWithParam<conv_1d_case> {};++TEST_P(convolution_1d_small_ic_gemm, vs_ref_kernel) {+ const auto& c = GetParam();+ if (c.dt == data_types::f16 && !get_test_engine().get_device_info().supports_fp16) {+ GTEST_SKIP() << "The test is skipped (cl_khr_fp16 is not supported).";+ }++ // convolution_gpu_ref accumulates in the input dtype, so an f16 reference would be+ // the inaccurate side; it runs in f32, leaving only this kernel's output rounding.+ const auto ref_dt = conv_1d_is_int8(c.dt) ? c.dt : data_types::f32;+ const auto expected = run_conv_1d(c, ref_dt, "convolution_gpu_ref");+ const auto actual = run_conv_1d(c, c.dt, "convolution_gpu_1d_small_ic_gemm");++ ASSERT_EQ(expected.size(), actual.size());+ const float tolerance = (c.dt == data_types::f16) ? 5e-4f : 1e-4f;+ for (size_t i = 0; i < expected.size(); ++i) {+ ASSERT_TRUE(are_equal(expected[i], actual[i], tolerance)) << "mismatch at flat index " << i;+ }+}++INSTANTIATE_TEST_SUITE_P(convolution_gpu_1d_small_ic_gemm,+ convolution_1d_small_ic_gemm,+ ::testing::ValuesIn(conv_1d_cases),+ [](const testing::TestParamInfo<conv_1d_case>& info) {+ return std::string(info.param.name);+ });++// The IC bound is selection policy, so it lives in Validate(). Repeated as a literal+// rather than read from max_input_features, so widening it cannot pass silently.+TEST(convolution_1d_small_ic_gemm_gate, rejects_input_features_above_max) {+ conv_1d_case c = conv_1d_cases[0];+ c.in_features = 2;+ // kernel_selector throws when the forced kernel rejects the params.+ ASSERT_ANY_THROW(run_conv_1d(c, c.dt, "convolution_gpu_1d_small_ic_gemm"))+ << "kernel accepted IC = " << c.in_features;+}