From ca8025d2c6a796ca56575f6a2ae83f06891515c3 Mon Sep 17 00:00:00 2001 From: Samuel Omlin Date: Fri, 6 Dec 2024 18:16:07 +0100 Subject: [PATCH 01/16] move storage of state to caller --- src/ParallelKernel/init_parallel_kernel.jl | 53 +++++++++++++++------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/src/ParallelKernel/init_parallel_kernel.jl b/src/ParallelKernel/init_parallel_kernel.jl index dbd8bf2a..259ff234 100644 --- a/src/ParallelKernel/init_parallel_kernel.jl +++ b/src/ParallelKernel/init_parallel_kernel.jl @@ -87,28 +87,49 @@ function init_parallel_kernel(caller::Module, package::Symbol, numbertype::DataT end +function Metadata_PK() + :(module $MOD_METADATA_PK # NOTE: there cannot be any newline before 'module $MOD_METADATA_PK' or it will create a begin end block and the module creation will fail. + let + global is_initialized, set_initialized, set_package, get_package, set_numbertype, get_numbertype, set_inbounds, get_inbounds, set_padding, get_padding, check_initialized, check_already_initialized + _is_initialized::Dict{Module, Bool} = Dict{Module, Bool}() + package::Dict{Module, Symbol} = Dict{Module, Symbol}() + numbertype::Dict{Module, DataType} = Dict{Module, DataType}() + inbounds::Dict{Module, Bool} = Dict{Module, Bool}() + padding::Dict{Module, Bool} = Dict{Module, Bool}() + set_initialized(caller::Module, flag::Bool) = (_is_initialized[caller] = flag) + is_initialized(caller::Module) = haskey(_is_initialized, caller) && _is_initialized[caller] + set_package(caller::Module, pkg::Symbol) = (package[caller] = pkg) + get_package(caller::Module) = package[caller] + set_numbertype(caller::Module, T::DataType) = (numbertype[caller] = T) + get_numbertype(caller::Module) = numbertype[caller] + set_inbounds(caller::Module, flag::Bool) = (inbounds[caller] = flag) + get_inbounds(caller::Module) = inbounds[caller] + set_padding(caller::Module, flag::Bool) = (padding[caller] = flag) + get_padding(caller::Module) = padding[caller] + end + end) +end + +createmeta_PK(caller::Module) = if !hasmeta_PK(caller) @eval(caller, $(Metadata_PK())) end + + macro is_initialized() is_initialized(__module__) end macro get_package() esc(get_package(__module__)) end # NOTE: escaping is required here, to avoid that the symbol is evaluated in this module, instead of just being returned as a symbol. macro get_numbertype() get_numbertype(__module__) end macro get_inbounds() get_inbounds(__module__) end macro get_padding() get_padding(__module__) end let - global is_initialized, set_initialized, set_package, get_package, set_numbertype, get_numbertype, set_inbounds, get_inbounds, set_padding, get_padding, check_initialized, check_already_initialized - _is_initialized::Dict{Module, Bool} = Dict{Module, Bool}() - package::Dict{Module, Symbol} = Dict{Module, Symbol}() - numbertype::Dict{Module, DataType} = Dict{Module, DataType}() - inbounds::Dict{Module, Bool} = Dict{Module, Bool}() - padding::Dict{Module, Bool} = Dict{Module, Bool}() - set_initialized(caller::Module, flag::Bool) = (_is_initialized[caller] = flag) - is_initialized(caller::Module) = haskey(_is_initialized, caller) && _is_initialized[caller] - set_package(caller::Module, pkg::Symbol) = (package[caller] = pkg) - get_package(caller::Module) = package[caller] - set_numbertype(caller::Module, T::DataType) = (numbertype[caller] = T) - get_numbertype(caller::Module) = numbertype[caller] - set_inbounds(caller::Module, flag::Bool) = (inbounds[caller] = flag) - get_inbounds(caller::Module) = inbounds[caller] - set_padding(caller::Module, flag::Bool) = (padding[caller] = flag) - get_padding(caller::Module) = padding[caller] + global is_initialized, set_initialized, set_package, get_package, set_numbertype, get_numbertype, set_inbounds, get_inbounds, set_padding, get_padding, check_initialized, check_already_initialized + set_initialized(caller::Module, flag::Bool) = (createmeta_PK(caller); @eval(caller, $MOD_METADATA_PK.set_initialized($caller, $flag))) + is_initialized(caller::Module) = hasmeta_PK(caller) && @eval(caller, $MOD_METADATA_PK.is_initialized($caller)) + set_package(caller::Module, pkg::Symbol) = (createmeta_PK(caller); @eval(caller, $MOD_METADATA_PK.set_package($caller, $(quote_expr(pkg))))) + get_package(caller::Module) = hasmeta_PK(caller) ? @eval(caller, $MOD_METADATA_PK.get_package($caller)) : PKG_NONE + set_numbertype(caller::Module, T::DataType) = (createmeta_PK(caller); @eval(caller, $MOD_METADATA_PK.set_numbertype($caller, $T))) + get_numbertype(caller::Module) = hasmeta_PK(caller) ? @eval(caller, $MOD_METADATA_PK.get_numbertype($caller)) : NUMBERTYPE_NONE + set_inbounds(caller::Module, flag::Bool) = (createmeta_PK(caller); @eval(caller, $MOD_METADATA_PK.set_inbounds($caller, $flag))) + get_inbounds(caller::Module) = hasmeta_PK(caller) ? @eval(caller, $MOD_METADATA_PK.get_inbounds($caller)) : INBOUNDS_DEFAULT + set_padding(caller::Module, flag::Bool) = (createmeta_PK(caller); @eval(caller, $MOD_METADATA_PK.set_padding($caller, $flag))) + get_padding(caller::Module) = hasmeta_PK(caller) ? @eval(caller, $MOD_METADATA_PK.get_padding($caller)) : PADDING_DEFAULT check_initialized(caller::Module) = if !is_initialized(caller) @NotInitializedError("no ParallelKernel macro or function can be called before @init_parallel_kernel in each module (missing call in $caller).") end check_already_initialized(caller::Module) = if is_initialized(caller) @IncoherentCallError("ParallelKernel has already been initialized for the module $caller.") end end From c37a1b3884de1bb832a889a72c6dbefaaace4039 Mon Sep 17 00:00:00 2001 From: Samuel Omlin Date: Fri, 6 Dec 2024 18:17:02 +0100 Subject: [PATCH 02/16] move storage of state to caller --- src/init_parallel_stencil.jl | 75 ++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 24 deletions(-) diff --git a/src/init_parallel_stencil.jl b/src/init_parallel_stencil.jl index cfa923fd..4855a5c2 100644 --- a/src/init_parallel_stencil.jl +++ b/src/init_parallel_stencil.jl @@ -68,6 +68,41 @@ function init_parallel_stencil(caller::Module, package::Symbol, numbertype::Data end +function Metadata_PS() + :(module $MOD_METADATA_PS # NOTE: there cannot be any newline before 'module $MOD_METADATA_PS' or it will create a begin end block and the module creation will fail. + let + global is_initialized, set_initialized, set_package, get_package, set_numbertype, get_numbertype, set_ndims, get_ndims, set_inbounds, get_inbounds, set_padding, get_padding, set_memopt, get_memopt, set_nonconst_metadata, get_nonconst_metadata, check_initialized, check_already_initialized + _is_initialized::Dict{Module, Bool} = Dict{Module, Bool}() + package::Dict{Module, Symbol} = Dict{Module, Symbol}() + numbertype::Dict{Module, DataType} = Dict{Module, DataType}() + ndims::Dict{Module, Integer} = Dict{Module, Integer}() + inbounds::Dict{Module, Bool} = Dict{Module, Bool}() + padding::Dict{Module, Bool} = Dict{Module, Bool}() + memopt::Dict{Module, Bool} = Dict{Module, Bool}() + nonconst_metadata::Dict{Module, Bool} = Dict{Module, Bool}() + set_initialized(caller::Module, flag::Bool) = (_is_initialized[caller] = flag) + is_initialized(caller::Module) = haskey(_is_initialized, caller) && _is_initialized[caller] + set_package(caller::Module, pkg::Symbol) = (package[caller] = pkg) + get_package(caller::Module) = package[caller] + set_numbertype(caller::Module, T::DataType) = (numbertype[caller] = T) + get_numbertype(caller::Module) = numbertype[caller] + set_ndims(caller::Module, n::Integer) = (ndims[caller] = n) + get_ndims(caller::Module) = ndims[caller] + set_inbounds(caller::Module, flag::Bool) = (inbounds[caller] = flag) + get_inbounds(caller::Module) = inbounds[caller] + set_padding(caller::Module, flag::Bool) = (padding[caller] = flag) + get_padding(caller::Module) = padding[caller] + set_memopt(caller::Module, flag::Bool) = (memopt[caller] = flag) + get_memopt(caller::Module) = memopt[caller] + set_nonconst_metadata(caller::Module, flag::Bool) = (nonconst_metadata[caller] = flag) + get_nonconst_metadata(caller::Module) = nonconst_metadata[caller] + end + end) +end + +createmeta_PS(caller::Module) = if !hasmeta_PS(caller) @eval(caller, $(Metadata_PS())) end + + macro is_initialized() is_initialized(__module__) end macro get_package() esc(get_package(__module__)) end # NOTE: escaping is required here, to avoid that the symbol is evaluated in this module, instead of just being returned as a symbol. macro get_numbertype() get_numbertype(__module__) end @@ -78,30 +113,22 @@ macro get_memopt() get_memopt(__module__) end macro get_nonconst_metadata() get_nonconst_metadata(__module__) end let global is_initialized, set_initialized, set_package, get_package, set_numbertype, get_numbertype, set_ndims, get_ndims, set_inbounds, get_inbounds, set_padding, get_padding, set_memopt, get_memopt, set_nonconst_metadata, get_nonconst_metadata, check_initialized, check_already_initialized - _is_initialized::Dict{Module, Bool} = Dict{Module, Bool}() - package::Dict{Module, Symbol} = Dict{Module, Symbol}() - numbertype::Dict{Module, DataType} = Dict{Module, DataType}() - ndims::Dict{Module, Integer} = Dict{Module, Integer}() - inbounds::Dict{Module, Bool} = Dict{Module, Bool}() - padding::Dict{Module, Bool} = Dict{Module, Bool}() - memopt::Dict{Module, Bool} = Dict{Module, Bool}() - nonconst_metadata::Dict{Module, Bool} = Dict{Module, Bool}() - set_initialized(caller::Module, flag::Bool) = (_is_initialized[caller] = flag) - is_initialized(caller::Module) = haskey(_is_initialized, caller) && _is_initialized[caller] - set_package(caller::Module, pkg::Symbol) = (package[caller] = pkg) - get_package(caller::Module) = package[caller] - set_numbertype(caller::Module, T::DataType) = (numbertype[caller] = T) - get_numbertype(caller::Module) = numbertype[caller] - set_ndims(caller::Module, n::Integer) = (ndims[caller] = n) - get_ndims(caller::Module) = ndims[caller] - set_inbounds(caller::Module, flag::Bool) = (inbounds[caller] = flag) - get_inbounds(caller::Module) = inbounds[caller] - set_padding(caller::Module, flag::Bool) = (padding[caller] = flag) - get_padding(caller::Module) = padding[caller] - set_memopt(caller::Module, flag::Bool) = (memopt[caller] = flag) - get_memopt(caller::Module) = memopt[caller] - set_nonconst_metadata(caller::Module, flag::Bool) = (nonconst_metadata[caller] = flag) - get_nonconst_metadata(caller::Module) = nonconst_metadata[caller] + set_initialized(caller::Module, flag::Bool) = (createmeta_PS(caller); @eval(caller, $MOD_METADATA_PS.set_initialized($caller, $flag))) + is_initialized(caller::Module) = hasmeta_PS(caller) && @eval(caller, $MOD_METADATA_PS.is_initialized($caller)) + set_package(caller::Module, pkg::Symbol) = (createmeta_PS(caller); @eval(caller, $MOD_METADATA_PS.set_package($caller, $(quote_expr(pkg))))) + get_package(caller::Module) = hasmeta_PS(caller) ? @eval(caller, $MOD_METADATA_PS.get_package($caller)) : PKG_NONE + set_numbertype(caller::Module, T::DataType) = (createmeta_PS(caller); @eval(caller, $MOD_METADATA_PS.set_numbertype($caller, $T))) + get_numbertype(caller::Module) = hasmeta_PS(caller) ? @eval(caller, $MOD_METADATA_PS.get_numbertype($caller)) : NUMBERTYPE_NONE + set_ndims(caller::Module, n::Integer) = (createmeta_PS(caller); @eval(caller, $MOD_METADATA_PS.set_ndims($caller, $n))) + get_ndims(caller::Module) = hasmeta_PS(caller) ? @eval(caller, $MOD_METADATA_PS.get_ndims($caller)) : NDIMS_NONE + set_inbounds(caller::Module, flag::Bool) = (createmeta_PS(caller); @eval(caller, $MOD_METADATA_PS.set_inbounds($caller, $flag))) + get_inbounds(caller::Module) = hasmeta_PS(caller) ? @eval(caller, $MOD_METADATA_PS.get_inbounds($caller)) : INBOUNDS_DEFAULT + set_padding(caller::Module, flag::Bool) = (createmeta_PS(caller); @eval(caller, $MOD_METADATA_PS.set_padding($caller, $flag))) + get_padding(caller::Module) = hasmeta_PS(caller) ? @eval(caller, $MOD_METADATA_PS.get_padding($caller)) : PADDING_DEFAULT + set_memopt(caller::Module, flag::Bool) = (createmeta_PS(caller); @eval(caller, $MOD_METADATA_PS.set_memopt($caller, $flag))) + get_memopt(caller::Module) = hasmeta_PS(caller) ? @eval(caller, $MOD_METADATA_PS.get_memopt($caller)) : MEMOPT_DEFAULT + set_nonconst_metadata(caller::Module, flag::Bool) = (createmeta_PS(caller); @eval(caller, $MOD_METADATA_PS.set_nonconst_metadata($caller, $flag))) + get_nonconst_metadata(caller::Module) = hasmeta_PS(caller) ? @eval(caller, $MOD_METADATA_PS.get_nonconst_metadata($caller)) : NONCONST_METADATA_DEFAULT check_initialized(caller::Module) = if !is_initialized(caller) @NotInitializedError("no ParallelStencil macro or function can be called before @init_parallel_stencil in each module (missing call in $caller).") end function check_already_initialized(caller::Module, package::Symbol, numbertype::DataType, ndims::Integer, inbounds::Bool, padding::Bool, memopt::Bool, nonconst_metadata::Bool) From d01e136d4cfdcc470590724c88f32ab9f9b7d756 Mon Sep 17 00:00:00 2001 From: Samuel Omlin Date: Fri, 6 Dec 2024 18:17:45 +0100 Subject: [PATCH 03/16] move storage of state to caller --- src/ParallelKernel/reset_parallel_kernel.jl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ParallelKernel/reset_parallel_kernel.jl b/src/ParallelKernel/reset_parallel_kernel.jl index 1f1b7bee..50ed4680 100644 --- a/src/ParallelKernel/reset_parallel_kernel.jl +++ b/src/ParallelKernel/reset_parallel_kernel.jl @@ -16,8 +16,10 @@ function reset_parallel_kernel(caller::Module) tdata_module = TData_none() @eval(caller, $tdata_module) end - set_initialized(caller, false) - set_package(caller, PKG_NONE) - set_numbertype(caller, NUMBERTYPE_NONE) + if isdefined(caller, MOD_METADATA_PK) + set_initialized(caller, false) + set_package(caller, PKG_NONE) + set_numbertype(caller, NUMBERTYPE_NONE) + end return nothing end From b376d619671683dd840aba87ab39150867c1cf92 Mon Sep 17 00:00:00 2001 From: Samuel Omlin Date: Fri, 6 Dec 2024 18:18:21 +0100 Subject: [PATCH 04/16] move storage of state to caller --- src/reset_parallel_stencil.jl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/reset_parallel_stencil.jl b/src/reset_parallel_stencil.jl index e987c061..c736e5df 100644 --- a/src/reset_parallel_stencil.jl +++ b/src/reset_parallel_stencil.jl @@ -9,9 +9,11 @@ macro reset_parallel_stencil() esc(reset_parallel_stencil(__module__)) end function reset_parallel_stencil(caller::Module) ParallelKernel.reset_parallel_kernel(caller) - set_initialized(caller, false) - set_package(caller, PKG_NONE) - set_numbertype(caller, NUMBERTYPE_NONE) - set_ndims(caller, NDIMS_NONE) + if isdefined(caller, MOD_METADATA_PS) + set_initialized(caller, false) + set_package(caller, PKG_NONE) + set_numbertype(caller, NUMBERTYPE_NONE) + set_ndims(caller, NDIMS_NONE) + end return nothing end From b48940af932110957bb3c814438778dc5994df6e Mon Sep 17 00:00:00 2001 From: Samuel Omlin Date: Fri, 6 Dec 2024 18:23:39 +0100 Subject: [PATCH 05/16] move storage of state to caller --- src/ParallelKernel/shared.jl | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ParallelKernel/shared.jl b/src/ParallelKernel/shared.jl index 4325b372..2155ab71 100644 --- a/src/ParallelKernel/shared.jl +++ b/src/ParallelKernel/shared.jl @@ -9,10 +9,11 @@ gensym_world(tag::String, generator::Module) = gensym(string(tag, GENSYM_SEPARAT gensym_world(tag::Symbol, generator::Module) = gensym(string(tag, GENSYM_SEPARATOR, generator)) gensym_world(tag::Expr, generator::Module) = gensym(string(tag, GENSYM_SEPARATOR, generator)) -ixd(count) = @ModuleInternalError("function ixd had not be evaluated at parse time") -iyd(count) = @ModuleInternalError("function iyd had not be evaluated at parse time") -izd(count) = @ModuleInternalError("function izd had not be evaluated at parse time") +ixd(count) = @ModuleInternalError("function ixd had not been evaluated at parse time") +iyd(count) = @ModuleInternalError("function iyd had not been evaluated at parse time") +izd(count) = @ModuleInternalError("function izd had not been evaluated at parse time") +const MOD_METADATA_PK = :__metadata_PK__ # gensym_world("__metadata__", @__MODULE__) # # TODO: name mangling should be used here later, or if there is any sense to leave it like that then at check whether it's available must be done before creating it const PKG_CUDA = :CUDA const PKG_AMDGPU = :AMDGPU const PKG_METAL = :Metal @@ -53,6 +54,8 @@ const SUPPORTED_LITERALTYPES = [Float16, Float32, Float64, Complex{Fl const SUPPORTED_NUMBERTYPES = [Float16, Float32, Float64, Complex{Float16}, Complex{Float32}, Complex{Float64}] const PKNumber = Union{Float16, Float32, Float64, Complex{Float16}, Complex{Float32}, Complex{Float64}} # NOTE: this always needs to correspond to SUPPORTED_NUMBERTYPES! const NUMBERTYPE_NONE = DataType +const INBOUNDS_DEFAULT = false +const PADDING_DEFAULT = false const MODULENAME_DATA = :Data const MODULENAME_TDATA = :TData const MODULENAME_DEVICE = :Device @@ -566,12 +569,16 @@ end interpolate(sym::Symbol, vals_expr::Expr, block::Expr) = interpolate(sym, (extract_tuple(vals_expr)...,), block) +quote_expr(expr) = :($(Expr(:quote, expr))) + ## FUNCTIONS/MACROS FOR DIVERSE SYNTAX SUGAR iscpu(package) = return (package in (PKG_THREADS, PKG_POLYESTER)) isgpu(package) = return (package in (PKG_CUDA, PKG_AMDGPU, PKG_METAL)) +hasmeta_PK(caller::Module) = isdefined(caller, MOD_METADATA_PK) + ## TEMPORARY FUNCTION DEFINITIONS TO BE MERGED IN MACROTOOLS (https://github.com/FluxML/MacroTools.jl/pull/173) From 3ef526302f7a09b9ec0c9168e70940f60807448d Mon Sep 17 00:00:00 2001 From: Samuel Omlin Date: Fri, 6 Dec 2024 18:24:21 +0100 Subject: [PATCH 06/16] move storage of state to caller --- src/shared.jl | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/shared.jl b/src/shared.jl index 1617c310..670cd0c8 100644 --- a/src/shared.jl +++ b/src/shared.jl @@ -1,6 +1,6 @@ import MacroTools: @capture, postwalk, splitdef, splitarg # NOTE: inexpr_walk used instead of MacroTools.inexpr -import .ParallelKernel: eval_arg, split_args, split_kwargs, extract_posargs_init, extract_kernel_args, insert_device_types, is_kernel, is_call, gensym_world, isgpu, iscpu, @isgpu, @iscpu, substitute, substitute_in_kernel, in_signature, inexpr_walk, adjust_signatures, handle_indices_and_literals, add_inbounds, cast, @ranges, @rangelengths, @return_value, @return_nothing, @firstindex, @lastindex, is_access, find_vars, handle_padding, handle_inverses, increment_arg -import .ParallelKernel: PKG_CUDA, PKG_AMDGPU, PKG_METAL, PKG_THREADS, PKG_POLYESTER, PKG_NONE, NUMBERTYPE_NONE, SUPPORTED_NUMBERTYPES, SUPPORTED_PACKAGES, ERRMSG_UNSUPPORTED_PACKAGE, INT_CUDA, INT_AMDGPU, INT_METAL, INT_POLYESTER, INT_THREADS, INDICES, INDICES_INN, INDICES_DIR, INDICES_DIR_FUNCTIONS_SYMS, PKNumber, RANGES_VARNAME, RANGES_TYPE, RANGELENGTH_XYZ_TYPE, RANGELENGTHS_VARNAMES, THREADIDS_VARNAMES, GENSYM_SEPARATOR, AD_SUPPORTED_ANNOTATIONS, ARRAYTYPES, FIELDTYPES, SCALARTYPES +import .ParallelKernel: eval_arg, split_args, split_kwargs, extract_posargs_init, extract_kernel_args, insert_device_types, is_kernel, is_call, gensym_world, isgpu, iscpu, @isgpu, @iscpu, substitute, substitute_in_kernel, in_signature, inexpr_walk, adjust_signatures, handle_indices_and_literals, add_inbounds, cast, @ranges, @rangelengths, @return_value, @return_nothing, @firstindex, @lastindex, is_access, find_vars, handle_padding, handle_inverses, increment_arg, quote_expr +import .ParallelKernel: PKG_CUDA, PKG_AMDGPU, PKG_METAL, PKG_THREADS, PKG_POLYESTER, PKG_NONE, NUMBERTYPE_NONE, INBOUNDS_DEFAULT, PADDING_DEFAULT, SUPPORTED_NUMBERTYPES, SUPPORTED_PACKAGES, ERRMSG_UNSUPPORTED_PACKAGE, INT_CUDA, INT_AMDGPU, INT_METAL, INT_POLYESTER, INT_THREADS, INDICES, INDICES_INN, INDICES_DIR, INDICES_DIR_FUNCTIONS_SYMS, PKNumber, RANGES_VARNAME, RANGES_TYPE, RANGELENGTH_XYZ_TYPE, RANGELENGTHS_VARNAMES, THREADIDS_VARNAMES, GENSYM_SEPARATOR, AD_SUPPORTED_ANNOTATIONS, ARRAYTYPES, FIELDTYPES, SCALARTYPES import .ParallelKernel: @require, @symbols, symbols, longnameof, @prettyexpand, @prettystring, prettystring, @gorgeousexpand, @gorgeousstring, gorgeousstring, interpolate @@ -17,6 +17,7 @@ Return an expression that evaluates to `true` if the indices generated by @paral const SUPPORTED_NDIMS = [1, 2, 3] const NDIMS_NONE = 0 +const MEMOPT_DEFAULT = false const ERRMSG_KERNEL_UNSUPPORTED = "unsupported kernel statements in @parallel kernel definition: @parallel is only applicable to kernels that contain exclusively array assignments using macros from FiniteDifferences{1|2|3}D or from another compatible computation submodule. @parallel_indices supports any kind of statements in the kernels." const ERRMSG_CHECK_NDIMS = "ndims must be evaluatable at parse time (e.g. literal or constant) and has to be one of the following Integers: $(join(SUPPORTED_NDIMS,", "))" const ERRMSG_CHECK_MEMOPT = "memopt must be evaluatable at parse time (e.g. literal or constant) and has to be of type Bool." @@ -32,7 +33,7 @@ const USE_SHMEMHALO_1D_DEFAULT = true const USE_FULLRANGE_DEFAULT = (false, false, true) const FULLRANGE_THRESHOLD = 1 const NOEXPR = :(begin end) -const MOD_METADATA = :__metadata__ # gensym_world("__metadata__", @__MODULE__) # # TODO: name mangling should be used here later, or if there is any sense to leave it like that then at check whether it's available must be done before creating it +const MOD_METADATA_PS = :__metadata_PS__ # gensym_world("__metadata__", @__MODULE__) # # TODO: name mangling should be used here later, or if there is any sense to leave it like that then at check whether it's available must be done before creating it const META_FUNCTION_PREFIX = string(gensym_world("META", @__MODULE__)) @@ -89,4 +90,9 @@ end check_ndims(ndims) = ( if !isa(ndims, Integer) || !(ndims in SUPPORTED_NDIMS) @ArgumentError("$ERRMSG_CHECK_NDIMS (obtained: $ndims)." ) end ) check_memopt(memopt) = ( if !isa(memopt, Bool) @ArgumentError("$ERRMSG_CHECK_MEMOPT (obtained: $memopt)." ) end ) -check_nonconst_metadata(nonconst_metadata) = ( if !isa(nonconst_metadata, Bool) @ArgumentError("$ERRMSG_CHECK_NONCONST_METADATA (obtained: $nonconst_metadata)." ) end ) \ No newline at end of file +check_nonconst_metadata(nonconst_metadata) = ( if !isa(nonconst_metadata, Bool) @ArgumentError("$ERRMSG_CHECK_NONCONST_METADATA (obtained: $nonconst_metadata)." ) end ) + + +## FUNCTIONS/MACROS FOR DIVERSE SYNTAX SUGAR + +hasmeta_PS(caller::Module) = isdefined(caller, MOD_METADATA_PS) From 51541c63f5a02a4e2e621357ec052376dfdc4b65 Mon Sep 17 00:00:00 2001 From: Samuel Omlin Date: Fri, 6 Dec 2024 18:25:10 +0100 Subject: [PATCH 07/16] move storage of state to caller --- src/parallel.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/parallel.jl b/src/parallel.jl index ab45670c..6d08ffd3 100644 --- a/src/parallel.jl +++ b/src/parallel.jl @@ -462,8 +462,8 @@ end function create_metadata_storage(source::LineNumberNode, caller::Module, kernel::Expr) kernelid = get_kernelid(get_name(kernel), source.file, source.line) - create_module(caller, MOD_METADATA) - topmodule = @eval(caller, $MOD_METADATA) + create_module(caller, MOD_METADATA_PS) + topmodule = @eval(caller, $MOD_METADATA_PS) create_module(topmodule, kernelid) metadata_module = @eval(topmodule, $kernelid) metadata_function = create_metadata_function(kernel, metadata_module) From dc5361ddd211f9a49124dc4dfcf015d7446e0ebf Mon Sep 17 00:00:00 2001 From: Samuel Omlin Date: Fri, 6 Dec 2024 18:28:08 +0100 Subject: [PATCH 08/16] move storage of state to caller --- test/ParallelKernel/test_init_parallel_kernel.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/ParallelKernel/test_init_parallel_kernel.jl b/test/ParallelKernel/test_init_parallel_kernel.jl index 852b039b..d6c62c1a 100644 --- a/test/ParallelKernel/test_init_parallel_kernel.jl +++ b/test/ParallelKernel/test_init_parallel_kernel.jl @@ -133,6 +133,7 @@ Base.retry_load_extensions() # Potentially needed to load the extensions after t @reset_parallel_kernel() end; @testset "3. Exceptions" begin + @init_parallel_kernel(package=$package) # NOTE: Initialization is potentially later required to create the metadata module @testset "already initialized" begin set_initialized(@__MODULE__, true) @require is_initialized(@__MODULE__) From 5b98102554a51830e8511a6d84080772b3c537d6 Mon Sep 17 00:00:00 2001 From: Samuel Omlin Date: Fri, 6 Dec 2024 18:28:35 +0100 Subject: [PATCH 09/16] move storage of state to caller --- test/test_init_parallel_stencil.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_init_parallel_stencil.jl b/test/test_init_parallel_stencil.jl index 8a69d291..90519169 100644 --- a/test/test_init_parallel_stencil.jl +++ b/test/test_init_parallel_stencil.jl @@ -99,6 +99,7 @@ Base.retry_load_extensions() # Potentially needed to load the extensions after t @reset_parallel_stencil() end; @testset "3. Exceptions" begin + @init_parallel_stencil(package=$package) # NOTE: Initialization is potentially later required to create the metadata module @testset "already initialized" begin set_initialized(@__MODULE__, true) set_package(@__MODULE__, :CUDA) From d61bffdac7a2e361c7775b21bcc838d268de8127 Mon Sep 17 00:00:00 2001 From: Samuel Omlin Date: Fri, 6 Dec 2024 18:29:10 +0100 Subject: [PATCH 10/16] move storage of state to caller --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index cb847afd..3692d64a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -7,7 +7,7 @@ import ParallelStencil: SUPPORTED_PACKAGES, PKG_CUDA, PKG_AMDGPU, PKG_METAL @static if (PKG_AMDGPU in SUPPORTED_PACKAGES) import AMDGPU end @static if (PKG_METAL in SUPPORTED_PACKAGES && Sys.isapple()) import Metal end -excludedfiles = [ "test_excluded.jl", "test_incremental_compilation.jl"]; # TODO: test_incremental_compilation has to be deactivated until Polyester support released +excludedfiles = [ "test_excluded.jl", "test_incremental_compilation.jl", "test_revise.jl"]; # TODO: test_incremental_compilation has to be deactivated until Polyester support released function runtests() exename = joinpath(Sys.BINDIR, Base.julia_exename()) From aa9453de0e76a841a8c23b6989e4a4aebea8877c Mon Sep 17 00:00:00 2001 From: Samuel Omlin Date: Fri, 6 Dec 2024 19:48:10 +0100 Subject: [PATCH 11/16] simplify storage not using dictionary anymore --- src/init_parallel_stencil.jl | 82 ++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/src/init_parallel_stencil.jl b/src/init_parallel_stencil.jl index 4855a5c2..454ee360 100644 --- a/src/init_parallel_stencil.jl +++ b/src/init_parallel_stencil.jl @@ -71,31 +71,31 @@ end function Metadata_PS() :(module $MOD_METADATA_PS # NOTE: there cannot be any newline before 'module $MOD_METADATA_PS' or it will create a begin end block and the module creation will fail. let - global is_initialized, set_initialized, set_package, get_package, set_numbertype, get_numbertype, set_ndims, get_ndims, set_inbounds, get_inbounds, set_padding, get_padding, set_memopt, get_memopt, set_nonconst_metadata, get_nonconst_metadata, check_initialized, check_already_initialized - _is_initialized::Dict{Module, Bool} = Dict{Module, Bool}() - package::Dict{Module, Symbol} = Dict{Module, Symbol}() - numbertype::Dict{Module, DataType} = Dict{Module, DataType}() - ndims::Dict{Module, Integer} = Dict{Module, Integer}() - inbounds::Dict{Module, Bool} = Dict{Module, Bool}() - padding::Dict{Module, Bool} = Dict{Module, Bool}() - memopt::Dict{Module, Bool} = Dict{Module, Bool}() - nonconst_metadata::Dict{Module, Bool} = Dict{Module, Bool}() - set_initialized(caller::Module, flag::Bool) = (_is_initialized[caller] = flag) - is_initialized(caller::Module) = haskey(_is_initialized, caller) && _is_initialized[caller] - set_package(caller::Module, pkg::Symbol) = (package[caller] = pkg) - get_package(caller::Module) = package[caller] - set_numbertype(caller::Module, T::DataType) = (numbertype[caller] = T) - get_numbertype(caller::Module) = numbertype[caller] - set_ndims(caller::Module, n::Integer) = (ndims[caller] = n) - get_ndims(caller::Module) = ndims[caller] - set_inbounds(caller::Module, flag::Bool) = (inbounds[caller] = flag) - get_inbounds(caller::Module) = inbounds[caller] - set_padding(caller::Module, flag::Bool) = (padding[caller] = flag) - get_padding(caller::Module) = padding[caller] - set_memopt(caller::Module, flag::Bool) = (memopt[caller] = flag) - get_memopt(caller::Module) = memopt[caller] - set_nonconst_metadata(caller::Module, flag::Bool) = (nonconst_metadata[caller] = flag) - get_nonconst_metadata(caller::Module) = nonconst_metadata[caller] + global set_initialized, is_initialized, set_package, get_package, set_numbertype, get_numbertype, set_ndims, get_ndims, set_inbounds, get_inbounds, set_padding, get_padding, set_memopt, get_memopt, set_nonconst_metadata, get_nonconst_metadata + _is_initialized::Bool = false + package::Symbol = $(quote_expr(PKG_NONE)) + numbertype::DataType = $NUMBERTYPE_NONE + ndims::Integer = $NDIMS_NONE + inbounds::Bool = $INBOUNDS_DEFAULT + padding::Bool = $PADDING_DEFAULT + memopt::Bool = $MEMOPT_DEFAULT + nonconst_metadata::Bool = $NONCONST_METADATA_DEFAULT + set_initialized(flag::Bool) = (_is_initialized = flag) + is_initialized() = _is_initialized + set_package(pkg::Symbol) = (package = pkg) + get_package() = package + set_numbertype(T::DataType) = (numbertype = T) + get_numbertype() = numbertype + set_ndims(n::Integer) = (ndims = n) + get_ndims() = ndims + set_inbounds(flag::Bool) = (inbounds = flag) + get_inbounds() = inbounds + set_padding(flag::Bool) = (padding = flag) + get_padding() = padding + set_memopt(flag::Bool) = (memopt = flag) + get_memopt() = memopt + set_nonconst_metadata(flag::Bool) = (nonconst_metadata = flag) + get_nonconst_metadata() = nonconst_metadata end end) end @@ -113,22 +113,22 @@ macro get_memopt() get_memopt(__module__) end macro get_nonconst_metadata() get_nonconst_metadata(__module__) end let global is_initialized, set_initialized, set_package, get_package, set_numbertype, get_numbertype, set_ndims, get_ndims, set_inbounds, get_inbounds, set_padding, get_padding, set_memopt, get_memopt, set_nonconst_metadata, get_nonconst_metadata, check_initialized, check_already_initialized - set_initialized(caller::Module, flag::Bool) = (createmeta_PS(caller); @eval(caller, $MOD_METADATA_PS.set_initialized($caller, $flag))) - is_initialized(caller::Module) = hasmeta_PS(caller) && @eval(caller, $MOD_METADATA_PS.is_initialized($caller)) - set_package(caller::Module, pkg::Symbol) = (createmeta_PS(caller); @eval(caller, $MOD_METADATA_PS.set_package($caller, $(quote_expr(pkg))))) - get_package(caller::Module) = hasmeta_PS(caller) ? @eval(caller, $MOD_METADATA_PS.get_package($caller)) : PKG_NONE - set_numbertype(caller::Module, T::DataType) = (createmeta_PS(caller); @eval(caller, $MOD_METADATA_PS.set_numbertype($caller, $T))) - get_numbertype(caller::Module) = hasmeta_PS(caller) ? @eval(caller, $MOD_METADATA_PS.get_numbertype($caller)) : NUMBERTYPE_NONE - set_ndims(caller::Module, n::Integer) = (createmeta_PS(caller); @eval(caller, $MOD_METADATA_PS.set_ndims($caller, $n))) - get_ndims(caller::Module) = hasmeta_PS(caller) ? @eval(caller, $MOD_METADATA_PS.get_ndims($caller)) : NDIMS_NONE - set_inbounds(caller::Module, flag::Bool) = (createmeta_PS(caller); @eval(caller, $MOD_METADATA_PS.set_inbounds($caller, $flag))) - get_inbounds(caller::Module) = hasmeta_PS(caller) ? @eval(caller, $MOD_METADATA_PS.get_inbounds($caller)) : INBOUNDS_DEFAULT - set_padding(caller::Module, flag::Bool) = (createmeta_PS(caller); @eval(caller, $MOD_METADATA_PS.set_padding($caller, $flag))) - get_padding(caller::Module) = hasmeta_PS(caller) ? @eval(caller, $MOD_METADATA_PS.get_padding($caller)) : PADDING_DEFAULT - set_memopt(caller::Module, flag::Bool) = (createmeta_PS(caller); @eval(caller, $MOD_METADATA_PS.set_memopt($caller, $flag))) - get_memopt(caller::Module) = hasmeta_PS(caller) ? @eval(caller, $MOD_METADATA_PS.get_memopt($caller)) : MEMOPT_DEFAULT - set_nonconst_metadata(caller::Module, flag::Bool) = (createmeta_PS(caller); @eval(caller, $MOD_METADATA_PS.set_nonconst_metadata($caller, $flag))) - get_nonconst_metadata(caller::Module) = hasmeta_PS(caller) ? @eval(caller, $MOD_METADATA_PS.get_nonconst_metadata($caller)) : NONCONST_METADATA_DEFAULT + set_initialized(caller::Module, flag::Bool) = (createmeta_PS(caller); @eval(caller, $MOD_METADATA_PS.set_initialized($flag))) + is_initialized(caller::Module) = hasmeta_PS(caller) && @eval(caller, $MOD_METADATA_PS.is_initialized()) + set_package(caller::Module, pkg::Symbol) = (createmeta_PS(caller); @eval(caller, $MOD_METADATA_PS.set_package($(quote_expr(pkg))))) + get_package(caller::Module) = hasmeta_PS(caller) ? @eval(caller, $MOD_METADATA_PS.get_package()) : PKG_NONE + set_numbertype(caller::Module, T::DataType) = (createmeta_PS(caller); @eval(caller, $MOD_METADATA_PS.set_numbertype($T))) + get_numbertype(caller::Module) = hasmeta_PS(caller) ? @eval(caller, $MOD_METADATA_PS.get_numbertype()) : NUMBERTYPE_NONE + set_ndims(caller::Module, n::Integer) = (createmeta_PS(caller); @eval(caller, $MOD_METADATA_PS.set_ndims($n))) + get_ndims(caller::Module) = hasmeta_PS(caller) ? @eval(caller, $MOD_METADATA_PS.get_ndims()) : NDIMS_NONE + set_inbounds(caller::Module, flag::Bool) = (createmeta_PS(caller); @eval(caller, $MOD_METADATA_PS.set_inbounds($flag))) + get_inbounds(caller::Module) = hasmeta_PS(caller) ? @eval(caller, $MOD_METADATA_PS.get_inbounds()) : INBOUNDS_DEFAULT + set_padding(caller::Module, flag::Bool) = (createmeta_PS(caller); @eval(caller, $MOD_METADATA_PS.set_padding($flag))) + get_padding(caller::Module) = hasmeta_PS(caller) ? @eval(caller, $MOD_METADATA_PS.get_padding()) : PADDING_DEFAULT + set_memopt(caller::Module, flag::Bool) = (createmeta_PS(caller); @eval(caller, $MOD_METADATA_PS.set_memopt($flag))) + get_memopt(caller::Module) = hasmeta_PS(caller) ? @eval(caller, $MOD_METADATA_PS.get_memopt()) : MEMOPT_DEFAULT + set_nonconst_metadata(caller::Module, flag::Bool) = (createmeta_PS(caller); @eval(caller, $MOD_METADATA_PS.set_nonconst_metadata($flag))) + get_nonconst_metadata(caller::Module) = hasmeta_PS(caller) ? @eval(caller, $MOD_METADATA_PS.get_nonconst_metadata()) : NONCONST_METADATA_DEFAULT check_initialized(caller::Module) = if !is_initialized(caller) @NotInitializedError("no ParallelStencil macro or function can be called before @init_parallel_stencil in each module (missing call in $caller).") end function check_already_initialized(caller::Module, package::Symbol, numbertype::DataType, ndims::Integer, inbounds::Bool, padding::Bool, memopt::Bool, nonconst_metadata::Bool) From dee3ae3b9bddc090911b21a95e4f7eaa094f95ef Mon Sep 17 00:00:00 2001 From: Samuel Omlin Date: Fri, 6 Dec 2024 19:48:35 +0100 Subject: [PATCH 12/16] simplify storage not using dictionary anymore --- src/ParallelKernel/init_parallel_kernel.jl | 52 +++++++++++----------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/ParallelKernel/init_parallel_kernel.jl b/src/ParallelKernel/init_parallel_kernel.jl index 259ff234..16d21903 100644 --- a/src/ParallelKernel/init_parallel_kernel.jl +++ b/src/ParallelKernel/init_parallel_kernel.jl @@ -90,22 +90,22 @@ end function Metadata_PK() :(module $MOD_METADATA_PK # NOTE: there cannot be any newline before 'module $MOD_METADATA_PK' or it will create a begin end block and the module creation will fail. let - global is_initialized, set_initialized, set_package, get_package, set_numbertype, get_numbertype, set_inbounds, get_inbounds, set_padding, get_padding, check_initialized, check_already_initialized - _is_initialized::Dict{Module, Bool} = Dict{Module, Bool}() - package::Dict{Module, Symbol} = Dict{Module, Symbol}() - numbertype::Dict{Module, DataType} = Dict{Module, DataType}() - inbounds::Dict{Module, Bool} = Dict{Module, Bool}() - padding::Dict{Module, Bool} = Dict{Module, Bool}() - set_initialized(caller::Module, flag::Bool) = (_is_initialized[caller] = flag) - is_initialized(caller::Module) = haskey(_is_initialized, caller) && _is_initialized[caller] - set_package(caller::Module, pkg::Symbol) = (package[caller] = pkg) - get_package(caller::Module) = package[caller] - set_numbertype(caller::Module, T::DataType) = (numbertype[caller] = T) - get_numbertype(caller::Module) = numbertype[caller] - set_inbounds(caller::Module, flag::Bool) = (inbounds[caller] = flag) - get_inbounds(caller::Module) = inbounds[caller] - set_padding(caller::Module, flag::Bool) = (padding[caller] = flag) - get_padding(caller::Module) = padding[caller] + global set_initialized, is_initialized, set_package, get_package, set_numbertype, get_numbertype, set_inbounds, get_inbounds, set_padding, get_padding + _is_initialized::Bool = false + package::Symbol = $(quote_expr(PKG_NONE)) + numbertype::DataType = $NUMBERTYPE_NONE + inbounds::Bool = $INBOUNDS_DEFAULT + padding::Bool = $PADDING_DEFAULT + set_initialized(flag::Bool) = (_is_initialized = flag) + is_initialized() = _is_initialized + set_package(pkg::Symbol) = (package = pkg) + get_package() = package + set_numbertype(T::DataType) = (numbertype = T) + get_numbertype() = numbertype + set_inbounds(flag::Bool) = (inbounds = flag) + get_inbounds() = inbounds + set_padding(flag::Bool) = (padding = flag) + get_padding() = padding end end) end @@ -120,16 +120,16 @@ macro get_inbounds() get_inbounds(__module__) end macro get_padding() get_padding(__module__) end let global is_initialized, set_initialized, set_package, get_package, set_numbertype, get_numbertype, set_inbounds, get_inbounds, set_padding, get_padding, check_initialized, check_already_initialized - set_initialized(caller::Module, flag::Bool) = (createmeta_PK(caller); @eval(caller, $MOD_METADATA_PK.set_initialized($caller, $flag))) - is_initialized(caller::Module) = hasmeta_PK(caller) && @eval(caller, $MOD_METADATA_PK.is_initialized($caller)) - set_package(caller::Module, pkg::Symbol) = (createmeta_PK(caller); @eval(caller, $MOD_METADATA_PK.set_package($caller, $(quote_expr(pkg))))) - get_package(caller::Module) = hasmeta_PK(caller) ? @eval(caller, $MOD_METADATA_PK.get_package($caller)) : PKG_NONE - set_numbertype(caller::Module, T::DataType) = (createmeta_PK(caller); @eval(caller, $MOD_METADATA_PK.set_numbertype($caller, $T))) - get_numbertype(caller::Module) = hasmeta_PK(caller) ? @eval(caller, $MOD_METADATA_PK.get_numbertype($caller)) : NUMBERTYPE_NONE - set_inbounds(caller::Module, flag::Bool) = (createmeta_PK(caller); @eval(caller, $MOD_METADATA_PK.set_inbounds($caller, $flag))) - get_inbounds(caller::Module) = hasmeta_PK(caller) ? @eval(caller, $MOD_METADATA_PK.get_inbounds($caller)) : INBOUNDS_DEFAULT - set_padding(caller::Module, flag::Bool) = (createmeta_PK(caller); @eval(caller, $MOD_METADATA_PK.set_padding($caller, $flag))) - get_padding(caller::Module) = hasmeta_PK(caller) ? @eval(caller, $MOD_METADATA_PK.get_padding($caller)) : PADDING_DEFAULT + set_initialized(caller::Module, flag::Bool) = (createmeta_PK(caller); @eval(caller, $MOD_METADATA_PK.set_initialized($flag))) + is_initialized(caller::Module) = hasmeta_PK(caller) && @eval(caller, $MOD_METADATA_PK.is_initialized()) + set_package(caller::Module, pkg::Symbol) = (createmeta_PK(caller); @eval(caller, $MOD_METADATA_PK.set_package($(quote_expr(pkg))))) + get_package(caller::Module) = hasmeta_PK(caller) ? @eval(caller, $MOD_METADATA_PK.get_package()) : PKG_NONE + set_numbertype(caller::Module, T::DataType) = (createmeta_PK(caller); @eval(caller, $MOD_METADATA_PK.set_numbertype($T))) + get_numbertype(caller::Module) = hasmeta_PK(caller) ? @eval(caller, $MOD_METADATA_PK.get_numbertype()) : NUMBERTYPE_NONE + set_inbounds(caller::Module, flag::Bool) = (createmeta_PK(caller); @eval(caller, $MOD_METADATA_PK.set_inbounds($flag))) + get_inbounds(caller::Module) = hasmeta_PK(caller) ? @eval(caller, $MOD_METADATA_PK.get_inbounds()) : INBOUNDS_DEFAULT + set_padding(caller::Module, flag::Bool) = (createmeta_PK(caller); @eval(caller, $MOD_METADATA_PK.set_padding($flag))) + get_padding(caller::Module) = hasmeta_PK(caller) ? @eval(caller, $MOD_METADATA_PK.get_padding()) : PADDING_DEFAULT check_initialized(caller::Module) = if !is_initialized(caller) @NotInitializedError("no ParallelKernel macro or function can be called before @init_parallel_kernel in each module (missing call in $caller).") end check_already_initialized(caller::Module) = if is_initialized(caller) @IncoherentCallError("ParallelKernel has already been initialized for the module $caller.") end end From 11e658f7888c2becc3980931efc6bb950e7ad080 Mon Sep 17 00:00:00 2001 From: Samuel Omlin Date: Fri, 6 Dec 2024 19:49:12 +0100 Subject: [PATCH 13/16] simplify storage not using dictionary anymore --- src/shared.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/shared.jl b/src/shared.jl index 670cd0c8..60662105 100644 --- a/src/shared.jl +++ b/src/shared.jl @@ -18,6 +18,7 @@ Return an expression that evaluates to `true` if the indices generated by @paral const SUPPORTED_NDIMS = [1, 2, 3] const NDIMS_NONE = 0 const MEMOPT_DEFAULT = false +const NONCONST_METADATA_DEFAULT = false const ERRMSG_KERNEL_UNSUPPORTED = "unsupported kernel statements in @parallel kernel definition: @parallel is only applicable to kernels that contain exclusively array assignments using macros from FiniteDifferences{1|2|3}D or from another compatible computation submodule. @parallel_indices supports any kind of statements in the kernels." const ERRMSG_CHECK_NDIMS = "ndims must be evaluatable at parse time (e.g. literal or constant) and has to be one of the following Integers: $(join(SUPPORTED_NDIMS,", "))" const ERRMSG_CHECK_MEMOPT = "memopt must be evaluatable at parse time (e.g. literal or constant) and has to be of type Bool." From 88a2694cb3155b11f89b2b9df04816d91a2a5a2f Mon Sep 17 00:00:00 2001 From: Samuel Omlin Date: Fri, 6 Dec 2024 19:49:44 +0100 Subject: [PATCH 14/16] ad unit test for revise --- test/test_revise.jl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 test/test_revise.jl diff --git a/test/test_revise.jl b/test/test_revise.jl new file mode 100644 index 00000000..2d7bf573 --- /dev/null +++ b/test/test_revise.jl @@ -0,0 +1,20 @@ +using Pkg, Test +using Revise + +package_root = joinpath(@__DIR__, "..") +test_project = joinpath(@__DIR__, "test_projects", "Diffusion3D_Revise") +test_file = joinpath(@__DIR__, "test_projects", "shared", "diffusion3D.jl") +test_file_tmp = joinpath(@__DIR__, "test_projects", "Diffusion3D_Revise", "src", "diffusion3D_tmp.jl") + +# Copy the missing test file to the test project, activate, use and test it +cp(test_file, test_file_tmp; force=true) +Pkg.activate(test_project) +# Pkg.instantiate() +Pkg.develop(path=package_root) +using Diffusion3D_Revise +@test Diffusion3D_Revise.diffusion3D() + +# Revise the test file in the test project and test it +test_code = read(test_file, String) +write(test_file_tmp, replace(test_code, "return true"=>"return false")) +@test !(Diffusion3D_Revise.diffusion3D()) From d0e9cc4cb7a7d4d941eeb191e6f18fa3db08aec7 Mon Sep 17 00:00:00 2001 From: Samuel Omlin Date: Fri, 6 Dec 2024 19:50:01 +0100 Subject: [PATCH 15/16] ad unit test for revise --- .../Diffusion3D_Revise/Project.toml | 10 +++++ .../src/Diffusion3D_Revise.jl | 6 +++ .../Diffusion3D_Revise/src/diffusion3D_tmp.jl | 39 +++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 test/test_projects/Diffusion3D_Revise/Project.toml create mode 100644 test/test_projects/Diffusion3D_Revise/src/Diffusion3D_Revise.jl create mode 100644 test/test_projects/Diffusion3D_Revise/src/diffusion3D_tmp.jl diff --git a/test/test_projects/Diffusion3D_Revise/Project.toml b/test/test_projects/Diffusion3D_Revise/Project.toml new file mode 100644 index 00000000..6f99326f --- /dev/null +++ b/test/test_projects/Diffusion3D_Revise/Project.toml @@ -0,0 +1,10 @@ +name = "Diffusion3D_Revise" +uuid = "763c5dee-143d-409d-8529-7cbbae6ea527" +authors = ["Samuel Omlin "] +version = "0.1.0" + +[deps] +ParallelStencil = "94395366-693c-11ea-3b26-d9b7aac5d958" + +[compat] +ParallelStencil = ">= 0.4.0" diff --git a/test/test_projects/Diffusion3D_Revise/src/Diffusion3D_Revise.jl b/test/test_projects/Diffusion3D_Revise/src/Diffusion3D_Revise.jl new file mode 100644 index 00000000..02d217e9 --- /dev/null +++ b/test/test_projects/Diffusion3D_Revise/src/Diffusion3D_Revise.jl @@ -0,0 +1,6 @@ +module Diffusion3D_Revise + using ParallelStencil + using ParallelStencil.FiniteDifferences3D + @init_parallel_stencil(Threads, Float64, 3) + include(joinpath(@__DIR__, "diffusion3D_tmp.jl")) +end diff --git a/test/test_projects/Diffusion3D_Revise/src/diffusion3D_tmp.jl b/test/test_projects/Diffusion3D_Revise/src/diffusion3D_tmp.jl new file mode 100644 index 00000000..6d99554b --- /dev/null +++ b/test/test_projects/Diffusion3D_Revise/src/diffusion3D_tmp.jl @@ -0,0 +1,39 @@ +@parallel function diffusion3D_step!(T2, T, Ci, lam, dt, dx, dy, dz) + @inn(T2) = @inn(T) + dt*(lam*@inn(Ci)*(@d2_xi(T)/dx^2 + @d2_yi(T)/dy^2 + @d2_zi(T)/dz^2)); + return +end + +function diffusion3D() +# Physics +lam = 1.0; # Thermal conductivity +cp_min = 1.0; # Minimal heat capacity +lx, ly, lz = 10.0, 10.0, 10.0; # Length of computational domain in dimension x, y and z + +# Numerics +nx, ny, nz = 8, 8, 8; # Number of gridpoints in dimensions x, y and z +nt = 3; # Number of time steps +dx = lx/(nx-1); # Space step in x-dimension +dy = ly/(ny-1); # Space step in y-dimension +dz = lz/(nz-1); # Space step in z-dimension + +# Array initializations +T = @zeros(nx, ny, nz); +T2 = @zeros(nx, ny, nz); +Ci = @zeros(nx, ny, nz); + +# Initial conditions (heat capacity and temperature with two Gaussian anomalies each) +Ci .= 1.0./( cp_min .+ Data.Array([5*exp(-(((ix-1)*dx-lx/1.5))^2-(((iy-1)*dy-ly/2))^2-(((iz-1)*dz-lz/1.5))^2) + + 5*exp(-(((ix-1)*dx-lx/3.0))^2-(((iy-1)*dy-ly/2))^2-(((iz-1)*dz-lz/1.5))^2) for ix=1:size(T,1), iy=1:size(T,2), iz=1:size(T,3)]) ) +T .= Data.Array([100*exp(-(((ix-1)*dx-lx/2)/2)^2-(((iy-1)*dy-ly/2)/2)^2-(((iz-1)*dz-lz/3.0)/2)^2) + + 50*exp(-(((ix-1)*dx-lx/2)/2)^2-(((iy-1)*dy-ly/2)/2)^2-(((iz-1)*dz-lz/1.5)/2)^2) for ix=1:size(T,1), iy=1:size(T,2), iz=1:size(T,3)]) +T2 .= T; # Assign also T2 to get correct boundary conditions. + +# Time loop +dt = min(dx^2,dy^2,dz^2)*cp_min/lam/8.1; # Time step for the 3D Heat diffusion +for it = 1:nt + @parallel diffusion3D_step!(T2, T, Ci, lam, dt, dx, dy, dz); + T, T2 = T2, T; +end + +return false +end From 493374ef92651ae7e811840a946681acf81f01fc Mon Sep 17 00:00:00 2001 From: Samuel Omlin Date: Fri, 6 Dec 2024 19:52:29 +0100 Subject: [PATCH 16/16] restore name mangling for meta data module --- src/ParallelKernel/shared.jl | 2 +- src/shared.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ParallelKernel/shared.jl b/src/ParallelKernel/shared.jl index 2155ab71..5d4a4f8a 100644 --- a/src/ParallelKernel/shared.jl +++ b/src/ParallelKernel/shared.jl @@ -13,7 +13,7 @@ ixd(count) = @ModuleInternalError("function ixd had not been evaluated at parse iyd(count) = @ModuleInternalError("function iyd had not been evaluated at parse time") izd(count) = @ModuleInternalError("function izd had not been evaluated at parse time") -const MOD_METADATA_PK = :__metadata_PK__ # gensym_world("__metadata__", @__MODULE__) # # TODO: name mangling should be used here later, or if there is any sense to leave it like that then at check whether it's available must be done before creating it +const MOD_METADATA_PK = gensym_world("__metadata_PK__", @__MODULE__) # # TODO: name mangling should be used here later, or if there is any sense to leave it like that then at check whether it's available must be done before creating it const PKG_CUDA = :CUDA const PKG_AMDGPU = :AMDGPU const PKG_METAL = :Metal diff --git a/src/shared.jl b/src/shared.jl index 60662105..b855d030 100644 --- a/src/shared.jl +++ b/src/shared.jl @@ -34,7 +34,7 @@ const USE_SHMEMHALO_1D_DEFAULT = true const USE_FULLRANGE_DEFAULT = (false, false, true) const FULLRANGE_THRESHOLD = 1 const NOEXPR = :(begin end) -const MOD_METADATA_PS = :__metadata_PS__ # gensym_world("__metadata__", @__MODULE__) # # TODO: name mangling should be used here later, or if there is any sense to leave it like that then at check whether it's available must be done before creating it +const MOD_METADATA_PS = gensym_world("__metadata_PS__", @__MODULE__) # # TODO: name mangling should be used here later, or if there is any sense to leave it like that then at check whether it's available must be done before creating it const META_FUNCTION_PREFIX = string(gensym_world("META", @__MODULE__))