Skip to content
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

Allow single indexing of arrays of GPU arrays #760

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ChainRules"
uuid = "082447d4-558c-5d27-93f4-14fc19e9eca2"
version = "1.58.0"
version = "1.58.1"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
2 changes: 1 addition & 1 deletion src/rulesets/Base/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ end
ChainRules.@non_differentiable _setindex_zero(x::AbstractArray, dy::Any, inds::Any...)

function ∇getindex!(dx::AbstractArray, dy, inds::Integer...)
view(dx, inds...) .+= Ref(dy)
@views dx[inds...] += dy
return dx
end
function ∇getindex!(dx::AbstractArray, dy, inds...)
Expand Down
8 changes: 8 additions & 0 deletions test/rulesets/Base/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ end
@test Array(y3) == Array(x_23_gpu)[1, [1,1,2]]
@test unthunk(bk3(jl(ones(3)))[2]) == jl([2 1 0; 0 0 0])
end

@testset "getindex(::Array{<:AbstractGPUArray})" begin
x_gpu = jl(rand(1))
y, back = rrule(getindex, [x_gpu], 1)
@test y === x_gpu
dxs_gpu = unthunk(back(jl([1.0]))[2])
@test dxs_gpu == [jl([1.0])]
end
end

# first & tail handled by getfield rules
Expand Down
Loading