@@ -762,6 +762,7 @@ struct whisper_context {
762762    whisper_state * state = nullptr ;
763763
764764    std::string path_model; //  populated by whisper_init_from_file()
765+     whisper_context_params params;
765766};
766767
767768static  void  whisper_default_log (const  char  * text) {
@@ -2917,12 +2918,13 @@ struct whisper_state * whisper_init_state(whisper_context * ctx) {
29172918    }
29182919
29192920#ifdef  GGML_USE_METAL
2920-     //  TODO: Param for enable GPU
2921-     state->ctx_metal  = ggml_metal_init (1 );
2922-     if  (!state->ctx_metal ) {
2923-         log (" %s: ggml_metal_init() failed\n " 
2924-         delete  state;
2925-         return  nullptr ;
2921+     if  (ctx->params .use_gpu ) {
2922+         state->ctx_metal  = ggml_metal_init (1 );
2923+         if  (!state->ctx_metal ) {
2924+             log (" %s: ggml_metal_init() failed\n " 
2925+             delete  state;
2926+             return  nullptr ;
2927+         }
29262928    }
29272929
29282930    if  (state->ctx_metal ) {
@@ -3030,7 +3032,7 @@ int whisper_ctx_init_openvino_encoder(
30303032#endif 
30313033}
30323034
3033- struct  whisper_context  * whisper_init_from_file_no_state (const  char  * path_model) {
3035+ struct  whisper_context  * whisper_init_from_file_no_state (const  char  * path_model, whisper_context_params params ) {
30343036    log (" %s: loading model from '%s'\n " 
30353037
30363038    auto  fin = std::ifstream (path_model, std::ios::binary);
@@ -3059,7 +3061,7 @@ struct whisper_context * whisper_init_from_file_no_state(const char * path_model
30593061        fin->close ();
30603062    };
30613063
3062-     auto  ctx = whisper_init_no_state (&loader);
3064+     auto  ctx = whisper_init_no_state (&loader, params );
30633065
30643066    if  (ctx) {
30653067        ctx->path_model  = path_model;
@@ -3068,7 +3070,7 @@ struct whisper_context * whisper_init_from_file_no_state(const char * path_model
30683070    return  ctx;
30693071}
30703072
3071- struct  whisper_context  * whisper_init_from_buffer_no_state (void  * buffer, size_t  buffer_size) {
3073+ struct  whisper_context  * whisper_init_from_buffer_no_state (void  * buffer, size_t  buffer_size, whisper_context_params params ) {
30723074    struct  buf_context  {
30733075        uint8_t * buffer;
30743076        size_t  size;
@@ -3102,13 +3104,14 @@ struct whisper_context * whisper_init_from_buffer_no_state(void * buffer, size_t
31023104
31033105    loader.close  = [](void  * /* ctx*/ 
31043106
3105-     return  whisper_init_no_state (&loader);
3107+     return  whisper_init_no_state (&loader, params );
31063108}
31073109
3108- struct  whisper_context  * whisper_init_no_state (struct  whisper_model_loader  * loader) {
3110+ struct  whisper_context  * whisper_init_no_state (struct  whisper_model_loader  * loader, whisper_context_params params ) {
31093111    ggml_time_init ();
31103112
31113113    whisper_context * ctx = new  whisper_context;
3114+     ctx->params  = params;
31123115
31133116    if  (!whisper_model_load (loader, *ctx)) {
31143117        loader->close (loader->context );
@@ -3122,8 +3125,8 @@ struct whisper_context * whisper_init_no_state(struct whisper_model_loader * loa
31223125    return  ctx;
31233126}
31243127
3125- struct  whisper_context  * whisper_init_from_file (const  char  * path_model) {
3126-     whisper_context * ctx = whisper_init_from_file_no_state (path_model);
3128+ struct  whisper_context  * whisper_init_from_file (const  char  * path_model, whisper_context_params params ) {
3129+     whisper_context * ctx = whisper_init_from_file_no_state (path_model, params );
31273130    if  (!ctx) {
31283131        return  nullptr ;
31293132    }
@@ -3137,8 +3140,8 @@ struct whisper_context * whisper_init_from_file(const char * path_model) {
31373140    return  ctx;
31383141}
31393142
3140- struct  whisper_context  * whisper_init_from_buffer (void  * buffer, size_t  buffer_size) {
3141-     whisper_context * ctx = whisper_init_from_buffer_no_state (buffer, buffer_size);
3143+ struct  whisper_context  * whisper_init_from_buffer (void  * buffer, size_t  buffer_size, whisper_context_params params ) {
3144+     whisper_context * ctx = whisper_init_from_buffer_no_state (buffer, buffer_size, params );
31423145    if  (!ctx) {
31433146        return  nullptr ;
31443147    }
@@ -3152,8 +3155,8 @@ struct whisper_context * whisper_init_from_buffer(void * buffer, size_t buffer_s
31523155    return  ctx;
31533156}
31543157
3155- struct  whisper_context  * whisper_init (struct  whisper_model_loader  * loader) {
3156-     whisper_context * ctx = whisper_init_no_state (loader);
3158+ struct  whisper_context  * whisper_init (struct  whisper_model_loader  * loader, whisper_context_params params ) {
3159+     whisper_context * ctx = whisper_init_no_state (loader, params );
31573160    if  (!ctx) {
31583161        return  nullptr ;
31593162    }
0 commit comments