Skip to content

Commit b9b23b4

Browse files
authored
examples : fix c++ standard errors and pedantic warnings (leejet#239)
1 parent b5b3d6f commit b9b23b4

File tree

11 files changed

+88
-85
lines changed

11 files changed

+88
-85
lines changed

examples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ if (GGML_ALL_WARNINGS)
22
if (NOT MSVC)
33
set(cxx_flags
44
# TODO(marella): Add other warnings.
5+
-Wpedantic
56
-Wunused-variable
67
-Wno-unused-function
78
-Wno-multichar

examples/dolly-v2/main.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ bool dollyv2_model_load(const std::string & fname, dollyv2_model & model, gpt_vo
212212
// create the ggml context
213213
{
214214
struct ggml_init_params params = {
215-
.mem_size = ctx_size,
216-
.mem_buffer = NULL,
217-
.no_alloc = false,
215+
/*.mem_size =*/ ctx_size,
216+
/*.mem_buffer =*/ NULL,
217+
/*.no_alloc =*/ false,
218218
};
219219

220220
model.ctx = ggml_init(params);
@@ -473,9 +473,9 @@ bool dollyv2_eval(
473473
}
474474

475475
struct ggml_init_params params = {
476-
.mem_size = buf_size,
477-
.mem_buffer = buf,
478-
.no_alloc = false,
476+
/*.mem_size =*/ buf_size,
477+
/*.mem_buffer =*/ buf,
478+
/*.no_alloc =*/ false,
479479
};
480480

481481
struct ggml_context * ctx0 = ggml_init(params);

examples/gpt-2/main.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ bool gpt2_model_load(const std::string & fname, gpt2_model & model, gpt_vocab &
196196
// create the ggml context
197197
{
198198
struct ggml_init_params params = {
199-
.mem_size = ctx_size,
200-
.mem_buffer = NULL,
201-
.no_alloc = false,
199+
/*.mem_size =*/ ctx_size,
200+
/*.mem_buffer =*/ NULL,
201+
/*.no_alloc =*/ false,
202202
};
203203

204204
model.ctx = ggml_init(params);
@@ -418,9 +418,9 @@ bool gpt2_eval(
418418
}
419419

420420
struct ggml_init_params params = {
421-
.mem_size = buf_size,
422-
.mem_buffer = buf,
423-
.no_alloc = false,
421+
/*.mem_size =*/ buf_size,
422+
/*.mem_buffer =*/ buf,
423+
/*.no_alloc =*/ false,
424424
};
425425

426426
struct ggml_context * ctx0 = ggml_init(params);

examples/gpt-j/main.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ bool gptj_model_load(const std::string & fname, gptj_model & model, gpt_vocab &
194194
// create the ggml context
195195
{
196196
struct ggml_init_params params = {
197-
.mem_size = ctx_size,
198-
.mem_buffer = NULL,
199-
.no_alloc = false,
197+
/*.mem_size =*/ ctx_size,
198+
/*.mem_buffer =*/ NULL,
199+
/*.no_alloc =*/ false,
200200
};
201201

202202
model.ctx = ggml_init(params);
@@ -413,9 +413,9 @@ bool gptj_eval(
413413
}
414414

415415
struct ggml_init_params params = {
416-
.mem_size = buf_size,
417-
.mem_buffer = buf,
418-
.no_alloc = false,
416+
/*.mem_size =*/ buf_size,
417+
/*.mem_buffer =*/ buf,
418+
/*.no_alloc =*/ false,
419419
};
420420

421421
struct ggml_context * ctx0 = ggml_init(params);

examples/gpt-neox/main.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ bool gpt_neox_model_load(const std::string & fname, gpt_neox_model & model, gpt_
198198
// create the ggml context
199199
{
200200
struct ggml_init_params params = {
201-
.mem_size = ctx_size,
202-
.mem_buffer = NULL,
203-
.no_alloc = false,
201+
/*.mem_size =*/ ctx_size,
202+
/*.mem_buffer =*/ NULL,
203+
/*.no_alloc =*/ false,
204204
};
205205

206206
model.ctx = ggml_init(params);
@@ -465,9 +465,9 @@ bool gpt_neox_eval(
465465
}
466466

467467
struct ggml_init_params params = {
468-
.mem_size = buf_size,
469-
.mem_buffer = buf,
470-
.no_alloc = false,
468+
/*.mem_size =*/ buf_size,
469+
/*.mem_buffer =*/ buf,
470+
/*.no_alloc =*/ false,
471471
};
472472

473473
struct ggml_context * ctx0 = ggml_init(params);

examples/mnist/main-cpu.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ int mnist_eval(
4545
static void * buf = malloc(buf_size);
4646

4747
struct ggml_init_params params = {
48-
.mem_size = buf_size,
49-
.mem_buffer = buf,
50-
.no_alloc = false,
48+
/*.mem_size =*/ buf_size,
49+
/*.mem_buffer =*/ buf,
50+
/*.no_alloc =*/ false,
5151
};
5252

5353
struct ggml_context * ctx_work = ggml_init(params);

examples/mnist/main.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ bool mnist_model_load(const std::string & fname, mnist_model & model) {
7373
// create the ggml context
7474
{
7575
struct ggml_init_params params = {
76-
.mem_size = ctx_size + 1024*1024,
77-
.mem_buffer = NULL,
78-
.no_alloc = false,
76+
/*.mem_size =*/ ctx_size + 1024*1024,
77+
/*.mem_buffer =*/ NULL,
78+
/*.no_alloc =*/ false,
7979
};
8080

8181
model.ctx = ggml_init(params);
@@ -175,9 +175,9 @@ int mnist_eval(
175175
static void * buf = malloc(buf_size);
176176

177177
struct ggml_init_params params = {
178-
.mem_size = buf_size,
179-
.mem_buffer = buf,
180-
.no_alloc = false,
178+
/*.mem_size =*/ buf_size,
179+
/*.mem_buffer =*/ buf,
180+
/*.no_alloc =*/ false,
181181
};
182182

183183
struct ggml_context * ctx0 = ggml_init(params);

examples/mpt/main.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,9 @@ bool mpt_model_load(const std::string & fname, mpt_model & model, gpt_vocab & vo
291291
// create the ggml context
292292
{
293293
struct ggml_init_params params = {
294-
.mem_size = ctx_size,
295-
.mem_buffer = NULL,
296-
.no_alloc = false,
294+
/*.mem_size =*/ ctx_size,
295+
/*.mem_buffer =*/ NULL,
296+
/*.no_alloc =*/ false,
297297
};
298298

299299
model.ctx = ggml_init(params);
@@ -488,13 +488,14 @@ bool mpt_eval(const mpt_model & model, const int n_threads, const int n_past,
488488
}
489489

490490
struct ggml_init_params params = {
491-
.mem_size = buf_size,
492-
.mem_buffer = buf,
493-
.no_alloc = false,
491+
/*.mem_size =*/ buf_size,
492+
/*.mem_buffer =*/ buf,
493+
/*.no_alloc =*/ false,
494494
};
495495

496496
struct ggml_context * ctx0 = ggml_init(params);
497-
struct ggml_cgraph gf = {.n_threads = n_threads};
497+
struct ggml_cgraph gf = {};
498+
gf.n_threads = n_threads;
498499

499500
struct ggml_tensor * embd = ggml_new_tensor_1d(ctx0, GGML_TYPE_I32, N);
500501
memcpy(embd->data, embd_inp.data(), N * ggml_element_size(embd));

examples/replit/main.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,9 @@ bool replit_model_load(const std::string & fname, replit_model & model, replit_t
260260
// create the ggml context
261261
{
262262
struct ggml_init_params params = {
263-
.mem_size = ctx_size,
264-
.mem_buffer = NULL,
265-
.no_alloc = false,
263+
/*.mem_size =*/ ctx_size,
264+
/*.mem_buffer =*/ NULL,
265+
/*.no_alloc =*/ false,
266266
};
267267

268268
model.ctx = ggml_init(params);
@@ -452,13 +452,14 @@ bool replit_eval(const replit_model & model, const int n_threads, const int n_pa
452452
}
453453

454454
struct ggml_init_params params = {
455-
.mem_size = buf_size,
456-
.mem_buffer = buf,
457-
.no_alloc = false,
455+
/*.mem_size =*/ buf_size,
456+
/*.mem_buffer =*/ buf,
457+
/*.no_alloc =*/ false,
458458
};
459459

460460
struct ggml_context * ctx0 = ggml_init(params);
461-
struct ggml_cgraph gf = {.n_threads = n_threads};
461+
struct ggml_cgraph gf = {};
462+
gf.n_threads = n_threads;
462463

463464
struct ggml_tensor * embd = ggml_new_tensor_1d(ctx0, GGML_TYPE_I32, N);
464465
memcpy(embd->data, embd_inp.data(), N * ggml_element_size(embd));
@@ -764,4 +765,4 @@ int main(int argc, char ** argv) {
764765
ggml_free(model.ctx);
765766

766767
return 0;
767-
}
768+
}

examples/starcoder/main.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@ bool starcoder_model_load(const std::string & fname, starcoder_model & model, gp
214214
// create the ggml context
215215
{
216216
struct ggml_init_params params = {
217-
.mem_size = ctx_size,
218-
.mem_buffer = NULL,
219-
.no_alloc = false,
217+
/*.mem_size =*/ ctx_size,
218+
/*.mem_buffer =*/ NULL,
219+
/*.no_alloc =*/ false,
220220
};
221221

222222
model.ctx = ggml_init(params);
@@ -448,9 +448,9 @@ bool starcoder_eval(
448448
}
449449

450450
struct ggml_init_params params = {
451-
.mem_size = buf_size,
452-
.mem_buffer = buf,
453-
.no_alloc = false,
451+
/*.mem_size =*/ buf_size,
452+
/*.mem_buffer =*/ buf,
453+
/*.no_alloc =*/ false,
454454
};
455455

456456
struct ggml_context * ctx0 = ggml_init(params);

examples/whisper/main.cpp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -424,13 +424,13 @@ bool output_json(struct whisper_context * ctx, const char * fname, const whisper
424424
indent++;
425425
};
426426

427-
auto end_arr = [&](bool end = false) {
427+
auto end_arr = [&](bool end) {
428428
indent--;
429429
doindent();
430430
fout << (end ? "]\n" : "},\n");
431431
};
432432

433-
auto start_obj = [&](const char *name = nullptr) {
433+
auto start_obj = [&](const char *name) {
434434
doindent();
435435
if (name) {
436436
fout << "\"" << name << "\": {\n";
@@ -440,7 +440,7 @@ bool output_json(struct whisper_context * ctx, const char * fname, const whisper
440440
indent++;
441441
};
442442

443-
auto end_obj = [&](bool end = false) {
443+
auto end_obj = [&](bool end) {
444444
indent--;
445445
doindent();
446446
fout << (end ? "}\n" : "},\n");
@@ -451,24 +451,24 @@ bool output_json(struct whisper_context * ctx, const char * fname, const whisper
451451
fout << "\"" << name << "\": ";
452452
};
453453

454-
auto value_s = [&](const char *name, const char *val, bool end = false) {
454+
auto value_s = [&](const char *name, const char *val, bool end) {
455455
start_value(name);
456456
char * val_escaped = escape_double_quotes_and_backslashes(val);
457457
fout << "\"" << val_escaped << (end ? "\"\n" : "\",\n");
458458
free(val_escaped);
459459
};
460460

461-
auto end_value = [&](bool end = false) {
461+
auto end_value = [&](bool end) {
462462
fout << (end ? "\n" : ",\n");
463463
};
464464

465-
auto value_i = [&](const char *name, const int64_t val, bool end = false) {
465+
auto value_i = [&](const char *name, const int64_t val, bool end) {
466466
start_value(name);
467467
fout << val;
468468
end_value(end);
469469
};
470470

471-
auto value_b = [&](const char *name, const bool val, bool end = false) {
471+
auto value_b = [&](const char *name, const bool val, bool end) {
472472
start_value(name);
473473
fout << (val ? "true" : "false");
474474
end_value(end);
@@ -480,35 +480,35 @@ bool output_json(struct whisper_context * ctx, const char * fname, const whisper
480480
}
481481

482482
fprintf(stderr, "%s: saving output to '%s'\n", __func__, fname);
483-
start_obj();
484-
value_s("systeminfo", whisper_print_system_info());
483+
start_obj(nullptr);
484+
value_s("systeminfo", whisper_print_system_info(), false);
485485
start_obj("model");
486-
value_s("type", whisper_model_type_readable(ctx));
487-
value_b("multilingual", whisper_is_multilingual(ctx));
488-
value_i("vocab", whisper_model_n_vocab(ctx));
486+
value_s("type", whisper_model_type_readable(ctx), false);
487+
value_b("multilingual", whisper_is_multilingual(ctx), false);
488+
value_i("vocab", whisper_model_n_vocab(ctx), false);
489489
start_obj("audio");
490-
value_i("ctx", whisper_model_n_audio_ctx(ctx));
491-
value_i("state", whisper_model_n_audio_state(ctx));
492-
value_i("head", whisper_model_n_audio_head(ctx));
490+
value_i("ctx", whisper_model_n_audio_ctx(ctx), false);
491+
value_i("state", whisper_model_n_audio_state(ctx), false);
492+
value_i("head", whisper_model_n_audio_head(ctx), false);
493493
value_i("layer", whisper_model_n_audio_layer(ctx), true);
494-
end_obj();
494+
end_obj(false);
495495
start_obj("text");
496-
value_i("ctx", whisper_model_n_text_ctx(ctx));
497-
value_i("state", whisper_model_n_text_state(ctx));
498-
value_i("head", whisper_model_n_text_head(ctx));
496+
value_i("ctx", whisper_model_n_text_ctx(ctx), false);
497+
value_i("state", whisper_model_n_text_state(ctx), false);
498+
value_i("head", whisper_model_n_text_head(ctx), false);
499499
value_i("layer", whisper_model_n_text_layer(ctx), true);
500-
end_obj();
501-
value_i("mels", whisper_model_n_mels(ctx));
500+
end_obj(false);
501+
value_i("mels", whisper_model_n_mels(ctx), false);
502502
value_i("ftype", whisper_model_ftype(ctx), true);
503-
end_obj();
503+
end_obj(false);
504504
start_obj("params");
505-
value_s("model", params.model.c_str());
506-
value_s("language", params.language.c_str());
505+
value_s("model", params.model.c_str(), false);
506+
value_s("language", params.language.c_str(), false);
507507
value_b("translate", params.translate, true);
508-
end_obj();
508+
end_obj(false);
509509
start_obj("result");
510510
value_s("language", whisper_lang_str(whisper_full_lang_id(ctx)), true);
511-
end_obj();
511+
end_obj(false);
512512
start_arr("transcription");
513513

514514
const int n_segments = whisper_full_n_segments(ctx);
@@ -517,15 +517,15 @@ bool output_json(struct whisper_context * ctx, const char * fname, const whisper
517517
const int64_t t0 = whisper_full_get_segment_t0(ctx, i);
518518
const int64_t t1 = whisper_full_get_segment_t1(ctx, i);
519519

520-
start_obj();
520+
start_obj(nullptr);
521521
start_obj("timestamps");
522-
value_s("from", to_timestamp(t0, true).c_str());
522+
value_s("from", to_timestamp(t0, true).c_str(), false);
523523
value_s("to", to_timestamp(t1, true).c_str(), true);
524-
end_obj();
524+
end_obj(false);
525525
start_obj("offsets");
526-
value_i("from", t0 * 10);
526+
value_i("from", t0 * 10, false);
527527
value_i("to", t1 * 10, true);
528-
end_obj();
528+
end_obj(false);
529529
value_s("text", text, true);
530530
end_obj(i == (n_segments - 1));
531531
}

0 commit comments

Comments
 (0)