diff --git a/src/ggml-cuda/ggml-cuda.cu b/src/ggml-cuda/ggml-cuda.cu index 025f11e16e..01852f1247 100644 --- a/src/ggml-cuda/ggml-cuda.cu +++ b/src/ggml-cuda/ggml-cuda.cu @@ -1333,7 +1333,7 @@ typedef void (*ggml_cuda_op_mul_mat_t)( const int64_t src1_padded_row_size, cudaStream_t stream); -#if !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA) +#if !defined(GGML_USE_MUSA) __global__ void quantize_rowwise_i8_cuda(const float * src, int8_t * dst, float * scales, int64_t k, int64_t rows) { const int64_t row = blockIdx.x; const int tid = threadIdx.x; @@ -1377,12 +1377,14 @@ __global__ void quantize_rowwise_i8_cuda(const float * src, int8_t * dst, float } } +template __global__ void quantize_rowwise_i8_convrot_cuda( const float * src, int8_t * dst, float * scales, int64_t k, int64_t rows, int64_t dst_stride) { - constexpr int group_size = 256; constexpr int group_threads = group_size / 4; constexpr int groups_per_wave = 1024 / group_threads; + // H4 carries a 1/2 normalization, applied log4(group_size) times. + constexpr float hadamard_norm = group_size == 256 ? (1.0f / 16.0f) : (1.0f / 8.0f); const int64_t row = blockIdx.x; const int tid = threadIdx.x; @@ -1396,7 +1398,7 @@ __global__ void quantize_rowwise_i8_convrot_cuda( int8_t * dst_row = dst + row * dst_stride; for (int64_t i = tid; i < k; i += blockDim.x) { - values[i] = src_row[i] * (1.0f / 16.0f); + values[i] = src_row[i] * hadamard_norm; } __syncthreads(); @@ -1466,27 +1468,32 @@ __global__ void quantize_rowwise_i8_convrot_cuda( } } +template __global__ void convrot_group_amax_i8_cuda( const float * src, float * partial_max, int64_t k, int64_t groups, int64_t total_groups) { + constexpr int group_threads = group_size / 4; + // H4 carries a 1/2 normalization, applied log4(group_size) times. + constexpr float hadamard_norm = group_size == 256 ? (1.0f / 16.0f) : (1.0f / 8.0f); + const int64_t index = blockIdx.x; const int tid = threadIdx.x; if (index >= total_groups) { return; } - __shared__ float values[256]; - __shared__ float maxima[2]; + __shared__ float values[group_size]; + __shared__ float maxima[group_threads]; const int64_t row = index / groups; const int64_t group = index - row * groups; - const float * input = src + row * k + group * 256; - values[tid] = input[tid] * (1.0f / 16.0f); - values[tid + 64] = input[tid + 64] * (1.0f / 16.0f); - values[tid + 128] = input[tid + 128] * (1.0f / 16.0f); - values[tid + 192] = input[tid + 192] * (1.0f / 16.0f); + const float * input = src + row * k + group * group_size; +#pragma unroll + for (int j = 0; j < 4; ++j) { + values[tid + j * group_threads] = input[tid + j * group_threads] * hadamard_norm; + } __syncthreads(); #pragma unroll - for (int stride = 1; stride < 256; stride *= 4) { + for (int stride = 1; stride < group_size; stride *= 4) { const int base = (tid / stride) * 4 * stride + tid % stride; const int i0 = base; const int i1 = i0 + stride; @@ -1503,18 +1510,21 @@ __global__ void convrot_group_amax_i8_cuda( __syncthreads(); } - float value = fmaxf(fabsf(values[tid]), fabsf(values[tid + 64])); - value = fmaxf(value, fabsf(values[tid + 128])); - value = fmaxf(value, fabsf(values[tid + 192])); - for (int offset = 16; offset > 0; offset >>= 1) { - value = fmaxf(value, __shfl_down_sync(0xffffffff, value, offset)); - } - if ((tid & 31) == 0) { - maxima[tid >> 5] = value; + float value = 0.0f; +#pragma unroll + for (int j = 0; j < 4; ++j) { + value = fmaxf(value, fabsf(values[tid + j * group_threads])); } + maxima[tid] = value; __syncthreads(); + for (int stride = group_threads / 2; stride > 0; stride >>= 1) { + if (tid < stride) { + maxima[tid] = fmaxf(maxima[tid], maxima[tid + stride]); + } + __syncthreads(); + } if (tid == 0) { - partial_max[index] = fmaxf(maxima[0], maxima[1]); + partial_max[index] = maxima[0]; } } @@ -1544,28 +1554,33 @@ __global__ void reduce_convrot_row_amax_i8_cuda( } } +template __global__ void convrot_group_quantize_i8_cuda( const float * src, int8_t * dst, const float * scales, int64_t k, int64_t groups, int64_t total_groups, int64_t dst_stride) { + constexpr int group_threads = group_size / 4; + // H4 carries a 1/2 normalization, applied log4(group_size) times. + constexpr float hadamard_norm = group_size == 256 ? (1.0f / 16.0f) : (1.0f / 8.0f); + const int64_t index = blockIdx.x; const int tid = threadIdx.x; if (index >= total_groups) { return; } - __shared__ float values[256]; + __shared__ float values[group_size]; const int64_t row = index / groups; const int64_t group = index - row * groups; - const float * input = src + row * k + group * 256; - int8_t * output = dst + row * dst_stride + group * 256; - values[tid] = input[tid] * (1.0f / 16.0f); - values[tid + 64] = input[tid + 64] * (1.0f / 16.0f); - values[tid + 128] = input[tid + 128] * (1.0f / 16.0f); - values[tid + 192] = input[tid + 192] * (1.0f / 16.0f); + const float * input = src + row * k + group * group_size; + int8_t * output = dst + row * dst_stride + group * group_size; +#pragma unroll + for (int j = 0; j < 4; ++j) { + values[tid + j * group_threads] = input[tid + j * group_threads] * hadamard_norm; + } __syncthreads(); #pragma unroll - for (int stride = 1; stride < 256; stride *= 4) { + for (int stride = 1; stride < group_size; stride *= 4) { const int base = (tid / stride) * 4 * stride + tid % stride; const int i0 = base; const int i1 = i0 + stride; @@ -1584,12 +1599,12 @@ __global__ void convrot_group_quantize_i8_cuda( const float row_scale = scales[row]; const float inv_scale = row_scale == 0.0f ? 0.0f : 1.0f / row_scale; - const int indices[4] = { tid, tid + 64, tid + 128, tid + 192 }; #pragma unroll - for (int i = 0; i < 4; ++i) { - int value = row_scale == 0.0f ? 0 : __float2int_rn(values[indices[i]] * inv_scale); + for (int j = 0; j < 4; ++j) { + const int element = tid + j * group_threads; + int value = row_scale == 0.0f ? 0 : __float2int_rn(values[element] * inv_scale); value = max(-127, min(127, value)); - output[indices[i]] = (int8_t)value; + output[element] = (int8_t)value; } if (group == 0 && tid == 0 && dst_stride != k) { *((float *)(dst + row * dst_stride + k)) = row_scale; @@ -1623,7 +1638,8 @@ static void ggml_cuda_quantize_i8_convrot( int64_t k, int64_t rows, int64_t rows_padded, - int64_t dst_stride) { + int64_t dst_stride, + int group_size) { cudaStream_t stream = ctx.stream(); if (rows_padded > rows) { CUDA_CHECK(cudaMemsetAsync( @@ -1633,26 +1649,43 @@ static void ggml_cuda_quantize_i8_convrot( const size_t nbytes_shared = (size_t)k * sizeof(float); const size_t smpbo = ggml_cuda_info().devices[ggml_cuda_get_device()].smpbo; if (nbytes_shared + 128 <= smpbo) { - CUDA_SET_SHARED_MEMORY_LIMIT(quantize_rowwise_i8_convrot_cuda, smpbo - 128); - quantize_rowwise_i8_convrot_cuda<<>>( - src, dst, scales, k, rows, dst_stride); + if (group_size == 64) { + CUDA_SET_SHARED_MEMORY_LIMIT(quantize_rowwise_i8_convrot_cuda<64>, smpbo - 128); + quantize_rowwise_i8_convrot_cuda<64><<>>( + src, dst, scales, k, rows, dst_stride); + } else { + CUDA_SET_SHARED_MEMORY_LIMIT(quantize_rowwise_i8_convrot_cuda<256>, smpbo - 128); + quantize_rowwise_i8_convrot_cuda<256><<>>( + src, dst, scales, k, rows, dst_stride); + } return; } - const int64_t groups = k / 256; + const int64_t groups = k / group_size; const int64_t total_groups = rows * groups; + const int group_threads = group_size / 4; ggml_cuda_pool_alloc partial_max(ctx.pool(), total_groups); ggml_cuda_pool_alloc packed_scales(ctx.pool()); float * scales_d = scales; if (scales_d == nullptr) { scales_d = packed_scales.alloc(rows); } - convrot_group_amax_i8_cuda<<>>( - src, partial_max.get(), k, groups, total_groups); + if (group_size == 64) { + convrot_group_amax_i8_cuda<64><<>>( + src, partial_max.get(), k, groups, total_groups); + } else { + convrot_group_amax_i8_cuda<256><<>>( + src, partial_max.get(), k, groups, total_groups); + } reduce_convrot_row_amax_i8_cuda<<>>( partial_max.get(), scales_d, groups, rows); - convrot_group_quantize_i8_cuda<<>>( - src, dst, scales_d, k, groups, total_groups, dst_stride); + if (group_size == 64) { + convrot_group_quantize_i8_cuda<64><<>>( + src, dst, scales_d, k, groups, total_groups, dst_stride); + } else { + convrot_group_quantize_i8_cuda<256><<>>( + src, dst, scales_d, k, groups, total_groups, dst_stride); + } } static bool ggml_cuda_op_quantize_i8_convrot( @@ -1665,7 +1698,7 @@ static bool ggml_cuda_op_quantize_i8_convrot( const int64_t scale_rows = (rows * (int64_t)sizeof(float) + src->ne[0] - 1) / src->ne[0]; if (src->type != GGML_TYPE_F32 || dst->type != GGML_TYPE_I8 || !ggml_is_contiguous(src) || !ggml_is_contiguous(dst) || - group_size != 256 || src->ne[0] % group_size != 0 || + (group_size != 64 && group_size != 256) || src->ne[0] % group_size != 0 || dst->ne[0] != src->ne[0] || dst->ne[1] != rows_padded + scale_rows) { return false; } @@ -1679,7 +1712,8 @@ static bool ggml_cuda_op_quantize_i8_convrot( src->ne[0], rows, rows_padded, - src->ne[0]); + src->ne[0], + group_size); return true; } @@ -1707,7 +1741,7 @@ static void ggml_cuda_mul_mat_i8( GGML_ASSERT(src1->ne[0] == k); GGML_ASSERT(!prequantized || (src1->op == GGML_OP_QUANTIZE_I8_CONVROT && src1->ne[1] == rows_padded + scale_rows)); - GGML_ASSERT(convrot_group_size == 0 || convrot_group_size == 256); + GGML_ASSERT(convrot_group_size == 0 || convrot_group_size == 64 || convrot_group_size == 256); ggml_cuda_pool_alloc qdata(ctx.pool()); ggml_cuda_pool_alloc scales(ctx.pool()); @@ -1727,7 +1761,7 @@ static void ggml_cuda_mul_mat_i8( (const float *)src1->data, qdata_d, scales_d, k, rows); } else { ggml_cuda_quantize_i8_convrot( - ctx, (const float *)src1->data, qdata_d, scales_d, k, rows, rows_padded, k); + ctx, (const float *)src1->data, qdata_d, scales_d, k, rows, rows_padded, k, convrot_group_size); } const float * weight_scales = dst->src[2] != nullptr ? (const float *)dst->src[2]->data : nullptr; @@ -2237,10 +2271,10 @@ static void ggml_cuda_mul_mat(ggml_backend_cuda_context & ctx, const ggml_tensor } if (src0->type == GGML_TYPE_I8) { -#if !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA) +#if !defined(GGML_USE_MUSA) ggml_cuda_mul_mat_i8(ctx, src0, src1, dst); #else - GGML_ABORT("INT8 tensorwise matmul is only implemented for CUDA"); + GGML_ABORT("INT8 tensorwise matmul is only implemented for CUDA and HIP"); #endif return; } @@ -2646,10 +2680,10 @@ static bool ggml_cuda_compute_forward(ggml_backend_cuda_context & ctx, struct gg ggml_cuda_mul_mat_id(ctx, dst); break; case GGML_OP_QUANTIZE_I8_CONVROT: -#if !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA) +#if !defined(GGML_USE_MUSA) GGML_ASSERT(ggml_cuda_op_quantize_i8_convrot(ctx, dst->src[0], dst, ggml_get_op_params_i32(dst, 0))); #else - GGML_ABORT("INT8 convrot quantization is only implemented for CUDA"); + GGML_ABORT("INT8 convrot quantization is only implemented for CUDA and HIP"); #endif break; case GGML_OP_OUT_PROD: @@ -5236,7 +5270,7 @@ static bool ggml_backend_cuda_device_supports_op(ggml_backend_dev_t dev, const g return false; // TODO this could in principle be implemented though currently there is no use case. } if (a->type == GGML_TYPE_I8) { -#if !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA) +#if !defined(GGML_USE_MUSA) const ggml_tensor * weight_scale = op->src[2]; const ggml_tensor * bias = op->src[3]; const int convrot_group_size = ggml_get_op_params_i32(op, 2); @@ -5259,8 +5293,12 @@ static bool ggml_backend_cuda_device_supports_op(ggml_backend_dev_t dev, const g (bias == nullptr || (bias->type == GGML_TYPE_F32 && ggml_is_contiguous(bias) && ggml_nelements(bias) == a->ne[1])) && - (convrot_group_size == 0 || (convrot_group_size == 256 && a->ne[0] % 256 == 0)) && - turing_mma_available(ggml_cuda_info().devices[dev_ctx->device].cc); + (convrot_group_size == 0 || + ((convrot_group_size == 64 || convrot_group_size == 256) && + a->ne[0] % convrot_group_size == 0)) && + (turing_mma_available(ggml_cuda_info().devices[dev_ctx->device].cc) || + amd_wmma_available(ggml_cuda_info().devices[dev_ctx->device].cc) || + amd_mfma_available(ggml_cuda_info().devices[dev_ctx->device].cc)); #else return false; #endif @@ -5640,7 +5678,7 @@ static bool ggml_backend_cuda_device_supports_op(ggml_backend_dev_t dev, const g case GGML_OP_LIGHTNING_INDEXER: return ggml_cuda_lightning_indexer_supported(dev_ctx->device, op); case GGML_OP_QUANTIZE_I8_CONVROT: -#if !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA) +#if !defined(GGML_USE_MUSA) { const ggml_tensor * src = op->src[0]; const int group_size = ggml_get_op_params_i32(op, 0); @@ -5651,7 +5689,7 @@ static bool ggml_backend_cuda_device_supports_op(ggml_backend_dev_t dev, const g : 0; return src != nullptr && src->type == GGML_TYPE_F32 && op->type == GGML_TYPE_I8 && ggml_is_contiguous(src) && ggml_is_contiguous(op) && - group_size == 256 && src->ne[0] % group_size == 0 && + (group_size == 64 || group_size == 256) && src->ne[0] % group_size == 0 && op->ne[0] == src->ne[0] && op->ne[1] == rows_padded + scale_rows; } #else diff --git a/src/ggml-cuda/vendors/hip.h b/src/ggml-cuda/vendors/hip.h index 9aa558f3f4..e37c54c175 100644 --- a/src/ggml-cuda/vendors/hip.h +++ b/src/ggml-cuda/vendors/hip.h @@ -20,6 +20,8 @@ #define CUDA_R_16F HIPBLAS_R_16F #define CUDA_R_16BF HIPBLAS_R_16B #define CUDA_R_32F HIPBLAS_R_32F +#define CUDA_R_8I HIPBLAS_R_8I +#define CUDA_R_32I HIPBLAS_R_32I #define CUBLAS_SIDE_RIGHT HIPBLAS_SIDE_RIGHT #define CUBLAS_FILL_MODE_UPPER HIPBLAS_FILL_MODE_UPPER #define CUBLAS_DIAG_NON_UNIT HIPBLAS_DIAG_NON_UNIT @@ -32,6 +34,8 @@ #define __shfl_sync(mask, var, laneMask, width) __shfl(var, laneMask, width) #define __shfl_up_sync(mask, var, laneMask, width) __shfl_up(var, laneMask, width) #define __shfl_xor_sync(mask, var, laneMask, width) __shfl_xor(var, laneMask, width) +// Variadic: call sites may omit the trailing width argument. +#define __shfl_down_sync(mask, ...) __shfl_down(__VA_ARGS__) #define __all_sync(mask, var) __all(var) #define __any_sync(mask, var) __any(var) #define cublasStrsmBatched hipblasStrsmBatched @@ -159,6 +163,7 @@ #if HIP_VERSION >= 60500000 #define CUBLAS_COMPUTE_16F HIPBLAS_COMPUTE_16F #define CUBLAS_COMPUTE_32F HIPBLAS_COMPUTE_32F +#define CUBLAS_COMPUTE_32I HIPBLAS_COMPUTE_32I #define CUBLAS_COMPUTE_32F_FAST_16F HIPBLAS_COMPUTE_32F_FAST_16F #define cublasComputeType_t hipblasComputeType_t #define cudaDataType_t hipDataType diff --git a/src/ggml-vulkan/ggml-vulkan.cpp b/src/ggml-vulkan/ggml-vulkan.cpp index 7ac745c762..10398a7094 100644 --- a/src/ggml-vulkan/ggml-vulkan.cpp +++ b/src/ggml-vulkan/ggml-vulkan.cpp @@ -912,6 +912,7 @@ struct vk_device_struct { vk_pipeline pipeline_matmul_split_k_reduce; vk_pipeline pipeline_quantize_q8_1_x4; vk_pipeline pipeline_quantize_i8_convrot; + vk_pipeline pipeline_quantize_i8_convrot_h64; vk_pipeline pipeline_mul_mat_i8_tensorwise; vk_pipeline pipeline_mul_mat_i8_tensorwise_cm1; @@ -5474,6 +5475,7 @@ static void ggml_vk_load_shaders(vk_device& device, vk_pipeline requested) { #if defined(GGML_VULKAN_INTEGER_DOT_GLSLC_SUPPORT) if (device->integer_dot_product) { ggml_vk_create_pipeline(device, device->pipeline_quantize_i8_convrot, "quantize_i8_convrot", quantize_i8_convrot_len, quantize_i8_convrot_data, "main", 3, sizeof(vk_quantize_i8_convrot_push_constants), {1, 1, 1}, {}, 1); + ggml_vk_create_pipeline(device, device->pipeline_quantize_i8_convrot_h64, "quantize_i8_convrot_h64", quantize_i8_convrot_h64_len, quantize_i8_convrot_h64_data, "main", 3, sizeof(vk_quantize_i8_convrot_push_constants), {1, 1, 1}, {}, 1); ggml_vk_create_pipeline(device, device->pipeline_mul_mat_i8_tensorwise, "mul_mat_i8_tensorwise", mul_mat_i8_tensorwise_len, mul_mat_i8_tensorwise_data, "main", 6, sizeof(vk_mul_mat_i8_tensorwise_push_constants), {16, 16, 1}, {}, 1); #if defined(GGML_VULKAN_COOPMAT_GLSLC_SUPPORT) if (device->coopmat_int_support) { @@ -9995,7 +9997,7 @@ static bool ggml_vk_can_use_quantize_i8_convrot(const vk_device & device, const const int64_t rows = ggml_nrows(src); const int64_t rows_padded = GGML_PAD(rows, 4); const int64_t scale_rows = (rows * (int64_t) sizeof(float) + src->ne[0] - 1) / src->ne[0]; - return group_size == 256 && src->ne[0] % 256 == 0 && + return (group_size == 64 || group_size == 256) && src->ne[0] % group_size == 0 && src->ne[0] <= std::numeric_limits::max() && rows <= std::numeric_limits::max() && dst->ne[0] == src->ne[0] && dst->ne[1] == rows_padded + scale_rows; @@ -10029,8 +10031,9 @@ static bool ggml_vk_can_use_mul_mat_i8_tensorwise(const vk_device & device, cons const int64_t rows = ggml_nrows(logical_input); const int64_t rows_padded = GGML_PAD(rows, 4); const int64_t scale_rows = (rows * (int64_t) sizeof(float) + weight->ne[0] - 1) / weight->ne[0]; - return convrot_group_size == 256 && ggml_get_op_params_i32(input, 0) == 256 && - weight->ne[0] % 256 == 0 && + return (convrot_group_size == 64 || convrot_group_size == 256) && + ggml_get_op_params_i32(input, 0) == convrot_group_size && + weight->ne[0] % convrot_group_size == 0 && input->ne[0] == weight->ne[0] && input->ne[1] == rows_padded + scale_rows && ggml_nrows(dst) == rows && weight_scale->type == GGML_TYPE_F32 && ggml_nelements(weight_scale) == weight->ne[1] && @@ -10051,7 +10054,10 @@ static void ggml_vk_quantize_i8_convrot( ggml_backend_vk_context * ctx, vk_context & subctx, const ggml_tensor * src, ggml_tensor * dst) { GGML_ASSERT(ggml_vk_can_use_quantize_i8_convrot(ctx->device, dst)); - vk_pipeline pipeline = ctx->device->pipeline_quantize_i8_convrot; + const int group_size = ggml_get_op_params_i32(dst, 0); + vk_pipeline pipeline = group_size == 64 + ? ctx->device->pipeline_quantize_i8_convrot_h64 + : ctx->device->pipeline_quantize_i8_convrot; ggml_pipeline_request_descriptor_sets(ctx, pipeline, 1); const uint32_t rows = (uint32_t) ggml_nrows(src); diff --git a/src/ggml-vulkan/vulkan-shaders/quantize_i8_convrot.comp b/src/ggml-vulkan/vulkan-shaders/quantize_i8_convrot.comp index 1c69d9dde2..e9ab6bc550 100644 --- a/src/ggml-vulkan/vulkan-shaders/quantize_i8_convrot.comp +++ b/src/ggml-vulkan/vulkan-shaders/quantize_i8_convrot.comp @@ -2,7 +2,21 @@ #extension GL_EXT_control_flow_attributes : require -layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in; +#ifndef GROUP_SIZE +#define GROUP_SIZE 256 +#endif +#if GROUP_SIZE != 64 && GROUP_SIZE != 256 +#error unsupported GROUP_SIZE +#endif +#define GROUP_THREADS (GROUP_SIZE / 4) + +#if GROUP_SIZE == 256 +#define HADAMARD_NORM (1.0 / 16.0) +#else +#define HADAMARD_NORM (1.0 / 8.0) +#endif + +layout(local_size_x = GROUP_THREADS, local_size_y = 1, local_size_z = 1) in; layout(push_constant) uniform parameter { @@ -14,22 +28,22 @@ layout(binding = 0, std430) readonly buffer A { float data_a[]; }; layout(binding = 1, std430) writeonly buffer D { uint data_d[]; }; layout(binding = 2, std430) writeonly buffer S { float data_s[]; }; -shared float values[256]; -shared float maxima[64]; +shared float values[GROUP_SIZE]; +shared float maxima[GROUP_THREADS]; void transform_group(const uint row, const uint group) { const uint tid = gl_LocalInvocationID.x; - const uint base_offset = row * p.k + group * 256; + const uint base_offset = row * p.k + group * GROUP_SIZE; [[unroll]] for (uint i = 0; i < 4; ++i) { - const uint index = tid + i * 64; - values[index] = data_a[base_offset + index] * (1.0 / 16.0); + const uint index = tid + i * GROUP_THREADS; + values[index] = data_a[base_offset + index] * HADAMARD_NORM; } barrier(); [[unroll]] - for (uint stride = 1; stride < 256; stride *= 4) { + for (uint stride = 1; stride < GROUP_SIZE; stride *= 4) { const uint base = (tid / stride) * 4 * stride + tid % stride; const uint i0 = base; const uint i1 = i0 + stride; @@ -54,14 +68,14 @@ uint quantize_value(const float value, const float inv_scale) { void quantize_row(const uint row) { const uint tid = gl_LocalInvocationID.x; - const uint groups = p.k / 256; + const uint groups = p.k / GROUP_SIZE; float local_max = 0.0; for (uint group = 0; group < groups; ++group) { transform_group(row, group); [[unroll]] for (uint i = 0; i < 4; ++i) { - local_max = max(local_max, abs(values[tid + i * 64])); + local_max = max(local_max, abs(values[tid + i * GROUP_THREADS])); } barrier(); } @@ -69,7 +83,7 @@ void quantize_row(const uint row) { maxima[tid] = local_max; barrier(); [[unroll]] - for (uint stride = 32; stride > 0; stride >>= 1) { + for (uint stride = GROUP_THREADS / 2; stride > 0; stride >>= 1) { if (tid < stride) { maxima[tid] = max(maxima[tid], maxima[tid + stride]); } @@ -90,7 +104,7 @@ void quantize_row(const uint row) { | (quantize_value(values[index + 1], inv_scale) << 8) | (quantize_value(values[index + 2], inv_scale) << 16) | (quantize_value(values[index + 3], inv_scale) << 24); - data_d[(row * p.k + group * 256) / 4 + tid] = packed; + data_d[(row * p.k + group * GROUP_SIZE) / 4 + tid] = packed; barrier(); } } diff --git a/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp b/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp index a0ae1c44cc..2dd7903fca 100644 --- a/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +++ b/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp @@ -878,6 +878,7 @@ void process_shaders() { #if defined(GGML_VULKAN_INTEGER_DOT_GLSLC_SUPPORT) string_to_spv("quantize_i8_convrot", "quantize_i8_convrot.comp", {}); + string_to_spv("quantize_i8_convrot_h64", "quantize_i8_convrot.comp", {{"GROUP_SIZE", "64"}}); string_to_spv("mul_mat_i8_tensorwise", "mul_mat_i8_tensorwise.comp", {}); #if defined(GGML_VULKAN_COOPMAT_GLSLC_SUPPORT) string_to_spv("mul_mat_i8_tensorwise", "mul_mat_i8_tensorwise_cm1.comp", {}, true, true);