# Emulation/CPU=correct,Execution/GPU=incorrect emulation

**URL:** <https://forums.developer.nvidia.com/t/emulation-cpu-correct-execution-gpu-incorrect-emulation/5190>\
**Category:** CUDA Programming and Performance\
**Created:** [August 26, 2008, 5:39pm UTC](https://forums.developer.nvidia.com/t/emulation-cpu-correct-execution-gpu-incorrect-emulation/5190 "2008-08-26T17:39:44Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![chrismc](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@chrismc](https://forums.developer.nvidia.com/u/chrismc)\
**Post date:** [September 1, 2008, 10:31am UTC](https://forums.developer.nvidia.com/t/emulation-cpu-correct-execution-gpu-incorrect-emulation/5190/21 "2008-09-01T10:31:27Z")

</div>

> [@](#):
>
> Not necessarily. At the moment I have only one thread perform one function while the rest wait (I haven’t yet thought how that function can be parallelised). I though the lack of syncthreads would be shown in the emulation anyway.
> 
> \_\_syncthreads synchronises threads in a block, not in a warp, is that correct? BUt threads are executed in warps ie groups of 32?
> 
> So when working with 400 threads/particles in 1 block and I place a \_\_syncthreads call after a function call in a kernel, not one thread should pass that \_\_syncthreads until all other 399 have reached that particular \_\_syncthreads? So with a maximum of 128 threads executing concurrently on a C870, ie 4 warps, with 400 threads not all threads are being computed concurrently.
> 
> I’ll try multiples of warps on both machines. I expect something interesting to happen with 5 warps.
> 
> [snapback]432808[/snapback]

results from both the parallel machine and the C870 agree upto and including 6 warps, but from 7 warps onwards the results from the C870 show unexpected behaviour while the parallel machine results are as expected.

Plus there is an unexpected performance gain at warps\>=7, in that the execution time drops dramatically from seconds to fractions of a millisecond.

Any suggestions?

---

<div class="post-metadata">

**Author:** ![E.D\_Riedijk](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@E.D\_Riedijk](https://forums.developer.nvidia.com/u/E.D_Riedijk)\
**Post date:** [September 1, 2008, 12:49pm UTC](https://forums.developer.nvidia.com/t/emulation-cpu-correct-execution-gpu-incorrect-emulation/5190/22 "2008-09-01T12:49:00Z")

</div>

check for errors after your kernel launch, you probably have to many registers for 7 warps per block. I think you are experiencing a too many resources requested error.

---

<div class="post-metadata">

**Author:** ![chrismc](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@chrismc](https://forums.developer.nvidia.com/u/chrismc)\
**Post date:** [September 1, 2008, 12:58pm UTC](https://forums.developer.nvidia.com/t/emulation-cpu-correct-execution-gpu-incorrect-emulation/5190/23 "2008-09-01T12:58:05Z")

</div>

> [@](#):
>
> check for errors after your kernel launch, you probably have to many registers for 7 warps per block. I think you are experiencing a too many resources requested error.
> 
> [snapback]433952[/snapback]

I’m beginning to suspect it could be something like that.

How do I check for the error you mention? From the example projects I have in my code

////////////////////////////////////

// Launch the device computation

SPH\<\<\<dimGrid, dimBlock\>\>\>(//variables);

CUT\_CHECK\_ERROR(“kernel error”);

////////////////////////////////////

Do I need to write something else?

---

<div class="post-metadata">

**Author:** ![theMarix](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/themarix/32/12058_2.png) [@theMarix](https://forums.developer.nvidia.com/u/theMarix)\
**Post date:** [September 1, 2008, 2:37pm UTC](https://forums.developer.nvidia.com/t/emulation-cpu-correct-execution-gpu-incorrect-emulation/5190/24 "2008-09-01T14:37:19Z")

</div>

Try to cudaThreadSynchronize before checking for the error value. (Actually cudaThreadSynchronize will report the error if there is one.)

---

<div class="post-metadata">

**Author:** ![cbuchner1](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/cbuchner1/32/14168_2.png) [@cbuchner1](https://forums.developer.nvidia.com/u/cbuchner1)\
**Post date:** [September 1, 2008, 9:57pm UTC](https://forums.developer.nvidia.com/t/emulation-cpu-correct-execution-gpu-incorrect-emulation/5190/25 "2008-09-01T21:57:07Z")

</div>

I just tripped over the fact that \_\_sinf only works within [-pi, pi] whereas in Emu mode it works correctly at all times. Similarly with \_\_cosf, I suppose. This screwed over my Hough Transform. ;)

---

<div class="post-metadata">

**Author:** ![alex\_dubinsky](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@alex\_dubinsky](https://forums.developer.nvidia.com/u/alex_dubinsky)\
**Post date:** [September 1, 2008, 10:14pm UTC](https://forums.developer.nvidia.com/t/emulation-cpu-correct-execution-gpu-incorrect-emulation/5190/26 "2008-09-01T22:14:37Z")

</div>

> [@](#):
>
> ////////////////////////////////////
> 
> // Launch the device computation
> 
> SPH\<\<\<dimGrid, dimBlock\>\>\>(//variables);
> 
> CUT\_CHECK\_ERROR(“kernel error”);
> 
> ////////////////////////////////////
> 
> Do I need to write something else?
> 
> [snapback]433956[/snapback]

Don’t forget to run in Debug mode. Check the custom build step of the sample in case anything doesn’t work.

---

<div class="post-metadata">

**Author:** ![Sylvain\_Collange](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Sylvain\_Collange](https://forums.developer.nvidia.com/u/Sylvain_Collange)\
**Post date:** [September 2, 2008, 5:01pm UTC](https://forums.developer.nvidia.com/t/emulation-cpu-correct-execution-gpu-incorrect-emulation/5190/27 "2008-09-02T17:01:35Z")

</div>

> [@](#):
>
> I just tripped over the fact that \_\_sinf only works within [-pi, pi]Â&nbsp; whereas in Emu mode it works correctly at all times. Similarly with \_\_cosf, I suppose. This screwed over my Hough Transform. ;)
> 
> [snapback]434167[/snapback]

More precisely, the **absolute** error of \_\_sinf and \_\_cosf is only guaranteed within [-pi, pi]. Outside this range, it will be less accurate, but still usable for most purposes (well, maybe not yours!)

You can think of \_\_sinf(x) as behaving much like sinf(fmodf(x, (float)TWO\_PI)). Only for very large inputs it will give a completely wrong answer in absolute terms.

But even inside [-pi, pi], CPU implementations can be much more accurate than \_\_sinf and \_\_cosf, if accurate means a smaller **relative** error (think \_\_sinf(x) when x is very close to 0).

[Previous page](https://forums.developer.nvidia.com/t/emulation-cpu-correct-execution-gpu-incorrect-emulation/5190.md?page=1)
