Skip to content

Commit 64c4759

Browse files
committed
sync : ggml (const correctness)
1 parent c02acb6 commit 64c4759

File tree

3 files changed

+75
-64
lines changed

3 files changed

+75
-64
lines changed

ggml-cuda.cu

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5745,6 +5745,7 @@ inline void ggml_cuda_op_rope(
57455745
(void) dst;
57465746
(void) src0_ddq_i;
57475747
(void) src1_ddf_i;
5748+
(void) i02;
57485749
(void) i1;
57495750
}
57505751

@@ -5780,6 +5781,7 @@ inline void ggml_cuda_op_alibi(
57805781
(void) src1;
57815782
(void) src0_ddq_i;
57825783
(void) src1_ddf_i;
5784+
(void) i02;
57835785
(void) i1;
57845786
}
57855787

ggml.c

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20119,27 +20119,27 @@ const char * gguf_type_name(enum gguf_type type) {
2011920119
return GGUF_TYPE_NAME[type];
2012020120
}
2012120121

20122-
int gguf_get_version(struct gguf_context * ctx) {
20122+
int gguf_get_version(const struct gguf_context * ctx) {
2012320123
return ctx->header.version;
2012420124
}
2012520125

20126-
size_t gguf_get_alignment(struct gguf_context * ctx) {
20126+
size_t gguf_get_alignment(const struct gguf_context * ctx) {
2012720127
return ctx->alignment;
2012820128
}
2012920129

20130-
size_t gguf_get_data_offset(struct gguf_context * ctx) {
20130+
size_t gguf_get_data_offset(const struct gguf_context * ctx) {
2013120131
return ctx->offset;
2013220132
}
2013320133

20134-
void * gguf_get_data(struct gguf_context * ctx) {
20134+
void * gguf_get_data(const struct gguf_context * ctx) {
2013520135
return ctx->data;
2013620136
}
2013720137

20138-
int gguf_get_n_kv(struct gguf_context * ctx) {
20138+
int gguf_get_n_kv(const struct gguf_context * ctx) {
2013920139
return ctx->header.n_kv;
2014020140
}
2014120141

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) {
2014320143
// return -1 if key not found
2014420144
int keyfound = -1;
2014520145

@@ -20155,85 +20155,85 @@ int gguf_find_key(struct gguf_context * ctx, const char * key) {
2015520155
return keyfound;
2015620156
}
2015720157

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) {
2015920159
return ctx->kv[i].key.data;
2016020160
}
2016120161

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) {
2016320163
return ctx->kv[i].type;
2016420164
}
2016520165

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) {
2016720167
return ctx->kv[i].value.arr.type;
2016820168
}
2016920169

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) {
2017120171
return ctx->kv[i].value.arr.data;
2017220172
}
2017320173

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) {
2017520175
struct gguf_kv * kv = &ctx->kv[key_id];
2017620176
struct gguf_str * str = &((struct gguf_str *) kv->value.arr.data)[i];
2017720177
return str->data;
2017820178
}
2017920179

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) {
2018120181
return ctx->kv[i].value.arr.n;
2018220182
}
2018320183

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) {
2018520185
return ctx->kv[i].value.uint8;
2018620186
}
2018720187

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) {
2018920189
return ctx->kv[i].value.int8;
2019020190
}
2019120191

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) {
2019320193
return ctx->kv[i].value.uint16;
2019420194
}
2019520195

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) {
2019720197
return ctx->kv[i].value.int16;
2019820198
}
2019920199

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) {
2020120201
return ctx->kv[i].value.uint32;
2020220202
}
2020320203

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) {
2020520205
return ctx->kv[i].value.int32;
2020620206
}
2020720207

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) {
2020920209
return ctx->kv[i].value.float32;
2021020210
}
2021120211

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) {
2021320213
return ctx->kv[i].value.uint64;
2021420214
}
2021520215

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) {
2021720217
return ctx->kv[i].value.int64;
2021820218
}
2021920219

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) {
2022120221
return ctx->kv[i].value.float64;
2022220222
}
2022320223

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) {
2022520225
return ctx->kv[i].value.bool_;
2022620226
}
2022720227

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) {
2022920229
return ctx->kv[i].value.str.data;
2023020230
}
2023120231

20232-
int gguf_get_n_tensors(struct gguf_context * ctx) {
20232+
int gguf_get_n_tensors(const struct gguf_context * ctx) {
2023320233
return ctx->header.n_tensors;
2023420234
}
2023520235

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) {
2023720237
// return -1 if tensor not found
2023820238
int tensorfound = -1;
2023920239

@@ -20249,11 +20249,11 @@ int gguf_find_tensor(struct gguf_context * ctx, const char * name) {
2024920249
return tensorfound;
2025020250
}
2025120251

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) {
2025320253
return ctx->infos[i].offset;
2025420254
}
2025520255

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) {
2025720257
return ctx->infos[i].name.data;
2025820258
}
2025920259

@@ -20536,7 +20536,7 @@ static void gguf_bwrite_el(struct gguf_buf * buf, const void * val, size_t el_si
2053620536
buf->offset += el_size;
2053720537
}
2053820538

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) {
2054020540
// write header
2054120541
gguf_bwrite_el(buf, &ctx->header.magic, sizeof(ctx->header.magic));
2054220542
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,
2065120651
}
2065220652
}
2065320653

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) {
2065520655
FILE * file = fopen(fname, "wb");
2065620656
if (!file) {
2065720657
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
2066820668
fclose(file);
2066920669
}
2067020670

20671-
size_t gguf_get_meta_size(struct gguf_context * ctx) {
20671+
size_t gguf_get_meta_size(const struct gguf_context * ctx) {
2067220672
// no allocs - only compute size
2067320673
struct gguf_buf buf = gguf_buf_init(0);
2067420674

@@ -20677,7 +20677,7 @@ size_t gguf_get_meta_size(struct gguf_context * ctx) {
2067720677
return buf.offset;
2067820678
}
2067920679

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) {
2068120681
struct gguf_buf buf = gguf_buf_init(16*1024);
2068220682

2068320683
gguf_write_to_buf(ctx, &buf, true);

ggml.h

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,14 @@
195195
# define GGML_DEPRECATED(func, hint) func
196196
#endif
197197

198+
#ifndef __GNUC__
199+
# define GGML_ATTRIBUTE_FORMAT(...)
200+
#elif defined(__MINGW32__)
201+
# define GGML_ATTRIBUTE_FORMAT(...) __attribute__((format(gnu_printf, __VA_ARGS__)))
202+
#else
203+
# define GGML_ATTRIBUTE_FORMAT(...) __attribute__((format(printf, __VA_ARGS__)))
204+
#endif
205+
198206
#include <stdint.h>
199207
#include <stddef.h>
200208
#include <stdbool.h>
@@ -685,6 +693,7 @@ extern "C" {
685693

686694
GGML_API const char * ggml_get_name (const struct ggml_tensor * tensor);
687695
GGML_API struct ggml_tensor * ggml_set_name ( struct ggml_tensor * tensor, const char * name);
696+
GGML_ATTRIBUTE_FORMAT(2, 3)
688697
GGML_API struct ggml_tensor * ggml_format_name( struct ggml_tensor * tensor, const char * fmt, ...);
689698

690699
//
@@ -1866,39 +1875,39 @@ extern "C" {
18661875

18671876
GGML_API const char * gguf_type_name(enum gguf_type type);
18681877

1869-
GGML_API int gguf_get_version (struct gguf_context * ctx);
1870-
GGML_API size_t gguf_get_alignment (struct gguf_context * ctx);
1871-
GGML_API size_t gguf_get_data_offset(struct gguf_context * ctx);
1872-
GGML_API void * gguf_get_data (struct gguf_context * ctx);
1878+
GGML_API int gguf_get_version (const struct gguf_context * ctx);
1879+
GGML_API size_t gguf_get_alignment (const struct gguf_context * ctx);
1880+
GGML_API size_t gguf_get_data_offset(const struct gguf_context * ctx);
1881+
GGML_API void * gguf_get_data (const struct gguf_context * ctx);
18731882

1874-
GGML_API int gguf_get_n_kv(struct gguf_context * ctx);
1875-
GGML_API int gguf_find_key(struct gguf_context * ctx, const char * key);
1876-
GGML_API const char * gguf_get_key (struct gguf_context * ctx, int i);
1883+
GGML_API int gguf_get_n_kv(const struct gguf_context * ctx);
1884+
GGML_API int gguf_find_key(const struct gguf_context * ctx, const char * key);
1885+
GGML_API const char * gguf_get_key (const struct gguf_context * ctx, int i);
18771886

1878-
GGML_API enum gguf_type gguf_get_kv_type (struct gguf_context * ctx, int i);
1879-
GGML_API enum gguf_type gguf_get_arr_type(struct gguf_context * ctx, int i);
1887+
GGML_API enum gguf_type gguf_get_kv_type (const struct gguf_context * ctx, int i);
1888+
GGML_API enum gguf_type gguf_get_arr_type(const struct gguf_context * ctx, int i);
18801889

18811890
// results are undefined if the wrong type is used for the key
1882-
GGML_API uint8_t gguf_get_val_u8 (struct gguf_context * ctx, int i);
1883-
GGML_API int8_t gguf_get_val_i8 (struct gguf_context * ctx, int i);
1884-
GGML_API uint16_t gguf_get_val_u16 (struct gguf_context * ctx, int i);
1885-
GGML_API int16_t gguf_get_val_i16 (struct gguf_context * ctx, int i);
1886-
GGML_API uint32_t gguf_get_val_u32 (struct gguf_context * ctx, int i);
1887-
GGML_API int32_t gguf_get_val_i32 (struct gguf_context * ctx, int i);
1888-
GGML_API float gguf_get_val_f32 (struct gguf_context * ctx, int i);
1889-
GGML_API uint64_t gguf_get_val_u64 (struct gguf_context * ctx, int i);
1890-
GGML_API int64_t gguf_get_val_i64 (struct gguf_context * ctx, int i);
1891-
GGML_API double gguf_get_val_f64 (struct gguf_context * ctx, int i);
1892-
GGML_API bool gguf_get_val_bool(struct gguf_context * ctx, int i);
1893-
GGML_API const char * gguf_get_val_str (struct gguf_context * ctx, int i);
1894-
GGML_API int gguf_get_arr_n (struct gguf_context * ctx, int i);
1895-
GGML_API const void * gguf_get_arr_data(struct gguf_context * ctx, int i);
1896-
GGML_API const char * gguf_get_arr_str (struct gguf_context * ctx, int key_id, int i);
1897-
1898-
GGML_API int gguf_get_n_tensors (struct gguf_context * ctx);
1899-
GGML_API int gguf_find_tensor (struct gguf_context * ctx, const char * name);
1900-
GGML_API size_t gguf_get_tensor_offset(struct gguf_context * ctx, int i);
1901-
GGML_API char * gguf_get_tensor_name (struct gguf_context * ctx, int i);
1891+
GGML_API uint8_t gguf_get_val_u8 (const struct gguf_context * ctx, int i);
1892+
GGML_API int8_t gguf_get_val_i8 (const struct gguf_context * ctx, int i);
1893+
GGML_API uint16_t gguf_get_val_u16 (const struct gguf_context * ctx, int i);
1894+
GGML_API int16_t gguf_get_val_i16 (const struct gguf_context * ctx, int i);
1895+
GGML_API uint32_t gguf_get_val_u32 (const struct gguf_context * ctx, int i);
1896+
GGML_API int32_t gguf_get_val_i32 (const struct gguf_context * ctx, int i);
1897+
GGML_API float gguf_get_val_f32 (const struct gguf_context * ctx, int i);
1898+
GGML_API uint64_t gguf_get_val_u64 (const struct gguf_context * ctx, int i);
1899+
GGML_API int64_t gguf_get_val_i64 (const struct gguf_context * ctx, int i);
1900+
GGML_API double gguf_get_val_f64 (const struct gguf_context * ctx, int i);
1901+
GGML_API bool gguf_get_val_bool(const struct gguf_context * ctx, int i);
1902+
GGML_API const char * gguf_get_val_str (const struct gguf_context * ctx, int i);
1903+
GGML_API int gguf_get_arr_n (const struct gguf_context * ctx, int i);
1904+
GGML_API const void * gguf_get_arr_data(const struct gguf_context * ctx, int i);
1905+
GGML_API const char * gguf_get_arr_str (const struct gguf_context * ctx, int key_id, int i);
1906+
1907+
GGML_API int gguf_get_n_tensors (const struct gguf_context * ctx);
1908+
GGML_API int gguf_find_tensor (const struct gguf_context * ctx, const char * name);
1909+
GGML_API size_t gguf_get_tensor_offset(const struct gguf_context * ctx, int i);
1910+
GGML_API char * gguf_get_tensor_name (const struct gguf_context * ctx, int i);
19021911

19031912
// overrides existing values or adds a new one
19041913
GGML_API void gguf_set_val_u8 (struct gguf_context * ctx, const char * key, uint8_t val);
@@ -1943,11 +1952,11 @@ extern "C" {
19431952
//
19441953

19451954
// write the entire context to a binary file
1946-
GGML_API void gguf_write_to_file(struct gguf_context * ctx, const char * fname, bool only_meta);
1955+
GGML_API void gguf_write_to_file(const struct gguf_context * ctx, const char * fname, bool only_meta);
19471956

19481957
// get the size in bytes of the meta data (header, kv pairs, tensor info) including padding
1949-
GGML_API size_t gguf_get_meta_size(struct gguf_context * ctx);
1950-
GGML_API void gguf_get_meta_data(struct gguf_context * ctx, void * data);
1958+
GGML_API size_t gguf_get_meta_size(const struct gguf_context * ctx);
1959+
GGML_API void gguf_get_meta_data(const struct gguf_context * ctx, void * data);
19511960

19521961
//
19531962
// system info

0 commit comments

Comments
 (0)