在CUDA中使用clock()函数 [英] Using clock() function in CUDA

查看:1009
本文介绍了在CUDA中使用clock()函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的内核,我使用clock()计时。
我在

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

所以我使用了
clock_t start = clock(); (同样停止)来计时。在编译时,我得到以下错误:

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:明显调用的括号之前的表达式必须有-to-)function type`

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?

此外,我尝试使用CUDA计时器( cudaEvent_t start,stop; ),但我得到的经过时间为0毫秒。我创建开始和停止,记录开始,做一些cuda东西,同步,记录停止,事件同步和测量经过的时间。这部分编译精细,但给我经过的时间为零。

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


推荐答案

t命名你的内核参数 clock ,因为这会让编译器混乱,因为你有一个名为 clock 的变量, code> clock 。而是这样做:

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

如果进行此更改, 。
很奇怪,你回答了关于你是否有任何其他变量叫做clock或者以no开头的问题,因为你有两者

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.

如果您需要帮助您使用cuda事件,请张贴您正在使用的实际代码来计时。您对所有cuda调用和内核调用执行错误检查?

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?

这篇关于在CUDA中使用clock()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆