Skip to content

Commit

Permalink
Cuda: Write cuFFT errors to the Log
Browse files Browse the repository at this point in the history
  • Loading branch information
M. Sallermann authored and M. Sallermann committed May 20, 2021
1 parent 3cfb43f commit a010ea0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
15 changes: 8 additions & 7 deletions core/include/engine/FFT.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define FFT_H
#include <Eigen/Core>
#include <data/Geometry.hpp>
#include <utility/Logging.hpp>
#include <engine/Vectormath_Defines.hpp>
#include <iostream>
#include <complex>
Expand All @@ -25,7 +26,7 @@
#include <cufft.h>
#endif

namespace Engine
namespace Engine
{
namespace FFT
{
Expand Down Expand Up @@ -84,7 +85,7 @@ namespace Engine
FFT_cpx_type res;
res[0] = d1[0] * s1[0] + d2[0] * s2[0] + d3[0] * s3[0] - d1[1] * s1[1] - d2[1] * s2[1] - d3[1] * s3[1];
res[1] = d1[0] * s1[1] + d2[0] * s2[1] + d3[0] * s3[1] + d1[1] * s1[0] + d2[1] * s2[0] + d3[1] * s3[0];
return res;
return res;
}

inline void addTo(FFT_cpx_type & a, const FFT_cpx_type & b, bool overwrite)
Expand Down Expand Up @@ -112,7 +113,7 @@ namespace Engine
FFT_cpx_type res;
res.x = d1.x * s1.x + d2.x * s2.x + d3.x * s3.x - d1.y * s1.y - d2.y * s2.y - d3.y * s3.y;
res.y = d1.x * s1.y + d2.x * s2.y + d3.x * s3.y + d1.y * s1.x + d2.y * s2.x + d3.y * s3.x;
return res;
return res;
}

inline __device__ void addTo(FFT_cpx_type & a, const FFT_cpx_type & b, bool overwrite = false)
Expand All @@ -135,7 +136,7 @@ namespace Engine
fftw_plan_with_nthreads(omp_get_max_threads());
#endif
}

inline void get_strides(field<int*> & strides, const field<int> & maxVal)
{
strides.resize(maxVal.size());
Expand Down Expand Up @@ -173,7 +174,7 @@ namespace Engine

//Constructor delegation
FFT_Plan() : FFT_Plan({2,2,2}, true, 1, 8)
{}
{}

FFT_Plan(std::vector<int> dims, bool inverse, int n_transforms, int len) :
dims(dims),
Expand All @@ -187,7 +188,7 @@ namespace Engine
}

//copy constructor
FFT_Plan(FFT_Plan const & other)
FFT_Plan(FFT_Plan const & other)
{
this->dims = other.dims;
this->inverse = other.inverse;
Expand Down Expand Up @@ -219,7 +220,7 @@ namespace Engine
}
return *this;
}

//move assignment operator
FFT_Plan& operator=(FFT_Plan const && other)
{
Expand Down
31 changes: 26 additions & 5 deletions core/src/engine/FFT.cu
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,29 @@ namespace Engine
{
std::cerr << "NOT IMPLEMENTED FOR cuFFT" << std::endl;
}

void iFour_3D(FFT_cfg cfg, FFT_cpx_type * in, FFT_real_type * out)
{
std::cerr << "NOT IMPLEMENTED FOR cuFFT" << std::endl;
}

void batch_Four_3D(FFT_Plan & plan)
{
cufftExecR2C(plan.cfg, plan.real_ptr.data(), plan.cpx_ptr.data());
auto res = cufftExecR2C(plan.cfg, plan.real_ptr.data(), plan.cpx_ptr.data());
if(res != CUFFT_SUCCESS)
{
Log(Utility::Log_Level::Error, Utility::Log_Sender::All, fmt::format("cufftExecR2C failed with error: {}", res));
}
cudaDeviceSynchronize();
}

void batch_iFour_3D(FFT_Plan & plan)
{
cufftExecC2R(plan.cfg, plan.cpx_ptr.data(), plan.real_ptr.data());
auto res = cufftExecC2R(plan.cfg, plan.cpx_ptr.data(), plan.real_ptr.data());
if(res != CUFFT_SUCCESS)
{
Log(Utility::Log_Level::Error, Utility::Log_Sender::All, fmt::format("cufftExecC2R failed with error: {}", res));
}
cudaDeviceSynchronize();
}

Expand All @@ -47,16 +56,28 @@ namespace Engine

if(this->inverse == false)
{
cufftPlanMany(&this->cfg, rank, n, inembed, istride, idist, onembed, ostride, odist, CUFFT_R2C, n_transforms);
auto res = cufftPlanMany(&this->cfg, rank, n, inembed, istride, idist, onembed, ostride, odist, CUFFT_R2C, n_transforms);
if(res != CUFFT_SUCCESS)
{
Log(Utility::Log_Level::Error, Utility::Log_Sender::All, fmt::format("cufftPlanMany failed with error: {}", res));
}
} else
{
cufftPlanMany(&this->cfg, rank, n, inembed, istride, idist, onembed, ostride, odist, CUFFT_C2R, n_transforms);
auto res = cufftPlanMany(&this->cfg, rank, n, inembed, istride, idist, onembed, ostride, odist, CUFFT_C2R, n_transforms);
if(res != CUFFT_SUCCESS)
{
Log(Utility::Log_Level::Error, Utility::Log_Sender::All, fmt::format("cufftPlanMany failed with error: {}", res));
}
}
}

void FFT_Plan::Free_Configuration()
{
cufftDestroy(this->cfg);
auto res = cufftDestroy(this->cfg);
if(res != CUFFT_SUCCESS)
{
Log(Utility::Log_Level::Error, Utility::Log_Sender::All, fmt::format("cufftDestroy failed with error: {}", res));
}
}
}
}
Expand Down

0 comments on commit a010ea0

Please sign in to comment.