# Aggressive optimizer and volatile modifier

**URL:** <https://forums.developer.nvidia.com/t/aggressive-optimizer-and-volatile-modifier/3708>\
**Category:** CUDA Programming and Performance\
**Created:** [May 14, 2008, 9:40am UTC](https://forums.developer.nvidia.com/t/aggressive-optimizer-and-volatile-modifier/3708 "2008-05-14T09:40:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fugl](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Fugl](https://forums.developer.nvidia.com/u/Fugl)\
**Post date:** [May 14, 2008, 9:40am UTC](https://forums.developer.nvidia.com/t/aggressive-optimizer-and-volatile-modifier/3708/1 "2008-05-14T09:40:33Z")

</div>

We are currently using CUDA for testing the intersection of geometric  
3D primitives and have implemented a number of algorithms for the case of  
triangle-triangle intersection tests.

A particular algorithm appears to be suffering from aggresive optimization  
by the Open64/nvopencc compiler (using the default -O3 settings).

Through inspection of mixed PTX/C-code (generated with: --opencc-options  
-LIST:source=on) it can be seen that _some_ if-else statements are  
no longer present in the listing. This has also been verified runtime as the  
branch do not work correctly although all input values are correct before  
and after the branch.

In CUDA 2.0 this can be remidied by adding a ‘volatile’ modifier to the  
local variables that the if-else statements depends on. The algorithm now  
works correctly.  
In CUDA 1.1 (which also supports the volatile modifier) this does not fix the  
problem.

Is this expected behaviour and is using the volatile modifier a good solution?  
Are there any other pitfalls we should be aware of?

Kind regards

Andreas

---

<div class="post-metadata">

**Author:** ![kristleifur](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/kristleifur/32/12055_2.png) [@kristleifur](https://forums.developer.nvidia.com/u/kristleifur)\
**Post date:** [May 15, 2008, 9:14am UTC](https://forums.developer.nvidia.com/t/aggressive-optimizer-and-volatile-modifier/3708/2 "2008-05-15T09:14:37Z")

</div>

I think I’ve been having similar problems. The volatile trick is useful information for me, at least, so thanks for that. Let’s hope we get some input on this.
