# Problem to use Asynchronous execution with PBO

**URL:** <https://forums.developer.nvidia.com/t/problem-to-use-asynchronous-execution-with-pbo/2876>\
**Category:** CUDA Programming and Performance\
**Created:** [March 4, 2008, 11:33am UTC](https://forums.developer.nvidia.com/t/problem-to-use-asynchronous-execution-with-pbo/2876 "2008-03-04T11:33:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![spacerat](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@spacerat](https://forums.developer.nvidia.com/u/spacerat)\
**Post date:** [March 4, 2008, 11:33am UTC](https://forums.developer.nvidia.com/t/problem-to-use-asynchronous-execution-with-pbo/2876/1 "2008-03-04T11:33:06Z")

</div>

I am trying to optimize may raycaster and found a couple of difficulties - I hope somebody can give me a good advice.

I seems the driver always stalls making CUDA calls. I always get framerates like 60,30,20,15,12,… but there is nothing in between, it basically snaps.

(Its not the VSync - I already switched that off)

I guess the problem is that I was not using the Asynchronous versions with events.

I therefore modified everything and found another problem which I guess could be a driver bug or undocumented problem…

If I want to use a mapped PBO along with the async code, the GPU seems to be doing nothing.

* * *

Here what happens without PBO’s:

* * *

```auto
...

asyncAPI_test()

...

```

Result:OK

time spent executing by the GPU: 181.57

time spent by CPU in CUDA calls: 0.11

CPU executed 354 iterations while waiting for GPU to finish

Test PASSED

* * *

Here what happens with PBO’s:

* * *

```auto
...

CUDA_SAFE_CALL(cudaGLMapBufferObject( (void**)&out_data, pbo_out));   

asyncAPI_test()

CUDA_SAFE_CALL(cudaGLUnmapBufferObject( pbo_out));

...

```

Result:Failed

Test FAILED

time spent executing by the GPU: 0.00

time spent by CPU in CUDA calls: 2.19

CPU executed 0 iterations while waiting for GPU to finish

any help is appreciated…

regards

---

<div class="post-metadata">

**Author:** ![wumpus](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/wumpus/32/12040_2.png) [@wumpus](https://forums.developer.nvidia.com/u/wumpus)\
**Post date:** [March 4, 2008, 11:54am UTC](https://forums.developer.nvidia.com/t/problem-to-use-asynchronous-execution-with-pbo/2876/2 "2008-03-04T11:54:08Z")

</div>

I do know that OpenGL calls always cause an implicit synchronisation when switching context (like when using CUDA), so using async calls together with OpenGL interoperability is only of limited use.

---

<div class="post-metadata">

**Author:** ![spacerat](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@spacerat](https://forums.developer.nvidia.com/u/spacerat)\
**Post date:** [March 4, 2008, 11:59am UTC](https://forums.developer.nvidia.com/t/problem-to-use-asynchronous-execution-with-pbo/2876/3 "2008-03-04T11:59:58Z")

</div>

> [@](#):
>
> I do know that OpenGL calls always cause an implicit synchronisation when switching context (like when using CUDA), so using async calls together with OpenGL interoperability is only of limited use.
> 
> [snapback]337442[/snapback]

Um… does it means it is impossible ?

Or is there any other possiblity to change the driver’s synchronization behavior?

It seems that there is an internal waiting loop synchronized to 60 fps…

I just want to get optimal performance.

---

<div class="post-metadata">

**Author:** ![wumpus](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/wumpus/32/12040_2.png) [@wumpus](https://forums.developer.nvidia.com/u/wumpus)\
**Post date:** [March 4, 2008, 12:09pm UTC](https://forums.developer.nvidia.com/t/problem-to-use-asynchronous-execution-with-pbo/2876/4 "2008-03-04T12:09:03Z")

</div>

Well I mean that you can do it, it just doesn’t help performance.

But the 60fps number is strange, CUDA shouldn’t lock it to a certain number of frames per second. I’ve had much higher fps rates with CUDA-using opengl programs.

---

<div class="post-metadata">

**Author:** ![spacerat](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@spacerat](https://forums.developer.nvidia.com/u/spacerat)\
**Post date:** [March 4, 2008, 12:43pm UTC](https://forums.developer.nvidia.com/t/problem-to-use-asynchronous-execution-with-pbo/2876/5 "2008-03-04T12:43:51Z")

</div>

> [@](#):
>
> Well I mean that you can do it, it just doesn’t help performance.
> 
> But the 60fps number is strange, CUDA shouldn’t lock it to a certain number of frames per second. I’ve had much higher fps rates with CUDA-using opengl programs.
> 
> [snapback]337445[/snapback]

Hm… its not just my program. In the SDK examples there is already a fluid demo that is showing the FPS. In my case its always 60.8 even I reduce the number of particles to a fraction of the original amount.

The strange thing is now: Once I start dragging the console window accross the GL-Window, the framerate increases from 60.8 up to 97 fps … ???

The only thing I can guess is that the synchronization is done event based and each times an event (like whatever) occurs, the synchronization checks if the GPU is done…

---

<div class="post-metadata">

**Author:** ![spacerat](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@spacerat](https://forums.developer.nvidia.com/u/spacerat)\
**Post date:** [March 4, 2008, 1:06pm UTC](https://forums.developer.nvidia.com/t/problem-to-use-asynchronous-execution-with-pbo/2876/6 "2008-03-04T13:06:32Z")

</div>

I just found out that in my case, already keeping a key pushed leads to a higher framerate … Its really an event-problem.

Is it possible to generate fake-key events e.g. in a timer loop ?

---

<div class="post-metadata">

**Author:** ![MisterAnderson42](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@MisterAnderson42](https://forums.developer.nvidia.com/u/MisterAnderson42)\
**Post date:** [March 4, 2008, 2:58pm UTC](https://forums.developer.nvidia.com/t/problem-to-use-asynchronous-execution-with-pbo/2876/7 "2008-03-04T14:58:56Z")

</div>

What event system are you using?

In windows you usually do these things in the Idle event. I seem to recall there being a return value that controlled how long it will be until the next idle event.
