@@ -762,6 +762,7 @@ struct whisper_context {
762
762
whisper_state * state = nullptr ;
763
763
764
764
std::string path_model; // populated by whisper_init_from_file()
765
+ whisper_context_params params;
765
766
};
766
767
767
768
static void whisper_default_log (const char * text) {
@@ -2917,12 +2918,13 @@ struct whisper_state * whisper_init_state(whisper_context * ctx) {
2917
2918
}
2918
2919
2919
2920
#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 " , __func__);
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 " , __func__);
2925
+ delete state;
2926
+ return nullptr ;
2927
+ }
2926
2928
}
2927
2929
2928
2930
if (state->ctx_metal ) {
@@ -3030,7 +3032,7 @@ int whisper_ctx_init_openvino_encoder(
3030
3032
#endif
3031
3033
}
3032
3034
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 ) {
3034
3036
log (" %s: loading model from '%s'\n " , __func__, path_model);
3035
3037
3036
3038
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
3059
3061
fin->close ();
3060
3062
};
3061
3063
3062
- auto ctx = whisper_init_no_state (&loader);
3064
+ auto ctx = whisper_init_no_state (&loader, params );
3063
3065
3064
3066
if (ctx) {
3065
3067
ctx->path_model = path_model;
@@ -3068,7 +3070,7 @@ struct whisper_context * whisper_init_from_file_no_state(const char * path_model
3068
3070
return ctx;
3069
3071
}
3070
3072
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 ) {
3072
3074
struct buf_context {
3073
3075
uint8_t * buffer;
3074
3076
size_t size;
@@ -3102,13 +3104,14 @@ struct whisper_context * whisper_init_from_buffer_no_state(void * buffer, size_t
3102
3104
3103
3105
loader.close = [](void * /* ctx*/ ) { };
3104
3106
3105
- return whisper_init_no_state (&loader);
3107
+ return whisper_init_no_state (&loader, params );
3106
3108
}
3107
3109
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 ) {
3109
3111
ggml_time_init ();
3110
3112
3111
3113
whisper_context * ctx = new whisper_context;
3114
+ ctx->params = params;
3112
3115
3113
3116
if (!whisper_model_load (loader, *ctx)) {
3114
3117
loader->close (loader->context );
@@ -3122,8 +3125,8 @@ struct whisper_context * whisper_init_no_state(struct whisper_model_loader * loa
3122
3125
return ctx;
3123
3126
}
3124
3127
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 );
3127
3130
if (!ctx) {
3128
3131
return nullptr ;
3129
3132
}
@@ -3137,8 +3140,8 @@ struct whisper_context * whisper_init_from_file(const char * path_model) {
3137
3140
return ctx;
3138
3141
}
3139
3142
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 );
3142
3145
if (!ctx) {
3143
3146
return nullptr ;
3144
3147
}
@@ -3152,8 +3155,8 @@ struct whisper_context * whisper_init_from_buffer(void * buffer, size_t buffer_s
3152
3155
return ctx;
3153
3156
}
3154
3157
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 );
3157
3160
if (!ctx) {
3158
3161
return nullptr ;
3159
3162
}
0 commit comments