metal : init

This commit is contained in:
Georgi Gerganov 2023-09-10 18:38:34 +03:00
parent 9b14418863
commit fbc3f8033e
No known key found for this signature in database
GPG Key ID: 449E073F9DC10735
2 changed files with 29 additions and 0 deletions

View File

@ -182,6 +182,13 @@ ifdef WHISPER_COREML_ALLOW_FALLBACK
endif
endif
ifndef WHISPER_NO_METAL
ifeq ($(UNAME_S),Darwin)
CXXFLAGS += -DGGML_USE_METAL
LDFLAGS += -framework Foundation -framework Metal -framework MetalKit
endif
endif
ifdef WHISPER_OPENBLAS
CFLAGS += -DGGML_USE_OPENBLAS -I/usr/local/include/openblas -I/usr/include/openblas
LDFLAGS += -lopenblas
@ -303,6 +310,13 @@ whisper-encoder-impl.o: coreml/whisper-encoder-impl.m coreml/whisper-encoder-imp
WHISPER_OBJ += whisper.o whisper-encoder.o whisper-encoder-impl.o
endif
ifndef WHISPER_NO_METAL
ggml-metal.o: ggml-metal.m ggml-metal.h
$(CC) $(CFLAGS) -c $< -o $@
WHISPER_OBJ += ggml-metal.o
endif
libwhisper.a: ggml.o $(WHISPER_OBJ)
$(AR) rcs libwhisper.a ggml.o $(WHISPER_OBJ)

View File

@ -3,6 +3,10 @@
#include "coreml/whisper-encoder.h"
#endif
#ifdef GGML_USE_METAL
# include "ggml-metal.h"
#endif
#ifdef WHISPER_USE_OPENVINO
#include "openvino/whisper-openvino-encoder.h"
#endif
@ -689,6 +693,10 @@ struct whisper_state {
whisper_coreml_context * ctx_coreml = nullptr;
#endif
#ifdef GGML_USE_METAL
ggml_metal_context * ctx_metal = nullptr;
#endif
#ifdef WHISPER_USE_OPENVINO
whisper_openvino_context * ctx_openvino = nullptr;
#endif
@ -3032,6 +3040,13 @@ void whisper_free_state(struct whisper_state * state)
}
#endif
#ifdef GGML_USE_METAL
if (state->ctx_metal) {
ggml_metal_free(state->ctx_metal);
state->ctx_metal = nullptr;
}
#endif
#ifdef WHISPER_USE_OPENVINO
if (state->ctx_openvino != nullptr) {
whisper_openvino_free(state->ctx_openvino);