Support for NaN?

Apr 1, 2013 at 10:05 PM

I've been experimenting a bit with CUDAfy and have seen great things so far. One thing I'm having trouble figuring out is how to work with NaN inside a CUDAfy function.

If I have any function that I tag with a [CUDAfy] tag, using Double.NaN or Double.IsNaN() cause a compilation error when the CudafyTranslator.Cudafy() call gets made.

When using Double.NaN the error is "identifier 'NaN' is undefined", when using Double.IsNaN(), it's "identifier 'IsNaN' is undefined"

I've tried finding special types or methods in the CUDAfy libraries but haven't had any luck. Is there a special way to do this, or is NaN simply not supported with CUDAfy?

Apr 5, 2013 at 1:43 PM
These properties are not supported for translation. CUDA has a isnan method (and isinf and isfinite) but this has not been added yet.
Apr 5, 2013 at 6:17 PM
Edited Apr 5, 2013 at 6:26 PM
as a quick fix, you can always do the following:
    public static int isnan(double a)
        return double.IsNaN(a) ? 1 : 0;
and add to your output folder an empty text file named

now you can simply use isnan(...) in your cudafy code. Example:
    public static void nantest(GThread th, double a, int[] res)
        res[0] = isnan(a);
P.S. My laptop gpu is only 1.1, so I only tested it with floats. It should work with doubles since, memory-wise, a NaN double representation is invariant between nvidia gpu <-> cpu.