mirror of
https://github.com/intel/isa-l.git
synced 2024-12-12 17:33:50 +01:00
test: Remove redundant arch-specific tests
Change-Id: Ifdbac9d8a99888bfd7a12da5d47dd07b8f85481d Signed-off-by: Greg Tucker <greg.b.tucker@intel.com>
This commit is contained in:
parent
6dcf6edba3
commit
cb4cea60da
@ -102,28 +102,16 @@ lsrc_x86_32 += \
|
||||
|
||||
unit_tests32 += erasure_code/erasure_code_base_test \
|
||||
erasure_code/erasure_code_test \
|
||||
erasure_code/erasure_code_sse_test \
|
||||
erasure_code/gf_vect_mul_test \
|
||||
erasure_code/gf_vect_mul_base_test \
|
||||
erasure_code/gf_vect_dot_prod_base_test \
|
||||
erasure_code/gf_vect_dot_prod_test \
|
||||
erasure_code/gf_vect_dot_prod_avx_test \
|
||||
erasure_code/gf_vect_dot_prod_sse_test \
|
||||
erasure_code/gf_2vect_dot_prod_sse_test \
|
||||
erasure_code/gf_3vect_dot_prod_sse_test \
|
||||
erasure_code/gf_4vect_dot_prod_sse_test
|
||||
erasure_code/gf_vect_dot_prod_test
|
||||
|
||||
perf_tests32 += erasure_code/gf_vect_mul_perf \
|
||||
erasure_code/gf_vect_dot_prod_perf \
|
||||
erasure_code/erasure_code_perf \
|
||||
erasure_code/erasure_code_base_perf \
|
||||
erasure_code/erasure_code_sse_perf \
|
||||
erasure_code/gf_vect_dot_prod_1tbl \
|
||||
erasure_code/gf_vect_dot_prod_avx_perf\
|
||||
erasure_code/gf_vect_dot_prod_sse_perf\
|
||||
erasure_code/gf_2vect_dot_prod_sse_perf \
|
||||
erasure_code/gf_3vect_dot_prod_sse_perf \
|
||||
erasure_code/gf_4vect_dot_prod_sse_perf
|
||||
erasure_code/gf_vect_dot_prod_1tbl
|
||||
|
||||
src_include += -I $(srcdir)/erasure_code
|
||||
extern_hdrs += include/erasure_code.h \
|
||||
@ -138,41 +126,28 @@ check_tests += erasure_code/gf_vect_mul_test \
|
||||
erasure_code/gf_inverse_test \
|
||||
erasure_code/erasure_code_update_test
|
||||
|
||||
unit_tests += erasure_code/gf_vect_mul_sse_test \
|
||||
erasure_code/gf_vect_mul_avx_test \
|
||||
unit_tests += \
|
||||
erasure_code/gf_vect_mul_base_test \
|
||||
erasure_code/gf_vect_dot_prod_sse_test \
|
||||
erasure_code/gf_vect_dot_prod_avx_test \
|
||||
erasure_code/gf_2vect_dot_prod_sse_test \
|
||||
erasure_code/gf_3vect_dot_prod_sse_test \
|
||||
erasure_code/gf_4vect_dot_prod_sse_test \
|
||||
erasure_code/gf_5vect_dot_prod_sse_test \
|
||||
erasure_code/gf_6vect_dot_prod_sse_test \
|
||||
erasure_code/gf_vect_dot_prod_base_test \
|
||||
erasure_code/gf_vect_dot_prod_test \
|
||||
erasure_code/gf_vect_mad_test \
|
||||
erasure_code/erasure_code_base_test \
|
||||
erasure_code/erasure_code_sse_test
|
||||
erasure_code/erasure_code_base_test
|
||||
|
||||
perf_tests += erasure_code/gf_vect_mul_perf \
|
||||
erasure_code/gf_vect_mul_sse_perf \
|
||||
erasure_code/gf_vect_mul_avx_perf \
|
||||
erasure_code/gf_vect_dot_prod_sse_perf \
|
||||
erasure_code/gf_vect_dot_prod_avx_perf \
|
||||
erasure_code/gf_2vect_dot_prod_sse_perf \
|
||||
erasure_code/gf_3vect_dot_prod_sse_perf \
|
||||
erasure_code/gf_4vect_dot_prod_sse_perf \
|
||||
erasure_code/gf_5vect_dot_prod_sse_perf \
|
||||
erasure_code/gf_6vect_dot_prod_sse_perf \
|
||||
erasure_code/gf_vect_dot_prod_perf \
|
||||
erasure_code/gf_vect_dot_prod_1tbl \
|
||||
erasure_code/gf_vect_mad_perf \
|
||||
erasure_code/erasure_code_perf \
|
||||
erasure_code/erasure_code_base_perf \
|
||||
erasure_code/erasure_code_sse_perf \
|
||||
erasure_code/erasure_code_update_perf
|
||||
|
||||
other_tests += erasure_code/gen_rs_matrix_limits
|
||||
other_tests += \
|
||||
erasure_code/gen_rs_matrix_limits \
|
||||
erasure_code/gf_2vect_dot_prod_sse_test \
|
||||
erasure_code/gf_3vect_dot_prod_sse_test \
|
||||
erasure_code/gf_4vect_dot_prod_sse_test \
|
||||
erasure_code/gf_5vect_dot_prod_sse_test \
|
||||
erasure_code/gf_6vect_dot_prod_sse_test
|
||||
|
||||
other_src += include/test.h \
|
||||
include/types.h
|
||||
|
@ -1,168 +0,0 @@
|
||||
/**********************************************************************
|
||||
Copyright(c) 2011-2015 Intel Corporation All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Intel Corporation nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h> // for memset, memcmp
|
||||
#include "erasure_code.h"
|
||||
#include "test.h"
|
||||
|
||||
//#define CACHED_TEST
|
||||
#ifdef CACHED_TEST
|
||||
// Cached test, loop many times over small dataset
|
||||
# define TEST_SOURCES 32
|
||||
# define TEST_LEN(m) ((128*1024 / m) & ~(64-1))
|
||||
# define TEST_LOOPS(m) (10000*m)
|
||||
# define TEST_TYPE_STR "_warm"
|
||||
#else
|
||||
# ifndef TEST_CUSTOM
|
||||
// Uncached test. Pull from large mem base.
|
||||
# define TEST_SOURCES 32
|
||||
# define GT_L3_CACHE 32*1024*1024 /* some number > last level cache */
|
||||
# define TEST_LEN(m) ((GT_L3_CACHE / m) & ~(64-1))
|
||||
# define TEST_LOOPS(m) (50*m)
|
||||
# define TEST_TYPE_STR "_cold"
|
||||
# else
|
||||
# define TEST_TYPE_STR "_cus"
|
||||
# ifndef TEST_LOOPS
|
||||
# define TEST_LOOPS(m) 1000
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define MMAX TEST_SOURCES
|
||||
#define KMAX TEST_SOURCES
|
||||
|
||||
typedef unsigned char u8;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, j, rtest, m, k, nerrs, r;
|
||||
void *buf;
|
||||
u8 *temp_buffs[TEST_SOURCES], *buffs[TEST_SOURCES];
|
||||
u8 a[MMAX * KMAX], b[MMAX * KMAX], c[MMAX * KMAX], d[MMAX * KMAX];
|
||||
u8 g_tbls[KMAX * TEST_SOURCES * 32], src_in_err[TEST_SOURCES];
|
||||
u8 src_err_list[TEST_SOURCES], *recov[TEST_SOURCES];
|
||||
struct perf start, stop;
|
||||
|
||||
// Pick test parameters
|
||||
m = 14;
|
||||
k = 10;
|
||||
nerrs = 4;
|
||||
const u8 err_list[] = { 2, 4, 5, 7 };
|
||||
|
||||
printf("erasure_code_sse_perf: %dx%d %d\n", m, TEST_LEN(m), nerrs);
|
||||
|
||||
if (m > MMAX || k > KMAX || nerrs > (m - k)) {
|
||||
printf(" Input test parameter error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(src_err_list, err_list, nerrs);
|
||||
memset(src_in_err, 0, TEST_SOURCES);
|
||||
for (i = 0; i < nerrs; i++)
|
||||
src_in_err[src_err_list[i]] = 1;
|
||||
|
||||
// Allocate the arrays
|
||||
for (i = 0; i < m; i++) {
|
||||
if (posix_memalign(&buf, 64, TEST_LEN(m))) {
|
||||
printf("alloc error: Fail\n");
|
||||
return -1;
|
||||
}
|
||||
buffs[i] = buf;
|
||||
}
|
||||
|
||||
for (i = 0; i < (m - k); i++) {
|
||||
if (posix_memalign(&buf, 64, TEST_LEN(m))) {
|
||||
printf("alloc error: Fail\n");
|
||||
return -1;
|
||||
}
|
||||
temp_buffs[i] = buf;
|
||||
}
|
||||
|
||||
// Make random data
|
||||
for (i = 0; i < k; i++)
|
||||
for (j = 0; j < TEST_LEN(m); j++)
|
||||
buffs[i][j] = rand();
|
||||
|
||||
gf_gen_rs_matrix(a, m, k);
|
||||
ec_init_tables(k, m - k, &a[k * k], g_tbls);
|
||||
ec_encode_data_sse(TEST_LEN(m), k, m - k, g_tbls, buffs, &buffs[k]);
|
||||
|
||||
// Start encode test
|
||||
perf_start(&start);
|
||||
for (rtest = 0; rtest < TEST_LOOPS(m); rtest++) {
|
||||
// Make parity vects
|
||||
ec_init_tables(k, m - k, &a[k * k], g_tbls);
|
||||
ec_encode_data_sse(TEST_LEN(m), k, m - k, g_tbls, buffs, &buffs[k]);
|
||||
}
|
||||
perf_stop(&stop);
|
||||
printf("erasure_code_sse_encode" TEST_TYPE_STR ": ");
|
||||
perf_print(stop, start, (long long)(TEST_LEN(m)) * (m) * rtest);
|
||||
|
||||
// Start decode test
|
||||
perf_start(&start);
|
||||
for (rtest = 0; rtest < TEST_LOOPS(m); rtest++) {
|
||||
// Construct b by removing error rows
|
||||
for (i = 0, r = 0; i < k; i++, r++) {
|
||||
while (src_in_err[r])
|
||||
r++;
|
||||
recov[i] = buffs[r];
|
||||
for (j = 0; j < k; j++)
|
||||
b[k * i + j] = a[k * r + j];
|
||||
}
|
||||
|
||||
if (gf_invert_matrix(b, d, k) < 0) {
|
||||
printf("BAD MATRIX\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < nerrs; i++)
|
||||
for (j = 0; j < k; j++)
|
||||
c[k * i + j] = d[k * src_err_list[i] + j];
|
||||
|
||||
// Recover data
|
||||
ec_init_tables(k, nerrs, c, g_tbls);
|
||||
ec_encode_data_sse(TEST_LEN(m), k, nerrs, g_tbls, recov, temp_buffs);
|
||||
}
|
||||
perf_stop(&stop);
|
||||
|
||||
for (i = 0; i < nerrs; i++) {
|
||||
if (0 != memcmp(temp_buffs[i], buffs[src_err_list[i]], TEST_LEN(m))) {
|
||||
printf("Fail error recovery (%d, %d, %d) - ", m, k, nerrs);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
printf("erasure_code_sse_decode" TEST_TYPE_STR ": ");
|
||||
perf_print(stop, start, (long long)(TEST_LEN(m)) * (k + nerrs) * rtest);
|
||||
|
||||
printf("done all: Pass\n");
|
||||
return 0;
|
||||
}
|
@ -1,764 +0,0 @@
|
||||
/**********************************************************************
|
||||
Copyright(c) 2011-2015 Intel Corporation All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Intel Corporation nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h> // for memset, memcmp
|
||||
#include "erasure_code.h"
|
||||
#include "types.h"
|
||||
|
||||
#define TEST_LEN 8192
|
||||
#define TEST_SIZE (TEST_LEN/2)
|
||||
|
||||
#ifndef TEST_SOURCES
|
||||
# define TEST_SOURCES 127
|
||||
#endif
|
||||
#ifndef RANDOMS
|
||||
# define RANDOMS 200
|
||||
#endif
|
||||
|
||||
#define MMAX TEST_SOURCES
|
||||
#define KMAX TEST_SOURCES
|
||||
|
||||
#define EFENCE_TEST_MIN_SIZE 16
|
||||
|
||||
#ifdef EC_ALIGNED_ADDR
|
||||
// Define power of 2 range to check ptr, len alignment
|
||||
# define PTR_ALIGN_CHK_B 0
|
||||
# define LEN_ALIGN_CHK_B 0 // 0 for aligned only
|
||||
#else
|
||||
// Define power of 2 range to check ptr, len alignment
|
||||
# define PTR_ALIGN_CHK_B 32
|
||||
# define LEN_ALIGN_CHK_B 32 // 0 for aligned only
|
||||
#endif
|
||||
|
||||
#ifndef TEST_SEED
|
||||
#define TEST_SEED 11
|
||||
#endif
|
||||
|
||||
typedef unsigned char u8;
|
||||
|
||||
void dump(unsigned char *buf, int len)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < len;) {
|
||||
printf(" %2x", 0xff & buf[i++]);
|
||||
if (i % 32 == 0)
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void dump_matrix(unsigned char **s, int k, int m)
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < k; i++) {
|
||||
for (j = 0; j < m; j++) {
|
||||
printf(" %2x", s[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void dump_u8xu8(unsigned char *s, int k, int m)
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < k; i++) {
|
||||
for (j = 0; j < m; j++) {
|
||||
printf(" %2x", 0xff & s[j + (i * m)]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
// Generate Random errors
|
||||
static void gen_err_list(unsigned char *src_err_list,
|
||||
unsigned char *src_in_err, int *pnerrs, int *pnsrcerrs, int k, int m)
|
||||
{
|
||||
int i, err;
|
||||
int nerrs = 0, nsrcerrs = 0;
|
||||
|
||||
for (i = 0, nerrs = 0, nsrcerrs = 0; i < m && nerrs < m - k; i++) {
|
||||
err = 1 & rand();
|
||||
src_in_err[i] = err;
|
||||
if (err) {
|
||||
src_err_list[nerrs++] = i;
|
||||
if (i < k) {
|
||||
nsrcerrs++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (nerrs == 0) { // should have at least one error
|
||||
while ((err = (rand() % KMAX)) >= m) ;
|
||||
src_err_list[nerrs++] = err;
|
||||
src_in_err[err] = 1;
|
||||
if (err < k)
|
||||
nsrcerrs = 1;
|
||||
}
|
||||
*pnerrs = nerrs;
|
||||
*pnsrcerrs = nsrcerrs;
|
||||
return;
|
||||
}
|
||||
|
||||
#define NO_INVERT_MATRIX -2
|
||||
// Generate decode matrix from encode matrix
|
||||
static int gf_gen_decode_matrix(unsigned char *encode_matrix,
|
||||
unsigned char *decode_matrix,
|
||||
unsigned char *invert_matrix,
|
||||
unsigned int *decode_index,
|
||||
unsigned char *src_err_list,
|
||||
unsigned char *src_in_err,
|
||||
int nerrs, int nsrcerrs, int k, int m)
|
||||
{
|
||||
int i, j, p;
|
||||
int r;
|
||||
unsigned char *backup, *b, s;
|
||||
int incr = 0;
|
||||
|
||||
b = malloc(MMAX * KMAX);
|
||||
backup = malloc(MMAX * KMAX);
|
||||
|
||||
if (b == NULL || backup == NULL) {
|
||||
printf("Test failure! Error with malloc\n");
|
||||
free(b);
|
||||
free(backup);
|
||||
return -1;
|
||||
}
|
||||
// Construct matrix b by removing error rows
|
||||
for (i = 0, r = 0; i < k; i++, r++) {
|
||||
while (src_in_err[r])
|
||||
r++;
|
||||
for (j = 0; j < k; j++) {
|
||||
b[k * i + j] = encode_matrix[k * r + j];
|
||||
backup[k * i + j] = encode_matrix[k * r + j];
|
||||
}
|
||||
decode_index[i] = r;
|
||||
}
|
||||
incr = 0;
|
||||
while (gf_invert_matrix(b, invert_matrix, k) < 0) {
|
||||
if (nerrs == (m - k)) {
|
||||
free(b);
|
||||
free(backup);
|
||||
printf("BAD MATRIX\n");
|
||||
return NO_INVERT_MATRIX;
|
||||
}
|
||||
incr++;
|
||||
memcpy(b, backup, MMAX * KMAX);
|
||||
for (i = nsrcerrs; i < nerrs - nsrcerrs; i++) {
|
||||
if (src_err_list[i] == (decode_index[k - 1] + incr)) {
|
||||
// skip the erased parity line
|
||||
incr++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (decode_index[k - 1] + incr >= m) {
|
||||
free(b);
|
||||
free(backup);
|
||||
printf("BAD MATRIX\n");
|
||||
return NO_INVERT_MATRIX;
|
||||
}
|
||||
decode_index[k - 1] += incr;
|
||||
for (j = 0; j < k; j++)
|
||||
b[k * (k - 1) + j] = encode_matrix[k * decode_index[k - 1] + j];
|
||||
|
||||
};
|
||||
|
||||
for (i = 0; i < nsrcerrs; i++) {
|
||||
for (j = 0; j < k; j++) {
|
||||
decode_matrix[k * i + j] = invert_matrix[k * src_err_list[i] + j];
|
||||
}
|
||||
}
|
||||
/* src_err_list from encode_matrix * invert of b for parity decoding */
|
||||
for (p = nsrcerrs; p < nerrs; p++) {
|
||||
for (i = 0; i < k; i++) {
|
||||
s = 0;
|
||||
for (j = 0; j < k; j++)
|
||||
s ^= gf_mul(invert_matrix[j * k + i],
|
||||
encode_matrix[k * src_err_list[p] + j]);
|
||||
|
||||
decode_matrix[k * p + i] = s;
|
||||
}
|
||||
}
|
||||
free(b);
|
||||
free(backup);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int re = 0;
|
||||
int i, j, p, rtest, m, k;
|
||||
int nerrs, nsrcerrs;
|
||||
void *buf;
|
||||
unsigned int decode_index[MMAX];
|
||||
unsigned char *temp_buffs[TEST_SOURCES], *buffs[TEST_SOURCES];
|
||||
unsigned char *encode_matrix, *decode_matrix, *invert_matrix, *g_tbls;
|
||||
unsigned char src_in_err[TEST_SOURCES], src_err_list[TEST_SOURCES];
|
||||
unsigned char *recov[TEST_SOURCES];
|
||||
|
||||
int rows, align, size;
|
||||
unsigned char *efence_buffs[TEST_SOURCES];
|
||||
unsigned int offset;
|
||||
u8 *ubuffs[TEST_SOURCES];
|
||||
u8 *temp_ubuffs[TEST_SOURCES];
|
||||
|
||||
printf("erasure_code_sse_test: %dx%d ", TEST_SOURCES, TEST_LEN);
|
||||
srand(TEST_SEED);
|
||||
|
||||
// Allocate the arrays
|
||||
for (i = 0; i < TEST_SOURCES; i++) {
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
buffs[i] = buf;
|
||||
}
|
||||
|
||||
for (i = 0; i < TEST_SOURCES; i++) {
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
temp_buffs[i] = buf;
|
||||
}
|
||||
|
||||
// Test erasure code by encode and recovery
|
||||
|
||||
encode_matrix = malloc(MMAX * KMAX);
|
||||
decode_matrix = malloc(MMAX * KMAX);
|
||||
invert_matrix = malloc(MMAX * KMAX);
|
||||
g_tbls = malloc(KMAX * TEST_SOURCES * 32);
|
||||
if (encode_matrix == NULL || decode_matrix == NULL
|
||||
|| invert_matrix == NULL || g_tbls == NULL) {
|
||||
printf("Test failure! Error with malloc\n");
|
||||
return -1;
|
||||
}
|
||||
// Pick a first test
|
||||
m = 9;
|
||||
k = 5;
|
||||
if (m > MMAX || k > KMAX)
|
||||
return -1;
|
||||
|
||||
// Make random data
|
||||
for (i = 0; i < k; i++)
|
||||
for (j = 0; j < TEST_LEN; j++)
|
||||
buffs[i][j] = rand();
|
||||
|
||||
// Generate encode matrix encode_matrix
|
||||
// The matrix generated by gf_gen_rs_matrix
|
||||
// is not always invertable.
|
||||
gf_gen_rs_matrix(encode_matrix, m, k);
|
||||
|
||||
// Generate g_tbls from encode matrix encode_matrix
|
||||
ec_init_tables(k, m - k, &encode_matrix[k * k], g_tbls);
|
||||
|
||||
// Perform matrix dot_prod for EC encoding
|
||||
// using g_tbls from encode matrix encode_matrix
|
||||
ec_encode_data_sse(TEST_LEN, k, m - k, g_tbls, buffs, &buffs[k]);
|
||||
|
||||
// Choose random buffers to be in erasure
|
||||
memset(src_in_err, 0, TEST_SOURCES);
|
||||
gen_err_list(src_err_list, src_in_err, &nerrs, &nsrcerrs, k, m);
|
||||
|
||||
// Generate decode matrix
|
||||
re = gf_gen_decode_matrix(encode_matrix, decode_matrix,
|
||||
invert_matrix, decode_index, src_err_list, src_in_err,
|
||||
nerrs, nsrcerrs, k, m);
|
||||
if (re != 0) {
|
||||
printf("Fail to gf_gen_decode_matrix\n");
|
||||
return -1;
|
||||
}
|
||||
// Pack recovery array as list of valid sources
|
||||
// Its order must be the same as the order
|
||||
// to generate matrix b in gf_gen_decode_matrix
|
||||
for (i = 0; i < k; i++) {
|
||||
recov[i] = buffs[decode_index[i]];
|
||||
}
|
||||
|
||||
// Recover data
|
||||
ec_init_tables(k, nerrs, decode_matrix, g_tbls);
|
||||
ec_encode_data_sse(TEST_LEN, k, nerrs, g_tbls, recov, &temp_buffs[k]);
|
||||
for (i = 0; i < nerrs; i++) {
|
||||
|
||||
if (0 != memcmp(temp_buffs[k + i], buffs[src_err_list[i]], TEST_LEN)) {
|
||||
printf("Fail error recovery (%d, %d, %d)\n", m, k, nerrs);
|
||||
printf(" - erase list = ");
|
||||
for (j = 0; j < nerrs; j++)
|
||||
printf(" %d", src_err_list[j]);
|
||||
printf(" - Index = ");
|
||||
for (p = 0; p < k; p++)
|
||||
printf(" %d", decode_index[p]);
|
||||
printf("\nencode_matrix:\n");
|
||||
dump_u8xu8((u8 *) encode_matrix, m, k);
|
||||
printf("inv b:\n");
|
||||
dump_u8xu8((u8 *) invert_matrix, k, k);
|
||||
printf("\ndecode_matrix:\n");
|
||||
dump_u8xu8((u8 *) decode_matrix, m, k);
|
||||
printf("recov %d:", src_err_list[i]);
|
||||
dump(temp_buffs[k + i], 25);
|
||||
printf("orig :");
|
||||
dump(buffs[src_err_list[i]], 25);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Pick a first test
|
||||
m = 9;
|
||||
k = 5;
|
||||
if (m > MMAX || k > KMAX)
|
||||
return -1;
|
||||
|
||||
// Make random data
|
||||
for (i = 0; i < k; i++)
|
||||
for (j = 0; j < TEST_LEN; j++)
|
||||
buffs[i][j] = rand();
|
||||
|
||||
// The matrix generated by gf_gen_cauchy1_matrix
|
||||
// is always invertable.
|
||||
gf_gen_cauchy1_matrix(encode_matrix, m, k);
|
||||
|
||||
// Generate g_tbls from encode matrix encode_matrix
|
||||
ec_init_tables(k, m - k, &encode_matrix[k * k], g_tbls);
|
||||
|
||||
// Perform matrix dot_prod for EC encoding
|
||||
// using g_tbls from encode matrix encode_matrix
|
||||
ec_encode_data_sse(TEST_LEN, k, m - k, g_tbls, buffs, &buffs[k]);
|
||||
|
||||
// Choose random buffers to be in erasure
|
||||
memset(src_in_err, 0, TEST_SOURCES);
|
||||
gen_err_list(src_err_list, src_in_err, &nerrs, &nsrcerrs, k, m);
|
||||
|
||||
// Generate decode matrix
|
||||
re = gf_gen_decode_matrix(encode_matrix, decode_matrix,
|
||||
invert_matrix, decode_index, src_err_list, src_in_err,
|
||||
nerrs, nsrcerrs, k, m);
|
||||
if (re != 0) {
|
||||
printf("Fail to gf_gen_decode_matrix\n");
|
||||
return -1;
|
||||
}
|
||||
// Pack recovery array as list of valid sources
|
||||
// Its order must be the same as the order
|
||||
// to generate matrix b in gf_gen_decode_matrix
|
||||
for (i = 0; i < k; i++) {
|
||||
recov[i] = buffs[decode_index[i]];
|
||||
}
|
||||
|
||||
// Recover data
|
||||
ec_init_tables(k, nerrs, decode_matrix, g_tbls);
|
||||
ec_encode_data_sse(TEST_LEN, k, nerrs, g_tbls, recov, &temp_buffs[k]);
|
||||
for (i = 0; i < nerrs; i++) {
|
||||
|
||||
if (0 != memcmp(temp_buffs[k + i], buffs[src_err_list[i]], TEST_LEN)) {
|
||||
printf("Fail error recovery (%d, %d, %d)\n", m, k, nerrs);
|
||||
printf(" - erase list = ");
|
||||
for (j = 0; j < nerrs; j++)
|
||||
printf(" %d", src_err_list[j]);
|
||||
printf(" - Index = ");
|
||||
for (p = 0; p < k; p++)
|
||||
printf(" %d", decode_index[p]);
|
||||
printf("\nencode_matrix:\n");
|
||||
dump_u8xu8((u8 *) encode_matrix, m, k);
|
||||
printf("inv b:\n");
|
||||
dump_u8xu8((u8 *) invert_matrix, k, k);
|
||||
printf("\ndecode_matrix:\n");
|
||||
dump_u8xu8((u8 *) decode_matrix, m, k);
|
||||
printf("recov %d:", src_err_list[i]);
|
||||
dump(temp_buffs[k + i], 25);
|
||||
printf("orig :");
|
||||
dump(buffs[src_err_list[i]], 25);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Do more random tests
|
||||
for (rtest = 0; rtest < RANDOMS; rtest++) {
|
||||
while ((m = (rand() % MMAX)) < 2) ;
|
||||
while ((k = (rand() % KMAX)) >= m || k < 1) ;
|
||||
|
||||
if (m > MMAX || k > KMAX)
|
||||
continue;
|
||||
|
||||
// Make random data
|
||||
for (i = 0; i < k; i++)
|
||||
for (j = 0; j < TEST_LEN; j++)
|
||||
buffs[i][j] = rand();
|
||||
|
||||
// The matrix generated by gf_gen_cauchy1_matrix
|
||||
// is always invertable.
|
||||
gf_gen_cauchy1_matrix(encode_matrix, m, k);
|
||||
|
||||
// Make parity vects
|
||||
// Generate g_tbls from encode matrix a
|
||||
ec_init_tables(k, m - k, &encode_matrix[k * k], g_tbls);
|
||||
// Perform matrix dot_prod for EC encoding
|
||||
// using g_tbls from encode matrix a
|
||||
ec_encode_data_sse(TEST_LEN, k, m - k, g_tbls, buffs, &buffs[k]);
|
||||
|
||||
// Random errors
|
||||
memset(src_in_err, 0, TEST_SOURCES);
|
||||
gen_err_list(src_err_list, src_in_err, &nerrs, &nsrcerrs, k, m);
|
||||
|
||||
// Generate decode matrix
|
||||
re = gf_gen_decode_matrix(encode_matrix, decode_matrix,
|
||||
invert_matrix, decode_index, src_err_list,
|
||||
src_in_err, nerrs, nsrcerrs, k, m);
|
||||
if (re != 0) {
|
||||
printf("Fail to gf_gen_decode_matrix\n");
|
||||
return -1;
|
||||
}
|
||||
// Pack recovery array as list of valid sources
|
||||
// Its order must be the same as the order
|
||||
// to generate matrix b in gf_gen_decode_matrix
|
||||
for (i = 0; i < k; i++) {
|
||||
recov[i] = buffs[decode_index[i]];
|
||||
}
|
||||
|
||||
// Recover data
|
||||
ec_init_tables(k, nerrs, decode_matrix, g_tbls);
|
||||
ec_encode_data_sse(TEST_LEN, k, nerrs, g_tbls, recov, &temp_buffs[k]);
|
||||
|
||||
for (i = 0; i < nerrs; i++) {
|
||||
|
||||
if (0 != memcmp(temp_buffs[k + i], buffs[src_err_list[i]], TEST_LEN)) {
|
||||
printf("Fail error recovery (%d, %d, %d) - ", m, k, nerrs);
|
||||
printf(" - erase list = ");
|
||||
for (j = 0; j < nerrs; j++)
|
||||
printf(" %d", src_err_list[j]);
|
||||
printf(" - Index = ");
|
||||
for (p = 0; p < k; p++)
|
||||
printf(" %d", decode_index[p]);
|
||||
printf("\nencode_matrix:\n");
|
||||
dump_u8xu8((u8 *) encode_matrix, m, k);
|
||||
printf("inv b:\n");
|
||||
dump_u8xu8((u8 *) invert_matrix, k, k);
|
||||
printf("\ndecode_matrix:\n");
|
||||
dump_u8xu8((u8 *) decode_matrix, m, k);
|
||||
printf("orig data:\n");
|
||||
dump_matrix(buffs, m, 25);
|
||||
printf("orig :");
|
||||
dump(buffs[src_err_list[i]], 25);
|
||||
printf("recov %d:", src_err_list[i]);
|
||||
dump(temp_buffs[k + i], 25);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
putchar('.');
|
||||
}
|
||||
|
||||
// Run tests at end of buffer for Electric Fence
|
||||
k = 16;
|
||||
align = (LEN_ALIGN_CHK_B != 0) ? 1 : 16;
|
||||
if (k > KMAX)
|
||||
return -1;
|
||||
|
||||
for (rows = 1; rows <= 16; rows++) {
|
||||
m = k + rows;
|
||||
if (m > MMAX)
|
||||
return -1;
|
||||
|
||||
// Make random data
|
||||
for (i = 0; i < k; i++)
|
||||
for (j = 0; j < TEST_LEN; j++)
|
||||
buffs[i][j] = rand();
|
||||
|
||||
for (size = EFENCE_TEST_MIN_SIZE; size <= TEST_SIZE; size += align) {
|
||||
for (i = 0; i < m; i++) { // Line up TEST_SIZE from end
|
||||
efence_buffs[i] = buffs[i] + TEST_LEN - size;
|
||||
}
|
||||
|
||||
// The matrix generated by gf_gen_cauchy1_matrix
|
||||
// is always invertable.
|
||||
gf_gen_cauchy1_matrix(encode_matrix, m, k);
|
||||
|
||||
// Make parity vects
|
||||
// Generate g_tbls from encode matrix a
|
||||
ec_init_tables(k, m - k, &encode_matrix[k * k], g_tbls);
|
||||
// Perform matrix dot_prod for EC encoding
|
||||
// using g_tbls from encode matrix a
|
||||
ec_encode_data_sse(size, k, m - k, g_tbls, efence_buffs,
|
||||
&efence_buffs[k]);
|
||||
|
||||
// Random errors
|
||||
memset(src_in_err, 0, TEST_SOURCES);
|
||||
gen_err_list(src_err_list, src_in_err, &nerrs, &nsrcerrs, k, m);
|
||||
|
||||
// Generate decode matrix
|
||||
re = gf_gen_decode_matrix(encode_matrix, decode_matrix,
|
||||
invert_matrix, decode_index, src_err_list,
|
||||
src_in_err, nerrs, nsrcerrs, k, m);
|
||||
if (re != 0) {
|
||||
printf("Fail to gf_gen_decode_matrix\n");
|
||||
return -1;
|
||||
}
|
||||
// Pack recovery array as list of valid sources
|
||||
// Its order must be the same as the order
|
||||
// to generate matrix b in gf_gen_decode_matrix
|
||||
for (i = 0; i < k; i++) {
|
||||
recov[i] = efence_buffs[decode_index[i]];
|
||||
}
|
||||
|
||||
// Recover data
|
||||
ec_init_tables(k, nerrs, decode_matrix, g_tbls);
|
||||
ec_encode_data_sse(size, k, nerrs, g_tbls, recov, &temp_buffs[k]);
|
||||
|
||||
for (i = 0; i < nerrs; i++) {
|
||||
|
||||
if (0 !=
|
||||
memcmp(temp_buffs[k + i], efence_buffs[src_err_list[i]],
|
||||
size)) {
|
||||
printf("Efence: Fail error recovery (%d, %d, %d)\n", m,
|
||||
k, nerrs);
|
||||
|
||||
printf("size = %d\n", size);
|
||||
|
||||
printf("Test erase list = ");
|
||||
for (j = 0; j < nerrs; j++)
|
||||
printf(" %d", src_err_list[j]);
|
||||
printf(" - Index = ");
|
||||
for (p = 0; p < k; p++)
|
||||
printf(" %d", decode_index[p]);
|
||||
printf("\nencode_matrix:\n");
|
||||
dump_u8xu8((u8 *) encode_matrix, m, k);
|
||||
printf("inv b:\n");
|
||||
dump_u8xu8((u8 *) invert_matrix, k, k);
|
||||
printf("\ndecode_matrix:\n");
|
||||
dump_u8xu8((u8 *) decode_matrix, m, k);
|
||||
|
||||
printf("recov %d:", src_err_list[i]);
|
||||
dump(temp_buffs[k + i], align);
|
||||
printf("orig :");
|
||||
dump(efence_buffs[src_err_list[i]], align);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Test rand ptr alignment if available
|
||||
|
||||
for (rtest = 0; rtest < RANDOMS; rtest++) {
|
||||
while ((m = (rand() % MMAX)) < 2) ;
|
||||
while ((k = (rand() % KMAX)) >= m || k < 1) ;
|
||||
|
||||
if (m > MMAX || k > KMAX)
|
||||
continue;
|
||||
|
||||
size = (TEST_LEN - PTR_ALIGN_CHK_B) & ~15;
|
||||
|
||||
offset = (PTR_ALIGN_CHK_B != 0) ? 1 : PTR_ALIGN_CHK_B;
|
||||
// Add random offsets
|
||||
for (i = 0; i < m; i++) {
|
||||
memset(buffs[i], 0, TEST_LEN); // zero pad to check write-over
|
||||
memset(temp_buffs[i], 0, TEST_LEN); // zero pad to check write-over
|
||||
ubuffs[i] = buffs[i] + (rand() & (PTR_ALIGN_CHK_B - offset));
|
||||
temp_ubuffs[i] = temp_buffs[i] + (rand() & (PTR_ALIGN_CHK_B - offset));
|
||||
}
|
||||
|
||||
for (i = 0; i < k; i++)
|
||||
for (j = 0; j < size; j++)
|
||||
ubuffs[i][j] = rand();
|
||||
|
||||
// The matrix generated by gf_gen_cauchy1_matrix
|
||||
// is always invertable.
|
||||
gf_gen_cauchy1_matrix(encode_matrix, m, k);
|
||||
|
||||
// Make parity vects
|
||||
// Generate g_tbls from encode matrix a
|
||||
ec_init_tables(k, m - k, &encode_matrix[k * k], g_tbls);
|
||||
// Perform matrix dot_prod for EC encoding
|
||||
// using g_tbls from encode matrix a
|
||||
ec_encode_data_sse(size, k, m - k, g_tbls, ubuffs, &ubuffs[k]);
|
||||
|
||||
// Random errors
|
||||
memset(src_in_err, 0, TEST_SOURCES);
|
||||
gen_err_list(src_err_list, src_in_err, &nerrs, &nsrcerrs, k, m);
|
||||
|
||||
// Generate decode matrix
|
||||
re = gf_gen_decode_matrix(encode_matrix, decode_matrix,
|
||||
invert_matrix, decode_index, src_err_list,
|
||||
src_in_err, nerrs, nsrcerrs, k, m);
|
||||
if (re != 0) {
|
||||
printf("Fail to gf_gen_decode_matrix\n");
|
||||
return -1;
|
||||
}
|
||||
// Pack recovery array as list of valid sources
|
||||
// Its order must be the same as the order
|
||||
// to generate matrix b in gf_gen_decode_matrix
|
||||
for (i = 0; i < k; i++) {
|
||||
recov[i] = ubuffs[decode_index[i]];
|
||||
}
|
||||
|
||||
// Recover data
|
||||
ec_init_tables(k, nerrs, decode_matrix, g_tbls);
|
||||
ec_encode_data_sse(size, k, nerrs, g_tbls, recov, &temp_ubuffs[k]);
|
||||
|
||||
for (i = 0; i < nerrs; i++) {
|
||||
|
||||
if (0 != memcmp(temp_ubuffs[k + i], ubuffs[src_err_list[i]], size)) {
|
||||
printf("Fail error recovery (%d, %d, %d) - ", m, k, nerrs);
|
||||
printf(" - erase list = ");
|
||||
for (j = 0; j < nerrs; j++)
|
||||
printf(" %d", src_err_list[j]);
|
||||
printf(" - Index = ");
|
||||
for (p = 0; p < k; p++)
|
||||
printf(" %d", decode_index[p]);
|
||||
printf("\nencode_matrix:\n");
|
||||
dump_u8xu8((unsigned char *)encode_matrix, m, k);
|
||||
printf("inv b:\n");
|
||||
dump_u8xu8((unsigned char *)invert_matrix, k, k);
|
||||
printf("\ndecode_matrix:\n");
|
||||
dump_u8xu8((unsigned char *)decode_matrix, m, k);
|
||||
printf("orig data:\n");
|
||||
dump_matrix(ubuffs, m, 25);
|
||||
printf("orig :");
|
||||
dump(ubuffs[src_err_list[i]], 25);
|
||||
printf("recov %d:", src_err_list[i]);
|
||||
dump(temp_ubuffs[k + i], 25);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Confirm that padding around dests is unchanged
|
||||
memset(temp_buffs[0], 0, PTR_ALIGN_CHK_B); // Make reference zero buff
|
||||
|
||||
for (i = 0; i < m; i++) {
|
||||
|
||||
offset = ubuffs[i] - buffs[i];
|
||||
|
||||
if (memcmp(buffs[i], temp_buffs[0], offset)) {
|
||||
printf("Fail rand ualign encode pad start\n");
|
||||
return -1;
|
||||
}
|
||||
if (memcmp
|
||||
(buffs[i] + offset + size, temp_buffs[0],
|
||||
PTR_ALIGN_CHK_B - offset)) {
|
||||
printf("Fail rand ualign encode pad end\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < nerrs; i++) {
|
||||
|
||||
offset = temp_ubuffs[k + i] - temp_buffs[k + i];
|
||||
if (memcmp(temp_buffs[k + i], temp_buffs[0], offset)) {
|
||||
printf("Fail rand ualign decode pad start\n");
|
||||
return -1;
|
||||
}
|
||||
if (memcmp
|
||||
(temp_buffs[k + i] + offset + size, temp_buffs[0],
|
||||
PTR_ALIGN_CHK_B - offset)) {
|
||||
printf("Fail rand ualign decode pad end\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
putchar('.');
|
||||
}
|
||||
|
||||
// Test size alignment
|
||||
|
||||
align = (LEN_ALIGN_CHK_B != 0) ? 13 : 16;
|
||||
|
||||
for (size = TEST_LEN; size > 0; size -= align) {
|
||||
while ((m = (rand() % MMAX)) < 2) ;
|
||||
while ((k = (rand() % KMAX)) >= m || k < 1) ;
|
||||
|
||||
if (m > MMAX || k > KMAX)
|
||||
continue;
|
||||
|
||||
for (i = 0; i < k; i++)
|
||||
for (j = 0; j < size; j++)
|
||||
buffs[i][j] = rand();
|
||||
|
||||
// The matrix generated by gf_gen_cauchy1_matrix
|
||||
// is always invertable.
|
||||
gf_gen_cauchy1_matrix(encode_matrix, m, k);
|
||||
|
||||
// Make parity vects
|
||||
// Generate g_tbls from encode matrix a
|
||||
ec_init_tables(k, m - k, &encode_matrix[k * k], g_tbls);
|
||||
// Perform matrix dot_prod for EC encoding
|
||||
// using g_tbls from encode matrix a
|
||||
ec_encode_data_sse(size, k, m - k, g_tbls, buffs, &buffs[k]);
|
||||
|
||||
// Random errors
|
||||
memset(src_in_err, 0, TEST_SOURCES);
|
||||
gen_err_list(src_err_list, src_in_err, &nerrs, &nsrcerrs, k, m);
|
||||
// Generate decode matrix
|
||||
re = gf_gen_decode_matrix(encode_matrix, decode_matrix,
|
||||
invert_matrix, decode_index, src_err_list,
|
||||
src_in_err, nerrs, nsrcerrs, k, m);
|
||||
if (re != 0) {
|
||||
printf("Fail to gf_gen_decode_matrix\n");
|
||||
return -1;
|
||||
}
|
||||
// Pack recovery array as list of valid sources
|
||||
// Its order must be the same as the order
|
||||
// to generate matrix b in gf_gen_decode_matrix
|
||||
for (i = 0; i < k; i++) {
|
||||
recov[i] = buffs[decode_index[i]];
|
||||
}
|
||||
|
||||
// Recover data
|
||||
ec_init_tables(k, nerrs, decode_matrix, g_tbls);
|
||||
ec_encode_data_sse(size, k, nerrs, g_tbls, recov, &temp_buffs[k]);
|
||||
|
||||
for (i = 0; i < nerrs; i++) {
|
||||
|
||||
if (0 != memcmp(temp_buffs[k + i], buffs[src_err_list[i]], size)) {
|
||||
printf("Fail error recovery (%d, %d, %d) - ", m, k, nerrs);
|
||||
printf(" - erase list = ");
|
||||
for (j = 0; j < nerrs; j++)
|
||||
printf(" %d", src_err_list[j]);
|
||||
printf(" - Index = ");
|
||||
for (p = 0; p < k; p++)
|
||||
printf(" %d", decode_index[p]);
|
||||
printf("\nencode_matrix:\n");
|
||||
dump_u8xu8((unsigned char *)encode_matrix, m, k);
|
||||
printf("inv b:\n");
|
||||
dump_u8xu8((unsigned char *)invert_matrix, k, k);
|
||||
printf("\ndecode_matrix:\n");
|
||||
dump_u8xu8((unsigned char *)decode_matrix, m, k);
|
||||
printf("orig data:\n");
|
||||
dump_matrix(buffs, m, 25);
|
||||
printf("orig :");
|
||||
dump(buffs[src_err_list[i]], 25);
|
||||
printf("recov %d:", src_err_list[i]);
|
||||
dump(temp_buffs[k + i], 25);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("done EC tests: Pass\n");
|
||||
return 0;
|
||||
}
|
@ -1,216 +0,0 @@
|
||||
/**********************************************************************
|
||||
Copyright(c) 2011-2015 Intel Corporation All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Intel Corporation nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h> // for memset, memcmp
|
||||
#include "erasure_code.h"
|
||||
#include "test.h"
|
||||
|
||||
#ifndef FUNCTION_UNDER_TEST
|
||||
# define FUNCTION_UNDER_TEST gf_2vect_dot_prod_sse
|
||||
#endif
|
||||
|
||||
#define str(s) #s
|
||||
#define xstr(s) str(s)
|
||||
|
||||
//#define CACHED_TEST
|
||||
#ifdef CACHED_TEST
|
||||
// Cached test, loop many times over small dataset
|
||||
# define TEST_SOURCES 10
|
||||
# define TEST_LEN 8*1024
|
||||
# define TEST_LOOPS 40000
|
||||
# define TEST_TYPE_STR "_warm"
|
||||
#else
|
||||
# ifndef TEST_CUSTOM
|
||||
// Uncached test. Pull from large mem base.
|
||||
# define TEST_SOURCES 10
|
||||
# define GT_L3_CACHE 32*1024*1024 /* some number > last level cache */
|
||||
# define TEST_LEN ((GT_L3_CACHE / TEST_SOURCES) & ~(64-1))
|
||||
# define TEST_LOOPS 100
|
||||
# define TEST_TYPE_STR "_cold"
|
||||
# else
|
||||
# define TEST_TYPE_STR "_cus"
|
||||
# ifndef TEST_LOOPS
|
||||
# define TEST_LOOPS 1000
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
typedef unsigned char u8;
|
||||
|
||||
void dump(unsigned char *buf, int len)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < len;) {
|
||||
printf(" %2x", 0xff & buf[i++]);
|
||||
if (i % 32 == 0)
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void dump_matrix(unsigned char **s, int k, int m)
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < k; i++) {
|
||||
for (j = 0; j < m; j++) {
|
||||
printf(" %2x", s[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, j;
|
||||
void *buf;
|
||||
u8 g1[TEST_SOURCES], g2[TEST_SOURCES], g_tbls[2 * TEST_SOURCES * 32];
|
||||
u8 *dest1, *dest2, *dest_ref1, *dest_ref2, *dest_ptrs[2];
|
||||
u8 *buffs[TEST_SOURCES];
|
||||
struct perf start, stop;
|
||||
|
||||
printf(xstr(FUNCTION_UNDER_TEST) ": %dx%d\n", TEST_SOURCES, TEST_LEN);
|
||||
|
||||
// Allocate the arrays
|
||||
for (i = 0; i < TEST_SOURCES; i++) {
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
buffs[i] = buf;
|
||||
}
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest1 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest2 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest_ref1 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest_ref2 = buf;
|
||||
|
||||
dest_ptrs[0] = dest1;
|
||||
dest_ptrs[1] = dest2;
|
||||
|
||||
// Performance test
|
||||
for (i = 0; i < TEST_SOURCES; i++)
|
||||
for (j = 0; j < TEST_LEN; j++)
|
||||
buffs[i][j] = rand();
|
||||
|
||||
memset(dest1, 0, TEST_LEN);
|
||||
memset(dest2, 0, TEST_LEN);
|
||||
memset(dest_ref1, 0, TEST_LEN);
|
||||
memset(dest_ref2, 0, TEST_LEN);
|
||||
|
||||
for (i = 0; i < TEST_SOURCES; i++) {
|
||||
g1[i] = rand();
|
||||
g2[i] = rand();
|
||||
}
|
||||
|
||||
for (j = 0; j < TEST_SOURCES; j++) {
|
||||
gf_vect_mul_init(g1[j], &g_tbls[j * 32]);
|
||||
gf_vect_mul_init(g2[j], &g_tbls[(32 * TEST_SOURCES) + (j * 32)]);
|
||||
}
|
||||
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref1);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[32 * TEST_SOURCES], buffs,
|
||||
dest_ref2);
|
||||
|
||||
#ifdef DO_REF_PERF
|
||||
perf_start(&start);
|
||||
for (i = 0; i < TEST_LOOPS / 100; i++) {
|
||||
for (j = 0; j < TEST_SOURCES; j++) {
|
||||
gf_vect_mul_init(g1[j], &g_tbls[j * 32]);
|
||||
gf_vect_mul_init(g2[j], &g_tbls[(32 * TEST_SOURCES) + (j * 32)]);
|
||||
}
|
||||
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref1);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[32 * TEST_SOURCES],
|
||||
buffs, dest_ref2);
|
||||
}
|
||||
perf_stop(&stop);
|
||||
printf("gf_2vect_dot_prod_base" TEST_TYPE_STR ": ");
|
||||
perf_print(stop, start, (long long)TEST_LEN * (TEST_SOURCES + 2) * i);
|
||||
#endif
|
||||
|
||||
FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest_ptrs);
|
||||
|
||||
perf_start(&start);
|
||||
for (i = 0; i < TEST_LOOPS; i++) {
|
||||
for (j = 0; j < TEST_SOURCES; j++) {
|
||||
gf_vect_mul_init(g1[j], &g_tbls[j * 32]);
|
||||
gf_vect_mul_init(g2[j], &g_tbls[(32 * TEST_SOURCES) + (j * 32)]);
|
||||
}
|
||||
|
||||
FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest_ptrs);
|
||||
}
|
||||
perf_stop(&stop);
|
||||
printf(xstr(FUNCTION_UNDER_TEST) TEST_TYPE_STR ": ");
|
||||
perf_print(stop, start, (long long)TEST_LEN * (TEST_SOURCES + 2) * i);
|
||||
|
||||
if (0 != memcmp(dest_ref1, dest1, TEST_LEN)) {
|
||||
printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test1\n");
|
||||
dump_matrix(buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref1, 25);
|
||||
printf("dprod_dut:");
|
||||
dump(dest1, 25);
|
||||
return -1;
|
||||
}
|
||||
if (0 != memcmp(dest_ref2, dest2, TEST_LEN)) {
|
||||
printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test2\n");
|
||||
dump_matrix(buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref2, 25);
|
||||
printf("dprod_dut:");
|
||||
dump(dest2, 25);
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("pass perf check\n");
|
||||
return 0;
|
||||
|
||||
}
|
@ -1,246 +0,0 @@
|
||||
/**********************************************************************
|
||||
Copyright(c) 2011-2015 Intel Corporation All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Intel Corporation nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h> // for memset, memcmp
|
||||
#include "erasure_code.h"
|
||||
#include "test.h"
|
||||
|
||||
#ifndef FUNCTION_UNDER_TEST
|
||||
# define FUNCTION_UNDER_TEST gf_3vect_dot_prod_sse
|
||||
#endif
|
||||
|
||||
#define str(s) #s
|
||||
#define xstr(s) str(s)
|
||||
|
||||
//#define CACHED_TEST
|
||||
#ifdef CACHED_TEST
|
||||
// Cached test, loop many times over small dataset
|
||||
# define TEST_SOURCES 10
|
||||
# define TEST_LEN 8*1024
|
||||
# define TEST_LOOPS 40000
|
||||
# define TEST_TYPE_STR "_warm"
|
||||
#else
|
||||
# ifndef TEST_CUSTOM
|
||||
// Uncached test. Pull from large mem base.
|
||||
# define TEST_SOURCES 10
|
||||
# define GT_L3_CACHE 32*1024*1024 /* some number > last level cache */
|
||||
# define TEST_LEN ((GT_L3_CACHE / TEST_SOURCES) & ~(64-1))
|
||||
# define TEST_LOOPS 100
|
||||
# define TEST_TYPE_STR "_cold"
|
||||
# else
|
||||
# define TEST_TYPE_STR "_cus"
|
||||
# ifndef TEST_LOOPS
|
||||
# define TEST_LOOPS 1000
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
typedef unsigned char u8;
|
||||
|
||||
void dump(unsigned char *buf, int len)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < len;) {
|
||||
printf(" %2x", 0xff & buf[i++]);
|
||||
if (i % 32 == 0)
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void dump_matrix(unsigned char **s, int k, int m)
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < k; i++) {
|
||||
for (j = 0; j < m; j++) {
|
||||
printf(" %2x", s[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, j;
|
||||
void *buf;
|
||||
u8 g1[TEST_SOURCES], g2[TEST_SOURCES], g3[TEST_SOURCES];
|
||||
u8 g_tbls[3 * TEST_SOURCES * 32], *dest_ptrs[3], *buffs[TEST_SOURCES];
|
||||
u8 *dest1, *dest2, *dest3, *dest_ref1, *dest_ref2, *dest_ref3;
|
||||
struct perf start, stop;
|
||||
|
||||
printf(xstr(FUNCTION_UNDER_TEST) ": %dx%d\n", TEST_SOURCES, TEST_LEN);
|
||||
|
||||
// Allocate the arrays
|
||||
for (i = 0; i < TEST_SOURCES; i++) {
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
buffs[i] = buf;
|
||||
}
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest1 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest2 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest3 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest_ref1 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest_ref2 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest_ref3 = buf;
|
||||
|
||||
dest_ptrs[0] = dest1;
|
||||
dest_ptrs[1] = dest2;
|
||||
dest_ptrs[2] = dest3;
|
||||
|
||||
// Performance test
|
||||
for (i = 0; i < TEST_SOURCES; i++)
|
||||
for (j = 0; j < TEST_LEN; j++)
|
||||
buffs[i][j] = rand();
|
||||
|
||||
memset(dest1, 0, TEST_LEN);
|
||||
memset(dest2, 0, TEST_LEN);
|
||||
memset(dest_ref1, 0, TEST_LEN);
|
||||
memset(dest_ref2, 0, TEST_LEN);
|
||||
|
||||
for (i = 0; i < TEST_SOURCES; i++) {
|
||||
g1[i] = rand();
|
||||
g2[i] = rand();
|
||||
g3[i] = rand();
|
||||
}
|
||||
|
||||
for (j = 0; j < TEST_SOURCES; j++) {
|
||||
gf_vect_mul_init(g1[j], &g_tbls[j * 32]);
|
||||
gf_vect_mul_init(g2[j], &g_tbls[(32 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g3[j], &g_tbls[(64 * TEST_SOURCES) + (j * 32)]);
|
||||
}
|
||||
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref1);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[32 * TEST_SOURCES], buffs,
|
||||
dest_ref2);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[64 * TEST_SOURCES], buffs,
|
||||
dest_ref3);
|
||||
|
||||
#ifdef DO_REF_PERF
|
||||
perf_start(&start);
|
||||
for (i = 0; i < TEST_LOOPS / 100; i++) {
|
||||
for (j = 0; j < TEST_SOURCES; j++) {
|
||||
gf_vect_mul_init(g1[j], &g_tbls[j * 32]);
|
||||
gf_vect_mul_init(g2[j], &g_tbls[(32 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g3[j], &g_tbls[(64 * TEST_SOURCES) + (j * 32)]);
|
||||
}
|
||||
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref1);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[32 * TEST_SOURCES],
|
||||
buffs, dest_ref2);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[64 * TEST_SOURCES],
|
||||
buffs, dest_ref3);
|
||||
}
|
||||
perf_stop(&stop);
|
||||
printf("gf_3vect_dot_prod_base" TEST_TYPE_STR ": ");
|
||||
perf_print(stop, start, (long long)TEST_LEN * (TEST_SOURCES + 3) * i);
|
||||
#endif
|
||||
|
||||
FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest_ptrs);
|
||||
|
||||
perf_start(&start);
|
||||
for (i = 0; i < TEST_LOOPS; i++) {
|
||||
for (j = 0; j < TEST_SOURCES; j++) {
|
||||
gf_vect_mul_init(g1[j], &g_tbls[j * 32]);
|
||||
gf_vect_mul_init(g2[j], &g_tbls[(32 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g3[j], &g_tbls[(64 * TEST_SOURCES) + (j * 32)]);
|
||||
}
|
||||
|
||||
FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest_ptrs);
|
||||
}
|
||||
perf_stop(&stop);
|
||||
printf(xstr(FUNCTION_UNDER_TEST) TEST_TYPE_STR ": ");
|
||||
perf_print(stop, start, (long long)TEST_LEN * (TEST_SOURCES + 3) * i);
|
||||
|
||||
if (0 != memcmp(dest_ref1, dest1, TEST_LEN)) {
|
||||
printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test1\n");
|
||||
dump_matrix(buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref1, 25);
|
||||
printf("dprod_dut:");
|
||||
dump(dest1, 25);
|
||||
return -1;
|
||||
}
|
||||
if (0 != memcmp(dest_ref2, dest2, TEST_LEN)) {
|
||||
printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test2\n");
|
||||
dump_matrix(buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref2, 25);
|
||||
printf("dprod_dut:");
|
||||
dump(dest2, 25);
|
||||
return -1;
|
||||
}
|
||||
if (0 != memcmp(dest_ref3, dest3, TEST_LEN)) {
|
||||
printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test3\n");
|
||||
dump_matrix(buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref3, 25);
|
||||
printf("dprod_dut:");
|
||||
dump(dest3, 25);
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("pass perf check\n");
|
||||
return 0;
|
||||
|
||||
}
|
@ -1,281 +0,0 @@
|
||||
/**********************************************************************
|
||||
Copyright(c) 2011-2015 Intel Corporation All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Intel Corporation nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h> // for memset, memcmp
|
||||
#include "erasure_code.h"
|
||||
#include "test.h"
|
||||
|
||||
#ifndef FUNCTION_UNDER_TEST
|
||||
# define FUNCTION_UNDER_TEST gf_4vect_dot_prod_sse
|
||||
#endif
|
||||
|
||||
#define str(s) #s
|
||||
#define xstr(s) str(s)
|
||||
|
||||
//#define CACHED_TEST
|
||||
#ifdef CACHED_TEST
|
||||
// Cached test, loop many times over small dataset
|
||||
# define TEST_SOURCES 10
|
||||
# define TEST_LEN 8*1024
|
||||
# define TEST_LOOPS 40000
|
||||
# define TEST_TYPE_STR "_warm"
|
||||
#else
|
||||
# ifndef TEST_CUSTOM
|
||||
// Uncached test. Pull from large mem base.
|
||||
# define TEST_SOURCES 10
|
||||
# define GT_L3_CACHE 32*1024*1024 /* some number > last level cache */
|
||||
# define TEST_LEN ((GT_L3_CACHE / TEST_SOURCES) & ~(64-1))
|
||||
# define TEST_LOOPS 100
|
||||
# define TEST_TYPE_STR "_cold"
|
||||
# else
|
||||
# define TEST_TYPE_STR "_cus"
|
||||
# ifndef TEST_LOOPS
|
||||
# define TEST_LOOPS 1000
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
typedef unsigned char u8;
|
||||
|
||||
void dump(unsigned char *buf, int len)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < len;) {
|
||||
printf(" %2x", 0xff & buf[i++]);
|
||||
if (i % 32 == 0)
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void dump_matrix(unsigned char **s, int k, int m)
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < k; i++) {
|
||||
for (j = 0; j < m; j++) {
|
||||
printf(" %2x", s[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, j;
|
||||
void *buf;
|
||||
u8 g1[TEST_SOURCES], g2[TEST_SOURCES], g3[TEST_SOURCES];
|
||||
u8 g4[TEST_SOURCES], g_tbls[4 * TEST_SOURCES * 32], *buffs[TEST_SOURCES];
|
||||
u8 *dest1, *dest2, *dest3, *dest4, *dest_ref1, *dest_ref2, *dest_ref3;
|
||||
u8 *dest_ref4, *dest_ptrs[4];
|
||||
struct perf start, stop;
|
||||
|
||||
printf(xstr(FUNCTION_UNDER_TEST) ": %dx%d\n", TEST_SOURCES, TEST_LEN);
|
||||
|
||||
// Allocate the arrays
|
||||
for (i = 0; i < TEST_SOURCES; i++) {
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
buffs[i] = buf;
|
||||
}
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest1 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest2 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest3 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest4 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest_ref1 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest_ref2 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest_ref3 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest_ref4 = buf;
|
||||
|
||||
dest_ptrs[0] = dest1;
|
||||
dest_ptrs[1] = dest2;
|
||||
dest_ptrs[2] = dest3;
|
||||
dest_ptrs[3] = dest4;
|
||||
|
||||
// Performance test
|
||||
for (i = 0; i < TEST_SOURCES; i++)
|
||||
for (j = 0; j < TEST_LEN; j++)
|
||||
buffs[i][j] = rand();
|
||||
|
||||
memset(dest1, 0, TEST_LEN);
|
||||
memset(dest2, 0, TEST_LEN);
|
||||
memset(dest3, 0, TEST_LEN);
|
||||
memset(dest4, 0, TEST_LEN);
|
||||
memset(dest_ref1, 0, TEST_LEN);
|
||||
memset(dest_ref2, 0, TEST_LEN);
|
||||
memset(dest_ref3, 0, TEST_LEN);
|
||||
memset(dest_ref4, 0, TEST_LEN);
|
||||
|
||||
for (i = 0; i < TEST_SOURCES; i++) {
|
||||
g1[i] = rand();
|
||||
g2[i] = rand();
|
||||
g3[i] = rand();
|
||||
g4[i] = rand();
|
||||
}
|
||||
|
||||
for (j = 0; j < TEST_SOURCES; j++) {
|
||||
gf_vect_mul_init(g1[j], &g_tbls[j * 32]);
|
||||
gf_vect_mul_init(g2[j], &g_tbls[(32 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g3[j], &g_tbls[(64 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g4[j], &g_tbls[(96 * TEST_SOURCES) + (j * 32)]);
|
||||
}
|
||||
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref1);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[32 * TEST_SOURCES], buffs,
|
||||
dest_ref2);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[64 * TEST_SOURCES], buffs,
|
||||
dest_ref3);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[96 * TEST_SOURCES], buffs,
|
||||
dest_ref4);
|
||||
|
||||
#ifdef DO_REF_PERF
|
||||
perf_start(&start);
|
||||
for (i = 0; i < TEST_LOOPS / 100; i++) {
|
||||
for (j = 0; j < TEST_SOURCES; j++) {
|
||||
gf_vect_mul_init(g1[j], &g_tbls[j * 32]);
|
||||
gf_vect_mul_init(g2[j], &g_tbls[(32 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g3[j], &g_tbls[(64 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g4[j], &g_tbls[(96 * TEST_SOURCES) + (j * 32)]);
|
||||
}
|
||||
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref1);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[32 * TEST_SOURCES],
|
||||
buffs, dest_ref2);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[64 * TEST_SOURCES],
|
||||
buffs, dest_ref3);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[96 * TEST_SOURCES],
|
||||
buffs, dest_ref4);
|
||||
}
|
||||
perf_stop(&stop);
|
||||
printf("gf_4vect_dot_prod_base" TEST_TYPE_STR ": ");
|
||||
perf_print(stop, start, (long long)TEST_LEN * (TEST_SOURCES + 4) * i);
|
||||
#endif
|
||||
|
||||
FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest_ptrs);
|
||||
|
||||
perf_start(&start);
|
||||
for (i = 0; i < TEST_LOOPS; i++) {
|
||||
for (j = 0; j < TEST_SOURCES; j++) {
|
||||
gf_vect_mul_init(g1[j], &g_tbls[j * 32]);
|
||||
gf_vect_mul_init(g2[j], &g_tbls[(32 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g3[j], &g_tbls[(64 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g4[j], &g_tbls[(96 * TEST_SOURCES) + (j * 32)]);
|
||||
}
|
||||
|
||||
FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest_ptrs);
|
||||
}
|
||||
perf_stop(&stop);
|
||||
printf(xstr(FUNCTION_UNDER_TEST) TEST_TYPE_STR ": ");
|
||||
perf_print(stop, start, (long long)TEST_LEN * (TEST_SOURCES + 4) * i);
|
||||
|
||||
if (0 != memcmp(dest_ref1, dest1, TEST_LEN)) {
|
||||
printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test1\n");
|
||||
dump_matrix(buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref1, 25);
|
||||
printf("dprod_dut:");
|
||||
dump(dest1, 25);
|
||||
return -1;
|
||||
}
|
||||
if (0 != memcmp(dest_ref2, dest2, TEST_LEN)) {
|
||||
printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test2\n");
|
||||
dump_matrix(buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref2, 25);
|
||||
printf("dprod_dut:");
|
||||
dump(dest2, 25);
|
||||
return -1;
|
||||
}
|
||||
if (0 != memcmp(dest_ref3, dest3, TEST_LEN)) {
|
||||
printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test3\n");
|
||||
dump_matrix(buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref3, 25);
|
||||
printf("dprod_dut:");
|
||||
dump(dest3, 25);
|
||||
return -1;
|
||||
}
|
||||
if (0 != memcmp(dest_ref4, dest4, TEST_LEN)) {
|
||||
printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test3\n");
|
||||
dump_matrix(buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref4, 25);
|
||||
printf("dprod_dut:");
|
||||
dump(dest4, 25);
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("pass perf check\n");
|
||||
return 0;
|
||||
|
||||
}
|
@ -1,319 +0,0 @@
|
||||
/**********************************************************************
|
||||
Copyright(c) 2011-2015 Intel Corporation All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Intel Corporation nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h> // for memset, memcmp
|
||||
#include "erasure_code.h"
|
||||
#include "test.h"
|
||||
|
||||
#ifndef FUNCTION_UNDER_TEST
|
||||
# define FUNCTION_UNDER_TEST gf_5vect_dot_prod_sse
|
||||
#endif
|
||||
|
||||
#define str(s) #s
|
||||
#define xstr(s) str(s)
|
||||
|
||||
//#define CACHED_TEST
|
||||
#ifdef CACHED_TEST
|
||||
// Cached test, loop many times over small dataset
|
||||
# define TEST_SOURCES 10
|
||||
# define TEST_LEN 8*1024
|
||||
# define TEST_LOOPS 40000
|
||||
# define TEST_TYPE_STR "_warm"
|
||||
#else
|
||||
# ifndef TEST_CUSTOM
|
||||
// Uncached test. Pull from large mem base.
|
||||
# define TEST_SOURCES 10
|
||||
# define GT_L3_CACHE 32*1024*1024 /* some number > last level cache */
|
||||
# define TEST_LEN ((GT_L3_CACHE / TEST_SOURCES) & ~(64-1))
|
||||
# define TEST_LOOPS 100
|
||||
# define TEST_TYPE_STR "_cold"
|
||||
# else
|
||||
# define TEST_TYPE_STR "_cus"
|
||||
# ifndef TEST_LOOPS
|
||||
# define TEST_LOOPS 1000
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
typedef unsigned char u8;
|
||||
|
||||
void dump(unsigned char *buf, int len)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < len;) {
|
||||
printf(" %2x", 0xff & buf[i++]);
|
||||
if (i % 32 == 0)
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void dump_matrix(unsigned char **s, int k, int m)
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < k; i++) {
|
||||
for (j = 0; j < m; j++) {
|
||||
printf(" %2x", s[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, j;
|
||||
void *buf;
|
||||
u8 g1[TEST_SOURCES], g2[TEST_SOURCES], g3[TEST_SOURCES];
|
||||
u8 g4[TEST_SOURCES], g5[TEST_SOURCES], *g_tbls, *buffs[TEST_SOURCES];
|
||||
u8 *dest1, *dest2, *dest3, *dest4, *dest5, *dest_ref1, *dest_ref2;
|
||||
u8 *dest_ref3, *dest_ref4, *dest_ref5, *dest_ptrs[5];
|
||||
struct perf start, stop;
|
||||
|
||||
printf(xstr(FUNCTION_UNDER_TEST) ": %dx%d\n", TEST_SOURCES, TEST_LEN);
|
||||
|
||||
// Allocate the arrays
|
||||
for (i = 0; i < TEST_SOURCES; i++) {
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
buffs[i] = buf;
|
||||
}
|
||||
|
||||
if (posix_memalign(&buf, 16, 6 * TEST_SOURCES * 32)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
g_tbls = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest1 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest2 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest3 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest4 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest5 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest_ref1 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest_ref2 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest_ref3 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest_ref4 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest_ref5 = buf;
|
||||
|
||||
dest_ptrs[0] = dest1;
|
||||
dest_ptrs[1] = dest2;
|
||||
dest_ptrs[2] = dest3;
|
||||
dest_ptrs[3] = dest4;
|
||||
dest_ptrs[4] = dest5;
|
||||
|
||||
// Performance test
|
||||
for (i = 0; i < TEST_SOURCES; i++)
|
||||
for (j = 0; j < TEST_LEN; j++)
|
||||
buffs[i][j] = rand();
|
||||
|
||||
memset(dest1, 0, TEST_LEN);
|
||||
memset(dest2, 0, TEST_LEN);
|
||||
memset(dest3, 0, TEST_LEN);
|
||||
memset(dest4, 0, TEST_LEN);
|
||||
memset(dest5, 0, TEST_LEN);
|
||||
memset(dest_ref1, 0, TEST_LEN);
|
||||
memset(dest_ref2, 0, TEST_LEN);
|
||||
memset(dest_ref3, 0, TEST_LEN);
|
||||
memset(dest_ref4, 0, TEST_LEN);
|
||||
memset(dest_ref5, 0, TEST_LEN);
|
||||
|
||||
for (i = 0; i < TEST_SOURCES; i++) {
|
||||
g1[i] = rand();
|
||||
g2[i] = rand();
|
||||
g3[i] = rand();
|
||||
g4[i] = rand();
|
||||
g5[i] = rand();
|
||||
}
|
||||
|
||||
for (j = 0; j < TEST_SOURCES; j++) {
|
||||
gf_vect_mul_init(g1[j], &g_tbls[j * 32]);
|
||||
gf_vect_mul_init(g2[j], &g_tbls[(32 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g3[j], &g_tbls[(64 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g4[j], &g_tbls[(96 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g5[j], &g_tbls[(128 * TEST_SOURCES) + (j * 32)]);
|
||||
}
|
||||
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref1);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[32 * TEST_SOURCES], buffs,
|
||||
dest_ref2);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[64 * TEST_SOURCES], buffs,
|
||||
dest_ref3);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[96 * TEST_SOURCES], buffs,
|
||||
dest_ref4);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[128 * TEST_SOURCES], buffs,
|
||||
dest_ref5);
|
||||
|
||||
#ifdef DO_REF_PERF
|
||||
perf_start(&start);
|
||||
for (i = 0; i < TEST_LOOPS / 20; i++) {
|
||||
for (j = 0; j < TEST_SOURCES; j++) {
|
||||
gf_vect_mul_init(g1[j], &g_tbls[j * 32]);
|
||||
gf_vect_mul_init(g2[j], &g_tbls[(32 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g3[j], &g_tbls[(64 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g4[j], &g_tbls[(96 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g5[j], &g_tbls[(128 * TEST_SOURCES) + (j * 32)]);
|
||||
}
|
||||
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref1);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[32 * TEST_SOURCES],
|
||||
buffs, dest_ref2);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[64 * TEST_SOURCES],
|
||||
buffs, dest_ref3);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[96 * TEST_SOURCES],
|
||||
buffs, dest_ref4);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[128 * TEST_SOURCES],
|
||||
buffs, dest_ref5);
|
||||
}
|
||||
perf_stop(&stop);
|
||||
printf("gf_5vect_dot_prod_base" TEST_TYPE_STR ": ");
|
||||
perf_print(stop, start, (long long)TEST_LEN * (TEST_SOURCES + 5) * i);
|
||||
#endif
|
||||
|
||||
FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest_ptrs);
|
||||
|
||||
perf_start(&start);
|
||||
for (i = 0; i < TEST_LOOPS; i++) {
|
||||
for (j = 0; j < TEST_SOURCES; j++) {
|
||||
gf_vect_mul_init(g1[j], &g_tbls[j * 32]);
|
||||
gf_vect_mul_init(g2[j], &g_tbls[(32 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g3[j], &g_tbls[(64 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g4[j], &g_tbls[(96 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g5[j], &g_tbls[(128 * TEST_SOURCES) + (j * 32)]);
|
||||
}
|
||||
|
||||
FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest_ptrs);
|
||||
}
|
||||
perf_stop(&stop);
|
||||
printf(xstr(FUNCTION_UNDER_TEST) TEST_TYPE_STR ": ");
|
||||
perf_print(stop, start, (long long)TEST_LEN * (TEST_SOURCES + 5) * i);
|
||||
|
||||
if (0 != memcmp(dest_ref1, dest1, TEST_LEN)) {
|
||||
printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test1\n");
|
||||
dump_matrix(buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref1, 25);
|
||||
printf("dprod_dut:");
|
||||
dump(dest1, 25);
|
||||
return -1;
|
||||
}
|
||||
if (0 != memcmp(dest_ref2, dest2, TEST_LEN)) {
|
||||
printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test2\n");
|
||||
dump_matrix(buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref2, 25);
|
||||
printf("dprod_dut:");
|
||||
dump(dest2, 25);
|
||||
return -1;
|
||||
}
|
||||
if (0 != memcmp(dest_ref3, dest3, TEST_LEN)) {
|
||||
printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test3\n");
|
||||
dump_matrix(buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref3, 25);
|
||||
printf("dprod_dut:");
|
||||
dump(dest3, 25);
|
||||
return -1;
|
||||
}
|
||||
if (0 != memcmp(dest_ref4, dest4, TEST_LEN)) {
|
||||
printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test4\n");
|
||||
dump_matrix(buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref4, 25);
|
||||
printf("dprod_dut:");
|
||||
dump(dest4, 25);
|
||||
return -1;
|
||||
}
|
||||
if (0 != memcmp(dest_ref5, dest5, TEST_LEN)) {
|
||||
printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test5\n");
|
||||
dump_matrix(buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref5, 25);
|
||||
printf("dprod_dut:");
|
||||
dump(dest5, 25);
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("pass perf check\n");
|
||||
return 0;
|
||||
|
||||
}
|
@ -1,352 +0,0 @@
|
||||
/**********************************************************************
|
||||
Copyright(c) 2011-2015 Intel Corporation All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Intel Corporation nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h> // for memset, memcmp
|
||||
#include "erasure_code.h"
|
||||
#include "test.h"
|
||||
|
||||
#ifndef FUNCTION_UNDER_TEST
|
||||
# define FUNCTION_UNDER_TEST gf_6vect_dot_prod_sse
|
||||
#endif
|
||||
|
||||
#define str(s) #s
|
||||
#define xstr(s) str(s)
|
||||
|
||||
//#define CACHED_TEST
|
||||
#ifdef CACHED_TEST
|
||||
// Cached test, loop many times over small dataset
|
||||
# define TEST_SOURCES 10
|
||||
# define TEST_LEN 8*1024
|
||||
# define TEST_LOOPS 40000
|
||||
# define TEST_TYPE_STR "_warm"
|
||||
#else
|
||||
# ifndef TEST_CUSTOM
|
||||
// Uncached test. Pull from large mem base.
|
||||
# define TEST_SOURCES 10
|
||||
# define GT_L3_CACHE 32*1024*1024 /* some number > last level cache */
|
||||
# define TEST_LEN ((GT_L3_CACHE / TEST_SOURCES) & ~(64-1))
|
||||
# define TEST_LOOPS 100
|
||||
# define TEST_TYPE_STR "_cold"
|
||||
# else
|
||||
# define TEST_TYPE_STR "_cus"
|
||||
# ifndef TEST_LOOPS
|
||||
# define TEST_LOOPS 1000
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
typedef unsigned char u8;
|
||||
|
||||
void dump(unsigned char *buf, int len)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < len;) {
|
||||
printf(" %2x", 0xff & buf[i++]);
|
||||
if (i % 32 == 0)
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void dump_matrix(unsigned char **s, int k, int m)
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < k; i++) {
|
||||
for (j = 0; j < m; j++) {
|
||||
printf(" %2x", s[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, j;
|
||||
void *buf;
|
||||
u8 g1[TEST_SOURCES], g2[TEST_SOURCES], g3[TEST_SOURCES];
|
||||
u8 g4[TEST_SOURCES], g5[TEST_SOURCES], g6[TEST_SOURCES], *g_tbls;
|
||||
u8 *dest1, *dest2, *dest3, *dest4, *dest5, *dest6, *dest_ref1;
|
||||
u8 *dest_ref2, *dest_ref3, *dest_ref4, *dest_ref5, *dest_ref6;
|
||||
u8 *dest_ptrs[6], *buffs[TEST_SOURCES];
|
||||
struct perf start, stop;
|
||||
|
||||
printf(xstr(FUNCTION_UNDER_TEST) ": %dx%d\n", TEST_SOURCES, TEST_LEN);
|
||||
|
||||
// Allocate the arrays
|
||||
for (i = 0; i < TEST_SOURCES; i++) {
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
buffs[i] = buf;
|
||||
}
|
||||
|
||||
if (posix_memalign(&buf, 16, 6 * TEST_SOURCES * 32)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
g_tbls = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest1 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest2 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest3 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest4 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest5 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest6 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest_ref1 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest_ref2 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest_ref3 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest_ref4 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest_ref5 = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest_ref6 = buf;
|
||||
|
||||
dest_ptrs[0] = dest1;
|
||||
dest_ptrs[1] = dest2;
|
||||
dest_ptrs[2] = dest3;
|
||||
dest_ptrs[3] = dest4;
|
||||
dest_ptrs[4] = dest5;
|
||||
dest_ptrs[5] = dest6;
|
||||
|
||||
// Performance test
|
||||
for (i = 0; i < TEST_SOURCES; i++)
|
||||
for (j = 0; j < TEST_LEN; j++)
|
||||
buffs[i][j] = rand();
|
||||
|
||||
memset(dest1, 0, TEST_LEN);
|
||||
memset(dest2, 0, TEST_LEN);
|
||||
memset(dest3, 0, TEST_LEN);
|
||||
memset(dest4, 0, TEST_LEN);
|
||||
memset(dest5, 0, TEST_LEN);
|
||||
memset(dest6, 0, TEST_LEN);
|
||||
memset(dest_ref1, 0, TEST_LEN);
|
||||
memset(dest_ref2, 0, TEST_LEN);
|
||||
memset(dest_ref3, 0, TEST_LEN);
|
||||
memset(dest_ref4, 0, TEST_LEN);
|
||||
memset(dest_ref5, 0, TEST_LEN);
|
||||
memset(dest_ref6, 0, TEST_LEN);
|
||||
|
||||
for (i = 0; i < TEST_SOURCES; i++) {
|
||||
g1[i] = rand();
|
||||
g2[i] = rand();
|
||||
g3[i] = rand();
|
||||
g4[i] = rand();
|
||||
g5[i] = rand();
|
||||
g6[i] = rand();
|
||||
}
|
||||
|
||||
for (j = 0; j < TEST_SOURCES; j++) {
|
||||
gf_vect_mul_init(g1[j], &g_tbls[j * 32]);
|
||||
gf_vect_mul_init(g2[j], &g_tbls[(32 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g3[j], &g_tbls[(64 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g4[j], &g_tbls[(96 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g5[j], &g_tbls[(128 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g6[j], &g_tbls[(160 * TEST_SOURCES) + (j * 32)]);
|
||||
}
|
||||
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref1);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[32 * TEST_SOURCES], buffs,
|
||||
dest_ref2);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[64 * TEST_SOURCES], buffs,
|
||||
dest_ref3);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[96 * TEST_SOURCES], buffs,
|
||||
dest_ref4);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[128 * TEST_SOURCES], buffs,
|
||||
dest_ref5);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[160 * TEST_SOURCES], buffs,
|
||||
dest_ref6);
|
||||
|
||||
#ifdef DO_REF_PERF
|
||||
perf_start(&start);
|
||||
for (i = 0; i < TEST_LOOPS / 20; i++) {
|
||||
for (j = 0; j < TEST_SOURCES; j++) {
|
||||
gf_vect_mul_init(g1[j], &g_tbls[j * 32]);
|
||||
gf_vect_mul_init(g2[j], &g_tbls[(32 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g3[j], &g_tbls[(64 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g4[j], &g_tbls[(96 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g5[j], &g_tbls[(128 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g6[j], &g_tbls[(160 * TEST_SOURCES) + (j * 32)]);
|
||||
}
|
||||
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref1);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[32 * TEST_SOURCES],
|
||||
buffs, dest_ref2);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[64 * TEST_SOURCES],
|
||||
buffs, dest_ref3);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[96 * TEST_SOURCES],
|
||||
buffs, dest_ref4);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[128 * TEST_SOURCES],
|
||||
buffs, dest_ref5);
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[160 * TEST_SOURCES],
|
||||
buffs, dest_ref6);
|
||||
}
|
||||
perf_stop(&stop);
|
||||
printf("gf_6vect_dot_prod_base" TEST_TYPE_STR ": ");
|
||||
perf_print(stop, start, (long long)TEST_LEN * (TEST_SOURCES + 6) * i);
|
||||
#endif
|
||||
|
||||
FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest_ptrs);
|
||||
|
||||
perf_start(&start);
|
||||
for (i = 0; i < TEST_LOOPS; i++) {
|
||||
for (j = 0; j < TEST_SOURCES; j++) {
|
||||
gf_vect_mul_init(g1[j], &g_tbls[j * 32]);
|
||||
gf_vect_mul_init(g2[j], &g_tbls[(32 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g3[j], &g_tbls[(64 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g4[j], &g_tbls[(96 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g5[j], &g_tbls[(128 * TEST_SOURCES) + (j * 32)]);
|
||||
gf_vect_mul_init(g6[j], &g_tbls[(160 * TEST_SOURCES) + (j * 32)]);
|
||||
}
|
||||
|
||||
FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest_ptrs);
|
||||
}
|
||||
perf_stop(&stop);
|
||||
printf(xstr(FUNCTION_UNDER_TEST) TEST_TYPE_STR ": ");
|
||||
perf_print(stop, start, (long long)TEST_LEN * (TEST_SOURCES + 6) * i);
|
||||
|
||||
if (0 != memcmp(dest_ref1, dest1, TEST_LEN)) {
|
||||
printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test1\n");
|
||||
dump_matrix(buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref1, 25);
|
||||
printf("dprod_dut:");
|
||||
dump(dest1, 25);
|
||||
return -1;
|
||||
}
|
||||
if (0 != memcmp(dest_ref2, dest2, TEST_LEN)) {
|
||||
printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test2\n");
|
||||
dump_matrix(buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref2, 25);
|
||||
printf("dprod_dut:");
|
||||
dump(dest2, 25);
|
||||
return -1;
|
||||
}
|
||||
if (0 != memcmp(dest_ref3, dest3, TEST_LEN)) {
|
||||
printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test3\n");
|
||||
dump_matrix(buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref3, 25);
|
||||
printf("dprod_dut:");
|
||||
dump(dest3, 25);
|
||||
return -1;
|
||||
}
|
||||
if (0 != memcmp(dest_ref4, dest4, TEST_LEN)) {
|
||||
printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test4\n");
|
||||
dump_matrix(buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref4, 25);
|
||||
printf("dprod_dut:");
|
||||
dump(dest4, 25);
|
||||
return -1;
|
||||
}
|
||||
if (0 != memcmp(dest_ref5, dest5, TEST_LEN)) {
|
||||
printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test5\n");
|
||||
dump_matrix(buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref5, 25);
|
||||
printf("dprod_dut:");
|
||||
dump(dest5, 25);
|
||||
return -1;
|
||||
}
|
||||
if (0 != memcmp(dest_ref6, dest6, TEST_LEN)) {
|
||||
printf("Fail perf " xstr(FUNCTION_UNDER_TEST) " test6\n");
|
||||
dump_matrix(buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref6, 25);
|
||||
printf("dprod_dut:");
|
||||
dump(dest6, 25);
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("pass perf check\n");
|
||||
return 0;
|
||||
|
||||
}
|
@ -1,184 +0,0 @@
|
||||
/**********************************************************************
|
||||
Copyright(c) 2011-2015 Intel Corporation All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Intel Corporation nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h> // for memset, memcmp
|
||||
#include "erasure_code.h"
|
||||
#include "test.h"
|
||||
|
||||
#ifndef FUNCTION_UNDER_TEST
|
||||
# define FUNCTION_UNDER_TEST gf_vect_dot_prod_avx
|
||||
#endif
|
||||
|
||||
#define str(s) #s
|
||||
#define xstr(s) str(s)
|
||||
|
||||
//#define CACHED_TEST
|
||||
#ifdef CACHED_TEST
|
||||
// Cached test, loop many times over small dataset
|
||||
# define TEST_SOURCES 10
|
||||
# define TEST_LEN 8*1024
|
||||
# define TEST_LOOPS 40000
|
||||
# define TEST_TYPE_STR "_warm"
|
||||
#else
|
||||
# ifndef TEST_CUSTOM
|
||||
// Uncached test. Pull from large mem base.
|
||||
# define TEST_SOURCES 10
|
||||
# define GT_L3_CACHE 32*1024*1024 /* some number > last level cache */
|
||||
# define TEST_LEN ((GT_L3_CACHE / TEST_SOURCES) & ~(64-1))
|
||||
# define TEST_LOOPS 100
|
||||
# define TEST_TYPE_STR "_cold"
|
||||
# else
|
||||
# define TEST_TYPE_STR "_cus"
|
||||
# ifndef TEST_LOOPS
|
||||
# define TEST_LOOPS 1000
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
typedef unsigned char u8;
|
||||
|
||||
void dump(unsigned char *buf, int len)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < len;) {
|
||||
printf(" %2x", 0xff & buf[i++]);
|
||||
if (i % 32 == 0)
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void dump_matrix(unsigned char **s, int k, int m)
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < k; i++) {
|
||||
for (j = 0; j < m; j++) {
|
||||
printf(" %2x", s[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, j;
|
||||
void *buf;
|
||||
u8 g[TEST_SOURCES], g_tbls[TEST_SOURCES * 32], *dest, *dest_ref;
|
||||
u8 *temp_buff, *buffs[TEST_SOURCES];
|
||||
struct perf start, stop;
|
||||
|
||||
printf(xstr(FUNCTION_UNDER_TEST) ": %dx%d\n", TEST_SOURCES, TEST_LEN);
|
||||
|
||||
// Allocate the arrays
|
||||
for (i = 0; i < TEST_SOURCES; i++) {
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
buffs[i] = buf;
|
||||
}
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest_ref = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
temp_buff = buf;
|
||||
|
||||
// Performance test
|
||||
for (i = 0; i < TEST_SOURCES; i++)
|
||||
for (j = 0; j < TEST_LEN; j++)
|
||||
buffs[i][j] = rand();
|
||||
|
||||
memset(dest, 0, TEST_LEN);
|
||||
memset(temp_buff, 0, TEST_LEN);
|
||||
memset(dest_ref, 0, TEST_LEN);
|
||||
memset(g, 0, TEST_SOURCES);
|
||||
|
||||
for (i = 0; i < TEST_SOURCES; i++)
|
||||
g[i] = rand();
|
||||
|
||||
for (j = 0; j < TEST_SOURCES; j++)
|
||||
gf_vect_mul_init(g[j], &g_tbls[j * 32]);
|
||||
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref);
|
||||
|
||||
#ifdef DO_REF_PERF
|
||||
perf_start(&start);
|
||||
for (i = 0; i < TEST_LOOPS; i++) {
|
||||
for (j = 0; j < TEST_SOURCES; j++)
|
||||
gf_vect_mul_init(g[j], &g_tbls[j * 32]);
|
||||
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref);
|
||||
}
|
||||
perf_stop(&stop);
|
||||
printf("gf_vect_dot_prod_base" TEST_TYPE_STR ": ");
|
||||
perf_print(stop, start, (long long)TEST_LEN * (TEST_SOURCES + 1) * i);
|
||||
#endif
|
||||
|
||||
FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest);
|
||||
|
||||
perf_start(&start);
|
||||
for (i = 0; i < TEST_LOOPS; i++) {
|
||||
for (j = 0; j < TEST_SOURCES; j++)
|
||||
gf_vect_mul_init(g[j], &g_tbls[j * 32]);
|
||||
|
||||
FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest);
|
||||
}
|
||||
perf_stop(&stop);
|
||||
printf(xstr(FUNCTION_UNDER_TEST) TEST_TYPE_STR ": ");
|
||||
perf_print(stop, start, (long long)TEST_LEN * (TEST_SOURCES + 1) * i);
|
||||
|
||||
if (0 != memcmp(dest_ref, dest, TEST_LEN)) {
|
||||
printf("Fail zero " xstr(FUNCTION_UNDER_TEST) " test\n");
|
||||
dump_matrix(buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref, 25);
|
||||
printf("dprod:");
|
||||
dump(dest, 25);
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("pass perf check\n");
|
||||
return 0;
|
||||
}
|
@ -1,525 +0,0 @@
|
||||
/**********************************************************************
|
||||
Copyright(c) 2011-2015 Intel Corporation All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Intel Corporation nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h> // for memset, memcmp
|
||||
#include "erasure_code.h"
|
||||
#include "types.h"
|
||||
|
||||
#ifndef FUNCTION_UNDER_TEST
|
||||
# define FUNCTION_UNDER_TEST gf_vect_dot_prod_avx
|
||||
#endif
|
||||
#ifndef TEST_MIN_SIZE
|
||||
# define TEST_MIN_SIZE 16
|
||||
#endif
|
||||
|
||||
#define str(s) #s
|
||||
#define xstr(s) str(s)
|
||||
|
||||
#define TEST_LEN 8192
|
||||
#define TEST_SIZE (TEST_LEN/2)
|
||||
|
||||
#ifndef TEST_SOURCES
|
||||
# define TEST_SOURCES 16
|
||||
#endif
|
||||
#ifndef RANDOMS
|
||||
# define RANDOMS 20
|
||||
#endif
|
||||
|
||||
#define MMAX TEST_SOURCES
|
||||
#define KMAX TEST_SOURCES
|
||||
|
||||
#ifdef EC_ALIGNED_ADDR
|
||||
// Define power of 2 range to check ptr, len alignment
|
||||
# define PTR_ALIGN_CHK_B 0
|
||||
# define LEN_ALIGN_CHK_B 0 // 0 for aligned only
|
||||
#else
|
||||
// Define power of 2 range to check ptr, len alignment
|
||||
# define PTR_ALIGN_CHK_B 32
|
||||
# define LEN_ALIGN_CHK_B 32 // 0 for aligned only
|
||||
#endif
|
||||
|
||||
typedef unsigned char u8;
|
||||
|
||||
void dump(unsigned char *buf, int len)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < len;) {
|
||||
printf(" %2x", 0xff & buf[i++]);
|
||||
if (i % 32 == 0)
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void dump_matrix(unsigned char **s, int k, int m)
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < k; i++) {
|
||||
for (j = 0; j < m; j++) {
|
||||
printf(" %2x", s[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void dump_u8xu8(unsigned char *s, int k, int m)
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < k; i++) {
|
||||
for (j = 0; j < m; j++) {
|
||||
printf(" %2x", 0xff & s[j + (i * m)]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, j, rtest, srcs, m, k, nerrs, r, err;
|
||||
void *buf;
|
||||
u8 g[TEST_SOURCES], g_tbls[TEST_SOURCES * 32], src_in_err[TEST_SOURCES];
|
||||
u8 *dest, *dest_ref, *temp_buff, *buffs[TEST_SOURCES];
|
||||
u8 a[MMAX * KMAX], b[MMAX * KMAX], d[MMAX * KMAX];
|
||||
u8 src_err_list[TEST_SOURCES], *recov[TEST_SOURCES];
|
||||
|
||||
int align, size;
|
||||
unsigned char *efence_buffs[TEST_SOURCES];
|
||||
unsigned int offset;
|
||||
u8 *ubuffs[TEST_SOURCES];
|
||||
u8 *udest_ptr;
|
||||
|
||||
printf(xstr(FUNCTION_UNDER_TEST) ": %dx%d ", TEST_SOURCES, TEST_LEN);
|
||||
|
||||
// Allocate the arrays
|
||||
for (i = 0; i < TEST_SOURCES; i++) {
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
buffs[i] = buf;
|
||||
}
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest_ref = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
temp_buff = buf;
|
||||
|
||||
// Test of all zeros
|
||||
for (i = 0; i < TEST_SOURCES; i++)
|
||||
memset(buffs[i], 0, TEST_LEN);
|
||||
|
||||
memset(dest, 0, TEST_LEN);
|
||||
memset(temp_buff, 0, TEST_LEN);
|
||||
memset(dest_ref, 0, TEST_LEN);
|
||||
memset(g, 0, TEST_SOURCES);
|
||||
|
||||
for (i = 0; i < TEST_SOURCES; i++)
|
||||
gf_vect_mul_init(g[i], &g_tbls[i * 32]);
|
||||
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref);
|
||||
|
||||
FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest);
|
||||
|
||||
if (0 != memcmp(dest_ref, dest, TEST_LEN)) {
|
||||
printf("Fail zero " xstr(FUNCTION_UNDER_TEST) " \n");
|
||||
dump_matrix(buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref, 25);
|
||||
printf("dprod:");
|
||||
dump(dest, 25);
|
||||
return -1;
|
||||
} else
|
||||
putchar('.');
|
||||
|
||||
// Rand data test
|
||||
for (rtest = 0; rtest < RANDOMS; rtest++) {
|
||||
for (i = 0; i < TEST_SOURCES; i++)
|
||||
for (j = 0; j < TEST_LEN; j++)
|
||||
buffs[i][j] = rand();
|
||||
|
||||
for (i = 0; i < TEST_SOURCES; i++)
|
||||
g[i] = rand();
|
||||
|
||||
for (i = 0; i < TEST_SOURCES; i++)
|
||||
gf_vect_mul_init(g[i], &g_tbls[i * 32]);
|
||||
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref);
|
||||
FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest);
|
||||
|
||||
if (0 != memcmp(dest_ref, dest, TEST_LEN)) {
|
||||
printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " 1\n");
|
||||
dump_matrix(buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref, 25);
|
||||
printf("dprod:");
|
||||
dump(dest, 25);
|
||||
return -1;
|
||||
}
|
||||
|
||||
putchar('.');
|
||||
}
|
||||
|
||||
// Rand data test with varied parameters
|
||||
for (rtest = 0; rtest < RANDOMS; rtest++) {
|
||||
for (srcs = TEST_SOURCES; srcs > 0; srcs--) {
|
||||
for (i = 0; i < srcs; i++)
|
||||
for (j = 0; j < TEST_LEN; j++)
|
||||
buffs[i][j] = rand();
|
||||
|
||||
for (i = 0; i < srcs; i++)
|
||||
g[i] = rand();
|
||||
|
||||
for (i = 0; i < srcs; i++)
|
||||
gf_vect_mul_init(g[i], &g_tbls[i * 32]);
|
||||
|
||||
gf_vect_dot_prod_base(TEST_LEN, srcs, &g_tbls[0], buffs, dest_ref);
|
||||
FUNCTION_UNDER_TEST(TEST_LEN, srcs, g_tbls, buffs, dest);
|
||||
|
||||
if (0 != memcmp(dest_ref, dest, TEST_LEN)) {
|
||||
printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test 2\n");
|
||||
dump_matrix(buffs, 5, srcs);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref, 5);
|
||||
printf("dprod:");
|
||||
dump(dest, 5);
|
||||
return -1;
|
||||
}
|
||||
|
||||
putchar('.');
|
||||
}
|
||||
}
|
||||
|
||||
// Test erasure code using gf_vect_dot_prod
|
||||
|
||||
// Pick a first test
|
||||
m = 9;
|
||||
k = 5;
|
||||
if (m > MMAX || k > KMAX)
|
||||
return -1;
|
||||
|
||||
gf_gen_rs_matrix(a, m, k);
|
||||
|
||||
// Make random data
|
||||
for (i = 0; i < k; i++)
|
||||
for (j = 0; j < TEST_LEN; j++)
|
||||
buffs[i][j] = rand();
|
||||
|
||||
// Make parity vects
|
||||
for (i = k; i < m; i++) {
|
||||
for (j = 0; j < k; j++)
|
||||
gf_vect_mul_init(a[k * i + j], &g_tbls[j * 32]);
|
||||
#ifndef USEREF
|
||||
FUNCTION_UNDER_TEST(TEST_LEN, k, g_tbls, buffs, buffs[i]);
|
||||
#else
|
||||
gf_vect_dot_prod_base(TEST_LEN, k, &g_tbls[0], buffs, buffs[i]);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Random buffers in erasure
|
||||
memset(src_in_err, 0, TEST_SOURCES);
|
||||
for (i = 0, nerrs = 0; i < k && nerrs < m - k; i++) {
|
||||
err = 1 & rand();
|
||||
src_in_err[i] = err;
|
||||
if (err)
|
||||
src_err_list[nerrs++] = i;
|
||||
}
|
||||
|
||||
// construct b by removing error rows
|
||||
for (i = 0, r = 0; i < k; i++, r++) {
|
||||
while (src_in_err[r]) {
|
||||
r++;
|
||||
continue;
|
||||
}
|
||||
for (j = 0; j < k; j++)
|
||||
b[k * i + j] = a[k * r + j];
|
||||
}
|
||||
|
||||
if (gf_invert_matrix((u8 *) b, (u8 *) d, k) < 0)
|
||||
printf("BAD MATRIX\n");
|
||||
|
||||
for (i = 0, r = 0; i < k; i++, r++) {
|
||||
while (src_in_err[r]) {
|
||||
r++;
|
||||
continue;
|
||||
}
|
||||
recov[i] = buffs[r];
|
||||
}
|
||||
|
||||
// Recover data
|
||||
for (i = 0; i < nerrs; i++) {
|
||||
for (j = 0; j < k; j++)
|
||||
gf_vect_mul_init(d[k * src_err_list[i] + j], &g_tbls[j * 32]);
|
||||
#ifndef USEREF
|
||||
FUNCTION_UNDER_TEST(TEST_LEN, k, g_tbls, recov, temp_buff);
|
||||
#else
|
||||
gf_vect_dot_prod_base(TEST_LEN, k, &g_tbls[0], recov, temp_buff);
|
||||
#endif
|
||||
|
||||
if (0 != memcmp(temp_buff, buffs[src_err_list[i]], TEST_LEN)) {
|
||||
printf("Fail error recovery (%d, %d, %d)\n", m, k, nerrs);
|
||||
printf("recov %d:", src_err_list[i]);
|
||||
dump(temp_buff, 25);
|
||||
printf("orig :");
|
||||
dump(buffs[src_err_list[i]], 25);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Do more random tests
|
||||
|
||||
for (rtest = 0; rtest < RANDOMS; rtest++) {
|
||||
while ((m = (rand() % MMAX)) < 2) ;
|
||||
while ((k = (rand() % KMAX)) >= m || k < 1) ;
|
||||
|
||||
if (m > MMAX || k > KMAX)
|
||||
continue;
|
||||
|
||||
gf_gen_rs_matrix(a, m, k);
|
||||
|
||||
// Make random data
|
||||
for (i = 0; i < k; i++)
|
||||
for (j = 0; j < TEST_LEN; j++)
|
||||
buffs[i][j] = rand();
|
||||
|
||||
// Make parity vects
|
||||
for (i = k; i < m; i++) {
|
||||
for (j = 0; j < k; j++)
|
||||
gf_vect_mul_init(a[k * i + j], &g_tbls[j * 32]);
|
||||
#ifndef USEREF
|
||||
FUNCTION_UNDER_TEST(TEST_LEN, k, g_tbls, buffs, buffs[i]);
|
||||
#else
|
||||
gf_vect_dot_prod_base(TEST_LEN, k, &g_tbls[0], buffs, buffs[i]);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Random errors
|
||||
memset(src_in_err, 0, TEST_SOURCES);
|
||||
for (i = 0, nerrs = 0; i < k && nerrs < m - k; i++) {
|
||||
err = 1 & rand();
|
||||
src_in_err[i] = err;
|
||||
if (err)
|
||||
src_err_list[nerrs++] = i;
|
||||
}
|
||||
if (nerrs == 0) { // should have at least one error
|
||||
while ((err = (rand() % KMAX)) >= k) ;
|
||||
src_err_list[nerrs++] = err;
|
||||
src_in_err[err] = 1;
|
||||
}
|
||||
// construct b by removing error rows
|
||||
for (i = 0, r = 0; i < k; i++, r++) {
|
||||
while (src_in_err[r]) {
|
||||
r++;
|
||||
continue;
|
||||
}
|
||||
for (j = 0; j < k; j++)
|
||||
b[k * i + j] = a[k * r + j];
|
||||
}
|
||||
|
||||
if (gf_invert_matrix((u8 *) b, (u8 *) d, k) < 0)
|
||||
printf("BAD MATRIX\n");
|
||||
|
||||
for (i = 0, r = 0; i < k; i++, r++) {
|
||||
while (src_in_err[r]) {
|
||||
r++;
|
||||
continue;
|
||||
}
|
||||
recov[i] = buffs[r];
|
||||
}
|
||||
|
||||
// Recover data
|
||||
for (i = 0; i < nerrs; i++) {
|
||||
for (j = 0; j < k; j++)
|
||||
gf_vect_mul_init(d[k * src_err_list[i] + j], &g_tbls[j * 32]);
|
||||
#ifndef USEREF
|
||||
FUNCTION_UNDER_TEST(TEST_LEN, k, g_tbls, recov, temp_buff);
|
||||
#else
|
||||
gf_vect_dot_prod_base(TEST_LEN, k, &g_tbls[0], recov, temp_buff);
|
||||
#endif
|
||||
if (0 != memcmp(temp_buff, buffs[src_err_list[i]], TEST_LEN)) {
|
||||
printf("Fail error recovery (%d, %d, %d) - ", m, k, nerrs);
|
||||
printf(" - erase list = ");
|
||||
for (i = 0; i < nerrs; i++)
|
||||
printf(" %d", src_err_list[i]);
|
||||
printf("\na:\n");
|
||||
dump_u8xu8((u8 *) a, m, k);
|
||||
printf("inv b:\n");
|
||||
dump_u8xu8((u8 *) d, k, k);
|
||||
printf("orig data:\n");
|
||||
dump_matrix(buffs, m, 25);
|
||||
printf("orig :");
|
||||
dump(buffs[src_err_list[i]], 25);
|
||||
printf("recov %d:", src_err_list[i]);
|
||||
dump(temp_buff, 25);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
putchar('.');
|
||||
}
|
||||
|
||||
// Run tests at end of buffer for Electric Fence
|
||||
align = (LEN_ALIGN_CHK_B != 0) ? 1 : 16;
|
||||
for (size = TEST_MIN_SIZE; size <= TEST_SIZE; size += align) {
|
||||
for (i = 0; i < TEST_SOURCES; i++)
|
||||
for (j = 0; j < TEST_LEN; j++)
|
||||
buffs[i][j] = rand();
|
||||
|
||||
for (i = 0; i < TEST_SOURCES; i++) // Line up TEST_SIZE from end
|
||||
efence_buffs[i] = buffs[i] + TEST_LEN - size;
|
||||
|
||||
for (i = 0; i < TEST_SOURCES; i++)
|
||||
g[i] = rand();
|
||||
|
||||
for (i = 0; i < TEST_SOURCES; i++)
|
||||
gf_vect_mul_init(g[i], &g_tbls[i * 32]);
|
||||
|
||||
gf_vect_dot_prod_base(size, TEST_SOURCES, &g_tbls[0], efence_buffs, dest_ref);
|
||||
FUNCTION_UNDER_TEST(size, TEST_SOURCES, g_tbls, efence_buffs, dest);
|
||||
|
||||
if (0 != memcmp(dest_ref, dest, size)) {
|
||||
printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test 3\n");
|
||||
dump_matrix(efence_buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref, align);
|
||||
printf("dprod:");
|
||||
dump(dest, align);
|
||||
return -1;
|
||||
}
|
||||
|
||||
putchar('.');
|
||||
}
|
||||
|
||||
// Test rand ptr alignment if available
|
||||
|
||||
for (rtest = 0; rtest < RANDOMS; rtest++) {
|
||||
size = (TEST_LEN - PTR_ALIGN_CHK_B) & ~(TEST_MIN_SIZE - 1);
|
||||
srcs = rand() % TEST_SOURCES;
|
||||
if (srcs == 0)
|
||||
continue;
|
||||
|
||||
offset = (PTR_ALIGN_CHK_B != 0) ? 1 : PTR_ALIGN_CHK_B;
|
||||
// Add random offsets
|
||||
for (i = 0; i < srcs; i++)
|
||||
ubuffs[i] = buffs[i] + (rand() & (PTR_ALIGN_CHK_B - offset));
|
||||
|
||||
udest_ptr = dest + (rand() & (PTR_ALIGN_CHK_B - offset));
|
||||
|
||||
memset(dest, 0, TEST_LEN); // zero pad to check write-over
|
||||
|
||||
for (i = 0; i < srcs; i++)
|
||||
for (j = 0; j < size; j++)
|
||||
ubuffs[i][j] = rand();
|
||||
|
||||
for (i = 0; i < srcs; i++)
|
||||
g[i] = rand();
|
||||
|
||||
for (i = 0; i < srcs; i++)
|
||||
gf_vect_mul_init(g[i], &g_tbls[i * 32]);
|
||||
|
||||
gf_vect_dot_prod_base(size, srcs, &g_tbls[0], ubuffs, dest_ref);
|
||||
|
||||
FUNCTION_UNDER_TEST(size, srcs, g_tbls, ubuffs, udest_ptr);
|
||||
|
||||
if (memcmp(dest_ref, udest_ptr, size)) {
|
||||
printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " ualign srcs=%d\n",
|
||||
srcs);
|
||||
dump_matrix(ubuffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref, 25);
|
||||
printf("dprod:");
|
||||
dump(udest_ptr, 25);
|
||||
return -1;
|
||||
}
|
||||
// Confirm that padding around dests is unchanged
|
||||
memset(dest_ref, 0, PTR_ALIGN_CHK_B); // Make reference zero buff
|
||||
offset = udest_ptr - dest;
|
||||
|
||||
if (memcmp(dest, dest_ref, offset)) {
|
||||
printf("Fail rand ualign pad start\n");
|
||||
return -1;
|
||||
}
|
||||
if (memcmp(dest + offset + size, dest_ref, PTR_ALIGN_CHK_B - offset)) {
|
||||
printf("Fail rand ualign pad end\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
putchar('.');
|
||||
}
|
||||
|
||||
// Test all size alignment
|
||||
align = (LEN_ALIGN_CHK_B != 0) ? 1 : 16;
|
||||
|
||||
for (size = TEST_LEN; size >= TEST_MIN_SIZE; size -= align) {
|
||||
srcs = TEST_SOURCES;
|
||||
|
||||
for (i = 0; i < srcs; i++)
|
||||
for (j = 0; j < size; j++)
|
||||
buffs[i][j] = rand();
|
||||
|
||||
for (i = 0; i < srcs; i++)
|
||||
g[i] = rand();
|
||||
|
||||
for (i = 0; i < srcs; i++)
|
||||
gf_vect_mul_init(g[i], &g_tbls[i * 32]);
|
||||
|
||||
gf_vect_dot_prod_base(size, srcs, &g_tbls[0], buffs, dest_ref);
|
||||
|
||||
FUNCTION_UNDER_TEST(size, srcs, g_tbls, buffs, dest);
|
||||
|
||||
if (memcmp(dest_ref, dest, size)) {
|
||||
printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " ualign len=%d\n",
|
||||
size);
|
||||
dump_matrix(buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref, 25);
|
||||
printf("dprod:");
|
||||
dump(dest, 25);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
printf("done all: Pass\n");
|
||||
return 0;
|
||||
}
|
@ -1,184 +0,0 @@
|
||||
/**********************************************************************
|
||||
Copyright(c) 2011-2015 Intel Corporation All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Intel Corporation nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h> // for memset, memcmp
|
||||
#include "erasure_code.h"
|
||||
#include "test.h"
|
||||
|
||||
#ifndef FUNCTION_UNDER_TEST
|
||||
# define FUNCTION_UNDER_TEST gf_vect_dot_prod_sse
|
||||
#endif
|
||||
|
||||
#define str(s) #s
|
||||
#define xstr(s) str(s)
|
||||
|
||||
//#define CACHED_TEST
|
||||
#ifdef CACHED_TEST
|
||||
// Cached test, loop many times over small dataset
|
||||
# define TEST_SOURCES 10
|
||||
# define TEST_LEN 8*1024
|
||||
# define TEST_LOOPS 40000
|
||||
# define TEST_TYPE_STR "_warm"
|
||||
#else
|
||||
# ifndef TEST_CUSTOM
|
||||
// Uncached test. Pull from large mem base.
|
||||
# define TEST_SOURCES 10
|
||||
# define GT_L3_CACHE 32*1024*1024 /* some number > last level cache */
|
||||
# define TEST_LEN ((GT_L3_CACHE / TEST_SOURCES) & ~(64-1))
|
||||
# define TEST_LOOPS 100
|
||||
# define TEST_TYPE_STR "_cold"
|
||||
# else
|
||||
# define TEST_TYPE_STR "_cus"
|
||||
# ifndef TEST_LOOPS
|
||||
# define TEST_LOOPS 1000
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
typedef unsigned char u8;
|
||||
|
||||
void dump(unsigned char *buf, int len)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < len;) {
|
||||
printf(" %2x", 0xff & buf[i++]);
|
||||
if (i % 32 == 0)
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void dump_matrix(unsigned char **s, int k, int m)
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < k; i++) {
|
||||
for (j = 0; j < m; j++) {
|
||||
printf(" %2x", s[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, j;
|
||||
void *buf;
|
||||
u8 g[TEST_SOURCES], g_tbls[TEST_SOURCES * 32], *dest, *dest_ref;
|
||||
u8 *temp_buff, *buffs[TEST_SOURCES];
|
||||
struct perf start, stop;
|
||||
|
||||
printf(xstr(FUNCTION_UNDER_TEST) ": %dx%d\n", TEST_SOURCES, TEST_LEN);
|
||||
|
||||
// Allocate the arrays
|
||||
for (i = 0; i < TEST_SOURCES; i++) {
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
buffs[i] = buf;
|
||||
}
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest_ref = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
temp_buff = buf;
|
||||
|
||||
// Performance test
|
||||
for (i = 0; i < TEST_SOURCES; i++)
|
||||
for (j = 0; j < TEST_LEN; j++)
|
||||
buffs[i][j] = rand();
|
||||
|
||||
memset(dest, 0, TEST_LEN);
|
||||
memset(temp_buff, 0, TEST_LEN);
|
||||
memset(dest_ref, 0, TEST_LEN);
|
||||
memset(g, 0, TEST_SOURCES);
|
||||
|
||||
for (i = 0; i < TEST_SOURCES; i++)
|
||||
g[i] = rand();
|
||||
|
||||
for (j = 0; j < TEST_SOURCES; j++)
|
||||
gf_vect_mul_init(g[j], &g_tbls[j * 32]);
|
||||
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref);
|
||||
|
||||
#ifdef DO_REF_PERF
|
||||
perf_start(&start);
|
||||
for (i = 0; i < TEST_LOOPS; i++) {
|
||||
for (j = 0; j < TEST_SOURCES; j++)
|
||||
gf_vect_mul_init(g[j], &g_tbls[j * 32]);
|
||||
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref);
|
||||
}
|
||||
perf_stop(&stop);
|
||||
printf("gf_vect_dot_prod_base" TEST_TYPE_STR ": ");
|
||||
perf_print(stop, start, (long long)TEST_LEN * (TEST_SOURCES + 1) * i);
|
||||
#endif
|
||||
|
||||
FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest);
|
||||
|
||||
perf_start(&start);
|
||||
for (i = 0; i < TEST_LOOPS; i++) {
|
||||
for (j = 0; j < TEST_SOURCES; j++)
|
||||
gf_vect_mul_init(g[j], &g_tbls[j * 32]);
|
||||
|
||||
FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest);
|
||||
}
|
||||
perf_stop(&stop);
|
||||
printf(xstr(FUNCTION_UNDER_TEST) TEST_TYPE_STR ": ");
|
||||
perf_print(stop, start, (long long)TEST_LEN * (TEST_SOURCES + 1) * i);
|
||||
|
||||
if (0 != memcmp(dest_ref, dest, TEST_LEN)) {
|
||||
printf("Fail zero " xstr(FUNCTION_UNDER_TEST) " test\n");
|
||||
dump_matrix(buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref, 25);
|
||||
printf("dprod:");
|
||||
dump(dest, 25);
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("pass perf check\n");
|
||||
return 0;
|
||||
}
|
@ -1,528 +0,0 @@
|
||||
/**********************************************************************
|
||||
Copyright(c) 2011-2015 Intel Corporation All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Intel Corporation nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h> // for memset, memcmp
|
||||
#include "erasure_code.h"
|
||||
#include "types.h"
|
||||
|
||||
#ifndef FUNCTION_UNDER_TEST
|
||||
# define FUNCTION_UNDER_TEST gf_vect_dot_prod_sse
|
||||
#endif
|
||||
#ifndef TEST_MIN_SIZE
|
||||
# define TEST_MIN_SIZE 16
|
||||
#endif
|
||||
|
||||
#define str(s) #s
|
||||
#define xstr(s) str(s)
|
||||
|
||||
#define TEST_LEN 8192
|
||||
#define TEST_SIZE (TEST_LEN/2)
|
||||
|
||||
#ifndef TEST_SOURCES
|
||||
# define TEST_SOURCES 16
|
||||
#endif
|
||||
#ifndef RANDOMS
|
||||
# define RANDOMS 20
|
||||
#endif
|
||||
|
||||
#define MMAX TEST_SOURCES
|
||||
#define KMAX TEST_SOURCES
|
||||
|
||||
#ifdef EC_ALIGNED_ADDR
|
||||
// Define power of 2 range to check ptr, len alignment
|
||||
# define PTR_ALIGN_CHK_B 0
|
||||
# define LEN_ALIGN_CHK_B 0 // 0 for aligned only
|
||||
#else
|
||||
// Define power of 2 range to check ptr, len alignment
|
||||
# define PTR_ALIGN_CHK_B 32
|
||||
# define LEN_ALIGN_CHK_B 32 // 0 for aligned only
|
||||
#endif
|
||||
|
||||
extern void FUNCTION_UNDER_TEST(int len, int vlen, unsigned char *gftbls,
|
||||
unsigned char **src, unsigned char *dest);
|
||||
|
||||
typedef unsigned char u8;
|
||||
|
||||
void dump(unsigned char *buf, int len)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < len;) {
|
||||
printf(" %2x", 0xff & buf[i++]);
|
||||
if (i % 32 == 0)
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void dump_matrix(unsigned char **s, int k, int m)
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < k; i++) {
|
||||
for (j = 0; j < m; j++) {
|
||||
printf(" %2x", s[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void dump_u8xu8(unsigned char *s, int k, int m)
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < k; i++) {
|
||||
for (j = 0; j < m; j++) {
|
||||
printf(" %2x", 0xff & s[j + (i * m)]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, j, rtest, srcs, m, k, nerrs, r, err;
|
||||
void *buf;
|
||||
u8 g[TEST_SOURCES], g_tbls[TEST_SOURCES * 32], src_in_err[TEST_SOURCES];
|
||||
u8 *dest, *dest_ref, *temp_buff, *buffs[TEST_SOURCES];
|
||||
u8 a[MMAX * KMAX], b[MMAX * KMAX], d[MMAX * KMAX];
|
||||
u8 src_err_list[TEST_SOURCES], *recov[TEST_SOURCES];
|
||||
|
||||
int align, size;
|
||||
unsigned char *efence_buffs[TEST_SOURCES];
|
||||
unsigned int offset;
|
||||
u8 *ubuffs[TEST_SOURCES];
|
||||
u8 *udest_ptr;
|
||||
|
||||
printf(xstr(FUNCTION_UNDER_TEST) ": %dx%d ", TEST_SOURCES, TEST_LEN);
|
||||
|
||||
// Allocate the arrays
|
||||
for (i = 0; i < TEST_SOURCES; i++) {
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
buffs[i] = buf;
|
||||
}
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
dest_ref = buf;
|
||||
|
||||
if (posix_memalign(&buf, 64, TEST_LEN)) {
|
||||
printf("alloc error: Fail");
|
||||
return -1;
|
||||
}
|
||||
temp_buff = buf;
|
||||
|
||||
// Test of all zeros
|
||||
for (i = 0; i < TEST_SOURCES; i++)
|
||||
memset(buffs[i], 0, TEST_LEN);
|
||||
|
||||
memset(dest, 0, TEST_LEN);
|
||||
memset(temp_buff, 0, TEST_LEN);
|
||||
memset(dest_ref, 0, TEST_LEN);
|
||||
memset(g, 0, TEST_SOURCES);
|
||||
|
||||
for (i = 0; i < TEST_SOURCES; i++)
|
||||
gf_vect_mul_init(g[i], &g_tbls[i * 32]);
|
||||
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref);
|
||||
|
||||
FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest);
|
||||
|
||||
if (0 != memcmp(dest_ref, dest, TEST_LEN)) {
|
||||
printf("Fail zero " xstr(FUNCTION_UNDER_TEST) " \n");
|
||||
dump_matrix(buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref, 25);
|
||||
printf("dprod:");
|
||||
dump(dest, 25);
|
||||
return -1;
|
||||
} else
|
||||
putchar('.');
|
||||
|
||||
// Rand data test
|
||||
for (rtest = 0; rtest < RANDOMS; rtest++) {
|
||||
for (i = 0; i < TEST_SOURCES; i++)
|
||||
for (j = 0; j < TEST_LEN; j++)
|
||||
buffs[i][j] = rand();
|
||||
|
||||
for (i = 0; i < TEST_SOURCES; i++)
|
||||
g[i] = rand();
|
||||
|
||||
for (i = 0; i < TEST_SOURCES; i++)
|
||||
gf_vect_mul_init(g[i], &g_tbls[i * 32]);
|
||||
|
||||
gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref);
|
||||
FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest);
|
||||
|
||||
if (0 != memcmp(dest_ref, dest, TEST_LEN)) {
|
||||
printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " 1\n");
|
||||
dump_matrix(buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref, 25);
|
||||
printf("dprod:");
|
||||
dump(dest, 25);
|
||||
return -1;
|
||||
}
|
||||
|
||||
putchar('.');
|
||||
}
|
||||
|
||||
// Rand data test with varied parameters
|
||||
for (rtest = 0; rtest < RANDOMS; rtest++) {
|
||||
for (srcs = TEST_SOURCES; srcs > 0; srcs--) {
|
||||
for (i = 0; i < srcs; i++)
|
||||
for (j = 0; j < TEST_LEN; j++)
|
||||
buffs[i][j] = rand();
|
||||
|
||||
for (i = 0; i < srcs; i++)
|
||||
g[i] = rand();
|
||||
|
||||
for (i = 0; i < srcs; i++)
|
||||
gf_vect_mul_init(g[i], &g_tbls[i * 32]);
|
||||
|
||||
gf_vect_dot_prod_base(TEST_LEN, srcs, &g_tbls[0], buffs, dest_ref);
|
||||
FUNCTION_UNDER_TEST(TEST_LEN, srcs, g_tbls, buffs, dest);
|
||||
|
||||
if (0 != memcmp(dest_ref, dest, TEST_LEN)) {
|
||||
printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test 2\n");
|
||||
dump_matrix(buffs, 5, srcs);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref, 5);
|
||||
printf("dprod:");
|
||||
dump(dest, 5);
|
||||
return -1;
|
||||
}
|
||||
|
||||
putchar('.');
|
||||
}
|
||||
}
|
||||
|
||||
// Test erasure code using gf_vect_dot_prod
|
||||
|
||||
// Pick a first test
|
||||
m = 9;
|
||||
k = 5;
|
||||
if (m > MMAX || k > KMAX)
|
||||
return -1;
|
||||
|
||||
gf_gen_rs_matrix(a, m, k);
|
||||
|
||||
// Make random data
|
||||
for (i = 0; i < k; i++)
|
||||
for (j = 0; j < TEST_LEN; j++)
|
||||
buffs[i][j] = rand();
|
||||
|
||||
// Make parity vects
|
||||
for (i = k; i < m; i++) {
|
||||
for (j = 0; j < k; j++)
|
||||
gf_vect_mul_init(a[k * i + j], &g_tbls[j * 32]);
|
||||
#ifndef USEREF
|
||||
FUNCTION_UNDER_TEST(TEST_LEN, k, g_tbls, buffs, buffs[i]);
|
||||
#else
|
||||
gf_vect_dot_prod_base(TEST_LEN, k, &g_tbls[0], buffs, buffs[i]);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Random buffers in erasure
|
||||
memset(src_in_err, 0, TEST_SOURCES);
|
||||
for (i = 0, nerrs = 0; i < k && nerrs < m - k; i++) {
|
||||
err = 1 & rand();
|
||||
src_in_err[i] = err;
|
||||
if (err)
|
||||
src_err_list[nerrs++] = i;
|
||||
}
|
||||
|
||||
// construct b by removing error rows
|
||||
for (i = 0, r = 0; i < k; i++, r++) {
|
||||
while (src_in_err[r]) {
|
||||
r++;
|
||||
continue;
|
||||
}
|
||||
for (j = 0; j < k; j++)
|
||||
b[k * i + j] = a[k * r + j];
|
||||
}
|
||||
|
||||
if (gf_invert_matrix((u8 *) b, (u8 *) d, k) < 0)
|
||||
printf("BAD MATRIX\n");
|
||||
|
||||
for (i = 0, r = 0; i < k; i++, r++) {
|
||||
while (src_in_err[r]) {
|
||||
r++;
|
||||
continue;
|
||||
}
|
||||
recov[i] = buffs[r];
|
||||
}
|
||||
|
||||
// Recover data
|
||||
for (i = 0; i < nerrs; i++) {
|
||||
for (j = 0; j < k; j++)
|
||||
gf_vect_mul_init(d[k * src_err_list[i] + j], &g_tbls[j * 32]);
|
||||
#ifndef USEREF
|
||||
FUNCTION_UNDER_TEST(TEST_LEN, k, g_tbls, recov, temp_buff);
|
||||
#else
|
||||
gf_vect_dot_prod_base(TEST_LEN, k, &g_tbls[0], recov, temp_buff);
|
||||
#endif
|
||||
|
||||
if (0 != memcmp(temp_buff, buffs[src_err_list[i]], TEST_LEN)) {
|
||||
printf("Fail error recovery (%d, %d, %d)\n", m, k, nerrs);
|
||||
printf("recov %d:", src_err_list[i]);
|
||||
dump(temp_buff, 25);
|
||||
printf("orig :");
|
||||
dump(buffs[src_err_list[i]], 25);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Do more random tests
|
||||
|
||||
for (rtest = 0; rtest < RANDOMS; rtest++) {
|
||||
while ((m = (rand() % MMAX)) < 2) ;
|
||||
while ((k = (rand() % KMAX)) >= m || k < 1) ;
|
||||
|
||||
if (m > MMAX || k > KMAX)
|
||||
continue;
|
||||
|
||||
gf_gen_rs_matrix(a, m, k);
|
||||
|
||||
// Make random data
|
||||
for (i = 0; i < k; i++)
|
||||
for (j = 0; j < TEST_LEN; j++)
|
||||
buffs[i][j] = rand();
|
||||
|
||||
// Make parity vects
|
||||
for (i = k; i < m; i++) {
|
||||
for (j = 0; j < k; j++)
|
||||
gf_vect_mul_init(a[k * i + j], &g_tbls[j * 32]);
|
||||
#ifndef USEREF
|
||||
FUNCTION_UNDER_TEST(TEST_LEN, k, g_tbls, buffs, buffs[i]);
|
||||
#else
|
||||
gf_vect_dot_prod_base(TEST_LEN, k, &g_tbls[0], buffs, buffs[i]);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Random errors
|
||||
memset(src_in_err, 0, TEST_SOURCES);
|
||||
for (i = 0, nerrs = 0; i < k && nerrs < m - k; i++) {
|
||||
err = 1 & rand();
|
||||
src_in_err[i] = err;
|
||||
if (err)
|
||||
src_err_list[nerrs++] = i;
|
||||
}
|
||||
if (nerrs == 0) { // should have at least one error
|
||||
while ((err = (rand() % KMAX)) >= k) ;
|
||||
src_err_list[nerrs++] = err;
|
||||
src_in_err[err] = 1;
|
||||
}
|
||||
// construct b by removing error rows
|
||||
for (i = 0, r = 0; i < k; i++, r++) {
|
||||
while (src_in_err[r]) {
|
||||
r++;
|
||||
continue;
|
||||
}
|
||||
for (j = 0; j < k; j++)
|
||||
b[k * i + j] = a[k * r + j];
|
||||
}
|
||||
|
||||
if (gf_invert_matrix((u8 *) b, (u8 *) d, k) < 0)
|
||||
printf("BAD MATRIX\n");
|
||||
|
||||
for (i = 0, r = 0; i < k; i++, r++) {
|
||||
while (src_in_err[r]) {
|
||||
r++;
|
||||
continue;
|
||||
}
|
||||
recov[i] = buffs[r];
|
||||
}
|
||||
|
||||
// Recover data
|
||||
for (i = 0; i < nerrs; i++) {
|
||||
for (j = 0; j < k; j++)
|
||||
gf_vect_mul_init(d[k * src_err_list[i] + j], &g_tbls[j * 32]);
|
||||
#ifndef USEREF
|
||||
FUNCTION_UNDER_TEST(TEST_LEN, k, g_tbls, recov, temp_buff);
|
||||
#else
|
||||
gf_vect_dot_prod_base(TEST_LEN, k, &g_tbls[0], recov, temp_buff);
|
||||
#endif
|
||||
if (0 != memcmp(temp_buff, buffs[src_err_list[i]], TEST_LEN)) {
|
||||
printf("Fail error recovery (%d, %d, %d) - ", m, k, nerrs);
|
||||
printf(" - erase list = ");
|
||||
for (i = 0; i < nerrs; i++)
|
||||
printf(" %d", src_err_list[i]);
|
||||
printf("\na:\n");
|
||||
dump_u8xu8((u8 *) a, m, k);
|
||||
printf("inv b:\n");
|
||||
dump_u8xu8((u8 *) d, k, k);
|
||||
printf("orig data:\n");
|
||||
dump_matrix(buffs, m, 25);
|
||||
printf("orig :");
|
||||
dump(buffs[src_err_list[i]], 25);
|
||||
printf("recov %d:", src_err_list[i]);
|
||||
dump(temp_buff, 25);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
putchar('.');
|
||||
}
|
||||
|
||||
// Run tests at end of buffer for Electric Fence
|
||||
align = (LEN_ALIGN_CHK_B != 0) ? 1 : 16;
|
||||
for (size = TEST_MIN_SIZE; size <= TEST_SIZE; size += align) {
|
||||
for (i = 0; i < TEST_SOURCES; i++)
|
||||
for (j = 0; j < TEST_LEN; j++)
|
||||
buffs[i][j] = rand();
|
||||
|
||||
for (i = 0; i < TEST_SOURCES; i++) // Line up TEST_SIZE from end
|
||||
efence_buffs[i] = buffs[i] + TEST_LEN - size;
|
||||
|
||||
for (i = 0; i < TEST_SOURCES; i++)
|
||||
g[i] = rand();
|
||||
|
||||
for (i = 0; i < TEST_SOURCES; i++)
|
||||
gf_vect_mul_init(g[i], &g_tbls[i * 32]);
|
||||
|
||||
gf_vect_dot_prod_base(size, TEST_SOURCES, &g_tbls[0], efence_buffs, dest_ref);
|
||||
FUNCTION_UNDER_TEST(size, TEST_SOURCES, g_tbls, efence_buffs, dest);
|
||||
|
||||
if (0 != memcmp(dest_ref, dest, size)) {
|
||||
printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test 3\n");
|
||||
dump_matrix(efence_buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref, align);
|
||||
printf("dprod:");
|
||||
dump(dest, align);
|
||||
return -1;
|
||||
}
|
||||
|
||||
putchar('.');
|
||||
}
|
||||
|
||||
// Test rand ptr alignment if available
|
||||
|
||||
for (rtest = 0; rtest < RANDOMS; rtest++) {
|
||||
size = (TEST_LEN - PTR_ALIGN_CHK_B) & ~(TEST_MIN_SIZE - 1);
|
||||
srcs = rand() % TEST_SOURCES;
|
||||
if (srcs == 0)
|
||||
continue;
|
||||
|
||||
offset = (PTR_ALIGN_CHK_B != 0) ? 1 : PTR_ALIGN_CHK_B;
|
||||
// Add random offsets
|
||||
for (i = 0; i < srcs; i++)
|
||||
ubuffs[i] = buffs[i] + (rand() & (PTR_ALIGN_CHK_B - offset));
|
||||
|
||||
udest_ptr = dest + (rand() & (PTR_ALIGN_CHK_B - offset));
|
||||
|
||||
memset(dest, 0, TEST_LEN); // zero pad to check write-over
|
||||
|
||||
for (i = 0; i < srcs; i++)
|
||||
for (j = 0; j < size; j++)
|
||||
ubuffs[i][j] = rand();
|
||||
|
||||
for (i = 0; i < srcs; i++)
|
||||
g[i] = rand();
|
||||
|
||||
for (i = 0; i < srcs; i++)
|
||||
gf_vect_mul_init(g[i], &g_tbls[i * 32]);
|
||||
|
||||
gf_vect_dot_prod_base(size, srcs, &g_tbls[0], ubuffs, dest_ref);
|
||||
|
||||
FUNCTION_UNDER_TEST(size, srcs, g_tbls, ubuffs, udest_ptr);
|
||||
|
||||
if (memcmp(dest_ref, udest_ptr, size)) {
|
||||
printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " ualign srcs=%d\n",
|
||||
srcs);
|
||||
dump_matrix(ubuffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref, 25);
|
||||
printf("dprod:");
|
||||
dump(udest_ptr, 25);
|
||||
return -1;
|
||||
}
|
||||
// Confirm that padding around dests is unchanged
|
||||
memset(dest_ref, 0, PTR_ALIGN_CHK_B); // Make reference zero buff
|
||||
offset = udest_ptr - dest;
|
||||
|
||||
if (memcmp(dest, dest_ref, offset)) {
|
||||
printf("Fail rand ualign pad start\n");
|
||||
return -1;
|
||||
}
|
||||
if (memcmp(dest + offset + size, dest_ref, PTR_ALIGN_CHK_B - offset)) {
|
||||
printf("Fail rand ualign pad end\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
putchar('.');
|
||||
}
|
||||
|
||||
// Test all size alignment
|
||||
align = (LEN_ALIGN_CHK_B != 0) ? 1 : 16;
|
||||
|
||||
for (size = TEST_LEN; size >= TEST_MIN_SIZE; size -= align) {
|
||||
srcs = TEST_SOURCES;
|
||||
|
||||
for (i = 0; i < srcs; i++)
|
||||
for (j = 0; j < size; j++)
|
||||
buffs[i][j] = rand();
|
||||
|
||||
for (i = 0; i < srcs; i++)
|
||||
g[i] = rand();
|
||||
|
||||
for (i = 0; i < srcs; i++)
|
||||
gf_vect_mul_init(g[i], &g_tbls[i * 32]);
|
||||
|
||||
gf_vect_dot_prod_base(size, srcs, &g_tbls[0], buffs, dest_ref);
|
||||
|
||||
FUNCTION_UNDER_TEST(size, srcs, g_tbls, buffs, dest);
|
||||
|
||||
if (memcmp(dest_ref, dest, size)) {
|
||||
printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " ualign len=%d\n",
|
||||
size);
|
||||
dump_matrix(buffs, 5, TEST_SOURCES);
|
||||
printf("dprod_base:");
|
||||
dump(dest_ref, 25);
|
||||
printf("dprod:");
|
||||
dump(dest, 25);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
printf("done all: Pass\n");
|
||||
return 0;
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
/**********************************************************************
|
||||
Copyright(c) 2011-2015 Intel Corporation All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Intel Corporation nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h> // for memset
|
||||
#include "erasure_code.h"
|
||||
#include "test.h"
|
||||
|
||||
//#define CACHED_TEST
|
||||
#ifdef CACHED_TEST
|
||||
// Cached test, loop many times over small dataset
|
||||
# define TEST_LEN 8*1024
|
||||
# define TEST_LOOPS 4000000
|
||||
# define TEST_TYPE_STR "_warm"
|
||||
#else
|
||||
# ifndef TEST_CUSTOM
|
||||
// Uncached test. Pull from large mem base.
|
||||
# define TEST_SOURCES 10
|
||||
# define GT_L3_CACHE 32*1024*1024 /* some number > last level cache */
|
||||
# define TEST_LEN GT_L3_CACHE / 2
|
||||
# define TEST_LOOPS 1000
|
||||
# define TEST_TYPE_STR "_cold"
|
||||
# else
|
||||
# define TEST_TYPE_STR "_cus"
|
||||
# ifndef TEST_LOOPS
|
||||
# define TEST_LOOPS 1000
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define TEST_MEM (2 * TEST_LEN)
|
||||
|
||||
typedef unsigned char u8;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
u8 *buff1, *buff2, gf_const_tbl[64], a = 2;
|
||||
struct perf start, stop;
|
||||
|
||||
printf("gf_vect_mul_avx_perf:\n");
|
||||
|
||||
gf_vect_mul_init(a, gf_const_tbl);
|
||||
|
||||
// Allocate large mem region
|
||||
buff1 = (u8 *) malloc(TEST_LEN);
|
||||
buff2 = (u8 *) malloc(TEST_LEN);
|
||||
if (NULL == buff1 || NULL == buff2) {
|
||||
printf("Failed to allocate %dB\n", TEST_LEN);
|
||||
return 1;
|
||||
}
|
||||
|
||||
memset(buff1, 0, TEST_LEN);
|
||||
memset(buff2, 0, TEST_LEN);
|
||||
|
||||
gf_vect_mul_avx(TEST_LEN, gf_const_tbl, buff1, buff2);
|
||||
|
||||
printf("Start timed tests\n");
|
||||
fflush(0);
|
||||
|
||||
gf_vect_mul_avx(TEST_LEN, gf_const_tbl, buff1, buff2);
|
||||
perf_start(&start);
|
||||
for (i = 0; i < TEST_LOOPS; i++) {
|
||||
gf_vect_mul_init(a, gf_const_tbl);
|
||||
gf_vect_mul_avx(TEST_LEN, gf_const_tbl, buff1, buff2);
|
||||
}
|
||||
perf_stop(&stop);
|
||||
printf("gf_vect_mul_avx" TEST_TYPE_STR ": ");
|
||||
perf_print(stop, start, (long long)TEST_LEN * i);
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,143 +0,0 @@
|
||||
/**********************************************************************
|
||||
Copyright(c) 2011-2015 Intel Corporation All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Intel Corporation nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h> // for memset
|
||||
#include "erasure_code.h"
|
||||
|
||||
#define TEST_SIZE 8192
|
||||
#define TEST_MEM TEST_SIZE
|
||||
#define TEST_LOOPS 100000
|
||||
#define TEST_TYPE_STR ""
|
||||
|
||||
typedef unsigned char u8;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
u8 *buff1, *buff2, *buff3, gf_const_tbl[64], a = 2;
|
||||
int align, size;
|
||||
unsigned char *efence_buff1;
|
||||
unsigned char *efence_buff2;
|
||||
unsigned char *efence_buff3;
|
||||
|
||||
printf("gf_vect_mul_avx:\n");
|
||||
|
||||
gf_vect_mul_init(a, gf_const_tbl);
|
||||
|
||||
buff1 = (u8 *) malloc(TEST_SIZE);
|
||||
buff2 = (u8 *) malloc(TEST_SIZE);
|
||||
buff3 = (u8 *) malloc(TEST_SIZE);
|
||||
|
||||
if (NULL == buff1 || NULL == buff2 || NULL == buff3) {
|
||||
printf("buffer alloc error\n");
|
||||
return -1;
|
||||
}
|
||||
// Fill with rand data
|
||||
for (i = 0; i < TEST_SIZE; i++)
|
||||
buff1[i] = rand();
|
||||
|
||||
gf_vect_mul_avx(TEST_SIZE, gf_const_tbl, buff1, buff2);
|
||||
|
||||
for (i = 0; i < TEST_SIZE; i++)
|
||||
if (gf_mul(a, buff1[i]) != buff2[i]) {
|
||||
printf("fail at %d, 0x%x x 2 = 0x%x (0x%x)\n", i, buff1[i], buff2[i],
|
||||
gf_mul(2, buff1[i]));
|
||||
return 1;
|
||||
}
|
||||
|
||||
gf_vect_mul_base(TEST_SIZE, gf_const_tbl, buff1, buff3);
|
||||
|
||||
// Check reference function
|
||||
for (i = 0; i < TEST_SIZE; i++)
|
||||
if (buff2[i] != buff3[i]) {
|
||||
printf("fail at %d, 0x%x x 0x%d = 0x%x (0x%x)\n",
|
||||
i, a, buff1[i], buff2[i], gf_mul(a, buff1[i]));
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < TEST_SIZE; i++)
|
||||
buff1[i] = rand();
|
||||
|
||||
// Check each possible constant
|
||||
printf("Random tests ");
|
||||
for (a = 0; a != 255; a++) {
|
||||
gf_vect_mul_init(a, gf_const_tbl);
|
||||
gf_vect_mul_avx(TEST_SIZE, gf_const_tbl, buff1, buff2);
|
||||
|
||||
for (i = 0; i < TEST_SIZE; i++)
|
||||
if (gf_mul(a, buff1[i]) != buff2[i]) {
|
||||
printf("fail at %d, 0x%x x %d = 0x%x (0x%x)\n",
|
||||
i, a, buff1[i], buff2[i], gf_mul(2, buff1[i]));
|
||||
return 1;
|
||||
}
|
||||
putchar('.');
|
||||
}
|
||||
|
||||
// Run tests at end of buffer for Electric Fence
|
||||
align = 32;
|
||||
a = 2;
|
||||
|
||||
gf_vect_mul_init(a, gf_const_tbl);
|
||||
for (size = 0; size < TEST_SIZE; size += align) {
|
||||
// Line up TEST_SIZE from end
|
||||
efence_buff1 = buff1 + size;
|
||||
efence_buff2 = buff2 + size;
|
||||
efence_buff3 = buff3 + size;
|
||||
|
||||
gf_vect_mul_avx(TEST_SIZE - size, gf_const_tbl, efence_buff1, efence_buff2);
|
||||
|
||||
for (i = 0; i < TEST_SIZE - size; i++)
|
||||
if (gf_mul(a, efence_buff1[i]) != efence_buff2[i]) {
|
||||
printf("fail at %d, 0x%x x 2 = 0x%x (0x%x)\n",
|
||||
i, efence_buff1[i], efence_buff2[i], gf_mul(2,
|
||||
efence_buff1
|
||||
[i]));
|
||||
return 1;
|
||||
}
|
||||
|
||||
gf_vect_mul_base(TEST_SIZE - size, gf_const_tbl, efence_buff1, efence_buff3);
|
||||
|
||||
// Check reference function
|
||||
for (i = 0; i < TEST_SIZE - size; i++)
|
||||
if (efence_buff2[i] != efence_buff3[i]) {
|
||||
printf("fail at %d, 0x%x x 0x%d = 0x%x (0x%x)\n",
|
||||
i, a, efence_buff2[i], efence_buff3[i], gf_mul(2,
|
||||
efence_buff1
|
||||
[i]));
|
||||
return 1;
|
||||
}
|
||||
|
||||
putchar('.');
|
||||
}
|
||||
|
||||
printf(" done: Pass\n");
|
||||
return 0;
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
/**********************************************************************
|
||||
Copyright(c) 2011-2015 Intel Corporation All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Intel Corporation nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h> // for memset
|
||||
#include "erasure_code.h"
|
||||
#include "test.h"
|
||||
|
||||
//#define CACHED_TEST
|
||||
#ifdef CACHED_TEST
|
||||
// Cached test, loop many times over small dataset
|
||||
# define TEST_LEN 8*1024
|
||||
# define TEST_LOOPS 4000000
|
||||
# define TEST_TYPE_STR "_warm"
|
||||
#else
|
||||
# ifndef TEST_CUSTOM
|
||||
// Uncached test. Pull from large mem base.
|
||||
# define TEST_SOURCES 10
|
||||
# define GT_L3_CACHE 32*1024*1024 /* some number > last level cache */
|
||||
# define TEST_LEN GT_L3_CACHE / 2
|
||||
# define TEST_LOOPS 1000
|
||||
# define TEST_TYPE_STR "_cold"
|
||||
# else
|
||||
# define TEST_TYPE_STR "_cus"
|
||||
# ifndef TEST_LOOPS
|
||||
# define TEST_LOOPS 1000
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define TEST_MEM (2 * TEST_LEN)
|
||||
|
||||
typedef unsigned char u8;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
u8 *buff1, *buff2, gf_const_tbl[64], a = 2;
|
||||
struct perf start, stop;
|
||||
|
||||
printf("gf_vect_mul_sse_perf:\n");
|
||||
|
||||
gf_vect_mul_init(a, gf_const_tbl);
|
||||
|
||||
// Allocate large mem region
|
||||
buff1 = (u8 *) malloc(TEST_LEN);
|
||||
buff2 = (u8 *) malloc(TEST_LEN);
|
||||
if (NULL == buff1 || NULL == buff2) {
|
||||
printf("Failed to allocate %dB\n", TEST_LEN);
|
||||
return 1;
|
||||
}
|
||||
|
||||
memset(buff1, 0, TEST_LEN);
|
||||
memset(buff2, 0, TEST_LEN);
|
||||
|
||||
printf("Start timed tests\n");
|
||||
fflush(0);
|
||||
|
||||
gf_vect_mul_sse(TEST_LEN, gf_const_tbl, buff1, buff2);
|
||||
perf_start(&start);
|
||||
for (i = 0; i < TEST_LOOPS; i++) {
|
||||
gf_vect_mul_init(a, gf_const_tbl); // in a re-build would only calc once
|
||||
gf_vect_mul_sse(TEST_LEN, gf_const_tbl, buff1, buff2);
|
||||
}
|
||||
perf_stop(&stop);
|
||||
printf("gf_vect_mul_sse" TEST_TYPE_STR ": ");
|
||||
perf_print(stop, start, (long long)TEST_LEN * i);
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,160 +0,0 @@
|
||||
/**********************************************************************
|
||||
Copyright(c) 2011-2015 Intel Corporation All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Intel Corporation nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "erasure_code.h"
|
||||
|
||||
#define TEST_SIZE (128*1024)
|
||||
|
||||
typedef unsigned char u8;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
u8 *buff1, *buff2, *buff3, gf_const_tbl[64], a = 2;
|
||||
int tsize;
|
||||
int align, size;
|
||||
unsigned char *efence_buff1;
|
||||
unsigned char *efence_buff2;
|
||||
unsigned char *efence_buff3;
|
||||
|
||||
printf("gf_vect_mul_sse_test: ");
|
||||
|
||||
gf_vect_mul_init(a, gf_const_tbl);
|
||||
|
||||
buff1 = (u8 *) malloc(TEST_SIZE);
|
||||
buff2 = (u8 *) malloc(TEST_SIZE);
|
||||
buff3 = (u8 *) malloc(TEST_SIZE);
|
||||
|
||||
if (NULL == buff1 || NULL == buff2 || NULL == buff3) {
|
||||
printf("buffer alloc error\n");
|
||||
return -1;
|
||||
}
|
||||
// Fill with rand data
|
||||
for (i = 0; i < TEST_SIZE; i++)
|
||||
buff1[i] = rand();
|
||||
|
||||
gf_vect_mul_sse(TEST_SIZE, gf_const_tbl, buff1, buff2);
|
||||
|
||||
for (i = 0; i < TEST_SIZE; i++) {
|
||||
if (gf_mul(a, buff1[i]) != buff2[i]) {
|
||||
printf("fail at %d, 0x%x x 2 = 0x%x (0x%x)\n", i,
|
||||
buff1[i], buff2[i], gf_mul(2, buff1[i]));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
gf_vect_mul_base(TEST_SIZE, gf_const_tbl, buff1, buff3);
|
||||
|
||||
// Check reference function
|
||||
for (i = 0; i < TEST_SIZE; i++) {
|
||||
if (buff2[i] != buff3[i]) {
|
||||
printf("fail at %d, 0x%x x 0x%d = 0x%x (0x%x)\n",
|
||||
i, a, buff1[i], buff2[i], gf_mul(a, buff1[i]));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < TEST_SIZE; i++)
|
||||
buff1[i] = rand();
|
||||
|
||||
// Check each possible constant
|
||||
for (a = 0; a != 255; a++) {
|
||||
gf_vect_mul_init(a, gf_const_tbl);
|
||||
gf_vect_mul_sse(TEST_SIZE, gf_const_tbl, buff1, buff2);
|
||||
|
||||
for (i = 0; i < TEST_SIZE; i++)
|
||||
if (gf_mul(a, buff1[i]) != buff2[i]) {
|
||||
printf("fail at %d, 0x%x x %d = 0x%x (0x%x)\n",
|
||||
i, a, buff1[i], buff2[i], gf_mul(2, buff1[i]));
|
||||
return -1;
|
||||
}
|
||||
putchar('.');
|
||||
}
|
||||
|
||||
// Check buffer len
|
||||
for (tsize = TEST_SIZE; tsize > 0; tsize -= 32) {
|
||||
a = rand();
|
||||
gf_vect_mul_init(a, gf_const_tbl);
|
||||
gf_vect_mul_sse(tsize, gf_const_tbl, buff1, buff2);
|
||||
|
||||
for (i = 0; i < tsize; i++)
|
||||
if (gf_mul(a, buff1[i]) != buff2[i]) {
|
||||
printf("fail at %d, 0x%x x %d = 0x%x (0x%x)\n",
|
||||
i, a, buff1[i], buff2[i], gf_mul(2, buff1[i]));
|
||||
return -1;
|
||||
}
|
||||
if (0 == tsize % (32 * 8)) {
|
||||
putchar('.');
|
||||
fflush(0);
|
||||
}
|
||||
}
|
||||
|
||||
// Run tests at end of buffer for Electric Fence
|
||||
align = 32;
|
||||
a = 2;
|
||||
|
||||
gf_vect_mul_init(a, gf_const_tbl);
|
||||
for (size = 0; size < TEST_SIZE; size += align) {
|
||||
// Line up TEST_SIZE from end
|
||||
efence_buff1 = buff1 + size;
|
||||
efence_buff2 = buff2 + size;
|
||||
efence_buff3 = buff3 + size;
|
||||
|
||||
gf_vect_mul_sse(TEST_SIZE - size, gf_const_tbl, efence_buff1, efence_buff2);
|
||||
|
||||
for (i = 0; i < TEST_SIZE - size; i++)
|
||||
if (gf_mul(a, efence_buff1[i]) != efence_buff2[i]) {
|
||||
printf("fail at %d, 0x%x x 2 = 0x%x (0x%x)\n",
|
||||
i, efence_buff1[i], efence_buff2[i], gf_mul(2,
|
||||
efence_buff1
|
||||
[i]));
|
||||
return 1;
|
||||
}
|
||||
|
||||
gf_vect_mul_base(TEST_SIZE - size, gf_const_tbl, efence_buff1, efence_buff3);
|
||||
|
||||
// Check reference function
|
||||
for (i = 0; i < TEST_SIZE - size; i++)
|
||||
if (efence_buff2[i] != efence_buff3[i]) {
|
||||
printf("fail at %d, 0x%x x 0x%d = 0x%x (0x%x)\n",
|
||||
i, a, efence_buff2[i], efence_buff3[i], gf_mul(2,
|
||||
efence_buff1
|
||||
[i]));
|
||||
return 1;
|
||||
}
|
||||
|
||||
putchar('.');
|
||||
}
|
||||
|
||||
printf(" done: Pass\n");
|
||||
fflush(0);
|
||||
return 0;
|
||||
}
|
@ -29,13 +29,9 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h> // for memset
|
||||
#include "erasure_code.h"
|
||||
|
||||
#define TEST_SIZE 8192
|
||||
#define TEST_MEM TEST_SIZE
|
||||
#define TEST_LOOPS 100000
|
||||
#define TEST_TYPE_STR ""
|
||||
#define TEST_SIZE (128*1024)
|
||||
|
||||
typedef unsigned char u8;
|
||||
|
||||
@ -43,12 +39,13 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
u8 *buff1, *buff2, *buff3, gf_const_tbl[64], a = 2;
|
||||
int tsize;
|
||||
int align, size;
|
||||
unsigned char *efence_buff1;
|
||||
unsigned char *efence_buff2;
|
||||
unsigned char *efence_buff3;
|
||||
|
||||
printf("gf_vect_mul_test:\n");
|
||||
printf("gf_vect_mul_test: ");
|
||||
|
||||
gf_vect_mul_init(a, gf_const_tbl);
|
||||
|
||||
@ -66,42 +63,60 @@ int main(int argc, char *argv[])
|
||||
|
||||
gf_vect_mul(TEST_SIZE, gf_const_tbl, buff1, buff2);
|
||||
|
||||
for (i = 0; i < TEST_SIZE; i++)
|
||||
for (i = 0; i < TEST_SIZE; i++) {
|
||||
if (gf_mul(a, buff1[i]) != buff2[i]) {
|
||||
printf("fail at %d, 0x%x x 2 = 0x%x (0x%x)\n", i, buff1[i], buff2[i],
|
||||
gf_mul(2, buff1[i]));
|
||||
return 1;
|
||||
printf("fail at %d, 0x%x x 2 = 0x%x (0x%x)\n", i,
|
||||
buff1[i], buff2[i], gf_mul(2, buff1[i]));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
gf_vect_mul_base(TEST_SIZE, gf_const_tbl, buff1, buff3);
|
||||
|
||||
// Check reference function
|
||||
for (i = 0; i < TEST_SIZE; i++)
|
||||
for (i = 0; i < TEST_SIZE; i++) {
|
||||
if (buff2[i] != buff3[i]) {
|
||||
printf("fail at %d, 0x%x x 0x%d = 0x%x (0x%x)\n",
|
||||
i, a, buff1[i], buff2[i], gf_mul(a, buff1[i]));
|
||||
return 1;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < TEST_SIZE; i++)
|
||||
buff1[i] = rand();
|
||||
|
||||
// Check each possible constant
|
||||
printf("Random tests ");
|
||||
for (a = 0; a != 255; a++) {
|
||||
gf_vect_mul_init(a, gf_const_tbl);
|
||||
gf_vect_mul(TEST_SIZE, gf_const_tbl, buff1, buff2);
|
||||
|
||||
for (i = 0; i < TEST_SIZE; i++) {
|
||||
for (i = 0; i < TEST_SIZE; i++)
|
||||
if (gf_mul(a, buff1[i]) != buff2[i]) {
|
||||
printf("fail at %d, 0x%x x %d = 0x%x (0x%x)\n",
|
||||
i, a, buff1[i], buff2[i], gf_mul(2, buff1[i]));
|
||||
return 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
putchar('.');
|
||||
}
|
||||
|
||||
// Check buffer len
|
||||
for (tsize = TEST_SIZE; tsize > 0; tsize -= 32) {
|
||||
a = rand();
|
||||
gf_vect_mul_init(a, gf_const_tbl);
|
||||
gf_vect_mul(tsize, gf_const_tbl, buff1, buff2);
|
||||
|
||||
for (i = 0; i < tsize; i++)
|
||||
if (gf_mul(a, buff1[i]) != buff2[i]) {
|
||||
printf("fail at %d, 0x%x x %d = 0x%x (0x%x)\n",
|
||||
i, a, buff1[i], buff2[i], gf_mul(2, buff1[i]));
|
||||
return -1;
|
||||
}
|
||||
if (0 == tsize % (32 * 8)) {
|
||||
putchar('.');
|
||||
fflush(0);
|
||||
}
|
||||
}
|
||||
|
||||
// Run tests at end of buffer for Electric Fence
|
||||
align = 32;
|
||||
a = 2;
|
||||
@ -138,5 +153,6 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
printf(" done: Pass\n");
|
||||
fflush(0);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user