You won’t be able to run arbitrary code like that on the GPU. GPU kernels need to be relatively simple, for example, have a look at this introductory tutorial from the CUDA.jl docs: Introduction · CUDA.jl
If you want more complicated operations to work, without the experience to write your own kernels, you’ll be better off relying on the array abstractions we provide. These are vectorized operations (think map, reduce, scan, sort) that have been implemented in a parallel manner, and use the GPU efficiently. If it’s possible to rephrase your problem in terms of such operations, that will be the easier way to use the GPU.
If that doesn’t work you’ll need to look into writing your own kernel, but there’s a lot of caveats: you cannot use dynamic dispatch, GC allocations, non-isbits types, etc.