# \#gpuarrays

**URL:** https://discourse.julialang.org/tag/gpuarrays/95.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## ["I don't like NumPy" - Julia equivalents to the numpy code?](https://discourse.julialang.org/t/i-dont-like-numpy-julia-equivalents-to-the-numpy-code/129052)

<div class="topic-metadata">

**Author:** [@MDSW](https://discourse.julialang.org/u/MDSW)\
**Replies:** 19\
**Last updated:** [May 21, 2025, 7:46pm UTC](https://discourse.julialang.org/t/i-dont-like-numpy-julia-equivalents-to-the-numpy-code/129052 "2025-05-21T19:46:36Z")

</div>

I came across this post and, not being an expert in either NumPy or the how it would be done in Julia, was curious if anyone here could weigh in with idiomatic Julia versions of some of these examples for comparison. No…

---

## [Is there a way to use @allowscalar in a heterogeneous manner using KernelAbstractions?](https://discourse.julialang.org/t/is-there-a-way-to-use-allowscalar-in-a-heterogeneous-manner-using-kernelabstractions/127828)

<div class="topic-metadata">

**Author:** [@0samuraiE](https://discourse.julialang.org/u/0samuraiE)\
**Replies:** 3\
**Last updated:** [April 10, 2025, 6:33am UTC](https://discourse.julialang.org/t/is-there-a-way-to-use-allowscalar-in-a-heterogeneous-manner-using-kernelabstractions/127828 "2025-04-10T06:33:57Z")

</div>

Hi all, Is it correct that scalar indexing like Out\[1\] is not allowed with KernelAbstractions.jl alone, and that we need GPUArrays.@allowscalar for this? Should we always use GPUArrays together with KernelAbstractions f…

---

## [Inconsistency in \`accumulate\` between \`Array\` and \`CuArray.\`](https://discourse.julialang.org/t/inconsistency-in-accumulate-between-array-and-cuarray/127382)

<div class="topic-metadata">

**Author:** [@0samuraiE](https://discourse.julialang.org/u/0samuraiE)\
**Replies:** 2\
**Last updated:** [March 26, 2025, 11:58pm UTC](https://discourse.julialang.org/t/inconsistency-in-accumulate-between-array-and-cuarray/127382 "2025-03-26T23:58:38Z")

</div>

Hi all. I’m performing the following computation using GPUArrays: julia\> using GPUArrays julia\> src = CuArray(rand(0:9, 10)) 10-element CuArray{Int64, 1, CUDA.DeviceMemory}: 3 4 3 7 3 9 7 2 9 6 julia\> dst =…

---

## [Cumulative sum on GPUArray using KernelAbstractions](https://discourse.julialang.org/t/cumulative-sum-on-gpuarray-using-kernelabstractions/124098)

<div class="topic-metadata">

**Author:** [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Replies:** 4\
**Last updated:** [December 24, 2024, 3:16pm UTC](https://discourse.julialang.org/t/cumulative-sum-on-gpuarray-using-kernelabstractions/124098 "2024-12-24T15:16:37Z")

</div>

Hello, I need to implement the cumulative sum (cumsum) on a GPU array (CUDA.jl or Metal.jl). Looking at the CUDA.jl repository, I found this definition function cumsum!(sums) shift = 1 while shift \< length(sum…

---

## [Can I move an array asynchronously from main program to CUDA?](https://discourse.julialang.org/t/can-i-move-an-array-asynchronously-from-main-program-to-cuda/119976)

<div class="topic-metadata">

**Author:** [@joaquimg](https://discourse.julialang.org/u/joaquimg)\
**Replies:** 7\
**Last updated:** [December 15, 2024, 8:37pm UTC](https://discourse.julialang.org/t/can-i-move-an-array-asynchronously-from-main-program-to-cuda/119976 "2024-12-15T20:37:49Z")

</div>

I have an application that would benefit from passing an array asynchronously from the main program to my CUDA GPU while I am doing other computations on my CPU. The GPU would only be working on receiving the array. Als…

---

## [Implement feature common to all \`AbstractGPUArrays\` through KernelAbstractions.jl](https://discourse.julialang.org/t/implement-feature-common-to-all-abstractgpuarrays-through-kernelabstractions-jl/123855)

<div class="topic-metadata">

**Author:** [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Replies:** 2\
**Last updated:** [December 15, 2024, 2:20pm UTC](https://discourse.julialang.org/t/implement-feature-common-to-all-abstractgpuarrays-through-kernelabstractions-jl/123855 "2024-12-15T14:20:39Z")

</div>

Hello, Let’s imagine I have a very common function LinearAlgebra.kron(a::VT, b::VT) where VT\<:AbstractGPUArray which can support any AbstractGPUArray since I’m using KernelAbstractions.jl. Where should I implement suc…

---

## [Suggestion: abstraction for integrated GPUs?](https://discourse.julialang.org/t/suggestion-abstraction-for-integrated-gpus/117061)

<div class="topic-metadata">

**Author:** [@bremez](https://discourse.julialang.org/u/bremez)\
**Replies:** 7\
**Last updated:** [July 16, 2024, 7:06am UTC](https://discourse.julialang.org/t/suggestion-abstraction-for-integrated-gpus/117061 "2024-07-16T07:06:16Z")

</div>

I have had the following thought: many people do not have regular access to HPC or high-end GPUs (where Nvidia seems most popular), and/or prioritize the benefit of interactive sessions on their personal laptops and low …

---

## [Do a function like relu need a kernel ? When you need to write a GPU kernel rather than "just" using CuArray?](https://discourse.julialang.org/t/do-a-function-like-relu-need-a-kernel-when-you-need-to-write-a-gpu-kernel-rather-than-just-using-cuarray/116265)

<div class="topic-metadata">

**Author:** [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Replies:** 3\
**Last updated:** [June 26, 2024, 4:54pm UTC](https://discourse.julialang.org/t/do-a-function-like-relu-need-a-kernel-when-you-need-to-write-a-gpu-kernel-rather-than-just-using-cuarray/116265 "2024-06-26T16:54:03Z")

</div>

The relu function works elementwise by returning the input that is non-negative, i.e. relu(x) = ifelse.(x .\> 0, x, 0). Does the fact that it works elementwise means I need to write a GPU kernel for it, or I can simply u…

---

## [Difference between GPUArrays.jl and KernelAbstractations.jl](https://discourse.julialang.org/t/difference-between-gpuarrays-jl-and-kernelabstractations-jl/115457)

<div class="topic-metadata">

**Author:** [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Replies:** 4\
**Last updated:** [June 12, 2024, 2:17pm UTC](https://discourse.julialang.org/t/difference-between-gpuarrays-jl-and-kernelabstractations-jl/115457 "2024-06-12T14:17:50Z")

</div>

Hello, I would like to implement some simple matrix-vector multiplication, when none of them are strided arrays (e.g., @view(A\[\[1, 4, 5\], 1:10\])). Standard LinearAlgebra.mul! doesn’t support these arrays, so I thought t…

---

## [Newbie question regarding GPU with metal.jl](https://discourse.julialang.org/t/newbie-question-regarding-gpu-with-metal-jl/112850)

<div class="topic-metadata">

**Author:** [@cloner0110](https://discourse.julialang.org/u/cloner0110)\
**Replies:** 0\
**Last updated:** [April 11, 2024, 10:39pm UTC](https://discourse.julialang.org/t/newbie-question-regarding-gpu-with-metal-jl/112850 "2024-04-11T22:39:14Z")

</div>

Hi Everyone, Im a bit new to julia and GPU programming, Im about to solve a system of equation using metal.jl on a GPU and see the performance, as a starting point, does any of you have any suggestions? Cheers,

---

## [GPU problems with RecursiveArrayTools](https://discourse.julialang.org/t/gpu-problems-with-recursivearraytools/110830)

<div class="topic-metadata">

**Author:** [@agelgazzar](https://discourse.julialang.org/u/agelgazzar)\
**Replies:** 1\
**Last updated:** [February 28, 2024, 8:25pm UTC](https://discourse.julialang.org/t/gpu-problems-with-recursivearraytools/110830 "2024-02-28T20:25:29Z")

</div>

Hi, I have an system of ODEs where the state is an array of arrays. I want to be able to solve my ODE on the gpu. I am using ArrayPartition where each array is an CuArray. However, I get the scalar indexing error. The co…

---

## [Inverse problem with NeuralPDE and GPU support](https://discourse.julialang.org/t/inverse-problem-with-neuralpde-and-gpu-support/109051)

<div class="topic-metadata">

**Author:** [@Rene\_Schenkendorf](https://discourse.julialang.org/u/Rene_Schenkendorf)\
**Replies:** 5\
**Last updated:** [January 23, 2024, 8:29am UTC](https://discourse.julialang.org/t/inverse-problem-with-neuralpde-and-gpu-support/109051 "2024-01-23T08:29:00Z")

</div>

Hello everyone. I am new to Julia (at least that’s how it feels from time to time). Using the GPU according to tutorial https://docs.sciml.ai/NeuralPDE/stable/tutorials/gpu/ works; the inverse problem (first-principles m…

---

## [Having issues with running NeuralPDE on GPU](https://discourse.julialang.org/t/having-issues-with-running-neuralpde-on-gpu/108581)

<div class="topic-metadata">

**Author:** [@tajimura](https://discourse.julialang.org/u/tajimura)\
**Replies:** 5\
**Last updated:** [January 22, 2024, 9:49am UTC](https://discourse.julialang.org/t/having-issues-with-running-neuralpde-on-gpu/108581 "2024-01-22T09:49:58Z")

</div>

Was trying to train a PINN for NLSE using NeuralPDE. Everything runs fine on CPU, but when I try to move calculations to GPU, I get the following error: ERROR: CuArray only supports element types that are allocated inli…

---

## [Peculiar GPU behavior: zero performance cost for math functions?](https://discourse.julialang.org/t/peculiar-gpu-behavior-zero-performance-cost-for-math-functions/105764)

<div class="topic-metadata">

**Author:** [@bremez](https://discourse.julialang.org/u/bremez)\
**Replies:** 5\
**Last updated:** [November 4, 2023, 4:24am UTC](https://discourse.julialang.org/t/peculiar-gpu-behavior-zero-performance-cost-for-math-functions/105764 "2023-11-04T04:24:15Z")

</div>

I have a use case where the performance bottleneck is in computing trigonometric functions. I thought that maybe it would benefit from some more parallelism, and realized that having access to a university computing clus…

---

## [How to sum the result of mapslices on the GPU while tracking gradients?](https://discourse.julialang.org/t/how-to-sum-the-result-of-mapslices-on-the-gpu-while-tracking-gradients/105310)

<div class="topic-metadata">

**Author:** [@taotree](https://discourse.julialang.org/u/taotree)\
**Replies:** 0\
**Last updated:** [October 23, 2023, 11:52am UTC](https://discourse.julialang.org/t/how-to-sum-the-result-of-mapslices-on-the-gpu-while-tracking-gradients/105310 "2023-10-23T11:52:49Z")

</div>

I need to do mapslices but need it to support gradient tracking for Zygote. So, I’m trying to use SliceMap.slicemap. I can’t use SliceMap.mapcols because I have parameters inside the function. SliceMap.slicemap returns a…

---

## [Broadcast update multiple vectors at once](https://discourse.julialang.org/t/broadcast-update-multiple-vectors-at-once/99490)

<div class="topic-metadata">

**Author:** [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Replies:** 7\
**Last updated:** [May 28, 2023, 7:24am UTC](https://discourse.julialang.org/t/broadcast-update-multiple-vectors-at-once/99490 "2023-05-28T07:24:51Z")

</div>

Simple question. I have a few vectors which hold the states of a list of particles. I update these with broadcast (which is nice since the vectors are on the GPU). For example: position⁰ .= position position .+=…

---

## [Creating sparse diagonal matrix of CuArray](https://discourse.julialang.org/t/creating-sparse-diagonal-matrix-of-cuarray/97108)

<div class="topic-metadata">

**Author:** [@Hemsh94](https://discourse.julialang.org/u/Hemsh94)\
**Replies:** 0\
**Last updated:** [April 5, 2023, 9:40am UTC](https://discourse.julialang.org/t/creating-sparse-diagonal-matrix-of-cuarray/97108 "2023-04-05T09:40:42Z")

</div>

Hello everyone, If we have a vector (u), we can easily convert it into a sparse diagonal matrix using the command spdiagm(u). I want to do the same operation using CUDA where u is defined as CuArray(u). The command spd…

---

## [CUDA.jl - Memory Efficient Operations, Manipulations and Calculations on Large Sparse Arrays](https://discourse.julialang.org/t/cuda-jl-memory-efficient-operations-manipulations-and-calculations-on-large-sparse-arrays/83091)

<div class="topic-metadata">

**Author:** [@moukann](https://discourse.julialang.org/u/moukann)\
**Replies:** 6\
**Last updated:** [June 21, 2022, 7:54pm UTC](https://discourse.julialang.org/t/cuda-jl-memory-efficient-operations-manipulations-and-calculations-on-large-sparse-arrays/83091 "2022-06-21T19:54:00Z")

</div>

Hello all, I formerly created this topic, my problem is continuing until this day: The problem is related to GPU RAM and its size. The global system is a square matrix, consisting of Float64 values. However, it is mos…

---

## [Cross-platform (CPU/GPU) data structure for linear algebra](https://discourse.julialang.org/t/cross-platform-cpu-gpu-data-structure-for-linear-algebra/79877)

<div class="topic-metadata">

**Author:** [@FireCrumb](https://discourse.julialang.org/u/FireCrumb)\
**Replies:** 3\
**Last updated:** [May 13, 2022, 7:26am UTC](https://discourse.julialang.org/t/cross-platform-cpu-gpu-data-structure-for-linear-algebra/79877 "2022-05-13T07:26:20Z")

</div>

Hi, I’m building an ML application, and want to pass around a data structure that contains several scalars/arrays/vertices/matrices. The dimension will be determined at runtime, depending on input dataset etc. The nume…

---

## [CUDA.jl - Variable Sized Local Arrays Inside CUDA Kernel](https://discourse.julialang.org/t/cuda-jl-variable-sized-local-arrays-inside-cuda-kernel/78567)

<div class="topic-metadata">

**Author:** [@moukann](https://discourse.julialang.org/u/moukann)\
**Replies:** 2\
**Last updated:** [March 28, 2022, 11:13am UTC](https://discourse.julialang.org/t/cuda-jl-variable-sized-local-arrays-inside-cuda-kernel/78567 "2022-03-28T11:13:53Z")

</div>

Hello all, I am trying to parallelize a computational mechanics code. I encountered a problem which I cannot solve. I am trying to allocate variable sized arrays for every thread. However, for a particular thread, the s…

---

## [CUDA/AMD/CPU device agnostic array creation best practice](https://discourse.julialang.org/t/cuda-amd-cpu-device-agnostic-array-creation-best-practice/75059)

<div class="topic-metadata">

**Author:** [@Marcell\_Havlik](https://discourse.julialang.org/u/Marcell_Havlik)\
**Replies:** 9\
**Last updated:** [January 23, 2022, 3:42pm UTC](https://discourse.julialang.org/t/cuda-amd-cpu-device-agnostic-array-creation-best-practice/75059 "2022-01-23T15:42:43Z")

</div>

Dear Julianners, What is the best practice to do a device agnostic array initialisation. I believe this package written by many person already. For example: get\_worker\_type() = :CUDA # This is actually a function tha…

---

## [CUDA global synchronization HOWTO](https://discourse.julialang.org/t/cuda-global-synchronization-howto/74920)

<div class="topic-metadata">

**Author:** [@Marcell\_Havlik](https://discourse.julialang.org/u/Marcell_Havlik)\
**Replies:** 9\
**Last updated:** [January 20, 2022, 12:52pm UTC](https://discourse.julialang.org/t/cuda-global-synchronization-howto/74920 "2022-01-20T12:52:47Z")

</div>

Dear Julianners, I try to create an algorithm that runs an elementwise update operation and a reduction in 10k iteration and about 1\_000\_000 times, so the kernel restarts(2-8us) are really expensive in this scenario. T…

---

## [Error While adding CuArrays.jl package](https://discourse.julialang.org/t/error-while-adding-cuarrays-jl-package/58387)

<div class="topic-metadata">

**Author:** [@Sumanshekhar17](https://discourse.julialang.org/u/Sumanshekhar17)\
**Replies:** 12\
**Last updated:** [April 2, 2021, 10:02am UTC](https://discourse.julialang.org/t/error-while-adding-cuarrays-jl-package/58387 "2021-04-02T10:02:13Z")

</div>

There are two problems that I am facing first is that- I have tried CUDA.has\_cuda(), and it gave me false. The second is that when I tried to add CuArrays.jl it gave me this error- julia\> import Pkg julia\> Pkg.add("C…

---

## [Scalar getindex is disallowed](https://discourse.julialang.org/t/scalar-getindex-is-disallowed/53280)

<div class="topic-metadata">

**Author:** [@tgautam03](https://discourse.julialang.org/u/tgautam03)\
**Replies:** 2\
**Last updated:** [January 13, 2021, 4:20pm UTC](https://discourse.julialang.org/t/scalar-getindex-is-disallowed/53280 "2021-01-13T16:20:22Z")

</div>

Hi, I just wrote a function that computes chain rule using Finite Difference derivatives and ran into a weird issue. The function that calculates the derivative is defined as function chain\_deriv(chain:: Vector{\<:Funct…

---

## [Virtual GPU office hours](https://discourse.julialang.org/t/virtual-gpu-office-hours/38385)

<div class="topic-metadata">

**Author:** [@vchuravy](https://discourse.julialang.org/u/vchuravy)\
**Replies:** 0\
**Last updated:** [April 28, 2020, 5:09pm UTC](https://discourse.julialang.org/t/virtual-gpu-office-hours/38385 "2020-04-28T17:09:41Z")

</div>

We have decided to experiment with a new format and decided to hold virtual office hours for GPU programming in Julia. So everything that is under the JuliaGPU · GitHub umbrella. Feel free to drop by and to discuss your…

---

## [GPU Sort Function](https://discourse.julialang.org/t/gpu-sort-function/36065)

<div class="topic-metadata">

**Author:** [@bmit](https://discourse.julialang.org/u/bmit)\
**Replies:** 20\
**Last updated:** [April 2, 2020, 1:28pm UTC](https://discourse.julialang.org/t/gpu-sort-function/36065 "2020-04-02T13:28:25Z")

</div>

I was wondering if anyone has implemented a sort or partialsort function that is GPU friendly. Ultimately I need to compute statistical metrics of a dataset such as median or quartile that require sorting. I saw it was …

---

## [What do I get when I subtype GPUArray?](https://discourse.julialang.org/t/what-do-i-get-when-i-subtype-gpuarray/31537)

<div class="topic-metadata">

**Author:** [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)\
**Replies:** 7\
**Last updated:** [November 27, 2019, 11:04am UTC](https://discourse.julialang.org/t/what-do-i-get-when-i-subtype-gpuarray/31537 "2019-11-27T11:04:44Z")

</div>

As the main developer of ROCArrays.jl, I’m trying to understand what benefits I get when I make ROCArray \<: GPUArray. GPUArrays.jl is a rather large package (likely due to it also implementing JLArray), so it’s hard for …

---

## [GPU support in Knet: Cannot allocate before CuArrays has been initialized](https://discourse.julialang.org/t/gpu-support-in-knet-cannot-allocate-before-cuarrays-has-been-initialized/30859)

<div class="topic-metadata">

**Author:** [@Peter.Zentis](https://discourse.julialang.org/u/Peter.Zentis)\
**Replies:** 2\
**Last updated:** [November 8, 2019, 3:04pm UTC](https://discourse.julialang.org/t/gpu-support-in-knet-cannot-allocate-before-cuarrays-has-been-initialized/30859 "2019-11-08T15:04:21Z")

</div>

Hi all, I am trying to work through the Knet tutorial (https://github.com/denizyuret/Knet.jl/blob/master/tutorial/50.cnn.ipynb) which worked great, just until I needed/wanted to use gpu support i.e. use a KnetArray. I …

---

## [Generalised CUDA/CPU](https://discourse.julialang.org/t/generalised-cuda-cpu/29633)

<div class="topic-metadata">

**Author:** [@Raf](https://discourse.julialang.org/u/Raf)\
**Replies:** 10\
**Last updated:** [October 10, 2019, 2:53pm UTC](https://discourse.julialang.org/t/generalised-cuda-cpu/29633 "2019-10-10T14:53:55Z")

</div>

So this is the old question of using exponents and similar in code that runs on Cuda. I’m wondering what solutions are people using in late 2019. There are answers like this: https://github.com/JuliaGPU/CuArrays.jl/issu…

---

## [Initializing CuArrays](https://discourse.julialang.org/t/initializing-cuarrays/27976)

<div class="topic-metadata">

**Author:** [@wiktorkujawa](https://discourse.julialang.org/u/wiktorkujawa)\
**Replies:** 0\
**Last updated:** [August 25, 2019, 11:24pm UTC](https://discourse.julialang.org/t/initializing-cuarrays/27976 "2019-08-25T23:24:39Z")

</div>

How to initialize this type of array: ArrayName=cu(fill(\[0.0f0,0.0f0\],(20,20,5))), I don’t want to use Tuples because there are too many problems with math operations doing on them(they can’t for example increment and …

[Next page](https://discourse.julialang.org/tag/gpuarrays/95.md?match_all_tags=true&page=1&tags%5B%5D=gpuarrays)
