]>
git.proxmox.com Git - ceph.git/blob - ceph/src/isa-l/erasure_code/gf_3vect_dot_prod_sse_perf.c
1 /**********************************************************************
2 Copyright(c) 2011-2015 Intel Corporation All rights reserved.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
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
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.
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 **********************************************************************/
32 #include <string.h> // for memset, memcmp
33 #include "erasure_code.h"
36 #ifndef FUNCTION_UNDER_TEST
37 # define FUNCTION_UNDER_TEST gf_3vect_dot_prod_sse
41 #define xstr(s) str(s)
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"
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"
59 # define TEST_TYPE_STR "_cus"
61 # define TEST_LOOPS 1000
66 typedef unsigned char u8
;
68 void dump(unsigned char *buf
, int len
)
71 for (i
= 0; i
< len
;) {
72 printf(" %2x", 0xff & buf
[i
++]);
79 void dump_matrix(unsigned char **s
, int k
, int m
)
82 for (i
= 0; i
< k
; i
++) {
83 for (j
= 0; j
< m
; j
++) {
84 printf(" %2x", s
[i
][j
]);
91 int main(int argc
, char *argv
[])
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
;
100 printf(xstr(FUNCTION_UNDER_TEST
) ": %dx%d\n", TEST_SOURCES
, TEST_LEN
);
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");
111 if (posix_memalign(&buf
, 64, TEST_LEN
)) {
112 printf("alloc error: Fail");
117 if (posix_memalign(&buf
, 64, TEST_LEN
)) {
118 printf("alloc error: Fail");
123 if (posix_memalign(&buf
, 64, TEST_LEN
)) {
124 printf("alloc error: Fail");
129 if (posix_memalign(&buf
, 64, TEST_LEN
)) {
130 printf("alloc error: Fail");
135 if (posix_memalign(&buf
, 64, TEST_LEN
)) {
136 printf("alloc error: Fail");
141 if (posix_memalign(&buf
, 64, TEST_LEN
)) {
142 printf("alloc error: Fail");
147 dest_ptrs
[0] = dest1
;
148 dest_ptrs
[1] = dest2
;
149 dest_ptrs
[2] = dest3
;
152 for (i
= 0; i
< TEST_SOURCES
; i
++)
153 for (j
= 0; j
< TEST_LEN
; j
++)
154 buffs
[i
][j
] = rand();
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
);
161 for (i
= 0; i
< TEST_SOURCES
; i
++) {
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)]);
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
,
176 gf_vect_dot_prod_base(TEST_LEN
, TEST_SOURCES
, &g_tbls
[64 * TEST_SOURCES
], buffs
,
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)]);
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
],
191 gf_vect_dot_prod_base(TEST_LEN
, TEST_SOURCES
, &g_tbls
[64 * TEST_SOURCES
],
195 printf("gf_3vect_dot_prod_base" TEST_TYPE_STR
": ");
196 perf_print(stop
, start
, (long long)TEST_LEN
* (TEST_SOURCES
+ 3) * i
);
199 FUNCTION_UNDER_TEST(TEST_LEN
, TEST_SOURCES
, g_tbls
, buffs
, dest_ptrs
);
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)]);
209 FUNCTION_UNDER_TEST(TEST_LEN
, TEST_SOURCES
, g_tbls
, buffs
, dest_ptrs
);
212 printf(xstr(FUNCTION_UNDER_TEST
) TEST_TYPE_STR
": ");
213 perf_print(stop
, start
, (long long)TEST_LEN
* (TEST_SOURCES
+ 3) * i
);
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:");
220 printf("dprod_dut:");
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:");
229 printf("dprod_dut:");
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:");
238 printf("dprod_dut:");
243 printf("pass perf check\n");