Hi,
It is more a question than a issue as I didn't see any information in the doc:
Is the preparation thread safe?
This kind of code seems to work but is it legit for all possible backend?
julia> backendZ = AutoZygote()
AutoZygote()
julia> backendFD = AutoForwardDiff()
AutoForwardDiff()
julia> prepFD = prepare_gradient(sin, backendFD, x)
DifferentiationInterface.PullbackGradientPrep{Nothing, Float64, DifferentiationInterface.PushforwardPullbackPrep{Nothing, DifferentiationInterfaceForwardDiffExt.ForwardDiffOneArgPushforwardPrep{Nothing, ForwardDiff.Tag{typeof(sin), Float64}, ForwardDiff.Dual{ForwardDiff.Tag{typeof(sin), Float64}, Float64, 1}, Tuple{}}}}(Val{Nothing}(), 0.8414709848078965, DifferentiationInterface.PushforwardPullbackPrep{Nothing, DifferentiationInterfaceForwardDiffExt.ForwardDiffOneArgPushforwardPrep{Nothing, ForwardDiff.Tag{typeof(sin), Float64}, ForwardDiff.Dual{ForwardDiff.Tag{typeof(sin), Float64}, Float64, 1}, Tuple{}}}(Val{Nothing}(), DifferentiationInterfaceForwardDiffExt.ForwardDiffOneArgPushforwardPrep{Nothing, ForwardDiff.Tag{typeof(sin), Float64}, ForwardDiff.Dual{ForwardDiff.Tag{typeof(sin), Float64}, Float64, 1}, Tuple{}}(Val{Nothing}(), ForwardDiff.Tag{typeof(sin), Float64}, Dual{ForwardDiff.Tag{typeof(sin), Float64}}(1.0,1.0), ())))
julia> prepZ = prepare_gradient(sin, backendZ, x)
DifferentiationInterface.NoGradientPrep{Nothing}(Val{Nothing}())
julia> a = randn(1000);
julia> grad = similar(a);
julia> Threads.@threads for i in eachindex(a,grad); grad[i] = DifferentiationInterface.gradient(sin, prepZ, backendZ,a[i]) ; end
julia> Threads.@threads for i in eachindex(a,grad); grad[i] = DifferentiationInterface.gradient(sin, prepFD, backendFD,a[i]) ; end
Hi,
It is more a question than a issue as I didn't see any information in the doc:
Is the preparation thread safe?
This kind of code seems to work but is it legit for all possible backend?