我正在尝试确定 Microsoft C++ 异常的来源:
First-chance exception at 0x770ab9bc in test_fft.exe: Microsoft C++ exception: cudaError_enum at memory location 0x016cf234...
我的构建环境是:
- IDE:Microsoft Visual C++ 2010 Express
- NVIDIA 驱动程序:301.27
- CUDA:NVIDIA CUDA 工具包 v4.2(32 位)
- SDK:NVIDIA GPU 计算 SDK 4.2(32 位)
问题范围:我试图将 CUFFT 包装在 C++ 类后面。这样我就可以隐藏从一种数据类型到 cufftComplex 的转换、FFT 的执行和来自调用代码的内存传输。
类标题:
#ifndef SIGNAL_PROCESSING_FFT_HPP
#define SIGNAL_PROCESSING_FFT_HPP
#include "signal_processing\types.hpp"
#include <boost/cstdint.hpp>
#include <cufft.h>
#include <vector>
namespace signal_processing {
class FFT {
public:
FFT ( boost::uint32_t size );
virtual ~FFT();
void forward ( ComplexVectorT const& input, ComplexVectorT& output );
void reverse ( ComplexVectorT const& input, ComplexVectorT& output );
private:
cufftComplex* m_device_data;
cufftComplex* m_host_data;
cufftHandle m_plan;
boost::uint32_t m_size;
};
}
#endif // SIGNAL_PROCESSING_FFT_HPP
FFT构造函数:
FFT::FFT ( boost::uint32_t size )
: m_size ( size )
{
CudaSafeCall ( cudaMalloc((void**)&m_device_data, sizeof(cufftComplex) * m_size ) );
m_host_data = (cufftComplex*) malloc ( m_size * sizeof(cufftComplex) );
CufftSafeCall ( cufftPlan1d ( &m_plan, m_size, CUFFT_C2C, 1 ) );
}
在调用 cudaMalloc 的第一行的 FFT 构造函数中抛出了 Microsoft C++ 异常。如果我使用 FFT 类和 Visual Studio 调试器运行代码,似乎只会发生此错误。
引用资料
CudaSafeCall 定义
#define CudaSafeCall(err) __cudaSafeCall ( err, __FILE__, __LINE__ )
__cudaSafeCall 定义
inline void __cudaSafeCall ( cudaError err, const char* file, const int line )
{
#ifdef CUDA_ERROR_CHECK
if ( cudaSuccess != err )
{
std::cerr << boost::format ( "cudaSafeCall() failed at %1$s:%2$i : %3$s\n" )
% file
% line
% cudaGetErrorString ( err );
exit(-1);
}
#endif
return;
}
最佳答案
您所做的观察与在 CUDA 库中正确捕获和处理的异常有关。在某些情况下,它是 CUDA GPU 操作的正常部分。我相信您的应用程序在这种情况下不会返回任何 API 错误。如果您不在可以报告这一点的 VS 环境中,您根本不会观察到这一点。
这被认为是 CUDA 下的正常行为。我相信有一些尝试在 CUDA 5.5 中消除它。您可能希望尝试一下,尽管这两种方式都不是问题。
关于c++ - 无法找到异常源 : cudaError_enum at memory location,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10952742/