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

Add native GPU support. #504

Merged
merged 5 commits into from
Jul 30, 2022
Merged

Add native GPU support. #504

merged 5 commits into from
Jul 30, 2022

Conversation

N5N3
Copy link
Contributor

@N5N3 N5N3 commented Jul 27, 2022

Only 1d and 2d BSpline Interpolations are tested though.
Test has been added for Gridded and Lanczos.
Since this overload needs GPUArraysCore.jl, we need to drop < 1.6 compatibility if we don't want to add more @require.
Base.getindex is overloaded with a InterpGetIndex wrapper in the latest design. Thus there's no need to depend on GPUArraysCore.jl. (We can keep < 1.6 compatibility now)

@codecov
Copy link

codecov bot commented Jul 27, 2022

Codecov Report

Merging #504 (074110e) into master (4c29ad6) will increase coverage by 0.18%.
The diff coverage is 97.05%.

@@            Coverage Diff             @@
##           master     #504      +/-   ##
==========================================
+ Coverage   86.91%   87.10%   +0.18%     
==========================================
  Files          27       28       +1     
  Lines        1819     1845      +26     
==========================================
+ Hits         1581     1607      +26     
  Misses        238      238              
Impacted Files Coverage Δ
src/b-splines/indexing.jl 78.57% <75.00%> (ø)
src/gpu_support.jl 97.67% <97.67%> (ø)
src/Interpolations.jl 75.92% <100.00%> (-3.61%) ⬇️
src/b-splines/b-splines.jl 90.09% <100.00%> (+0.09%) ⬆️
src/extrapolation/extrapolation.jl 70.78% <100.00%> (ø)
src/gridded/indexing.jl 75.21% <100.00%> (ø)
src/lanczos/lanczos.jl 100.00% <100.00%> (ø)
src/scaling/scaling.jl 90.57% <100.00%> (ø)
src/gridded/gridded.jl 98.41% <0.00%> (+1.58%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4c29ad6...074110e. Read the comment docs.

@mkitti
Copy link
Collaborator

mkitti commented Jul 27, 2022

I'm a bit wary of dependency creep. Is there a way to do this via a subpackage?

@johnnychen94
Copy link
Contributor

The additional dependencies are quite small (loading time from 0.74s to 0.79s in my machine). But they request bumping Julia compat to 1.6, which is okay as well (I think).

Either living in here or in the new interpolationsGPU would be great!

cc: @timholy @ChantalJuntao (from JuliaImages/ImageTransformations.jl#156)

Copy link
Collaborator

@mkitti mkitti left a comment

Choose a reason for hiding this comment

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

Just a few questions ...

Copy link
Collaborator

@mkitti mkitti left a comment

Choose a reason for hiding this comment

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

This looks pretty good to me. Could you add some developer documentation about how to use Adapt when someone adds a new interpolation tyoe?

@mkitti
Copy link
Collaborator

mkitti commented Jul 29, 2022

In particular, can you please update this document:
https://github.com/JuliaMath/Interpolations.jl/blob/master/docs/src/devdocs.md

@N5N3
Copy link
Contributor Author

N5N3 commented Jul 29, 2022

@mkitti devdoc has been updated (including the new InterpGetindex wrapper).
The Adapt based transformation itself should be familiar to every GPU end users.
So I just emphasize that 'eltype' may change during adaption.

Copy link
Collaborator

@mkitti mkitti left a comment

Choose a reason for hiding this comment

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

I did some editing on the documentation.

Also I notice there are some cases that are not covered by the tests. Could you expand test coverage?

Comment on lines 190 to 192
To achieve this, an `ITP <: AbstractInterpolation` should define it's own `Adapt.adapt_structure(to, itp::ITP)`, which constructs a new `ITP` with the adapted
fields (`adapt(to, itp.fieldname)`) of `itp`. The field adaption could be skipped
if we know that it has been GPU-compatable, e.g. a bit range.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
To achieve this, an `ITP <: AbstractInterpolation` should define it's own `Adapt.adapt_structure(to, itp::ITP)`, which constructs a new `ITP` with the adapted
fields (`adapt(to, itp.fieldname)`) of `itp`. The field adaption could be skipped
if we know that it has been GPU-compatable, e.g. a bit range.
To achieve this, an `ITP <: AbstractInterpolation` should define its own `Adapt.adapt_structure(to, itp::ITP)`.
`adapt_structure` constructs a new `ITP` with the adapted fields of `itp` as defined by `adapt(to, itp.fieldname)`. The field adaption could be skipped if we know that it is been GPU-compatable, e.g. a bit range.

Also what do you mean by "bit range" here. Do you mean bit type where isbitstype is true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, has been replaced with "a isbit range"

Base.@propagate_inbounds Base.getindex(A::InterpGetindex{N}, I::Vararg{Union{Int,WeightedIndex},N}) where {N} =
interp_getindex(A.coeffs, I, ntuple(d->0, Val(N))...)

# TODO: should we drop the following injection?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you elaborate? Is this fully obsolete now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Base._getindex is an internal api anyway. Since Interpolations.jl itself no-longer use it. It makes sense to me to dop it.

N5N3 and others added 5 commits July 30, 2022 05:49
Co-Authored-By: Mark Kittisopikul <[email protected]>
This should omit the `isempty` check if inference give good result.

fix test on 1.6, `range(2, 19.0, 101)` was introduced in 1.7
and remove unneeded `@propagate_inbounds`.
And fix the inference problem.
@mkitti
Copy link
Collaborator

mkitti commented Jul 29, 2022

Is this ready to merge?

@N5N3
Copy link
Contributor Author

N5N3 commented Jul 30, 2022

Yes, CI passed. The test also passed locally with 1.6.7.

@mkitti mkitti merged commit 6ec8f1f into JuliaMath:master Jul 30, 2022
@N5N3 N5N3 deleted the GPUsupport branch July 30, 2022 04:16
@ChantalJuntao
Copy link

Only 1d and 2d BSpline Interpolations are tested though. Test has been added for Gridded and Lanczos. Since this overload needs GPUArraysCore.jl, we need to drop < 1.6 compatibility if we don't want to add more @require. Base.getindex is overloaded with a InterpGetIndex wrapper in the latest design. Thus there's no need to depend on GPUArraysCore.jl. (We can keep < 1.6 compatibility now)

This is kind of late, but was it OK to merge this without tests for 3D? And I thought that Cl's tests don't cover GPU code?

@mkitti
Copy link
Collaborator

mkitti commented Jul 30, 2022

Feel free to submit another pull request. As far as I know there are no GPUs to run CI on here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants