与VS2010/Cuda4.2相比,VS2013/Cuda7.0中的CUFFT慢1000倍
CUFFT is 1000x slower in VS2013/Cuda7.0 compared to VS2010/Cuda4.2
这个简单的CUFFT代码在两个IDE上运行-
- VS 2013与Cuda 7.0
- VS 2010与Cuda 4.2
我发现使用Cuda 7.0的VS 2013的1000
大约慢了一倍。代码在VS 2010的0.6 ms
中执行,在VS 2013的520 ms
中执行,两者平均而言。
#include "stdafx.h"
#include "cuda.h"
#include "cuda_runtime_api.h"
#include "cufft.h"
typedef cuComplex Complex;
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cudaEvent_t start, stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);
cudaEventRecord(start);
const int SIZE = 10000;
Complex *h_col = (Complex*)malloc(SIZE*sizeof(Complex));
for (int i = 0; i < SIZE; i++)
{
h_col[i].x = i;
h_col[i].y = i;
}
Complex *d_col;
cudaMalloc((void**)&d_col, SIZE*sizeof(Complex));
cudaMemcpy(d_col, h_col, SIZE*sizeof(Complex), cudaMemcpyHostToDevice);
cufftHandle plan;
const int BATCH = 1;
cufftPlan1d(&plan, SIZE, CUFFT_C2C, BATCH);
cufftExecC2C(plan, d_col, d_col, CUFFT_FORWARD);
cudaMemcpy(h_col, d_col, SIZE*sizeof(Complex), cudaMemcpyDeviceToHost);
cudaEventRecord(stop);
cudaEventSynchronize(stop);
float milliseconds = 0;
cudaEventElapsedTime(&milliseconds, start, stop);
cufftDestroy(plan);
cout << milliseconds;
return 0;
}
代码在同一台计算机上运行,使用相同的操作系统,相同的显卡,并且立即一个接一个地运行。这两种情况下的配置都是x64版本。您可以选择是使用C++编译器还是使用CUDA C/C++编译文件。我在这两个项目上都尝试了两种选择,但没有什么不同。
有什么解决办法吗?
FWIW,我在VS 2013上获得了与Cuda 7 相同的Cuda 6.5结果
从4.2到7.0,cufft库变得相当大,这导致了更多的初始化时间。如果你去掉这个初始化时间的因素,我想你会发现执行时间的差异将远远小于1000倍。
这里有一个修改后的代码来演示这一点:
$ cat t807.cu
#include <cufft.h>
#include <cuComplex.h>
typedef cuComplex Complex;
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
cudaEvent_t start, stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);
cudaEventRecord(start);
const int SIZE = 10000;
Complex *h_col = (Complex*)malloc(SIZE*sizeof(Complex));
for (int i = 0; i < SIZE; i++)
{
h_col[i].x = i;
h_col[i].y = i;
}
Complex *d_col;
cudaMalloc((void**)&d_col, SIZE*sizeof(Complex));
cudaMemcpy(d_col, h_col, SIZE*sizeof(Complex), cudaMemcpyHostToDevice);
cufftHandle plan;
const int BATCH = 1;
cufftPlan1d(&plan, SIZE, CUFFT_C2C, BATCH);
cufftExecC2C(plan, d_col, d_col, CUFFT_FORWARD);
cudaMemcpy(h_col, d_col, SIZE*sizeof(Complex), cudaMemcpyDeviceToHost);
cudaEventRecord(stop);
cudaEventSynchronize(stop);
float milliseconds = 0;
cudaEventElapsedTime(&milliseconds, start, stop);
cufftDestroy(plan);
cout << milliseconds << endl;
cudaEventRecord(start);
for (int i = 0; i < SIZE; i++)
{
h_col[i].x = i;
h_col[i].y = i;
}
cudaMemcpy(d_col, h_col, SIZE*sizeof(Complex), cudaMemcpyHostToDevice);
cufftPlan1d(&plan, SIZE, CUFFT_C2C, BATCH);
cufftExecC2C(plan, d_col, d_col, CUFFT_FORWARD);
cudaMemcpy(h_col, d_col, SIZE*sizeof(Complex), cudaMemcpyDeviceToHost);
cudaEventRecord(stop);
cudaEventSynchronize(stop);
milliseconds = 0;
cudaEventElapsedTime(&milliseconds, start, stop);
cufftDestroy(plan);
cout << milliseconds << endl;
return 0;
}
$ nvcc -o t807 t807.cu -lcufft
$ ./t807
94.8298
1.44778
$
上面的第二个数字表示基本上相同的代码,去掉了cufft初始化(因为它是在第一次通过时完成的)。
相关文章:
- 将成员变量添加到共享库中的类中,不会破坏二进制兼容性吗
- .cpp和.h文件中的模板专用化声明
- 反向给定链表中的K节点
- 正在查找文档以获得PS4平台的C++中的设备信息
- enum是C++中的宏变量还是整数变量
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 将字符串存储在c++中的稳定内存中
- 文本文件中的单词链表
- 递归函数计算序列中的平方和(并输出过程)
- 如何从C++中的依赖类型中获得它所依赖的类型
- C++中的"inline"关键字
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 用C++中的一个变量定义一个常量
- vector.resize()中的分配错误
- 使用指针从C++中的数组中获取最大值
- arr[-1]在c++中的奇怪行为
- 具有奇怪重复模板模式的派生类中的成员变量已损坏
- 将值指定给向量(2D)的向量中的某个位置
- 与VS2010/Cuda4.2相比,VS2013/Cuda7.0中的CUFFT慢1000倍