# Does CUDA.jl have sortperm! implemented?

**URL:** https://discourse.julialang.org/t/does-cuda-jl-have-sortperm-implemented/111594
**Category:** General Usage
**Created:** [March 13, 2024, 11:10pm UTC](https://discourse.julialang.org/t/does-cuda-jl-have-sortperm-implemented/111594 "2024-03-13T23:10:44Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)
#### Post date: [March 13, 2024, 11:10pm UTC](https://discourse.julialang.org/t/does-cuda-jl-have-sortperm-implemented/111594/1 "2024-03-13T23:10:44Z")

</div>

Hello!

I am getting quite confused. I have a vector of CartesianIndices and when I call sortperm! on it, it works great. I notice though that when tracking performance with CUDA.@time it reports to me a lot of CPU allocations. How come, isn’t the computation being performed on GPU, if the inputs to `sortperm!` are CuArrays?

Kind regards

---

<div class="post-metadata">

### Author: ![Zentrik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zentrik/32/35409_2.png) [@Zentrik](https://discourse.julialang.org/u/Zentrik)
#### Post date: [March 14, 2024, 1:00am UTC](https://discourse.julialang.org/t/does-cuda-jl-have-sortperm-implemented/111594/2 "2024-03-14T01:00:19Z")

</div>

It does seem to [CUDA.jl/src/sorting.jl at 9306cea23b813c3331df6749595c8b46d6c8b27c · JuliaGPU/CUDA.jl · GitHub](https://github.com/JuliaGPU/CUDA.jl/blob/9306cea23b813c3331df6749595c8b46d6c8b27c/src/sorting.jl#L979-L987).  
A brief look at `bitonic_sort!` seemed to suggest it might be doing a fair amount of stuff on the cpu as well as on the gpu.

---

<div class="post-metadata">

### Author: ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)
#### Post date: [March 14, 2024, 2:41pm UTC](https://discourse.julialang.org/t/does-cuda-jl-have-sortperm-implemented/111594/3 "2024-03-14T14:41:50Z")

</div>

Thanks for sharing!

Yes, that is what perplexed me too, but from the code I can see what you describe a lot of allocations on CPU. I was surprised that it would be 10k+ allocations though. The speed of it is ok being about 160 mus for 3000 elements, considering that the GPU does not get a chance to scale properly on such a small vector.

Atleast I can now confirm something is happening on GPU, thanks!
