Division Operator in CUDA Toolkit 4.0

I’ve been having some issues using the division operator “/” within my CUDA kernel, and I couldn’t find another post discussing the issue. Basically, the problem is that using the operator within any line of code within my kernel will cause the kernel to be terminated at that line when run. This behavior only popped up after switching from CUDA runtime 3.2 with VS 2008 to CUDA runtime 4.0 with VS 2010.

Am I doing something wrong? Here are a couple examples of lines that will cause the kernel to terminate.

int variable = (double) array[number] / number;
cos(number * number / number)

I actually have yet to try using the division operator within strictly integer operations, as these two are within double operations. So ill try that and see if that works, but if it does, then what operator do I use for division for double operations.

Thanks in advance.

Are you sure that you do not have “number” being zero in some thread?

Another thing to verify is that if number is a valid index for “array”.

Thanks for the quick reply. No, its not a divide by zero issue. The first line uses a constant 32767, and the second line never has a zero in the denominator either. As for the valid index, that’s also not the issue as I’ve tried both lines separately and they both fail by themselves.

Also, I’ve tried what I was talking about at the end of my first post. And it looks like that it blows up when I try to use the division operator in the middle of some double operations.

For example,

This works:
double fun = fun1 / fun2; (where both fun1 and fun2 are integers, fun1 and fun2 are 1 and 2 respectively, result of this is 0)

while this doesnt:
double fun = (double) fun1 / fun2; (result of this should be .5)

Also within the cos operation there is no explicit double cast, so it just looks like it blows up when I try to use the division operator in the midst of double operations.

What am I supposed to use instead?



Do you have a device with capability > 1.3?

I am not sure about it, but when I am about to do this kind of operation

double fun = (double) fun1 / fun2

I used to cast both the nominator and denominator or I use in the following form

double fun = (double) ( fun1 / fun2 )

in order to assure that the cast will be done on the result of the integer division.

double fun = (double) (fun1/fun2) would result in zero in that case, which is not what I want. I will try double casting both of them, but again, this problem occurs within the cosine operation as well where there is no double cast.

As for my CC, its 2.0, I have a gtx580, and I’ve also set compute_20 and sm_20. I had this code working perfectly in 3.2, well not perfectly, it was blowing up this mod operation within the double operations, so I had to separate the mod operation and save it to a variable, but other than that, I had no issues in 3.2.

That is odd. I suggest you to report this as a bug in https://nvdeveloper.nvidia.com/. Maybe there is something wrong with the compiler.

Ok Ill do that. Thanks for the help

Actually, I just tried it with a float, and it worked. Hmm…

Looks like your code is not being compiled for double precision support. I found this link


Take a look at Explanation section where there is a problem reported when using double pointers with math functions.

Try to check the compiler flags to see if there anything missing.