]> git.proxmox.com Git - ceph.git/blob - ceph/src/isa-l/erasure_code/gf_vect_dot_prod_avx_perf.c
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / isa-l / erasure_code / gf_vect_dot_prod_avx_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_vect_dot_prod_avx
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 g[TEST_SOURCES], g_tbls[TEST_SOURCES * 32], *dest, *dest_ref;
96 u8 *temp_buff, *buffs[TEST_SOURCES];
97 struct perf start, stop;
98
99 printf(xstr(FUNCTION_UNDER_TEST) ": %dx%d\n", TEST_SOURCES, TEST_LEN);
100
101 // Allocate the arrays
102 for (i = 0; i < TEST_SOURCES; i++) {
103 if (posix_memalign(&buf, 64, TEST_LEN)) {
104 printf("alloc error: Fail");
105 return -1;
106 }
107 buffs[i] = buf;
108 }
109
110 if (posix_memalign(&buf, 64, TEST_LEN)) {
111 printf("alloc error: Fail");
112 return -1;
113 }
114 dest = buf;
115
116 if (posix_memalign(&buf, 64, TEST_LEN)) {
117 printf("alloc error: Fail");
118 return -1;
119 }
120 dest_ref = buf;
121
122 if (posix_memalign(&buf, 64, TEST_LEN)) {
123 printf("alloc error: Fail");
124 return -1;
125 }
126 temp_buff = buf;
127
128 // Performance test
129 for (i = 0; i < TEST_SOURCES; i++)
130 for (j = 0; j < TEST_LEN; j++)
131 buffs[i][j] = rand();
132
133 memset(dest, 0, TEST_LEN);
134 memset(temp_buff, 0, TEST_LEN);
135 memset(dest_ref, 0, TEST_LEN);
136 memset(g, 0, TEST_SOURCES);
137
138 for (i = 0; i < TEST_SOURCES; i++)
139 g[i] = rand();
140
141 for (j = 0; j < TEST_SOURCES; j++)
142 gf_vect_mul_init(g[j], &g_tbls[j * 32]);
143
144 gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref);
145
146 #ifdef DO_REF_PERF
147 perf_start(&start);
148 for (i = 0; i < TEST_LOOPS; i++) {
149 for (j = 0; j < TEST_SOURCES; j++)
150 gf_vect_mul_init(g[j], &g_tbls[j * 32]);
151
152 gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref);
153 }
154 perf_stop(&stop);
155 printf("gf_vect_dot_prod_base" TEST_TYPE_STR ": ");
156 perf_print(stop, start, (long long)TEST_LEN * (TEST_SOURCES + 1) * i);
157 #endif
158
159 FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest);
160
161 perf_start(&start);
162 for (i = 0; i < TEST_LOOPS; i++) {
163 for (j = 0; j < TEST_SOURCES; j++)
164 gf_vect_mul_init(g[j], &g_tbls[j * 32]);
165
166 FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest);
167 }
168 perf_stop(&stop);
169 printf(xstr(FUNCTION_UNDER_TEST) TEST_TYPE_STR ": ");
170 perf_print(stop, start, (long long)TEST_LEN * (TEST_SOURCES + 1) * i);
171
172 if (0 != memcmp(dest_ref, dest, TEST_LEN)) {
173 printf("Fail zero " xstr(FUNCTION_UNDER_TEST) " test\n");
174 dump_matrix(buffs, 5, TEST_SOURCES);
175 printf("dprod_base:");
176 dump(dest_ref, 25);
177 printf("dprod:");
178 dump(dest, 25);
179 return -1;
180 }
181
182 printf("pass perf check\n");
183 return 0;
184 }