3
3
#include "examples/mulmat-tune/mulmat-tune.h"
4
4
#include "ggml.h"
5
5
6
+ #define UNUSED (x ) (void)(x)
7
+
6
8
// TODO: this should be setup by llama instead.
7
9
int ggml_mulmat_tune_setup_model (struct ggml_mulmat_tune * tune ,
8
10
const char * model_name , int m_num ) {
@@ -129,10 +131,10 @@ int ggml_mulmat_tune_read_data(struct ggml_mulmat_tune *tune, FILE *fp) {
129
131
for (int i_shape = 0 ; i_shape < tune -> n_shapes ; i_shape ++ ) {
130
132
struct ggml_mulmat_tune_shape * shape = & tune -> shapes [i_shape ];
131
133
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 ) {
136
138
return rc ;
137
139
}
138
140
@@ -159,8 +161,8 @@ int ggml_mulmat_tune_read_data(struct ggml_mulmat_tune *tune, FILE *fp) {
159
161
for (int j = 0 ; j < 3 ; j ++ ) {
160
162
struct ggml_task_stage * ts = & profile -> stages [j ];
161
163
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 ) {
164
166
return rc ;
165
167
}
166
168
ts -> backend = backend ;
@@ -173,16 +175,17 @@ int ggml_mulmat_tune_read_data(struct ggml_mulmat_tune *tune, FILE *fp) {
173
175
int M ;
174
176
for (int ip = 0 ; ip < shape -> n_profiles ; ip ++ ) {
175
177
if (ip == 0 ) {
176
- if (rc = fscanf (fp , "%d" , & M ), rc <= 0 ) {
178
+ rc = fscanf (fp , "%d" , & M );
179
+ if (rc <= 0 ) {
177
180
return rc ;
178
181
}
179
182
}
180
183
struct ggml_mulmat_tune_m * item =
181
184
& shape -> items [ip * shape -> m_num + i_m ];
182
185
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 ) {
186
189
return rc ;
187
190
}
188
191
}
@@ -194,10 +197,10 @@ int ggml_mulmat_tune_read_data(struct ggml_mulmat_tune *tune, FILE *fp) {
194
197
195
198
int ggml_mulmat_tune_write_data (const struct ggml_mulmat_tune * tune , FILE * fp ) {
196
199
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 ) {
201
204
return rc ;
202
205
}
203
206
@@ -206,29 +209,31 @@ int ggml_mulmat_tune_write_data(const struct ggml_mulmat_tune *tune, FILE *fp) {
206
209
printf ("\n" );
207
210
}
208
211
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 ) {
213
216
return rc ;
214
217
}
215
218
216
219
for (int i = 0 ; i < shape -> n_profiles ; i ++ ) {
217
220
struct ggml_task_profile * profile = & shape -> profiles [i ];
218
221
for (int j = 0 ; j < 3 ; j ++ ) {
219
222
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 ) {
223
226
return rc ;
224
227
}
225
228
if (j < 2 ) {
226
- if (rc = fprintf (fp , " " ), rc <= 0 ) {
229
+ rc = fprintf (fp , " " );
230
+ if (rc <= 0 ) {
227
231
return rc ;
228
232
}
229
233
}
230
234
}
231
- if (rc = fprintf (fp , "\n" ), rc <= 0 ) {
235
+ rc = fprintf (fp , "\n" );
236
+ if (rc <= 0 ) {
232
237
return rc ;
233
238
}
234
239
}
@@ -238,26 +243,29 @@ int ggml_mulmat_tune_write_data(const struct ggml_mulmat_tune *tune, FILE *fp) {
238
243
struct ggml_mulmat_tune_m * item =
239
244
& shape -> items [ip * shape -> m_num + i_m ];
240
245
if (ip == 0 ) {
241
- if (rc = fprintf (fp , "%4d" , item -> M ), rc <= 0 ) {
246
+ rc = fprintf (fp , "%4d" , item -> M );
247
+ if (rc <= 0 ) {
242
248
return rc ;
243
249
}
244
250
}
245
251
246
252
struct ggml_task_profile * profile = & shape -> profiles [ip ];
247
253
for (int k = 0 ; k < 3 ; k ++ ) {
248
254
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 ) {
251
257
return rc ;
252
258
}
253
259
} else {
254
- if (rc = fprintf (fp , " 0" ), rc <= 0 ) {
260
+ rc = fprintf (fp , " 0" );
261
+ if (rc <= 0 ) {
255
262
return rc ;
256
263
}
257
264
}
258
265
}
259
266
}
260
- if (rc = fprintf (fp , "\n" ), rc <= 0 ) {
267
+ rc = fprintf (fp , "\n" );
268
+ if (rc <= 0 ) {
261
269
return rc ;
262
270
}
263
271
}
@@ -366,13 +374,14 @@ void ggml_mulmat_tune_shape_estimate_time(
366
374
int curr_v = curr -> stages_time [stage ];
367
375
368
376
// t = aM + b
369
- double a , b ;
377
+ double a ;
378
+ double b ;
370
379
371
380
if (prev == curr ) {
372
381
a = 0.0 ;
373
382
b = curr_v ;
374
383
} else {
375
- a = (curr_v - prev_v ) / (curr -> M - prev -> M );
384
+ a = 1.0 * (curr_v - prev_v ) / (curr -> M - prev -> M );
376
385
b = curr_v - a * curr -> M ;
377
386
}
378
387
double t = a * M + b ;
@@ -405,7 +414,7 @@ const char *ggml_get_backend_name(enum ggml_backend backend) {
405
414
}
406
415
407
416
const char * ggml_get_blas_vendor (void ) {
408
- const char * vendor ;
417
+ const char * vendor = NULL ;
409
418
#if defined(GGML_USE_CUBLAS )
410
419
vendor = "CUBLAS" ;
411
420
#endif
@@ -441,6 +450,7 @@ enum ggml_backend ggml_auto_detect_backend(void) {
441
450
442
451
int ggml_get_builtin_blas_backends (int backends []) {
443
452
if (!ggml_cpu_has_blas ()) {
453
+ UNUSED (backends );
444
454
return 0 ;
445
455
}
446
456
@@ -573,7 +583,6 @@ int ggml_mulmat_get_task_profiles(struct ggml_task_profile **profiles,
573
583
} else if (ggml_is_quantized (src0_type )) {
574
584
* profiles = ggml_mulmat_task_profiles_qxx ;
575
585
return ggml_mulmat_task_profiles_qxx_n ;
576
- } else {
577
- GGML_ASSERT (false);
578
586
}
587
+ GGML_ASSERT (false);
579
588
}
0 commit comments