Skip to content

Commit 16ebdc5

Browse files
authored
Merge pull request #37 from sroecker/cuda-ada-mmq-tile-cap
cuda: tune Ada MMQ tile cap for small quants
2 parents dcf305b + 239296c commit 16ebdc5

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

ggml/src/ggml-cuda/mmq.cuh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,26 @@ static int get_mmq_x_max_host(const int cc) {
116116
#endif // GGML_CUDA_FORCE_MMQ
117117
}
118118

119+
template <ggml_type type>
120+
static int get_mmq_x_max_host_for_type(const int cc) {
121+
const int mmq_x_max = get_mmq_x_max_host(cc);
122+
123+
if (GGML_CUDA_CC_IS_NVIDIA(cc) && cc >= GGML_CUDA_CC_ADA_LOVELACE) {
124+
switch (type) {
125+
case GGML_TYPE_IQ2_XXS:
126+
case GGML_TYPE_IQ2_S:
127+
case GGML_TYPE_IQ3_XXS:
128+
case GGML_TYPE_IQ3_S:
129+
case GGML_TYPE_Q3_K:
130+
return mmq_x_max < 64 ? mmq_x_max : 64;
131+
default:
132+
break;
133+
}
134+
}
135+
136+
return mmq_x_max;
137+
}
138+
119139
static constexpr __device__ int get_mmq_x_max_device() {
120140
#if defined(TURING_MMA_AVAILABLE) || defined(AMD_WMMA_AVAILABLE)
121141
return 128;
@@ -4060,7 +4080,7 @@ void mul_mat_q_case(ggml_backend_cuda_context & ctx, const mmq_args & args, cuda
40604080
const int warp_size = ggml_cuda_info().devices[id].warp_size;
40614081
const int nwarps = mmq_get_nwarps_host(cc, warp_size);
40624082

4063-
const int mmq_x_max = get_mmq_x_max_host(cc);
4083+
const int mmq_x_max = get_mmq_x_max_host_for_type<type>(cc);
40644084
const int mmq_y = get_mmq_y_host(cc);
40654085

40664086
int mmq_x_best = 0;
@@ -4173,4 +4193,3 @@ void ggml_cuda_op_mul_mat_q(
41734193
const int64_t src1_padded_row_size, cudaStream_t stream);
41744194

41754195
bool ggml_cuda_should_use_mmq(enum ggml_type type, int cc, int64_t ne11, int64_t n_experts);
4176-

0 commit comments

Comments
 (0)