【问题标题】:inconsistent timing from .net StopWatch来自.net StopWatch 的时间不一致
【发布时间】:2015-09-09 10:59:30
【问题描述】:

我有一个使用 GPU (NVIDA GTX980) 进行图像处理的 C# 和 .NET 应用程序。有 4 个阶段,我将 CPU 与 GPU 同步(时间上没有重叠)来进行计时。但数字不加起来。

Launch() 将异步启动 GPU 内核)但 synchronize() 会等到它完成。

  1. 总计: tThreshold:4.2827ms

  • 直方图:3.7714ms
  • tHistogramSum: 0.1065ms
  • tIQR:3.8603ms
  • tThresholdOnly:0.4126ms

发生了什么事?

   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;
    }

【问题讨论】:

  • 您是在问为什么 4 个值加起来不等于总数吗?如果是这样的话,你就错了一些基本的算术逻辑......
  • 不应该 tIQR = TotalMillisconds - (tHistogram + tHistogramSum) & tThresholdOnly 类似地减去先前值的总和。

标签: c# .net timing stopwatch cudafy.net


【解决方案1】:

由于 TotalMilliseconds 不断增加并且您试图找到时间点之间的差异,因此您需要在第二个差异之后减去前面差异的总和,因此:

tIQR = watch.Elapsed.TotalMillisconds - (tHistogram + tHistogramSum);

&

tThresholdOnly= watch.Elapsed.TotalMillisconds - (tHistogram + tHistogramSum + tIQR);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-21
    • 2023-03-17
    • 2015-06-21
    • 2012-10-30
    • 1970-01-01
    • 2011-09-04
    相关资源
    最近更新 更多