@@ -79,25 +79,31 @@ int ggml_mulmat_tune_read_data(struct ggml_mulmat_tune *tune, FILE *fp) {
79
79
return rc ;
80
80
}
81
81
82
- tune -> items = malloc (sizeof (struct ggml_mulmat_tune_m ) *
83
- (tune -> n_shapes * tune -> n_profiles * tune -> m_num ));
84
- if (tune -> items == NULL ) {
85
- fprintf (stderr , "failed to allocate memory\n" );
86
- return -2 ;
82
+ {
83
+ size_t item_size = sizeof (struct ggml_mulmat_tune_m ) *
84
+ (tune -> n_shapes * tune -> n_profiles * tune -> m_num );
85
+ tune -> items = malloc (item_size );
86
+ if (tune -> items == NULL ) {
87
+ fprintf (stderr , "failed to allocate memory\n" );
88
+ return -2 ;
89
+ }
90
+ memset (tune -> items , 0 , item_size );
87
91
}
88
92
89
- size_t sz = sizeof (struct ggml_task_profile ) * tune -> n_profiles ;
90
- tune -> profiles = malloc (sz );
91
- GGML_ASSERT (tune -> profiles );
92
- memset (tune -> profiles , 0 , sz );
93
+ {
94
+ size_t sz = sizeof (struct ggml_task_profile ) * tune -> n_profiles ;
95
+ tune -> profiles = malloc (sz );
96
+ GGML_ASSERT (tune -> profiles );
97
+ memset (tune -> profiles , 0 , sz );
98
+ }
93
99
94
100
for (int ip = 0 ; ip < tune -> n_profiles ; ip ++ ) {
95
101
struct ggml_task_profile * profile = & tune -> profiles [ip ];
96
102
for (int j = 0 ; j < 3 ; j ++ ) {
97
103
struct ggml_task_stage * ts = & profile -> stages [j ];
98
104
int backend , parallel , wait ;
99
- rc = fscanf (fp , "%d %d %d" , & backend , & parallel , & wait );
100
- if ( rc <= 0 ) {
105
+ if ( rc = fscanf (fp , "%d %d %d" , & backend , & parallel , & wait ),
106
+ rc <= 0 ) {
101
107
return rc ;
102
108
}
103
109
ts -> backend = backend ;
@@ -107,28 +113,27 @@ int ggml_mulmat_tune_read_data(struct ggml_mulmat_tune *tune, FILE *fp) {
107
113
}
108
114
109
115
for (int i_shape = 0 ; i_shape < tune -> n_shapes ; i_shape ++ ) {
110
- rc = fscanf (fp , "%d %d" , & tune -> shapes [i_shape ].N ,
111
- & tune -> shapes [i_shape ].K );
112
- if ( rc <= 0 ) {
116
+ if ( rc = fscanf (fp , "%d %d" , & tune -> shapes [i_shape ].N ,
117
+ & tune -> shapes [i_shape ].K ),
118
+ rc <= 0 ) {
113
119
return rc ;
114
120
}
115
121
116
122
for (int i_m = 0 ; i_m < tune -> m_num ; i_m ++ ) {
117
123
int M ;
118
124
for (int ip = 0 ; ip < tune -> n_profiles ; ip ++ ) {
119
125
if (ip == 0 ) {
120
- rc = fscanf (fp , "%d" , & M );
121
- if (rc <= 0 ) {
126
+ if (rc = fscanf (fp , "%d" , & M ), rc <= 0 ) {
122
127
return rc ;
123
128
}
124
129
}
125
130
int index =
126
131
ggml_mulmat_tune_get_item_index (tune , i_shape , ip , i_m );
127
132
struct ggml_mulmat_tune_m * item = & tune -> items [index ];
128
133
item -> M = M ;
129
- rc = fscanf (fp , "%d %d %d" , & item -> stages_time [0 ],
130
- & item -> stages_time [1 ], & item -> stages_time [2 ]);
131
- if ( rc <= 0 ) {
134
+ if ( rc = fscanf (fp , "%d %d %d" , & item -> stages_time [0 ],
135
+ & item -> stages_time [1 ], & item -> stages_time [2 ]),
136
+ rc <= 0 ) {
132
137
return rc ;
133
138
}
134
139
}
@@ -139,40 +144,38 @@ int ggml_mulmat_tune_read_data(struct ggml_mulmat_tune *tune, FILE *fp) {
139
144
}
140
145
141
146
int ggml_mulmat_tune_write_data (const struct ggml_mulmat_tune * tune , FILE * fp ) {
142
- int rc = fprintf (fp , "%d %s %d %s %d %s %d %d %d %d\n" , tune -> version ,
147
+ int rc ;
148
+ if (rc = fprintf (fp , "%d %s %d %s %d %s %d %d %d %d\n" , tune -> version ,
143
149
tune -> model , tune -> type , tune -> type_name , tune -> backend ,
144
150
tune -> blas_vendor , tune -> n_shapes , tune -> m_step ,
145
- tune -> m_num , tune -> n_profiles );
146
- if ( rc <= 0 ) {
151
+ tune -> m_num , tune -> n_profiles ),
152
+ rc <= 0 ) {
147
153
return rc ;
148
154
}
149
155
150
156
for (int i = 0 ; i < tune -> n_profiles ; i ++ ) {
151
157
struct ggml_task_profile * profile = & tune -> profiles [i ];
152
158
for (int j = 0 ; j < 3 ; j ++ ) {
153
159
struct ggml_task_stage * ts = & profile -> stages [j ];
154
- rc = fprintf (fp , "%2d %d %d" , ts -> backend ,
155
- ts -> parallel ? 1 : 0 , ts -> wait ? 1 : 0 );
156
- if ( rc <= 0 ) {
160
+ if ( rc = fprintf (fp , "%2d %d %d" , ts -> backend , ts -> parallel ? 1 : 0 ,
161
+ ts -> wait ? 1 : 0 ),
162
+ rc <= 0 ) {
157
163
return rc ;
158
164
}
159
165
if (j < 2 ) {
160
- rc = fprintf (fp , " " );
161
- if (rc <= 0 ) {
166
+ if (rc = fprintf (fp , " " ), rc <= 0 ) {
162
167
return rc ;
163
168
}
164
169
}
165
170
}
166
- rc = fprintf (fp , "\n" );
167
- if (rc <= 0 ) {
171
+ if (rc = fprintf (fp , "\n" ), rc <= 0 ) {
168
172
return rc ;
169
173
}
170
174
}
171
175
172
176
for (int i_shape = 0 ; i_shape < tune -> n_shapes ; i_shape ++ ) {
173
177
const struct ggml_mulmat_tune_nk * shape = & tune -> shapes [i_shape ];
174
- rc = fprintf (fp , "%d %d\n" , shape -> N , shape -> K );
175
- if (rc <= 0 ) {
178
+ if (rc = fprintf (fp , "%d %d\n" , shape -> N , shape -> K ), rc <= 0 ) {
176
179
return rc ;
177
180
}
178
181
@@ -182,29 +185,26 @@ int ggml_mulmat_tune_write_data(const struct ggml_mulmat_tune *tune, FILE *fp) {
182
185
ggml_mulmat_tune_get_item_index (tune , i_shape , ip , i_m );
183
186
struct ggml_mulmat_tune_m * item = & tune -> items [index ];
184
187
if (ip == 0 ) {
185
- rc = fprintf (fp , "%3d" , item -> M );
186
- if (rc <= 0 ) {
188
+ if (rc = fprintf (fp , "%3d" , item -> M ), rc <= 0 ) {
187
189
return rc ;
188
190
}
189
191
}
190
192
191
193
struct ggml_task_profile * profile = & tune -> profiles [ip ];
192
194
for (int k = 0 ; k < 3 ; k ++ ) {
193
195
if (profile -> stages [k ].backend != GGML_BACKEND_UNKNOWN ) {
194
- rc = fprintf (fp , "%9d" , item -> stages_time [k ]);
195
- if ( rc <= 0 ) {
196
+ if ( rc = fprintf (fp , "%9d" , item -> stages_time [k ]),
197
+ rc <= 0 ) {
196
198
return rc ;
197
199
}
198
200
} else {
199
- rc = fprintf (fp , " 0" );
200
- if (rc <= 0 ) {
201
+ if (rc = fprintf (fp , " 0" ), rc <= 0 ) {
201
202
return rc ;
202
203
}
203
204
}
204
205
}
205
206
}
206
- rc = fprintf (fp , "\n" );
207
- if (rc <= 0 ) {
207
+ if (rc = fprintf (fp , "\n" ), rc <= 0 ) {
208
208
return rc ;
209
209
}
210
210
}
@@ -298,8 +298,8 @@ void ggml_mulmat_tune_estimate_time(
298
298
if (ts -> parallel ) {
299
299
t /= nth ;
300
300
}
301
- time_stats -> profile_time [ip ].stage_time [stage ] = t ;
302
- time_stats -> profile_time [ip ].total_time += t ;
301
+ time_stats -> profile_time [ip ].stage_time [stage ] = ( int ) t ;
302
+ time_stats -> profile_time [ip ].total_time += ( int ) t ;
303
303
}
304
304
}
305
305
}
@@ -313,7 +313,7 @@ static const char *ggml_backend_names[] = {
313
313
314
314
const char * ggml_get_backend_name (enum ggml_backend backend ) {
315
315
if (backend == GGML_BACKEND_UNKNOWN ) {
316
- return "" ;
316
+ return "UNKNOWN " ;
317
317
}
318
318
return ggml_backend_names [backend ];
319
319
}
0 commit comments