# accessing device memory during kernel execution

**URL:** <https://forums.developer.nvidia.com/t/accessing-device-memory-during-kernel-execution/15403>\
**Category:** CUDA Programming and Performance\
**Created:** [March 9, 2010, 5:41pm UTC](https://forums.developer.nvidia.com/t/accessing-device-memory-during-kernel-execution/15403 "2010-03-09T17:41:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![m\_habanero](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@m\_habanero](https://forums.developer.nvidia.com/u/m_habanero)\
**Post date:** [March 9, 2010, 5:41pm UTC](https://forums.developer.nvidia.com/t/accessing-device-memory-during-kernel-execution/15403/1 "2010-03-09T17:41:30Z")

</div>

I’m curious, what happens when issuing a cudaMalloc, cudaMemcpy, or cudaFree while a kernel is executing on the device? Does the memory call block until the kernel completes, or does CUDA allow concurrent host and device memory accesses? Thanks for any answers :)

---

<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:** [March 9, 2010, 6:01pm UTC](https://forums.developer.nvidia.com/t/accessing-device-memory-during-kernel-execution/15403/2 "2010-03-09T18:01:04Z")

</div>

cudaMalloc and cudaFree require the GPU to complete all pending work before completing (for the most part). cudaMemcpyAsync can overlap with kernels in different streams, which implies that the developer is guaranteeing that you are not accessing the same region from a memcpy and a kernel simultaneously (unless they’re both only reading).

---

<div class="post-metadata">

**Author:** ![m\_habanero](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@m\_habanero](https://forums.developer.nvidia.com/u/m_habanero)\
**Post date:** [March 9, 2010, 8:06pm UTC](https://forums.developer.nvidia.com/t/accessing-device-memory-during-kernel-execution/15403/3 "2010-03-09T20:06:02Z")

</div>

> [@](#):
>
> cudaMalloc and cudaFree require the GPU to complete all pending work before completing (for the most part). cudaMemcpyAsync can overlap with kernels in different streams, which implies that the developer is guaranteeing that you are not accessing the same region from a memcpy and a kernel simultaneously (unless they’re both only reading).

OK, I see in the CUDA programming guide how to use streams, but only a way to separate the streams that cudaMemcpy acts on. Is there any way to use streams with cudaMallocs or cudaFrees?

---

<div class="post-metadata">

**Author:** ![gshi](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@gshi](https://forums.developer.nvidia.com/u/gshi)\
**Post date:** [March 10, 2010, 4:44pm UTC](https://forums.developer.nvidia.com/t/accessing-device-memory-during-kernel-execution/15403/4 "2010-03-10T16:44:10Z")

</div>

Not that I know of.

You don’t find function calls like cudaMallocAsync() but you can find cudaMemcpyAsync()

After all cudaMalloc() usually takes no time and it is not worth to overlap it with something else.

> [@](#):
>
> OK, I see in the CUDA programming guide how to use streams, but only a way to separate the streams that cudaMemcpy acts on. Is there any way to use streams with cudaMallocs or cudaFrees?
