# cudaEventSync with cudaMemcpyAsync\_Host2Device

**URL:** <https://forums.developer.nvidia.com/t/cudaeventsync-with-cudamemcpyasync-host2device/184263>\
**Category:** CUDA Programming and Performance\
**Created:** [July 21, 2021, 5:44am UTC](https://forums.developer.nvidia.com/t/cudaeventsync-with-cudamemcpyasync-host2device/184263 "2021-07-21T05:44:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![RhettYing](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/rhettying/32/112416_2.png) [@RhettYing](https://forums.developer.nvidia.com/u/RhettYing)\
**Post date:** [July 21, 2021, 5:44am UTC](https://forums.developer.nvidia.com/t/cudaeventsync-with-cudamemcpyasync-host2device/184263/1 "2021-07-21T05:44:32Z")

</div>

I want cudaEventSync() returns once the target event finishes, but it seems returns when more events finished, even after the event that last called cudaEventRecord(). Is this expected?

event\_t copyHost2Dev(){  
cudaStreamcreate(&stream) // stream is different in each loop.  
cudaEventCreate(&eid)  
cudaMemcpyAsync(stream);  
cudaEventRecord(eid, stream)  
return eid;  
}  
void wait(id){  
cudaEventSynchronize(id)  
}

eid =   
for(int i =0; i \< 5; ++I){  
eid.append(copyHost2Dev())  
}  
wait(eid[0]) ------------------ This line returns only when all events are synced. what I expect is it returns once eid[0] finished.

I looked into with nsight system. and find cudaEventSynch(eid) synch all events, or the last call of cudaEventRecord() in most of times, just regardless of the target event id I cared. Is this expected?

I know all Host2Dev mem copy is serialized. is this correct?

---

<div class="post-metadata">

**Author:** ![striker159](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@striker159](https://forums.developer.nvidia.com/u/striker159)\
**Post date:** [July 21, 2021, 8:15am UTC](https://forums.developer.nvidia.com/t/cudaeventsync-with-cudamemcpyasync-host2device/184263/2 "2021-07-21T08:15:12Z")

</div>

If you use cudaEventRecord the same way as in your example, it will not work the way you intended.  
`cudaError_t cudaEventRecord ( cudaEvent_t event, cudaStream_t stream = 0 )`

You do not pass the stream to cudaEventRecord the event is recorded on the default stream.

---

<div class="post-metadata">

**Author:** ![RhettYing](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/rhettying/32/112416_2.png) [@RhettYing](https://forums.developer.nvidia.com/u/RhettYing)\
**Post date:** [July 21, 2021, 8:50am UTC](https://forums.developer.nvidia.com/t/cudaeventsync-with-cudamemcpyasync-host2device/184263/3 "2021-07-21T08:50:10Z")

</div>

my typo. I actually called with cudaEventRecord(eid, stream). `stream` here is used in cudaMemcpyAsync(). And I cannot get what I want yet.

---

<div class="post-metadata">

**Author:** ![striker159](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@striker159](https://forums.developer.nvidia.com/u/striker159)\
**Post date:** [July 21, 2021, 9:45am UTC](https://forums.developer.nvidia.com/t/cudaeventsync-with-cudamemcpyasync-host2device/184263/4 "2021-07-21T09:45:05Z")

</div>

If that’s the case, you should provide a complete example which can be compiled and run.

---

<div class="post-metadata">

**Author:** ![RhettYing](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/rhettying/32/112416_2.png) [@RhettYing](https://forums.developer.nvidia.com/u/RhettYing)\
**Post date:** [July 22, 2021, 3:16am UTC](https://forums.developer.nvidia.com/t/cudaeventsync-with-cudamemcpyasync-host2device/184263/5 "2021-07-22T03:16:54Z")

</div>

cudaEvencSync works well. I find it’s caused by incorrect use.  
Thanks for your help.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/system/32/68080_2.png) [@system](https://forums.developer.nvidia.com/u/system)\
**Post date:** [September 20, 2021, 3:17am UTC](https://forums.developer.nvidia.com/t/cudaeventsync-with-cudamemcpyasync-host2device/184263/6 "2021-09-20T03:17:48Z")

</div>

Closed on September 20, 2021, 3:17am UTC

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
