]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | /********************************************************************** |
2 | Copyright(c) 2011-2015 Intel Corporation All rights reserved. | |
3 | ||
4 | Redistribution and use in source and binary forms, with or without | |
5 | modification, are permitted provided that the following conditions | |
6 | are met: | |
7 | * Redistributions of source code must retain the above copyright | |
8 | notice, this list of conditions and the following disclaimer. | |
9 | * Redistributions in binary form must reproduce the above copyright | |
10 | notice, this list of conditions and the following disclaimer in | |
11 | the documentation and/or other materials provided with the | |
12 | distribution. | |
13 | * Neither the name of Intel Corporation nor the names of its | |
14 | contributors may be used to endorse or promote products derived | |
15 | from this software without specific prior written permission. | |
16 | ||
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
28 | **********************************************************************/ | |
29 | ||
30 | #include <stdio.h> | |
31 | #include <stdlib.h> | |
32 | #include <string.h> // for memset, memcmp | |
33 | #include "erasure_code.h" | |
34 | #include "test.h" | |
35 | ||
36 | #ifndef FUNCTION_UNDER_TEST | |
37 | # define FUNCTION_UNDER_TEST gf_vect_dot_prod | |
38 | #endif | |
39 | ||
40 | #define str(s) #s | |
41 | #define xstr(s) str(s) | |
42 | ||
43 | //#define CACHED_TEST | |
44 | #ifdef CACHED_TEST | |
45 | // Cached test, loop many times over small dataset | |
46 | # define TEST_SOURCES 10 | |
47 | # define TEST_LEN 8*1024 | |
9f95a23c TL |
48 | # define TEST_TYPE_STR "_warm" |
49 | #else | |
50 | # ifndef TEST_CUSTOM | |
51 | // Uncached test. Pull from large mem base. | |
52 | # define TEST_SOURCES 10 | |
53 | # define GT_L3_CACHE 32*1024*1024 /* some number > last level cache */ | |
54 | # define TEST_LEN ((GT_L3_CACHE / TEST_SOURCES) & ~(64-1)) | |
9f95a23c TL |
55 | # define TEST_TYPE_STR "_cold" |
56 | # else | |
57 | # define TEST_TYPE_STR "_cus" | |
9f95a23c TL |
58 | # endif |
59 | #endif | |
60 | ||
61 | typedef unsigned char u8; | |
62 | ||
63 | void dump(unsigned char *buf, int len) | |
64 | { | |
65 | int i; | |
66 | for (i = 0; i < len;) { | |
67 | printf(" %2x", 0xff & buf[i++]); | |
68 | if (i % 32 == 0) | |
69 | printf("\n"); | |
70 | } | |
71 | printf("\n"); | |
72 | } | |
73 | ||
74 | void dump_matrix(unsigned char **s, int k, int m) | |
75 | { | |
76 | int i, j; | |
77 | for (i = 0; i < k; i++) { | |
78 | for (j = 0; j < m; j++) { | |
79 | printf(" %2x", s[i][j]); | |
80 | } | |
81 | printf("\n"); | |
82 | } | |
83 | printf("\n"); | |
84 | } | |
85 | ||
f67539c2 TL |
86 | void vect_dot_prod_perf(void (*fun_ptr) |
87 | (int, int, unsigned char *, unsigned char **, unsigned char *), | |
88 | u8 * g, u8 * g_tbls, u8 ** buffs, u8 * dest_ref) | |
89 | { | |
90 | int j; | |
91 | for (j = 0; j < TEST_SOURCES; j++) | |
92 | gf_vect_mul_init(g[j], &g_tbls[j * 32]); | |
93 | ||
94 | (*fun_ptr) (TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref); | |
95 | } | |
96 | ||
9f95a23c TL |
97 | int main(int argc, char *argv[]) |
98 | { | |
99 | int i, j; | |
100 | void *buf; | |
101 | u8 g[TEST_SOURCES], g_tbls[TEST_SOURCES * 32], *dest, *dest_ref; | |
102 | u8 *temp_buff, *buffs[TEST_SOURCES]; | |
f67539c2 | 103 | struct perf start; |
9f95a23c TL |
104 | |
105 | printf(xstr(FUNCTION_UNDER_TEST) ": %dx%d\n", TEST_SOURCES, TEST_LEN); | |
106 | ||
107 | // Allocate the arrays | |
108 | for (i = 0; i < TEST_SOURCES; i++) { | |
109 | if (posix_memalign(&buf, 64, TEST_LEN)) { | |
110 | printf("alloc error: Fail"); | |
111 | return -1; | |
112 | } | |
113 | buffs[i] = buf; | |
114 | } | |
115 | ||
116 | if (posix_memalign(&buf, 64, TEST_LEN)) { | |
117 | printf("alloc error: Fail"); | |
118 | return -1; | |
119 | } | |
120 | dest = buf; | |
121 | ||
122 | if (posix_memalign(&buf, 64, TEST_LEN)) { | |
123 | printf("alloc error: Fail"); | |
124 | return -1; | |
125 | } | |
126 | dest_ref = buf; | |
127 | ||
128 | if (posix_memalign(&buf, 64, TEST_LEN)) { | |
129 | printf("alloc error: Fail"); | |
130 | return -1; | |
131 | } | |
132 | temp_buff = buf; | |
133 | ||
134 | // Performance test | |
135 | for (i = 0; i < TEST_SOURCES; i++) | |
136 | for (j = 0; j < TEST_LEN; j++) | |
137 | buffs[i][j] = rand(); | |
138 | ||
139 | memset(dest, 0, TEST_LEN); | |
140 | memset(temp_buff, 0, TEST_LEN); | |
141 | memset(dest_ref, 0, TEST_LEN); | |
142 | memset(g, 0, TEST_SOURCES); | |
143 | ||
144 | for (i = 0; i < TEST_SOURCES; i++) | |
145 | g[i] = rand(); | |
146 | ||
9f95a23c | 147 | #ifdef DO_REF_PERF |
f67539c2 TL |
148 | BENCHMARK(&start, BENCHMARK_TIME, |
149 | vect_dot_prod_perf(&gf_vect_dot_prod_base, g, g_tbls, buffs, dest_ref) | |
150 | ); | |
9f95a23c | 151 | printf("gf_vect_dot_prod_base" TEST_TYPE_STR ": "); |
f67539c2 TL |
152 | perf_print(start, (long long)TEST_LEN * (TEST_SOURCES + 1)); |
153 | #else | |
154 | vect_dot_prod_perf(&gf_vect_dot_prod_base, g, g_tbls, buffs, dest_ref); | |
9f95a23c TL |
155 | #endif |
156 | ||
f67539c2 TL |
157 | BENCHMARK(&start, BENCHMARK_TIME, |
158 | vect_dot_prod_perf(&FUNCTION_UNDER_TEST, g, g_tbls, buffs, dest)); | |
9f95a23c | 159 | printf(xstr(FUNCTION_UNDER_TEST) TEST_TYPE_STR ": "); |
f67539c2 | 160 | perf_print(start, (long long)TEST_LEN * (TEST_SOURCES + 1)); |
9f95a23c TL |
161 | |
162 | if (0 != memcmp(dest_ref, dest, TEST_LEN)) { | |
163 | printf("Fail zero " xstr(FUNCTION_UNDER_TEST) " test\n"); | |
164 | dump_matrix(buffs, 5, TEST_SOURCES); | |
165 | printf("dprod_base:"); | |
166 | dump(dest_ref, 25); | |
167 | printf("dprod:"); | |
168 | dump(dest, 25); | |
169 | return -1; | |
170 | } | |
171 | ||
172 | printf("pass perf check\n"); | |
173 | return 0; | |
174 | } |