Skip to content

Commit

Permalink
Revert "Enzyme: Mark CuArray as noalias (#2395)"
Browse files Browse the repository at this point in the history
This reverts commit beff592.

[skip ci]
  • Loading branch information
maleadt committed May 28, 2024
1 parent beff592 commit f2062a5
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 78 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ CUDA_Runtime_jll = "0.14"
ChainRulesCore = "1"
Crayons = "4"
DataFrames = "1"
EnzymeCore = "0.7.3"
EnzymeCore = "0.7.1"
ExprTools = "0.1"
GPUArrays = "10.0.1"
GPUCompiler = "0.24, 0.25, 0.26"
Expand Down
65 changes: 0 additions & 65 deletions ext/EnzymeCoreExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,32 +99,6 @@ function EnzymeCore.EnzymeRules.forward(ofn::Const{Type{CT}},
end
end

function EnzymeCore.EnzymeRules.forward(ofn::Const{Type{CT}},
::Type{RT}, uval::EnzymeCore.Annotation{DR}, args...; kwargs...) where {CT <: CuArray, DR <: CUDA.DataRef, RT}
primargs = ntuple(Val(length(args))) do i
Base.@_inline_meta
args[i].val
end
if RT <: Duplicated
shadow = ofn.val(uval.val, primargs...; kwargs...)
Duplicated(ofn.val(uval.dval, primargs...; kwargs...), shadow)
elseif RT <: Const
ofn.val(uval.val, primargs...; kwargs...)
elseif RT <: DuplicatedNoNeed
ofn.val(uval.dval, primargs...; kwargs...)
else
tup = ntuple(Val(EnzymeCore.batch_size(RT))) do i
Base.@_inline_meta
shadow = ofn.val(uval.dval[i], primargs...; kwargs...)
end
if RT <: BatchDuplicated
BatchDuplicated(ofv.val(uval.val), tup)
else
tup
end
end
end

function EnzymeCore.EnzymeRules.forward(ofn::Const{typeof(synchronize)},
::Type{RT}, args::Vararg{EnzymeCore.Annotation, N}; kwargs...) where {RT, N}
pargs = ntuple(Val(N)) do i
Expand Down Expand Up @@ -295,44 +269,5 @@ function EnzymeCore.EnzymeRules.reverse(config, ofn::Const{Type{CT}}, ::Type{RT}
nothing
end
end

function EnzymeCore.EnzymeRules.augmented_primal(config, ofn::Const{Type{CT}}, ::Type{RT}, uval::EnzymeCore.Annotation{DR}, args...; kwargs...) where {CT <: CuArray, DR <: CUDA.DataRef, RT}
primargs = ntuple(Val(length(args))) do i
Base.@_inline_meta
args[i].val
end

primal = if EnzymeRules.needs_primal(config)
ofn.val(uval.val, primargs...; kwargs...)
else
nothing
end

shadow = if EnzymeRules.needs_shadow(config)
if EnzymeRules.width(config) == 1
ofn.val(uval.dval, primargs...; kwargs...)
else
ntuple(Val(EnzymeRules.width(config))) do i
Base.@_inline_meta
ofn.val(uval.dval[i], primargs...; kwargs...)
end
end
else
nothing
end
return EnzymeRules.AugmentedReturn{(EnzymeRules.needs_primal(config) ? CT : Nothing), (EnzymeRules.needs_shadow(config) ? (EnzymeRules.width(config) == 1 ? CT : NTuple{EnzymeRules.width(config), CT}) : Nothing), Nothing}(primal, shadow, nothing)
end

function EnzymeCore.EnzymeRules.reverse(config, ofn::Const{Type{CT}}, ::Type{RT}, tape, A::EnzymeCore.Annotation{DR}, args::Vararg{EnzymeCore.Annotation, N}; kwargs...) where {CT <: CuArray, DR <: CUDA.DataRef, RT, N}
ntuple(Val(N+1)) do i
Base.@_inline_meta
nothing
end
end

function EnzymeCore.EnzymeRules.noalias(::Type{CT}, ::UndefInitializer, args...) where {CT <: CuArray}
return nothing
end

end # module

12 changes: 0 additions & 12 deletions test/extensions/enzyme.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,6 @@ end
@test all(shad .≈ 0.0)
end

firstsum(x, y) = first(x .+ y)
@testset "Forward broadcast" begin
x = CuArray(5*ones(5))
y = CuArray(3*ones(5))
dx = CuArray([1.0, 0.0, 0.0, 0.0, 0.0])
dy = CuArray([0.2, 0.0, 0.1, 0.0, 0.0])
f(x, y)
res = autodiff(Forward, firstsum, Duplicated, Duplicated(x, dx), Duplicated(y, dy))
@test res[1] 8
@test res[2] 1.2
end

# TODO once reverse kernels are in
# function togpu(x)
# x = CuArray(x)
Expand Down

2 comments on commit f2062a5

@maleadt
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/107777

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v5.4.0 -m "<description of version>" f2062a5c6e8781662a8464f54b35b15541e22a3b
git push origin v5.4.0

Please sign in to comment.