Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add experimental cuFFT support. #587

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 29 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ option(ENABLE_TIDY "Enable clang tidy" OFF)

option(USE_LTE_RATES "Use standard LTE sampling rates" OFF)
option(USE_MKL "Use MKL instead of fftw" OFF)
option(USE_CUDA "Use cuFFT instead of fftw (experimental)" OFF)

option(ENABLE_TIMEPROF "Enable time profiling" ON)

Expand Down Expand Up @@ -129,25 +130,34 @@ endif()
# Threads
find_package(Threads REQUIRED)

# FFT
if(USE_MKL)
find_package(MKL REQUIRED)
include_directories(${MKL_INCLUDE_DIRS})
link_directories(${MKL_LIBRARY_DIRS})
set(FFT_LIBRARIES "${MKL_STATIC_LIBRARIES}") # Static by default
else(USE_MKL)
find_package(FFTW3F REQUIRED)
if(FFTW3F_FOUND)
include_directories(${FFTW3F_INCLUDE_DIRS})
link_directories(${FFTW3F_LIBRARY_DIRS})
if(BUILD_STATIC)
set(FFT_LIBRARIES "${FFTW3F_STATIC_LIBRARIES}")
else(BUILD_STATIC)
set(FFT_LIBRARIES "${FFTW3F_LIBRARIES}")
endif(BUILD_STATIC)
message(STATUS "FFT_LIBRARIES: " ${FFT_LIBRARIES})
endif(FFTW3F_FOUND)
endif(USE_MKL)
# CUDA
if(USE_CUDA)
find_package(CUDA REQUIRED)
include_directories(${CUDA_INCLUDE_DIRS})
add_definitions("-DUSE_CUFFTW")
set(FFT_LIBRARIES cufftw)
message(STATUS "FFT_LIBRARIES: " ${FFT_LIBRARIES})
else()
# FFT
if(USE_MKL)
find_package(MKL REQUIRED)
include_directories(${MKL_INCLUDE_DIRS})
link_directories(${MKL_LIBRARY_DIRS})
set(FFT_LIBRARIES "${MKL_STATIC_LIBRARIES}") # Static by default
else(USE_MKL)
find_package(FFTW3F REQUIRED)
if(FFTW3F_FOUND)
include_directories(${FFTW3F_INCLUDE_DIRS})
link_directories(${FFTW3F_LIBRARY_DIRS})
if(BUILD_STATIC)
set(FFT_LIBRARIES "${FFTW3F_STATIC_LIBRARIES}")
else(BUILD_STATIC)
set(FFT_LIBRARIES "${FFTW3F_LIBRARIES}")
endif(BUILD_STATIC)
message(STATUS "FFT_LIBRARIES: " ${FFT_LIBRARIES})
endif(FFTW3F_FOUND)
endif(USE_MKL)
endif()

# Crypto
find_package(Polarssl)
Expand Down
4 changes: 4 additions & 0 deletions lib/include/srslte/phy/dft/dft.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ SRSLTE_API int srslte_dft_plan_guru_c(srslte_dft_plan_t* plan,
int idist,
int odist);

#ifndef USE_CUFFTW
SRSLTE_API int srslte_dft_plan_r(srslte_dft_plan_t* plan, int dft_points, srslte_dft_dir_t dir);
#endif

SRSLTE_API int srslte_dft_replan(srslte_dft_plan_t* plan, const int new_dft_points);

Expand All @@ -98,7 +100,9 @@ SRSLTE_API int srslte_dft_replan_guru_c(srslte_dft_plan_t* plan,

SRSLTE_API int srslte_dft_replan_c(srslte_dft_plan_t* plan, int new_dft_points);

#ifndef USE_CUFFTW
SRSLTE_API int srslte_dft_replan_r(srslte_dft_plan_t* plan, int new_dft_points);
#endif

SRSLTE_API void srslte_dft_plan_free(srslte_dft_plan_t* plan);

Expand Down
24 changes: 24 additions & 0 deletions lib/src/phy/dft/dft_fftw.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@

#include "srslte/srslte.h"
#include <complex.h>
#ifdef USE_CUFFTW
#include <cufftw.h>
#else
#include <fftw3.h>
#endif
#include <math.h>
#include <pwd.h>
#include <string.h>
Expand All @@ -33,6 +37,8 @@
#define dft_ceil(a, b) ((a - 1) / b + 1)
#define dft_floor(a, b) (a / b)

#ifndef USE_CUFFTW

#define FFTW_WISDOM_FILE "%s/.srslte_fftwisdom"

static int get_fftw_wisdom_file(char* full_path, uint32_t n)
Expand All @@ -45,6 +51,8 @@ static int get_fftw_wisdom_file(char* full_path, uint32_t n)
return snprintf(full_path, n, FFTW_WISDOM_FILE, homedir);
}

#endif

#ifdef FFTW_WISDOM_FILE
#define FFTW_TYPE FFTW_MEASURE
#else
Expand All @@ -61,8 +69,10 @@ __attribute__((constructor)) static void srslte_dft_load()
get_fftw_wisdom_file(full_path, sizeof(full_path));
fftwf_import_wisdom_from_filename(full_path);
#else
#ifndef USE_CUFFTW
printf("Warning: FFTW Wisdom file not defined\n");
#endif
#endif
}

// This function is called in the ending of any executable where it is linked
Expand All @@ -82,7 +92,12 @@ int srslte_dft_plan(srslte_dft_plan_t* plan, const int dft_points, srslte_dft_di
if (mode == SRSLTE_DFT_COMPLEX) {
return srslte_dft_plan_c(plan, dft_points, dir);
} else {
#ifndef USE_CUFFTW
return srslte_dft_plan_r(plan, dft_points, dir);
#else
ERROR("srslte_dft_plan_r: R2R not available in cuFFTW.\n");
return 0;
#endif
}
return 0;
}
Expand All @@ -93,7 +108,12 @@ int srslte_dft_replan(srslte_dft_plan_t* plan, const int new_dft_points)
if (plan->mode == SRSLTE_DFT_COMPLEX) {
return srslte_dft_replan_c(plan, new_dft_points);
} else {
#ifndef USE_CUFFTW
return srslte_dft_replan_r(plan, new_dft_points);
#else
ERROR("srslte_dft_replan_r: R2R not available in cuFFTW.\n");
return 0;
#endif
}
} else {
ERROR("DFT: Error calling replan: new_dft_points (%d) must be lower or equal "
Expand Down Expand Up @@ -228,6 +248,8 @@ int srslte_dft_plan_c(srslte_dft_plan_t* plan, const int dft_points, srslte_dft_
return 0;
}

#ifndef USE_CUFFTW

int srslte_dft_replan_r(srslte_dft_plan_t* plan, const int new_dft_points)
{
int sign = (plan->dir == SRSLTE_DFT_FORWARD) ? FFTW_R2HC : FFTW_HC2R;
Expand Down Expand Up @@ -272,6 +294,8 @@ int srslte_dft_plan_r(srslte_dft_plan_t* plan, const int dft_points, srslte_dft_
return 0;
}

#endif

void srslte_dft_plan_set_mirror(srslte_dft_plan_t* plan, bool val)
{
plan->mirror = val;
Expand Down