Skip to content

Commit 5b8d505

Browse files
committed
tests : fix UB in test-quantize-perf
1 parent 43bbfb7 commit 5b8d505

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

tests/test-quantize-perf.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,21 @@ static void * align_with_offset(void * ptr, int offset) {
7676
return (char *) std::align(MAX_ALIGNMENT, MAX_ALIGNMENT, ptr, dummy_size) + offset;
7777
}
7878

79-
static void benchmark_function(size_t size, size_t q_size, int64_t iterations, const std::function<size_t(void)> & function) {
79+
static void benchmark_function(size_t size, size_t q_size, int64_t iterations, const std::function<float(void)> & func) {
8080
int64_t min_time_us = INT64_MAX;
8181
int64_t total_time_us = 0;
8282
int64_t min_time_cycles = INT64_MAX;
8383
int64_t total_time_cycles = 0;
8484

8585
for (int i = 0; i < WARMUP; i++) {
86-
function();
86+
func();
8787
}
8888

89-
9089
for (int i = 0; i < iterations; i++) {
9190
const int64_t start_time = ggml_time_us();
9291
const int64_t start_cycles = cpu_cycles();
9392

94-
function();
93+
func();
9594

9695
const int64_t end_cycles = cpu_cycles();
9796
const int64_t end_time = ggml_time_us();
@@ -245,15 +244,15 @@ int main(int argc, char * argv[]) {
245244

246245
std::vector<uint8_t> test_data1_v(largest*4 + MAX_ALIGNMENT*2);
247246
std::vector<uint8_t> test_data2_v(largest*4 + MAX_ALIGNMENT*2);
248-
std::vector<uint8_t> test_q1_v(largest*4 + MAX_ALIGNMENT*2);
249-
std::vector<uint8_t> test_q2_v(largest*4 + MAX_ALIGNMENT*2);
250-
std::vector<uint8_t> test_out_v(largest*4 + MAX_ALIGNMENT*2);
247+
std::vector<uint8_t> test_q1_v (largest*4 + MAX_ALIGNMENT*2);
248+
std::vector<uint8_t> test_q2_v (largest*4 + MAX_ALIGNMENT*2);
249+
std::vector<uint8_t> test_out_v (largest*4 + MAX_ALIGNMENT*2);
251250

252251
float * test_data1 = (float *) align_with_offset(test_data1_v.data(), params.alignment_offset);
253252
float * test_data2 = (float *) align_with_offset(test_data2_v.data(), params.alignment_offset);
254-
float * test_q1 = (float *) align_with_offset(test_q1_v.data(), params.alignment_offset);
255-
float * test_q2 = (float *) align_with_offset(test_q2_v.data(), params.alignment_offset);
256-
float * test_out = (float *) align_with_offset(test_out_v.data(), params.alignment_offset);
253+
float * test_q1 = (float *) align_with_offset(test_q1_v.data(), params.alignment_offset);
254+
float * test_q2 = (float *) align_with_offset(test_q2_v.data(), params.alignment_offset);
255+
float * test_out = (float *) align_with_offset(test_out_v.data(), params.alignment_offset);
257256

258257
generate_data(0, largest, test_data1);
259258
generate_data(1, largest, test_data2);
@@ -283,7 +282,7 @@ int main(int argc, char * argv[]) {
283282
printf(" quantize_row_q_reference\n");
284283
for (size_t size : params.test_sizes) {
285284
printf(" %zu values (%.2f MB)\n", size, 4*size/(float)(1024*1024));
286-
auto quantize_fn = [&](void ) {
285+
auto quantize_fn = [&](void) -> float {
287286
qfns.from_float_reference(test_data1, test_q1, size);
288287
return test_q1[0];
289288
};
@@ -297,7 +296,7 @@ int main(int argc, char * argv[]) {
297296
printf(" quantize_row_q\n");
298297
for (size_t size : params.test_sizes) {
299298
printf(" %zu values (%.2f MB)\n", size, 4*size/(float)(1024*1024));
300-
auto quantize_fn = [&](void ) {
299+
auto quantize_fn = [&](void) -> float {
301300
qfns.from_float(test_data1, test_q1, size);
302301
return test_q1[0];
303302
};
@@ -312,7 +311,7 @@ int main(int argc, char * argv[]) {
312311
qfns.from_float(test_data1, test_q1, largest);
313312
for (size_t size : params.test_sizes) {
314313
printf(" %zu values (%.2f MB)\n", size, 4*size/(float)(1024*1024));
315-
auto quantize_fn = [&](void ) {
314+
auto quantize_fn = [&](void) -> float {
316315
qfns.to_float(test_q1, test_out, size);
317316
return test_out[0];
318317
};
@@ -326,7 +325,7 @@ int main(int argc, char * argv[]) {
326325
printf(" quantize_row_q_dot\n");
327326
for (size_t size : params.test_sizes) {
328327
printf(" %zu values (%.2f MB)\n", size, 4*size/(float)(1024*1024));
329-
auto quantize_fn = [&](void ) {
328+
auto quantize_fn = [&](void) -> float {
330329
auto vdot = ggml_internal_get_type_traits(qfns.vec_dot_type);
331330
vdot.from_float(test_data1, test_q1, size);
332331
return test_q1[0];
@@ -343,7 +342,7 @@ int main(int argc, char * argv[]) {
343342
qfns.from_float(test_data2, test_q2, largest);
344343
for (size_t size : params.test_sizes) {
345344
printf(" %zu values (%.2f MB)\n", size, 4*size/(float)(1024*1024));
346-
auto quantize_fn = [&](void ) {
345+
auto quantize_fn = [&](void) -> float {
347346
float result;
348347
qfns.vec_dot(size, &result, test_q1, test_q2);
349348
return result;

0 commit comments

Comments
 (0)