-
Notifications
You must be signed in to change notification settings - Fork 218
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
Subarrays/views support #172
Comments
I vaguely remember a discussion at JuliaCon about a unified array class (ie. across GPU/DL libraries) where such information would obviously need to be encoded in the struct. So that might be a valid short-term fix, because the whole array wrapping business is pretty unsolved wrt. GPU types (eg. how to broadcast over this container, Adapt.jl, etc). |
I just noticed Base.cconvert(::Type{Ptr{T}}, V::SubArray{T,N,P,<:Tuple{Vararg{RangeIndex}}}) where {T,N,P<:CuArray} =
Mem.view(unsafe_buffer(V.parent), (Base.first_index(V) - 1)*sizeof(T)) and rely on the |
Is this solution acceptable or are there GPU specific caveats? |
Correct me if I'm mistaken, but that only supports a special case of strides, right? [But I'm on board if it solves an issue for you now, of course; I don't think it would cause issues elsewhere] In principle I'd rather support general SubArrays and other wrapper types here. The nested wrapping issue has come up a lot, and if we had a good solution to those problems it should be very easy to do. Sadly, since we don't have that, supporting wrapper types leads to hacks on top of hacks. So in the shorter term I think it's fine to just put strides and offsets in the |
Are you referring to the |
|
This has been implemented now, e.g.: CUDA.jl/lib/cublas/wrappers.jl Lines 89 to 102 in bc0184e
|
I've been trying to make more of the highlevel linear algebra routines work similarly to the Base versions. For this to really work well, we'll need support for strided views where
stride(A,1)==1
butstride(A,2)>size(A,1)
. Currently, I see two approaches to supportview
forCuArrays
: 1) Make Base'sSubArray
s work forCuArray
or 2) include strides information in theCuArray
to support this.The
CuArray
struct already includes a field for offset and it wraps a memory buffer so it might make sense to makeCuArray
s more general and add a strides field. The cost is that people working explicitly with the buffer would have to be more careful about the strides information. These views would also be less general than Base'sSubArray
s but I think they'll cover the more important cases.Last night I tried the other approach, i.e. to just wrap
CuArray
s inSubArray
but it doesn't work withccall
and it might require some controversial changes to howCuArray
s are converted toPtr
if we want to go this direction. Basically, the problem is thatunsafe_convert(Ptr{T}, CuArray{T})
isn't defined and therefore you can't pass aSubArray{CuArray}
toccall
.What do people think? Which one is the better solution or have a missed a third better option? Personally, I lean towards including stride information in
CuArray
s since we already wrap a memory buffer and attach shape information so also doing this as part of aSubArray
is kind of double wrapping.The text was updated successfully, but these errors were encountered: