Discussion:
[CUDPP][1116] Potential Unsafe Floating-point to Unsigned Int Casting
Wei-Fan Chiang
2015-03-10 22:46:59 UTC
Permalink
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*
https://github.com/cudpp/cudpp/blob/master/apps/cudpp_testrig/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,
the similar casting code used in *rand_cta.cu*
https://github.com/cudpp/cudpp/blob/master/src/cudpp/cta/rand_cta.cuh is
safe:

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
--
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+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/cudpp.
For more options, visit https://groups.google.com/d/optout.
John Owens
2015-03-13 03:28:12 UTC
Permalink
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
Post by Wei-Fan Chiang
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*
https://github.com/cudpp/cudpp/blob/master/apps/cudpp_testrig/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,
the similar casting code used in *rand_cta.cu <http://rand_cta.cu>*
https://github.com/cudpp/cudpp/blob/master/src/cudpp/cta/rand_cta.cuh is
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
--
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
Visit this group at http://groups.google.com/group/cudpp.
For more options, visit https://groups.google.com/d/optout.
--
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+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/cudpp.
For more options, visit https://groups.google.com/d/optout.
Loading...