From f5f1ee186eed3de5516ed568a89d2bd8446a8642 Mon Sep 17 00:00:00 2001 From: ismagom Date: Mon, 3 Mar 2014 21:01:04 +0000 Subject: [PATCH] Added VOLK support --- CMakeLists.txt | 4 +-- cmake/modules/FindVolk.cmake | 29 +++++++++++++++ examples/mib_track.c | 68 ++++++++++++++++++------------------ lte/lib/CMakeLists.txt | 18 +++++++++- lte/lib/utils/src/vector.c | 16 ++++----- 5 files changed, 89 insertions(+), 46 deletions(-) create mode 100644 cmake/modules/FindVolk.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 411885780..d1389040e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,8 +51,8 @@ SET(DATA_DIR share/${CPACK_PACKAGE_NAME}) IF(NOT CMAKE_BUILD_TYPE) - SET(CMAKE_BUILD_TYPE "Release") - MESSAGE(STATUS "Build type not specified: defaulting to release.") + SET(CMAKE_BUILD_TYPE Release) + MESSAGE(STATUS "Build type not specified: defaulting to Release.") ENDIF(NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "") diff --git a/cmake/modules/FindVolk.cmake b/cmake/modules/FindVolk.cmake new file mode 100644 index 000000000..3da43592d --- /dev/null +++ b/cmake/modules/FindVolk.cmake @@ -0,0 +1,29 @@ +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(PC_VOLK volk QUIET) + +FIND_PATH( + VOLK_INCLUDE_DIRS + NAMES volk.h + HINTS $ENV{VOLK_DIR}/include/volk + ${CMAKE_INSTALL_PREFIX}/include/volk + ${PC_VOLK_INCLUDE_DIR} + PATHS /usr/local/include/volk + /usr/include/volk +) + +FIND_LIBRARY( + VOLK_LIBRARIES + NAMES volk + HINTS $ENV{VOLK_DIR}/lib + ${CMAKE_INSTALL_PREFIX}/lib + ${CMAKE_INSTALL_PREFIX}/lib64 + ${PC_VOLK_LIBDIR} + PATHS /usr/local/lib + /usr/local/lib64 + /usr/lib + /usr/lib64 +) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(VOLK DEFAULT_MSG VOLK_LIBRARIES VOLK_INCLUDE_DIRS) +MARK_AS_ADVANCED(VOLK_LIBRARIES VOLK_INCLUDE_DIRS) diff --git a/examples/mib_track.c b/examples/mib_track.c index f33a7cdf7..d41c7df83 100644 --- a/examples/mib_track.c +++ b/examples/mib_track.c @@ -154,6 +154,18 @@ int base_init(int frame_length) { if (filesource_init(&fsrc, input_file_name, COMPLEX_FLOAT_BIN)) { return -1; } + } else { + /* open UHD device */ + #ifndef DISABLE_UHD + printf("Opening UHD device...\n"); + if (cuhd_open(uhd_args,&uhd)) { + fprintf(stderr, "Error opening uhd\n"); + return -1; + } + #else + printf("Error UHD not configured. Select an input file\n"); + return -1; + #endif } input_buffer = (cf_t*) malloc(frame_length * sizeof(cf_t)); @@ -193,26 +205,18 @@ int base_init(int frame_length) { return -1; } - /* open UHD device */ -#ifndef DISABLE_UHD - printf("Opening UHD device...\n"); - if (cuhd_open(uhd_args,&uhd)) { - fprintf(stderr, "Error opening uhd\n"); - return -1; - } -#endif return 0; } void base_free() { int i; -#ifndef DISABLE_UHD - cuhd_close(&uhd); -#endif - if (input_file_name) { filesource_free(&fsrc); + } else { + #ifndef DISABLE_UHD + cuhd_close(&uhd); + #endif } sync_free(&sfind); @@ -280,6 +284,7 @@ int main(int argc, char **argv) { int nslot; pbch_mib_t mib; float cfo; + int n; int nof_found_mib = 0; parse_args(argc,argv); @@ -292,11 +297,20 @@ int main(int argc, char **argv) { sync_pss_det_peakmean(&sfind); sync_pss_det_peakmean(&strack); -#ifndef DISABLE_UHD - INFO("Setting sampling frequency %.2f MHz\n", (float) SAMP_FREQ/MHZ); - cuhd_set_rx_srate(uhd, SAMP_FREQ); - cuhd_set_rx_gain(uhd, uhd_gain); -#endif + if (!input_file_name) { + #ifndef DISABLE_UHD + INFO("Setting sampling frequency %.2f MHz\n", (float) SAMP_FREQ/MHZ); + cuhd_set_rx_srate(uhd, SAMP_FREQ); + cuhd_set_rx_gain(uhd, uhd_gain); + /* set uhd_freq */ + cuhd_set_rx_freq(uhd, (double) uhd_freq); + cuhd_rx_wait_lo_locked(uhd); + DEBUG("Set uhd_freq to %.3f MHz\n", (double) uhd_freq); + + DEBUG("Starting receiver...\n",0); + cuhd_start_rx_stream(uhd); + #endif + } state = FIND; nslot = 0; @@ -308,21 +322,8 @@ int main(int argc, char **argv) { sync_set_threshold(&sfind, find_threshold); sync_force_N_id_2(&sfind, -1); -#ifndef DISABLE_UHD - /* set uhd_freq */ - cuhd_set_rx_freq(uhd, (double) uhd_freq); - cuhd_rx_wait_lo_locked(uhd); - DEBUG("Set uhd_freq to %.3f MHz\n", (double) uhd_freq); - - DEBUG("Starting receiver...\n",0); - cuhd_start_rx_stream(uhd); -#endif - while(frame_cnt < nof_frames || nof_frames==-1) { INFO(" ----- RECEIVING %d SAMPLES ---- \n", FLEN); -#ifndef DISABLE_UHD - cuhd_recv(uhd, input_buffer, FLEN, 1); -#else if (input_file_name) { n = filesource_read(&fsrc, input_buffer, FLEN); if (n == -1) { @@ -333,11 +334,10 @@ int main(int argc, char **argv) { filesource_read(&fsrc, input_buffer, FLEN); } } else { - fprintf(stderr, "UHD is DISABLED but input file name not specified\n"); - usage(argv[0]); - exit(-1); + #ifndef DISABLE_UHD + cuhd_recv(uhd, input_buffer, FLEN, 1); + #endif } -#endif switch(state) { case FIND: diff --git a/lte/lib/CMakeLists.txt b/lte/lib/CMakeLists.txt index 5f4be9ed0..6d3888e69 100644 --- a/lte/lib/CMakeLists.txt +++ b/lte/lib/CMakeLists.txt @@ -25,8 +25,15 @@ ######################################################################## FIND_PACKAGE(FFTW3F REQUIRED) # TODO: distribute kissfft instead -include_directories(${FFTW3F_INCLUDE_DIRS}) +INCLUDE_DIRECTORIES(${FFTW3F_INCLUDE_DIRS}) +IF(${DISABLE_VOLK}) + IF(${DISABLE_VOLK} EQUAL 0) + FIND_PACKAGE(Volk) + ENDIF(${DISABLE_VOLK} EQUAL 0) +ELSE(${DISABLE_VOLK}) + FIND_PACKAGE(Volk) +ENDIF(${DISABLE_VOLK}) ######################################################################## # Recurse subdirectories and compile all source files into the same lib @@ -46,6 +53,15 @@ TARGET_LINK_LIBRARIES(lte m ${FFTW3F_LIBRARIES}) INSTALL(TARGETS lte DESTINATION ${LIBRARY_DIR}) LIBLTE_SET_PIC(lte) +IF(VOLK_FOUND) + INCLUDE_DIRECTORIES(${VOLK_INCLUDE_DIRS}) + SET_TARGET_PROPERTIES(lte PROPERTIES COMPILE_DEFINITIONS "HAVE_VOLK") + TARGET_LINK_LIBRARIES(lte ${VOLK_LIBRARIES}) + MESSAGE(STATUS " Compiling with VOLK SIMD library.") +ELSE(VOLK_FOUND) + MESSAGE(STATUS " VOLK SIMD library NOT found. Using generic implementation.") +ENDIF(VOLK_FOUND) + diff --git a/lte/lib/utils/src/vector.c b/lte/lib/utils/src/vector.c index e45c5b477..1fb0c55fe 100644 --- a/lte/lib/utils/src/vector.c +++ b/lte/lib/utils/src/vector.c @@ -31,8 +31,6 @@ #include #include -//#define HAVE_VOLK - #ifdef HAVE_VOLK #include "volk/volk.h" #endif @@ -56,7 +54,7 @@ float vec_acc_ff(float *x, int len) { return z; #else float result; - volk_32f_accumulator_s32f_a(&result,x,(unsigned int) len); + volk_32f_accumulator_s32f_u(&result,x,(unsigned int) len); return result; #endif } @@ -94,7 +92,7 @@ void vec_sc_prod_cfc(cf_t *x, float h, cf_t *z, int len) { cf_t hh; __real__ hh = h; __imag__ hh = 0; - volk_32fc_s32fc_multiply_32fc_a(z,x,hh,(unsigned int) len); + volk_32fc_s32fc_multiply_32fc_u(z,x,hh,(unsigned int) len); #endif } @@ -105,7 +103,7 @@ void vec_sc_prod_ccc(cf_t *x, cf_t h, cf_t *z, int len) { z[i] = x[i]*h; } #else - volk_32fc_s32fc_multiply_32fc_a(z,x,h,(unsigned int) len); + volk_32fc_s32fc_multiply_32fc_u(z,x,h,(unsigned int) len); #endif } @@ -170,7 +168,7 @@ void vec_conj_cc(cf_t *x, cf_t *y, int len) { y[i] = conjf(x[i]); } #else - volk_32fc_conjugate_32fc_a(y,x,(unsigned int) len); + volk_32fc_conjugate_32fc_u(y,x,(unsigned int) len); #endif } @@ -181,7 +179,7 @@ void vec_prod_ccc(cf_t *x,cf_t *y, cf_t *z, int len) { z[i] = x[i]*y[i]; } #else - volk_32fc_x2_multiply_32fc_a(z,x,y,(unsigned int) len); + volk_32fc_x2_multiply_32fc_u(z,x,y,(unsigned int) len); #endif } @@ -220,7 +218,7 @@ void vec_abs_cf(cf_t *x, float *abs, int len) { abs[i] = cabsf(x[i]); } #else - volk_32fc_magnitude_32f_a(abs,x,(unsigned int) len); + volk_32fc_magnitude_32f_u(abs,x,(unsigned int) len); #endif @@ -240,7 +238,7 @@ int vec_max_fi(float *x, int len) { return p; #else unsigned int target=0; - volk_32f_index_max_16u_a(&target,x,(unsigned int) len); + volk_32f_index_max_16u_u(&target,x,(unsigned int) len); return (int) target; #endif }