# floating point precision

Hi all,

Luobin had found a potential problem with floating-point precision.
When summing up a collection of floating-point numbers, the result
obtained from using GPUs differs from that from the CPUs.

Is anyone experiencing similar problems?

Steve

It probably does unless you know what you’re doing in both cases. If you use standard floating point arithmetic on the CPU, it’s actually 80-bit floating point. Also, if you didn’t compile with -arch sm_13 and use a GT200 to run your tests, you won’t get double precision on the GPU.

Basically it can’t be expected to match exactly unless you use very specific constraints.

Thanks for the quick reply. All we did was to generate a 1D array of floating point numbers and then sum them up.

Ordinary floating point numbers are represented with 32 bits, right? So 80 bits is more than we need and shouldn’t

that preserve the precision? The divergence widens quickly when more numbers are summed.

What are the actual magnitudes of the differences? If abs(calculated - expected) / expected <= 10^(-5), then there is nothing wrong.

If it is higher, then you are probably adding values of vastly different magnitudes. I.e. 10^12 + 1 = 10^12 in floating point. This resource has everything you need to know about why that happens (and more): http://docs.sun.com/source/806-3568/ncg_goldberg.html
{"ft_lang_label":"__label__en","ft_lang_prob":0.9148733,"math_prob":0.94210577,"size":1582,"snap":"2022-27-2022-33","text_gpt3_token_len":356,"char_repetition_ratio":0.12040558,"word_repetition_ratio":0.264,"special_character_ratio":0.2250316,"punctuation_ratio":0.116504855,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9820103,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-07-05T13:39:47Z\",\"WARC-Record-ID\":\"<urn:uuid:64bf185d-5821-4f06-b216-685a7d44f239>\",\"Content-Length\":\"28661\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:1c589a5f-4c23-4552-9e17-f49aeb2d7241>\",\"WARC-Concurrent-To\":\"<urn:uuid:cde100d7-4f64-496f-81a3-a9aa0c55b734>\",\"WARC-IP-Address\":\"184.105.176.47\",\"WARC-Target-URI\":\"https://forums.developer.nvidia.com/t/floating-point-precision/8830\",\"WARC-Payload-Digest\":\"sha1:LDVRNNLD4EGDIHFSYTGUU5WWR7MVNSNI\",\"WARC-Block-Digest\":\"sha1:VGGES3JJD42EKBFRDFAKQVOPDITUK6WR\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-27/CC-MAIN-2022-27_segments_1656104576719.83_warc_CC-MAIN-20220705113756-20220705143756-00326.warc.gz\"}"}