• R/O
  • SSH
  • HTTPS

chibios: Commit


Commit MetaInfo

Revisão14525 (tree)
Hora2021-06-10 19:13:26
Autorgdisirio

Mensagem de Log

FFT benchmark.

Mudança Sumário

Diff

--- trunk/test/corebmk/source/test/corebmk_test_root.c (revision 14524)
+++ trunk/test/corebmk/source/test/corebmk_test_root.c (revision 14525)
@@ -13,6 +13,13 @@
1313 See the License for the specific language governing permissions and
1414 limitations under the License.
1515 */
16+/*
17+ This module is based on the work of John Walker (April of 1989) and
18+ merely adapted to work in ChibiOS. The author has not specified
19+ additional license terms so this is released using the most permissive
20+ license used in ChibiOS. The license covers the changes only, not the
21+ original work.
22+ */
1623
1724 /**
1825 * @mainpage Test Suite Specification
@@ -43,7 +50,9 @@
4350 * @brief Array of test sequences.
4451 */
4552 const testsequence_t * const corebmk_test_suite_array[] = {
53+#if (CH_CFG_USE_HEAP == TRUE) || defined(__DOXYGEN__)
4654 &corebmk_test_sequence_001,
55+#endif
4756 NULL
4857 };
4958
@@ -51,7 +60,7 @@
5160 * @brief Test suite root structure.
5261 */
5362 const testsuite_t corebmk_test_suite = {
54- "ChibiOS/NIL Test Suite",
63+ "Core Benchmarks Test Suite",
5564 corebmk_test_suite_array
5665 };
5766
--- trunk/test/corebmk/source/test/corebmk_test_root.h (revision 14524)
+++ trunk/test/corebmk/source/test/corebmk_test_root.h (revision 14525)
@@ -13,6 +13,13 @@
1313 See the License for the specific language governing permissions and
1414 limitations under the License.
1515 */
16+/*
17+ This module is based on the work of John Walker (April of 1989) and
18+ merely adapted to work in ChibiOS. The author has not specified
19+ additional license terms so this is released using the most permissive
20+ license used in ChibiOS. The license covers the changes only, not the
21+ original work.
22+ */
1623
1724 /**
1825 * @file corebmk_test_root.h
--- trunk/test/corebmk/source/test/corebmk_test_sequence_001.c (revision 14524)
+++ trunk/test/corebmk/source/test/corebmk_test_sequence_001.c (revision 14525)
@@ -13,6 +13,13 @@
1313 See the License for the specific language governing permissions and
1414 limitations under the License.
1515 */
16+/*
17+ This module is based on the work of John Walker (April of 1989) and
18+ merely adapted to work in ChibiOS. The author has not specified
19+ additional license terms so this is released using the most permissive
20+ license used in ChibiOS. The license covers the changes only, not the
21+ original work.
22+ */
1623
1724 #include "hal.h"
1825 #include "corebmk_test_root.h"
@@ -29,17 +36,40 @@
2936 * This sequence reports configuration and version information about
3037 * execution environment.
3138 *
39+ * <h2>Conditions</h2>
40+ * This sequence is only executed if the following preprocessor condition
41+ * evaluates to true:
42+ * - CH_CFG_USE_HEAP == TRUE
43+ * .
44+ *
3245 * <h2>Test Cases</h2>
3346 * - @subpage corebmk_test_001_001
47+ * - @subpage corebmk_test_001_002
3448 * .
3549 */
3650
51+#if (CH_CFG_USE_HEAP == TRUE) || defined(__DOXYGEN__)
52+
3753 /****************************************************************************
3854 * Shared code.
3955 ****************************************************************************/
4056
57+#include <string.h>
58+
4159 #include "ch.h"
4260
61+#include "ffbench_mod.h"
62+
63+#define ASIZE 64 /* Array edge size. */
64+#define NITERATIONS 10 /* Number of iterations. */
65+#define NPASSES 50 /* Number of FFT/Inverse passes. */
66+
67+#define max(a, b) ((a) > (b) ? (a) : (b))
68+#define min(a, b) ((a) <= (b) ? (a) : (b))
69+
70+float *fdatas;
71+double *fdatad;
72+
4373 /****************************************************************************
4474 * Test cases.
4575 ****************************************************************************/
@@ -102,6 +132,123 @@
102132 corebmk_test_001_001_execute
103133 };
104134
135+/**
136+ * @page corebmk_test_001_002 [1.2] Two-dimensional FFT
137+ *
138+ * <h2>Description</h2>
139+ * Two-dimensional FFT benchmark, execution time is reported, expected
140+ * results are checked.
141+ *
142+ * <h2>Test Steps</h2>
143+ * - [1.2.1] Allocating memory for single precision work matrix.
144+ * - [1.2.2] Printing setup.
145+ * - [1.2.3] Running single precision FFT iterations.
146+ * - [1.2.4] Printing results.
147+ * .
148+ */
149+
150+static void corebmk_test_001_002_setup(void) {
151+ fdatas = NULL;
152+}
153+
154+static void corebmk_test_001_002_teardown(void) {
155+ if (fdatas != NULL) {
156+ chHeapFree((void *)fdatas);
157+ }
158+}
159+
160+static void corebmk_test_001_002_execute(void) {
161+ time_msecs_t msecs;
162+ size_t fasize, fanum;
163+ int faedge;
164+ int nsize[] = {0, 0, 0};
165+
166+ /* [1.2.1] Allocating memory for single precision work matrix.*/
167+ test_set_step(1);
168+ {
169+ faedge = ASIZE; /* FFT array edge size.*/
170+ fanum = faedge * faedge;
171+ fasize = ((fanum + 1) * 2 * sizeof(float)); /* FFT array size.*/
172+ fdatas = (float *)chHeapAlloc(NULL, fasize);
173+ nsize[1] = nsize[2] = faedge;
174+
175+ test_assert(fdatas != NULL, "single precision matrix allocation failed");
176+ }
177+ test_end_step(1);
178+
179+ /* [1.2.2] Printing setup.*/
180+ test_set_step(2);
181+ {
182+ test_print("--- Matrix: ");
183+ test_printn(ASIZE);
184+ test_print("x");
185+ test_printn(ASIZE);
186+ test_println("");
187+ test_print("--- Iter. : ");
188+ test_printn(NITERATIONS);
189+ test_println("");
190+ test_print("--- Passes: ");
191+ test_printn(NPASSES);
192+ test_println("");
193+ }
194+ test_end_step(2);
195+
196+ /* [1.2.3] Running single precision FFT iterations.*/
197+ test_set_step(3);
198+ {
199+ systime_t start, end;
200+ int i, j, k, iters;
201+
202+ /* Time stamp for benchmark start.*/
203+ start = chVTGetSystemTime();
204+
205+ iters = 0;
206+ for (k = 0; k < NITERATIONS; k++) {
207+
208+ /* Generate data array to process.*/
209+ memset(fdatas, 0, fasize);
210+ for (i = 0; i < faedge; i++) {
211+ for (j = 0; j < faedge; j++) {
212+ if (((i & 15) == 8) || ((j & 15) == 8)) {
213+ fdatas[1 + ((faedge * i) + j) * 2] = 128.0;
214+ }
215+ }
216+ }
217+
218+ for (i = 0; i < NPASSES; i++) {
219+ /* Transform image to frequency domain.*/
220+ fourn_float(fdatas, nsize, 2, 1);
221+
222+ /* Back-transform to image.*/
223+ fourn_float(fdatas, nsize, 2, -1);
224+
225+ iters++;
226+ }
227+ }
228+
229+ /* Time stamp for benchmark end.*/
230+ end = chVTGetSystemTime();
231+ msecs = chTimeI2MS(chTimeDiffX(start, end));
232+ }
233+ test_end_step(3);
234+
235+ /* [1.2.4] Printing results.*/
236+ test_set_step(4);
237+ {
238+ test_print("--- Time : ");
239+ test_printn(msecs);
240+ test_println(" milliseconds");
241+ }
242+ test_end_step(4);
243+}
244+
245+static const testcase_t corebmk_test_001_002 = {
246+ "Two-dimensional FFT",
247+ corebmk_test_001_002_setup,
248+ corebmk_test_001_002_teardown,
249+ corebmk_test_001_002_execute
250+};
251+
105252 /****************************************************************************
106253 * Exported data.
107254 ****************************************************************************/
@@ -111,6 +258,7 @@
111258 */
112259 const testcase_t * const corebmk_test_sequence_001_array[] = {
113260 &corebmk_test_001_001,
261+ &corebmk_test_001_002,
114262 NULL
115263 };
116264
@@ -121,3 +269,5 @@
121269 "Information",
122270 corebmk_test_sequence_001_array
123271 };
272+
273+#endif /* CH_CFG_USE_HEAP == TRUE */
--- trunk/test/corebmk/source/test/corebmk_test_sequence_001.h (revision 14524)
+++ trunk/test/corebmk/source/test/corebmk_test_sequence_001.h (revision 14525)
@@ -13,6 +13,13 @@
1313 See the License for the specific language governing permissions and
1414 limitations under the License.
1515 */
16+/*
17+ This module is based on the work of John Walker (April of 1989) and
18+ merely adapted to work in ChibiOS. The author has not specified
19+ additional license terms so this is released using the most permissive
20+ license used in ChibiOS. The license covers the changes only, not the
21+ original work.
22+ */
1623
1724 /**
1825 * @file corebmk_test_sequence_001.h
--- trunk/test/corebmk/source/test/ffbench_mod.c (revision 14524)
+++ trunk/test/corebmk/source/test/ffbench_mod.c (revision 14525)
@@ -21,11 +21,82 @@
2121 original work.
2222 */
2323
24-static void corebmk_fourn(Float data[], int nn[], const int ndim, const int isign) {
24+#include <math.h>
25+
26+#define SWAP(a, b) tempr=(a); (a)=(b); (b)=tempr
27+
28+void fourn_float(float data[], int nn[], const int ndim, const int isign) {
2529 int i1, i2, i3;
2630 int i2rev, i3rev, ip1, ip2, ip3, ifp1, ifp2;
2731 int ibit, idim, k1, k2, n, nprev, nrem, ntot;
28- Float tempi, tempr;
32+ float tempi, tempr;
33+ float theta, wi, wpi, wpr, wr, wtemp;
34+
35+ ntot = 1;
36+ for (idim = 1; idim <= ndim; idim++) {
37+ ntot *= nn[idim];
38+ }
39+ nprev = 1;
40+ for (idim = ndim; idim >= 1; idim--) {
41+ n = nn[idim];
42+ nrem = ntot / (n * nprev);
43+ ip1 = nprev << 1;
44+ ip2 = ip1 * n;
45+ ip3 = ip2 * nrem;
46+ i2rev = 1;
47+ for (i2 = 1; i2 <= ip2; i2 += ip1) {
48+ if (i2 < i2rev) {
49+ for (i1 = i2; i1 <= i2 + ip1 - 2; i1 += 2) {
50+ for (i3 = i1; i3 <= ip3; i3 += ip2) {
51+ i3rev = i2rev + i3 - i2;
52+ SWAP(data[i3], data[i3rev]);
53+ SWAP(data[i3 + 1], data[i3rev + 1]);
54+ }
55+ }
56+ }
57+ ibit = ip2 >> 1;
58+ while (ibit >= ip1 && i2rev > ibit) {
59+ i2rev -= ibit;
60+ ibit >>= 1;
61+ }
62+ i2rev += ibit;
63+ }
64+ ifp1 = ip1;
65+ while (ifp1 < ip2) {
66+ ifp2 = ifp1 << 1;
67+ theta = (float)isign * 6.28318530717959f / (ifp2 / ip1);
68+ wtemp = sinf(0.5f * theta);
69+ wpr = -2.0f * wtemp * wtemp;
70+ wpi = sinf(theta);
71+ wr = 1.0f;
72+ wi = 0.0f;
73+ for (i3 = 1; i3 <= ifp1; i3 += ip1) {
74+ for (i1 = i3; i1 <= i3 + ip1 - 2; i1 += 2) {
75+ for (i2 = i1; i2 <= ip3; i2 += ifp2) {
76+ k1 = i2;
77+ k2 = k1 + ifp1;
78+ tempr = wr * data[k2] - wi * data[k2 + 1];
79+ tempi = wr * data[k2 + 1] + wi * data[k2];
80+ data[k2] = data[k1] - tempr;
81+ data[k2 + 1] = data[k1 + 1] - tempi;
82+ data[k1] += tempr;
83+ data[k1 + 1] += tempi;
84+ }
85+ }
86+ wr = (wtemp = wr) * wpr - wi * wpi + wr;
87+ wi = wi * wpr + wtemp * wpi + wi;
88+ }
89+ ifp1 = ifp2;
90+ }
91+ nprev *= n;
92+ }
93+}
94+
95+void fourn_double(double data[], int nn[], const int ndim, const int isign) {
96+ int i1, i2, i3;
97+ int i2rev, i3rev, ip1, ip2, ip3, ifp1, ifp2;
98+ int ibit, idim, k1, k2, n, nprev, nrem, ntot;
99+ double tempi, tempr;
29100 double theta, wi, wpi, wpr, wr, wtemp;
30101
31102 ntot = 1;
--- trunk/test/corebmk/source/test/ffbench_mod.h (nonexistent)
+++ trunk/test/corebmk/source/test/ffbench_mod.h (revision 14525)
@@ -0,0 +1,31 @@
1+/*
2+ ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3+
4+ Licensed under the Apache License, Version 2.0 (the "License");
5+ you may not use this file except in compliance with the License.
6+ You may obtain a copy of the License at
7+
8+ http://www.apache.org/licenses/LICENSE-2.0
9+
10+ Unless required by applicable law or agreed to in writing, software
11+ distributed under the License is distributed on an "AS IS" BASIS,
12+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ See the License for the specific language governing permissions and
14+ limitations under the License.
15+*/
16+/*
17+ This module is based on the work of John Walker (April of 1989) and
18+ merely adapted to work in ChibiOS. The author has not specified
19+ additional license terms so this is released using the most permissive
20+ license used in ChibiOS. The license covers the changes only, not the
21+ original work.
22+ */
23+
24+#ifdef __cplusplus
25+extern "C" {
26+#endif
27+ void fourn_float(float data[], int nn[], const int ndim, const int isign);
28+ void fourn_double(double data[], int nn[], const int ndim, const int isign);
29+#ifdef __cplusplus
30+}
31+#endif
--- trunk/test/corebmk/configuration.xml (revision 14524)
+++ trunk/test/corebmk/configuration.xml (revision 14525)
@@ -3,7 +3,7 @@
33 id="org.chibios.spc5.components.portable.chibios_unitary_tests_engine">
44 <description>
55 <brief>
6- <value>ChibiOS/NIL Test Suite.</value>
6+ <value>Core Benchmarks Test Suite.</value>
77 </brief>
88 <copyright>
99 <value><![CDATA[/*
@@ -20,7 +20,14 @@
2020 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2121 See the License for the specific language governing permissions and
2222 limitations under the License.
23-*/]]></value>
23+*/
24+/*
25+ This module is based on the work of John Walker (April of 1989) and
26+ merely adapted to work in ChibiOS. The author has not specified
27+ additional license terms so this is released using the most permissive
28+ license used in ChibiOS. The license covers the changes only, not the
29+ original work.
30+ */]]></value>
2431 </copyright>
2532 <introduction>
2633 <value>Test suite for core benchmarks. The purpose of this suite
@@ -58,11 +65,25 @@
5865 </value>
5966 </description>
6067 <condition>
61- <value />
68+ <value><![CDATA[CH_CFG_USE_HEAP == TRUE]]></value>
6269 </condition>
6370 <shared_code>
6471 <value><![CDATA[
72+#include <string.h>
73+
6574 #include "ch.h"
75+
76+#include "ffbench_mod.h"
77+
78+#define ASIZE 64 /* Array edge size. */
79+#define NITERATIONS 10 /* Number of iterations. */
80+#define NPASSES 50 /* Number of FFT/Inverse passes. */
81+
82+#define max(a, b) ((a) > (b) ? (a) : (b))
83+#define min(a, b) ((a) <= (b) ? (a) : (b))
84+
85+float *fdatas;
86+double *fdatad;
6687 ]]></value>
6788 </shared_code>
6889 <cases>
@@ -133,6 +154,143 @@
133154 </step>
134155 </steps>
135156 </case>
157+ <case>
158+ <brief>
159+ <value>Two-dimensional FFT</value>
160+ </brief>
161+ <description>
162+ <value>Two-dimensional FFT benchmark, execution time is reported, expected results are checked.</value>
163+ </description>
164+ <condition>
165+ <value />
166+ </condition>
167+ <various_code>
168+ <setup_code>
169+ <value><![CDATA[
170+fdatas = NULL;
171+]]></value>
172+ </setup_code>
173+ <teardown_code>
174+ <value><![CDATA[
175+if (fdatas != NULL) {
176+ chHeapFree((void *)fdatas);
177+}
178+]]></value>
179+ </teardown_code>
180+ <local_variables>
181+ <value><![CDATA[
182+time_msecs_t msecs;
183+size_t fasize, fanum;
184+int faedge;
185+int nsize[] = {0, 0, 0};
186+]]></value>
187+ </local_variables>
188+ </various_code>
189+ <steps>
190+ <step>
191+ <description>
192+ <value>Allocating memory for single precision work matrix</value>
193+ </description>
194+ <tags>
195+ <value />
196+ </tags>
197+ <code>
198+ <value><![CDATA[
199+faedge = ASIZE; /* FFT array edge size.*/
200+fanum = faedge * faedge;
201+fasize = ((fanum + 1) * 2 * sizeof(float)); /* FFT array size.*/
202+fdatas = (float *)chHeapAlloc(NULL, fasize);
203+nsize[1] = nsize[2] = faedge;
204+
205+test_assert(fdatas != NULL, "single precision matrix allocation failed");
206+]]></value>
207+ </code>
208+ </step>
209+ <step>
210+ <description>
211+ <value>Printing setup</value>
212+ </description>
213+ <tags>
214+ <value />
215+ </tags>
216+ <code>
217+ <value><![CDATA[
218+test_print("--- Matrix: ");
219+test_printn(ASIZE);
220+test_print("x");
221+test_printn(ASIZE);
222+test_println("");
223+test_print("--- Iter. : ");
224+test_printn(NITERATIONS);
225+test_println("");
226+test_print("--- Passes: ");
227+test_printn(NPASSES);
228+test_println("");
229+]]></value>
230+ </code>
231+ </step>
232+ <step>
233+ <description>
234+ <value>Running single precision FFT iterations</value>
235+ </description>
236+ <tags>
237+ <value />
238+ </tags>
239+ <code>
240+ <value><![CDATA[
241+systime_t start, end;
242+int i, j, k, iters;
243+
244+/* Time stamp for benchmark start.*/
245+start = chVTGetSystemTime();
246+
247+iters = 0;
248+for (k = 0; k < NITERATIONS; k++) {
249+
250+ /* Generate data array to process.*/
251+ memset(fdatas, 0, fasize);
252+ for (i = 0; i < faedge; i++) {
253+ for (j = 0; j < faedge; j++) {
254+ if (((i & 15) == 8) || ((j & 15) == 8)) {
255+ fdatas[1 + ((faedge * i) + j) * 2] = 128.0;
256+ }
257+ }
258+ }
259+
260+ for (i = 0; i < NPASSES; i++) {
261+ /* Transform image to frequency domain.*/
262+ fourn_float(fdatas, nsize, 2, 1);
263+
264+ /* Back-transform to image.*/
265+ fourn_float(fdatas, nsize, 2, -1);
266+
267+ iters++;
268+ }
269+}
270+
271+/* Time stamp for benchmark end.*/
272+end = chVTGetSystemTime();
273+msecs = chTimeI2MS(chTimeDiffX(start, end));
274+]]></value>
275+ </code>
276+ </step>
277+ <step>
278+ <description>
279+ <value>Printing results</value>
280+ </description>
281+ <tags>
282+ <value />
283+ </tags>
284+ <code>
285+ <value><![CDATA[
286+test_print("--- Time : ");
287+test_printn(msecs);
288+test_println(" milliseconds");
289+]]></value>
290+ </code>
291+ </step>
292+ </steps>
293+ </case>
136294 </cases>
137295 </sequence>
138296 </sequences>
Show on old repository browser