Spaces:
Running
Running
Commit
·
b021272
1
Parent(s):
ba2469d
CUDA: fix --split-mode row race condition (llama/9413)
Browse files- ggml/src/ggml-cuda/mmq.cu +5 -1
- ggml/src/ggml-cuda/mmq.cuh +2 -2
ggml/src/ggml-cuda/mmq.cu
CHANGED
|
@@ -26,7 +26,11 @@ void ggml_cuda_op_mul_mat_q(
|
|
| 26 |
// nrows_dst == nrows of the matrix that the kernel writes into
|
| 27 |
const int64_t nrows_dst = id == ctx.device ? ne0 : row_diff;
|
| 28 |
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
switch (src0->type) {
|
| 32 |
case GGML_TYPE_Q4_0:
|
|
|
|
| 26 |
// nrows_dst == nrows of the matrix that the kernel writes into
|
| 27 |
const int64_t nrows_dst = id == ctx.device ? ne0 : row_diff;
|
| 28 |
|
| 29 |
+
// The stream-k decomposition is only faster for recent NVIDIA GPUs.
|
| 30 |
+
// Also its fixup needs to allocate a temporary buffer in the memory pool.
|
| 31 |
+
// There are multiple parallel CUDA streams for src1_ncols != ne11 which would introduce a race condition for this buffer.
|
| 32 |
+
const bool use_stream_k = compute_capability >= CC_VOLTA && compute_capability < CC_OFFSET_AMD && src1_ncols == ne11;
|
| 33 |
+
const mmq_args args = {src0_dd_i, src1_ddq_i, dst_dd_i, ne00, row_diff, stride00, src1_padded_row_size, src1_ncols, ne11, nrows_dst, use_stream_k};
|
| 34 |
|
| 35 |
switch (src0->type) {
|
| 36 |
case GGML_TYPE_Q4_0:
|
ggml/src/ggml-cuda/mmq.cuh
CHANGED
|
@@ -2742,6 +2742,7 @@ struct mmq_args {
|
|
| 2742 |
int64_t ne00; int64_t ne01; int64_t stride01;
|
| 2743 |
int64_t ne10; int64_t ne11; int64_t stride11;
|
| 2744 |
int64_t ne0;
|
|
|
|
| 2745 |
};
|
| 2746 |
|
| 2747 |
template<ggml_type type>
|
|
@@ -2777,8 +2778,7 @@ static void launch_mul_mat_q(ggml_backend_cuda_context & ctx, const mmq_args & a
|
|
| 2777 |
const int ntx = (args.ne11 + mmq_x - 1) / mmq_x;
|
| 2778 |
const dim3 block_nums_xy_tiling(nty, ntx, 1);
|
| 2779 |
|
| 2780 |
-
|
| 2781 |
-
if (!use_stream_k) {
|
| 2782 |
if (args.ne01 % mmq_y == 0) {
|
| 2783 |
constexpr bool need_check = false;
|
| 2784 |
mul_mat_q<type, mmq_x, MMQ_NWARPS, need_check><<<block_nums_xy_tiling, block_dims, shmem, stream>>>
|
|
|
|
| 2742 |
int64_t ne00; int64_t ne01; int64_t stride01;
|
| 2743 |
int64_t ne10; int64_t ne11; int64_t stride11;
|
| 2744 |
int64_t ne0;
|
| 2745 |
+
bool use_stream_k;
|
| 2746 |
};
|
| 2747 |
|
| 2748 |
template<ggml_type type>
|
|
|
|
| 2778 |
const int ntx = (args.ne11 + mmq_x - 1) / mmq_x;
|
| 2779 |
const dim3 block_nums_xy_tiling(nty, ntx, 1);
|
| 2780 |
|
| 2781 |
+
if (!args.use_stream_k) {
|
|
|
|
| 2782 |
if (args.ne01 % mmq_y == 0) {
|
| 2783 |
constexpr bool need_check = false;
|
| 2784 |
mul_mat_q<type, mmq_x, MMQ_NWARPS, need_check><<<block_nums_xy_tiling, block_dims, shmem, stream>>>
|