return GGUF_TYPE_NAME[type];
}
-int gguf_get_version(struct gguf_context * ctx) {
+int gguf_get_version(const struct gguf_context * ctx) {
return ctx->header.version;
}
-size_t gguf_get_alignment(struct gguf_context * ctx) {
+size_t gguf_get_alignment(const struct gguf_context * ctx) {
return ctx->alignment;
}
-size_t gguf_get_data_offset(struct gguf_context * ctx) {
+size_t gguf_get_data_offset(const struct gguf_context * ctx) {
return ctx->offset;
}
-void * gguf_get_data(struct gguf_context * ctx) {
+void * gguf_get_data(const struct gguf_context * ctx) {
return ctx->data;
}
-int gguf_get_n_kv(struct gguf_context * ctx) {
+int gguf_get_n_kv(const struct gguf_context * ctx) {
return ctx->header.n_kv;
}
-int gguf_find_key(struct gguf_context * ctx, const char * key) {
+int gguf_find_key(const struct gguf_context * ctx, const char * key) {
// return -1 if key not found
int keyfound = -1;
return keyfound;
}
-const char * gguf_get_key(struct gguf_context * ctx, int i) {
+const char * gguf_get_key(const struct gguf_context * ctx, int i) {
return ctx->kv[i].key.data;
}
-enum gguf_type gguf_get_kv_type(struct gguf_context * ctx, int i) {
+enum gguf_type gguf_get_kv_type(const struct gguf_context * ctx, int i) {
return ctx->kv[i].type;
}
-enum gguf_type gguf_get_arr_type(struct gguf_context * ctx, int i) {
+enum gguf_type gguf_get_arr_type(const struct gguf_context * ctx, int i) {
return ctx->kv[i].value.arr.type;
}
-const void * gguf_get_arr_data(struct gguf_context * ctx, int i) {
+const void * gguf_get_arr_data(const struct gguf_context * ctx, int i) {
return ctx->kv[i].value.arr.data;
}
-const char * gguf_get_arr_str(struct gguf_context * ctx, int key_id, int i) {
+const char * gguf_get_arr_str(const struct gguf_context * ctx, int key_id, int i) {
struct gguf_kv * kv = &ctx->kv[key_id];
struct gguf_str * str = &((struct gguf_str *) kv->value.arr.data)[i];
return str->data;
}
-int gguf_get_arr_n(struct gguf_context * ctx, int i) {
+int gguf_get_arr_n(const struct gguf_context * ctx, int i) {
return ctx->kv[i].value.arr.n;
}
-uint8_t gguf_get_val_u8(struct gguf_context * ctx, int i) {
+uint8_t gguf_get_val_u8(const struct gguf_context * ctx, int i) {
return ctx->kv[i].value.uint8;
}
-int8_t gguf_get_val_i8(struct gguf_context * ctx, int i) {
+int8_t gguf_get_val_i8(const struct gguf_context * ctx, int i) {
return ctx->kv[i].value.int8;
}
-uint16_t gguf_get_val_u16(struct gguf_context * ctx, int i) {
+uint16_t gguf_get_val_u16(const struct gguf_context * ctx, int i) {
return ctx->kv[i].value.uint16;
}
-int16_t gguf_get_val_i16(struct gguf_context * ctx, int i) {
+int16_t gguf_get_val_i16(const struct gguf_context * ctx, int i) {
return ctx->kv[i].value.int16;
}
-uint32_t gguf_get_val_u32(struct gguf_context * ctx, int i) {
+uint32_t gguf_get_val_u32(const struct gguf_context * ctx, int i) {
return ctx->kv[i].value.uint32;
}
-int32_t gguf_get_val_i32(struct gguf_context * ctx, int i) {
+int32_t gguf_get_val_i32(const struct gguf_context * ctx, int i) {
return ctx->kv[i].value.int32;
}
-float gguf_get_val_f32(struct gguf_context * ctx, int i) {
+float gguf_get_val_f32(const struct gguf_context * ctx, int i) {
return ctx->kv[i].value.float32;
}
-uint64_t gguf_get_val_u64(struct gguf_context * ctx, int i) {
+uint64_t gguf_get_val_u64(const struct gguf_context * ctx, int i) {
return ctx->kv[i].value.uint64;
}
-int64_t gguf_get_val_i64(struct gguf_context * ctx, int i) {
+int64_t gguf_get_val_i64(const struct gguf_context * ctx, int i) {
return ctx->kv[i].value.int64;
}
-double gguf_get_val_f64(struct gguf_context * ctx, int i) {
+double gguf_get_val_f64(const struct gguf_context * ctx, int i) {
return ctx->kv[i].value.float64;
}
-bool gguf_get_val_bool(struct gguf_context * ctx, int i) {
+bool gguf_get_val_bool(const struct gguf_context * ctx, int i) {
return ctx->kv[i].value.bool_;
}
-const char * gguf_get_val_str (struct gguf_context * ctx, int i) {
+const char * gguf_get_val_str (const struct gguf_context * ctx, int i) {
return ctx->kv[i].value.str.data;
}
-int gguf_get_n_tensors(struct gguf_context * ctx) {
+int gguf_get_n_tensors(const struct gguf_context * ctx) {
return ctx->header.n_tensors;
}
-int gguf_find_tensor(struct gguf_context * ctx, const char * name) {
+int gguf_find_tensor(const struct gguf_context * ctx, const char * name) {
// return -1 if tensor not found
int tensorfound = -1;
return tensorfound;
}
-size_t gguf_get_tensor_offset(struct gguf_context * ctx, int i) {
+size_t gguf_get_tensor_offset(const struct gguf_context * ctx, int i) {
return ctx->infos[i].offset;
}
-char * gguf_get_tensor_name(struct gguf_context * ctx, int i) {
+char * gguf_get_tensor_name(const struct gguf_context * ctx, int i) {
return ctx->infos[i].name.data;
}
buf->offset += el_size;
}
-static void gguf_write_to_buf(struct gguf_context * ctx, struct gguf_buf * buf, bool only_meta) {
+static void gguf_write_to_buf(const struct gguf_context * ctx, struct gguf_buf * buf, bool only_meta) {
// write header
gguf_bwrite_el(buf, &ctx->header.magic, sizeof(ctx->header.magic));
gguf_bwrite_el(buf, &ctx->header.version, sizeof(ctx->header.version));
}
}
-void gguf_write_to_file(struct gguf_context * ctx, const char * fname, bool only_meta) {
+void gguf_write_to_file(const struct gguf_context * ctx, const char * fname, bool only_meta) {
FILE * file = fopen(fname, "wb");
if (!file) {
GGML_ASSERT(false && "failed to open file for writing");
fclose(file);
}
-size_t gguf_get_meta_size(struct gguf_context * ctx) {
+size_t gguf_get_meta_size(const struct gguf_context * ctx) {
// no allocs - only compute size
struct gguf_buf buf = gguf_buf_init(0);
return buf.offset;
}
-void gguf_get_meta_data(struct gguf_context * ctx, void * data) {
+void gguf_get_meta_data(const struct gguf_context * ctx, void * data) {
struct gguf_buf buf = gguf_buf_init(16*1024);
gguf_write_to_buf(ctx, &buf, true);
# define GGML_DEPRECATED(func, hint) func
#endif
+#ifndef __GNUC__
+# define GGML_ATTRIBUTE_FORMAT(...)
+#elif defined(__MINGW32__)
+# define GGML_ATTRIBUTE_FORMAT(...) __attribute__((format(gnu_printf, __VA_ARGS__)))
+#else
+# define GGML_ATTRIBUTE_FORMAT(...) __attribute__((format(printf, __VA_ARGS__)))
+#endif
+
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
GGML_API const char * ggml_get_name (const struct ggml_tensor * tensor);
GGML_API struct ggml_tensor * ggml_set_name ( struct ggml_tensor * tensor, const char * name);
+ GGML_ATTRIBUTE_FORMAT(2, 3)
GGML_API struct ggml_tensor * ggml_format_name( struct ggml_tensor * tensor, const char * fmt, ...);
//
GGML_API const char * gguf_type_name(enum gguf_type type);
- GGML_API int gguf_get_version (struct gguf_context * ctx);
- GGML_API size_t gguf_get_alignment (struct gguf_context * ctx);
- GGML_API size_t gguf_get_data_offset(struct gguf_context * ctx);
- GGML_API void * gguf_get_data (struct gguf_context * ctx);
+ GGML_API int gguf_get_version (const struct gguf_context * ctx);
+ GGML_API size_t gguf_get_alignment (const struct gguf_context * ctx);
+ GGML_API size_t gguf_get_data_offset(const struct gguf_context * ctx);
+ GGML_API void * gguf_get_data (const struct gguf_context * ctx);
- GGML_API int gguf_get_n_kv(struct gguf_context * ctx);
- GGML_API int gguf_find_key(struct gguf_context * ctx, const char * key);
- GGML_API const char * gguf_get_key (struct gguf_context * ctx, int i);
+ GGML_API int gguf_get_n_kv(const struct gguf_context * ctx);
+ GGML_API int gguf_find_key(const struct gguf_context * ctx, const char * key);
+ GGML_API const char * gguf_get_key (const struct gguf_context * ctx, int i);
- GGML_API enum gguf_type gguf_get_kv_type (struct gguf_context * ctx, int i);
- GGML_API enum gguf_type gguf_get_arr_type(struct gguf_context * ctx, int i);
+ GGML_API enum gguf_type gguf_get_kv_type (const struct gguf_context * ctx, int i);
+ GGML_API enum gguf_type gguf_get_arr_type(const struct gguf_context * ctx, int i);
// results are undefined if the wrong type is used for the key
- GGML_API uint8_t gguf_get_val_u8 (struct gguf_context * ctx, int i);
- GGML_API int8_t gguf_get_val_i8 (struct gguf_context * ctx, int i);
- GGML_API uint16_t gguf_get_val_u16 (struct gguf_context * ctx, int i);
- GGML_API int16_t gguf_get_val_i16 (struct gguf_context * ctx, int i);
- GGML_API uint32_t gguf_get_val_u32 (struct gguf_context * ctx, int i);
- GGML_API int32_t gguf_get_val_i32 (struct gguf_context * ctx, int i);
- GGML_API float gguf_get_val_f32 (struct gguf_context * ctx, int i);
- GGML_API uint64_t gguf_get_val_u64 (struct gguf_context * ctx, int i);
- GGML_API int64_t gguf_get_val_i64 (struct gguf_context * ctx, int i);
- GGML_API double gguf_get_val_f64 (struct gguf_context * ctx, int i);
- GGML_API bool gguf_get_val_bool(struct gguf_context * ctx, int i);
- GGML_API const char * gguf_get_val_str (struct gguf_context * ctx, int i);
- GGML_API int gguf_get_arr_n (struct gguf_context * ctx, int i);
- GGML_API const void * gguf_get_arr_data(struct gguf_context * ctx, int i);
- GGML_API const char * gguf_get_arr_str (struct gguf_context * ctx, int key_id, int i);
-
- GGML_API int gguf_get_n_tensors (struct gguf_context * ctx);
- GGML_API int gguf_find_tensor (struct gguf_context * ctx, const char * name);
- GGML_API size_t gguf_get_tensor_offset(struct gguf_context * ctx, int i);
- GGML_API char * gguf_get_tensor_name (struct gguf_context * ctx, int i);
+ GGML_API uint8_t gguf_get_val_u8 (const struct gguf_context * ctx, int i);
+ GGML_API int8_t gguf_get_val_i8 (const struct gguf_context * ctx, int i);
+ GGML_API uint16_t gguf_get_val_u16 (const struct gguf_context * ctx, int i);
+ GGML_API int16_t gguf_get_val_i16 (const struct gguf_context * ctx, int i);
+ GGML_API uint32_t gguf_get_val_u32 (const struct gguf_context * ctx, int i);
+ GGML_API int32_t gguf_get_val_i32 (const struct gguf_context * ctx, int i);
+ GGML_API float gguf_get_val_f32 (const struct gguf_context * ctx, int i);
+ GGML_API uint64_t gguf_get_val_u64 (const struct gguf_context * ctx, int i);
+ GGML_API int64_t gguf_get_val_i64 (const struct gguf_context * ctx, int i);
+ GGML_API double gguf_get_val_f64 (const struct gguf_context * ctx, int i);
+ GGML_API bool gguf_get_val_bool(const struct gguf_context * ctx, int i);
+ GGML_API const char * gguf_get_val_str (const struct gguf_context * ctx, int i);
+ GGML_API int gguf_get_arr_n (const struct gguf_context * ctx, int i);
+ GGML_API const void * gguf_get_arr_data(const struct gguf_context * ctx, int i);
+ GGML_API const char * gguf_get_arr_str (const struct gguf_context * ctx, int key_id, int i);
+
+ GGML_API int gguf_get_n_tensors (const struct gguf_context * ctx);
+ GGML_API int gguf_find_tensor (const struct gguf_context * ctx, const char * name);
+ GGML_API size_t gguf_get_tensor_offset(const struct gguf_context * ctx, int i);
+ GGML_API char * gguf_get_tensor_name (const struct gguf_context * ctx, int i);
// overrides existing values or adds a new one
GGML_API void gguf_set_val_u8 (struct gguf_context * ctx, const char * key, uint8_t val);
//
// write the entire context to a binary file
- GGML_API void gguf_write_to_file(struct gguf_context * ctx, const char * fname, bool only_meta);
+ GGML_API void gguf_write_to_file(const struct gguf_context * ctx, const char * fname, bool only_meta);
// get the size in bytes of the meta data (header, kv pairs, tensor info) including padding
- GGML_API size_t gguf_get_meta_size(struct gguf_context * ctx);
- GGML_API void gguf_get_meta_data(struct gguf_context * ctx, void * data);
+ GGML_API size_t gguf_get_meta_size(const struct gguf_context * ctx);
+ GGML_API void gguf_get_meta_data(const struct gguf_context * ctx, void * data);
//
// system info