Skip to content

WIP: GPU-compatibility of Jacobians #406

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions src/apiutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,36 +55,31 @@ end

function seed!(duals::AbstractArray{Dual{T,V,N}}, x,
seed::Partials{N,V} = zero(Partials{N,V})) where {T,V,N}
for i in eachindex(duals)
duals[i] = Dual{T,V,N}(x[i], seed)
end
duals .= Dual{T,V,N}.(x, (seed,))
return duals
end

function seed!(duals::AbstractArray{Dual{T,V,N}}, x,
seeds::NTuple{N,Partials{N,V}}) where {T,V,N}
for i in 1:N
duals[i] = Dual{T,V,N}(x[i], seeds[i])
end
i = 1:N
@views duals[i] .= Dual{T,V,N}.(x[i], seeds)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps these @views could be reduced in "strength" by putting them where they are needed, e.g. only on the x[i]? And could the usage of @. be consistent among the changes (it's not used here, but used in other places).

return duals
end

function seed!(duals::AbstractArray{Dual{T,V,N}}, x, index,
seed::Partials{N,V} = zero(Partials{N,V})) where {T,V,N}
offset = index - 1
for i in 1:N
j = i + offset
duals[j] = Dual{T,V,N}(x[j], seed)
end
i = 1:N
j = i .+ offset
@views @. duals[j] = Dual{T,V,N}(x[j], seed)
return duals
end

function seed!(duals::AbstractArray{Dual{T,V,N}}, x, index,
seeds::NTuple{N,Partials{N,V}}, chunksize = N) where {T,V,N}
offset = index - 1
for i in 1:chunksize
j = i + offset
duals[j] = Dual{T,V,N}(x[j], seeds[i])
end
i = 1:chunksize
j = i .+ offset
@views @. duals[j] = Dual{T,V,N}(x[j], seeds[i])
return duals
end