[SOLVED] Crash with CUDA math trigonometric functions and OptiX

Hello,

I am trying to create a path tracing algorithm using OptiX, but I have recently encountered a strange issue.
I use CUDA intrinsics such as sqrtf, cosf and sinf for my BRDF computations. But, whereas sqrtf seems to works well in every case, when cosf or sinf (or every trigonometric functions for that matter) is called with an argument that is different than a locally defined variable, the program crashes.

Example :

float random = curand_uniform(&state);
float z = 2 * PI;
float y = sqrtf(random);
float test = cosf(lambda);                                        //If you test them  
float test = cosf(debug_buffer[launch_index].data.x);             //one at a time
float test = cosf(kd);                                            //they all cause
float test = cosf(y);                                             //the program to crash
float test = cosf(z);                                              //The only one that does not crash

rtPrintf("random is in %p\n", random);
rtPrintf("z is in %p\n", z);
rtPrintf("y is in %p\n", y);
rtPrintf("lambda (context variable) is in %p\n", lambda);
rtPrintf("debug buffer data for this launch index is in %p\n", debug_buffer[launch_index].data.x);
rtPrintf("kd (program variable) is in %p\n", kd);

Result :

random is in 3F9C7D0A40000000
z is in 401921FB40000000
y is in 3FC5598E20000000
lambda (context variable) is in 4010000000000000
debug buffer data for this launch index is in 3FE99999A0000000
kd (program variable) is in 3FF0000000000000

I was thinking of a memory address issue, but difficult to pinpoint precisely the problem. The offending variables can be read, written with no problem whatsoever outside of this case (at least to my knowledge).
Any hindsight?

I use OptiX 3.5.1 and CUDA 5.5
Windows 7 Pro SP1 64bit
GTX780 3GB with drivers 337.88

Do you have some more information in the kind of crash you observe?

Please always add OS version, OS bitness, installed GPUs, and display driver version along with the OptiX and CUDA versions when reporting issues.

Are you using the nvcc command line parameter --use_fast_math when compiling your CUDA *.cu sources to PTX?

OptiX 3.6.0 with CUDA 6.0 and Maxwell support is available on the same location where you downloaded OptiX 3.5.1. Definitely worth a try.

I added the information about OS and driver in the last post.
I am also using Visual Studio 2012.

I do not have more information in the kind of crash I observe. I dont know exactly how I could get some. It is always the same error message when the program crash, about “Access violation reading location 0x00000000000010” that I get everytime something is wrong with the way I set up or write the OptiX programs.

I tried with both --use_fast_math and without. Both cause the same issue.

I do not see where to download OptiX 3.6.0. Last time, I took the survey for applying to be a registered developer, and got a link to download it. Now, when I go to the same page, I am redirected directly to the page congratulating me for having already taken the survey, and nothing else happens.
I do remember receiving a mail informing me of the pending release of OptiX 3.6.0 a while back, but I am afraid the mail got deleted. Do I have to contact NVIDIA, or is there another way to get access to this version?

Do you still have the mail containing the link you used to download OptiX last time?
The same link should now give you access to OptiX 3.6.0.

Found it.
Downloading now. I will try it out and tell you.

If you haven’t got the download information anymore, please contact the OptiX team with via the e-mail you’ll find inside the OptiX release notes from your e-mail with which you registered last time. They can look up your registration and resend the informaiton. It said “keep it safe” for a reason.

To your original problem, that could be anything like using a nullptr + 16 bytes offset as read address.
When running it inside the debugger and it crashes, in which module is the access violation happening?
Do you have a call stack at that point?

Just for isolation, does the same happen when removing all rtPrintf() calls?

I’ve never experienced any issues with cosf() and sinf() in OptiX. I’m using MSVS 2010 though.

I tried OptiX 3.6.0 with CUDA 6.0, but the same problem is still happening. It should also be noted that every function in optixu/optixu_math_namespace.h that relies on those function also crashes. ( for example cosine_sample_hemisphere ).

Here is the Call Stack I get when the program crashes :

optix.1.dll!000007fee675ffef()	Unknown
 	optix.1.dll!000007fee6848086()	Unknown
 	optix.1.dll!000007fee684895d()	Unknown
 	optix.1.dll!000007fee68a67c3()	Unknown
 	optix.1.dll!000007fee68a7bb4()	Unknown
 	optix.1.dll!000007fee68969a9()	Unknown
 	optix.1.dll!000007fee68a0f69()	Unknown
 	optix.1.dll!000007fee6897006()	Unknown
 	optix.1.dll!000007fee692bd51()	Unknown
 	optix.1.dll!000007fee690a003()	Unknown
>	FloconDeNeigeOptiX.exe!main(int argc, char * * argv) Line 117	C++
 	FloconDeNeigeOptiX.exe!__tmainCRTStartup() Line 536	C
 	kernel32.dll!00000000771b59ed()	Unknown
 	ntdll.dll!00000000772ec541()	Unknown

And here is the output in the console :

First-chance exception at 0x000007FEFD3C940D in FloconDeNeigeOptiX.exe: Microsoft C++ exception: optix::shared::AssertionFailure at memory location 0x000000000020DE90.
First-chance exception at 0x000007FEFD3C940D in FloconDeNeigeOptiX.exe: Microsoft C++ exception: optix::shared::AssertionFailure at memory location 0x000000000020DE90.
First-chance exception at 0x000007FEE675FFEF (optix.1.dll) in FloconDeNeigeOptiX.exe: 0xC0000005: Access violation reading location 0x0000000000000010.

It seems it is the optix.1.dll module that causes the crash.
The rtPrintf() have no impact. There is nothing in my program except this line of code, and it still fails.

Another thing to note, the program does not even need to be called to cause the application to crash. Right now, this computation is done inside a material program, and after removing all the rtTrace() calls, the program still crashes.

When I look at the declaration of cosf, it leads me to this file :
c:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\math.h
Which might not be part of CUDA… But it is also the sqrtf function from this same file that I use and which works fine with every type of variable.

***EDIT
I tried using __cosf instead of cosf to be sure of using the CUDA version but, while it compiles and runs, it simply returns nonsense (actually it seems to always return the same value).

Not sure if that’s relevant, but I’ve been facing some similar trouble with cosf and sinf : https://devtalk.nvidia.com/default/topic/735307/optix/strange-error-while-reading-a-ptx-file/

The problem was that VS2010 wasn’t actually using the --fast-math option even if it was told to do so.

Thank you HamzaC, it actually solves the issue :)
For future person having the same problem, add --use_fast_math to the additional options box in the CUDA C/C++ command line.

But I am left to wonder why this issue exists. Is it a problem of VS, from OptiX, or from another source?

You’re welcome :)

I guess it comes from VS and/or the integration of CUDA in VS.
I don’t know if it still happens with CUDA 6 under VS 2013.

Dear HamzaC!

Sorry for aside question. Do you use VS2013 really?
Is the work inside VS2013 similar to work in VS2010 or in 2012? I work in VS2010, can’t install (no permission) VS2012 but I wish to try so called “OptiX project wizard”.
Probably I use wrong terms.

sudak

Hi sudak,

I’m using VS2013 but my current work does not involve OptiX and I was using VS2010 before. So for the moment, I have never tried the OptiX wizard.
I’ve been manually setting the compilation options for the PTX files, which does the job. I guess the problem will be that you won’t be able to use the MSVC 2013 compiler since CUDA 6.0 does not support it.

Thank you, HamzaC!

That sounds sad as Nvidia spent efforts for MSVS 2012 while MSoft issued VS 2013.

You can use VS 2013 with the 2012 toolchain (v110). That is what I do; I haven’t had any issues.