Refactored vector library with SIMD independent architecture inline functions test-benchmark

master
Xavier Arteaga 7 years ago
parent 1c3b5552be
commit c9f6bfccd4

@ -80,8 +80,8 @@ SRSLTE_API void srslte_vec_load_file(char *filename, void *buffer, uint32_t len)
SRSLTE_API void srslte_vec_sum_ch(uint8_t *x, uint8_t *y, char *z, uint32_t len); SRSLTE_API void srslte_vec_sum_ch(uint8_t *x, uint8_t *y, char *z, uint32_t len);
SRSLTE_API void srslte_vec_sum_fff(float *x, float *y, float *z, uint32_t len); SRSLTE_API void srslte_vec_sum_fff(float *x, float *y, float *z, uint32_t len);
SRSLTE_API void srslte_vec_sum_ccc(cf_t *x, cf_t *y, cf_t *z, uint32_t len); SRSLTE_API void srslte_vec_sum_ccc(cf_t *x, cf_t *y, cf_t *z, uint32_t len);
SRSLTE_API void srslte_vec_sub_sss(short *x, short *y, short *z, uint32_t len); SRSLTE_API void srslte_vec_sub_sss(int16_t *x, int16_t *y, int16_t *z, uint32_t len);
SRSLTE_API void srslte_vec_sum_sss(short *x, short *y, short *z, uint32_t len); SRSLTE_API void srslte_vec_sum_sss(int16_t *x, int16_t *y, int16_t *z, uint32_t len);
/* substract two vectors z=x-y */ /* substract two vectors z=x-y */
SRSLTE_API void srslte_vec_sub_fff(float *x, float *y, float *z, uint32_t len); SRSLTE_API void srslte_vec_sub_fff(float *x, float *y, float *z, uint32_t len);
@ -91,7 +91,7 @@ SRSLTE_API void srslte_vec_sub_ccc(cf_t *x, cf_t *y, cf_t *z, uint32_t len);
SRSLTE_API void srslte_vec_ema_filter(cf_t *new_data, cf_t *average, cf_t *output, float coeff, uint32_t len); SRSLTE_API void srslte_vec_ema_filter(cf_t *new_data, cf_t *average, cf_t *output, float coeff, uint32_t len);
/* Square distance */ /* Square distance */
SRSLTE_API void srslte_vec_square_dist(cf_t symbol, cf_t *points, float *distance, uint32_t npoints); //SRSLTE_API void srslte_vec_square_dist(cf_t symbol, cf_t *points, float *distance, uint32_t npoints);
/* scalar addition */ /* scalar addition */
SRSLTE_API void srslte_vec_sc_add_fff(float *x, float h, float *z, uint32_t len); SRSLTE_API void srslte_vec_sc_add_fff(float *x, float h, float *z, uint32_t len);
@ -132,7 +132,7 @@ SRSLTE_API void srslte_vec_prod_conj_ccc(cf_t *x, cf_t *y, cf_t *z, uint32_t len
/* real vector product (element-wise) */ /* real vector product (element-wise) */
SRSLTE_API void srslte_vec_prod_fff(float *x, float *y, float *z, uint32_t len); SRSLTE_API void srslte_vec_prod_fff(float *x, float *y, float *z, uint32_t len);
SRSLTE_API void srslte_vec_prod_sss(short *x, short *y, short *z, uint32_t len); SRSLTE_API void srslte_vec_prod_sss(int16_t *x, int16_t *y, int16_t *z, uint32_t len);
/* Dot-product */ /* Dot-product */
SRSLTE_API cf_t srslte_vec_dot_prod_cfc(cf_t *x, float *y, uint32_t len); SRSLTE_API cf_t srslte_vec_dot_prod_cfc(cf_t *x, float *y, uint32_t len);

@ -35,45 +35,64 @@ extern "C" {
#include <stdint.h> #include <stdint.h>
#include "srslte/config.h" #include "srslte/config.h"
SRSLTE_API int srslte_vec_dot_prod_sss_sse(short *x, short *y, uint32_t len); #ifdef LV_HAVE_AVX512
#define SRSLTE_IS_ALIGNED(PTR) (((size_t)(PTR) & 0x3F) == 0)
#else /* LV_HAVE_AVX512 */
#ifdef LV_HAVE_AVX
#define SRSLTE_IS_ALIGNED(PTR) (((size_t)(PTR) & 0x1F) == 0)
#else /* LV_HAVE_AVX */
#ifdef LV_HAVE_SSE
#define SRSLTE_IS_ALIGNED(PTR) (((size_t)(PTR) & 0x0F) == 0)
#else /* LV_HAVE_SSE */
#define SRSLTE_IS_ALIGNED(PTR) (true)
#endif /* LV_HAVE_SSE */
#endif /* LV_HAVE_AVX */
#endif /* LV_HAVE_AVX512 */
SRSLTE_API int srslte_vec_dot_prod_sss_simd(int16_t *x, int16_t *y, int len);
SRSLTE_API void srslte_vec_sum_sss_simd(int16_t *x, int16_t *y, int16_t *z, int len);
SRSLTE_API void srslte_vec_sub_sss_simd(int16_t *x, int16_t *y, int16_t *z, int len);
SRSLTE_API int srslte_vec_dot_prod_sss_avx2(short *x, short *y, uint32_t len); SRSLTE_API void srslte_vec_sub_sss_avx2(short *x, short *y, short *z, uint32_t len);
SRSLTE_API void srslte_vec_sum_sss_sse(short *x, short *y, short *z, uint32_t len);
SRSLTE_API void srslte_vec_sum_sss_avx2(short *x, short *y, short *z, uint32_t len);
SRSLTE_API void srslte_vec_sub_sss_sse(short *x, short *y, short *z, uint32_t len); SRSLTE_API cf_t srslte_vec_acc_cc_simd(cf_t *x, int len);
SRSLTE_API void srslte_vec_sub_sss_avx2(short *x, short *y, short *z, uint32_t len); SRSLTE_API void srslte_vec_add_fff_simd(float *x, float *y, float *z, int len);
SRSLTE_API void srslte_vec_sum_fff_sse(float *x, float *y, float *z, uint32_t len); SRSLTE_API void srslte_vec_sub_fff_simd(float *x, float *y, float *z, int len);
SRSLTE_API void srslte_vec_sum_fff_avx(float *x, float *y, float *z, uint32_t len); SRSLTE_API void srslte_vec_sc_prod_fff_simd(float *x, float h, float *z, int len);
SRSLTE_API void srslte_vec_sub_fff_sse(float *x, float *y, float *z, uint32_t len); SRSLTE_API void srslte_vec_sc_prod_ccc_simd(cf_t *x, cf_t h, cf_t *z, int len);
SRSLTE_API void srslte_vec_sub_fff_avx(float *x, float *y, float *z, uint32_t len); SRSLTE_API void srslte_vec_prod_fff_simd(float *x, float *y, float *z, int len);
SRSLTE_API void srslte_vec_sc_prod_fff_sse(float *x, float h, float *z, uint32_t len); SRSLTE_API void srslte_vec_prod_ccc_simd(cf_t *x,cf_t *y, cf_t *z, int len);
SRSLTE_API void srslte_vec_sc_prod_ccc_sse(cf_t *x, cf_t h, cf_t *z, uint32_t len); SRSLTE_API void srslte_vec_prod_conj_ccc_simd(cf_t *x,cf_t *y, cf_t *z, int len);
SRSLTE_API void srslte_vec_prod_ccc_sse(cf_t *x,cf_t *y, cf_t *z, uint32_t len); SRSLTE_API void srslte_vec_prod_ccc_cf_simd(float *a_re, float *a_im, float *b_re, float *b_im, float *r_re, float *r_im, int len);
SRSLTE_API void srslte_vec_prod_sss_sse(short *x, short *y, short *z, uint32_t len); SRSLTE_API void srslte_vec_prod_ccc_c16_simd(int16_t *a_re, int16_t *a_im, int16_t *b_re, int16_t *b_im, int16_t *r_re,
int16_t *r_im, int len);
SRSLTE_API void srslte_vec_prod_sss_avx2(short *x, short *y, short *z, uint32_t len); SRSLTE_API void srslte_vec_prod_sss_simd(int16_t *x, int16_t *y, int16_t *z, int len);
SRSLTE_API cf_t srslte_vec_dot_prod_conj_ccc_sse(cf_t *x, cf_t *y, uint32_t len); SRSLTE_API cf_t srslte_vec_dot_prod_conj_ccc_simd(cf_t *x, cf_t *y, int len);
SRSLTE_API void srslte_vec_prod_conj_ccc_sse(cf_t *x,cf_t *y, cf_t *z, uint32_t len); SRSLTE_API cf_t srslte_vec_dot_prod_ccc_simd(cf_t *x, cf_t *y, int len);
SRSLTE_API cf_t srslte_vec_dot_prod_ccc_sse(cf_t *x, cf_t *y, uint32_t len); SRSLTE_API cf_t srslte_vec_dot_prod_ccc_sse(cf_t *x, cf_t *y, uint32_t len);
SRSLTE_API c16_t srslte_vec_dot_prod_ccc_c16i_simd(c16_t *x, c16_t *y, int len);
SRSLTE_API void srslte_vec_sc_div2_sss_avx2(short *x, int k, short *z, uint32_t len); SRSLTE_API void srslte_vec_sc_div2_sss_avx2(short *x, int k, short *z, uint32_t len);
SRSLTE_API void srslte_vec_abs_square_cf_sse(cf_t *x, float *z, uint32_t len); SRSLTE_API void srslte_vec_abs_cf_simd(cf_t *x, float *z, int len);
SRSLTE_API void srslte_vec_abs_square_cf_simd(cf_t *x, float *z, int len);
SRSLTE_API void srslte_vec_prod_sss_sse(short *x, short *y, short *z, uint32_t len); SRSLTE_API void srslte_vec_prod_sss_sse(short *x, short *y, short *z, uint32_t len);
@ -93,7 +112,9 @@ SRSLTE_API void srslte_vec_lut_sss_sse(short *x, unsigned short *lut, short *y,
SRSLTE_API void srslte_vec_convert_fi_sse(float *x, int16_t *z, float scale, uint32_t len); SRSLTE_API void srslte_vec_convert_fi_sse(float *x, int16_t *z, float scale, uint32_t len);
SRSLTE_API void srslte_vec_sc_prod_cfc_avx(const cf_t *x,const float h,cf_t *y,const uint32_t len); SRSLTE_API void srslte_vec_sc_prod_cfc_simd(const cf_t *x,const float h,cf_t *y,const int len);
SRSLTE_API void srslte_vec_cp_simd(cf_t *src, cf_t *dst, int len);
#ifdef __cplusplus #ifdef __cplusplus
} }

@ -42,3 +42,6 @@ target_link_libraries(algebra_test srslte_phy)
add_test(algebra_2x2_zf_solver_test algebra_test -z) add_test(algebra_2x2_zf_solver_test algebra_test -z)
add_test(algebra_2x2_mmse_solver_test algebra_test -m) add_test(algebra_2x2_mmse_solver_test algebra_test -m)
add_executable(vector_test vector_test.c)
target_link_libraries(vector_test srslte_phy)

@ -0,0 +1,555 @@
/**
*
* \section COPYRIGHT
*
* Copyright 2013-2015 Software Radio Systems Limited
*
* \section LICENSE
*
* This file is part of the srsLTE library.
*
* srsLTE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* srsLTE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* A copy of the GNU Affero General Public License can be found in
* the LICENSE file in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <complex.h>
#include <stdbool.h>
#include <immintrin.h>
#include <sys/time.h>
#include <srslte/phy/utils/vector_simd.h>
#include <memory.h>
#include <math.h>
#include "srslte/phy/utils/mat.h"
#include "srslte/phy/utils/simd.h"
#include "srslte/phy/utils/vector.h"
bool zf_solver = false;
bool mmse_solver = false;
bool verbose = false;
#define MAX_MSE (1e-3)
#define NOF_REPETITIONS (1024*128)
#define MAX_FUNCTIONS (64)
#define MAX_BLOCKS (16)
#define RANDOM_F() ((float)rand())/((float)RAND_MAX)
#define RANDOM_S() ((int16_t)(rand() && 0x800F))
#define RANDOM_CF() (RANDOM_F() + _Complex_I*RANDOM_F())
#define TEST_CALL(TEST_CODE) gettimeofday(&start, NULL);\
for (int i = 0; i < NOF_REPETITIONS; i++){TEST_CODE;}\
gettimeofday(&end, NULL); \
*timing = elapsed_us(&start, &end);
#define TEST(X, CODE) static bool test_##X (char *func_name, double *timing, uint32_t block_size) {\
struct timeval start, end;\
float mse = 0.0f;\
bool passed;\
strncpy(func_name, #X, 32);\
CODE;\
passed = (mse < MAX_MSE);\
printf("%32s (%5d) ... %7.1f MSamp/s ... %3s Passed\n", func_name, block_size, \
(double) block_size*NOF_REPETITIONS/ *timing, passed?"":"Not");\
return passed;\
}
#define MALLOC(TYPE, NAME) TYPE *NAME = srslte_vec_malloc(sizeof(TYPE)*block_size)
static double elapsed_us(struct timeval *ts_start, struct timeval *ts_end) {
if (ts_end->tv_usec > ts_start->tv_usec) {
return ((double) ts_end->tv_sec - (double) ts_start->tv_sec) * 1000000 +
(double) ts_end->tv_usec - (double) ts_start->tv_usec;
} else {
return ((double) ts_end->tv_sec - (double) ts_start->tv_sec - 1) * 1000000 +
((double) ts_end->tv_usec + 1000000) - (double) ts_start->tv_usec;
}
}
float squared_error (cf_t a, cf_t b) {
float diff_re = __real__ a - __real__ b;
float diff_im = __imag__ a - __imag__ b;
return diff_re*diff_re + diff_im*diff_im;
}
TEST(srslte_vec_dot_prod_sss,
MALLOC(int16_t, x);
MALLOC(int16_t, y);
int16_t z;
cf_t gold = 0.0f;
for (int i = 0; i < block_size; i++) {
x[i] = RANDOM_S();
y[i] = RANDOM_S();
}
TEST_CALL(z = srslte_vec_dot_prod_sss(x, y, block_size))
for (int i = 0; i < block_size; i++) {
gold += x[i] * y[i];
}
mse += cabsf(gold - z) / cabsf(gold);
free(x);
free(y);
)
TEST(srslte_vec_sum_sss,
MALLOC(int16_t, x);
MALLOC(int16_t, y);
MALLOC(int16_t, z);
cf_t gold = 0.0f;
for (int i = 0; i < block_size; i++) {
x[i] = RANDOM_S();
y[i] = RANDOM_S();
}
TEST_CALL(srslte_vec_sum_sss(x, y, z, block_size))
for (int i = 0; i < block_size; i++) {
gold = x[i] + y[i];
mse += cabsf(gold - z[i]);
}
free(x);
free(y);
free(z);
)
TEST(srslte_vec_sub_sss,
MALLOC(int16_t, x);
MALLOC(int16_t, y);
MALLOC(int16_t, z);
cf_t gold = 0.0f;
for (int i = 0; i < block_size; i++) {
x[i] = RANDOM_S();
y[i] = RANDOM_S();
}
TEST_CALL(srslte_vec_sub_sss(x, y, z, block_size))
for (int i = 0; i < block_size; i++) {
gold = x[i] - y[i];
mse += cabsf(gold - z[i]);
}
free(x);
free(y);
free(z);
)
TEST(srslte_vec_prod_sss,
MALLOC(int16_t, x);
MALLOC(int16_t, y);
MALLOC(int16_t, z);
cf_t gold = 0.0f;
for (int i = 0; i < block_size; i++) {
x[i] = RANDOM_S();
y[i] = RANDOM_S();
}
TEST_CALL(srslte_vec_prod_sss(x, y, z, block_size))
for (int i = 0; i < block_size; i++) {
gold = x[i] * y[i];
mse += cabsf(gold - z[i]);
}
free(x);
free(y);
free(z);
)
TEST(srslte_vec_acc_cc,
MALLOC(cf_t, x);
cf_t z;
cf_t gold = 0.0f;
for (int i = 0; i < block_size; i++) {
x[i] = RANDOM_F();
}
TEST_CALL(z = srslte_vec_acc_cc(x, block_size))
for (int i = 0; i < block_size; i++) {
gold += x[i];
}
mse += cabsf(gold - z)/cabsf(gold);
free(x);
)
TEST(srslte_vec_sum_fff,
MALLOC(float, x);
MALLOC(float, y);
MALLOC(float, z);
cf_t gold = 0.0f;
for (int i = 0; i < block_size; i++) {
x[i] = RANDOM_F();
y[i] = RANDOM_F();
}
TEST_CALL(srslte_vec_sum_fff(x, y, z, block_size))
for (int i = 0; i < block_size; i++) {
gold = x[i] + y[i];
mse += cabsf(gold - z[i]);
}
free(x);
free(y);
)
TEST(srslte_vec_sub_fff,
MALLOC(float, x);
MALLOC(float, y);
MALLOC(float, z);
cf_t gold = 0.0f;
for (int i = 0; i < block_size; i++) {
x[i] = RANDOM_F();
y[i] = RANDOM_F();
}
TEST_CALL(srslte_vec_sub_fff(x, y, z, block_size))
for (int i = 0; i < block_size; i++) {
gold = x[i] - y[i];
mse += cabsf(gold - z[i]);
}
free(x);
free(y);
)
TEST(srslte_vec_dot_prod_ccc,
MALLOC(cf_t, x);
MALLOC(cf_t, y);
cf_t z;
cf_t gold = 0.0f;
for (int i = 0; i < block_size; i++) {
x[i] = RANDOM_CF();
y[i] = RANDOM_CF();
}
TEST_CALL(z = srslte_vec_dot_prod_ccc(x, y, block_size))
for (int i = 0; i < block_size; i++) {
gold += x[i] * y[i];
}
mse = cabsf(gold - z) / cabsf(gold);
free(x);
free(y);
)
TEST(srslte_vec_dot_prod_conj_ccc,
MALLOC(cf_t, x);
MALLOC(cf_t, y);
cf_t z;
cf_t gold = 0.0f;
for (int i = 0; i < block_size; i++) {
x[i] = RANDOM_CF();
y[i] = RANDOM_CF();
}
TEST_CALL(z = srslte_vec_dot_prod_conj_ccc(x, y, block_size))
for (int i = 0; i < block_size; i++) {
gold += x[i] * conjf(y[i]);
}
mse = cabsf(gold - z) / cabsf(gold);
free(x);
free(y);
)
TEST(srslte_vec_prod_ccc,
MALLOC(cf_t, x);
MALLOC(cf_t, y);
MALLOC(cf_t, z);
cf_t gold;
for (int i = 0; i < block_size; i++) {
x[i] = RANDOM_CF();
y[i] = RANDOM_CF();
}
TEST_CALL(srslte_vec_prod_ccc(x, y, z, block_size))
for (int i = 0; i < block_size; i++) {
gold = x[i] * y[i];
mse += cabsf(gold - z[i]);
}
free(x);
free(z);
)
TEST(srslte_vec_prod_conj_ccc,
MALLOC(cf_t, x);
MALLOC(cf_t, y);
MALLOC(cf_t, z);
cf_t gold;
for (int i = 0; i < block_size; i++) {
x[i] = RANDOM_CF();
y[i] = RANDOM_CF();
}
TEST_CALL(srslte_vec_prod_conj_ccc(x, y, z, block_size))
for (int i = 0; i < block_size; i++) {
gold = x[i] * conjf(y[i]);
mse += cabsf(gold - z[i]);
}
free(x);
free(z);
)
TEST(srslte_vec_sc_prod_ccc,
MALLOC(cf_t, x);
MALLOC(cf_t, z);
cf_t y = RANDOM_F();
cf_t gold;
for (int i = 0; i < block_size; i++) {
x[i] = RANDOM_CF();
}
TEST_CALL(srslte_vec_sc_prod_ccc(x, y, z, block_size))
for (int i = 0; i < block_size; i++) {
gold = x[i] * y;
mse += cabsf(gold - z[i]);
}
free(x);
free(z);
)
TEST(srslte_vec_prod_fff,
MALLOC(float, x);
MALLOC(float, y);
MALLOC(float, z);
cf_t gold;
for (int i = 0; i < block_size; i++) {
x[i] = RANDOM_CF();
y[i] = RANDOM_CF();
}
TEST_CALL(srslte_vec_prod_fff(x, y, z, block_size))
for (int i = 0; i < block_size; i++) {
gold = x[i] * y[i];
mse += cabsf(gold - z[i]);
}
free(x);
free(z);
)
TEST(srslte_vec_sc_prod_fff,
MALLOC(float, x);
MALLOC(float, z);
float y = RANDOM_F();
float gold;
for (int i = 0; i < block_size; i++) {
x[i] = RANDOM_CF();
}
TEST_CALL(srslte_vec_sc_prod_fff(x, y, z, block_size))
for (int i = 0; i < block_size; i++) {
gold = x[i] * y;
mse += cabsf(gold - z[i]);
}
free(x);
free(z);
)
TEST(srslte_vec_abs_cf,
MALLOC(cf_t, x);
MALLOC(float, z);
float gold;
for (int i = 0; i < block_size; i++) {
x[i] = RANDOM_CF();
}
TEST_CALL(srslte_vec_abs_cf(x, z, block_size))
for (int i = 0; i < block_size; i++) {
gold = sqrtf(crealf(x[i]) * crealf(x[i]) + cimagf(x[i])*cimagf(x[i]));
mse += cabsf(gold - z[i]);
}
free(x);
free(z);
)
TEST(srslte_vec_abs_square_cf,
MALLOC(cf_t, x);
MALLOC(float, z);
float gold;
for (int i = 0; i < block_size; i++) {
x[i] = RANDOM_CF();
}
TEST_CALL(srslte_vec_abs_square_cf(x, z, block_size))
for (int i = 0; i < block_size; i++) {
gold = crealf(x[i]) * crealf(x[i]) + cimagf(x[i])*cimagf(x[i]);
mse += cabsf(gold - z[i]);
}
free(x);
free(z);
)
TEST(srslte_vec_sc_prod_cfc,
MALLOC(cf_t, x);
MALLOC(cf_t, z);
cf_t gold;
float h = RANDOM_F();
for (int i = 0; i < block_size; i++) {
x[i] = RANDOM_CF();
}
TEST_CALL(srslte_vec_sc_prod_cfc(x, h, z, block_size))
for (int i = 0; i < block_size; i++) {
gold = x[i] * h;
mse += cabsf(gold - z[i]);
}
free(x);
free(z);
)
int main(int argc, char **argv) {
char func_names[MAX_FUNCTIONS][32];
double timmings[MAX_FUNCTIONS][MAX_BLOCKS];
uint32_t sizes[32];
uint32_t size_count = 0;
uint32_t func_count = 0;
bool passed = true;
for (uint32_t block_size = 1; block_size <= 1024*16; block_size *= 2) {
func_count = 0;
passed &= test_srslte_vec_dot_prod_sss(func_names[func_count], &timmings[func_count][size_count], block_size);
func_count++;
passed &= test_srslte_vec_sum_sss(func_names[func_count], &timmings[func_count][size_count], block_size);
func_count++;
passed &= test_srslte_vec_sub_sss(func_names[func_count], &timmings[func_count][size_count], block_size);
func_count++;
passed &= test_srslte_vec_prod_sss(func_names[func_count], &timmings[func_count][size_count], block_size);
func_count++;
passed &= test_srslte_vec_acc_cc(func_names[func_count], &timmings[func_count][size_count], block_size);
func_count++;
passed &= test_srslte_vec_sum_fff(func_names[func_count], &timmings[func_count][size_count], block_size);
func_count++;
passed &= test_srslte_vec_sub_fff(func_names[func_count], &timmings[func_count][size_count], block_size);
func_count++;
passed &= test_srslte_vec_dot_prod_ccc(func_names[func_count], &timmings[func_count][size_count], block_size);
func_count++;
passed &= test_srslte_vec_dot_prod_conj_ccc(func_names[func_count], &timmings[func_count][size_count], block_size);
func_count++;
passed &= test_srslte_vec_prod_fff(func_names[func_count], &timmings[func_count][size_count], block_size);
func_count++;
passed &= test_srslte_vec_prod_ccc(func_names[func_count], &timmings[func_count][size_count], block_size);
func_count++;
passed &= test_srslte_vec_prod_conj_ccc(func_names[func_count], &timmings[func_count][size_count], block_size);
func_count++;
passed &= test_srslte_vec_sc_prod_ccc(func_names[func_count], &timmings[func_count][size_count], block_size);
func_count++;
passed &= test_srslte_vec_sc_prod_fff(func_names[func_count], &timmings[func_count][size_count], block_size);
func_count++;
passed &= test_srslte_vec_abs_cf(func_names[func_count], &timmings[func_count][size_count], block_size);
func_count++;
passed &= test_srslte_vec_abs_square_cf(func_names[func_count], &timmings[func_count][size_count], block_size);
func_count++;
passed &= test_srslte_vec_sc_prod_cfc(func_names[func_count], &timmings[func_count][size_count], block_size);
func_count++;
sizes[size_count] = block_size;
size_count++;
}
printf("\n");
printf("%32s |", "Subroutine/MSps");
for (int i = 0; i < size_count; i++) {
printf(" %7d", sizes[i]);
}
printf(" |\n");
for (int j = 0; j < 32; j++) {
printf("-");
}
printf("-+-");
for (int j = 0; j < size_count; j++) {
printf("--------");
}
printf("-|\n");
for (int i = 0; i < func_count; i++) {
printf("%32s | ", func_names[i]);
for (int j = 0; j < size_count; j++) {
printf(" %7.1f", (double) NOF_REPETITIONS*(double)sizes[j]/timmings[i][j]);
}
printf(" |\n");
}
return (passed)?SRSLTE_SUCCESS:SRSLTE_ERROR;
}

@ -36,25 +36,6 @@
#include "srslte/phy/utils/bit.h" #include "srslte/phy/utils/bit.h"
#ifdef LV_HAVE_SSE
#include <smmintrin.h>
#endif
#ifdef LV_HAVE_AVX
#include <immintrin.h>
#endif
#ifdef HAVE_VOLK
#include "volk/volk.h"
#endif
#ifdef DEBUG_MODE
#warning FIXME: Disabling SSE/AVX vector code
#undef LV_HAVE_SSE
#undef LV_HAVE_AVX
#endif
int srslte_vec_acc_ii(int *x, uint32_t len) { int srslte_vec_acc_ii(int *x, uint32_t len) {
int i; int i;
@ -88,51 +69,25 @@ void srslte_vec_ema_filter(cf_t *new_data, cf_t *average, cf_t *output, float co
} }
cf_t srslte_vec_acc_cc(cf_t *x, uint32_t len) { cf_t srslte_vec_acc_cc(cf_t *x, uint32_t len) {
int i; return srslte_vec_acc_cc_simd(x, len);
cf_t z=0;
for (i=0;i<len;i++) {
z+=x[i];
}
return z;
} }
void srslte_vec_square_dist(cf_t symbol, cf_t *points, float *distance, uint32_t npoints) { #warning Remove function if not used!
/*void srslte_vec_square_dist(cf_t symbol, cf_t *points, float *distance, uint32_t npoints) {
uint32_t i; uint32_t i;
cf_t diff; cf_t diff;
for (i=0;i<npoints;i++) { for (i=0;i<npoints;i++) {
diff = symbol - points[i]; diff = symbol - points[i];
distance[i] = crealf(diff) * crealf(diff) + cimagf(diff) * cimagf(diff); distance[i] = crealf(diff) * crealf(diff) + cimagf(diff) * cimagf(diff);
} }
} }*/
void srslte_vec_sub_fff(float *x, float *y, float *z, uint32_t len) { void srslte_vec_sub_fff(float *x, float *y, float *z, uint32_t len) {
#ifndef LV_HAVE_SSE srslte_vec_sub_fff_simd(x, y, z, len);
int i;
for (i=0;i<len;i++) {
z[i] = x[i]-y[i];
}
#else
#ifdef LV_HAVE_AVX
srslte_vec_sub_fff_avx(x, y, z, len);
#else
srslte_vec_sub_fff_sse(x, y, z, len);
#endif
#endif
} }
void srslte_vec_sub_sss(short *x, short *y, short *z, uint32_t len) { void srslte_vec_sub_sss(int16_t *x, int16_t *y, int16_t *z, uint32_t len) {
#ifdef LV_HAVE_AVX2 srslte_vec_sub_sss_simd(x, y, z, len);
srslte_vec_sub_sss_avx2(x, y, z, len);
#else
#ifdef LV_HAVE_SSE
srslte_vec_sub_sss_sse(x, y, z, len);
#else
int i;
for (i=0;i<len;i++) {
z[i] = x[i]-y[i];
}
#endif
#endif
} }
// Noise estimation in chest_dl, interpolation // Noise estimation in chest_dl, interpolation
@ -142,33 +97,11 @@ void srslte_vec_sub_ccc(cf_t *x, cf_t *y, cf_t *z, uint32_t len) {
// Used in PSS/SSS and sum_ccc // Used in PSS/SSS and sum_ccc
void srslte_vec_sum_fff(float *x, float *y, float *z, uint32_t len) { void srslte_vec_sum_fff(float *x, float *y, float *z, uint32_t len) {
#ifndef LV_HAVE_SSE srslte_vec_add_fff_simd(x, y, z, len);
int i;
for (i=0;i<len;i++) {
z[i] = x[i]+y[i];
}
#else
#ifdef LV_HAVE_AVX
srslte_vec_sum_fff_avx(x, y, z, len);
#else
srslte_vec_sum_fff_sse(x, y, z, len);
#endif
#endif
} }
void srslte_vec_sum_sss(short *x, short *y, short *z, uint32_t len) { void srslte_vec_sum_sss(int16_t *x, int16_t *y, int16_t *z, uint32_t len) {
#ifdef LV_HAVE_AVX2 srslte_vec_sum_sss_simd(x, y, z, len);
srslte_vec_sum_sss_avx2(x, y, z, len);
#else
#ifdef LV_HAVE_SSE
srslte_vec_sum_sss_sse(x, y, z, len);
#else
int i;
for (i=0;i<len;i++) {
z[i] = x[i]+y[i];
}
#endif
#endif
} }
void srslte_vec_sum_ccc(cf_t *x, cf_t *y, cf_t *z, uint32_t len) { void srslte_vec_sum_ccc(cf_t *x, cf_t *y, cf_t *z, uint32_t len) {
@ -211,14 +144,7 @@ void srslte_vec_sc_add_sss(int16_t *x, int16_t h, int16_t *z, uint32_t len) {
} }
// PSS, PBCH, DEMOD, FFTW, etc. // PSS, PBCH, DEMOD, FFTW, etc.
void srslte_vec_sc_prod_fff(float *x, float h, float *z, uint32_t len) { void srslte_vec_sc_prod_fff(float *x, float h, float *z, uint32_t len) {
#ifndef LV_HAVE_SSE srslte_vec_sc_prod_fff_simd(x, h, z, len);
int i;
for (i=0;i<len;i++) {
z[i] = x[i]*h;
}
#else
srslte_vec_sc_prod_fff_sse(x, h, z, len);
#endif
} }
void srslte_vec_sc_prod_sfs(short *x, float h, short *z, uint32_t len) { void srslte_vec_sc_prod_sfs(short *x, float h, short *z, uint32_t len) {
@ -228,7 +154,8 @@ void srslte_vec_sc_prod_sfs(short *x, float h, short *z, uint32_t len) {
} }
} }
void srslte_vec_sc_div2_sss(short *x, int n_rightshift, short *z, uint32_t len) { #warning remove function if it is not used
/*void srslte_vec_sc_div2_sss(short *x, int n_rightshift, short *z, uint32_t len) {
#ifdef LV_HAVE_AVX2 #ifdef LV_HAVE_AVX2
srslte_vec_sc_div2_sss_avx2(x, n_rightshift, z, len); srslte_vec_sc_div2_sss_avx2(x, n_rightshift, z, len);
#else #else
@ -242,7 +169,7 @@ void srslte_vec_sc_div2_sss(short *x, int n_rightshift, short *z, uint32_t len)
} }
#endif #endif
#endif #endif
} }*/
// TODO: Improve this implementation // TODO: Improve this implementation
void srslte_vec_norm_cfc(cf_t *x, float amplitude, cf_t *y, uint32_t len) { void srslte_vec_norm_cfc(cf_t *x, float amplitude, cf_t *y, uint32_t len) {
@ -257,14 +184,7 @@ void srslte_vec_norm_cfc(cf_t *x, float amplitude, cf_t *y, uint32_t len) {
// Used throughout // Used throughout
void srslte_vec_sc_prod_cfc(cf_t *x, float h, cf_t *z, uint32_t len) { void srslte_vec_sc_prod_cfc(cf_t *x, float h, cf_t *z, uint32_t len) {
#ifdef LV_HAVE_AVX srslte_vec_sc_prod_cfc_simd(x,h,z,len);
srslte_vec_sc_prod_cfc_avx(x,h,z,len);
#else
int i;
for (i=0;i<len;i++) {
z[i] = x[i]*h;
}
#endif
} }
@ -276,7 +196,7 @@ void srslte_vec_sc_prod_ccc(cf_t *x, cf_t h, cf_t *z, uint32_t len) {
z[i] = x[i]*h; z[i] = x[i]*h;
} }
#else #else
srslte_vec_sc_prod_ccc_sse(x,h,z,len); srslte_vec_sc_prod_ccc_simd(x,h,z,len);
#endif #endif
} }
@ -360,7 +280,7 @@ void srslte_vec_deinterleave_real_cf(cf_t *x, float *real, uint32_t len) {
*/ */
void *srslte_vec_malloc(uint32_t size) { void *srslte_vec_malloc(uint32_t size) {
void *ptr; void *ptr;
if (posix_memalign(&ptr,256,size)) { if (posix_memalign(&ptr,512,size)) {
return NULL; return NULL;
} else { } else {
return ptr; return ptr;
@ -511,50 +431,22 @@ void srslte_vec_prod_cfc(cf_t *x, float *y, cf_t *z, uint32_t len) {
// Used in scrambling float // Used in scrambling float
void srslte_vec_prod_fff(float *x, float *y, float *z, uint32_t len) { void srslte_vec_prod_fff(float *x, float *y, float *z, uint32_t len) {
int i; srslte_vec_prod_fff_simd(x, y, z, len);
for (i=0;i<len;i++) {
z[i] = x[i]*y[i];
}
} }
// Scrambling Short // Scrambling Short
void srslte_vec_prod_sss(short *x, short *y, short *z, uint32_t len) { void srslte_vec_prod_sss(int16_t *x, int16_t *y, int16_t *z, uint32_t len) {
#ifdef LV_HAVE_AVX2 srslte_vec_prod_sss_simd(x,y,z,len);
srslte_vec_prod_sss_avx2(x,y,z,len);
#else
#ifdef LV_HAVE_SSE
srslte_vec_prod_sss_sse(x,y,z,len);
#else
int i;
for (i=0;i<len;i++) {
z[i] = x[i]*y[i];
}
#endif
#endif
} }
// CFO and OFDM processing // CFO and OFDM processing
void srslte_vec_prod_ccc(cf_t *x,cf_t *y, cf_t *z, uint32_t len) { void srslte_vec_prod_ccc(cf_t *x,cf_t *y, cf_t *z, uint32_t len) {
#ifndef LV_HAVE_SSE srslte_vec_prod_ccc_simd(x,y,z,len);
int i;
for (i=0;i<len;i++) {
z[i] = x[i]*y[i];
}
#else
srslte_vec_prod_ccc_sse(x,y,z,len);
#endif
} }
// PRACH, CHEST UL, etc. // PRACH, CHEST UL, etc.
void srslte_vec_prod_conj_ccc(cf_t *x,cf_t *y, cf_t *z, uint32_t len) { void srslte_vec_prod_conj_ccc(cf_t *x,cf_t *y, cf_t *z, uint32_t len) {
#ifndef LV_HAVE_SSE srslte_vec_prod_conj_ccc_simd(x,y,z,len);
int i;
for (i=0;i<len;i++) {
z[i] = x[i]*conjf(y[i]);
}
#else
srslte_vec_prod_conj_ccc_sse(x,y,z,len);
#endif
} }
//#define DIV_USE_VEC //#define DIV_USE_VEC
@ -598,16 +490,7 @@ void srslte_vec_div_fff(float *x, float *y, float *z, uint32_t len) {
// PSS. convolution // PSS. convolution
cf_t srslte_vec_dot_prod_ccc(cf_t *x, cf_t *y, uint32_t len) { cf_t srslte_vec_dot_prod_ccc(cf_t *x, cf_t *y, uint32_t len) {
#ifndef LV_HAVE_SSE return srslte_vec_dot_prod_ccc_simd(x, y, len);
uint32_t i;
cf_t res = 0;
for (i=0;i<len;i++) {
res += x[i]*y[i];
}
return res;
#else
return srslte_vec_dot_prod_ccc_sse(x, y, len);
#endif
} }
// Convolution filter and in SSS search // Convolution filter and in SSS search
@ -622,17 +505,7 @@ cf_t srslte_vec_dot_prod_cfc(cf_t *x, float *y, uint32_t len) {
// SYNC // SYNC
cf_t srslte_vec_dot_prod_conj_ccc(cf_t *x, cf_t *y, uint32_t len) { cf_t srslte_vec_dot_prod_conj_ccc(cf_t *x, cf_t *y, uint32_t len) {
#ifndef LV_HAVE_SSE return srslte_vec_dot_prod_conj_ccc_simd(x, y, len);
uint32_t i;
cf_t res = 0;
for (i=0;i<len;i++) {
res += x[i]*conjf(y[i]);
}
return res;
#else
return srslte_vec_dot_prod_conj_ccc_sse(x, y, len);
#endif
} }
// PHICH // PHICH
@ -646,20 +519,7 @@ float srslte_vec_dot_prod_fff(float *x, float *y, uint32_t len) {
} }
int32_t srslte_vec_dot_prod_sss(int16_t *x, int16_t *y, uint32_t len) { int32_t srslte_vec_dot_prod_sss(int16_t *x, int16_t *y, uint32_t len) {
#ifdef LV_HAVE_AVX2 return srslte_vec_dot_prod_sss_simd(x, y, len);
return srslte_vec_dot_prod_sss_avx2(x, y, len);
#else
#ifdef LV_HAVE_SSE
return srslte_vec_dot_prod_sss_sse(x, y, len);
#else
uint32_t i;
int32_t res = 0;
for (i=0;i<len;i++) {
res += x[i]*y[i];
}
return res;
#endif
#endif
} }
float srslte_vec_avg_power_cf(cf_t *x, uint32_t len) { float srslte_vec_avg_power_cf(cf_t *x, uint32_t len) {
@ -672,27 +532,17 @@ float srslte_vec_corr_ccc(cf_t *x, cf_t *y, uint32_t len) {
float s_x = crealf(srslte_vec_dot_prod_conj_ccc(x, x, len))/len; float s_x = crealf(srslte_vec_dot_prod_conj_ccc(x, x, len))/len;
float s_y = crealf(srslte_vec_dot_prod_conj_ccc(y, y, len))/len; float s_y = crealf(srslte_vec_dot_prod_conj_ccc(y, y, len))/len;
float cov = crealf(srslte_vec_dot_prod_conj_ccc(x, y, len))/len; float cov = crealf(srslte_vec_dot_prod_conj_ccc(x, y, len))/len;
return cov/(sqrt(s_x*s_y)); return cov/(sqrtf(s_x*s_y));
} }
// PSS (disabled and using abs_square ) // PSS (disabled and using abs_square )
void srslte_vec_abs_cf(cf_t *x, float *abs, uint32_t len) { void srslte_vec_abs_cf(cf_t *x, float *abs, uint32_t len) {
int i; srslte_vec_abs_cf_simd(x, abs, len);
for (i=0;i<len;i++) {
abs[i] = cabsf(x[i]);
}
} }
// PRACH // PRACH
void srslte_vec_abs_square_cf(cf_t *x, float *abs_square, uint32_t len) { void srslte_vec_abs_square_cf(cf_t *x, float *abs_square, uint32_t len) {
#ifndef LV_HAVE_SSE srslte_vec_abs_square_cf_simd(x,abs_square,len);
int i;
for (i=0;i<len;i++) {
abs_square[i] = crealf(x[i])*crealf(x[i])+cimagf(x[i])*cimagf(x[i]);
}
#else
srslte_vec_abs_square_cf_sse(x,abs_square,len);
#endif
} }
@ -821,23 +671,5 @@ void srslte_vec_quant_suc(int16_t *in, uint8_t *out, float gain, int16_t offset,
} }
void srs_vec_cf_cpy(cf_t *dst, cf_t *src, int len) { void srs_vec_cf_cpy(cf_t *dst, cf_t *src, int len) {
int i = 0; srslte_vec_cp_simd(dst, src, len);
#ifdef LV_HAVE_AVX
for (; i < len - 3; i += 4) {
_mm256_store_ps((float *) &dst[i], _mm256_load_ps((float *) &src[i]));
}
#endif /* LV_HAVE_AVX */
#ifdef LV_HAVE_SSE
for (; i < len - 1; i += 2) {
_mm_store_ps((float *) &dst[i], _mm_load_ps((float *) &src[i]));
}
for (; i < len; i++) {
((__m64*) dst)[i] = ((__m64*) src)[i];
}
#else
for (; i < len; i++) {
dst[i] = src[i];
}
#endif /* LV_HAVE_SSE */
} }

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save