Potential Unsafe Floating-point to Unsigned Int Casting

12 views
Skip to first unread message

Wei-Fan Chiang

unread,
Mar 10, 2015, 9:13:31 PM3/10/15
to cu...@googlegroups.com, Ganesh Gopalakrishnan, Zvonimir Rakamaric
Dear CUDPP developers, 

My name is Wei-Fan Chiang, and I am currently a PhD student of School of Computing at University of Utah. 
We (my colleague and me) are currently interesting in unsafe type casting detection for GPU programs. 

In the current version of CUDPP in Github (https://github.com/cudpp/cudpp), 
I suspect that there are some potential unsafe type castings (specifically, floating-point to unsigned int casting) in file rand_gold.cpp 

In functions FF, GG, HH, and II, 
there are type castings shown as follows. 

float = sin((float)(i)) * p;
unsigned int trigFunc = (unsigned int)(t);

To my best knowledge, such floating-point-to-unsigned-int casting is unsafe: the casting result is undefined when t is negative or greater than the maximum value of unsigned int. 

In contrast, 

float t = sin(__int_as_float(i))* p;
unsigned int trigFunc = __float2uint_rd(t);  

I wonder that whether rand_gold.cpp is used in any routines provided by CUDPP or it is just for testing CUDPP? 

Thanks.

Regards, 
- Wei-Fan

John Owens

unread,
Mar 12, 2015, 11:28:13 PM3/12/15
to cu...@googlegroups.com
The "gold" files run only on the CPU and are only used to generate CPU results for comparison with GPU results. So we might have an incorrect cast (and would be happy to incorporate any patches you may submit!), but I don't believe this typecast affects any code that runs on the GPU.

JDO

--
You received this message because you are subscribed to the Google Groups "CUDPP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cudpp+un...@googlegroups.com.
To post to this group, send email to cu...@googlegroups.com.
Visit this group at http://groups.google.com/group/cudpp.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages