使用事件与windows的CUDA传输定时
我正在传输多达48kb的数据块(带有固定内存),尽管cuda事件看到它以5gb/秒的速度增长,但当我们回到windows时,我们只看到一半的速度。这是不可避免的驱动程序开销,还是有办法减轻这种开销?我已经在下面的测试程序中封装了这个过程使用事件与windows的CUDA传输定时,cuda,memcpy,Cuda,Memcpy,我正在传输多达48kb的数据块(带有固定内存),尽管cuda事件看到它以5gb/秒的速度增长,但当我们回到windows时,我们只看到一半的速度。这是不可避免的驱动程序开销,还是有办法减轻这种开销?我已经在下面的测试程序中封装了这个过程 void transferUp(size_t size) { StopWatchWin timer; timer.start(); float tUpCopyStart,tUpCopyStop; cudaEvent_t sendUpStopEvent,se
void transferUp(size_t size)
{
StopWatchWin timer;
timer.start();
float tUpCopyStart,tUpCopyStop;
cudaEvent_t sendUpStopEvent,sendUpStartEvent;
checkCudaErrors(cudaEventCreate( &sendUpStartEvent ));
checkCudaErrors(cudaEventCreate( &sendUpStopEvent ));
unsigned *cpu_sending = (unsigned *)malloc(size);
checkCudaErrors(cudaHostAlloc(&cpu_sending, size*sizeof(unsigned), cudaHostAllocPortable));
unsigned *gpu_receiving;
checkCudaErrors(cudaMalloc(&gpu_receiving, size*sizeof(unsigned)));
tUpCopyStart = timer.getTime();
checkCudaErrors(cudaEventRecord(sendUpStartEvent));
checkCudaErrors(cudaMemcpyAsync(gpu_receiving, cpu_sending, size*sizeof(unsigned), cudaMemcpyHostToDevice));
checkCudaErrors(cudaEventRecord(sendUpStopEvent));
checkCudaErrors(cudaEventSynchronize(sendUpStopEvent));
tUpCopyStop = timer.getTime();
double sendTimeWindows = tUpCopyStop - tUpCopyStart;
float sendTimeCuda;
checkCudaErrors(cudaEventElapsedTime( &sendTimeCuda,sendUpStartEvent,sendUpStopEvent));
float GbSec_cuda = (size*sizeof(unsigned)/1000)/(sendTimeCuda*1000);
float GbSec_win = (size*sizeof(unsigned)/1000)/(sendTimeWindows*1000);
printf("size=%06d bytes eventTime=%.03fms windowsTime=%0.3fms cudaSpeed=%.01f gb/s winSpeed=%.01f gb/s\n",
size*sizeof(unsigned),sendTimeCuda,sendTimeWindows,GbSec_cuda,GbSec_win);
checkCudaErrors(cudaEventDestroy( sendUpStartEvent ));
checkCudaErrors(cudaEventDestroy( sendUpStopEvent ));
checkCudaErrors(cudaFreeHost(cpu_sending));
checkCudaErrors(cudaFree(gpu_receiving));
}
对这个小操作进行计时的开销超过了测量
对于小型主机->设备拷贝(例如,64K或更小),CUDA驱动程序会将数据内联到命令缓冲区中,因此即使据称是同步的memcpy调用实际上也是异步完成的。但是,代码中的
cudaEventSynchronize()
调用会强制CPU等待而不是继续执行。您是否在TCC?Tiny C编译器中运行?不,visual studio 2010。@sedona2222:TCC=Tesla Compute Cluster,Windows平台上CUDA的专用非显示驱动程序是的,我记得。但不可以,不使用它。在全PCIe带宽下,48千兆位传输将需要约6微秒(假设为8千兆位/秒)。在WDDM上发布内存复制和同步的开销大于6µs,因此您会遇到CUDA驱动程序和WDDM开销。如果您在Nsight VSE或visualprofiler中跟踪您的程序,这将很容易在时间线上看到。