1

I have a simple kernel which I am timing using clock(). I got to know about this function in How to measure the inner kernel time in NVIDIA CUDA?

So I have used clock_t start = clock(); (and similarly stop) to time it. On compilation, I get the following error:

tex1.cu(14): error: expression preceding parentheses of apparent call must have (pointer-to-) function type`

Am I missing a header file, or a compiler option?

Also, I tried using CUDA timers (cudaEvent_t start, stop;) but the elapsed time I get is 0 ms. I create start and stop, record start, do some CUDA stuff, synchronize, record stop, event synchronize and measure elapsed time. This part compiles fine but gives me elapsed time as zero.

It is a simple kernel that I am using to test my understanding of texture memory. The Kernel:

__global__ void magic(float *mean, int *clock){
    int i, tid = threadIdx.x + blockIdx.x * blockDim.x;
    float t, sum=0.0;
    clock_t start = clock();
    if ( tid < dimy )
    {
        for(i=0;i<dimx; i++){
            t = tex2D( input, i, tid );
            sum = sum + t*t;
        }
        clock_t stop = clock();
        clock[tid] = (int)(stop-start);
    }
}
tomix86
  • 1,336
  • 2
  • 18
  • 29
Rmj
  • 15
  • 1
  • 5

1 Answers1

4

In your kernel, don't name your kernel parameter clock as this is confusing the compiler because you have a variable named clock and a function named clock. Instead do this:

__global__ void magic(float *mean, int *myclock){

...
myclock[tid] = (int)(stop-start);
}

If you make that change, the error about the expression preceding parenthesis will go away. It's odd that you answered the question about whether you have any other variables called clock or start with no, because you have both.

If you would like help with your usage of cuda events, please post the actual code you are using for timing. Are you doing error checking on all cuda calls and kernel calls?

Robert Crovella
  • 143,785
  • 11
  • 213
  • 257
  • How to measure it in milisecond? – ericmoraess Apr 30 '14 at 19:32
  • read the [previous linked question and answers](http://stackoverflow.com/questions/10585990/how-how-to-measure-the-inner-kernel-time-in-nvidia-cuda) carefully. – Robert Crovella Apr 30 '14 at 19:36
  • GPU clock frequencies can be retrieved using [NVML](https://developer.nvidia.com/gpu-deployment-kit) or directly using the CUDA runtime or driver API. Take a look at the [deviceQuery sample](http://docs.nvidia.com/cuda/cuda-samples/index.html#device-query). – Robert Crovella Apr 30 '14 at 20:13