]>
git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/isa-l/erasure_code/gf_vect_dot_prod_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
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_TYPE_STR "_warm"
51 // Uncached test. Pull from large mem base.
52 # define TEST_SOURCES 10
53 # define GT_L3_CACHE 32*1024*1024 /* some number > last level cache */
54 # define TEST_LEN ((GT_L3_CACHE / TEST_SOURCES) & ~(64-1))
55 # define TEST_TYPE_STR "_cold"
57 # define TEST_TYPE_STR "_cus"
61 typedef unsigned char u8
;
63 void dump(unsigned char *buf
, int len
)
66 for (i
= 0; i
< len
;) {
67 printf(" %2x", 0xff & buf
[i
++]);
74 void dump_matrix(unsigned char **s
, int k
, int m
)
77 for (i
= 0; i
< k
; i
++) {
78 for (j
= 0; j
< m
; j
++) {
79 printf(" %2x", s
[i
][j
]);
86 void vect_dot_prod_perf(void (*fun_ptr
)
87 (int, int, unsigned char *, unsigned char **, unsigned char *),
88 u8
* g
, u8
* g_tbls
, u8
** buffs
, u8
* dest_ref
)
91 for (j
= 0; j
< TEST_SOURCES
; j
++)
92 gf_vect_mul_init(g
[j
], &g_tbls
[j
* 32]);
94 (*fun_ptr
) (TEST_LEN
, TEST_SOURCES
, &g_tbls
[0], buffs
, dest_ref
);
97 int main(int argc
, char *argv
[])
101 u8 g
[TEST_SOURCES
], g_tbls
[TEST_SOURCES
* 32], *dest
, *dest_ref
;
102 u8
*temp_buff
, *buffs
[TEST_SOURCES
];
105 printf(xstr(FUNCTION_UNDER_TEST
) ": %dx%d\n", TEST_SOURCES
, TEST_LEN
);
107 // Allocate the arrays
108 for (i
= 0; i
< TEST_SOURCES
; i
++) {
109 if (posix_memalign(&buf
, 64, TEST_LEN
)) {
110 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");
128 if (posix_memalign(&buf
, 64, TEST_LEN
)) {
129 printf("alloc error: Fail");
135 for (i
= 0; i
< TEST_SOURCES
; i
++)
136 for (j
= 0; j
< TEST_LEN
; j
++)
137 buffs
[i
][j
] = rand();
139 memset(dest
, 0, TEST_LEN
);
140 memset(temp_buff
, 0, TEST_LEN
);
141 memset(dest_ref
, 0, TEST_LEN
);
142 memset(g
, 0, TEST_SOURCES
);
144 for (i
= 0; i
< TEST_SOURCES
; i
++)
148 BENCHMARK(&start
, BENCHMARK_TIME
,
149 vect_dot_prod_perf(&gf_vect_dot_prod_base
, g
, g_tbls
, buffs
, dest_ref
)
151 printf("gf_vect_dot_prod_base" TEST_TYPE_STR
": ");
152 perf_print(start
, (long long)TEST_LEN
* (TEST_SOURCES
+ 1));
154 vect_dot_prod_perf(&gf_vect_dot_prod_base
, g
, g_tbls
, buffs
, dest_ref
);
157 BENCHMARK(&start
, BENCHMARK_TIME
,
158 vect_dot_prod_perf(&FUNCTION_UNDER_TEST
, g
, g_tbls
, buffs
, dest
));
159 printf(xstr(FUNCTION_UNDER_TEST
) TEST_TYPE_STR
": ");
160 perf_print(start
, (long long)TEST_LEN
* (TEST_SOURCES
+ 1));
162 if (0 != memcmp(dest_ref
, dest
, TEST_LEN
)) {
163 printf("Fail zero " xstr(FUNCTION_UNDER_TEST
) " test\n");
164 dump_matrix(buffs
, 5, TEST_SOURCES
);
165 printf("dprod_base:");
172 printf("pass perf check\n");