Skip to content

Commit bcbce3e

Browse files
committed
Merge branch 'master' of https://github.com/ggml-org/llama.cpp
2 parents 3e528d7 + 0c89864 commit bcbce3e

10 files changed

Lines changed: 39 additions & 19 deletions

File tree

‎.github/workflows/docker.yml‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ jobs:
4545
- { tag: "intel", dockerfile: ".devops/intel.Dockerfile", platforms: "linux/amd64", full: true, light: true, server: true, free_disk_space: true, runs_on: "ubuntu-22.04" }
4646
- { tag: "vulkan", dockerfile: ".devops/vulkan.Dockerfile", platforms: "linux/amd64", full: true, light: true, server: true, free_disk_space: false, runs_on: "ubuntu-22.04" }
4747
- { tag: "s390x", dockerfile: ".devops/s390x.Dockerfile", platforms: "linux/s390x", full: true, light: true, server: true, free_disk_space: false, runs_on: "ubuntu-22.04-s390x" }
48-
# Note: the rocm images are failing due to a compiler error and are disabled until this is fixed to allow the workflow to complete
49-
#- {tag: "rocm", dockerfile: ".devops/rocm.Dockerfile", platforms: "linux/amd64,linux/arm64", full: true, light: true, server: true, free_disk_space: true }
48+
- { tag: "rocm", dockerfile: ".devops/rocm.Dockerfile", platforms: "linux/amd64", full: true, light: true, server: true, free_disk_space: true, runs_on: "ubuntu-22.04" }
5049
steps:
5150
- name: Check out the repo
5251
uses: actions/checkout@v4

‎common/common.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ bool set_process_priority(enum ggml_sched_priority prio) {
251251
case GGML_SCHED_PRIO_REALTIME: p = -20; break;
252252
}
253253

254-
if (!setpriority(PRIO_PROCESS, 0, p)) {
254+
if (setpriority(PRIO_PROCESS, 0, p) != 0) {
255255
LOG_WRN("failed to set process priority %d : %s (%d)\n", prio, strerror(errno), errno);
256256
return false;
257257
}

‎examples/retrieval/retrieval.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,16 +222,16 @@ int main(int argc, char ** argv) {
222222
float * emb = embeddings.data();
223223

224224
// break into batches
225-
int p = 0; // number of prompts processed already
226-
int s = 0; // number of prompts in current batch
225+
unsigned int p = 0; // number of prompts processed already
226+
unsigned int s = 0; // number of prompts in current batch
227227
for (int k = 0; k < n_chunks; k++) {
228228
// clamp to n_batch tokens
229229
auto & inp = chunks[k].tokens;
230230

231231
const uint64_t n_toks = inp.size();
232232

233233
// encode if at capacity
234-
if (batch.n_tokens + n_toks > n_batch) {
234+
if (batch.n_tokens + n_toks > n_batch || s >= llama_n_seq_max(ctx)) {
235235
float * out = emb + p * n_embd;
236236
batch_process(ctx, batch, out, s, n_embd);
237237
common_batch_clear(batch);

‎ggml/src/ggml-cuda/CMakeLists.txt‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,17 @@ if (CUDAToolkit_FOUND)
4848
endif()
4949

5050
if (CUDAToolkit_VERSION VERSION_GREATER_EQUAL "12.8")
51-
list(APPEND ARCH_LIST "120a-real")
51+
# The CUDA architecture 120f-virtual would in principle work for Blackwell support
52+
# but the newly added "f" suffix conflicted with a preexising regex for validating CUDA architectures in CMake.
53+
# So either a recent CMake version or one with the backported fix is needed.
54+
# The following versions should work:
55+
# - CMake >= v3.31.8 && CMake < v4.0.0
56+
# - CMake >= v4.0.2
57+
# This is NOT documented in the CMake release notes,
58+
# check Modules/Internal/CMakeCUDAArchitecturesValidate.cmake in the CMake git repository instead.
59+
# However, the architectures 120a-real and 121a-real should work with basically any CMake version and
60+
# until the release of e.g. Rubin there is no benefit to shipping virtual architectures for Blackwell.
61+
list(APPEND ARCH_LIST "120a-real 121a-real")
5262
endif()
5363

5464
set(CMAKE_CUDA_ARCHITECTURES ${ARCH_LIST})
@@ -79,7 +89,7 @@ if (CUDAToolkit_FOUND)
7989
else()
8090
foreach(ARCH ${CMAKE_CUDA_ARCHITECTURES})
8191
if(ARCH MATCHES "^12[0-9](-real|-virtual)?$")
82-
message(FATAL_ERROR "Compute capability ${ARCH} used, use ${ARCH}a or ${ARCH}f for Blackwell specific optimizations")
92+
message(FATAL_ERROR "Compute capability ${ARCH} used, use ${ARCH}a or ${ARCH}f for Blackwell-specific optimizations")
8393
endif()
8494
endforeach()
8595
endif()

‎ggml/src/ggml-cuda/cumsum.cu‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,20 @@ static __global__ void cumsum_cub_kernel(
6161

6262
// Add offset to each item and store
6363
T thread_offset = thread_prefix - thread_sum + block_carry;
64-
#pragma unroll
64+
#pragma unroll
6565
for (int i = 0; i < UNROLL_FACTOR; i++) {
6666
int64_t idx = start + tid * UNROLL_FACTOR + i;
6767
if (idx < ne00) {
6868
dst_row[idx] = items[i] + thread_offset;
6969
}
7070
}
7171

72+
__syncthreads();
73+
7274
// Update carry for next tile
7375
if (tid == 0) {
7476
block_carry += block_total;
7577
}
76-
__syncthreads();
7778
}
7879
#else
7980
NO_DEVICE_CODE;
@@ -175,11 +176,12 @@ static __global__ void cumsum_kernel(
175176
}
176177
}
177178

179+
__syncthreads();
180+
178181
// Update carry for next chunk
179182
if (tid == 0) {
180183
*s_carry += *s_chunk_total;
181184
}
182-
__syncthreads();
183185
}
184186
}
185187

‎ggml/src/ggml-cuda/ggml-cuda.cu‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,15 +2211,15 @@ static void ggml_cuda_mul_mat(ggml_backend_cuda_context & ctx, const ggml_tensor
22112211

22122212
const int cc = ggml_cuda_info().devices[id].cc;
22132213
const int warp_size = ggml_cuda_info().devices[id].warp_size;
2214-
use_mul_mat_q = use_mul_mat_q && ggml_cuda_should_use_mmq(src0->type, cc, src1->ne[1]);
2214+
use_mul_mat_q = use_mul_mat_q && ggml_cuda_should_use_mmq(src0->type, cc, src1->ne[1], /*n_experts=*/0);
22152215
use_mul_mat_f = use_mul_mat_f && ggml_cuda_should_use_mmf(src0->type, cc, warp_size, src0->ne, src0->nb, src1->ne[1], /*mul_mat_id=*/false);
22162216
use_mul_mat_vec_f = use_mul_mat_vec_f && ggml_cuda_should_use_mmvf(src0->type, cc, src0->ne, src0->nb, src1->ne[1]);
22172217
any_gpus_with_slow_fp16 = any_gpus_with_slow_fp16 || !fast_fp16_hardware_available(cc);
22182218
}
22192219
} else {
22202220
const int cc = ggml_cuda_info().devices[ctx.device].cc;
22212221
const int warp_size = ggml_cuda_info().devices[ctx.device].warp_size;
2222-
use_mul_mat_q = use_mul_mat_q && ggml_cuda_should_use_mmq(src0->type, cc, src1->ne[1]);
2222+
use_mul_mat_q = use_mul_mat_q && ggml_cuda_should_use_mmq(src0->type, cc, src1->ne[1], /*n_experts=*/0);
22232223
use_mul_mat_f = use_mul_mat_f && ggml_cuda_should_use_mmf(src0->type, cc, warp_size, src0->ne, src0->nb, src1->ne[1], /*mul_mat_id=*/false);
22242224
use_mul_mat_vec_f = use_mul_mat_vec_f && ggml_cuda_should_use_mmvf(src0->type, cc, src0->ne, src0->nb, src1->ne[1]);
22252225
any_gpus_with_slow_fp16 = any_gpus_with_slow_fp16 || !fast_fp16_hardware_available(cc);
@@ -2287,7 +2287,7 @@ static void ggml_cuda_mul_mat_id(ggml_backend_cuda_context & ctx, ggml_tensor *
22872287
return;
22882288
}
22892289

2290-
if (ggml_cuda_should_use_mmq(src0->type, cc, ne12)) {
2290+
if (ggml_cuda_should_use_mmq(src0->type, cc, ne12, /*n_experts=*/ne02)) {
22912291
ggml_cuda_mul_mat_q(ctx, src0, src1, ids, dst);
22922292
return;
22932293
}

‎ggml/src/ggml-cuda/mmq.cu‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ void ggml_cuda_op_mul_mat_q(
259259
GGML_UNUSED_VARS(src1, dst, src1_ddf_i, src1_padded_row_size);
260260
}
261261

262-
bool ggml_cuda_should_use_mmq(enum ggml_type type, int cc, int64_t ne11) {
262+
bool ggml_cuda_should_use_mmq(enum ggml_type type, int cc, int64_t ne11, int64_t n_experts) {
263263
#ifdef GGML_CUDA_FORCE_CUBLAS
264264
return false;
265265
#endif // GGML_CUDA_FORCE_CUBLAS
@@ -320,7 +320,10 @@ bool ggml_cuda_should_use_mmq(enum ggml_type type, int cc, int64_t ne11) {
320320
if (GGML_CUDA_CC_IS_CDNA3(cc)) {
321321
return true;
322322
}
323-
if (ne11 <= 128 || type == GGML_TYPE_Q4_0 || type == GGML_TYPE_Q4_1 || type == GGML_TYPE_Q5_0 || type == GGML_TYPE_Q5_1) {
323+
if (n_experts > 64 || ne11 <= 128) {
324+
return true;
325+
}
326+
if (type == GGML_TYPE_Q4_0 || type == GGML_TYPE_Q4_1 || type == GGML_TYPE_Q5_0 || type == GGML_TYPE_Q5_1) {
324327
return true;
325328
}
326329
if (ne11 <= 256 && (type == GGML_TYPE_Q4_K || type == GGML_TYPE_Q5_K)) {

‎ggml/src/ggml-cuda/mmq.cuh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4082,4 +4082,4 @@ void ggml_cuda_op_mul_mat_q(
40824082
const char * src1_ddq_i, float * dst_dd_i, const int64_t row_low, const int64_t row_high, const int64_t src1_ncols,
40834083
const int64_t src1_padded_row_size, cudaStream_t stream);
40844084

4085-
bool ggml_cuda_should_use_mmq(enum ggml_type type, int cc, int64_t ne11);
4085+
bool ggml_cuda_should_use_mmq(enum ggml_type type, int cc, int64_t ne11, int64_t n_experts);

‎tools/completion/completion.cpp‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ int main(int argc, char ** argv) {
175175
struct ggml_threadpool_params tpp =
176176
ggml_threadpool_params_from_cpu_params(params.cpuparams);
177177

178-
set_process_priority(params.cpuparams.priority);
178+
if (!set_process_priority(params.cpuparams.priority)) {
179+
LOG_ERR("%s: error: failed to set process priority\n", __func__);
180+
return 1;
181+
}
179182

180183
struct ggml_threadpool * threadpool_batch = NULL;
181184
if (!ggml_threadpool_params_match(&tpp, &tpp_batch)) {

‎tools/llama-bench/llama-bench.cpp‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2037,7 +2037,10 @@ int main(int argc, char ** argv) {
20372037
llama_backend_init();
20382038
llama_numa_init(params.numa);
20392039

2040-
set_process_priority(params.prio);
2040+
if (!set_process_priority(params.prio)) {
2041+
fprintf(stderr, "%s: error: failed to set process priority\n", __func__);
2042+
return 1;
2043+
}
20412044

20422045
// initialize printer
20432046
std::unique_ptr<printer> p = create_printer(params.output_format);

0 commit comments

Comments
 (0)