-
Notifications
You must be signed in to change notification settings - Fork 112
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
Use Adapt.jl to change storage and element type #2212
Draft
vchuravy
wants to merge
1
commit into
main
Choose a base branch
from
vc/adapt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
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 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 |
---|---|---|
|
@@ -4,6 +4,7 @@ authors = ["Michael Schlottke-Lakemper <[email protected]>", "Gregor | |
version = "0.9.8-DEV" | ||
|
||
[deps] | ||
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" | ||
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" | ||
CodeTracking = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2" | ||
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9" | ||
|
@@ -64,6 +65,7 @@ TrixiMakieExt = "Makie" | |
TrixiNLsolveExt = "NLsolve" | ||
|
||
[compat] | ||
Adapt = "3.7, 4.0" | ||
Accessors = "0.1.12" | ||
CodeTracking = "1.0.5" | ||
ConstructionBase = "1.3" | ||
|
This file contains 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 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,22 @@ | ||
# By default, Julia/LLVM does not use fused multiply-add operations (FMAs). | ||
# Since these FMAs can increase the performance of many numerical algorithms, | ||
# we need to opt-in explicitly. | ||
# See https://ranocha.de/blog/Optimizing_EC_Trixi for further details. | ||
@muladd begin | ||
#! format: noindent | ||
|
||
# Wraps a Vector of Arrays, forwards `getindex` to the underlying Vector. | ||
# Implements `Adapt.adapt_structure` to allow offloading to the GPU which is | ||
# not possible for a plain Vector of Arrays. | ||
struct VecOfArrays{T <: AbstractArray} | ||
arrays::Vector{T} | ||
end | ||
Base.getindex(v::VecOfArrays, i::Int) = Base.getindex(v.arrays, i) | ||
Base.IndexStyle(v::VecOfArrays) = Base.IndexStyle(v.arrays) | ||
Base.size(v::VecOfArrays) = Base.size(v.arrays) | ||
Base.length(v::VecOfArrays) = Base.length(v.arrays) | ||
Base.eltype(v::VecOfArrays{T}) where {T} = T | ||
function Adapt.adapt_structure(to, v::VecOfArrays) | ||
return [Adapt.adapt(to, arr) for arr in v.arrays] |> VecOfArrays | ||
end | ||
end # @muladd |
This file contains 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 | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -30,19 +30,19 @@ mutable struct SemidiscretizationHyperbolic{Mesh, Equations, InitialCondition, | |||||||
|
||||||||
function SemidiscretizationHyperbolic{Mesh, Equations, InitialCondition, | ||||||||
BoundaryConditions, SourceTerms, Solver, | ||||||||
Cache}(mesh::Mesh, equations::Equations, | ||||||||
Cache}(mesh::Mesh, | ||||||||
equations::Equations, | ||||||||
initial_condition::InitialCondition, | ||||||||
boundary_conditions::BoundaryConditions, | ||||||||
source_terms::SourceTerms, | ||||||||
solver::Solver, | ||||||||
cache::Cache) where {Mesh, Equations, | ||||||||
cache::Cache, | ||||||||
performance_counter::PerformanceCounter) where {Mesh, Equations, | ||||||||
InitialCondition, | ||||||||
BoundaryConditions, | ||||||||
SourceTerms, | ||||||||
Solver, | ||||||||
Cache} | ||||||||
performance_counter = PerformanceCounter() | ||||||||
|
||||||||
new(mesh, equations, initial_condition, boundary_conditions, source_terms, | ||||||||
solver, cache, performance_counter) | ||||||||
end | ||||||||
|
@@ -74,14 +74,16 @@ function SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver | |||||||
|
||||||||
check_periodicity_mesh_boundary_conditions(mesh, _boundary_conditions) | ||||||||
|
||||||||
performance_counter = PerformanceCounter() | ||||||||
|
||||||||
SemidiscretizationHyperbolic{typeof(mesh), typeof(equations), | ||||||||
typeof(initial_condition), | ||||||||
typeof(_boundary_conditions), typeof(source_terms), | ||||||||
typeof(solver), typeof(cache)}(mesh, equations, | ||||||||
initial_condition, | ||||||||
_boundary_conditions, | ||||||||
source_terms, solver, | ||||||||
cache) | ||||||||
cache, performance_counter) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||
end | ||||||||
|
||||||||
# Create a new semidiscretization but change some parameters compared to the input. | ||||||||
|
@@ -103,6 +105,30 @@ function remake(semi::SemidiscretizationHyperbolic; uEltype = real(semi.solver), | |||||||
source_terms, boundary_conditions, uEltype) | ||||||||
end | ||||||||
|
||||||||
function Adapt.adapt_structure(to, semi::SemidiscretizationHyperbolic) | ||||||||
if !(typeof(semi.mesh) <: P4estMesh) | ||||||||
error("Adapt.adapt is only supported for semidiscretizations based on P4estMesh") | ||||||||
end | ||||||||
|
||||||||
mesh = semi.mesh | ||||||||
equations = Adapt.adapt_structure(to, semi.equations) | ||||||||
initial_condition = Adapt.adapt_structure(to, semi.initial_condition) | ||||||||
boundary_conditions = Adapt.adapt_structure(to, semi.boundary_conditions) | ||||||||
source_terms = Adapt.adapt_structure(to, semi.source_terms) | ||||||||
solver = Adapt.adapt_structure(to, semi.solver) | ||||||||
cache = Adapt.adapt_structure(to, semi.cache) | ||||||||
performance_counter = semi.performance_counter | ||||||||
|
||||||||
SemidiscretizationHyperbolic{typeof(mesh), typeof(equations), | ||||||||
typeof(initial_condition), | ||||||||
typeof(boundary_conditions), typeof(source_terms), | ||||||||
typeof(solver), typeof(cache)}(mesh, equations, | ||||||||
initial_condition, | ||||||||
boundary_conditions, | ||||||||
source_terms, solver, | ||||||||
cache, performance_counter) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||
end | ||||||||
|
||||||||
# general fallback | ||||||||
function digest_boundary_conditions(boundary_conditions, mesh, solver, cache) | ||||||||
boundary_conditions | ||||||||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶