]> git.proxmox.com Git - ceph.git/blame - ceph/src/isa-l/erasure_code/gf_2vect_dot_prod_sse_perf.c
bump version to 15.2.6-pve1
[ceph.git] / ceph / src / isa-l / erasure_code / gf_2vect_dot_prod_sse_perf.c
CommitLineData
7c673cae
FG
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_2vect_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
66typedef unsigned char u8;
67
68void 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
79void 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
91int main(int argc, char *argv[])
92{
93 int i, j;
94 void *buf;
95 u8 g1[TEST_SOURCES], g2[TEST_SOURCES], g_tbls[2 * TEST_SOURCES * 32];
96 u8 *dest1, *dest2, *dest_ref1, *dest_ref2, *dest_ptrs[2];
97 u8 *buffs[TEST_SOURCES];
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 dest_ref1 = buf;
128
129 if (posix_memalign(&buf, 64, TEST_LEN)) {
130 printf("alloc error: Fail");
131 return -1;
132 }
133 dest_ref2 = buf;
134
135 dest_ptrs[0] = dest1;
136 dest_ptrs[1] = dest2;
137
138 // Performance test
139 for (i = 0; i < TEST_SOURCES; i++)
140 for (j = 0; j < TEST_LEN; j++)
141 buffs[i][j] = rand();
142
143 memset(dest1, 0, TEST_LEN);
144 memset(dest2, 0, TEST_LEN);
145 memset(dest_ref1, 0, TEST_LEN);
146 memset(dest_ref2, 0, TEST_LEN);
147
148 for (i = 0; i < TEST_SOURCES; i++) {
149 g1[i] = rand();
150 g2[i] = rand();
151 }
152
153 for (j = 0; j < TEST_SOURCES; j++) {
154 gf_vect_mul_init(g1[j], &g_tbls[j * 32]);
155 gf_vect_mul_init(g2[j], &g_tbls[(32 * TEST_SOURCES) + (j * 32)]);
156 }
157
158 gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref1);
159 gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[32 * TEST_SOURCES], buffs,
160 dest_ref2);
161
162#ifdef DO_REF_PERF
163 perf_start(&start);
164 for (i = 0; i < TEST_LOOPS / 100; i++) {
165 for (j = 0; j < TEST_SOURCES; j++) {
166 gf_vect_mul_init(g1[j], &g_tbls[j * 32]);
167 gf_vect_mul_init(g2[j], &g_tbls[(32 * TEST_SOURCES) + (j * 32)]);
168 }
169
170 gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref1);
171 gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[32 * TEST_SOURCES],
172 buffs, dest_ref2);
173 }
174 perf_stop(&stop);
175 printf("gf_2vect_dot_prod_base" TEST_TYPE_STR ": ");
176 perf_print(stop, start, (long long)TEST_LEN * (TEST_SOURCES + 2) * i);
177#endif
178
179 FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest_ptrs);
180
181 perf_start(&start);
182 for (i = 0; i < TEST_LOOPS; i++) {
183 for (j = 0; j < TEST_SOURCES; j++) {
184 gf_vect_mul_init(g1[j], &g_tbls[j * 32]);
185 gf_vect_mul_init(g2[j], &g_tbls[(32 * TEST_SOURCES) + (j * 32)]);
186 }
187
188 FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest_ptrs);
189 }
190 perf_stop(&stop);
191 printf(xstr(FUNCTION_UNDER_TEST) TEST_TYPE_STR ": ");
192 perf_print(stop, start, (long long)TEST_LEN * (TEST_SOURCES + 2) * i);
193
194 if (0 != memcmp(dest_ref1, dest1, TEST_LEN)) {
195 printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test1\n");
196 dump_matrix(buffs, 5, TEST_SOURCES);
197 printf("dprod_base:");
198 dump(dest_ref1, 25);
199 printf("dprod_dut:");
200 dump(dest1, 25);
201 return -1;
202 }
203 if (0 != memcmp(dest_ref2, dest2, TEST_LEN)) {
204 printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test2\n");
205 dump_matrix(buffs, 5, TEST_SOURCES);
206 printf("dprod_base:");
207 dump(dest_ref2, 25);
208 printf("dprod_dut:");
209 dump(dest2, 25);
210 return -1;
211 }
212
213 printf("pass perf check\n");
214 return 0;
215
216}