]> git.proxmox.com Git - ceph.git/blob - ceph/src/isa-l/erasure_code/gf_3vect_dot_prod_sse_perf.c
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / isa-l / erasure_code / gf_3vect_dot_prod_sse_perf.c
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_3vect_dot_prod_sse
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
48 # define TEST_LOOPS 40000
49 # define TEST_TYPE_STR "_warm"
50 #else
51 # ifndef TEST_CUSTOM
52 // Uncached test. Pull from large mem base.
53 # define TEST_SOURCES 10
54 # define GT_L3_CACHE 32*1024*1024 /* some number > last level cache */
55 # define TEST_LEN ((GT_L3_CACHE / TEST_SOURCES) & ~(64-1))
56 # define TEST_LOOPS 100
57 # define TEST_TYPE_STR "_cold"
58 # else
59 # define TEST_TYPE_STR "_cus"
60 # ifndef TEST_LOOPS
61 # define TEST_LOOPS 1000
62 # endif
63 # endif
64 #endif
65
66 typedef unsigned char u8;
67
68 void dump(unsigned char *buf, int len)
69 {
70 int i;
71 for (i = 0; i < len;) {
72 printf(" %2x", 0xff & buf[i++]);
73 if (i % 32 == 0)
74 printf("\n");
75 }
76 printf("\n");
77 }
78
79 void dump_matrix(unsigned char **s, int k, int m)
80 {
81 int i, j;
82 for (i = 0; i < k; i++) {
83 for (j = 0; j < m; j++) {
84 printf(" %2x", s[i][j]);
85 }
86 printf("\n");
87 }
88 printf("\n");
89 }
90
91 int main(int argc, char *argv[])
92 {
93 int i, j;
94 void *buf;
95 u8 g1[TEST_SOURCES], g2[TEST_SOURCES], g3[TEST_SOURCES];
96 u8 g_tbls[3 * TEST_SOURCES * 32], *dest_ptrs[3], *buffs[TEST_SOURCES];
97 u8 *dest1, *dest2, *dest3, *dest_ref1, *dest_ref2, *dest_ref3;
98 struct perf start, stop;
99
100 printf(xstr(FUNCTION_UNDER_TEST) ": %dx%d\n", TEST_SOURCES, TEST_LEN);
101
102 // Allocate the arrays
103 for (i = 0; i < TEST_SOURCES; i++) {
104 if (posix_memalign(&buf, 64, TEST_LEN)) {
105 printf("alloc error: Fail");
106 return -1;
107 }
108 buffs[i] = buf;
109 }
110
111 if (posix_memalign(&buf, 64, TEST_LEN)) {
112 printf("alloc error: Fail");
113 return -1;
114 }
115 dest1 = buf;
116
117 if (posix_memalign(&buf, 64, TEST_LEN)) {
118 printf("alloc error: Fail");
119 return -1;
120 }
121 dest2 = buf;
122
123 if (posix_memalign(&buf, 64, TEST_LEN)) {
124 printf("alloc error: Fail");
125 return -1;
126 }
127 dest3 = buf;
128
129 if (posix_memalign(&buf, 64, TEST_LEN)) {
130 printf("alloc error: Fail");
131 return -1;
132 }
133 dest_ref1 = buf;
134
135 if (posix_memalign(&buf, 64, TEST_LEN)) {
136 printf("alloc error: Fail");
137 return -1;
138 }
139 dest_ref2 = buf;
140
141 if (posix_memalign(&buf, 64, TEST_LEN)) {
142 printf("alloc error: Fail");
143 return -1;
144 }
145 dest_ref3 = buf;
146
147 dest_ptrs[0] = dest1;
148 dest_ptrs[1] = dest2;
149 dest_ptrs[2] = dest3;
150
151 // Performance test
152 for (i = 0; i < TEST_SOURCES; i++)
153 for (j = 0; j < TEST_LEN; j++)
154 buffs[i][j] = rand();
155
156 memset(dest1, 0, TEST_LEN);
157 memset(dest2, 0, TEST_LEN);
158 memset(dest_ref1, 0, TEST_LEN);
159 memset(dest_ref2, 0, TEST_LEN);
160
161 for (i = 0; i < TEST_SOURCES; i++) {
162 g1[i] = rand();
163 g2[i] = rand();
164 g3[i] = rand();
165 }
166
167 for (j = 0; j < TEST_SOURCES; j++) {
168 gf_vect_mul_init(g1[j], &g_tbls[j * 32]);
169 gf_vect_mul_init(g2[j], &g_tbls[(32 * TEST_SOURCES) + (j * 32)]);
170 gf_vect_mul_init(g3[j], &g_tbls[(64 * TEST_SOURCES) + (j * 32)]);
171 }
172
173 gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref1);
174 gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[32 * TEST_SOURCES], buffs,
175 dest_ref2);
176 gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[64 * TEST_SOURCES], buffs,
177 dest_ref3);
178
179 #ifdef DO_REF_PERF
180 perf_start(&start);
181 for (i = 0; i < TEST_LOOPS / 100; i++) {
182 for (j = 0; j < TEST_SOURCES; j++) {
183 gf_vect_mul_init(g1[j], &g_tbls[j * 32]);
184 gf_vect_mul_init(g2[j], &g_tbls[(32 * TEST_SOURCES) + (j * 32)]);
185 gf_vect_mul_init(g3[j], &g_tbls[(64 * TEST_SOURCES) + (j * 32)]);
186 }
187
188 gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref1);
189 gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[32 * TEST_SOURCES],
190 buffs, dest_ref2);
191 gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[64 * TEST_SOURCES],
192 buffs, dest_ref3);
193 }
194 perf_stop(&stop);
195 printf("gf_3vect_dot_prod_base" TEST_TYPE_STR ": ");
196 perf_print(stop, start, (long long)TEST_LEN * (TEST_SOURCES + 3) * i);
197 #endif
198
199 FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest_ptrs);
200
201 perf_start(&start);
202 for (i = 0; i < TEST_LOOPS; i++) {
203 for (j = 0; j < TEST_SOURCES; j++) {
204 gf_vect_mul_init(g1[j], &g_tbls[j * 32]);
205 gf_vect_mul_init(g2[j], &g_tbls[(32 * TEST_SOURCES) + (j * 32)]);
206 gf_vect_mul_init(g3[j], &g_tbls[(64 * TEST_SOURCES) + (j * 32)]);
207 }
208
209 FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest_ptrs);
210 }
211 perf_stop(&stop);
212 printf(xstr(FUNCTION_UNDER_TEST) TEST_TYPE_STR ": ");
213 perf_print(stop, start, (long long)TEST_LEN * (TEST_SOURCES + 3) * i);
214
215 if (0 != memcmp(dest_ref1, dest1, TEST_LEN)) {
216 printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test1\n");
217 dump_matrix(buffs, 5, TEST_SOURCES);
218 printf("dprod_base:");
219 dump(dest_ref1, 25);
220 printf("dprod_dut:");
221 dump(dest1, 25);
222 return -1;
223 }
224 if (0 != memcmp(dest_ref2, dest2, TEST_LEN)) {
225 printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test2\n");
226 dump_matrix(buffs, 5, TEST_SOURCES);
227 printf("dprod_base:");
228 dump(dest_ref2, 25);
229 printf("dprod_dut:");
230 dump(dest2, 25);
231 return -1;
232 }
233 if (0 != memcmp(dest_ref3, dest3, TEST_LEN)) {
234 printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test3\n");
235 dump_matrix(buffs, 5, TEST_SOURCES);
236 printf("dprod_base:");
237 dump(dest_ref3, 25);
238 printf("dprod_dut:");
239 dump(dest3, 25);
240 return -1;
241 }
242
243 printf("pass perf check\n");
244 return 0;
245
246 }