我有一个C#&使用GPU(NVIDA GTX980)进行图像处理的.NET应用程序。有4个阶段,我将CPU与GPU同步(时间上没有重叠)来进行计时。但这些数字并没有加起来。
Launch()将执行GPU内核的异步启动但是同步() 将等到它完成。
发生了什么事?
public static void threshold()
{
Stopwatch watch = new Stopwatch();
watch.Start();
gpu.Lock();
dim3 block = new dim3(tileWidthBig, tileHeightBig);
dim3 grid = new dim3(Frame.width / tileWidthBig, Frame.height / tileHeightBig);
gpu.Launch(grid, block).gHistogram(gForeground, gPercentile, gInfo);
gpu.Synchronize();
tHistogram = watch.Elapsed.TotalMilliseconds;
block = new dim3(1024);
grid = new dim3(1);
gpu.Launch(grid, block).gSumHistogram(gPercentile);
gpu.Synchronize();
tHistogramSum = watch.Elapsed.TotalMilliseconds - tHistogram;
gpu.Launch(grid, block).gIQR(gPercentile, gInfo);
gpu.Synchronize();
tIQR = watch.Elapsed.TotalMilliseconds - tHistogramSum;
block = new dim3(256, 4);
grid = new dim3(Frame.width / 256, Frame.height / 4);
gpu.Launch(grid, block).gThreshold(gForeground, gMask, gInfo);
gpu.Synchronize();
tThresholdOnly = watch.Elapsed.TotalMilliseconds - tIQR;
gpu.Unlock();
watch.Stop();
tThreshold = watch.Elapsed.TotalMilliseconds;
}
答案 0 :(得分:6)
由于TotalMilliseconds不断增加&你试图找出时间点之间的差异,你需要在第二个之后减去前面差异的总和,因此:
tIQR = watch.Elapsed.TotalMillisconds - (tHistogram + tHistogramSum);
&安培;
tThresholdOnly= watch.Elapsed.TotalMillisconds - (tHistogram + tHistogramSum + tIQR);