Rmj
Rmj

Reputation: 15

Using clock() function in CUDA

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

Upvotes: 1

Views: 8219

Answers (1)

Robert Crovella
Robert Crovella

Reputation: 151799

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?

Upvotes: 4

Related Questions