-
Notifications
You must be signed in to change notification settings - Fork 151
Add AMDGPU CI and support AMDGPU through KernelAbstractions #2834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
38ac870
Add support for AMDGPU
vchuravy fd2f463
Add benchmark
vchuravy 1d32c22
Fix benchmark
vchuravy 005df50
Handle Trixi.log
vchuravy b69a005
Update benchmark
vchuravy 1c33900
Apply suggestions from code review
vchuravy 396d3c6
add 3D test
vchuravy 7881b61
update amdgpu test
vchuravy 2366843
Apply suggestion from @vchuravy
vchuravy 23fa348
add NEWS and update test/Project.toml
vchuravy bf9f5a3
remove dev dependencies
vchuravy b4b817e
tolerate more allocations
benegee 6efb053
Merge branch 'main' into vc/amdgpu
benegee 67d27de
Merge branch 'main' into vc/amdgpu
benegee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| [deps] | ||
| AMDGPU = "21141c5a-9bdb-4563-92ae-f87d6854732e" | ||
| JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" | ||
| OrdinaryDiffEqLowStorageRK = "b0944070-b475-4768-8dec-fb6eb410534d" | ||
| TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f" | ||
| Trixi = "a7f1ee26-1774-49b1-8366-f1abc58fbfcb" | ||
|
|
||
| [sources] | ||
| Trixi = {path = "../.."} | ||
|
|
||
| [compat] | ||
| AMDGPU = "2.3" | ||
| JSON = "1.4.0" | ||
| OrdinaryDiffEqLowStorageRK = "1.12.0" | ||
| TimerOutputs = "0.5.25" | ||
| Trixi = "0.16" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| using OrdinaryDiffEqLowStorageRK | ||
| using Trixi | ||
|
|
||
| ############################################################################### | ||
| # semidiscretization of the compressible Euler equations | ||
|
|
||
| equations = CompressibleEulerEquations3D(1.4) | ||
|
|
||
| function initial_condition_taylor_green_vortex(x, t, | ||
| equations::CompressibleEulerEquations3D) | ||
| A = 1.0 # magnitude of speed | ||
| Ms = 0.1 # maximum Mach number | ||
|
|
||
| rho = 1.0 | ||
| v1 = A * sin(x[1]) * cos(x[2]) * cos(x[3]) | ||
| v2 = -A * cos(x[1]) * sin(x[2]) * cos(x[3]) | ||
| v3 = 0.0 | ||
| p = (A / Ms)^2 * rho / equations.gamma # scaling to get Ms | ||
| p = p + | ||
| 1.0 / 16.0 * A^2 * rho * | ||
| (cos(2 * x[1]) * cos(2 * x[3]) + | ||
| 2 * cos(2 * x[2]) + 2 * cos(2 * x[1]) + cos(2 * x[2]) * cos(2 * x[3])) | ||
|
|
||
| return prim2cons(SVector(rho, v1, v2, v3, p), equations) | ||
| end | ||
|
|
||
| initial_condition = initial_condition_taylor_green_vortex | ||
|
|
||
| volume_flux = flux_ranocha | ||
| surface_flux = flux_lax_friedrichs | ||
| volume_integral = VolumeIntegralFluxDifferencing(volume_flux) | ||
| solver = DGSEM(polydeg = 5, surface_flux = surface_flux, volume_integral = volume_integral) | ||
|
|
||
| coordinates_min = (-1.0, -1.0, -1.0) .* pi | ||
| coordinates_max = (1.0, 1.0, 1.0) .* pi | ||
|
|
||
| initial_refinement_level = 1 | ||
| trees_per_dimension = (4, 4, 4) | ||
|
|
||
| mesh = P4estMesh(trees_per_dimension, polydeg = 1, | ||
| coordinates_min = coordinates_min, coordinates_max = coordinates_max, | ||
| periodicity = true, initial_refinement_level = initial_refinement_level) | ||
|
|
||
| semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver; | ||
| boundary_conditions = boundary_condition_periodic) | ||
|
|
||
| ############################################################################### | ||
| # ODE solvers, callbacks etc. | ||
|
|
||
| tspan = (0.0, 100.0) | ||
| ode = semidiscretize(semi, tspan; storage_type = nothing, real_type = nothing) | ||
|
|
||
| summary_callback = SummaryCallback() | ||
|
|
||
| stepsize_callback = StepsizeCallback(cfl = 0.1) | ||
|
|
||
| callbacks = CallbackSet(summary_callback, | ||
| stepsize_callback) | ||
|
|
||
| ############################################################################### | ||
| # run the simulation | ||
|
|
||
| maxiters = 200 | ||
|
|
||
| # disable warnings when maxiters is reached | ||
| integrator = init(ode, CarpenterKennedy2N54(williamson_condition = false), | ||
| dt = 1.0, | ||
| save_everystep = false, callback = callbacks, | ||
| maxiters = maxiters, verbose = false) | ||
|
|
||
| solve!(integrator) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| using Trixi | ||
| using AMDGPU | ||
| using TimerOutputs | ||
| using JSON | ||
|
|
||
| function main(elixir_path) | ||
|
|
||
| # setup | ||
| maxiters = 50 | ||
| initial_refinement_level = 3 | ||
| storage_type = ROCArray | ||
| real_type = Float64 | ||
|
|
||
| println("Warming up...") | ||
|
|
||
| # start simulation with tiny final time to trigger compilation | ||
| duration_compile = @elapsed begin | ||
| trixi_include(elixir_path, | ||
| tspan = (0.0, 1e-14), | ||
| storage_type = storage_type, | ||
| real_type = real_type) | ||
| end | ||
|
|
||
| println("Finished warm-up in $duration_compile seconds\n") | ||
| println("Starting simulation...") | ||
|
|
||
| # start the real simulation | ||
| duration_elixir = @elapsed trixi_include(elixir_path, | ||
| maxiters = maxiters, | ||
| initial_refinement_level = initial_refinement_level, | ||
| storage_type = storage_type, | ||
| real_type = real_type) | ||
|
|
||
| # store metrics (on every rank!) | ||
| metrics = Dict{String, Float64}("elapsed time" => duration_elixir) | ||
|
|
||
| # read TimerOutputs timings | ||
| timer = Trixi.timer() | ||
| metrics["total time"] = 1.0e-9 * TimerOutputs.tottime(timer) | ||
| metrics["rhs! time"] = 1.0e-9 * TimerOutputs.time(timer["rhs!"]) | ||
|
|
||
| # compute performance index | ||
| latest_semi = @invokelatest (@__MODULE__).semi | ||
| nrhscalls = Trixi.ncalls(latest_semi.performance_counter) | ||
| walltime = 1.0e-9 * take!(latest_semi.performance_counter) | ||
| metrics["PID"] = walltime * Trixi.mpi_nranks() / | ||
| (Trixi.ndofsglobal(latest_semi) * nrhscalls) | ||
|
|
||
| # write json file | ||
| open("metrics.out", "w") do f | ||
| indent = 2 | ||
| JSON.print(f, metrics, indent) | ||
| end | ||
| end | ||
|
|
||
| # hardcoded elixir | ||
| elixir_path = joinpath(@__DIR__(), "elixir_euler_taylor_green_vortex.jl") | ||
|
|
||
| main(elixir_path) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Package extension for adding AMDGPU-based features to Trixi.jl | ||
| module TrixiAMDGPUExt | ||
|
|
||
| using AMDGPU: AMDGPU, ROCArray, ROCDeviceArray | ||
| import AMDGPU.Device: @device_override | ||
| import AMDGPU.Runtime: Adaptor | ||
| import Trixi | ||
|
|
||
| function Trixi.storage_type(::Type{<:ROCArray}) | ||
| return ROCArray | ||
| end | ||
|
|
||
| function Trixi.unsafe_wrap_or_alloc(::Adaptor, vec, size) | ||
| return Trixi.unsafe_wrap_or_alloc(ROCDeviceArray, vec, size) | ||
| end | ||
|
|
||
| function Trixi.unsafe_wrap_or_alloc(::Type{<:ROCDeviceArray}, vec::ROCDeviceArray, size) | ||
| return reshape(vec, size) | ||
| end | ||
|
|
||
| @static if Trixi._PREFERENCE_LOG == "log_Trixi_NaN" | ||
| @device_override Trixi.log(x::Float64) = ccall("extern __ocml_log_f64", llvmcall, | ||
| Cdouble, | ||
| (Cdouble,), x) | ||
| @device_override Trixi.log(x::Float32) = ccall("extern __ocml_log_f32", llvmcall, | ||
| Cfloat, | ||
| (Cfloat,), x) | ||
| # TODO: Trixi.log(x::Float16) | ||
| end | ||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vchuravy marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| module TestAMDGPU2D | ||
|
|
||
| using Test | ||
| using Trixi | ||
|
|
||
| include("test_trixi.jl") | ||
|
|
||
| EXAMPLES_DIR = joinpath(examples_dir(), "p4est_2d_dgsem") | ||
|
|
||
| # Start with a clean environment: remove Trixi.jl output directory if it exists | ||
| outdir = "out" | ||
| isdir(outdir) && rm(outdir, recursive = true) | ||
|
|
||
| @testset "AMDGPU 2D" begin | ||
| #! format: noindent | ||
|
|
||
| @trixi_testset "elixir_advection_basic_gpu.jl native" begin | ||
| @test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_basic_gpu.jl"), | ||
| # Expected errors are exactly the same as with TreeMesh! | ||
| l2=8.311947673061856e-6, | ||
| linf=6.627000273229378e-5) | ||
| # Ensure that we do not have excessive memory allocations | ||
| # (e.g., from type instabilities) | ||
| semi = ode.p # `semidiscretize` adapts the semi, so we need to obtain it from the ODE problem. | ||
| @test_allocations(Trixi.rhs!, semi, sol, 1000) | ||
| @test real(ode.p.solver) == Float64 | ||
| @test real(ode.p.solver.basis) == Float64 | ||
| @test real(ode.p.solver.mortar) == Float64 | ||
| # TODO: `mesh` is currently not `adapt`ed correctly | ||
| @test real(ode.p.mesh) == Float64 | ||
|
|
||
| @test ode.u0 isa Array | ||
| @test ode.p.solver.basis.derivative_matrix isa Array | ||
|
|
||
| @test Trixi.storage_type(ode.p.cache.elements) === Array | ||
| @test Trixi.storage_type(ode.p.cache.interfaces) === Array | ||
| @test Trixi.storage_type(ode.p.cache.boundaries) === Array | ||
| @test Trixi.storage_type(ode.p.cache.mortars) === Array | ||
| end | ||
|
|
||
| @trixi_testset "elixir_advection_basic_gpu.jl Float32 / AMDGPU" begin | ||
| # Using AMDGPU inside the testset since otherwise the bindings are hiddend by the anonymous modules | ||
| using AMDGPU | ||
| @test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_basic_gpu.jl"), | ||
| # Expected errors are exactly the same as with TreeMesh! | ||
| l2=[Float32(8.311947673061856e-6)], | ||
| linf=[Float32(6.627000273229378e-5)], | ||
| RealT_for_test_tolerances=Float32, | ||
| real_type=Float32, | ||
| storage_type=ROCArray) | ||
| # Ensure that we do not have excessive memory allocations | ||
| # (e.g., from type instabilities) | ||
| semi = ode.p # `semidiscretize` adapts the semi, so we need to obtain it from the ODE problem. | ||
| @test_allocations(Trixi.rhs!, semi, sol, 50_000) | ||
| @test real(ode.p.solver) == Float32 | ||
| @test real(ode.p.solver.basis) == Float32 | ||
| @test real(ode.p.solver.mortar) == Float32 | ||
| # TODO: `mesh` is currently not `adapt`ed correctly | ||
| @test real(ode.p.mesh) == Float64 | ||
|
|
||
| @test ode.u0 isa ROCArray | ||
| @test ode.p.solver.basis.derivative_matrix isa ROCArray | ||
|
|
||
| @test Trixi.storage_type(ode.p.cache.elements) === ROCArray | ||
| @test Trixi.storage_type(ode.p.cache.interfaces) === ROCArray | ||
| @test Trixi.storage_type(ode.p.cache.boundaries) === ROCArray | ||
| @test Trixi.storage_type(ode.p.cache.mortars) === ROCArray | ||
| end | ||
|
|
||
| # Clean up afterwards: delete Trixi.jl output directory | ||
| @test_nowarn isdir(outdir) && rm(outdir, recursive = true) | ||
| end | ||
| end # module |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.