whisper : adding <stddef.h> needed for size_t + code style

pull/353/head
Georgi Gerganov 3 years ago
parent 48389940be
commit 06130452b6
No known key found for this signature in database
GPG Key ID: 449E073F9DC10735

@ -463,7 +463,7 @@ static bool whisper_model_load(struct whisper_model_loader * loader, whisper_con
uint32_t magic; uint32_t magic;
read_safe(loader, magic); read_safe(loader, magic);
if (magic != 0x67676d6c) { if (magic != 0x67676d6c) {
fprintf(stderr, "%s: invalid model file (bad magic)\n", __func__); fprintf(stderr, "%s: invalid model data (bad magic)\n", __func__);
return false; return false;
} }
} }
@ -2276,6 +2276,7 @@ struct whisper_context * whisper_init_from_buffer(void * buffer, size_t buffer_s
fprintf(stderr, "%s: loading model from buffer\n", __func__); fprintf(stderr, "%s: loading model from buffer\n", __func__);
loader.context = &ctx; loader.context = &ctx;
loader.read = [](void * ctx, void * output, size_t read_size) { loader.read = [](void * ctx, void * output, size_t read_size) {
buf_context * buf = reinterpret_cast<buf_context *>(ctx); buf_context * buf = reinterpret_cast<buf_context *>(ctx);
@ -2293,7 +2294,7 @@ struct whisper_context * whisper_init_from_buffer(void * buffer, size_t buffer_s
return buf->current_offset >= buf->size; return buf->current_offset >= buf->size;
}; };
loader.close = [](void * ctx) { }; loader.close = [](void * /*ctx*/) { };
return whisper_init(&loader); return whisper_init(&loader);
} }
@ -2315,6 +2316,7 @@ struct whisper_context * whisper_init(struct whisper_model_loader * loader) {
} }
ctx->t_load_us = ggml_time_us() - t_start_us; ctx->t_load_us = ggml_time_us() - t_start_us;
loader->close(loader->context); loader->close(loader->context);
return ctx; return ctx;

@ -1,6 +1,7 @@
#ifndef WHISPER_H #ifndef WHISPER_H
#define WHISPER_H #define WHISPER_H
#include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
@ -85,15 +86,16 @@ extern "C" {
} whisper_token_data; } whisper_token_data;
typedef struct whisper_model_loader { typedef struct whisper_model_loader {
void* context; void * context;
size_t (*read)(void * ctx, void * output, size_t read_size); size_t (*read)(void * ctx, void * output, size_t read_size);
bool (*eof)(void * ctx); bool (*eof)(void * ctx);
void (*close)(void * ctx); void (*close)(void * ctx);
} whisper_model_loader; } whisper_model_loader;
// Allocates all memory needed for the model and loads the model from the given file. // Various function to load a ggml whisper model.
// Returns NULL on failure. // Allocates (almost) all memory needed for the model.
// Return NULL on failure
WHISPER_API struct whisper_context * whisper_init_from_file(const char * path_model); WHISPER_API struct whisper_context * whisper_init_from_file(const char * path_model);
WHISPER_API struct whisper_context * whisper_init_from_buffer(void * buffer, size_t buffer_size); WHISPER_API struct whisper_context * whisper_init_from_buffer(void * buffer, size_t buffer_size);
WHISPER_API struct whisper_context * whisper_init(struct whisper_model_loader * loader); WHISPER_API struct whisper_context * whisper_init(struct whisper_model_loader * loader);

Loading…
Cancel
Save