]>
git.proxmox.com Git - ceph.git/blob - ceph/src/isa-l/erasure_code/gf_vect_dot_prod_avx_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_vect_dot_prod_avx
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 g
[TEST_SOURCES
], g_tbls
[TEST_SOURCES
* 32], *dest
, *dest_ref
;
96 u8
*temp_buff
, *buffs
[TEST_SOURCES
];
97 struct perf start
, stop
;
99 printf(xstr(FUNCTION_UNDER_TEST
) ": %dx%d\n", TEST_SOURCES
, TEST_LEN
);
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");
110 if (posix_memalign(&buf
, 64, TEST_LEN
)) {
111 printf("alloc error: Fail");
116 if (posix_memalign(&buf
, 64, TEST_LEN
)) {
117 printf("alloc error: Fail");
122 if (posix_memalign(&buf
, 64, TEST_LEN
)) {
123 printf("alloc error: Fail");
129 for (i
= 0; i
< TEST_SOURCES
; i
++)
130 for (j
= 0; j
< TEST_LEN
; j
++)
131 buffs
[i
][j
] = rand();
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
);
138 for (i
= 0; i
< TEST_SOURCES
; i
++)
141 for (j
= 0; j
< TEST_SOURCES
; j
++)
142 gf_vect_mul_init(g
[j
], &g_tbls
[j
* 32]);
144 gf_vect_dot_prod_base(TEST_LEN
, TEST_SOURCES
, &g_tbls
[0], buffs
, dest_ref
);
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]);
152 gf_vect_dot_prod_base(TEST_LEN
, TEST_SOURCES
, &g_tbls
[0], buffs
, dest_ref
);
155 printf("gf_vect_dot_prod_base" TEST_TYPE_STR
": ");
156 perf_print(stop
, start
, (long long)TEST_LEN
* (TEST_SOURCES
+ 1) * i
);
159 FUNCTION_UNDER_TEST(TEST_LEN
, TEST_SOURCES
, g_tbls
, buffs
, dest
);
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]);
166 FUNCTION_UNDER_TEST(TEST_LEN
, TEST_SOURCES
, g_tbls
, buffs
, dest
);
169 printf(xstr(FUNCTION_UNDER_TEST
) TEST_TYPE_STR
": ");
170 perf_print(stop
, start
, (long long)TEST_LEN
* (TEST_SOURCES
+ 1) * i
);
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:");
182 printf("pass perf check\n");