Skip to content

Commit 3977ba5

Browse files
committed
Merge remote-tracking branch 'origin/dev' into xcpt-handler
2 parents bf93446 + dab1471 commit 3977ba5

File tree

11 files changed

+628
-100
lines changed

11 files changed

+628
-100
lines changed

bareMetalC/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ include $(abs_top_srcdir)/Makefrag
22

33
tests = \
44
mvin_mvout \
5+
mvin_mvout_zeros \
56
mvin_mvout_stride \
7+
mvin_mvout_block_stride \
68
mvin_mvout_acc \
79
mvin_mvout_acc_zero_stride \
810
mvin_mvout_acc_stride \

bareMetalC/conv.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,32 @@
99
#include "include/gemmini_testutils.h"
1010

1111
#ifndef BAREMETAL
12+
1213
#define BATCH_SIZE 4
1314
#define IN_DIM 224
1415
#define IN_CHANNELS 3
1516
#define OUT_CHANNELS 32
1617
#define KERNEL_DIM 3
1718
#define PADDING 1
1819
#define STRIDE 2
20+
1921
#else
22+
2023
#ifdef FAST
24+
2125
#define IN_DIM 9
2226
#define IN_CHANNELS 5
2327
#define OUT_CHANNELS 7
28+
2429
#else
25-
#define IN_DIM 23
26-
#define IN_CHANNELS 17
27-
#define OUT_CHANNELS 31
30+
31+
#define IN_DIM 17
32+
#define IN_CHANNELS 18
33+
#define OUT_CHANNELS 19
34+
2835
#endif
2936

30-
#define BATCH_SIZE 3
37+
#define BATCH_SIZE 2
3138
#define KERNEL_DIM 3
3239
#define PADDING 1
3340
#define STRIDE 2
@@ -206,7 +213,7 @@ int main() {
206213

207214
printf("Gemmini conv...\n");
208215
uint64_t start_gemmini = read_cycles();
209-
tiled_conv_auto(
216+
tiled_conv_A_stride_auto(
210217
BATCH_SIZE, IN_DIM, IN_CHANNELS,
211218
OUT_CHANNELS, OUT_DIM,
212219
STRIDE, PADDING, KERNEL_DIM,

bareMetalC/conv_with_pool.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
#define IN_CHANNELS 5
3030
#define OUT_CHANNELS 7
3131
#else
32-
#define IN_DIM 23
33-
#define IN_CHANNELS 17
34-
#define OUT_CHANNELS 31
32+
#define IN_DIM 17
33+
#define IN_CHANNELS 18
34+
#define OUT_CHANNELS 19
3535
#endif
3636

37-
#define BATCH_SIZE 3
37+
#define BATCH_SIZE 2
3838
#define KERNEL_DIM 3
3939
#define PADDING 1
4040
#define STRIDE 2
@@ -383,8 +383,7 @@ int main() {
383383
printf("Gemmini conv...\n");
384384
uint64_t start_gemmini = read_cycles();
385385

386-
tiled_conv_auto(
387-
// tiled_conv(
386+
tiled_conv_A_stride_auto(
388387
BATCH_SIZE, IN_DIM, IN_CHANNELS,
389388
OUT_CHANNELS, OUT_DIM,
390389
STRIDE, PADDING, KERNEL_DIM,
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// See LICENSE for license details.
2+
3+
#include <stdint.h>
4+
#include <stddef.h>
5+
#include <assert.h>
6+
#include <stdlib.h>
7+
#include <stdio.h>
8+
#ifndef BAREMETAL
9+
#include <sys/mman.h>
10+
#endif
11+
#include "include/gemmini_testutils.h"
12+
13+
#define BLOCK_STRIDE (DIM*2)
14+
#define COLS (DIM*MAX_BLOCK_LEN)
15+
16+
void printMatrixFull(elem_t m[DIM][COLS]) {
17+
for (size_t i = 0; i < DIM; ++i) {
18+
for (size_t j = 0; j < COLS; ++j)
19+
#ifndef ELEM_T_IS_FLOAT
20+
printf("%d ", m[i][j]);
21+
#else
22+
printf("%x ", elem_t_to_elem_t_bits(m[i][j]));
23+
#endif
24+
printf("\n");
25+
}
26+
}
27+
28+
int main() {
29+
#ifndef BAREMETAL
30+
if (mlockall(MCL_CURRENT | MCL_FUTURE) != 0) {
31+
perror("mlockall failed");
32+
exit(1);
33+
}
34+
#endif
35+
36+
static elem_t In[DIM][COLS] row_align(1);
37+
static elem_t Out[DIM][COLS] row_align(1);
38+
39+
// printf("Flush\n");
40+
gemmini_flush(0);
41+
gemmini_extended4_config_ld(COLS * sizeof(elem_t), MVIN_SCALE_IDENTITY, false, BLOCK_STRIDE, 0);
42+
gemmini_config_st(COLS * sizeof(elem_t));
43+
44+
for (size_t i = 0; i < DIM; ++i)
45+
for (size_t j = 0; j < COLS; ++j)
46+
In[i][j] = i*COLS + j;
47+
48+
gemmini_block_mvin(In, 0, MAX_BLOCK_LEN);
49+
50+
gemmini_fence();
51+
52+
for (size_t n = 0; n < MAX_BLOCK_LEN; ++n) {
53+
gemmini_mvout((elem_t*)Out + n * DIM, n*BLOCK_STRIDE);
54+
}
55+
56+
// printf("Fence");
57+
gemmini_fence();
58+
59+
if (!MAT_IS_EQUAL(DIM, COLS, In, Out)) {
60+
printf("Matrix:\n");
61+
printMatrixFull(In);
62+
printf("\nMatrix output:\n");
63+
printMatrixFull(Out);
64+
printf("\n");
65+
66+
exit(1);
67+
}
68+
69+
exit(0);
70+
}
71+

bareMetalC/mvin_mvout_zeros.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// See LICENSE for license details.
2+
3+
#include <stdint.h>
4+
#include <stddef.h>
5+
#include <assert.h>
6+
#include <stdlib.h>
7+
#include <stdio.h>
8+
#ifndef BAREMETAL
9+
#include <sys/mman.h>
10+
#endif
11+
#include "include/gemmini_testutils.h"
12+
13+
int main() {
14+
#ifndef BAREMETAL
15+
if (mlockall(MCL_CURRENT | MCL_FUTURE) != 0) {
16+
perror("mlockall failed");
17+
exit(1);
18+
}
19+
#endif
20+
21+
// printf("Flush\n");
22+
gemmini_flush(0);
23+
gemmini_config_ld(DIM * sizeof(elem_t));
24+
gemmini_config_st(DIM * sizeof(elem_t));
25+
26+
static elem_t Out[DIM][DIM] row_align(1);
27+
28+
// printf("Mvin %d\n", n);
29+
gemmini_mvin(NULL, 0);
30+
// printf("Mvout %d\n", n);
31+
gemmini_mvout(Out, 0);
32+
33+
// printf("Fence");
34+
gemmini_fence();
35+
36+
bool success = true;
37+
38+
for (size_t i = 0; i < DIM; i++)
39+
for (size_t j = 0; j < DIM; j++)
40+
if (Out[i][j] != 0)
41+
success = false;
42+
43+
if (!success) {
44+
printf("Matrix:\n");
45+
printMatrix(Out);
46+
printf("\n");
47+
48+
exit(1);
49+
}
50+
51+
exit(0);
52+
}
53+

bareMetalC/tiled_matmul_ws_At.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ typedef acc_t ACC_T;
2121
typedef elem_t ACC_T;
2222
#endif
2323

24+
#ifdef FAST
25+
26+
#define MAT_DIM_I 19
27+
#define MAT_DIM_K 18
28+
#define MAT_DIM_J 17
29+
30+
#else
31+
2432
#ifndef BAREMETAL
2533
#define MAT_DIM_I 500
2634
#define MAT_DIM_K 412
@@ -31,6 +39,8 @@ typedef elem_t ACC_T;
3139
#define MAT_DIM_J 30
3240
#endif
3341

42+
#endif // ifdef FAST
43+
3444
void print_tile(elem_t* in, int tile_dim) {
3545
for (size_t r = 0; r < tile_dim; r++) {
3646
printf("row starts at: %p\n", in +r*MAT_DIM_J);
@@ -104,30 +114,51 @@ int main() {
104114
// printf("Init A\n");
105115
for (size_t i = 0; i < MAT_DIM_K; ++i) {
106116
for (size_t j = 0; j < MAT_DIM_I; ++j) {
117+
#ifdef FAST
118+
full_A[i][j] = 1;
119+
#else
107120
full_A[i][j] = rand() % 2;
121+
#endif
108122
}
109123
}
110124

111125
// printf("Init B\n");
112126
for (size_t i = 0; i < MAT_DIM_K; ++i) {
113127
for (size_t j = 0; j < MAT_DIM_J; ++j) {
128+
#ifdef FAST
129+
full_B[i][j] = 1;
130+
#else
114131
full_B[i][j] = rand() % 2;
132+
#endif
115133
}
116134
}
117135

118136
// printf("Init D\n");
119137
for (size_t i = 0; i < MAT_DIM_I; ++i) {
120138
for (size_t j = 0; j < MAT_DIM_J; ++j) {
139+
#ifdef FAST
140+
full_D[i][j] = NO_BIAS ? 0 : 1;
141+
#else
121142
full_D[i][j] = NO_BIAS ? 0 : rand() % 2;
143+
#endif
122144
}
123145
}
124146

147+
#ifdef FAST
148+
for (size_t i = 0; i < MAT_DIM_I; ++i) {
149+
for (size_t j = 0; j < MAT_DIM_J; ++j) {
150+
gold[i][j] = MAT_DIM_K + !NO_BIAS;
151+
}
152+
}
153+
#else
125154
printf("Starting slow CPU matmul\n");
126155
unsigned long cpu_start = read_cycles();
127156
full_matmul(full_A, full_B, full_D, gold_full);
128157
unsigned long cpu_end = read_cycles();
129158
printf("Cycles taken: %u\n", cpu_end-cpu_start);
130159
full_matscale(gold_full, gold, ACC_SCALE_IDENTITY);
160+
#endif // #ifdef FAST
161+
131162
#endif
132163

133164
printf("Starting gemmini matmul\n");
@@ -150,8 +181,12 @@ int main() {
150181
printf("C:\n");
151182
full_printMatrix(full_C);
152183
printf("Gold:\n");
184+
#ifdef FAST
185+
printf("All elements must be %d\n", MAT_DIM_K + !NO_BIAS);
186+
#else
153187
full_printMatrix(gold);
154188
printf("\n");
189+
#endif // ifdef FAST
155190

156191
exit(1);
157192
}

bareMetalC/tiled_matmul_ws_Bt.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// See LICENSE for license details.
21

32
#include <stdint.h>
43
#include <stddef.h>
@@ -21,6 +20,14 @@ typedef acc_t ACC_T;
2120
typedef elem_t ACC_T;
2221
#endif
2322

23+
#ifdef FAST
24+
25+
#define MAT_DIM_I 19
26+
#define MAT_DIM_K 18
27+
#define MAT_DIM_J 17
28+
29+
#else
30+
2431
#ifndef BAREMETAL
2532
#define MAT_DIM_I 500
2633
#define MAT_DIM_K 412
@@ -29,8 +36,11 @@ typedef elem_t ACC_T;
2936
#define MAT_DIM_I 60
3037
#define MAT_DIM_K 50
3138
#define MAT_DIM_J 30
39+
3240
#endif
3341

42+
#endif // ifdef FAST
43+
3444
void print_tile(elem_t* in, int tile_dim) {
3545
for (size_t r = 0; r < tile_dim; r++) {
3646
printf("row starts at: %p\n", in +r*MAT_DIM_J);
@@ -104,30 +114,51 @@ int main() {
104114
// printf("Init A\n");
105115
for (size_t i = 0; i < MAT_DIM_I; ++i) {
106116
for (size_t j = 0; j < MAT_DIM_K; ++j) {
117+
#ifdef FAST
118+
full_A[i][j] = 1;
119+
#else
107120
full_A[i][j] = rand() % 2;
121+
#endif
108122
}
109123
}
110124

111125
// printf("Init B\n");
112126
for (size_t i = 0; i < MAT_DIM_J; ++i) {
113127
for (size_t j = 0; j < MAT_DIM_K; ++j) {
128+
#ifdef FAST
129+
full_B[i][j] = 1;
130+
#else
114131
full_B[i][j] = rand() % 2;
132+
#endif
115133
}
116134
}
117135

118136
// printf("Init D\n");
119137
for (size_t i = 0; i < MAT_DIM_I; ++i) {
120138
for (size_t j = 0; j < MAT_DIM_J; ++j) {
139+
#ifdef FAST
140+
full_D[i][j] = NO_BIAS ? 0 : 1;
141+
#else
121142
full_D[i][j] = NO_BIAS ? 0 : rand() % 2;
143+
#endif
122144
}
123145
}
124146

147+
#ifdef FAST
148+
for (size_t i = 0; i < MAT_DIM_I; ++i) {
149+
for (size_t j = 0; j < MAT_DIM_J; ++j) {
150+
gold[i][j] = MAT_DIM_K + !NO_BIAS;
151+
}
152+
}
153+
#else
125154
printf("Starting slow CPU matmul\n");
126155
unsigned long cpu_start = read_cycles();
127156
full_matmul(full_A, full_B, full_D, gold_full);
128157
unsigned long cpu_end = read_cycles();
129158
printf("Cycles taken: %u\n", cpu_end-cpu_start);
130159
full_matscale(gold_full, gold, ACC_SCALE_IDENTITY);
160+
#endif // #ifdef FAST
161+
131162
#endif
132163

133164
printf("Starting gemmini matmul\n");
@@ -149,9 +180,14 @@ int main() {
149180
if (!full_is_equal(full_C, gold)) {
150181
printf("C:\n");
151182
full_printMatrix(full_C);
183+
152184
printf("Gold:\n");
185+
#ifdef FAST
186+
printf("All elements must be %d\n", MAT_DIM_K + !NO_BIAS);
187+
#else
153188
full_printMatrix(gold);
154189
printf("\n");
190+
#endif // ifdef FAST
155191

156192
exit(1);
157193
}

0 commit comments

Comments
 (0)