Skip to content

Commit f78aea7

Browse files
committed
whisper : impl whisper_timings struct & api
1 parent 9fcf1d1 commit f78aea7

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

include/whisper.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,14 @@ extern "C" {
423423
WHISPER_API whisper_token whisper_token_transcribe(struct whisper_context * ctx);
424424

425425
// Performance information from the default state.
426+
struct whisper_timings {
427+
float sample_ms;
428+
float encode_ms;
429+
float decode_ms;
430+
float batchd_ms;
431+
float prompt_ms;
432+
};
433+
WHISPER_API struct whisper_timings whisper_get_timings(struct whisper_context * ctx);
426434
WHISPER_API void whisper_print_timings(struct whisper_context * ctx);
427435
WHISPER_API void whisper_reset_timings(struct whisper_context * ctx);
428436

src/whisper.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4186,6 +4186,30 @@ whisper_token whisper_token_transcribe(struct whisper_context * ctx) {
41864186
return ctx->vocab.token_transcribe;
41874187
}
41884188

4189+
struct whisper_timings whisper_get_timings(struct whisper_context * ctx) {
4190+
if (ctx->state == nullptr) {
4191+
return whisper_timings {
4192+
.sample_ms = 0,
4193+
.encode_ms = 0,
4194+
.decode_ms = 0,
4195+
.batchd_ms = 0,
4196+
.prompt_ms = 0,
4197+
};
4198+
}
4199+
const int32_t n_sample = std::max(1, ctx->state->n_sample);
4200+
const int32_t n_encode = std::max(1, ctx->state->n_encode);
4201+
const int32_t n_decode = std::max(1, ctx->state->n_decode);
4202+
const int32_t n_batchd = std::max(1, ctx->state->n_batchd);
4203+
const int32_t n_prompt = std::max(1, ctx->state->n_prompt);
4204+
return whisper_timings {
4205+
.sample_ms = 1e-3f * ctx->state->t_sample_us / n_sample,
4206+
.encode_ms = 1e-3f * ctx->state->t_encode_us / n_encode,
4207+
.decode_ms = 1e-3f * ctx->state->t_decode_us / n_decode,
4208+
.batchd_ms = 1e-3f * ctx->state->t_batchd_us / n_batchd,
4209+
.prompt_ms = 1e-3f * ctx->state->t_prompt_us / n_prompt,
4210+
};
4211+
}
4212+
41894213
void whisper_print_timings(struct whisper_context * ctx) {
41904214
const int64_t t_end_us = ggml_time_us();
41914215

0 commit comments

Comments
 (0)