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 int8 dyn-quan FC (#27027)
Min, Byungilb5a59532a8b3
diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/fully_connected_gpu_bf_tiled.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/fully_connected_gpu_bf_tiled.clindex 70c55bfb73b..ef4cc76650e 100644--- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/fully_connected_gpu_bf_tiled.cl+++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/fully_connected_gpu_bf_tiled.cl@@ -22,36 +22,47 @@#if FC_KERNEL_DYNAMIC_QUANTIZEKERNEL(quantize_input)(const __global INPUT0_TYPE* input,- __global char* quantized_input,- __global INPUT0_TYPE* de_quan_scale) {+ __global DQ_TYPE* quantized_input,+ __global INPUT0_TYPE* quan_var+) {const uint offset = get_global_id(0);const uint input_offset = offset * QUANTIZE_GROUP_SIZE;const uint quantize_block = QUANTIZE_GROUP_SIZE / 4;- half4 input_0[quantize_block];- char4 quantized_value[quantize_block];- half max[quantize_block];+ MAKE_VECTOR_TYPE(INPUT0_TYPE, INPUT_LOAD_SIZE) input_0[quantize_block];+ MAKE_VECTOR_TYPE(DQ_TYPE, INPUT_LOAD_SIZE) quantized_value[quantize_block];+ INPUT0_TYPE max[quantize_block];unroll_for (uint i = 0 ; i < quantize_block ; ++i) {input_0[i] = vload4(0, &input[input_offset + i * 4]);max[i] = fmax(fmax(fabs(input_0[i][0]), fabs(input_0[i][1])), fmax(fabs(input_0[i][2]), fabs(input_0[i][3])));}- half max_value = 0.001;- for (uint i = 0 ; i < quantize_block; i+=8) {- half temp = fmax(fmax(fmax(max[i], max[i+1]), fmax(max[i+2], max[i+3])),+ INPUT0_TYPE max_value = 0.001;+ for (uint i = 0 ; i < quantize_block ; i+=8) {+ INPUT0_TYPE temp = fmax(fmax(fmax(max[i], max[i+1]), fmax(max[i+2], max[i+3])),fmax(fmax(max[i+4], max[i+5]), fmax(max[i+6], max[i+7])));max_value = fmax(max_value, temp);}- half quan_scale = max_value / 128;-- unroll_for (uint i = 0 ; i < quantize_block ; ++i) {- quantized_value[i] = CAT(convert_, MAKE_VECTOR_TYPE(char, INPUT_LOAD_SIZE))(input_0[i] / (half4)quan_scale);+ half quan_scale = (half)max_value / 127;+ #if COMPRESSED_WEIGHTS_INT8+ half quantized_sum = 0;+ #endif+ for (uint i = 0 ; i < quantize_block ; ++i) {+ half4 buff = input_0[i] / (half4)quan_scale;+ quantized_value[i] = CAT(CAT(convert_, MAKE_VECTOR_TYPE(DQ_TYPE, INPUT_LOAD_SIZE)), _rte)(buff);+ #if COMPRESSED_WEIGHTS_INT8+ quantized_sum += (buff[0] + buff[1] + buff[2] + buff[3]);+ #endifvstore4(quantized_value[i], 0, &quantized_input[input_offset + i * 4]);}- de_quan_scale[offset] = quan_scale;+ // Pair of quantizing_scale and quantized activation_sum for each group+ quan_var[offset * 2] = quan_scale;+ #if COMPRESSED_WEIGHTS_INT8+ quan_var[(offset * 2) + 1] = quantized_sum;+ #endif}#else // !FC_KERNEL_DYNAMIC_QUANTIZE@@ -189,6 +200,7 @@ inline void FUNC(fc_bf_tiled_kernel_default)(#elseuint gid = (uint)get_group_id(0);#endif+uint sglid = (uint)get_sub_group_local_id();// Dispatch as bs_fs_bsv_fsv, where bsv = DISPATCH_BSV and fsv = DISPATCH_FSV.@@ -212,10 +224,9 @@ inline void FUNC(fc_bf_tiled_kernel_default)(ACCUMULATOR_VEC_TYPE acc[TILE_B] = { };INPUT_VEC_TYPE in_0[TILE_B] = { };-#if !USE_SLM- FILTER_VEC_TYPE wei = 0;-#endif-+ #if !USE_SLM || !COMPRESSED_WEIGHTS_INT4+ FILTER_VEC_TYPE wei = 0;+ #endif#if OUTPUT_3Duint out_b0 = out_b / OUTPUT_FEATURE_NUM;@@ -743,19 +754,31 @@ inline void FUNC(fc_bf_tiled_kernel_default)(// =====================================================================================================================================}+++// Dyc Quantize#if USE_SLM && DYNAMIC_QUANTIZE-#define PACKED_DQ_TYPE int-#define DQ_VEC_TYPE MAKE_VECTOR_TYPE(DQ_TYPE, TILE_IFM)-#define DQ_SLM_FILTER_VEC MAKE_VECTOR_TYPE(DQ_TYPE, 4)++#if COMPRESSED_WEIGHTS_INT4+ #define SLM_WEIGHT_TYPE DQ_TYPE+#else+ #define SLM_WEIGHT_TYPE FILTER_TYPE+#endif++#define PACKED_DQ_TYPE uint+#define ACCUM_DQ_TYPE int#define DQ_SLM_FILTER_PACKED_VEC MAKE_VECTOR_TYPE(FILTER_TYPE, FILTER_ACTUAL_LOAD_BLOCK_SIZE)-#define DQ_SLM_FILTER_UNPACKED_VEC MAKE_VECTOR_TYPE(DQ_TYPE, FILTER_ELEMENTS_PER_LOAD)-#define DQ_FILTER_VEC_TYPE MAKE_VECTOR_TYPE(DQ_TYPE, TILE_K_OFM)+#define SLM_WEIGHT_VEC MAKE_VECTOR_TYPE(SLM_WEIGHT_TYPE, INPUT_LOAD_SIZE)+#define SLM_WEIGHT_UNPACKED_VEC MAKE_VECTOR_TYPE(SLM_WEIGHT_TYPE, FILTER_ELEMENTS_PER_LOAD)+#define WEIGHT_VEC_TYPE MAKE_VECTOR_TYPE(SLM_WEIGHT_TYPE, TILE_K_OFM)+#define MAKE_DQ_TYPE_VEC(x) MAKE_VECTOR_TYPE(DQ_TYPE, x)#define TO_DQ_TYPE(x) CAT(CAT(convert_, DQ_TYPE),_sat)(x)#define TO_DQ_VEC_TYPE(x) CAT(convert_, DQ_VEC_TYPE)(x)-#define TO_DQ_SLM_FILTER_UNPACKED_VEC(x) CAT(convert_, DQ_SLM_FILTER_UNPACKED_VEC)(x)-#define TO_DQ_FILTER_VEC_TYPE(x) CAT(convert_, DQ_FILTER_VEC_TYPE)(x)+#define TO_ACCUM_DQ_TYPE(x) CAT(convert_, ACCUM_DQ_TYPE)(x)+#define TO_SLM_WEIGHT_UNPACKED_VEC(x) CAT(convert_, SLM_WEIGHT_UNPACKED_VEC)(x)+#define TO_WEIGHT_VEC_TYPE(x) CAT(convert_, WEIGHT_VEC_TYPE)(x)#define AS_TYPE_N_(type, n, x) as_##type##n(x)#define AS_TYPE_N(type, n, x) AS_TYPE_N_(type, n, x)@@ -764,8 +787,8 @@ inline void FUNC(fc_bf_tiled_kernel_default)(inline void FUNC(fc_bf_tiled_kernel_dyn_quan)(OPTIONAL_SHAPE_INFO_ARGconst __global INPUT0_TYPE* input,- __global char* quantized_input,- __global INPUT0_TYPE* scale,+ __global DQ_TYPE* quantized_input,+ __global INPUT0_TYPE* quan_var, // pair of params for each quantizing group : scale, activation_sum#if DECOMPRESSION_SCALE_TERMconst __global DECOMPRESSION_SCALE_TYPE* decompression_scale,#endif@@ -774,7 +797,7 @@ inline void FUNC(fc_bf_tiled_kernel_dyn_quan)(#endif__global OUTPUT_TYPE* output,const __global FILTER_TYPE* weights- , __local int* wei_local_mem+ , __local uint* wei_local_mem#if BIAS_TERM, const __global BIAS_TYPE* biases#endif@@ -801,28 +824,32 @@ inline void FUNC(fc_bf_tiled_kernel_dyn_quan)(uint out_f = gid * (TILE_OFM * SIMD);uint out_b = LWS_BATCHES * TILE_B * (uint)get_group_id(2) + local_id * TILE_B;-#if OUTPUT_3D- uint out_b0 = out_b / OUTPUT_FEATURE_NUM;- uint out_b1 = out_b % OUTPUT_FEATURE_NUM;- uint input_offset = out_b0 * INPUT0_BATCH_PITCH + out_b1 * INPUT0_FEATURE_PITCH + INPUT0_OFFSET;-#else- uint input_offset = out_b * TILE_IN_B_PITCH + INPUT0_OFFSET;-#endif+ #if OUTPUT_3D+ uint out_b0 = out_b / OUTPUT_FEATURE_NUM;+ uint out_b1 = out_b % OUTPUT_FEATURE_NUM;+ uint input_offset = out_b0 * INPUT0_BATCH_PITCH + out_b1 * INPUT0_FEATURE_PITCH + INPUT0_OFFSET;+ #else+ uint input_offset = out_b * TILE_IN_B_PITCH + INPUT0_OFFSET;+ #endif-#if FILTER_LAYOUT_OS_IS_YX_OSV64_ISV2- const int power_of_two_for_simd = 5;- const int power_of_two_for_osv = 6;- const uint osv64_weight_base = (( (int) (out_f >> power_of_two_for_osv) ) << power_of_two_for_osv);- const uint osv_weight_stride = (INPUT_ELEMENTS_COUNT >> 1);- const uint out_f_offset = (int)((out_f >> power_of_two_for_simd) & 0x1) << power_of_two_for_simd;- // out_f(32) : 0 * osv_weight_stride + 32;- // out_f(64) : 64 * osv_weight_stride + 0;- // out_f(128) : 64 * osv_weight_stride + 32;- // ...- uint weights_offset = osv64_weight_base * osv_weight_stride + out_f_offset;-#else- uint weights_offset = out_f * (INPUT_ELEMENTS_COUNT / 2);-#endif+ #if COMPRESSED_WEIGHTS_INT4+ #if FILTER_LAYOUT_OS_IS_YX_OSV64_ISV2+ const int power_of_two_for_simd = 5;+ const int power_of_two_for_osv = 6;+ const uint osv64_weight_base = (( (int) (out_f >> power_of_two_for_osv) ) << power_of_two_for_osv);+ const uint osv_weight_stride = (INPUT_ELEMENTS_COUNT >> 1);+ const uint out_f_offset = (int)((out_f >> power_of_two_for_simd) & 0x1) << power_of_two_for_simd;+ // out_f(32) : 0 * osv_weight_stride + 32;+ // out_f(64) : 64 * osv_weight_stride + 0;+ // out_f(128) : 64 * osv_weight_stride + 32;+ // ...+ uint weights_offset = osv64_weight_base * osv_weight_stride + out_f_offset;+ #else+ uint weights_offset = out_f * (INPUT_ELEMENTS_COUNT / 2);+ #endif+ #else+ uint weights_offset = out_f * INPUT_ELEMENTS_COUNT;+ #endifACCUMULATOR_VEC_TYPE acc[TILE_B] = { };@@ -831,38 +858,42 @@ inline void FUNC(fc_bf_tiled_kernel_dyn_quan)(PACKED_DQ_TYPE packed_in_0[HALF_TILE_B] = { }; // Packing char4 inputs to 1 integerINPUT0_TYPE de_quantize_scale[TILE_B];-#if COMPRESSED_WEIGHTS && DECOMPRESSION_SCALE_GROUPS_NUM == 1- #if DECOMPRESSION_SCALE_LENGTH > 1 && DECOMPRESSION_SCALE_LENGTH % (TILE_OFM * SIMD) == 0- ACCUMULATOR_VEC_TYPE d_scale = TO_ACCUMULATOR_VEC_TYPE(BLOCK_READN(DECOMPRESSION_SCALE_TYPE, TILE_OFM, decompression_scale, out_f));- #elif DECOMPRESSION_SCALE_LENGTH > 1 && DECOMPRESSION_SCALE_LENGTH % (TILE_OFM * SIMD) != 0- ACCUMULATOR_VEC_TYPE d_scale = 0;- unroll_for(uint of = 0; of < TILE_OFM; ++of) {- uint offset = out_f + of*SIMD + get_sub_group_local_id();- if (offset < DECOMPRESSION_SCALE_LENGTH)- ((ACCUMULATOR_TYPE*)(&d_scale))[of] = decompression_scale[offset];- }- #else- ACCUMULATOR_VEC_TYPE d_scale = decompression_scale[0];+ #if COMPRESSED_WEIGHTS_INT8+ INPUT0_TYPE activation_sum[TILE_B] = { };#endif- ACCUMULATOR_TYPE* d_scales = (ACCUMULATOR_TYPE*)(&d_scale);-#endif+ #if COMPRESSED_WEIGHTS && DECOMPRESSION_SCALE_GROUPS_NUM == 1+ #if DECOMPRESSION_SCALE_LENGTH > 1 && DECOMPRESSION_SCALE_LENGTH % (TILE_OFM * SIMD) == 0+ ACCUMULATOR_VEC_TYPE d_scale = TO_ACCUMULATOR_VEC_TYPE(BLOCK_READN(DECOMPRESSION_SCALE_TYPE, TILE_OFM, decompression_scale, out_f));+ #elif DECOMPRESSION_SCALE_LENGTH > 1 && DECOMPRESSION_SCALE_LENGTH % (TILE_OFM * SIMD) != 0+ ACCUMULATOR_VEC_TYPE d_scale = 0;+ unroll_for(uint of = 0; of < TILE_OFM; ++of) {+ uint offset = out_f + of*SIMD + get_sub_group_local_id();+ if (offset < DECOMPRESSION_SCALE_LENGTH)+ ((ACCUMULATOR_TYPE*)(&d_scale))[of] = decompression_scale[offset];+ }+ #else+ ACCUMULATOR_VEC_TYPE d_scale = decompression_scale[0];+ #endif-#if COMPRESSED_WEIGHTS && DECOMPRESSION_ZP_TERM && DECOMPRESSION_ZP_GROUPS_NUM == 1 && !DECOMPRESSION_ZP_SCALAR- #if DECOMPRESSION_ZP_LENGTH > 1 && DECOMPRESSION_ZP_LENGTH % (TILE_OFM * SIMD) == 0- ACCUMULATOR_VEC_TYPE d_zp = TO_ACCUMULATOR_VEC_TYPE(BLOCK_READN(DECOMPRESSION_ZP_TYPE, TILE_OFM, decompression_zp, out_f));- #elif DECOMPRESSION_ZP_LENGTH > 1 && DECOMPRESSION_ZP_LENGTH % (TILE_OFM * SIMD) != 0- ACCUMULATOR_VEC_TYPE d_zp = 0;- unroll_for(uint of = 0; of < TILE_OFM; ++of) {- uint offset = out_f + of*SIMD + get_sub_group_local_id();- if (offset < DECOMPRESSION_ZP_LENGTH)- ((ACCUMULATOR_TYPE*)(&d_zp))[of] = decompression_zp[offset];- }- #else- ACCUMULATOR_VEC_TYPE d_zp = decompression_zp[0];+ ACCUMULATOR_TYPE* d_scales = (ACCUMULATOR_TYPE*)(&d_scale);+ #endif++ #if COMPRESSED_WEIGHTS && DECOMPRESSION_ZP_TERM && DECOMPRESSION_ZP_GROUPS_NUM == 1 && !DECOMPRESSION_ZP_SCALAR+ #if DECOMPRESSION_ZP_LENGTH > 1 && DECOMPRESSION_ZP_LENGTH % (TILE_OFM * SIMD) == 0+ ACCUMULATOR_VEC_TYPE d_zp = TO_ACCUMULATOR_VEC_TYPE(BLOCK_READN(DECOMPRESSION_ZP_TYPE, TILE_OFM, decompression_zp, out_f));+ #elif DECOMPRESSION_ZP_LENGTH > 1 && DECOMPRESSION_ZP_LENGTH % (TILE_OFM * SIMD) != 0+ ACCUMULATOR_VEC_TYPE d_zp = 0;+ unroll_for(uint of = 0; of < TILE_OFM; ++of) {+ uint offset = out_f + of*SIMD + get_sub_group_local_id();+ if (offset < DECOMPRESSION_ZP_LENGTH)+ ((ACCUMULATOR_TYPE*)(&d_zp))[of] = decompression_zp[offset];+ }+ #else+ ACCUMULATOR_VEC_TYPE d_zp = decompression_zp[0];+ #endif+ ACCUMULATOR_TYPE* d_zps = (ACCUMULATOR_TYPE*)(&d_zp);#endif- ACCUMULATOR_TYPE* d_zps = (ACCUMULATOR_TYPE*)(&d_zp);-#endif// =====================================================================================================================================// Main computation loop@@ -871,7 +902,7 @@ inline void FUNC(fc_bf_tiled_kernel_dyn_quan)(uint idx_sglid = (sglid * TILE_K) % TILE_IFM_ELEMENTS_SIZE; // same index for sglid 0~7 : to tile_k directionuint batch_sglid = (sglid * TILE_K) / TILE_IFM_ELEMENTS_SIZE; // 0 to 1 : to batch direction- const uint scale_pitch = TILE_IN_B_PITCH / QUANTIZE_GROUP_SIZE;+ const uint scale_pitch = (TILE_IN_B_PITCH / QUANTIZE_GROUP_SIZE);MAKE_VECTOR_TYPE(int, TILE_B) acc_tmp[TILE_OFM] = { };__attribute__((opencl_unroll_hint(1)))for (uint ni = 0; ni < iterations; ++ni) {@@ -881,14 +912,20 @@ inline void FUNC(fc_bf_tiled_kernel_dyn_quan)(// Load quantizing info from pre-quantizing kerneltiled_input_0[bi] = vload4(0, &quantized_input[in_offset]);// Packing : Get 4(B)x4(K) integer vector (packing to 4x1 vector)- packed_in_0[bi] = as_int(tiled_input_0[bi]);+ packed_in_0[bi] = as_uint(tiled_input_0[bi]);// Next batchin_offset += (TILE_IN_B_PITCH * 2);#if NUM_LOOP_IN_DYN_QUAN_GROUP == 1- de_quantize_scale[bi * 2] = scale[scale_offset];- de_quantize_scale[bi * 2 + 1] = scale[scale_offset+ scale_pitch];+ de_quantize_scale[bi * 2] = quan_var[scale_offset * 2];+ de_quantize_scale[bi * 2 + 1] = quan_var[scale_offset * 2 + scale_pitch * 2];+ #if COMPRESSED_WEIGHTS_INT8+ // Need additional accumulation of quantized activation along the dyn-quan group+ // to use i8 multiplier for int8 weight+ activation_sum[bi * 2] = quan_var[scale_offset * 2 + 1];+ activation_sum[bi * 2 + 1] = quan_var[scale_offset * 2 + 1 + scale_pitch * 2];+ #endifscale_offset += (scale_pitch * 2);#endif}@@ -896,7 +933,10 @@ inline void FUNC(fc_bf_tiled_kernel_dyn_quan)(#if NUM_LOOP_IN_DYN_QUAN_GROUP > 1if (ni % NUM_LOOP_IN_DYN_QUAN_GROUP == 0) {unroll_for (uint bi = 0; bi < TILE_B; ++bi) {- de_quantize_scale[bi] = scale[scale_offset];+ de_quantize_scale[bi] = quan_var[scale_offset * 2];+ #if COMPRESSED_WEIGHTS_INT8+ activation_sum[bi] = quan_var[scale_offset * 2 + 1];+ #endifscale_offset += scale_pitch;}}@@ -916,49 +956,64 @@ inline void FUNC(fc_bf_tiled_kernel_dyn_quan)(barrier(CLK_LOCAL_MEM_FENCE);#endif- __local int* char_slm_weight = (__local int*)wei_local_mem;+ __local uint* char_slm_weight = (__local uint*)wei_local_mem;- #if FILTER_LAYOUT_OS_IS_YX_OSV64_ISV2- uint weights_idx = weights_offset + local_id * SIMD * FILTER_LOAD_ITERS * FILTER_LOAD_BLOCK_SIZE * 2;+ #if COMPRESSED_WEIGHTS_INT4+ #if FILTER_LAYOUT_OS_IS_YX_OSV64_ISV2+ uint weights_idx = weights_offset + local_id * SIMD * FILTER_LOAD_ITERS * FILTER_LOAD_BLOCK_SIZE * 2;+ #else+ uint weights_idx = weights_offset + local_id * SIMD * FILTER_LOAD_ITERS * FILTER_ACTUAL_LOAD_BLOCK_SIZE;+ #endif#else- uint weights_idx = weights_offset + local_id * SIMD * FILTER_LOAD_ITERS * FILTER_ACTUAL_LOAD_BLOCK_SIZE;+ uint weights_idx = weights_offset + local_id * SIMD * FILTER_LOAD_ITERS * TILE_K_OFM_PACKED;#endifuint wei_local_idx = local_id * SIMD * FILTER_LOAD_ITERS * (FILTER_LOAD_BLOCK_SIZE/2) + sglid * 2;- // DECOMPRESSION_SCALE_POST_OP SHOULD be enabled for dynamic quantize FC : scale is ACCUMULATOR_VAL_ONE+ #if COMPRESSED_WEIGHTS_INT8+ ACCUMULATOR_TYPE wei_zp[TILE_OFM] = { };+ #endif++ // DQ_DECOMPRESSION_SCALE_POST_OP SHOULD be enabled for dynamic quantize FC : scale is ACCUMULATOR_VAL_ONEunroll_for(uint load_iter = 0; load_iter < FILTER_LOAD_ITERS; ++load_iter) {- #if FILTER_LAYOUT_OS_IYX_OSV16- SLM_FILTER_PACKED_VEC wei_packed0 = BLOCK_READN(FILTER_TYPE, FILTER_ACTUAL_LOAD_BLOCK_SIZE, weights, weights_idx);- SLM_FILTER_PACKED_VEC wei_packed1 = BLOCK_READN(FILTER_TYPE, FILTER_ACTUAL_LOAD_BLOCK_SIZE, weights, (weights_idx + ((IFM_SIZE / 2) * 16)));- DQ_SLM_FILTER_UNPACKED_VEC dq_wei_unpacked;- // loaded weights 'wei_packed' of os_iyx_osv16 format have continuous values along TILE_K. So no need to transpose while unpacking- dq_wei_unpacked.s0123 = UNPACK_INT4(DQ_TYPE, *((INT4_PACKED_TYPE_PRELOAD*)&wei_packed0));- dq_wei_unpacked.s4567 = UNPACK_INT4(DQ_TYPE, *((INT4_PACKED_TYPE_PRELOAD*)&wei_packed1));- #elif FILTER_LAYOUT_OS_IS_YX_OSV64_ISV2- SLM_FILTER_PACKED_VEC wei_packed0 = BLOCK_READN(FILTER_TYPE, FILTER_ACTUAL_LOAD_BLOCK_SIZE, weights, weights_idx);- SLM_FILTER_PACKED_VEC wei_packed1 = BLOCK_READN(FILTER_TYPE, FILTER_ACTUAL_LOAD_BLOCK_SIZE, weights, (weights_idx + (FILTER_LOAD_BLOCK_SIZE * SIMD)));- DQ_SLM_FILTER_UNPACKED_VEC dq_wei_unpacked;- DQ_SLM_FILTER_UNPACKED_VEC dq_wei_unpacked_tmp;- dq_wei_unpacked_tmp.s0123 = UNPACK_INT4(DQ_TYPE, *((INT4_PACKED_TYPE_PRELOAD*)&wei_packed0));- dq_wei_unpacked_tmp.s4567 = UNPACK_INT4(DQ_TYPE, *((INT4_PACKED_TYPE_PRELOAD*)&wei_packed1));- dq_wei_unpacked.s01 = dq_wei_unpacked_tmp.s01;- dq_wei_unpacked.s23 = dq_wei_unpacked_tmp.s45;- dq_wei_unpacked.s45 = dq_wei_unpacked_tmp.s23;- dq_wei_unpacked.s67 = dq_wei_unpacked_tmp.s67;- #else- SLM_FILTER_PACKED_VEC wei_packed = BLOCK_READN(FILTER_TYPE, FILTER_LOAD_BLOCK_SIZE, weights, weights_idx);- DQ_SLM_FILTER_UNPACKED_VEC dq_wei_unpacked = UNPACK_TRANSPOSED_INT4(DQ_TYPE, *((INT4_PACKED_TYPE_PRELOAD *)&wei_packed));+ #if COMPRESSED_WEIGHTS_INT4+ #if FILTER_LAYOUT_OS_IYX_OSV16+ SLM_FILTER_PACKED_VEC wei_packed0 = BLOCK_READN(FILTER_TYPE, FILTER_ACTUAL_LOAD_BLOCK_SIZE, weights, weights_idx);+ SLM_FILTER_PACKED_VEC wei_packed1 = BLOCK_READN(FILTER_TYPE, FILTER_ACTUAL_LOAD_BLOCK_SIZE, weights, (weights_idx + ((IFM_SIZE / 2) * 16)));+ SLM_WEIGHT_UNPACKED_VEC dq_wei_unpacked;+ // loaded weights 'wei_packed' of os_iyx_osv16 format have continuous values along TILE_K. So no need to transpose while unpacking+ dq_wei_unpacked.s0123 = (UNPACK_INT4(DQ_TYPE, *((INT4_PACKED_TYPE_PRELOAD*)&wei_packed0)));+ dq_wei_unpacked.s4567 = (UNPACK_INT4(DQ_TYPE, *((INT4_PACKED_TYPE_PRELOAD*)&wei_packed1)));+ #elif FILTER_LAYOUT_OS_IS_YX_OSV64_ISV2+ SLM_FILTER_PACKED_VEC wei_packed0 = BLOCK_READN(FILTER_TYPE, FILTER_ACTUAL_LOAD_BLOCK_SIZE, weights, weights_idx);+ SLM_FILTER_PACKED_VEC wei_packed1 = BLOCK_READN(FILTER_TYPE, FILTER_ACTUAL_LOAD_BLOCK_SIZE, weights, (weights_idx + (FILTER_LOAD_BLOCK_SIZE * SIMD)));+ SLM_WEIGHT_UNPACKED_VEC dq_wei_unpacked;+ SLM_WEIGHT_UNPACKED_VEC dq_wei_unpacked_tmp;+ dq_wei_unpacked_tmp.s0123 = (UNPACK_INT4(DQ_TYPE, *((INT4_PACKED_TYPE_PRELOAD*)&wei_packed0)));+ dq_wei_unpacked_tmp.s4567 = (UNPACK_INT4(DQ_TYPE, *((INT4_PACKED_TYPE_PRELOAD*)&wei_packed1)));+ dq_wei_unpacked.s01 = dq_wei_unpacked_tmp.s01;+ dq_wei_unpacked.s23 = dq_wei_unpacked_tmp.s45;+ dq_wei_unpacked.s45 = dq_wei_unpacked_tmp.s23;+ dq_wei_unpacked.s67 = dq_wei_unpacked_tmp.s67;+ #else+ SLM_FILTER_PACKED_VEC wei_packed = BLOCK_READN(FILTER_TYPE, FILTER_LOAD_BLOCK_SIZE, weights, weights_idx);+ SLM_WEIGHT_UNPACKED_VEC dq_wei_unpacked = (UNPACK_TRANSPOSED_INT4(DQ_TYPE, *((INT4_PACKED_TYPE_PRELOAD *)&wei_packed)));+ #endif+ #else // COMPRESSED_WEIGHTS_INT8+ SLM_WEIGHT_UNPACKED_VEC dq_wei_unpacked;+ WEIGHT_VEC_TYPE wei_packed = TO_WEIGHT_VEC_TYPE(FILTER_BLOCK_READ(weights, weights_idx));+ dq_wei_unpacked.s0123 = wei_packed.s0246;+ dq_wei_unpacked.s4567 = wei_packed.s1357;#endif- // Calculate zero-point and scale only for DECOMPRESSION_SCALE_POST_OP enabled+ // Calculate zero-point and scale only for DQ_DECOMPRESSION_SCALE_POST_OP enabled// Calculate weight : w = (w - dzp) * ds// if DECOMPRESSION_ZP_TERM is not enabled, then dzp is ACCUMULATOR_VAL_ZERO.- #if DECOMPRESSION_ZP_TERM+ #if DECOMPRESSION_ZP_TERM && !COMPRESSED_WEIGHTS_INT8#if DECOMPRESSION_ZP_SCALAR- DQ_SLM_FILTER_UNPACKED_VEC dzp = (DQ_SLM_FILTER_UNPACKED_VEC)(DECOMPRESSION_ZP_VALUE);+ SLM_WEIGHT_UNPACKED_VEC dzp = (SLM_WEIGHT_UNPACKED_VEC)(DECOMPRESSION_ZP_VALUE);dq_wei_unpacked -= dzp;#elif DECOMPRESSION_ZP_GROUPS_NUM > 1- DQ_TYPE* w = (DQ_TYPE*)(&dq_wei_unpacked);+ SLM_WEIGHT_TYPE* w = (SLM_WEIGHT_TYPE*)(&dq_wei_unpacked);const uint ni_offset = ni * TILE_IFM * SIMD + local_id * FILTER_LOAD_ITERS * FILTER_LOAD_BLOCK_SIZE;unroll_for(uint fi = 0; fi < TILE_OFM; ++fi) {const uint offset_ofm = out_f + fi*SIMD + sglid;@@ -966,11 +1021,11 @@ inline void FUNC(fc_bf_tiled_kernel_dyn_quan)(const uint offset_ifm = ni_offset + load_iter * FILTER_LOAD_BLOCK_SIZE + kii;const uint zp_offset = (offset_ofm % DECOMPRESSION_ZP_BATCH_NUM) * DECOMPRESSION_ZP_BATCH_PITCH +(offset_ifm / DECOMPRESSION_ZP_GROUP_SIZE) * DECOMPRESSION_ZP_FEATURE_PITCH;- w[W_DYN_QUAN_IDX] = w[W_DYN_QUAN_IDX] - TO_DQ_TYPE(decompression_zp[zp_offset]);+ w[W_DYN_QUAN_IDX] = w[W_DYN_QUAN_IDX] - CAT(CAT(convert_, SLM_WEIGHT_TYPE),_rte)(decompression_zp[zp_offset]);}}#else- DQ_TYPE* w = (DQ_TYPE*)(&dq_wei_unpacked);+ SLM_WEIGHT_TYPE* w = (SLM_WEIGHT_TYPE*)(&dq_wei_unpacked);unroll_for(uint fi = 0; fi < TILE_OFM; ++fi) {unroll_for(uint kii = 0; kii < FILTER_LOAD_BLOCK_SIZE; ++kii) {w[W_DYN_QUAN_IDX] = w[W_DYN_QUAN_IDX] - d_zps[fi % DECOMPRESSION_ZP_LENGTH];@@ -979,29 +1034,58 @@ inline void FUNC(fc_bf_tiled_kernel_dyn_quan)(#endif#endif+ #if COMPRESSED_WEIGHTS_INT8+ unroll_for(uint fi = 0; fi < TILE_OFM; ++fi) {+ #if DECOMPRESSION_ZP_TERM+ #if DECOMPRESSION_ZP_SCALAR+ wei_zp[fi] = (TO_ACCUMULATOR_TYPE)(DECOMPRESSION_ZP_VALUE);+ #elif DECOMPRESSION_ZP_GROUPS_NUM > 1+ #if FILTER_LOAD_BLOCK_SIZE % DECOMPRESSION_ZP_GROUP_SIZE != 0+ #error "FC bf_tiled kernel: Not support DECOMPRESSION_ZP_GROUPS_NUM > 1"+ #endif++ const uint ni_offset = ni * TILE_IFM * SIMD + local_id * FILTER_LOAD_ITERS * FILTER_LOAD_BLOCK_SIZE;+ const uint offset_ofm = out_f + fi*SIMD + sglid;+ const uint offset_ifm = ni_offset + load_iter * FILTER_LOAD_BLOCK_SIZE;+ const uint zp_offset = (offset_ofm % DECOMPRESSION_ZP_BATCH_NUM) * DECOMPRESSION_ZP_BATCH_PITCH ++ (offset_ifm / DECOMPRESSION_ZP_GROUP_SIZE) * DECOMPRESSION_ZP_FEATURE_PITCH;+ wei_zp[fi] = TO_ACCUMULATOR_TYPE(decompression_zp[zp_offset]);+ #else+ wei_zp[fi] = TO_ACCUMULATOR_TYPE(d_zps[fi % DECOMPRESSION_ZP_LENGTH]);+ #endif+ #else+ wei_zp[fi] = ACCUMULATOR_VAL_ZERO;+ #endif+ }+ #endif+#if FILTER_LOAD_BLOCK_SIZE == 2- DQ_SLM_FILTER_VEC wei_1 = {dq_wei_unpacked.s01, dq_wei_unpacked.s23};- char_slm_weight[wei_local_idx] = as_int(wei_1);+ SLM_WEIGHT_VEC wei_1 = {dq_wei_unpacked.s01, dq_wei_unpacked.s23};+ char_slm_weight[wei_local_idx] = as_uint(wei_1);#elif FILTER_LOAD_BLOCK_SIZE == 4- DQ_SLM_FILTER_VEC wei_1 = {dq_wei_unpacked.s01, dq_wei_unpacked.s23};- char_slm_weight[wei_local_idx] = as_int(wei_1);- DQ_SLM_FILTER_VEC wei_2 = {dq_wei_unpacked.s45, dq_wei_unpacked.s67};- char_slm_weight[wei_local_idx+1] = as_int(wei_2);+ SLM_WEIGHT_VEC wei_1 = {dq_wei_unpacked.s01, dq_wei_unpacked.s23};+ char_slm_weight[wei_local_idx] = as_uint(wei_1);+ SLM_WEIGHT_VEC wei_2 = {dq_wei_unpacked.s45, dq_wei_unpacked.s67};+ char_slm_weight[wei_local_idx+1] = as_uint(wei_2);#elif FILTER_LOAD_BLOCK_SIZE == 8- DQ_SLM_FILTER_VEC wei_1 = {dq_wei_unpacked.s01, dq_wei_unpacked.s23};- char_slm_weight[wei_local_idx] = as_int(wei_1);- DQ_SLM_FILTER_VEC wei_2 = {dq_wei_unpacked.s45, dq_wei_unpacked.s67};- char_slm_weight[wei_local_idx+1] = as_int(wei_2);- DQ_SLM_FILTER_VEC wei_3 = {dq_wei_unpacked.s89, dq_wei_unpacked.sab};- char_slm_weight[wei_local_idx+2] = as_int(wei_3);- DQ_SLM_FILTER_VEC wei_4 = {dq_wei_unpacked.scd, dq_wei_unpacked.sef};- char_slm_weight[wei_local_idx+3] = as_int(wei_4);+ SLM_WEIGHT_VEC wei_1 = {dq_wei_unpacked.s01, dq_wei_unpacked.s23};+ char_slm_weight[wei_local_idx] = as_uint(wei_1);+ SLM_WEIGHT_VEC wei_2 = {dq_wei_unpacked.s45, dq_wei_unpacked.s67};+ char_slm_weight[wei_local_idx+1] = as_uint(wei_2);+ SLM_WEIGHT_VEC wei_3 = {dq_wei_unpacked.s89, dq_wei_unpacked.sab};+ char_slm_weight[wei_local_idx+2] = as_uint(wei_3);+ SLM_WEIGHT_VEC wei_4 = {dq_wei_unpacked.scd, dq_wei_unpacked.sef};+ char_slm_weight[wei_local_idx+3] = as_uint(wei_4);#else#error "FC bf_tiled kernel: unsupported FILTER_LOAD_BLOCK_SIZE for SLM kernel"#endifwei_local_idx += SIMD * (FILTER_LOAD_BLOCK_SIZE/2);- weights_idx += SIMD * FILTER_ACTUAL_LOAD_BLOCK_SIZE;+ #if COMPRESSED_WEIGHTS_INT8+ weights_idx += SIMD * TILE_K_OFM_PACKED;+ #else+ weights_idx += SIMD * FILTER_ACTUAL_LOAD_BLOCK_SIZE;+ #endif}wei_local_idx = sglid * 2;@@ -1014,11 +1098,11 @@ inline void FUNC(fc_bf_tiled_kernel_dyn_quan)(#endif// Compute input * weight : packed char4 type- char8 weight = vload8(0, (__local char *)(&char_slm_weight[wei_local_idx + 16*2*ki]));- char4 first_weight = weight.s0123;- char4 second_weight = weight.s4567;+ WEIGHT_VEC_TYPE weight = vload8(0, (__local SLM_WEIGHT_TYPE *)(&char_slm_weight[wei_local_idx + 16*2*ki]));+ SLM_WEIGHT_VEC first_weight = weight.s0123;+ SLM_WEIGHT_VEC second_weight = weight.s4567;unroll_for (uint bi = 0; bi < TILE_B; ++bi) {- char4 input_val = as_char4(_sub_group_shuffle(packed_in_0[bi / 2], (bi % 2) * 8 + ki));+ MAKE_DQ_TYPE_VEC(4) input_val = AS_DQ_TYPE_4(_sub_group_shuffle(packed_in_0[bi / 2], (bi % 2) * 8 + ki));acc_tmp[0][bi] = imad_SW(acc_tmp[0][bi], input_val, first_weight);acc_tmp[1][bi] = imad_SW(acc_tmp[1][bi], input_val, second_weight);}@@ -1038,7 +1122,12 @@ inline void FUNC(fc_bf_tiled_kernel_dyn_quan)(ACCUMULATOR_TYPE ds = d_scales[fi % DECOMPRESSION_SCALE_LENGTH];#endif- ((ACCUMULATOR_TYPE*)(&acc[bi]))[fi] += convert_half(((int *)(&acc_tmp[fi]))[bi]) * ds * de_quantize_scale[bi];+ #if COMPRESSED_WEIGHTS_INT8+ ACCUM_DQ_TYPE modified_calc_buff = ((int *)(&acc_tmp[fi]))[bi] - ((float)(wei_zp[fi]) * (convert_float)(activation_sum[bi]));+ ((ACCUMULATOR_TYPE*)(&acc[bi]))[fi] += (convert_half)(convert_float(modified_calc_buff) * (float)ds * (float)de_quantize_scale[bi]);+ #else+ ((ACCUMULATOR_TYPE*)(&acc[bi]))[fi] += convert_half(((int *)(&acc_tmp[fi]))[bi]) * ds * de_quantize_scale[bi];+ #endifacc_tmp[fi][bi] = 0;}}@@ -1060,7 +1149,12 @@ inline void FUNC(fc_bf_tiled_kernel_dyn_quan)(ACCUMULATOR_TYPE ds = d_scales[fi % DECOMPRESSION_SCALE_LENGTH];#endif- ((ACCUMULATOR_TYPE*)(&acc[bi]))[fi] += convert_half(((int *)(&acc_tmp[fi]))[bi]) * ds * de_quantize_scale[bi];+ #if COMPRESSED_WEIGHTS_INT8+ ACCUM_DQ_TYPE modified_calc_buff = ((int *)(&acc_tmp[fi]))[bi] - ((float)(wei_zp[fi]) * (convert_float)(activation_sum[bi]));+ ((ACCUMULATOR_TYPE*)(&acc[bi]))[fi] += (convert_half)(convert_float(modified_calc_buff) * (float)ds * (float)de_quantize_scale[bi]);+ #else+ ((ACCUMULATOR_TYPE*)(&acc[bi]))[fi] += convert_half(((int *)(&acc_tmp[fi]))[bi]) * ds * de_quantize_scale[bi];+ #endifacc_tmp[fi][bi] = 0;}}@@ -1169,13 +1263,13 @@ KERNEL(fc)(, FUSED_OPS_DECLS#endif#if DYNAMIC_QUANTIZE- , __global char* quantized_input- , __global INPUT0_TYPE* de_quan_scale+ , __global DQ_TYPE* quantized_input+ , __global INPUT0_TYPE* quan_var#endif) {#if USE_SLM#if DYNAMIC_QUANTIZE- __local int dq_wei_local_mem[SIMD * TILE_OFM * SIMD];+ __local uint dq_wei_local_mem[SIMD * TILE_OFM * SIMD];#else__local ACCUMULATOR_TYPE wei_local_mem[TILE_IFM * SIMD * TILE_OFM * SIMD];#endif@@ -1321,7 +1415,7 @@ KERNEL(fc)(OPTIONAL_SHAPE_INFO_TENSORinput,quantized_input,- de_quan_scale,+ quan_var,#if DECOMPRESSION_SCALE_TERMdecompression_scale,#endif@@ -1368,7 +1462,7 @@ KERNEL(fc)(OPTIONAL_SHAPE_INFO_TENSORinput,quantized_input,- de_quan_scale,+ quan_var,#if DECOMPRESSION_SCALE_TERMdecompression_scale,#endifdiff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/include/batch_headers/int4_utils.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/include/batch_headers/int4_utils.clindex 68d778475f5..99ff124e3a3 100644--- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/include/batch_headers/int4_utils.cl+++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/include/batch_headers/int4_utils.cl@@ -59,6 +59,13 @@ inline char4 unpack_to_char(uint4x4_t v) __attribute__((overloadable)) {return (char4)(v0.s0, v0.s1, v1.s0, v1.s1);}+inline uchar4 unpack_to_uchar(uint4x4_t v) __attribute__((overloadable)) {+ uchar2 v0 = unpack_to_uchar(v.s0);+ uchar2 v1 = unpack_to_uchar(v.s1);+ return (uchar4)(v0.s0, v0.s1, v1.s0, v1.s1);+}++inline char4 unpack_transposed_to_char(int4x4_t v) __attribute__((overloadable)) {char2 v0 = unpack_to_char(v.s0);char2 v1 = unpack_to_char(v.s1);diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/fully_connected/fully_connected_kernel_bf_tiled.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/fully_connected/fully_connected_kernel_bf_tiled.cppindex 6604def1a69..178e1ea405b 100644--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/fully_connected/fully_connected_kernel_bf_tiled.cpp+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/fully_connected/fully_connected_kernel_bf_tiled.cpp@@ -8,6 +8,7 @@#include <functional>#include "common_types.h"+static constexpr size_t lws_batches = 8;static constexpr size_t simd = 16;static constexpr size_t min_quantize_grp_size = 32;static constexpr size_t min_slm_size = 256;@@ -50,6 +51,17 @@ static std::pair<size_t, size_t> get_output_aligned_bf_size(const fully_connectereturn {output_b, output_f};}+static bool is_weight_dyn_quantizable(const fully_connected_params& params) {+ auto weight_type = params.weights.GetDType();+ if (weight_type == WeightsType::INT4 || weight_type == WeightsType::UINT4)+ return true;+ // UINT8 weight type is supported by FC dyn-quantize(with SLM).+ if (weight_type == WeightsType::UINT8)+ return true;++ return false;+}+// DYNAMIC_QUANTIZEstatic size_t get_dynamic_quantize_group_size(const fully_connected_params& params) {auto dynamic_quantization_group_size = params.dynamic_quantization_group_size;@@ -91,7 +103,7 @@ static size_t get_dynamic_quantize_group_size(const fully_connected_params& parareturn 0;}-static bool should_dynamic_quantize(const fully_connected_params& params) {+static bool should_dynamic_quantize(const fully_connected_params& params, bool print_log = false) {size_t dynamic_quantization_group_size = get_dynamic_quantize_group_size(params);if (params.inputs[0].GetFirstElementOffset() != 0)@@ -110,11 +122,17 @@ static bool should_dynamic_quantize(const fully_connected_params& params) {const size_t scale_group_size = params.weights.IFM().v / params.decompression_scale.Feature().v;if ((scale_group_size % simd == 0) && (input_f % dynamic_quantization_group_size == 0) &&(params.is_shape_agnostic || (params.inputs[0].Batch().v > 1 && input_b > min_slm_size)) &&- params.inputs[0].GetDType() == Datatype::F16 &&- (params.weights.GetDType() == WeightsType::INT4 || params.weights.GetDType() == WeightsType::UINT4)) {- GPU_DEBUG_TRACE_DETAIL << " Dynamic quantizing for FC : scale_group_size " << scale_group_size << ", Input (" <<- kernel_selector::toString(params.inputs[0].GetDType()) << ", " << kernel_selector::toString(params.outputs[0].GetLayout()) <<- ") B: " << params.inputs[0].Batch().v << ", F: " << params.inputs[0].Feature().v << ", Y: " << params.inputs[0].Y().v << std ::endl;+ params.inputs[0].GetDType() == Datatype::F16 && is_weight_dyn_quantizable(params)) {+ if (print_log) {+ GPU_DEBUG_TRACE_DETAIL << " Dynamic quantizing for FC : scale_group_size: " << scale_group_size <<+ ", Dyn-quan group size: " << dynamic_quantization_group_size <<+ ", Type(I:" << kernel_selector::toString(params.inputs[0].GetDType()) <<+ ", O:" << kernel_selector::toString(params.outputs[0].GetDType()) <<+ ", W:" << kernel_selector::toString(params.weights.GetDType()) <<+ "), Format(W:" << kernel_selector::toString(params.weights.GetLayout()) <<+ ") B: " << params.inputs[0].Batch().v << ", F: " << params.inputs[0].Feature().v <<+ ", Y: " << params.inputs[0].Y().v << std ::endl;+ }return true;}@@ -204,8 +222,9 @@ DeviceFeaturesKey FullyConnected_bf_tiled::get_required_device_features_key(cons}bool FullyConnected_bf_tiled::Validate(const Params& params) const {- if (!Parent::Validate(params))+ if (!Parent::Validate(params)) {return false;+ }auto& fc_params = static_cast<const fully_connected_params&>(params);auto& input = fc_params.inputs[0];@@ -314,21 +333,21 @@ bool TuneParamsSelector::VerifyTuneParams(const fully_connected_params& params,if (tparams.tile_ofm * simd > 64)return false;- bool is_i4_u4 = (params.weights.GetDType() == WeightsType::INT4 || params.weights.GetDType() == WeightsType::UINT4);+ bool is_dyn_quantable_type = is_weight_dyn_quantizable(params);if (tparams.kernel_type == FullyConnected_bf_tiled::KernelType::SLM) {const auto required_batch_alignment = 64;if (!params.is_shape_agnostic && (!IsAligned(output_b, required_batch_alignment) || output_b < min_slm_size))return false;const auto required_tile_b = 8;- if ((tparams.tile_b != required_tile_b) && !is_i4_u4)+ if ((tparams.tile_b != required_tile_b) && !is_dyn_quantable_type)return false;const auto required_tile_ofm = 2;if (tparams.tile_ofm != required_tile_ofm)return false;- if (params.weights.GetDType() != WeightsType::INT4 && params.weights.GetDType() != WeightsType::UINT4)+ if (!is_dyn_quantable_type)return false;if (params.engineInfo.deviceType != dev_type::integrated_gpu)@@ -340,7 +359,7 @@ bool TuneParamsSelector::VerifyTuneParams(const fully_connected_params& params,return true;}- if (params.compressed && is_i4_u4) {+ if (params.compressed && is_dyn_quantable_type) {if (!(tparams.tile_ofm == 2 || tparams.tile_ofm == 4))return false;if (tparams.tile_ofm == 4 && tparams.outer_ofm == 2 && !is_suitable_outer_ofm(params, output_f))@@ -382,11 +401,10 @@ FullyConnected_bf_tiled::GetAutoTuneParams(const fully_connected_params& params,while (max_tile_ofm * 2 * simd <= output_f && max_tile_ofm < 4)max_tile_ofm *= 2;- if (params.weights.GetDType() == WeightsType::UINT4 || params.weights.GetDType() == WeightsType::INT4) {+ if (params.weights.GetDType() == WeightsType::UINT4 || params.weights.GetDType() == WeightsType::INT4 ||+ (is_weight_dyn_quantizable(params) && should_dynamic_quantize(params))) {+ // Only 4bit weight type is fully optimized to use SLM. In default kernel, SLM is not applied to 8bit weight.if (!params.is_shape_agnostic && batch == 1) {- if (should_dynamic_quantize(params))- return selector.Default(tune_params(1, 2, 4, 2, 1, 1, 1, EXE_MODE_DEFAULT));-// Tuning for Meteor Lakeif (is_weight_vertical(params, output_f)) {if (params.weights.GetLayout() == WeightsLayout::os_is_yx_osv32_isv2) {@@ -411,9 +429,11 @@ FullyConnected_bf_tiled::GetAutoTuneParams(const fully_connected_params& params,selector.Case(tune_params(16, 2, 2, 4, 1, 1, 1, EXE_MODE_DEFAULT, KernelType::SLM)).Case(tune_params(16, 2, 1, 4, 1, 1, 1, EXE_MODE_DEFAULT, KernelType::SLM));}+selector.Case(tune_params(8, 2, 2, 4, 1, 1, 1, EXE_MODE_DEFAULT, KernelType::SLM)).Case(tune_params(8, 2, 1, 4, 1, 1, 1, EXE_MODE_DEFAULT, KernelType::SLM));}+if (params.weights.GetLayout() == WeightsLayout::os_iyx_osv16)return selector.Default(tune_params(8, 1, 1, 4, 1, 1, 1, EXE_MODE_DEFAULT));else if (params.weights.GetLayout() == WeightsLayout::os_is_yx_osv64_isv2)@@ -501,7 +521,6 @@ FullyConnected_bf_tiled::SetDefault(const fully_connected_params& params, int auauto batch_threads = threads.first;auto feature_threads = threads.second;- const size_t lws_batches = 8;const size_t aligned_batch = Align(batch_threads, lws_batches); // Each WG calculates 8x8 batches (TILE_B x LWS[2] size)const bool can_use_slm = tparams.kernel_type == KernelType::SLM;@@ -550,7 +569,6 @@ JitConstants FullyConnected_bf_tiled::GetJitConstants(const fully_connected_paraWeightsType weights_dt = params.weights.GetDType();if (weights_dt == WeightsType::UINT4 || weights_dt == WeightsType::INT4) {tile_k_ofm_packed /= 2;-jit.Merge(make_int4_packed_type_jit_constant("INT4_PACKED_TYPE", weights_dt, tile_k_ofm));const size_t scale_group_size = params.weights.IFM().v / params.decompression_scale.Feature().v;// Do not use SCALE_POST_OP for SLM kernel, since it demonstrates worse performance@@ -581,7 +599,7 @@ JitConstants FullyConnected_bf_tiled::GetJitConstants(const fully_connected_paraif (dispatchData.use_slm) {OPENVINO_ASSERT(dispatchData.tile_n == 2, "[GPU] Unsupported TILE_OFM size for SLM kernel configuration");- OPENVINO_ASSERT(weights_dt == WeightsType::INT4 || weights_dt == WeightsType::UINT4, "[GPU] Unsupported FC weights type for SLM kernel configuration");+ OPENVINO_ASSERT(is_weight_dyn_quantizable(params), "[GPU] Unsupported FC weights type for SLM kernel configuration");auto lws_batches = dispatchData.lws[2];auto total_weights_elements = simd * dispatchData.tile_n * simd * dispatchData.tile_mk; // SIMD * TILE_OFM * SIMD * TILE_IFM@@ -608,15 +626,19 @@ JitConstants FullyConnected_bf_tiled::GetJitConstants(const fully_connected_parajit.AddConstant(MakeJitConstant("LWS_BATCHES", lws_batches));jit.AddConstant(MakeJitConstant("FILTER_LOAD_ITERS", weights_load_iters));- if (params.weights.GetLayout() == WeightsLayout::os_iyx_osv16) {- jit.AddConstant(MakeJitConstant("FILTER_ACTUAL_LOAD_BLOCK_SIZE", block_read_size / 2));- jit.Merge(make_int4_packed_type_jit_constant("INT4_PACKED_TYPE_PRELOAD", params.weights.GetDType(), weights_elements_per_load / 2));- } else if (params.weights.GetLayout() == WeightsLayout::os_is_yx_osv64_isv2) {- jit.AddConstant(MakeJitConstant("FILTER_ACTUAL_LOAD_BLOCK_SIZE", block_read_size / 2));- jit.Merge(make_int4_packed_type_jit_constant("INT4_PACKED_TYPE_PRELOAD", params.weights.GetDType(), weights_elements_per_load / 2));+ if (weights_dt == WeightsType::INT4 || weights_dt == WeightsType::UINT4) {+ if (params.weights.GetLayout() == WeightsLayout::os_iyx_osv16) {+ jit.AddConstant(MakeJitConstant("FILTER_ACTUAL_LOAD_BLOCK_SIZE", block_read_size / 2));+ jit.Merge(make_int4_packed_type_jit_constant("INT4_PACKED_TYPE_PRELOAD", params.weights.GetDType(), weights_elements_per_load / 2));+ } else if (params.weights.GetLayout() == WeightsLayout::os_is_yx_osv64_isv2) {+ jit.AddConstant(MakeJitConstant("FILTER_ACTUAL_LOAD_BLOCK_SIZE", block_read_size / 2));+ jit.Merge(make_int4_packed_type_jit_constant("INT4_PACKED_TYPE_PRELOAD", params.weights.GetDType(), weights_elements_per_load / 2));+ } else {+ jit.AddConstant(MakeJitConstant("FILTER_ACTUAL_LOAD_BLOCK_SIZE", block_read_size));+ jit.Merge(make_int4_packed_type_jit_constant("INT4_PACKED_TYPE_PRELOAD", params.weights.GetDType(), weights_elements_per_load));+ }} else {jit.AddConstant(MakeJitConstant("FILTER_ACTUAL_LOAD_BLOCK_SIZE", block_read_size));- jit.Merge(make_int4_packed_type_jit_constant("INT4_PACKED_TYPE_PRELOAD", params.weights.GetDType(), weights_elements_per_load));}jit.AddConstant(MakeJitConstant("FILTER_LOAD_BLOCK_SIZE", block_read_size));@@ -629,7 +651,6 @@ JitConstants FullyConnected_bf_tiled::GetJitConstants(const fully_connected_paraif (should_dynamic_quantize(params)) {jit.AddConstant(MakeJitConstant("DYNAMIC_QUANTIZE", 1));jit.AddConstant(MakeJitConstant("DQ_DECOMPRESSION_SCALE_POST_OP", 1));- jit.AddConstant(MakeJitConstant("DQ_TYPE", "char"));jit.AddConstant(MakeJitConstant("QUANTIZE_GROUP_SIZE", quantize_grp_size));} else {if (add_decompress_scale_post_op)@@ -637,6 +658,7 @@ JitConstants FullyConnected_bf_tiled::GetJitConstants(const fully_connected_parajit.AddConstant(MakeJitConstant("DYNAMIC_QUANTIZE", 0));jit.AddConstant(MakeJitConstant("QUANTIZE_GROUP_SIZE", min_quantize_grp_size));}+ jit.AddConstant(MakeJitConstant("DQ_TYPE", "char"));jit.AddConstant(MakeJitConstant("IFM_SIZE", get_input_bf_size(params).second));jit.AddConstant(MakeJitConstant("SIMD", simd));@@ -659,9 +681,7 @@ JitConstants FullyConnected_bf_tiled::GetJitConstants(const fully_connected_para}auto max_tile_b_size = dispatchData.tile_m;- if (params.compressed &&- params.is_shape_agnostic &&- (weights_dt == WeightsType::UINT4 || weights_dt == WeightsType::INT4))+ if (params.compressed && params.is_shape_agnostic && is_weight_dyn_quantizable(params))max_tile_b_size = std::max(max_tile_b_size, (uint32_t)8);jit.Merge(MakeConstantLoopUnrollJitConstants(max_tile_b_size));@@ -772,8 +792,10 @@ void FullyConnected_bf_tiled::GetUpdateDispatchDataFunc(KernelData& kd) const {if (kd.internalBufferSizes[0] < input_size) {kd.internalBufferSizes.clear();- kd.internalBufferSizes.push_back(input_size); // quantized input is char type- kd.internalBufferSizes.push_back(input_size / quantize_grp_size * 2); // de_quan_scale is half type+ // quantized input is char type+ kd.internalBufferSizes.push_back(input_size);+ // half type of de_quan_scale and activation sum for each quantized group+ kd.internalBufferSizes.push_back((input_size / quantize_grp_size) * 2 * 2);}kd.kernels[0].params.workGroups.global = {std::max((input_size / quantize_grp_size), (size_t)1), 1, 1};@@ -800,7 +822,7 @@ KernelsData FullyConnected_bf_tiled::GetTunedKernelsDataByIndex(const Params &pa&& (fc_params.weights.GetLayout() == WeightsLayout::oiyx || fc_params.weights.GetLayout() == WeightsLayout::os_is_yx_osv64_isv2)&& (fc_params.weights.GetDType() == WeightsType::INT4 || fc_params.weights.GetDType() == WeightsType::UINT4)&& is_weight_horizontal(fc_params, output_f)) {- // Large N + Small K case (horizontal weight) to use [osv64_isv2] + TILE_OFM 4 for batch 1+ // Large N + small K case (horizontal weight) to use [osv64_isv2] + TILE_OFM 4 for batch 1weights_layout = WeightsLayout::os_is_yx_osv64_isv2;} else if (fc_params.compressed && fc_params.inputs[0].GetDType() == Datatype::F16&& (fc_params.weights.GetDType() == WeightsType::INT4 || fc_params.weights.GetDType() == WeightsType::UINT4)@@ -947,6 +969,8 @@ KernelsData FullyConnected_bf_tiled::GetMultiKernelsData(const Params ¶ms,auto& quan_kernel = kd.kernels[0];DispatchData dyn_quan_dispatch = dispatchData;auto input_size = std::max(fc_params.inputs[0].PhysicalSize(), get_input_bf_size(fc_params).second);+ if (!params.is_shape_agnostic)+ input_size = std::max(input_size, Align(get_input_bf_size(fc_params).first, lws_batches) * get_input_bf_size(fc_params).second);dyn_quan_dispatch.gws = {input_size / quantize_grp_size, 1, 1};dyn_quan_dispatch.lws = {16, 1, 1};quan_kernel.params.workGroups.global = dyn_quan_dispatch.gws;@@ -958,7 +982,6 @@ KernelsData FullyConnected_bf_tiled::GetMultiKernelsData(const Params ¶ms,quan_cldnn_jit.AddConstant(MakeJitConstant("FC_KERNEL_DYNAMIC_QUANTIZE", 1));auto quan_jit = CreateJit(kernelName, quan_cldnn_jit, quan_entry_point);-FillCLKernelData(quan_kernel,dyn_quan_dispatch,params.engineInfo,@@ -977,8 +1000,10 @@ KernelsData FullyConnected_bf_tiled::GetMultiKernelsData(const Params ¶ms,quan_kernel.params.arguments.push_back({ArgumentDescriptor::Types::INPUT, 0});quan_kernel.params.arguments.push_back({ArgumentDescriptor::Types::INTERNAL_BUFFER, 0});quan_kernel.params.arguments.push_back({ArgumentDescriptor::Types::INTERNAL_BUFFER, 1});+ // char type quantized inputkd.internalBufferSizes.push_back(input_size);- kd.internalBufferSizes.push_back(input_size / quantize_grp_size * 2);+ // half type of de_quan_scale and activation sum for each quantized group+ kd.internalBufferSizes.push_back(input_size / quantize_grp_size * 2 * 2);kernel_number++;}kd.internalBufferDataType = Datatype::F16;diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/fully_connected_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/fully_connected_gpu_test.cppindex eed9760348f..6bf44a31add 100644--- a/src/plugins/intel_gpu/tests/unit/test_cases/fully_connected_gpu_test.cpp+++ b/src/plugins/intel_gpu/tests/unit/test_cases/fully_connected_gpu_test.cpp@@ -1589,7 +1589,7 @@ public:count++;OPENVINO_ASSERT(abs_diff < 256);}- GPU_DEBUG_LOG << "---> count: " << count << ", max_diff:" << max_diff << ", avg_diff: " << (avg/count) << std::endl;+ std::cout << "---> count: " << count << ", max_diff:" << max_diff << ", avg_diff: " << (avg/count) << std::endl;}void test_compressed_int4_scale(bool is_caching_test, bool is_dynamic, long int batch_num, long int scales_group_size = 128, bool is_wei_dyn = false) {@@ -2903,7 +2903,7 @@ public:auto config = get_test_default_config(engine);config.set_property(ov::intel_gpu::allow_new_shape_infer(true));- ov::intel_gpu::ImplementationDesc fc_impl_desc = { format::bfyx, "fully_connected_gpu_bf_tiled", impl_types::ocl };+ ov::intel_gpu::ImplementationDesc fc_impl_desc = { format::bfyx, "fully_connected_gpu_bfyx_ref", impl_types::ocl };config.set_property(ov::intel_gpu::force_implementations(ov::intel_gpu::ImplForcingMap{ {"fc_prim", fc_impl_desc} }));config.set_property(ov::hint::dynamic_quantization_group_size(0));@@ -2965,11 +2965,137 @@ public:max_diff = abs_diff;avg += abs_diff;count++;- OPENVINO_ASSERT(abs_diff < 5);+ OPENVINO_ASSERT(abs_diff < 6);}GPU_DEBUG_LOG << "---> count: " << count << ", max_diff:" << max_diff << ", avg_diff: " << (avg/count) << std::endl;OPENVINO_ASSERT((avg/count) < 0.5);}++ void test_compressed_int8_scale_dyn_quan_weight_u8(bool is_dynamic, int batch = 1, int ifm = 512, int ofm = 2048,+ int quantize_group_size = 32, int scales_group_size = 128,+ bool is_wzp_test = false, bool is_wzp_scalar = false) {+ tests::random_generator rg(GET_SUITE_NAME);+ auto& engine = get_test_engine();++ if (engine.get_device_info().dev_type == device_type::discrete_gpu)+ GTEST_SKIP();++ long int batch_num = batch;+ long int ifm_num = ifm;+ long int ofm_num = ofm;+ long int wzp_num = is_wzp_scalar ? 1 : ofm_num;++ auto input_ps = ov::PartialShape{ batch_num, 1, ifm_num };+ auto input_mem = engine.allocate_memory({ input_ps, data_types::f16, format::bfyx });++ auto weights_mem = engine.allocate_memory({ {ofm_num, ifm_num}, data_types::u8, format::bfyx });+ auto scale_mem = engine.allocate_memory({ {ofm_num, ifm_num / scales_group_size}, data_types::f16, format::fbyx });+ auto dcomp_zp_mem = engine.allocate_memory({ {wzp_num, 1}, data_types::u8, format::bfyx });+++ auto input_data = rg.generate_random_1d<ov::float16>(batch_num * ifm_num, -2.f, 2.f);+ set_values(input_mem, input_data);++ auto weigths_data = rg.generate_random_1d<uint8_t>(ofm_num * ifm_num, 0, 4);+ set_values(weights_mem, weigths_data);++ auto scale_data = rg.generate_random_1d<ov::float16>(ofm_num * ifm_num / scales_group_size, -2.f, 2.f);+ set_values(scale_mem, scale_data);++ if (is_wzp_test) {+ auto zp_data = rg.generate_random_1d<uint8_t>(wzp_num, 0, 2);+ set_values(dcomp_zp_mem, zp_data);+ }++ auto in_layout = is_dynamic ? layout{ ov::PartialShape{ -1, -1, -1 }, data_types::f16, format::bfyx }+ : layout{ input_ps, data_types::f16, format::bfyx };++ auto dcomp_zp_name = is_wzp_test ? "wzp" : "";+ auto fc_prim = fully_connected("fc_prim", input_info("input"), "weights", "", "scale", dcomp_zp_name, data_types::f16, 3, 2);++ if (is_wzp_test) {+ fc_prim.compressed_weights = true;+ fc_prim.decompression_zero_point = is_wzp_test ? "wzp" : "";+ }++ // Implemented dynamic quantize kernel+ auto get_ref_results = [&]() {+ topology topo;+ topo.add(input_layout("input", in_layout));+ topo.add(data("weights", weights_mem));+ topo.add(data("scale", scale_mem));+ topo.add(data("wzp", dcomp_zp_mem));+ topo.add(fc_prim);++ auto config = get_test_default_config(engine);+ config.set_property(ov::intel_gpu::allow_new_shape_infer(true));+ ov::intel_gpu::ImplementationDesc fc_impl_desc = { format::bfyx, "fully_connected_gpu_bf_tiled", impl_types::ocl };+ config.set_property(ov::intel_gpu::force_implementations(ov::intel_gpu::ImplForcingMap{ {"fc_prim", fc_impl_desc} }));+ config.set_property(ov::hint::dynamic_quantization_group_size(0));++ network network(engine, topo, config);+ network.set_input_data("input", input_mem);++ auto outputs = network.execute();+ OPENVINO_ASSERT(outputs.size() == 1);+ OPENVINO_ASSERT(outputs.begin()->first == "fc_prim");++ auto output_layout = outputs.begin()->second.get_layout();+ auto output_mem = outputs.begin()->second.get_memory();++ return engine.reinterpret_buffer(*output_mem, output_layout);+ };++ topology topology(+ input_layout("input", in_layout),+ data("weights", weights_mem),+ data("scale", scale_mem),+ data("wzp", dcomp_zp_mem),+ fc_prim+ );++ auto config = get_test_default_config(engine);+ config.set_property(ov::intel_gpu::allow_new_shape_infer(true));+ config.set_property(ov::intel_gpu::optimize_data(true));+ config.set_property(ov::hint::dynamic_quantization_group_size(quantize_group_size));++ network::ptr network = get_network(engine, topology, config, get_test_stream_ptr(), false);++ if (is_dynamic && !engine.get_device_info().supports_immad) {+ auto inst = network->get_primitive("fc_prim");+ auto impl = inst->get_impl();+ ASSERT_TRUE(impl != NULL);+ auto kernel_num = (is_dynamic) ? 3 : 2;+ kernel_num = (quantize_group_size < 32) ? 2 : kernel_num;+ ASSERT_EQ(impl->get_kernels().size(), size_t(kernel_num));+ }++ network->set_input_data("input", input_mem);++ auto outputs = network->execute();+ ASSERT_EQ(outputs.size(), size_t(1));+ ASSERT_EQ(outputs.begin()->first, "fc_prim");++ auto output_mem = outputs.begin()->second.get_memory();+ cldnn::mem_lock<ov::float16> output_ptr (output_mem, get_test_stream());++ auto ref_output_mem = get_ref_results();+ cldnn::mem_lock<ov::float16> output_ptr_ref (ref_output_mem, get_test_stream());++ size_t count = 0;+ float max_diff = 0.f;+ float avg = 0.f;+ for (size_t i = 0; i < output_ptr_ref.size(); ++i) {+ auto abs_diff = std::abs((float)output_ptr_ref[i] - (float)output_ptr[i]);+ if (max_diff < abs_diff)+ max_diff = abs_diff;+ avg += abs_diff;+ count++;+ OPENVINO_ASSERT(abs_diff < 8);+ }+ GPU_DEBUG_LOG << "---> count: " << count << ", max_diff:" << max_diff << ", avg_diff: " << (avg/count) << std::endl;+ OPENVINO_ASSERT((avg/count) < 0.8);+ }};using shared_dims = std::tuple<size_t, size_t, size_t>;@@ -4064,6 +4190,34 @@ TEST_F(fully_connected_gpu_tests, compressed_int4_scale_dynamic_quantize_wzp_stathis->test_compressed_int4_scale_dyn_quan_weight_i4(false, 320, 1024, 1024, 32, 32, true);}+TEST_F(fully_connected_gpu_tests, compressed_int8_scale_dynamic_quantize_wzp_128_large) {+ this->test_compressed_int8_scale_dyn_quan_weight_u8(true, 320, 4096, 4096, 128, 128, true);+}++TEST_F(fully_connected_gpu_tests, compressed_int8_scale_dynamic_quantize_wzp_32_ifm_1024) {+ this->test_compressed_int8_scale_dyn_quan_weight_u8(true, 320, 1024, 1024, 32, 32, true);+}++TEST_F(fully_connected_gpu_tests, compressed_int8_scale_dynamic_quantize_wzp_32_ifm_2048) {+ this->test_compressed_int8_scale_dyn_quan_weight_u8(true, 320, 2048, 2048, 32, 32, true);+}++TEST_F(fully_connected_gpu_tests, compressed_int8_scale_dynamic_quantize_wzp_32_ifm_4096) {+ this->test_compressed_int8_scale_dyn_quan_weight_u8(true, 320, 4096, 4096, 32, 32, true);+}++TEST_F(fully_connected_gpu_tests, compressed_int8_scale_dynamic_quantize_wzp_32_large_unaligned) {+ this->test_compressed_int8_scale_dyn_quan_weight_u8(true, 310, 1024, 1024, 32, 32, true);+}++TEST_F(fully_connected_gpu_tests, compressed_int8_scale_dynamic_quantize_wzp_128_small) {+ this->test_compressed_int8_scale_dyn_quan_weight_u8(true, 16, 1024, 1024, 128, 128, true);+}++TEST_F(fully_connected_gpu_tests, compressed_int8_scale_dynamic_quantize_wzp_128_single) {+ this->test_compressed_int8_scale_dyn_quan_weight_u8(true, 1, 1024, 1024, 128, 128, true);+}+TEST_F(fully_connected_gpu_tests, compressed_scale_bias) {this->test_compressed_scale_bias(false);}