Skip to content

Commit 0867e69

Browse files
committed
whisper : avoid whisper_model_data wrapper
1 parent 66bb2e9 commit 0867e69

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

whisper.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -518,10 +518,6 @@ struct whisper_kv_cache {
518518
int n; // number of tokens currently in the cache
519519
};
520520

521-
struct whisper_model_data {
522-
ggml_backend_buffer_t buffer_main;
523-
};
524-
525521
struct whisper_model {
526522
e_model type = MODEL_UNKNOWN;
527523

@@ -556,11 +552,11 @@ struct whisper_model {
556552
std::vector<whisper_layer_encoder> layers_encoder;
557553
std::vector<whisper_layer_decoder> layers_decoder;
558554

559-
// context
555+
// ggml context that contains all the meta information about the model tensors
560556
struct ggml_context * ctx;
561557

562558
// the model backend data is read-only and can be shared between processors
563-
struct whisper_model_data * data;
559+
struct ggml_backend_buffer * buffer;
564560

565561
// tensors
566562
int n_loaded;
@@ -1283,8 +1279,6 @@ static bool whisper_model_load(struct whisper_model_loader * loader, whisper_con
12831279

12841280
// init backends
12851281
{
1286-
model.data = new whisper_model_data;
1287-
12881282
ggml_backend_t backend_gpu = NULL;
12891283

12901284
// initialize the backends
@@ -1323,17 +1317,17 @@ static bool whisper_model_load(struct whisper_model_loader * loader, whisper_con
13231317
size_main += ggml_nbytes(t.second) + ggml_tensor_overhead();
13241318
}
13251319

1326-
model.data->buffer_main = ggml_backend_alloc_buffer(wctx.backend, size_main);
1320+
model.buffer = ggml_backend_alloc_buffer(wctx.backend, size_main);
13271321

13281322
WHISPER_LOG_INFO("%s: %8s buffer size = %8.2f MB\n", __func__, ggml_backend_name(wctx.backend), size_main / 1024.0 / 1024.0);
13291323
}
13301324

1331-
ggml_allocr * alloc_main = ggml_allocr_new_from_buffer(model.data->buffer_main);
1325+
ggml_allocr * alloc = ggml_allocr_new_from_buffer(model.buffer);
13321326

13331327
// allocate tensors in the backend buffers
13341328
{
13351329
for (const auto & t : model.tensors) {
1336-
ggml_allocr_alloc(alloc_main, t.second);
1330+
ggml_allocr_alloc(alloc, t.second);
13371331
}
13381332
}
13391333

@@ -1455,7 +1449,7 @@ static bool whisper_model_load(struct whisper_model_loader * loader, whisper_con
14551449
}
14561450
}
14571451

1458-
ggml_allocr_free(alloc_main);
1452+
ggml_allocr_free(alloc);
14591453

14601454
wctx.t_load_us = ggml_time_us() - t_start_us;
14611455

@@ -3198,10 +3192,9 @@ void whisper_free(struct whisper_context * ctx) {
31983192
if (ctx->model.ctx) {
31993193
ggml_free(ctx->model.ctx);
32003194
}
3201-
if (ctx->model.data) {
3202-
ggml_backend_buffer_free(ctx->model.data->buffer_main);
32033195

3204-
delete ctx->model.data;
3196+
if (ctx->model.buffer) {
3197+
ggml_backend_buffer_free(ctx->model.buffer);
32053198
}
32063199

32073200
whisper_free_state(ctx->state);

0 commit comments

Comments
 (0)