# cudaMemcpyAsync: where is it used?

**URL:** https://discourse.julialang.org/t/cudamemcpyasync-where-is-it-used/117967
**Category:** GPU
**Tags:** cuda
**Created:** [August 8, 2024, 6:15pm UTC](https://discourse.julialang.org/t/cudamemcpyasync-where-is-it-used/117967 "2024-08-08T18:15:25Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![wsshin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wsshin/32/360_2.png) [@wsshin](https://discourse.julialang.org/u/wsshin)
#### Post date: [August 13, 2024, 3:03pm UTC](https://discourse.julialang.org/t/cudamemcpyasync-where-is-it-used/117967/3 "2024-08-13T15:03:48Z")

</div>

I was able to identify one place where `cudaMemcpyAsync` is used: `normalize!`:

```julia-repl
julia> d = CUDA.rand(1024);

julia> CUDA.@profile normalize!(d)
Profiler ran for 1.98 s, capturing 39 events.

Host-side activity: calling CUDA APIs took 223.64 µs (0.01% of the trace)
┌──────────┬────────────┬───────┬───────────────────────────────────────┬──────────────────────────┐
│ Time (%) │ Total time │ Calls │ Time distribution │ Name │
├──────────┼────────────┼───────┼───────────────────────────────────────┼──────────────────────────┤
│ 0.01% │ 99.18 µs │ 1 │ │ cudaFuncGetAttributes │
│ 0.00% │ 57.94 µs │ 3 │ 19.31 µs ± 11.62 ( 5.96 ‥ 27.18) │ cudaLaunchKernel │
│ 0.00% │ 40.53 µs │ 2 │ 20.27 µs ± 3.71 ( 17.64 ‥ 22.89) │ cudaMemcpyAsync │
...

```

Is this something expected? If so, is there a way to perform `normalize!` on a CUDA array without copying data between the host and device? I call `normalize!` in a loop, so this is quite costly.

**UPDATE**. I find that `norm` also uses `cudaMemcpyAsync`:

```julia-repl
julia> CUDA.@profile norm(d)
Profiler ran for 801.43 ms, capturing 28 events.

Host-side activity: calling CUDA APIs took 170.23 µs (0.02% of the trace)
┌──────────┬────────────┬───────┬───────────────────────────────────────┬──────────────────────────┐
│ Time (%) │ Total time │ Calls │ Time distribution │ Name │
├──────────┼────────────┼───────┼───────────────────────────────────────┼──────────────────────────┤
│ 0.01% │ 68.9 µs │ 1 │ │ cudaFuncGetAttributes │
│ 0.00% │ 39.58 µs │ 2 │ 19.79 µs ± 0.34 ( 19.55 ‥ 20.03) │ cudaMemcpyAsync │
│ 0.00% │ 36.0 µs │ 2 │ 18.0 µs ± 16.35 ( 6.44 ‥ 29.56) │ cudaLaunchKernel │
...

```

---

_[View the full topic](https://discourse.julialang.org/t/cudamemcpyasync-where-is-it-used/117967)._
