@@ -147,18 +147,22 @@ struct DataDepsState{State<:Union{DataDepsAliasingState,DataDepsNonAliasingState
147147 # The mapping of memory space to remote argument copies
148148 remote_args:: Dict{MemorySpace,IdDict{Any,Any}}
149149
150+ # Cache of whether arguments supports in-place move
151+ supports_inplace_cache:: IdDict{Any,Bool}
152+
150153 # The aliasing analysis state
151154 alias_state:: State
152155
153156 function DataDepsState (aliasing:: Bool )
154157 dependencies = Pair{DTask,Vector{Tuple{Bool,Bool,<: AbstractAliasing ,<: Any ,<: Any }}}[]
155158 remote_args = Dict {MemorySpace,IdDict{Any,Any}} ()
159+ supports_inplace_cache = IdDict {Any,Bool} ()
156160 if aliasing
157161 state = DataDepsAliasingState ()
158162 else
159163 state = DataDepsNonAliasingState ()
160164 end
161- return new {typeof(state)} (aliasing, dependencies, remote_args, state)
165+ return new {typeof(state)} (aliasing, dependencies, remote_args, supports_inplace_cache, state)
162166 end
163167end
164168
@@ -168,6 +172,12 @@ function aliasing(astate::DataDepsAliasingState, arg, dep_mod)
168172 end
169173end
170174
175+ function supports_inplace_move (state:: DataDepsState , arg)
176+ return get! (state. supports_inplace_cache, arg) do
177+ return supports_inplace_move (arg)
178+ end
179+ end
180+
171181# Determine which arguments could be written to, and thus need tracking
172182
173183" Whether `arg` has any writedep in this datadeps region."
@@ -708,7 +718,7 @@ function distribute_tasks!(queue::DataDepsTaskQueue)
708718 end
709719
710720 # Is the data writeable?
711- if ! supports_inplace_move (arg)
721+ if ! supports_inplace_move (state, arg)
712722 @dagdebug nothing :spawn_datadeps " ($(repr (spec. f)) )[$idx ] Skipped copy-to (non-writeable)"
713723 spec. args[idx] = pos => arg
714724 continue
@@ -781,6 +791,7 @@ function distribute_tasks!(queue::DataDepsTaskQueue)
781791 arg, deps = unwrap_inout (arg)
782792 arg = arg isa DTask ? fetch (arg; raw= true ) : arg
783793 type_may_alias (typeof (arg)) || continue
794+ supports_inplace_move (state, arg) || continue
784795 if queue. aliasing
785796 for (dep_mod, _, writedep) in deps
786797 ainfo = aliasing (astate, arg, dep_mod)
@@ -862,7 +873,7 @@ function distribute_tasks!(queue::DataDepsTaskQueue)
862873 end
863874
864875 # Skip non-writeable arguments
865- if ! supports_inplace_move (arg)
876+ if ! supports_inplace_move (state, arg)
866877 @dagdebug nothing :spawn_datadeps " Skipped copy-from (non-writeable)"
867878 continue
868879 end
@@ -919,7 +930,7 @@ function distribute_tasks!(queue::DataDepsTaskQueue)
919930 end
920931
921932 # Can the data be written back to?
922- if ! supports_inplace_move (arg)
933+ if ! supports_inplace_move (state, arg)
923934 @dagdebug nothing :spawn_datadeps " Skipped copy-from (non-writeable)"
924935 end
925936
0 commit comments