Adapting Float64 struct equations to Float32 GPU code
buggpu
This conversion has a bug when the equation struct present some parameters that are entered by the user. For example `CompressibleEulerEquations2D(gamma)`. If `gamma` is not of the same type as `real_type` for the GPU kernel, the code will not run and will return the following error:
```julia
ERROR: LoadError: BoundsError: attempt to access NTuple{4, String} at index [5]
Stacktrace:
[1] getindex(t::Tuple, i::Int64)
@ Base ./tuple.jl:31
[2] (::Trixi.var"#1796#1803"{…})(file::HDF5.File)
@ Trixi ~/workspace/dev/Trixi.jl/src/callbacks_step/save_solution_dg.jl:67
[3] (::HDF5.var"#17#18"{HDF5.HDF5Context, @Kwargs{}, Trixi.var"#1796#1803"{…}, HDF5.File})()
@ HDF5 ~/.julia/packages/HDF5/8g5ny/src/file.jl:101
[4] task_local_storage(body::HDF5.var"#17#18"{…}, key::Symbol, val::HDF5.HDF5Context)
@ Base ./task.jl:304
[5] #h5open#16
@ ~/.julia/packages/HDF5/8g5ny/src/file.jl:96 [inlined]
[6] h5open
@ ~/.julia/packages/HDF5/8g5ny/src/file.jl:94 [inlined]
[7] save_solution_file(u::Array{…}, time::Float64, dt::Float64, timestep::Int64, mesh::P4estMesh{…}, equations::CompressibleEulerEquations2D{…}, dg::DGSEM{…}, cache::@NamedTuple{…}, solution_callback::SaveSolutionCallback{…}, element_variables::Dict{…}, node_variables::Dict{…}; system::String)
@ Trixi ~/workspace/dev/Trixi.jl/src/callbacks_step/save_solution_dg.jl:47
[8] save_solution_file
@ ~/workspace/dev/Trixi.jl/src/callbacks_step/save_solution_dg.jl:8 [inlined]
[9] #save_solution_file#1791
@ ~/workspace/dev/Trixi.jl/src/callbacks_step/save_solution.jl:306 [inlined]
[10] save_solution_file
@ ~/workspace/dev/Trixi.jl/src/callbacks_step/save_solution.jl:294 [inlined]
[11] macro expansion
@ ~/.julia/packages/TrixiBase/MGeKl/src/trixi_timeit.jl:67 [inlined]
[12] #save_solution_file#1788
@ ~/workspace/dev/Trixi.jl/src/callbacks_step/save_solution.jl:285 [inlined]
[13] save_solution_file
@ ~/workspace/dev/Trixi.jl/src/callbacks_step/save_solution.jl:260 [inlined]
[14] macro expansion
@ ~/workspace/dev/Trixi.jl/src/callbacks_step/save_solution.jl:252 [inlined]
[15] macro expansion
@ ~/.julia/packages/TrixiBase/MGeKl/src/trixi_timeit.jl:67 [inlined]
[16] (::SaveSolutionCallback{…})(integrator::OrdinaryDiffEqCore.ODEIntegrator{…})
@ Trixi ~/workspace/dev/Trixi.jl/src/callbacks_step/save_solution.jl:247
[17] initialize_save_cb!(solution_callback::SaveSolutionCallback{…}, u::ROCArray{…}, t::Float64, integrator::OrdinaryDiffEqCore.ODEIntegrator{…})
@ Trixi ~/workspace/dev/Trixi.jl/src/callbacks_step/save_solution.jl:181
[18] initialize_save_cb!
@ ~/workspace/dev/Trixi.jl/src/callbacks_step/save_solution.jl:171 [inlined]
[19] initialize!(u::ROCArray{…}, t::Float64, integrator::OrdinaryDiffEqCore.ODEIntegrator{…}, any_modified::Bool, c::DiscreteCallback{…}, cs::DiscreteCallback{…})
@ DiffEqBase ~/.julia/packages/DiffEqBase/CJTzr/src/callbacks.jl:17
[20] initialize!(::ROCArray{…}, ::Float64, ::OrdinaryDiffEqCore.ODEIntegrator{…}, ::Bool, ::DiscreteCallback{…}, ::DiscreteCallback{…}, ::Vararg{…})
@ DiffEqBase ~/.julia/packages/DiffEqBase/CJTzr/src/callbacks.jl:18
[21] initialize!(::ROCArray{…}, ::Float64, ::OrdinaryDiffEqCore.ODEIntegrator{…}, ::Bool, ::DiscreteCallback{…}, ::DiscreteCallback{…}, ::Vararg{…})
@ DiffEqBase ~/.julia/packages/DiffEqBase/CJTzr/src/callbacks.jl:18
[22] initialize!(::ROCArray{…}, ::Float64, ::OrdinaryDiffEqCore.ODEIntegrator{…}, ::Bool, ::DiscreteCallback{…}, ::DiscreteCallback{…}, ::Vararg{…})
@ DiffEqBase ~/.julia/packages/DiffEqBase/CJTzr/src/callbacks.jl:18
[23] initialize!
@ ~/.julia/packages/DiffEqBase/CJTzr/src/callbacks.jl:7 [inlined]
[24] initialize_callbacks!(integrator::OrdinaryDiffEqCore.ODEIntegrator{…}, initialize_save::Bool)
@ OrdinaryDiffEqCore ~/.julia/packages/OrdinaryDiffEqCore/rnOL4/src/solve.jl:1089
[25] _ode_init(prob::ODEProblem{…}, alg::CarpenterKennedy2N54{…}, timeseries_init::Tuple{}, ts_init::Tuple{}, ks_init::Tuple{}; saveat::Tuple{}, tstops::Tuple{}, d_discontinuities::Tuple{}, save_idxs::Nothing, save_everystep::Bool, save_on::Bool, save_discretes::Bool, save_start::Bool, save_end::Nothing, callback::CallbackSet{…}, dense::Bool, calck::Bool, dt::Float64, dtmin::Float64, dtmax::Float64, force_dtmin::Bool, adaptive::Bool, abstol::Nothing, reltol::Nothing, gamma::Nothing, qmin::Nothing, qmax::Nothing, qsteady_min::Nothing, qsteady_max::Nothing, beta1::Nothing, beta2::Nothing, qoldinit::Nothing, fullnormalize::Bool, failfactor::Int64, maxiters::Int64, internalnorm::typeof(DiffEqBase.ODE_DEFAULT_NORM), internalopnorm::typeof(LinearAlgebra.opnorm), isoutofdomain::typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN), unstable_check::typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK), verbose::Bool, controller::Nothing, timeseries_errors::Bool, dense_errors::Bool, advance_to_tstop::Bool, stop_at_next_tstop::Bool, initialize_save::Bool, progress::Bool, progress_steps::Int64, progress_name::String, progress_message::typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE), progress_id::Symbol, userdata::Nothing, allow_extrapolation::Bool, initialize_integrator::Bool, alias::ODEAliasSpecifier, initializealg::DiffEqBase.DefaultInit, rng::Nothing, save_noise::Bool, delta::Nothing, W::Nothing, P::Nothing, sqdt::Nothing, noise::Nothing, c::Nothing, rate_constants::Nothing, _cache::Nothing, _u::Nothing, _uprev::Nothing, seed::UInt64, kwargs::@Kwargs{})
@ OrdinaryDiffEqCore ~/.julia/packages/OrdinaryDiffEqCore/rnOL4/src/solve.jl:812
[26] _ode_init
@ ~/.julia/packages/OrdinaryDiffEqCore/rnOL4/src/solve.jl:47 [inlined]
[27] #__init#71
@ ~/.julia/packages/OrdinaryDiffEqCore/rnOL4/src/solve.jl:37 [inlined]
[28] __init (repeats 2 times)
@ ~/.julia/packages/OrdinaryDiffEqCore/rnOL4/src/solve.jl:19 [inlined]
[29] __solve(::ODEProblem{…}, ::CarpenterKennedy2N54{…}; kwargs::@Kwargs{…})
@ OrdinaryDiffEqCore ~/.julia/packages/OrdinaryDiffEqCore/rnOL4/src/solve.jl:9
[30] __solve
@ ~/.julia/packages/OrdinaryDiffEqCore/rnOL4/src/solve.jl:1 [inlined]
[31] solve_call(_prob::ODEProblem{…}, args::CarpenterKennedy2N54{…}; merge_callbacks::Bool, kwargshandle::Nothing, kwargs::@Kwargs{…})
@ DiffEqBase ~/.julia/packages/DiffEqBase/CJTzr/src/solve.jl:172
[32] solve_call
@ ~/.julia/packages/DiffEqBase/CJTzr/src/solve.jl:137 [inlined]
[33] #solve_up#38
@ ~/.julia/packages/DiffEqBase/CJTzr/src/solve.jl:646 [inlined]
[34] solve_up
@ ~/.julia/packages/DiffEqBase/CJTzr/src/solve.jl:619 [inlined]
[35] #solve#37
@ ~/.julia/packages/DiffEqBase/CJTzr/src/solve.jl:603 [inlined]
[36] top-level scope
@ ~/workspace/dev/Trixi.jl/examples/p4est_2d_dgsem/elixir_euler_source_terms_gpu.jl:60
[37] include(fname::String)
@ Base.MainInclude ./client.jl:494
[38] top-level scope
@ REPL[20]:1
in expression starting at /home/marco/workspace/dev/Trixi.jl/examples/p4est_2d_dgsem/elixir_euler_source_terms_gpu.jl:60
Some type information was truncated. Use `show(err)` to see complete types.
```
Apparently we do not retrieve the correct number of variables from: (Trixi.jl/src/callbacks_step/save_solution_dg.jl)
```julia
# Reinterpret the solution array as an array of conservative variables,
# compute the solution variables via broadcasting, and reinterpret the
# result as a plain array of floating point numbers
data = Array(reinterpret(eltype(u),
solution_variables.(reinterpret(SVector{nvariables(equations),
eltype(u)}, u),
Ref(equations))))
# Find out variable count by looking at output from `solution_variables` function
n_vars = size(data, 1)
```
When forcing the code to use the correct number of variables this problem is fixed.
2 条评论