-
Hi there, I'm trying to set up a simple Kolmogorov flow forced by a single sinusoidal mode using forcing_mode = 4
function setF!(Fh, sol, t, clock, vars, params, grid)
Fh .= zeros(eltype(grid), size(sol))
CUDA.@allowscalar Fh[1,forcing_mode] = -forcing_mode*nx*ny
return nothing
end My inexperience with GPUs shows here, however, with CUDA complaining about GPU compilation of the kernel. using GeophysicalFlows
dev = GPU()
n = 128
L = 2π
ν = 1e-2
nν= 1
μ = 0
nμ= 0
dt = 5e-4
function setF!(Fh, sol, t, clock, vars, params, grid)
Fh = @. zeros(eltype(grid), size(sol))
return nothing
end
prob = TwoDNavierStokes.Problem(dev; nx=n, Lx=L, ν, nν, μ, nμ, dt, stepper="ETDRK4",
calcF=setF!, stochastic=false)
sol, clock, vars, params, grid = prob.sol, prob.clock, prob.vars, prob.params, prob.grid
setF!(vars.Fh, sol, 0.0, clock, vars, params, grid) And the backtrace that appears afterwards:
If you can help me understand how to properly write such forcing functions for |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
There are a few problems with what you do here. First zeros(eltype(grid), size(sol)) is an array on the CPU. Also, (There is another "problem" that what you are doing up there is not that efficient since you are allocating a whole array every time you call This function setF!(Fh, sol, t, clock, vars, params, grid)
@. Fh = 0
return nothing
end is device-agnostic and thus will work. But perhaps just zeroing out the forcing is not what you really aiming for but you were just playing around? If you need to create an array, there is help?> device_array
search: device_array
device_array(device::Device)
device_array(device::Device, T, dim)
Return the proper array type according to the device, i.e., Array for CPU and CuArray for GPU. which will let you create the appropriate array on the device you are on, e.g., device_array(dev)(zeros(eltype(grid), size(sol)) For example, this would also work: julia> function setF!(Fh, sol, t, clock, vars, params, grid)
Fh = device_array(dev)(zeros(complex(eltype(grid)), size(sol)))
return nothing
end
setF! (generic function with 1 method)
julia> setF!(vars.Fh, sol, 0.0, clock, vars, params, grid) Btw, another thing I didn't quite understand is what the |
Beta Was this translation helpful? Give feedback.
There are a few problems with what you do here. First
is an array on the CPU. Also,
vars.Fh
is complex-valued but the array you create insetF!
is real-valued.(There is another "problem" that what you are doing up there is not that efficient since you are allocating a whole array every time you call
setF!
.)This
is device-agnostic and thus will work. But perhaps just zeroing out the forcing is not what you really aiming for but you were just playing around?
If you need to create an array, there is
device_array
: