ggerganov commited on
Commit
4ce2d25
·
unverified ·
1 Parent(s): 2dd8c56

sync : ggml (const correctness)

Browse files
Files changed (3) hide show
  1. ggml-cuda.cu +2 -0
  2. ggml.c +32 -32
  3. ggml.h +41 -32
ggml-cuda.cu CHANGED
@@ -5745,6 +5745,7 @@ inline void ggml_cuda_op_rope(
5745
  (void) dst;
5746
  (void) src0_ddq_i;
5747
  (void) src1_ddf_i;
 
5748
  (void) i1;
5749
  }
5750
 
@@ -5780,6 +5781,7 @@ inline void ggml_cuda_op_alibi(
5780
  (void) src1;
5781
  (void) src0_ddq_i;
5782
  (void) src1_ddf_i;
 
5783
  (void) i1;
5784
  }
5785
 
 
5745
  (void) dst;
5746
  (void) src0_ddq_i;
5747
  (void) src1_ddf_i;
5748
+ (void) i02;
5749
  (void) i1;
5750
  }
5751
 
 
5781
  (void) src1;
5782
  (void) src0_ddq_i;
5783
  (void) src1_ddf_i;
5784
+ (void) i02;
5785
  (void) i1;
5786
  }
5787
 
ggml.c CHANGED
@@ -20119,27 +20119,27 @@ const char * gguf_type_name(enum gguf_type type) {
20119
  return GGUF_TYPE_NAME[type];
20120
  }
20121
 
20122
- int gguf_get_version(struct gguf_context * ctx) {
20123
  return ctx->header.version;
20124
  }
20125
 
20126
- size_t gguf_get_alignment(struct gguf_context * ctx) {
20127
  return ctx->alignment;
20128
  }
20129
 
20130
- size_t gguf_get_data_offset(struct gguf_context * ctx) {
20131
  return ctx->offset;
20132
  }
20133
 
20134
- void * gguf_get_data(struct gguf_context * ctx) {
20135
  return ctx->data;
20136
  }
20137
 
20138
- int gguf_get_n_kv(struct gguf_context * ctx) {
20139
  return ctx->header.n_kv;
20140
  }
20141
 
20142
- int gguf_find_key(struct gguf_context * ctx, const char * key) {
20143
  // return -1 if key not found
20144
  int keyfound = -1;
20145
 
@@ -20155,85 +20155,85 @@ int gguf_find_key(struct gguf_context * ctx, const char * key) {
20155
  return keyfound;
20156
  }
20157
 
20158
- const char * gguf_get_key(struct gguf_context * ctx, int i) {
20159
  return ctx->kv[i].key.data;
20160
  }
20161
 
20162
- enum gguf_type gguf_get_kv_type(struct gguf_context * ctx, int i) {
20163
  return ctx->kv[i].type;
20164
  }
20165
 
20166
- enum gguf_type gguf_get_arr_type(struct gguf_context * ctx, int i) {
20167
  return ctx->kv[i].value.arr.type;
20168
  }
20169
 
20170
- const void * gguf_get_arr_data(struct gguf_context * ctx, int i) {
20171
  return ctx->kv[i].value.arr.data;
20172
  }
20173
 
20174
- const char * gguf_get_arr_str(struct gguf_context * ctx, int key_id, int i) {
20175
  struct gguf_kv * kv = &ctx->kv[key_id];
20176
  struct gguf_str * str = &((struct gguf_str *) kv->value.arr.data)[i];
20177
  return str->data;
20178
  }
20179
 
20180
- int gguf_get_arr_n(struct gguf_context * ctx, int i) {
20181
  return ctx->kv[i].value.arr.n;
20182
  }
20183
 
20184
- uint8_t gguf_get_val_u8(struct gguf_context * ctx, int i) {
20185
  return ctx->kv[i].value.uint8;
20186
  }
20187
 
20188
- int8_t gguf_get_val_i8(struct gguf_context * ctx, int i) {
20189
  return ctx->kv[i].value.int8;
20190
  }
20191
 
20192
- uint16_t gguf_get_val_u16(struct gguf_context * ctx, int i) {
20193
  return ctx->kv[i].value.uint16;
20194
  }
20195
 
20196
- int16_t gguf_get_val_i16(struct gguf_context * ctx, int i) {
20197
  return ctx->kv[i].value.int16;
20198
  }
20199
 
20200
- uint32_t gguf_get_val_u32(struct gguf_context * ctx, int i) {
20201
  return ctx->kv[i].value.uint32;
20202
  }
20203
 
20204
- int32_t gguf_get_val_i32(struct gguf_context * ctx, int i) {
20205
  return ctx->kv[i].value.int32;
20206
  }
20207
 
20208
- float gguf_get_val_f32(struct gguf_context * ctx, int i) {
20209
  return ctx->kv[i].value.float32;
20210
  }
20211
 
20212
- uint64_t gguf_get_val_u64(struct gguf_context * ctx, int i) {
20213
  return ctx->kv[i].value.uint64;
20214
  }
20215
 
20216
- int64_t gguf_get_val_i64(struct gguf_context * ctx, int i) {
20217
  return ctx->kv[i].value.int64;
20218
  }
20219
 
20220
- double gguf_get_val_f64(struct gguf_context * ctx, int i) {
20221
  return ctx->kv[i].value.float64;
20222
  }
20223
 
20224
- bool gguf_get_val_bool(struct gguf_context * ctx, int i) {
20225
  return ctx->kv[i].value.bool_;
20226
  }
20227
 
20228
- const char * gguf_get_val_str (struct gguf_context * ctx, int i) {
20229
  return ctx->kv[i].value.str.data;
20230
  }
20231
 
20232
- int gguf_get_n_tensors(struct gguf_context * ctx) {
20233
  return ctx->header.n_tensors;
20234
  }
20235
 
20236
- int gguf_find_tensor(struct gguf_context * ctx, const char * name) {
20237
  // return -1 if tensor not found
20238
  int tensorfound = -1;
20239
 
@@ -20249,11 +20249,11 @@ int gguf_find_tensor(struct gguf_context * ctx, const char * name) {
20249
  return tensorfound;
20250
  }
20251
 
20252
- size_t gguf_get_tensor_offset(struct gguf_context * ctx, int i) {
20253
  return ctx->infos[i].offset;
20254
  }
20255
 
20256
- char * gguf_get_tensor_name(struct gguf_context * ctx, int i) {
20257
  return ctx->infos[i].name.data;
20258
  }
20259
 
@@ -20536,7 +20536,7 @@ static void gguf_bwrite_el(struct gguf_buf * buf, const void * val, size_t el_si
20536
  buf->offset += el_size;
20537
  }
20538
 
20539
- static void gguf_write_to_buf(struct gguf_context * ctx, struct gguf_buf * buf, bool only_meta) {
20540
  // write header
20541
  gguf_bwrite_el(buf, &ctx->header.magic, sizeof(ctx->header.magic));
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
  }
20652
  }
20653
 
20654
- void gguf_write_to_file(struct gguf_context * ctx, const char * fname, bool only_meta) {
20655
  FILE * file = fopen(fname, "wb");
20656
  if (!file) {
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
  fclose(file);
20669
  }
20670
 
20671
- size_t gguf_get_meta_size(struct gguf_context * ctx) {
20672
  // no allocs - only compute size
20673
  struct gguf_buf buf = gguf_buf_init(0);
20674
 
@@ -20677,7 +20677,7 @@ size_t gguf_get_meta_size(struct gguf_context * ctx) {
20677
  return buf.offset;
20678
  }
20679
 
20680
- void gguf_get_meta_data(struct gguf_context * ctx, void * data) {
20681
  struct gguf_buf buf = gguf_buf_init(16*1024);
20682
 
20683
  gguf_write_to_buf(ctx, &buf, true);
 
20119
  return GGUF_TYPE_NAME[type];
20120
  }
20121
 
20122
+ int gguf_get_version(const struct gguf_context * ctx) {
20123
  return ctx->header.version;
20124
  }
20125
 
20126
+ size_t gguf_get_alignment(const struct gguf_context * ctx) {
20127
  return ctx->alignment;
20128
  }
20129
 
20130
+ size_t gguf_get_data_offset(const struct gguf_context * ctx) {
20131
  return ctx->offset;
20132
  }
20133
 
20134
+ void * gguf_get_data(const struct gguf_context * ctx) {
20135
  return ctx->data;
20136
  }
20137
 
20138
+ int gguf_get_n_kv(const struct gguf_context * ctx) {
20139
  return ctx->header.n_kv;
20140
  }
20141
 
20142
+ int gguf_find_key(const struct gguf_context * ctx, const char * key) {
20143
  // return -1 if key not found
20144
  int keyfound = -1;
20145
 
 
20155
  return keyfound;
20156
  }
20157
 
20158
+ const char * gguf_get_key(const struct gguf_context * ctx, int i) {
20159
  return ctx->kv[i].key.data;
20160
  }
20161
 
20162
+ enum gguf_type gguf_get_kv_type(const struct gguf_context * ctx, int i) {
20163
  return ctx->kv[i].type;
20164
  }
20165
 
20166
+ enum gguf_type gguf_get_arr_type(const struct gguf_context * ctx, int i) {
20167
  return ctx->kv[i].value.arr.type;
20168
  }
20169
 
20170
+ const void * gguf_get_arr_data(const struct gguf_context * ctx, int i) {
20171
  return ctx->kv[i].value.arr.data;
20172
  }
20173
 
20174
+ const char * gguf_get_arr_str(const struct gguf_context * ctx, int key_id, int i) {
20175
  struct gguf_kv * kv = &ctx->kv[key_id];
20176
  struct gguf_str * str = &((struct gguf_str *) kv->value.arr.data)[i];
20177
  return str->data;
20178
  }
20179
 
20180
+ int gguf_get_arr_n(const struct gguf_context * ctx, int i) {
20181
  return ctx->kv[i].value.arr.n;
20182
  }
20183
 
20184
+ uint8_t gguf_get_val_u8(const struct gguf_context * ctx, int i) {
20185
  return ctx->kv[i].value.uint8;
20186
  }
20187
 
20188
+ int8_t gguf_get_val_i8(const struct gguf_context * ctx, int i) {
20189
  return ctx->kv[i].value.int8;
20190
  }
20191
 
20192
+ uint16_t gguf_get_val_u16(const struct gguf_context * ctx, int i) {
20193
  return ctx->kv[i].value.uint16;
20194
  }
20195
 
20196
+ int16_t gguf_get_val_i16(const struct gguf_context * ctx, int i) {
20197
  return ctx->kv[i].value.int16;
20198
  }
20199
 
20200
+ uint32_t gguf_get_val_u32(const struct gguf_context * ctx, int i) {
20201
  return ctx->kv[i].value.uint32;
20202
  }
20203
 
20204
+ int32_t gguf_get_val_i32(const struct gguf_context * ctx, int i) {
20205
  return ctx->kv[i].value.int32;
20206
  }
20207
 
20208
+ float gguf_get_val_f32(const struct gguf_context * ctx, int i) {
20209
  return ctx->kv[i].value.float32;
20210
  }
20211
 
20212
+ uint64_t gguf_get_val_u64(const struct gguf_context * ctx, int i) {
20213
  return ctx->kv[i].value.uint64;
20214
  }
20215
 
20216
+ int64_t gguf_get_val_i64(const struct gguf_context * ctx, int i) {
20217
  return ctx->kv[i].value.int64;
20218
  }
20219
 
20220
+ double gguf_get_val_f64(const struct gguf_context * ctx, int i) {
20221
  return ctx->kv[i].value.float64;
20222
  }
20223
 
20224
+ bool gguf_get_val_bool(const struct gguf_context * ctx, int i) {
20225
  return ctx->kv[i].value.bool_;
20226
  }
20227
 
20228
+ const char * gguf_get_val_str (const struct gguf_context * ctx, int i) {
20229
  return ctx->kv[i].value.str.data;
20230
  }
20231
 
20232
+ int gguf_get_n_tensors(const struct gguf_context * ctx) {
20233
  return ctx->header.n_tensors;
20234
  }
20235
 
20236
+ int gguf_find_tensor(const struct gguf_context * ctx, const char * name) {
20237
  // return -1 if tensor not found
20238
  int tensorfound = -1;
20239
 
 
20249
  return tensorfound;
20250
  }
20251
 
20252
+ size_t gguf_get_tensor_offset(const struct gguf_context * ctx, int i) {
20253
  return ctx->infos[i].offset;
20254
  }
20255
 
20256
+ char * gguf_get_tensor_name(const struct gguf_context * ctx, int i) {
20257
  return ctx->infos[i].name.data;
20258
  }
20259
 
 
20536
  buf->offset += el_size;
20537
  }
20538
 
20539
+ static void gguf_write_to_buf(const struct gguf_context * ctx, struct gguf_buf * buf, bool only_meta) {
20540
  // write header
20541
  gguf_bwrite_el(buf, &ctx->header.magic, sizeof(ctx->header.magic));
20542
  gguf_bwrite_el(buf, &ctx->header.version, sizeof(ctx->header.version));
 
20651
  }
20652
  }
20653
 
20654
+ void gguf_write_to_file(const struct gguf_context * ctx, const char * fname, bool only_meta) {
20655
  FILE * file = fopen(fname, "wb");
20656
  if (!file) {
20657
  GGML_ASSERT(false && "failed to open file for writing");
 
20668
  fclose(file);
20669
  }
20670
 
20671
+ size_t gguf_get_meta_size(const struct gguf_context * ctx) {
20672
  // no allocs - only compute size
20673
  struct gguf_buf buf = gguf_buf_init(0);
20674
 
 
20677
  return buf.offset;
20678
  }
20679
 
20680
+ void gguf_get_meta_data(const struct gguf_context * ctx, void * data) {
20681
  struct gguf_buf buf = gguf_buf_init(16*1024);
20682
 
20683
  gguf_write_to_buf(ctx, &buf, true);
ggml.h CHANGED
@@ -195,6 +195,14 @@
195
  # define GGML_DEPRECATED(func, hint) func
196
  #endif
197
 
 
 
 
 
 
 
 
 
198
  #include <stdint.h>
199
  #include <stddef.h>
200
  #include <stdbool.h>
@@ -685,6 +693,7 @@ extern "C" {
685
 
686
  GGML_API const char * ggml_get_name (const struct ggml_tensor * tensor);
687
  GGML_API struct ggml_tensor * ggml_set_name ( struct ggml_tensor * tensor, const char * name);
 
688
  GGML_API struct ggml_tensor * ggml_format_name( struct ggml_tensor * tensor, const char * fmt, ...);
689
 
690
  //
@@ -1866,39 +1875,39 @@ extern "C" {
1866
 
1867
  GGML_API const char * gguf_type_name(enum gguf_type type);
1868
 
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);
1873
 
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);
1877
 
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);
1880
 
1881
  // 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);
1902
 
1903
  // overrides existing values or adds a new one
1904
  GGML_API void gguf_set_val_u8 (struct gguf_context * ctx, const char * key, uint8_t val);
@@ -1943,11 +1952,11 @@ extern "C" {
1943
  //
1944
 
1945
  // 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);
1947
 
1948
  // 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);
1951
 
1952
  //
1953
  // system info
 
195
  # define GGML_DEPRECATED(func, hint) func
196
  #endif
197
 
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
+
206
  #include <stdint.h>
207
  #include <stddef.h>
208
  #include <stdbool.h>
 
693
 
694
  GGML_API const char * ggml_get_name (const struct ggml_tensor * tensor);
695
  GGML_API struct ggml_tensor * ggml_set_name ( struct ggml_tensor * tensor, const char * name);
696
+ GGML_ATTRIBUTE_FORMAT(2, 3)
697
  GGML_API struct ggml_tensor * ggml_format_name( struct ggml_tensor * tensor, const char * fmt, ...);
698
 
699
  //
 
1875
 
1876
  GGML_API const char * gguf_type_name(enum gguf_type type);
1877
 
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);
1882
 
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);
1886
 
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);
1889
 
1890
  // results are undefined if the wrong type is used for the key
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);
1911
 
1912
  // overrides existing values or adds a new one
1913
  GGML_API void gguf_set_val_u8 (struct gguf_context * ctx, const char * key, uint8_t val);
 
1952
  //
1953
 
1954
  // write the entire context to a binary file
1955
+ GGML_API void gguf_write_to_file(const struct gguf_context * ctx, const char * fname, bool only_meta);
1956
 
1957
  // get the size in bytes of the meta data (header, kv pairs, tensor info) including padding
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);
1960
 
1961
  //
1962
  // system info