-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathmain.c
More file actions
113 lines (94 loc) · 3.3 KB
/
main.c
File metadata and controls
113 lines (94 loc) · 3.3 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Copyright 2025 University of Bologna and Fondazione Chips-IT.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
//
// Alberto Dequino <alberto.dequino@unibo.it>
// Alex Marchioni <alex.marchioni@chips.it>
#include <stdint.h>
#include "testinputs.h"
#include "testoutputs.h"
#include "Network.h"
int main(void) {
uint32_t hartid = get_hartid();
uint32_t l1_tile_base = get_l1_base(hartid);
uint32_t cycle_start, cycle_stop;
/* Init tile's iDMA, Redmule, fsync, event-unit */
idma_config_t idma_cfg = {.hartid = hartid};
idma_controller_t idma_ctrl = {
.base = NULL,
.cfg = &idma_cfg,
.api = &idma_api,
};
redmule_config_t redmule_cfg = {.hartid = hartid};
redmule_controller_t redmule_ctrl = {
.base = NULL,
.cfg = &redmule_cfg,
.api = &redmule_api,
};
fsync_config_t fsync_cfg = {.hartid = hartid};
fsync_controller_t fsync_ctrl = {
.base = NULL,
.cfg = &fsync_cfg,
.api = &fsync_api,
};
fsync_init(&fsync_ctrl);
idma_init(&idma_ctrl);
redmule_init(&redmule_ctrl);
eu_config_t eu_cfg = {.hartid = hartid};
eu_controller_t eu_ctrl = {
.base = NULL,
.cfg = &eu_cfg,
.api = &eu_api,
};
eu_init(&eu_ctrl);
eu_fsync_init(&eu_ctrl, 0);
eu_redmule_init(&eu_ctrl, 0);
eu_idma_init(&eu_ctrl, 0);
/* initialization */
InitNetwork();
fsync_sync_level(&fsync_ctrl, MAX_SYNC_LVL - 1, 0);
eu_fsync_wait(&eu_ctrl, WAIT_MODE);
/* input copy */
// TODO: check if memcopy is necessary!!!
if (hartid == 0) {
for (uint32_t buf = 0; buf < num_inputs; buf++) {
memcpy(inputs[buf], _inputs[buf], inputs_bytes[buf]);
}
}
fsync_sync_global(&fsync_ctrl);
eu_fsync_wait(&eu_ctrl, WAIT_MODE);
/* execution */
cycle_start = perf_get_cycles();
RunNetwork();
cycle_stop = perf_get_cycles();
printf("id: %d, cycles: %d\n", hartid, cycle_stop - cycle_start);
fsync_sync_global(&fsync_ctrl);
eu_fsync_wait(&eu_ctrl, WAIT_MODE);
/* comparison */
uint32_t errors = 0;
uint32_t tests = 0;
OUTPUTTYPE *computed_buf;
OUTPUTTYPE *expected_buf;
if (hartid == 0) {
for (uint32_t buf = 0; buf < num_outputs; buf++) {
tests += outputs_bytes[buf] / sizeof(OUTPUTTYPE);
for (uint32_t i = 0; i < outputs_bytes[buf] / sizeof(OUTPUTTYPE); i++) {
OUTPUTTYPE expected = ((OUTPUTTYPE *)_outputs[buf])[i];
OUTPUTTYPE computed = ((OUTPUTTYPE *)outputs[buf])[i];
OUTPUTTYPE diff = (computed > expected) ? (computed - expected) : (expected - computed);
if(diff > 0) {
if (ISOUTPUTFLOAT) {
// printf("Expected %10.6f computed: %10.6f diff: %10.6f (at index %u in output %u)\n",
// expected, computed, diff, i, buf);
} else {
printf("Expected %d computed: %d diff: %d (at index %u in output %u)\n",
expected, computed, diff, i, buf);
}
errors++;
}
}
}
printf("Number of errors: %d\n", errors);
}
return errors;
}