实现OpenCL的Ç睡眠() [英] Implement sleep() in OpenCL C
问题描述
我要测量不同装置即CPU和GPU的性能。
这是我的内核code:
I want to measure the performance of different devices viz CPU and GPUs. This is my kernel code:
__kernel void dataParallel(__global int* A)
{
sleep(10);
A[0]=2;
A[1]=3;
A[2]=5;
int pnp;//pnp=probable next prime
int pprime;//previous prime
int i,j;
for(i=3;i<10;i++)
{
j=0;
pprime=A[i-1];
pnp=pprime+2;
while((j<i) && A[j]<=sqrt((float)pnp))
{
if(pnp%A[j]==0)
{
pnp+=2;
j=0;
}
j++;
}
A[i]=pnp;
}
}
然而,睡眠()
功能不起作用。我收到以下错误buildlog:
However the sleep()
function doesnt work. I am getting the following error in buildlog:
<kernel>:4:2: warning: implicit declaration of function 'sleep' is invalid in C99
sleep(10);
builtins: link error: Linking globals named '__gpu_suld_1d_i8_trap': symbol multiply defined!
有没有实现功能的任何其他方式。也就是有没有办法记录执行这个code段所花费的时间。
Is there any other way to implement the function. Also is there a way to record the time taken to execute this code snippet.
P.S 我已经包括的#include&LT; unistd.h中方式&gt;
在我的主机code
P.S. I have included #include <unistd.h>
in my host code.
推荐答案
您不需要使用睡在你的内核来衡量的执行时间。
You dont need to use sleep in your kernel to measure the execution time.
有测量时间两种方式。
1.使用OpenCL的内在剖析
看看这里: CL API
There are two ways to measure the time. 1. Use opencl inherent profiling look here: cl api
得到您的主机code时间戳和前执行后对它们进行比较。
例如:
get timestamps in your hostcode and compare them before and after execution. example:
double start = getTimeInMS();
//The kernel starts here
clEnqueueNDRangeKernel(command_queue, kernel, 1, NULL, &tasksize, &local_size_in, 0, NULL, NULL)
//wait for kernel execution
clFinish(command_queue);
cout << "kernel execution time " << (getTimeInMS() - start) << endl;
在哪里getTimeinMs()是返回毫秒的双重价值的函数:
(窗口具体,覆盖与其他实施,如果你不使用Windows)
Where getTimeinMs() is a function that returns a double value of miliseconds: (windows specific, override with other implementation if you dont use windows)
static inline double getTimeInMS(){
SYSTEMTIME st;
GetLocalTime(&st);
return (double)st.wSecond * (double)1000 + (double)st.wMilliseconds;}
另外要:
#include <time.h>
对于Mac这将是(可以在Linux上工作,以及,不知道):
For Mac it would be (could work on Linux as well, not sure):
static inline double getTime() {
struct timeval starttime;
gettimeofday(&starttime, 0x0);
return (double)starttime.tv_sec * (double)1000 + (double)starttime.tv_usec / (double)1000;}
这篇关于实现OpenCL的Ç睡眠()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!