cancel
Showing results for 
Search instead for 
Did you mean: 

OpenCL

tgreen
Journeyman III

Re: GPU kernel has low performance if CPU has worked _before_ launch

Thanks for the hints.

Flushing did not change anything. The timing remains the same. As I described previously, I have tried different buffer flags, but it seems the current ones are actually the fastest, since the problem only worsens when I try different (valid) types.

I was originally asked for a zip to reproduce the problem, and eventually I uploaded the modified cloo demo project which does that, but I assume no one have yet had the time to try and run it? I have tried just about everything here now and it would be really interesting to learn if others experience the same behaviour with the same code.

0 Kudos
Reply
himanshu_gautam
Grandmaster

Re: GPU kernel has low performance if CPU has worked _before_ launch

Hi Thomas,

I will try your code soon.

But can you share your results of the kernelLaunch sample? Please try both AMD and NV cards, making them primary (one after the other).

Kernel launch has been slow but not as slow as 4ms. I will update you once i am able to run your code.

0 Kudos
Reply
himanshu_gautam
Grandmaster

Re: GPU kernel has low performance if CPU has worked _before_ launch

Hi,

I ran the modified cloo zip file and do find the setup time to be quite huge. But here are few possible reasons for it:

1. The kernel is run just once. GPU warm-up takes some time. The first kernel execution is also much slower than average kernel execution time. you must run the kernel several times to measure kernel launch time. Check KernelLaunch Sample for that.

2. As we are not sure, what operation is happening exactly at what time, some of the buffer transfers to GPU via PCIe may also be causing increase in launch time.

3. Cloo might have some overhead of its own.

PFA a simple OpenCL code, to get the timing information of kernel execution. This gives launch time of 80 micro seconds for the same data size as yours (10000000 uints).

tgreen
Journeyman III

Re: GPU kernel has low performance if CPU has worked _before_ launch

1. The kernel is run just once. GPU warm-up takes some time. The first kernel execution is also much slower than average kernel execution time. you must run the kernel several times to measure kernel launch time. Check KernelLaunch Sample for that.

Thanks for your reply. You have a point about the kernel needing to warm up, and that could be an issue in the cloo example. It was just that the nvidia card had a much different behavior.

You are, however, perfectly right in kernel warm up being the issue in my actual program. I did not realize that because I actually call the kernel many many times, and it was always running slower if the cpu had also been working, so I concluded that this was not the issue... but it turns out it is (or so it seems now).

My test was looping over

cpu calculate problem

GPU calculate same problem

compare results

repeat

When I removed the cpu calculation, gpu ran fast. With cpu, gpu ran slow. But only for my amd card.

By accident I now discovered that if I replaced "cpu calculate problem" with "Thread.Sleep(1100)", then the issue was exactly the same, but if I slept less than 1000ms, then the GPU was fast again.

So in conclusion... if the kernel is run again more than 1s after last run, it will start cold. That I did not know, and I have not seen it mentioned anywhere. I will close my current question and create a new one about this issue.

Thanks for all the response I have received from especially you here 🙂

0 Kudos
Reply
himanshu_gautam
Grandmaster

Re: GPU kernel has low performance if CPU has worked _before_ launch

Thomas: "By accident I now discovered that if I replaced "cpu calculate problem" with "Thread.Sleep(1100)", then the issue was exactly the same, but if I slept less than 1000ms, then the GPU was fast again"

Hmmm. That's interesting and quite possibly true. Thanks for your support. I look forward to the new questions you plan to post

EDIT: It will help me and also others if you mark the reply you find answering you issue as "correct Answer"  or "Helpful Answer".

Message was edited by: Himanshu Gautam

0 Kudos
Reply