NAN in ftp

54 views
Skip to first unread message

david.c...@crg.es

unread,
Apr 13, 2015, 5:30:05 AM4/13/15
to rei...@googlegroups.com
Hi Bogdan,

I've seen in the mako of the fft that you use NaN like


// This does not change the performance, but
// makes it much easier to catch bugs in addressing.
%for i in range(temp_array_size):
a[${i}] = complex_ctr(NAN, NAN);
%endfor

while CUDA does not understand NaN
error: identifier "NAN" is undefined

I've noticed it long time ago and solved it by defining NaN in the compiler (I think I put it somewhere in PyCUDA), but what is the purpose of using it? and is there any elegant way of defining NaN within reikna or python and pass it to the compiler?

Thanks in advance

David

Bogdan Opanchuk

unread,
Apr 13, 2015, 8:21:27 PM4/13/15
to rei...@googlegroups.com
Hi David,

That's weird, I've never had a problem with this constant in CUDA; just checked it now, works on CUDA 7. NAN is a C constant, maybe its availability is platform-specific or something? Which OS are you using? Perhaps I can replace NAN by a more CUDA-specific CUDART_NAN.

As for why it is there - it is mostly a debugging measure; this way if the local memory is accessed incorrectly, there won't be subtle numeric errors, but NaNs all over the place. Also some platforms require the array to be initialized with something (I think it was AMD OpenCL).

Best regards,
Bogdan

david.c...@crg.es

unread,
Apr 14, 2015, 2:37:55 AM4/14/15
to rei...@googlegroups.com
Hi Bogdan,

I tested in several windows 7 installations with CUDA 6 and CUDA 7 and always get that NAN is undefined. Maybe you have defined it by default on compilation.

I've seen posts where other users also state that NAN does not exist in CUDA, like:
http://stackoverflow.com/questions/15514286/way-to-get-floating-point-special-values-in-cuda
https://devtalk.nvidia.com/default/topic/416483/?comment=2911487

Regards

David

Bogdan Opanchuk

unread,
Apr 14, 2015, 2:48:49 AM4/14/15
to rei...@googlegroups.com
Hi David,

I'm sure I didn't define it anywhere, and neither did PyCUDA. Perhaps it's an OS dependent undocumented thing (I'm using OSX and Linux). There's no big problem in replacing it with CUDART_NAN when CUDA is used. Do you have the same problem with OpenCL, by the way?

david.c...@crg.es

unread,
Apr 14, 2015, 3:14:00 AM4/14/15
to rei...@googlegroups.com
Hi,

Strange, indeed. I've just tested now with OpenCL and it does not complain, only with CUDA.

Regards

David

Bogdan Opanchuk

unread,
Apr 16, 2015, 2:46:38 AM4/16/15
to rei...@googlegroups.com
Hi David,

Could you check that adding the following at the start of reikna/fft/fft.mako works:

#ifdef CUDA
#ifndef NAN
#include <math_constants.h>
%if dtypes.is_double(dtype):
#define NAN CUDART_NAN
%else:
#define NAN CUDART_NAN_F
%endif
#endif
#endif

If it does, I'll add it to the library.

david.c...@crg.es

unread,
Apr 21, 2015, 7:28:51 AM4/21/15
to rei...@googlegroups.com
Hi Bogdan,

I checked and works correctly in both CUDA and OpenCL.

Thank you for the effort

David
Reply all
Reply to author
Forward
0 new messages