# synchronous kernel calls?

**URL:** <https://forums.developer.nvidia.com/t/synchronous-kernel-calls/22208>\
**Category:** CUDA Programming and Performance\
**Created:** [April 28, 2011, 3:44pm UTC](https://forums.developer.nvidia.com/t/synchronous-kernel-calls/22208 "2011-04-28T15:44:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![xrismf](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@xrismf](https://forums.developer.nvidia.com/u/xrismf)\
**Post date:** [April 28, 2011, 3:44pm UTC](https://forums.developer.nvidia.com/t/synchronous-kernel-calls/22208/1 "2011-04-28T15:44:49Z")

</div>

Hello,

I was wondering if there is a way to execute kernel calls synchronously, so I might safely call kernels like this:

```auto
void function() {

    while(i<N) {

        kernel1<<<>>>();

        kernel2<<<>>>();

    }

}

```

Kind Regards

edit: cudaThreadSynchronize() or cudaGetLastError() do not seem to work for me…

---

<div class="post-metadata">

**Author:** ![mfatica](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@mfatica](https://forums.developer.nvidia.com/u/mfatica)\
**Post date:** [April 28, 2011, 3:57pm UTC](https://forums.developer.nvidia.com/t/synchronous-kernel-calls/22208/2 "2011-04-28T15:57:34Z")

</div>

Kernel2 will not start unless kernel1 is completed, if they are in the same stream.

---

<div class="post-metadata">

**Author:** ![xrismf](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@xrismf](https://forums.developer.nvidia.com/u/xrismf)\
**Post date:** [April 28, 2011, 4:29pm UTC](https://forums.developer.nvidia.com/t/synchronous-kernel-calls/22208/3 "2011-04-28T16:29:01Z")

</div>

Ok, then there must be some other reason for my problem. If I run the function as above, parts of the matrix I am calculating are NaN. If I outcomment one of the kernels, or set N to a small number, the results are fine. I do not use shared memory and there is not one division inside one of the kernels so I am out of my wits what might even cause NaN?

---

<div class="post-metadata">

**Author:** ![avidday](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/avidday/32/59219_2.png) [@avidday](https://forums.developer.nvidia.com/u/avidday)\
**Post date:** [April 28, 2011, 7:44pm UTC](https://forums.developer.nvidia.com/t/synchronous-kernel-calls/22208/4 "2011-04-28T19:44:09Z")

</div>

It might well be the case that the Nan values are coming from uninitialised memory. Either because you code is reading out of bounds, or because the code isn’t actually running to completion, leaving some of the output memory untouched.

---

<div class="post-metadata">

**Author:** ![tmurray](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@tmurray](https://forums.developer.nvidia.com/u/tmurray)\
**Post date:** [April 28, 2011, 7:49pm UTC](https://forums.developer.nvidia.com/t/synchronous-kernel-calls/22208/5 "2011-04-28T19:49:26Z")

</div>

check your errors.

---

<div class="post-metadata">

**Author:** ![xrismf](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@xrismf](https://forums.developer.nvidia.com/u/xrismf)\
**Post date:** [April 28, 2011, 8:39pm UTC](https://forums.developer.nvidia.com/t/synchronous-kernel-calls/22208/6 "2011-04-28T20:39:42Z")

</div>

> [@](#):
>
> Either because you code is reading out of bounds, or because the code isn’t actually running to completion, leaving some of the output memory untouched

The initial matrix contained some very small floating numbers. I’m not entirely sure, how this might have caused the problems; anyway, I scaled them up a bit and the program works, so I am happy for now :-) Thanks for the feedback!
