Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cuda : tweak mm stride to double perf on P40 + GTX 970 #4233

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions ggml-cuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,13 @@ static_assert(K_QUANTS_PER_ITERATION == 1 || K_QUANTS_PER_ITERATION == 2, "K_QUA
#define GGML_CUDA_PEER_MAX_BATCH_SIZE 128
#endif // GGML_CUDA_PEER_MAX_BATCH_SIZE

#define MUL_MAT_SRC1_COL_STRIDE_MMQ 128

#ifdef CUDA_USE_TENSOR_CORES
#define MUL_MAT_SRC1_COL_STRIDE 128
#else
#define MUL_MAT_SRC1_COL_STRIDE 4096
#endif

#define MAX_STREAMS 8
static cudaStream_t g_cudaStreams[GGML_CUDA_MAX_DEVICES][MAX_STREAMS] = { { nullptr } };
Expand Down Expand Up @@ -7158,7 +7164,10 @@ static void ggml_cuda_op_mul_mat(
CUDA_CHECK(cudaEventRecord(src0_extra->events[g_main_device][0], g_cudaStreams[g_main_device][0]));
}

const int64_t src1_col_stride = split && used_devices > 1 ? MUL_MAT_SRC1_COL_STRIDE : ne11;
const int64_t src1_col_stride = !split || used_devices == 1 ? ne11 :
convert_src1_to_q8_1 ? MUL_MAT_SRC1_COL_STRIDE_MMQ :
MUL_MAT_SRC1_COL_STRIDE;

for (int64_t src1_col_0 = 0; src1_col_0 < ne11; src1_col_0 += src1_col_stride) {
const int64_t is = split ? (src1_col_0/src1_col_stride) % MAX_STREAMS : 0;
const int64_t src1_ncols = src1_col_0 + src1_col_stride > ne11 ? ne11 - src1_col_0 : src1_col_stride;
Expand Down Expand Up @@ -7296,7 +7305,7 @@ static void ggml_cuda_op_mul_mat(

// main device waits for all other devices to be finished
if (split && g_device_count > 1) {
int64_t is_max = (ne11 + MUL_MAT_SRC1_COL_STRIDE - 1) / MUL_MAT_SRC1_COL_STRIDE;
int64_t is_max = (ne11 + src1_col_stride - 1) / src1_col_stride;
is_max = is_max <= MAX_STREAMS ? is_max : MAX_STREAMS;

CUDA_CHECK(ggml_cuda_set_device(g_main_device));
Expand Down
Loading