# Why numba.cuda has different results with CPU for loop?

**URL:** <https://numba.discourse.group/t/why-numba-cuda-has-different-results-with-cpu-for-loop/2479>\
**Category:** Support: How do I do ...?\
**Created:** [March 22, 2024, 3:14pm UTC](https://numba.discourse.group/t/why-numba-cuda-has-different-results-with-cpu-for-loop/2479 "2024-03-22T15:14:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BretHart](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/brethart/32/1032_2.png) [@BretHart](https://numba.discourse.group/u/BretHart)\
**Post date:** [March 22, 2024, 3:14pm UTC](https://numba.discourse.group/t/why-numba-cuda-has-different-results-with-cpu-for-loop/2479/1 "2024-03-22T15:14:41Z")

</div>

I’ve been researching on CT reconstruction these days, which is solving a linear equations Ax=b. And weighted matrix A need compute first. Because the matrix A is very large, it needs to be computed by the GPU.

I take two different methods to compute A, and their results are identical in CPU for loop. But when i change for loop to parallel in numba.cuda, the two GPU results are different, and none of them identical with CPU results.

So I’m here for your help, how can I rewrite my code to correct the GPU result.

* * *

I have used some operators and functions in cuda kernel function, including:

```auto
math.ceil()
int()
< 
!=
* / + -
**
math.cos(), math.sin()
max(), min()

```

In addition, i have two questions:

1. why result of math.ceil() is int in CPU, but float in numba.cuda?
2. cpu computation has precision problem(as below), but why cpu can get correct result finally?

```auto
-1.3 - 0.1 = -1.4000000000000001
1.3 + 0.1 = 1.4000000000000001
math.floor(-2.7755575615628914e-14) = -1

```

shoud i use round function in GPU to truncate result?

---

<div class="post-metadata">

**Author:** ![BretHart](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/brethart/32/1032_2.png) [@BretHart](https://numba.discourse.group/u/BretHart)\
**Post date:** [March 27, 2024, 11:29pm UTC](https://numba.discourse.group/t/why-numba-cuda-has-different-results-with-cpu-for-loop/2479/3 "2024-03-27T23:29:30Z")

</div>

its my fault. i forget to use atomic.add rather than + in back projection.
