From 3ea0b754cc00ee95b631cb587ef74784fda68e79 Mon Sep 17 00:00:00 2001 From: Luke Morris Date: Sat, 7 Dec 2024 12:21:50 -0500 Subject: [PATCH] Encapsulate, remove dead code, simplify control flow --- src/.simulation.jl.swp | Bin 0 -> 53248 bytes src/simulation.jl | 176 +++++++++++++--------------------------- test/simulation_core.jl | 2 +- 3 files changed, 58 insertions(+), 120 deletions(-) create mode 100644 src/.simulation.jl.swp diff --git a/src/.simulation.jl.swp b/src/.simulation.jl.swp new file mode 100644 index 0000000000000000000000000000000000000000..10b03bb72e74d6ae98d20530572db99258281185 GIT binary patch literal 53248 zcmeI536xt`nde0onk4~}0HI+5&kLY(s$^V*Oh!qC6t-gw-bj_5fN@kR=~b0tm89rN zWfy5f2sBGV!_3g#!;&zE1`-HoV9tbQ8J30+(rgV3%xR#z2|XTYmIGmihGv?r=l8$M zTO^fTHX*=_>iBO-_ucio+qd2OW}mWe`_AB^!g!9qN91z%zGQm-t=|q#`^k;D+(Nl> zFl_6=vHv!2pV~UMV{*^f)5f=6xaGn^y;&*O2PAo+&2Z!9W;NWnC9ITNe2EIz)Hg=$ z%EqX+*sYg4wPu5m0jY;ULkbKjaMBd$cIL(|Iy3jw@l8)r9_!Yw3C=lt?@4DjOgN;# zkOD&r3@I?Az>oq%3JfVQq`;5@zk3wuv>uv!5!F7$RsE3rd_d3VY3}zG?(=ZZ^M|3M#-`+b)C{8G>Jhq~WB|9|Xx?(^O0!Z*7L`g;DJ3lH7rYkHnP$c10(K7Z8n z{0tYq&VM?B`1~L2!ne84y*Ww|&s%z)yWru+kOD&r3@I?Az>oq%3JfVQq`;5@ zLkbKjFr>hc0>2Rol&iVi(sgE&*qOM}RLs zESI|lJRj@_7lCuY+2F%x=5lWWw}2LCg44jM;4cumUk+XdLa-H#gSFr+a3(kd{8y9% zZvZ!dgWwYI4HOP{fY*U5!Fk|Y2Xc)z*|rd z+yI^n&H-OUq3~I79XJG*z;nQ*;ECXo;1S^A;1eh(-VFW_6u_5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Znt&b#jCQl4q}XCn_Hc=)vg=q6@@7lnX9#> z4}~Mptv@j%#dveeNn(gqyyS3PuHPIxsD@dCtmOX}Aj`iCNd8B>Hh=$uoc}5CNpKms z1SpQ)1Mmst{JX&AU=P191ZM)-{=X0I0XKtXun+77yTJwEso?j4?)&>JxC`6}ra%Dh zMK|z$@DcE4Af3U>Km_#8za3!sH>ALj0z(Q6DKMnKkOD&r3@I?Az;6QuCf4QnH{jO7 zDuLcPs~Qf7Gch2{*&tVbLXO9LXx=`F9Z3!(sNB)p9HW?|da3x_x^{vk=$^KdNFw^2 zWHJsB`IINoJS(zV-w2u9oSm4jK2v0BIWrocdutUQP)sZnOX0@rGwnO(1`59!iyAS~ zcc6F;sO_&_Rdk zQ^W+k@uI6Y4agZ)`s6YDt_-6@;rf$qXRJBr!hEv|dI4#BjNxXSz7kVcoaagjdC6Yd z!_elC=z5*nDOPM*bDcZ}CI276{{26&iA(Kz+9sDJ}PO=J1&OrxG$0H8WZSs#*}IuH8>cNaw1vT`)WilF~q>0N@`9M zST6z0^W{4JbXa8ZTrdt3>HE|w9KkY&uW%N?s$Ofy*Gpo&r$Pm93D3Cx{YKk${MWn6 ztwPj{ef)Y%+57xedGsKdj!QJcg#vHBP3B;_2V2PS>dDj`FE<6`5F@VFYs(_nj}bA&n$BIV#5 z2M|*7|0T%J-vE;T*Eu=iZsht;fE&SczYn;G3>qpH$t3e?tlkDKMnKkOD&r z3@I?Az>oq%3ZyA;43FJoaNen7PFwm;9rXx6-tSy*2SqX*-kdbNIcc_8N8yluK^tRc scyp3J)-1n?k`>Rn37{ZzUC3&RNvMF0Q* literal 0 HcmV?d00001 diff --git a/src/simulation.jl b/src/simulation.jl index bc6ab66c..b9f5cc05 100644 --- a/src/simulation.jl +++ b/src/simulation.jl @@ -132,33 +132,6 @@ function hook_AVC_caching(c::AllocVecCall, resolved_form::Symbol, ::CUDABackend) :($(c.name) = CuVector{$(c.T)}(undef, nparts(mesh, $(QuoteNode(resolved_form))))) end -""" - compile_var(alloc_vectors::Vector{AllocVecCall}) - -This creates the vector allocations that will be used by the simulation body for in-place operations. -""" -function compile_var(alloc_vectors::Vector{AllocVecCall}) - return quote $(Expr.(alloc_vectors)...) end -end - -#= function get_form_number(d::SummationDecapode, var_id::Int) - type = d[var_id, :type] - if type == :Form0 - return 0 - elseif type == :Form1 - return 1 - elseif type == :Form2 - return 2 - end - return -1 -end - -# ! WARNING: This may not work if names are not unique, use above instead -function get_form_number(d::SummationDecapode, var_name::Symbol) -var_id = first(incident(d, var_name, :name)) -return get_form_number(d, var_id) -end =# - # TODO: This should be edited when we replace types as symbols with types as Julia types function is_form(d::SummationDecapode, var_id::Int) type = d[var_id, :type] @@ -224,49 +197,31 @@ end Base.showerror(io::IO, e::InvalidCodeTargetException) = print(io, "Provided code target $(e.code_target) is not yet supported in simulations") -""" - compile_env(d::SummationDecapode, dec_matrices::Vector{Symbol}, con_dec_operators::Vector{Symbol}, code_target::AbstractGenerationTarget) +# TODO: This function should be handled with dispatch. +""" compile_env(d::SummationDecapode, basic_dec_ops::Vector{Symbol}, contracted_ops::Vector{Symbol}, code_target::AbstractGenerationTarget) -This creates the symbol to function linking for the simulation output. Those run through the `default_dec` backend -expect both an in-place and an out-of-place variant in that order. User defined operations only support out-of-place. +Emit code to define functions given operator Symbols. + +Default operations return a tuple of an in-place and an out-of-place function. User-defined operations return an out-of-place function. """ -function compile_env(d::SummationDecapode, dec_matrices::Vector{Symbol}, con_dec_operators::Vector{Symbol}, code_target::AbstractGenerationTarget) - defined_ops = Set(con_dec_operators) +function compile_env(d::SummationDecapode, basic_dec_ops::Set{Symbol}, contracted_ops::Vector{Symbol}, code_target::AbstractGenerationTarget) + default_generation = @match code_target begin + ::CPUBackend => :default_dec_matrix_generate + ::CUDABackend => :default_dec_cu_matrix_generate + _ => throw(InvalidCodeTargetException(code_target)) + end defs = quote end - for op in dec_matrices - op in defined_ops && continue - + for op in setdiff(basic_dec_ops ∪ d[:op1] ∪ d[:op2], contracted_ops ∪ [DerivOp] ∪ ARITHMETIC_OPS) quote_op = QuoteNode(op) - mat_op = add_stub(GENSIM_INPLACE_STUB, op) - - # TODO: Add support for user-defined code targets - default_generation = @match code_target begin - ::CPUBackend => :default_dec_matrix_generate - ::CUDABackend => :default_dec_cu_matrix_generate - _ => throw(InvalidCodeTargetException(code_target)) - end - - def = :(($mat_op, $op) = $(default_generation)(mesh, $quote_op, hodge)) + def = op in basic_dec_ops ? + :(($(add_inplace_stub(op)), $op) = $(default_generation)(mesh, $quote_op, hodge)) : + :($op = operators(mesh, $quote_op)) push!(defs.args, def) - - push!(defined_ops, op) end - # Add in user-defined operations - for op in vcat(d[:op1], d[:op2]) - if op == DerivOp || op in defined_ops || op in ARITHMETIC_OPS - continue - end - ops = QuoteNode(op) - def = :($op = operators(mesh, $ops)) - push!(defs.args, def) - - push!(defined_ops, op) - end - - return defs + defs end struct AmbiguousNameException <: Exception @@ -372,15 +327,16 @@ const PROMOTE_ARITHMETIC_MAP = Dict(:(+) => :.+, :.= => :.=) """ - compile(d::SummationDecapode, inputs::Vector{Symbol}, alloc_vectors::Vector{AllocVecCall}, optimizable_dec_operators::Set{Symbol}, dimension::Int, stateeltype::DataType, code_target::AbstractGenerationTarget, preallocate::Bool) + compile(d::SummationDecapode, inputs::Vector{Symbol}, inplace_dec_ops::Set{Symbol}, dimension::Int, stateeltype::DataType, code_target::AbstractGenerationTarget, preallocate::Bool) Function that compiles the computation body. `d` is the input Decapode, `inputs` is a vector of state variables and literals, -`alloc_vec` should be empty when passed in, `optimizable_dec_operators` is a collection of all DEC operator symbols that can use special +`inplace_dec_ops` is a collection of all DEC operator symbols that can use special in-place methods, `dimension` is the dimension of the problem (usually 1 or 2), `stateeltype` is the type of the state elements (usually Float32 or Float64), `code_target` determines what architecture the code is compiled for (either CPU or CUDA), and `preallocate` which is set to `true` by default and determines if intermediate results can be preallocated.. """ -function compile(d::SummationDecapode, inputs::Vector{Symbol}, alloc_vectors::Vector{AllocVecCall}, optimizable_dec_operators::Set{Symbol}, dimension::Int, stateeltype::DataType, code_target::AbstractGenerationTarget, preallocate::Bool) +function compile(d::SummationDecapode, inputs::Vector{Symbol}, inplace_dec_ops::Set{Symbol}, dimension::Int, stateeltype::DataType, code_target::AbstractGenerationTarget, preallocate::Bool) + alloc_vectors = Vector{AllocVecCall}() # Get the Vars of the inputs (probably state Vars). visited_Var = falses(nparts(d, :Var)) @@ -417,7 +373,7 @@ function compile(d::SummationDecapode, inputs::Vector{Symbol}, alloc_vectors::Ve # TODO: Check to see if this is a DEC operator if preallocate && is_form(d, t) - if operator in optimizable_dec_operators + if operator in inplace_dec_ops equality = PROMOTE_ARITHMETIC_MAP[equality] operator = add_stub(GENSIM_INPLACE_STUB, operator) push!(alloc_vectors, AllocVecCall(tname, d[t, :type], dimension, stateeltype, code_target)) @@ -463,7 +419,7 @@ function compile(d::SummationDecapode, inputs::Vector{Symbol}, alloc_vectors::Ve equality = PROMOTE_ARITHMETIC_MAP[equality] push!(alloc_vectors, AllocVecCall(rname, d[r, :type], dimension, stateeltype, code_target)) end - elseif operator in optimizable_dec_operators + elseif operator in inplace_dec_ops operator = add_stub(GENSIM_INPLACE_STUB, operator) equality = PROMOTE_ARITHMETIC_MAP[equality] push!(alloc_vectors, AllocVecCall(rname, d[r, :type], dimension, stateeltype, code_target)) @@ -517,7 +473,7 @@ function compile(d::SummationDecapode, inputs::Vector{Symbol}, alloc_vectors::Ve end end - eq_exprs = Expr.(op_order) + Expr.(op_order), alloc_vectors end """ @@ -581,32 +537,24 @@ function infer_overload_compiler!(d::SummationDecapode, dimension::Int) end end -""" - init_dec_matrices!(d::SummationDecapode, dec_matrices::Vector{Symbol}, optimizable_dec_operators::Set{Symbol}) - -Collects all DEC operators that are concrete matrices. -""" -function init_dec_matrices!(d::SummationDecapode, dec_matrices::Vector{Symbol}, optimizable_dec_operators::Set{Symbol}) - for op_name in vcat(d[:op1], d[:op2]) - op_name in optimizable_dec_operators && push!(dec_matrices, op_name) - end -end - -""" link_contracted_operators!(d::SummationDecapode, contract_defs::Expr, con_dec_operators::Set{Symbol}, code_target::AbstractGenerationTarget) +""" link_contracted_operators!(d::SummationDecapode, code_target::AbstractGenerationTarget) Emit code to pre-multiply unique sequences of matrix operations, and rename corresponding operations. """ -function link_contracted_operators!(d::SummationDecapode, contract_defs::Expr, con_dec_operators::Vector{Symbol}, code_target::AbstractGenerationTarget) +function link_contracted_operators!(d::SummationDecapode, code_target::AbstractGenerationTarget) + contracted_defs = quote end + contracted_ops = Symbol[] chain_idxs = findall(x -> x isa AbstractArray, d[:op1]) for (i, chain) in enumerate(unique(d[chain_idxs, :op1])) LHS = add_stub(Symbol("GenSim-ConMat"), Symbol(i-1)) RHS = reverse!(add_inplace_stub.(chain)) - push!(con_dec_operators, LHS) - push!(contract_defs.args, mat_def_expr(LHS, RHS, code_target), mat_mul_func_expr(LHS)) + push!(contracted_ops, LHS) + push!(contracted_defs.args, mat_def_expr(LHS, RHS, code_target), mat_mul_func_expr(LHS)) d[findall(==(chain), d[:op1]), :op1] = LHS end + contracted_defs, contracted_ops end # Given the name of a matrix, return an Expr that multiplies by that matrix. @@ -664,7 +612,6 @@ to operator mappings to return a simulator that can be used to solve the represe `multigrid`: Enables multigrid methods during code generation. If `true`, then the function produced by `gensim` will expect a `PrimalGeometricMapSeries`. (Defaults to `false`) """ function gensim(user_d::SummationDecapode, input_vars::Vector{Symbol}; dimension::Int=2, stateeltype::DataType = Float64, code_target::AbstractGenerationTarget = CPUTarget(), preallocate::Bool = true, contract::Bool = true, multigrid::Bool = false) - (dimension == 1 || dimension == 2) || throw(UnsupportedDimensionException(dimension)) @@ -672,61 +619,52 @@ function gensim(user_d::SummationDecapode, input_vars::Vector{Symbol}; dimension throw(UnsupportedStateeltypeException(stateeltype)) # Explicit copy for safety - gen_d = deepcopy(user_d) + d = deepcopy(user_d) - recognize_types(gen_d) + recognize_types(d) # Makes copy - gen_d = expand_operators(gen_d) - - dec_matrices = Vector{Symbol}() - alloc_vectors = Vector{AllocVecCall}() + d = expand_operators(d) - vars = get_vars_code(gen_d, input_vars, stateeltype, code_target) - tars = set_tanvars_code(gen_d, code_target) + vars = get_vars_code(d, input_vars, stateeltype, code_target) + tars = set_tanvars_code(d, code_target) - infer_overload_compiler!(gen_d, dimension) - convert_cs_ps_to_infer!(gen_d) - infer_overload_compiler!(gen_d, dimension) + infer_overload_compiler!(d, dimension) + convert_cs_ps_to_infer!(d) + infer_overload_compiler!(d, dimension) - # TODO: This should probably be followed by an expand_operators. - replace_names!(gen_d, Pair{Symbol, Any}[], Pair{Symbol, Symbol}[(:∧₀₀ => :.*)]) - open_operators!(gen_d, dimension = dimension) - infer_overload_compiler!(gen_d, dimension) + # XXX: expand_operators should be called if any replacement is a chain of operations. + replace_names!(d, Pair{Symbol, Any}[], Pair{Symbol, Symbol}[(:∧₀₀ => :.*)]) + open_operators!(d, dimension = dimension) + infer_overload_compiler!(d, dimension) - # Generate necessary fundamental DEC operators. - optimizable_dec_operators = Set([:⋆₀, :⋆₁, :⋆₂, :⋆₀⁻¹, :⋆₂⁻¹, - :d₀, :d₁, :dual_d₀, :d̃₀, :dual_d₁, :d̃₁, - :avg₀₁]) - extra_dec_operators = Set([:⋆₁⁻¹, :∧₀₁, :∧₁₀, :∧₁₁, :∧₀₂, :∧₂₀]) + # Determine basic DEC operators to generate. + matrix_dec_ops = Set([:⋆₀, :⋆₁, :⋆₂, :⋆₀⁻¹, :⋆₂⁻¹, :d₀, :d₁, :dual_d₀, :d̃₀, :dual_d₁, :d̃₁, :avg₀₁]) + non_matrix_dec_ops = Set([:⋆₁⁻¹, :∧₀₁, :∧₁₀, :∧₁₁, :∧₀₂, :∧₂₀]) + dec_ops = matrix_dec_ops ∪ non_matrix_dec_ops - init_dec_matrices!(gen_d, dec_matrices, union(optimizable_dec_operators, extra_dec_operators)) + basic_dec_ops = Set{Symbol}(dec_ops ∩ (d[:op1] ∪ d[:op2])) - # Pre-multiply sequences of matrices. - contract_defs = quote end - contracted_dec_operators = Symbol[] - if contract - contract_operators!(gen_d, white_list = optimizable_dec_operators) - link_contracted_operators!(gen_d, contract_defs, contracted_dec_operators, code_target) - end + contract && contract_operators!(d, white_list = matrix_dec_ops) + contracted_defs, contracted_ops = link_contracted_operators!(d, code_target) - union!(optimizable_dec_operators, contracted_dec_operators, extra_dec_operators) + inplace_dec_ops = dec_ops ∪ contracted_ops # Compilation of the simulation - equations = compile(gen_d, input_vars, alloc_vectors, optimizable_dec_operators, dimension, stateeltype, code_target, preallocate) + equations, alloc_vectors = compile(d, input_vars, inplace_dec_ops, dimension, stateeltype, code_target, preallocate) data = post_process_vector_allocs(alloc_vectors, code_target) - func_defs = compile_env(gen_d, dec_matrices, contracted_dec_operators, code_target) - vect_defs = compile_var(alloc_vectors) + func_defs = compile_env(d, basic_dec_ops, contracted_ops, code_target) + vect_defs = quote $(Expr.(alloc_vectors)...) end - prologue = quote end - multigrid && push!(prologue.args, :(mesh = finest_mesh(mesh))) + multigrid_defs = quote end + multigrid && push!(multigrid_defs.args, :(mesh = finest_mesh(mesh))) quote (mesh, operators, hodge=GeometricHodge()) -> begin $func_defs - $contract_defs - $prologue + $contracted_defs + $multigrid_defs $vect_defs f(__du__, __u__, __p__, __t__) = begin $vars diff --git a/test/simulation_core.jl b/test/simulation_core.jl index 1ff9f448..5d6f3d0b 100644 --- a/test/simulation_core.jl +++ b/test/simulation_core.jl @@ -232,7 +232,7 @@ import Decapodes: compile_env, InvalidCodeTargetException # Test that error throws on unknown code target let d = @decapode begin end struct BadTarget <: AbstractGenerationTarget end - @test_throws InvalidCodeTargetException compile_env(d, [:test], Symbol[], BadTarget()) + @test_throws InvalidCodeTargetException compile_env(d, Set{Symbol}([:test]), Symbol[], BadTarget()) end end