# cudaHostAlloc memory initial time

**URL:** <https://forums.developer.nvidia.com/t/cudahostalloc-memory-initial-time/64266>\
**Category:** CUDA Programming and Performance\
**Created:** [August 19, 2018, 10:37am UTC](https://forums.developer.nvidia.com/t/cudahostalloc-memory-initial-time/64266 "2018-08-19T10:37:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dan.liu](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@dan.liu](https://forums.developer.nvidia.com/u/dan.liu)\
**Post date:** [August 19, 2018, 10:37am UTC](https://forums.developer.nvidia.com/t/cudahostalloc-memory-initial-time/64266/1 "2018-08-19T10:37:25Z")

</div>

Hello everyone! I know stream and asynchronous commands can achieve better performance. I run my code on TX2,and the code sample is like below.The problem is the most time is wasted on step3. when i use cudaMemcpy directly the data copy time is 20~40ms, but now use cudaMemcpyAsync, step3 is almost 40~60ms.what can i do to solve this problem?

```auto
cudaHostAlloc((void **)&h_a, sizeof(float)*N, cudaHostAllocDefault);
cudaMalloc((void **)&d_a, sizeof(float)*N);
/ **step3** /
for(int i=0; i<N; i++)
{
        h_a[i] = src_a[i];
}
/ **step3** /

cudaMemcpyAsync(d_a, h_a, sizeof(float)*N/nstreams, cudaMemcpyHostToDevice, stream[i]);

```
