# Same Kernel called multiple times in a loop has different runtimes

**URL:** <https://forums.developer.nvidia.com/t/same-kernel-called-multiple-times-in-a-loop-has-different-runtimes/49101>\
**Category:** CUDA Programming and Performance\
**Created:** [April 7, 2017, 10:06am UTC](https://forums.developer.nvidia.com/t/same-kernel-called-multiple-times-in-a-loop-has-different-runtimes/49101 "2017-04-07T10:06:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JohannesW](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@JohannesW](https://forums.developer.nvidia.com/u/JohannesW)\
**Post date:** [April 7, 2017, 10:06am UTC](https://forums.developer.nvidia.com/t/same-kernel-called-multiple-times-in-a-loop-has-different-runtimes/49101/1 "2017-04-07T10:06:30Z")

</div>

Hello,

I have a CUDA kernel performing a simulation that is called multiple times (~300x) in a loop. The output is written to global memory and with subsequent kernels processed. Preceding kernels create the simulation models. From time to time however, the loop iteration is slowed down and speeds up again. It even occurs, if I use just one block with a couple of threads.

If I analyze my program with nvvp, it shows up under “Performance-Critical Kernels” 2-3 times and for each entry, the kernel as a different runtime (varying from 4ms to 400ms). I attached a small screenshot of nvvp.

Can anybody give me hints, how to debug/analyze this behavior? The GPU is a 1050 Ti under Linux only used for CUDA. Graphics output is processed on a different GPU.

Thanks in advance

 ![nvvp.png](https://global.discourse-cdn.com/nvidia/original/2X/8/862d5542a215ca890673eee694bf0214057f2c21.png)

---

<div class="post-metadata">

**Author:** ![Robert\_Crovella](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/robert_crovella/32/14043_2.png) [@Robert\_Crovella](https://forums.developer.nvidia.com/u/Robert_Crovella)\
**Post date:** [April 7, 2017, 1:52pm UTC](https://forums.developer.nvidia.com/t/same-kernel-called-multiple-times-in-a-loop-has-different-runtimes/49101/2 "2017-04-07T13:52:15Z")

</div>

I’d certainly be wondering about the page faults.

---

<div class="post-metadata">

**Author:** ![JohannesW](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@JohannesW](https://forums.developer.nvidia.com/u/JohannesW)\
**Post date:** [April 8, 2017, 3:14pm UTC](https://forums.developer.nvidia.com/t/same-kernel-called-multiple-times-in-a-loop-has-different-runtimes/49101/3 "2017-04-08T15:14:44Z")

</div>

Thanks! I realized that I use managed memory for one kernel parameter. After prefetching it, everything works as expected.
