-
Notifications
You must be signed in to change notification settings - Fork 112
Add native GPU support. #504
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2cdba1d
Native GPU support.
N5N3 c8cebe2
Add some devdoc
N5N3 4946547
Simplify `update_eltype` and add more test
N5N3 4ebd975
Fully drop the old indexing overload for `WeightedIndex`.
N5N3 074110e
Reenable non-generated `interp_getindex`.
N5N3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import Adapt: adapt_structure | ||
using Adapt: adapt | ||
|
||
function adapt_structure(to, itp::BSplineInterpolation{T,N}) where {T,N} | ||
coefs′ = adapt(to, itp.coefs) | ||
T′ = update_eltype(T, coefs′, itp.coefs) | ||
BSplineInterpolation{T′,N}(coefs′, itp.parentaxes, itp.it) | ||
end | ||
|
||
function update_eltype(T, coefs′, coefs) | ||
ET = eltype(coefs′) | ||
ET === eltype(coefs) && return T | ||
WT = tweight(coefs′) | ||
T′ = Base.promote_op(*, WT, ET) | ||
(isconcretetype(T′) || isempty(coefs)) && return T′ | ||
return typeof(zero(WT) * convert(ET, first(coefs))) | ||
end | ||
|
||
function adapt_structure(to, itp::LanczosInterpolation{T,N}) where {T,N} | ||
coefs′ = adapt(to, itp.coefs) | ||
parentaxes′ = adapt(to, itp.parentaxes) | ||
LanczosInterpolation{eltype(coefs′),N}(coefs′, parentaxes′, itp.it) | ||
end | ||
|
||
function adapt_structure(to, itp::GriddedInterpolation{T,N}) where {T,N} | ||
coefs′ = adapt(to, itp.coefs) | ||
knots′ = adapt(to, itp.knots) | ||
T′ = update_eltype(T, coefs′, itp.coefs) | ||
GriddedInterpolation{T′,N,typeof(coefs′),itptype(itp),typeof(knots′)}(knots′, coefs′, itp.it) | ||
end | ||
|
||
function adapt_structure(to, itp::ScaledInterpolation{T,N,<:Any,IT,RT}) where {T,N,IT,RT<:NTuple{N,AbstractRange}} | ||
ranges = itp.ranges | ||
itp′ = adapt(to, itp.itp) | ||
ScaledInterpolation{eltype(itp′),N,typeof(itp′),IT,RT}(itp′, ranges) | ||
end | ||
|
||
function adapt_structure(to, itp::Extrapolation{T,N}) where {T,N} | ||
et = itp.et | ||
itp′ = adapt(to, itp.itp) | ||
Extrapolation{eltype(itp′),N,typeof(itp′),itptype(itp),typeof(et)}(itp′, et) | ||
end | ||
|
||
import Base.Broadcast: broadcasted, BroadcastStyle | ||
using Base.Broadcast: broadcastable, combine_styles, AbstractArrayStyle | ||
function broadcasted(itp::AbstractInterpolation, args...) | ||
args′ = map(broadcastable, args) | ||
# we overload BroadcastStyle here (try our best to do broadcast on GPU) | ||
style = combine_styles(Ref(itp), args′...) | ||
broadcasted(style, itp, args′...) | ||
end | ||
|
||
""" | ||
Interpolations.root_storage_type(::Type{<:AbstractInterpolation}) -> Type{<:AbstractArray} | ||
|
||
This function returns the type of the root cofficients array of an `AbstractInterpolation`. | ||
Some array wrappers, like `OffsetArray`, should be skipped. | ||
""" | ||
root_storage_type(::Type{T}) where {T<:Extrapolation} = root_storage_type(fieldtype(T, 1)) | ||
root_storage_type(::Type{T}) where {T<:ScaledInterpolation} = root_storage_type(fieldtype(T, 1)) | ||
root_storage_type(::Type{T}) where {T<:BSplineInterpolation} = root_storage_type(fieldtype(T, 1)) | ||
root_storage_type(::Type{T}) where {T<:LanczosInterpolation} = root_storage_type(fieldtype(T, 1)) | ||
root_storage_type(::Type{T}) where {T<:GriddedInterpolation} = root_storage_type(fieldtype(T, 2)) | ||
root_storage_type(::Type{T}) where {T<:OffsetArray} = root_storage_type(fieldtype(T, 1)) | ||
root_storage_type(::Type{T}) where {T<:AbstractArray} = T | ||
|
||
BroadcastStyle(::Type{<:Ref{T}}) where {T<:AbstractInterpolation} = _to_scalar_style(BroadcastStyle(T)) | ||
BroadcastStyle(::Type{T}) where {T<:AbstractInterpolation} = BroadcastStyle(root_storage_type(T)) | ||
|
||
_to_scalar_style(::S) where {S<:AbstractArrayStyle} = S(Val(0)) | ||
_to_scalar_style(S::AbstractArrayStyle{Any}) = S | ||
_to_scalar_style(S) = S |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.