Skip to content

Commit 3621657

Browse files
committed
try fix warnings from clang-tidy
1 parent 2820fbc commit 3621657

File tree

5 files changed

+55
-44
lines changed

5 files changed

+55
-44
lines changed

examples/mulmat-tune/mulmat-tune-tool.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121

2222
static int tune_time_min(int *a, int len);
2323
static void print_blas_build_tips(void);
24-
static void progress(int i, int max);
24+
static void progress(int i, int n);
2525
static bool prompt_yes_no(const char *prompt);
2626

27-
static void cmd_tune(struct ggml_mulmat_tune *b, int n_pass, bool verbose);
28-
static void cmd_analyze(struct ggml_mulmat_tune *b);
27+
static void cmd_tune(struct ggml_mulmat_tune *tune, int n_pass, bool verbose);
28+
static void cmd_analyze(struct ggml_mulmat_tune *tune);
2929

3030
static void usage(char *prog) {
3131
const char *usage_lines[] = {
@@ -90,6 +90,7 @@ int main(int argc, char **argv) {
9090

9191
{
9292
const char *name = ggml_get_blas_vendor();
93+
GGML_ASSERT(name != NULL);
9394
int n = sizeof(tune.blas_vendor);
9495
strncpy(tune.blas_vendor, name, n - 1);
9596
}
@@ -274,9 +275,8 @@ int main(int argc, char **argv) {
274275
model = arg_model;
275276
}
276277

277-
int rc;
278-
if (rc = ggml_mulmat_tune_setup_model(&tune, model, m_num),
279-
rc != 0) {
278+
int rc = ggml_mulmat_tune_setup_model(&tune, model, m_num);
279+
if (rc != 0) {
280280
fprintf(stderr, "error: unknown model: %s\n", model);
281281
usage(argv[0]);
282282
exit(1);
@@ -371,6 +371,7 @@ void cmd_tune(struct ggml_mulmat_tune *tune, int n_pass, bool verbose) {
371371
max_NxK = sz;
372372
}
373373
}
374+
GGML_ASSERT(max_NxK > 0);
374375

375376
// NOTE: proximate.
376377
size_t q_buf_size = 2 * max_NxK * sizeof(int64_t);
@@ -573,7 +574,8 @@ static bool prompt_yes_no(const char *prompt) {
573574
} else if (i == 2) {
574575
if (buf[0] == 'Y' || buf[0] == 'y') {
575576
return true;
576-
} else if (buf[0] == 'N' || buf[0] == 'n') {
577+
}
578+
if (buf[0] == 'N' || buf[0] == 'n') {
577579
return false;
578580
}
579581
}
@@ -632,6 +634,7 @@ static void cmd_analyze(struct ggml_mulmat_tune *tune) {
632634
for (int ip = 0; ip < shape->n_profiles; ip++) {
633635
const struct ggml_task_profile *profile = &shape->profiles[ip];
634636
int *total_time = malloc(sizeof(int) * m_num);
637+
memset(total_time, 0, sizeof(int) * m_num);
635638

636639
bool has_parallel = false;
637640
for (int k = 0; k < 3; k++) {

examples/mulmat-tune/mulmat-tune.c

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "examples/mulmat-tune/mulmat-tune.h"
44
#include "ggml.h"
55

6+
#define UNUSED(x) (void)(x)
7+
68
// TODO: this should be setup by llama instead.
79
int ggml_mulmat_tune_setup_model(struct ggml_mulmat_tune *tune,
810
const char *model_name, int m_num) {
@@ -129,10 +131,10 @@ int ggml_mulmat_tune_read_data(struct ggml_mulmat_tune *tune, FILE *fp) {
129131
for (int i_shape = 0; i_shape < tune->n_shapes; i_shape++) {
130132
struct ggml_mulmat_tune_shape *shape = &tune->shapes[i_shape];
131133

132-
if (rc = fscanf(fp, "%d %d %d %d %d %d", &shape->N, &shape->K,
133-
&shape->src0_type, &shape->src1_type,
134-
&shape->n_profiles, &shape->m_num),
135-
rc <= 0) {
134+
rc = fscanf(fp, "%d %d %d %d %d %d", &shape->N, &shape->K,
135+
&shape->src0_type, &shape->src1_type, &shape->n_profiles,
136+
&shape->m_num);
137+
if (rc <= 0) {
136138
return rc;
137139
}
138140

@@ -159,8 +161,8 @@ int ggml_mulmat_tune_read_data(struct ggml_mulmat_tune *tune, FILE *fp) {
159161
for (int j = 0; j < 3; j++) {
160162
struct ggml_task_stage *ts = &profile->stages[j];
161163
int backend, parallel, wait;
162-
if (rc = fscanf(fp, "%d %d %d", &backend, &parallel, &wait),
163-
rc <= 0) {
164+
rc = fscanf(fp, "%d %d %d", &backend, &parallel, &wait);
165+
if (rc <= 0) {
164166
return rc;
165167
}
166168
ts->backend = backend;
@@ -173,16 +175,17 @@ int ggml_mulmat_tune_read_data(struct ggml_mulmat_tune *tune, FILE *fp) {
173175
int M;
174176
for (int ip = 0; ip < shape->n_profiles; ip++) {
175177
if (ip == 0) {
176-
if (rc = fscanf(fp, "%d", &M), rc <= 0) {
178+
rc = fscanf(fp, "%d", &M);
179+
if (rc <= 0) {
177180
return rc;
178181
}
179182
}
180183
struct ggml_mulmat_tune_m *item =
181184
&shape->items[ip * shape->m_num + i_m];
182185
item->M = M;
183-
if (rc = fscanf(fp, "%d %d %d", &item->stages_time[0],
184-
&item->stages_time[1], &item->stages_time[2]),
185-
rc <= 0) {
186+
rc = fscanf(fp, "%d %d %d", &item->stages_time[0],
187+
&item->stages_time[1], &item->stages_time[2]);
188+
if (rc <= 0) {
186189
return rc;
187190
}
188191
}
@@ -194,10 +197,10 @@ int ggml_mulmat_tune_read_data(struct ggml_mulmat_tune *tune, FILE *fp) {
194197

195198
int ggml_mulmat_tune_write_data(const struct ggml_mulmat_tune *tune, FILE *fp) {
196199
int rc;
197-
if (rc = fprintf(fp, "%d %s %d %s %d %s %d\n\n", tune->version, tune->model,
198-
tune->type, tune->type_name, tune->backend,
199-
tune->blas_vendor, tune->n_shapes),
200-
rc <= 0) {
200+
rc = fprintf(fp, "%d %s %d %s %d %s %d\n\n", tune->version, tune->model,
201+
tune->type, tune->type_name, tune->backend, tune->blas_vendor,
202+
tune->n_shapes);
203+
if (rc <= 0) {
201204
return rc;
202205
}
203206

@@ -206,29 +209,31 @@ int ggml_mulmat_tune_write_data(const struct ggml_mulmat_tune *tune, FILE *fp) {
206209
printf("\n");
207210
}
208211
const struct ggml_mulmat_tune_shape *shape = &tune->shapes[i_shape];
209-
if (rc = fprintf(fp, "%d %d %d %d %d %d\n", shape->N, shape->K,
210-
shape->src0_type, shape->src1_type, shape->n_profiles,
211-
shape->m_num),
212-
rc <= 0) {
212+
rc = fprintf(fp, "%d %d %d %d %d %d\n", shape->N, shape->K,
213+
shape->src0_type, shape->src1_type, shape->n_profiles,
214+
shape->m_num);
215+
if (rc <= 0) {
213216
return rc;
214217
}
215218

216219
for (int i = 0; i < shape->n_profiles; i++) {
217220
struct ggml_task_profile *profile = &shape->profiles[i];
218221
for (int j = 0; j < 3; j++) {
219222
struct ggml_task_stage *ts = &profile->stages[j];
220-
if (rc = fprintf(fp, "%2d %d %d", ts->backend,
221-
ts->parallel ? 1 : 0, ts->wait ? 1 : 0),
222-
rc <= 0) {
223+
rc = fprintf(fp, "%2d %d %d", ts->backend, ts->parallel ? 1 : 0,
224+
ts->wait ? 1 : 0);
225+
if (rc <= 0) {
223226
return rc;
224227
}
225228
if (j < 2) {
226-
if (rc = fprintf(fp, " "), rc <= 0) {
229+
rc = fprintf(fp, " ");
230+
if (rc <= 0) {
227231
return rc;
228232
}
229233
}
230234
}
231-
if (rc = fprintf(fp, "\n"), rc <= 0) {
235+
rc = fprintf(fp, "\n");
236+
if (rc <= 0) {
232237
return rc;
233238
}
234239
}
@@ -238,26 +243,29 @@ int ggml_mulmat_tune_write_data(const struct ggml_mulmat_tune *tune, FILE *fp) {
238243
struct ggml_mulmat_tune_m *item =
239244
&shape->items[ip * shape->m_num + i_m];
240245
if (ip == 0) {
241-
if (rc = fprintf(fp, "%4d", item->M), rc <= 0) {
246+
rc = fprintf(fp, "%4d", item->M);
247+
if (rc <= 0) {
242248
return rc;
243249
}
244250
}
245251

246252
struct ggml_task_profile *profile = &shape->profiles[ip];
247253
for (int k = 0; k < 3; k++) {
248254
if (profile->stages[k].backend != GGML_BACKEND_UNKNOWN) {
249-
if (rc = fprintf(fp, "%9d", item->stages_time[k]),
250-
rc <= 0) {
255+
rc = fprintf(fp, "%9d", item->stages_time[k]);
256+
if (rc <= 0) {
251257
return rc;
252258
}
253259
} else {
254-
if (rc = fprintf(fp, " 0"), rc <= 0) {
260+
rc = fprintf(fp, " 0");
261+
if (rc <= 0) {
255262
return rc;
256263
}
257264
}
258265
}
259266
}
260-
if (rc = fprintf(fp, "\n"), rc <= 0) {
267+
rc = fprintf(fp, "\n");
268+
if (rc <= 0) {
261269
return rc;
262270
}
263271
}
@@ -366,13 +374,14 @@ void ggml_mulmat_tune_shape_estimate_time(
366374
int curr_v = curr->stages_time[stage];
367375

368376
// t = aM + b
369-
double a, b;
377+
double a;
378+
double b;
370379

371380
if (prev == curr) {
372381
a = 0.0;
373382
b = curr_v;
374383
} else {
375-
a = (curr_v - prev_v) / (curr->M - prev->M);
384+
a = 1.0 * (curr_v - prev_v) / (curr->M - prev->M);
376385
b = curr_v - a * curr->M;
377386
}
378387
double t = a * M + b;
@@ -405,7 +414,7 @@ const char *ggml_get_backend_name(enum ggml_backend backend) {
405414
}
406415

407416
const char *ggml_get_blas_vendor(void) {
408-
const char *vendor;
417+
const char *vendor = NULL;
409418
#if defined(GGML_USE_CUBLAS)
410419
vendor = "CUBLAS";
411420
#endif
@@ -441,6 +450,7 @@ enum ggml_backend ggml_auto_detect_backend(void) {
441450

442451
int ggml_get_builtin_blas_backends(int backends[]) {
443452
if (!ggml_cpu_has_blas()) {
453+
UNUSED(backends);
444454
return 0;
445455
}
446456

@@ -573,7 +583,6 @@ int ggml_mulmat_get_task_profiles(struct ggml_task_profile **profiles,
573583
} else if (ggml_is_quantized(src0_type)) {
574584
*profiles = ggml_mulmat_task_profiles_qxx;
575585
return ggml_mulmat_task_profiles_qxx_n;
576-
} else {
577-
GGML_ASSERT(false);
578586
}
587+
GGML_ASSERT(false);
579588
}

examples/mulmat-tune/mulmat-tune.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ int ggml_mulmat_tune_setup_model(struct ggml_mulmat_tune *tune,
8383

8484
int ggml_mulmat_tune_write_data(const struct ggml_mulmat_tune *tune, FILE *fp);
8585

86-
int ggml_mulmat_tune_read_data(struct ggml_mulmat_tune *tune, FILE *file);
86+
int ggml_mulmat_tune_read_data(struct ggml_mulmat_tune *tune, FILE *fp);
8787

8888
const struct ggml_mulmat_tune_shape *
8989
ggml_mulmat_tune_get_shape(const struct ggml_mulmat_tune *tune, int N, int K,

ggml.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14269,7 +14269,8 @@ static inline void ggml_graph_compute_thread_setup_workers(
1426914269
struct ggml_task_stage *next = &profile->stages[i];
1427014270
if (next->parallel) {
1427114271
break;
14272-
} else if (next->wait) {
14272+
}
14273+
if (next->wait) {
1427314274
shared->wait_on_task_done = true;
1427414275
GGML_PRINT_THREAD_DEBUG(">>>> wait_on_task_done is enabled\n");
1427514276
break;

tests/test-mulmat-tune.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ void test_ggml_mulmat_tune_estimate_time_zero_NK(void) {
189189
.blas_vendor = "OpenBLAS",
190190
};
191191

192-
const int m_step = 2;
193-
const int m_start = m_step;
194192
const int m_num = 2;
195193

196194
ggml_mulmat_tune_setup_model(&tune, "7B", m_num);

0 commit comments

Comments
 (0)