@@ -20119,27 +20119,27 @@ const char * gguf_type_name(enum gguf_type type) {
20119
20119
return GGUF_TYPE_NAME[type];
20120
20120
}
20121
20121
20122
- int gguf_get_version(struct gguf_context * ctx) {
20122
+ int gguf_get_version(const struct gguf_context * ctx) {
20123
20123
return ctx->header.version;
20124
20124
}
20125
20125
20126
- size_t gguf_get_alignment(struct gguf_context * ctx) {
20126
+ size_t gguf_get_alignment(const struct gguf_context * ctx) {
20127
20127
return ctx->alignment;
20128
20128
}
20129
20129
20130
- size_t gguf_get_data_offset(struct gguf_context * ctx) {
20130
+ size_t gguf_get_data_offset(const struct gguf_context * ctx) {
20131
20131
return ctx->offset;
20132
20132
}
20133
20133
20134
- void * gguf_get_data(struct gguf_context * ctx) {
20134
+ void * gguf_get_data(const struct gguf_context * ctx) {
20135
20135
return ctx->data;
20136
20136
}
20137
20137
20138
- int gguf_get_n_kv(struct gguf_context * ctx) {
20138
+ int gguf_get_n_kv(const struct gguf_context * ctx) {
20139
20139
return ctx->header.n_kv;
20140
20140
}
20141
20141
20142
- int gguf_find_key(struct gguf_context * ctx, const char * key) {
20142
+ int gguf_find_key(const struct gguf_context * ctx, const char * key) {
20143
20143
// return -1 if key not found
20144
20144
int keyfound = -1;
20145
20145
@@ -20155,85 +20155,85 @@ int gguf_find_key(struct gguf_context * ctx, const char * key) {
20155
20155
return keyfound;
20156
20156
}
20157
20157
20158
- const char * gguf_get_key(struct gguf_context * ctx, int i) {
20158
+ const char * gguf_get_key(const struct gguf_context * ctx, int i) {
20159
20159
return ctx->kv[i].key.data;
20160
20160
}
20161
20161
20162
- enum gguf_type gguf_get_kv_type(struct gguf_context * ctx, int i) {
20162
+ enum gguf_type gguf_get_kv_type(const struct gguf_context * ctx, int i) {
20163
20163
return ctx->kv[i].type;
20164
20164
}
20165
20165
20166
- enum gguf_type gguf_get_arr_type(struct gguf_context * ctx, int i) {
20166
+ enum gguf_type gguf_get_arr_type(const struct gguf_context * ctx, int i) {
20167
20167
return ctx->kv[i].value.arr.type;
20168
20168
}
20169
20169
20170
- const void * gguf_get_arr_data(struct gguf_context * ctx, int i) {
20170
+ const void * gguf_get_arr_data(const struct gguf_context * ctx, int i) {
20171
20171
return ctx->kv[i].value.arr.data;
20172
20172
}
20173
20173
20174
- const char * gguf_get_arr_str(struct gguf_context * ctx, int key_id, int i) {
20174
+ const char * gguf_get_arr_str(const struct gguf_context * ctx, int key_id, int i) {
20175
20175
struct gguf_kv * kv = &ctx->kv[key_id];
20176
20176
struct gguf_str * str = &((struct gguf_str *) kv->value.arr.data)[i];
20177
20177
return str->data;
20178
20178
}
20179
20179
20180
- int gguf_get_arr_n(struct gguf_context * ctx, int i) {
20180
+ int gguf_get_arr_n(const struct gguf_context * ctx, int i) {
20181
20181
return ctx->kv[i].value.arr.n;
20182
20182
}
20183
20183
20184
- uint8_t gguf_get_val_u8(struct gguf_context * ctx, int i) {
20184
+ uint8_t gguf_get_val_u8(const struct gguf_context * ctx, int i) {
20185
20185
return ctx->kv[i].value.uint8;
20186
20186
}
20187
20187
20188
- int8_t gguf_get_val_i8(struct gguf_context * ctx, int i) {
20188
+ int8_t gguf_get_val_i8(const struct gguf_context * ctx, int i) {
20189
20189
return ctx->kv[i].value.int8;
20190
20190
}
20191
20191
20192
- uint16_t gguf_get_val_u16(struct gguf_context * ctx, int i) {
20192
+ uint16_t gguf_get_val_u16(const struct gguf_context * ctx, int i) {
20193
20193
return ctx->kv[i].value.uint16;
20194
20194
}
20195
20195
20196
- int16_t gguf_get_val_i16(struct gguf_context * ctx, int i) {
20196
+ int16_t gguf_get_val_i16(const struct gguf_context * ctx, int i) {
20197
20197
return ctx->kv[i].value.int16;
20198
20198
}
20199
20199
20200
- uint32_t gguf_get_val_u32(struct gguf_context * ctx, int i) {
20200
+ uint32_t gguf_get_val_u32(const struct gguf_context * ctx, int i) {
20201
20201
return ctx->kv[i].value.uint32;
20202
20202
}
20203
20203
20204
- int32_t gguf_get_val_i32(struct gguf_context * ctx, int i) {
20204
+ int32_t gguf_get_val_i32(const struct gguf_context * ctx, int i) {
20205
20205
return ctx->kv[i].value.int32;
20206
20206
}
20207
20207
20208
- float gguf_get_val_f32(struct gguf_context * ctx, int i) {
20208
+ float gguf_get_val_f32(const struct gguf_context * ctx, int i) {
20209
20209
return ctx->kv[i].value.float32;
20210
20210
}
20211
20211
20212
- uint64_t gguf_get_val_u64(struct gguf_context * ctx, int i) {
20212
+ uint64_t gguf_get_val_u64(const struct gguf_context * ctx, int i) {
20213
20213
return ctx->kv[i].value.uint64;
20214
20214
}
20215
20215
20216
- int64_t gguf_get_val_i64(struct gguf_context * ctx, int i) {
20216
+ int64_t gguf_get_val_i64(const struct gguf_context * ctx, int i) {
20217
20217
return ctx->kv[i].value.int64;
20218
20218
}
20219
20219
20220
- double gguf_get_val_f64(struct gguf_context * ctx, int i) {
20220
+ double gguf_get_val_f64(const struct gguf_context * ctx, int i) {
20221
20221
return ctx->kv[i].value.float64;
20222
20222
}
20223
20223
20224
- bool gguf_get_val_bool(struct gguf_context * ctx, int i) {
20224
+ bool gguf_get_val_bool(const struct gguf_context * ctx, int i) {
20225
20225
return ctx->kv[i].value.bool_;
20226
20226
}
20227
20227
20228
- const char * gguf_get_val_str (struct gguf_context * ctx, int i) {
20228
+ const char * gguf_get_val_str (const struct gguf_context * ctx, int i) {
20229
20229
return ctx->kv[i].value.str.data;
20230
20230
}
20231
20231
20232
- int gguf_get_n_tensors(struct gguf_context * ctx) {
20232
+ int gguf_get_n_tensors(const struct gguf_context * ctx) {
20233
20233
return ctx->header.n_tensors;
20234
20234
}
20235
20235
20236
- int gguf_find_tensor(struct gguf_context * ctx, const char * name) {
20236
+ int gguf_find_tensor(const struct gguf_context * ctx, const char * name) {
20237
20237
// return -1 if tensor not found
20238
20238
int tensorfound = -1;
20239
20239
@@ -20249,11 +20249,11 @@ int gguf_find_tensor(struct gguf_context * ctx, const char * name) {
20249
20249
return tensorfound;
20250
20250
}
20251
20251
20252
- size_t gguf_get_tensor_offset(struct gguf_context * ctx, int i) {
20252
+ size_t gguf_get_tensor_offset(const struct gguf_context * ctx, int i) {
20253
20253
return ctx->infos[i].offset;
20254
20254
}
20255
20255
20256
- char * gguf_get_tensor_name(struct gguf_context * ctx, int i) {
20256
+ char * gguf_get_tensor_name(const struct gguf_context * ctx, int i) {
20257
20257
return ctx->infos[i].name.data;
20258
20258
}
20259
20259
@@ -20536,7 +20536,7 @@ static void gguf_bwrite_el(struct gguf_buf * buf, const void * val, size_t el_si
20536
20536
buf->offset += el_size;
20537
20537
}
20538
20538
20539
- static void gguf_write_to_buf(struct gguf_context * ctx, struct gguf_buf * buf, bool only_meta) {
20539
+ static void gguf_write_to_buf(const struct gguf_context * ctx, struct gguf_buf * buf, bool only_meta) {
20540
20540
// write header
20541
20541
gguf_bwrite_el(buf, &ctx->header.magic, sizeof(ctx->header.magic));
20542
20542
gguf_bwrite_el(buf, &ctx->header.version, sizeof(ctx->header.version));
@@ -20651,7 +20651,7 @@ static void gguf_write_to_buf(struct gguf_context * ctx, struct gguf_buf * buf,
20651
20651
}
20652
20652
}
20653
20653
20654
- void gguf_write_to_file(struct gguf_context * ctx, const char * fname, bool only_meta) {
20654
+ void gguf_write_to_file(const struct gguf_context * ctx, const char * fname, bool only_meta) {
20655
20655
FILE * file = fopen(fname, "wb");
20656
20656
if (!file) {
20657
20657
GGML_ASSERT(false && "failed to open file for writing");
@@ -20668,7 +20668,7 @@ void gguf_write_to_file(struct gguf_context * ctx, const char * fname, bool only
20668
20668
fclose(file);
20669
20669
}
20670
20670
20671
- size_t gguf_get_meta_size(struct gguf_context * ctx) {
20671
+ size_t gguf_get_meta_size(const struct gguf_context * ctx) {
20672
20672
// no allocs - only compute size
20673
20673
struct gguf_buf buf = gguf_buf_init(0);
20674
20674
@@ -20677,7 +20677,7 @@ size_t gguf_get_meta_size(struct gguf_context * ctx) {
20677
20677
return buf.offset;
20678
20678
}
20679
20679
20680
- void gguf_get_meta_data(struct gguf_context * ctx, void * data) {
20680
+ void gguf_get_meta_data(const struct gguf_context * ctx, void * data) {
20681
20681
struct gguf_buf buf = gguf_buf_init(16*1024);
20682
20682
20683
20683
gguf_write_to_buf(ctx, &buf, true);
0 commit comments