Calculate run time of kernel code in OpenCL C

时光总嘲笑我的痴心妄想 提交于 2019-12-02 10:03:22
autistic

However I have been told that it is not possible to use sleep() in the kernel code.

It's not that it's not possible; it might be. I don't know. That's not really specified in C. Having said that, it's simply not a good idea to block execution of a kernel until a period of time has elapsed. Even in general purpose programming, that doesn't seem like a good idea. Your function should finish processing as soon as possible, or pass control back to the kernel so that it can find something else to do while it's waiting on idle tasks.

Also, as I said that I wish to compare the performance of my CPU and the GPUs, one of the ways to achieve that is by computing the run time of the kernel code on the various devices while if there was another way by which I could get the code to start executing on all the devices at the same time then I would just have to list the corresponding end time of execution and that would serve the purpose as well! Is it possible?

Sure, something like that... but... I'm not even sure why you think injecting sleep(10) into each task will help you; you haven't explained that here. It doesn't seem like a requirement for profiling your code (e.g. checking its speed). Have you ever heard of the XY problem? I think sleep is your Y variable, in this case.

I mentioned profiling just now. Have you learnt about profilers? They do exactly what it is you're aiming to do, except that they do it without you having to write any code. Here's a tutorial on using perf to profile the Linux kernel...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!