forked from eembc/audiomark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
executable file
·143 lines (124 loc) · 3.49 KB
/
main.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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
* Copyright (C) 2022 EEMBC
* Copyright (C) 2022 Arm Limited
*
* All EEMBC Benchmark Software are products of EEMBC and are provided under the
* terms of the EEMBC Benchmark License Agreements. The EEMBC Benchmark Software
* are proprietary intellectual properties of EEMBC and its Members and is
* protected under all applicable laws, including all applicable copyright laws.
*
* If you received this EEMBC Benchmark Software without having a currently
* effective EEMBC Benchmark License Agreement, you must discontinue use.
*/
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include "ee_audiomark.h"
// There are several POSIX assumptions in this implementation.
#if defined __linux__ || __APPLE__
#include <time.h>
#elif defined _WIN32
#include <sys\timeb.h>
#elif defined __arm__
#include <RTE_Components.h>
#if defined __PERF_COUNTER__
#include "perf_counter.h"
#endif
#else
#error "Operating system not recognized"
#endif
#include <assert.h>
uint64_t
th_microseconds(void)
{
uint64_t usec = 0;
#if defined __linux__ || __APPLE__
const long NSEC_PER_SEC = 1000 * 1000 * 1000;
const long TIMER_RES_DIVIDER = 1000;
struct timespec t;
clock_gettime(CLOCK_REALTIME, &t);
usec = t.tv_sec * (NSEC_PER_SEC / TIMER_RES_DIVIDER)
+ t.tv_nsec / TIMER_RES_DIVIDER;
#elif defined _WIN32
struct timeb t;
ftime(&t);
usec = ((uint64_t)t.time) * 1000 * 1000 + ((uint64_t)t.millitm) * 1000;
#elif defined __arm__ && defined __PERF_COUNTER__
usec = (uint64_t)get_system_us();
#else
#error "Operating system not recognized"
#endif
return usec;
}
bool
time_audiomark_run(uint32_t iterations, uint64_t *dt)
{
uint64_t t0 = 0;
uint64_t t1 = 0;
bool err = false;
t0 = th_microseconds();
for (uint32_t i = 0; i < iterations; ++i)
{
if (ee_audiomark_run())
{
err = true;
break;
}
}
t1 = th_microseconds();
*dt = t1 - t0;
return err;
}
int
main(void)
{
bool err = false;
uint32_t iterations = 1;
uint64_t dt = 0;
printf("Initializing\n");
if (ee_audiomark_initialize())
{
printf("Failed to initialize\n");
return -1;
}
printf("Computing run speed\n");
do
{
iterations *= 2;
err = time_audiomark_run(iterations, &dt);
if (err)
{
break;
}
} while (dt < 1e6f);
if (err)
{
printf("Failed to compute iteration speed\n");
goto exit;
}
// Must run for 10 sec. or at least 10 iterations
float scale = 11e6f / dt;
iterations = (uint32_t)((float)iterations * scale);
iterations = iterations < 10 ? 10 : iterations;
printf("Measuring\n");
err = time_audiomark_run(iterations, &dt);
if (err)
{
printf("Failed main performance run\n");
goto exit;
}
/**
* The input stream is 24e3 samples at 16 kHz, which means to exactly
* match the throughput of the stream the score would be one iteration
* per 1.5 seconds. The score is how many times faster than the ADC
* the pipeline runs. x 1000 to make it a bigger number.
*/
float sec = (float)dt / 1.0e6f;
float score = (float)iterations / sec * 1000.f * (1.0f / 1.5f);
printf("Total runtime : %.3f seconds\n", sec);
printf("Total iterations : %d iterations\n", iterations);
printf("Score : %f AudioMarks\n", score);
exit:
ee_audiomark_release();
return err ? -1 : 0;
}