metal : fix kernel init + fix compile options
This commit is contained in:
parent
8437ff5ee2
commit
cd160f85f1
1 changed files with 14 additions and 9 deletions
23
ggml-metal.m
23
ggml-metal.m
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
#define GGML_MAX_CONCUR (2*GGML_DEFAULT_GRAPH_SIZE)
|
#define GGML_MAX_CONCUR (2*GGML_DEFAULT_GRAPH_SIZE)
|
||||||
|
|
||||||
#define GGML_METAL_MAX_KERNELS 1024
|
#define GGML_METAL_MAX_KERNELS 256
|
||||||
|
|
||||||
struct ggml_metal_buffer {
|
struct ggml_metal_buffer {
|
||||||
const char * name;
|
const char * name;
|
||||||
|
@ -294,16 +294,16 @@ struct ggml_metal_context * ggml_metal_init(int n_cb) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
MTLCompileOptions* options = nil;
|
// dictionary of preprocessor macros
|
||||||
|
NSMutableDictionary * prep = [NSMutableDictionary dictionary];
|
||||||
|
|
||||||
#ifdef GGML_QKK_64
|
#ifdef GGML_QKK_64
|
||||||
options = [MTLCompileOptions new];
|
prep[@"QK_K"] = @(64);
|
||||||
options.preprocessorMacros = @{ @"QK_K" : @(64) };
|
|
||||||
#endif
|
#endif
|
||||||
// try to disable fast-math
|
|
||||||
// NOTE: this seems to have no effect whatsoever
|
MTLCompileOptions* options = [MTLCompileOptions new];
|
||||||
// instead, in order to disable fast-math, we have to build default.metallib from the command line
|
options.preprocessorMacros = prep;
|
||||||
// using xcrun -sdk macosx metal -fno-fast-math -c ggml-metal.metal -o ggml-metal.air
|
|
||||||
// and go through the "pre-compiled library found" path above
|
|
||||||
//[options setFastMathEnabled:false];
|
//[options setFastMathEnabled:false];
|
||||||
|
|
||||||
ctx->library = [ctx->device newLibraryWithSource:src options:options error:&error];
|
ctx->library = [ctx->device newLibraryWithSource:src options:options error:&error];
|
||||||
|
@ -355,6 +355,11 @@ struct ggml_metal_context * ggml_metal_init(int n_cb) {
|
||||||
{
|
{
|
||||||
NSError * error = nil;
|
NSError * error = nil;
|
||||||
|
|
||||||
|
for (int i = 0; i < GGML_METAL_MAX_KERNELS; ++i) {
|
||||||
|
ctx->kernels[i].function = nil;
|
||||||
|
ctx->kernels[i].pipeline = nil;
|
||||||
|
}
|
||||||
|
|
||||||
#define GGML_METAL_ADD_KERNEL(e, name, family) \
|
#define GGML_METAL_ADD_KERNEL(e, name, family) \
|
||||||
if ([ctx->device supportsFamily:(family)]) { \
|
if ([ctx->device supportsFamily:(family)]) { \
|
||||||
struct ggml_metal_kernel * kernel = &ctx->kernels[e]; \
|
struct ggml_metal_kernel * kernel = &ctx->kernels[e]; \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue