Skip to content

Commit

Permalink
[EnzymeCore] Move adapt to extension (#1232)
Browse files Browse the repository at this point in the history
* [EnzymeCore] Move adapt to extension

* Update pipeline.yml
  • Loading branch information
wsmoses authored Jan 5, 2024
1 parent 443f798 commit bcf7246
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
1 change: 0 additions & 1 deletion .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ steps:
matrix:
setup:
version:
- "1.8"
- "1.9"
- "1.10"
plugins:
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Enzyme"
uuid = "7da242da-08ed-463a-9acd-ee780be4f1d9"
authors = ["William Moses <[email protected]>", "Valentin Churavy <[email protected]>"]
version = "0.11.12"
version = "0.11.13"

[deps]
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
Expand All @@ -18,7 +18,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[compat]
CEnum = "0.4, 0.5"
EnzymeCore = "0.6.4"
EnzymeCore = "0.6.4, 0.6.5"
Enzyme_jll = "0.0.98"
GPUCompiler = "0.21, 0.22, 0.23, 0.24, 0.25"
LLVM = "6.1"
Expand Down
16 changes: 11 additions & 5 deletions lib/EnzymeCore/Project.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
name = "EnzymeCore"
uuid = "f151be2c-9106-41f4-ab19-57ee4f262869"
authors = ["William Moses <[email protected]>", "Valentin Churavy <[email protected]>"]
version = "0.6.4"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
version = "0.6.5"

[compat]
Adapt = "3.3"
Adapt = "3, 4"
julia = "1.6"

[extensions]
AdaptExt = "Adapt"

[extras]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

[weakdeps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
11 changes: 11 additions & 0 deletions lib/EnzymeCore/ext/AdaptExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module AdaptExt
using Adapt
using EnzymeCore

Adapt.adapt_structure(to, x::Const) = Const(adapt(to, x.val))
Adapt.adapt_structure(to, x::Active) = Active(adapt(to, x.val))
Adapt.adapt_structure(to, x::Duplicated) = Duplicated(adapt(to, x.val), adapt(to, x.dval))
Adapt.adapt_structure(to, x::DuplicatedNoNeed) = DuplicatedNoNeed(adapt(to, x.val), adapt(to, x.dval))
Adapt.adapt_structure(to, x::BatchDuplicated) = BatchDuplicated(adapt(to, x.val), adapt(to, x.dval))
Adapt.adapt_structure(to, x::BatchDuplicatedNoNeed) = BatchDuplicatedNoNeed(adapt(to, x.val), adapt(to, x.dval))
end
8 changes: 0 additions & 8 deletions lib/EnzymeCore/src/EnzymeCore.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module EnzymeCore

using Adapt

export Forward, Reverse, ReverseWithPrimal, ReverseSplitNoPrimal, ReverseSplitWithPrimal
export ReverseSplitModified, ReverseSplitWidth
export Const, Active, Duplicated, DuplicatedNoNeed, BatchDuplicated, BatchDuplicatedNoNeed
Expand All @@ -28,7 +26,6 @@ Enzyme will not auto-differentiate in respect `Const` arguments.
struct Const{T} <: Annotation{T}
val::T
end
Adapt.adapt_structure(to, x::Const) = Const(adapt(to, x.val))

# To deal with Const(Int) and prevent it to go to `Const{DataType}(T)`
Const(::Type{T}) where T = Const{Type{T}}(T)
Expand All @@ -50,7 +47,6 @@ struct Active{T} <: Annotation{T}
@inline Active(x::T1) where {T1} = new{T1}(x)
@inline Active(x::T1) where {T1 <: Array} = error("Unsupported Active{"*string(T1)*"}, consider Duplicated or Const")
end
Adapt.adapt_structure(to, x::Active) = Active(adapt(to, x.val))

Active(i::Integer) = Active(float(i))

Expand All @@ -75,7 +71,6 @@ struct Duplicated{T} <: Annotation{T}
new{T1}(x, dx)
end
end
Adapt.adapt_structure(to, x::Duplicated) = Duplicated(adapt(to, x.val), adapt(to, x.dval))

"""
DuplicatedNoNeed(x, ∂f_∂x)
Expand All @@ -96,7 +91,6 @@ struct DuplicatedNoNeed{T} <: Annotation{T}
new{T1}(x, dx)
end
end
Adapt.adapt_structure(to, x::DuplicatedNoNeed) = DuplicatedNoNeed(adapt(to, x.val), adapt(to, x.dval))

"""
BatchDuplicated(x, ∂f_∂xs)
Expand All @@ -119,7 +113,6 @@ struct BatchDuplicated{T,N} <: Annotation{T}
new{T1, N}(x, dx)
end
end
Adapt.adapt_structure(to, x::BatchDuplicated) = BatchDuplicated(adapt(to, x.val), adapt(to, x.dval))

struct BatchDuplicatedFunc{T,N,Func} <: Annotation{T}
val::T
Expand Down Expand Up @@ -154,7 +147,6 @@ end
@inline batch_size(::Type{BatchDuplicated{T,N}}) where {T,N} = N
@inline batch_size(::Type{BatchDuplicatedFunc{T,N}}) where {T,N} = N
@inline batch_size(::Type{BatchDuplicatedNoNeed{T,N}}) where {T,N} = N
Adapt.adapt_structure(to, x::BatchDuplicatedNoNeed) = BatchDuplicatedNoNeed(adapt(to, x.val), adapt(to, x.dval))


"""
Expand Down

2 comments on commit bcf7246

@wsmoses
Copy link
Member Author

@wsmoses wsmoses commented on bcf7246 Jan 5, 2024

Choose a reason for hiding this comment

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

@JuliaRegistrator register subdir="lib/EnzymeCore"

@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/98245

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 EnzymeCore-v0.6.5 -m "<description of version>" bcf72469d477f5dcc768dd47fcefd47eaedb86b9
git push origin EnzymeCore-v0.6.5

Please sign in to comment.