1

I have a C# & .NET application that uses a GPU (NVIDA GTX980) to do image processing. There are 4 stages and I synch the CPU to the GPU (no overlap in time) to do timing. But the numbers do not add up.

Launch() will do a async launch of the GPU kernel) but synchronize() will wait till it is done.

  1. Total: tThreshold: 4.2827ms

  • tHistogram: 3.7714ms
  • tHistogramSum: 0.1065ms
  • tIQR: 3.8603ms
  • tThresholdOnly: 0.4126ms

What is going on?

   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;
    }
Dr.YSG
  • 7,171
  • 22
  • 81
  • 139
  • 1
    Are you just asking why the 4 values don't add up to the total? There's some basic arithmetic logic you've got wrong if that's the case... – James Thorpe Jun 23 '15 at 15:02
  • shouldn't tIQR = TotalMillisconds - (tHistogram + tHistogramSum) & tThresholdOnly similary subtract sum of previous values. – PaulF Jun 23 '15 at 15:02

1 Answers1

6

As the TotalMilliseconds is constantly incrementing & you are trying to find differences between points in time, you need to subtract the sum of the preceding differences after the second one, hence :

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

&

tThresholdOnly= watch.Elapsed.TotalMillisconds - (tHistogram + tHistogramSum + tIQR);
PaulF
  • 6,673
  • 2
  • 18
  • 29