-
Notifications
You must be signed in to change notification settings - Fork 234
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
Better support for unified and host memory #2138
Merged
Merged
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
dd0a37f
Allow scalar indexing with unified arrays.
maleadt 331573d
Make the default memory type configurable.
maleadt f3383df
Fix null ctor.
maleadt 085fb0c
Fix unsafe_wrap.
maleadt d5e6f1f
Fix some tests.
maleadt 0a68110
Fix another default constructor.
maleadt cce48cc
Bugfix.
maleadt 579309c
Test fixes.
maleadt a48715f
Pointer conversion improvements.
maleadt 9a498c3
Report preferences in the versioninfo output.
maleadt 427eb3e
Keep the default on device memory, but test unified memory support.
maleadt 9ecbdfd
Skip scalar indexing tests when using unified memory.
maleadt e945351
Store the dirty bit in task local storage, for correctness.
maleadt 4873f56
Prefetch unified memory before kernel launches.
maleadt 6f9c4ad
Rework unsafe_wrap.
maleadt fc63805
Better support for host memory.
maleadt 5460bfb
Run CI with host memory too.
maleadt 7bacf91
Add bounds checking to optimized scalar indexing functions.
maleadt f377f81
Try testing libraries with host memory.
maleadt 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 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 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 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 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 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 |
---|---|---|
|
@@ -121,35 +121,44 @@ end | |
|
||
## host to device value conversion | ||
|
||
struct Adaptor end | ||
struct KernelAdaptor end | ||
|
||
# convert CUDA host pointers to device pointers | ||
# TODO: use ordinary ptr? | ||
Adapt.adapt_storage(to::Adaptor, p::CuPtr{T}) where {T} = reinterpret(LLVMPtr{T,AS.Generic}, p) | ||
Adapt.adapt_storage(to::KernelAdaptor, p::CuPtr{T}) where {T} = | ||
reinterpret(LLVMPtr{T,AS.Generic}, p) | ||
|
||
# convert CUDA host arrays to device arrays | ||
function Adapt.adapt_storage(::KernelAdaptor, xs::DenseCuArray{T,N}) where {T,N} | ||
# prefetch unified memory as we're likely to use it on the GPU | ||
# TODO: make this configurable? | ||
if is_unified(xs) && sizeof(xs) > 0 && !is_capturing() | ||
buf = xs.data[] | ||
subbuf = Mem.UnifiedBuffer(buf.ctx, pointer(xs), sizeof(xs)) | ||
Mem.prefetch(subbuf) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pmccormick you were asking me about this yesterday. |
||
end | ||
|
||
Base.unsafe_convert(CuDeviceArray{T,N,AS.Global}, xs) | ||
end | ||
|
||
# Base.RefValue isn't GPU compatible, so provide a compatible alternative | ||
struct CuRefValue{T} <: Ref{T} | ||
x::T | ||
end | ||
Base.getindex(r::CuRefValue{T}) where T = r.x | ||
Adapt.adapt_structure(to::Adaptor, r::Base.RefValue) = CuRefValue(adapt(to, r[])) | ||
Adapt.adapt_structure(to::KernelAdaptor, r::Base.RefValue) = CuRefValue(adapt(to, r[])) | ||
|
||
# broadcast sometimes passes a ref(type), resulting in a GPU-incompatible DataType box. | ||
# avoid that by using a special kind of ref that knows about the boxed type. | ||
struct CuRefType{T} <: Ref{DataType} end | ||
Base.getindex(r::CuRefType{T}) where T = T | ||
Adapt.adapt_structure(to::Adaptor, r::Base.RefValue{<:Union{DataType,Type}}) = CuRefType{r[]}() | ||
Adapt.adapt_structure(to::KernelAdaptor, r::Base.RefValue{<:Union{DataType,Type}}) = | ||
CuRefType{r[]}() | ||
|
||
# case where type is the function being broadcasted | ||
Adapt.adapt_structure(to::Adaptor, bc::Base.Broadcast.Broadcasted{Style, <:Any, Type{T}}) where {Style, T} = | ||
Base.Broadcast.Broadcasted{Style}((x...) -> T(x...), adapt(to, bc.args), bc.axes) | ||
|
||
Adapt.adapt_storage(::Adaptor, xs::CuArray{T,N}) where {T,N} = | ||
Base.unsafe_convert(CuDeviceArray{T,N,AS.Global}, xs) | ||
|
||
# we materialize ReshapedArray/ReinterpretArray/SubArray/... directly as a device array | ||
Adapt.adapt_structure(::Adaptor, xs::DenseCuArray{T,N}) where {T,N} = | ||
Base.unsafe_convert(CuDeviceArray{T,N,AS.Global}, xs) | ||
Adapt.adapt_structure(to::KernelAdaptor, | ||
bc::Broadcast.Broadcasted{Style, <:Any, Type{T}}) where {Style, T} = | ||
Broadcast.Broadcasted{Style}((x...) -> T(x...), adapt(to, bc.args), bc.axes) | ||
|
||
""" | ||
cudaconvert(x) | ||
|
@@ -159,9 +168,9 @@ converted to a GPU-friendly format. By default, the function does nothing and re | |
input object `x` as-is. | ||
|
||
Do not add methods to this function, but instead extend the underlying Adapt.jl package and | ||
register methods for the the `CUDA.Adaptor` type. | ||
register methods for the the `CUDA.KernelAdaptor` type. | ||
""" | ||
cudaconvert(arg) = adapt(Adaptor(), arg) | ||
cudaconvert(arg) = adapt(KernelAdaptor(), arg) | ||
|
||
|
||
## abstract kernel functionality | ||
|
This file contains 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really need to finish TaskLocalValues.jl xD