# Map Performance with CuArrays

**URL:** <https://discourse.julialang.org/t/map-performance-with-cuarrays/33497>\
**Category:** GPU\
**Tags:** question, fftw, cuda, broadcast\
**Created:** [January 17, 2020, 5:54pm UTC](https://discourse.julialang.org/t/map-performance-with-cuarrays/33497 "2020-01-17T17:54:50Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)\
**Post date:** [January 30, 2020, 7:25am UTC](https://discourse.julialang.org/t/map-performance-with-cuarrays/33497/10 "2020-01-30T07:25:02Z")

</div>

OK, that example clarifies a lot. We don’t efficiently support what you’re doing there: broadcasting a function that does its own broadcasting over the inner 1D dataset. If that inner broadcast is coarse enough, i.e. if it does enough work to saturate the GPU, a mapslices-like approach might work (assuming we optimize the implementation of that API). But generally it will be more efficient to create a function that you can broadcast over the entire 2D dataset (not an array of arrays) in one go, e.g., like the batched fft interface in your first post. Some of your operations are element-wise anyway, and the final `reduce` you can perform in a batched manner with the `dims` keyword.

> [@bmit](#):
>
> Am I correct in concluding that I can’t broadcast on the GPU like I can on the CPU, at least not efficiently.

Don’t expect magic from the GPU. We implement `broadcast` to compile to a single kernel; you’re broadcasting a function that does an FFT and further broadcasts; that’s never going to work as a single kernel on the GPU. If you stick to this approach, optimizing `mapslices` would be the way to go. Else, you’d need to think about restructuring your operations to be dataset-wide, which would have advantages on the CPU too.

> [@bmit](#):
>
> I must be missing what Julia adds vs CUDA.

Except for the fact you’re writing high-level Julia code instead of CUDA C, you mean? 🙂

---

_[View the full topic](https://discourse.julialang.org/t/map-performance-with-cuarrays/33497)._
