Skip to content

Commit 515cfec

Browse files
committed
metal : fix Metal API debug warnings
1 parent 75c14f2 commit 515cfec

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ if (APPLE AND LLAMA_ACCELERATE)
155155
endif()
156156

157157
if (LLAMA_METAL)
158-
find_library(FOUNDATION_LIBRARY Foundation REQUIRED)
159-
find_library(METAL_FRAMEWORK Metal REQUIRED)
160-
find_library(METALKIT_FRAMEWORK MetalKit REQUIRED)
158+
find_library(FOUNDATION_LIBRARY Foundation REQUIRED)
159+
find_library(METAL_FRAMEWORK Metal REQUIRED)
160+
find_library(METALKIT_FRAMEWORK MetalKit REQUIRED)
161161

162162
message(STATUS "Metal framework found")
163163
set(GGML_HEADERS_METAL ggml-metal.h)

ggml-metal.m

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,7 @@ void ggml_metal_graph_compute(
12931293
[encoder setBytes:&pnb3 length:sizeof(pnb3) atIndex:26];
12941294
[encoder setBytes:&offs length:sizeof(offs) atIndex:27];
12951295

1296-
const int nth = MIN(1024, ne0);
1296+
const int nth = MIN((int) ctx->pipeline_add.maxTotalThreadsPerThreadgroup, ne00);
12971297

12981298
[encoder dispatchThreadgroups:MTLSizeMake(ne11, ne12, ne13) threadsPerThreadgroup:MTLSizeMake(nth, 1, 1)];
12991299
} break;
@@ -1793,8 +1793,9 @@ void ggml_metal_graph_compute(
17931793
[encoder setBytes:&r3 length:sizeof(r3) atIndex:17];
17941794
[encoder setBytes:&idx length:sizeof(idx) atIndex:18];
17951795
// TODO: how to make this an array? read Metal docs
1796-
for (int j = 0; j < n_as; ++j) {
1797-
struct ggml_tensor * src_cur = dst->src[2 + j];
1796+
for (int j = 0; j < 8; ++j) {
1797+
// NOTE: this is done like this to avoid uninitialized kernel arguments when n_as < 8
1798+
struct ggml_tensor * src_cur = dst->src[2 + (j % n_as)];
17981799

17991800
size_t offs_src_cur = 0;
18001801
id<MTLBuffer> id_src_cur = ggml_metal_get_buffer(ctx, src_cur, &offs_src_cur);
@@ -1917,8 +1918,9 @@ void ggml_metal_graph_compute(
19171918
[encoder setBytes:&r3 length:sizeof(r3) atIndex:21];
19181919
[encoder setBytes:&idx length:sizeof(idx) atIndex:22];
19191920
// TODO: how to make this an array? read Metal docs
1920-
for (int j = 0; j < n_as; ++j) {
1921-
struct ggml_tensor * src_cur = dst->src[2 + j];
1921+
for (int j = 0; j < 8; ++j) {
1922+
// NOTE: this is done like this to avoid uninitialized kernel arguments when n_as < 8
1923+
struct ggml_tensor * src_cur = dst->src[2 + (j % n_as)];
19221924

19231925
size_t offs_src_cur = 0;
19241926
id<MTLBuffer> id_src_cur = ggml_metal_get_buffer(ctx, src_cur, &offs_src_cur);

0 commit comments

Comments
 (0)