-
Notifications
You must be signed in to change notification settings - Fork 19
/
test.c
65 lines (57 loc) · 1.87 KB
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "helper_matrix.h"
#include "matmul.h"
#include <immintrin.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#ifdef OPENBLAS
#include <cblas.h>
#endif
int main(int argc, char* argv[]) {
srand(time(NULL));
int matsize_min = 8;
int matsize_max = 256;
int matsize_step = 1;
if (argc > 3) {
matsize_min = atoi(argv[1]);
matsize_max = atoi(argv[2]);
matsize_step = atoi(argv[3]);
}
printf("================\n");
printf("MINSIZE = %i\nMAXSIZE = %i\nSTEP = %i\n", matsize_min, matsize_max, matsize_step);
printf("================\n");
int n_tests = (matsize_max - matsize_min) / matsize_step;
int n_failed = 0;
for (int i = 0; i < n_tests; i += 1) {
int matsize = matsize_min + i * matsize_step;
int m = matsize, n = matsize, k = matsize;
float* A = (float*)_mm_malloc(m * k * sizeof(float), 64);
float* B = (float*)_mm_malloc(n * k * sizeof(float), 64);
float* C = (float*)_mm_malloc(m * n * sizeof(float), 64);
float* C_ref = (float*)_mm_malloc(m * n * sizeof(float), 64);
init_rand(A, m, k);
init_rand(B, k, n);
init_const(C, 0.0, m, n);
init_const(C_ref, 0.0, m, n);
#ifdef OPENBLAS
cblas_sgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, m, n, k, 1, A, m, B, k, 0, C, m);
#else
matmul(A, B, C, m, n, k);
#endif
matmul_naive(A, B, C_ref, m, n, k);
struct cmp_result result = compare_mats(C, C_ref, m, n);
if (result.n_false > 0) {
n_failed += 1;
printf("Test #%i: FAILED\n", i + 1);
} else {
printf("Test #%i: PASSED\n", i + 1);
}
_mm_free(A);
_mm_free(B);
_mm_free(C);
_mm_free(C_ref);
}
printf("=====================\n");
printf("PASSED: %i / %i\n", n_tests - n_failed, n_tests);
}