1
- # core definition of the GPUArray type
1
+ # core definition of the AbstractGPUArray type
2
2
3
- export GPUArray
3
+ export AbstractGPUArray
4
4
5
- abstract type GPUArray {T, N} <: DenseArray{T, N} end
5
+ abstract type AbstractGPUArray {T, N} <: DenseArray{T, N} end
6
6
7
7
# Sampler type that acts like a texture/image and allows interpolated access
8
8
abstract type Sampler{T, N} <: DenseArray{T, N} end
9
9
10
- const GPUVector{T} = GPUArray {T, 1 }
11
- const GPUMatrix{T} = GPUArray {T, 2 }
12
- const GPUVecOrMat{T} = Union{GPUArray {T, 1 }, GPUArray {T, 2 }}
10
+ const GPUVector{T} = AbstractGPUArray {T, 1 }
11
+ const GPUMatrix{T} = AbstractGPUArray {T, 2 }
12
+ const GPUVecOrMat{T} = Union{AbstractGPUArray {T, 1 }, AbstractGPUArray {T, 2 }}
13
13
14
14
# input/output
15
15
16
16
# # serialization
17
17
18
18
import Serialization: AbstractSerializer, serialize, deserialize, serialize_type
19
19
20
- function serialize (s:: AbstractSerializer , t:: T ) where T <: GPUArray
20
+ function serialize (s:: AbstractSerializer , t:: T ) where T <: AbstractGPUArray
21
21
serialize_type (s, T)
22
22
serialize (s, Array (t))
23
23
end
24
- function deserialize (s:: AbstractSerializer , :: Type{T} ) where T <: GPUArray
24
+ function deserialize (s:: AbstractSerializer , :: Type{T} ) where T <: AbstractGPUArray
25
25
A = deserialize (s)
26
26
T (A)
27
27
end
@@ -56,15 +56,15 @@ convert_to_cpu(xs) = adapt(Array, xs)
56
56
for (W, ctor) in (:AT => (A,mut)-> mut (A), Adapt. wrappers... )
57
57
@eval begin
58
58
# display
59
- Base. print_array (io:: IO , X:: $W where {AT <: GPUArray }) =
59
+ Base. print_array (io:: IO , X:: $W where {AT <: AbstractGPUArray }) =
60
60
Base. print_array (io, $ ctor (X, convert_to_cpu))
61
61
62
62
# show
63
- Base. _show_nonempty (io:: IO , X:: $W where {AT <: GPUArray }, prefix:: String ) =
63
+ Base. _show_nonempty (io:: IO , X:: $W where {AT <: AbstractGPUArray }, prefix:: String ) =
64
64
Base. _show_nonempty (io, $ ctor (X, convert_to_cpu), prefix)
65
- Base. _show_empty (io:: IO , X:: $W where {AT <: GPUArray }) =
65
+ Base. _show_empty (io:: IO , X:: $W where {AT <: AbstractGPUArray }) =
66
66
Base. _show_empty (io, $ ctor (X, convert_to_cpu))
67
- Base. show_vector (io:: IO , v:: $W where {AT <: GPUArray }, args... ) =
67
+ Base. show_vector (io:: IO , v:: $W where {AT <: AbstractGPUArray }, args... ) =
68
68
Base. show_vector (io, $ ctor (v, convert_to_cpu), args... )
69
69
end
70
70
end
@@ -75,7 +75,7 @@ collect_to_cpu(xs::AbstractArray) = collect(convert_to_cpu(xs))
75
75
76
76
for (W, ctor) in (:AT => (A,mut)-> mut (A), Adapt. wrappers... )
77
77
@eval begin
78
- Base. collect (X:: $W where {AT <: GPUArray }) = collect_to_cpu (X)
78
+ Base. collect (X:: $W where {AT <: AbstractGPUArray }) = collect_to_cpu (X)
79
79
end
80
80
end
81
81
86
86
87
87
# convert to something we can get a pointer to
88
88
materialize (x:: AbstractArray ) = Array (x)
89
- materialize (x:: GPUArray ) = x
89
+ materialize (x:: AbstractGPUArray ) = x
90
90
materialize (x:: Array ) = x
91
91
92
- # TODO : do we want to support `copyto(..., WrappedArray{GPUArray })`
92
+ # TODO : do we want to support `copyto(..., WrappedArray{AbstractGPUArray })`
93
93
# if so (does not work due to lack of copy constructors):
94
94
# for (W, ctor) in (:AT => (A,mut)->mut(A), Adapt.wrappers...)
95
95
# @eval begin
96
- # materialize(X::$W) where {AT <: GPUArray } = AT(X)
96
+ # materialize(X::$W) where {AT <: AbstractGPUArray } = AT(X)
97
97
# end
98
98
# end
99
99
100
- for (D, S) in ((GPUArray , AbstractArray), (Array, GPUArray ), (GPUArray, GPUArray ))
100
+ for (D, S) in ((AbstractGPUArray , AbstractArray), (Array, AbstractGPUArray ), (AbstractGPUArray, AbstractGPUArray ))
101
101
@eval begin
102
102
function Base. copyto! (dest:: $D{T, N} , rdest:: NTuple{N, UnitRange} ,
103
103
src:: $S{T, N} , ssrc:: NTuple{N, UnitRange} ) where {T, N}
128
128
129
129
# # generalized blocks of heterogeneous memory
130
130
131
- Base. copyto! (dest:: GPUArray , src:: GPUArray ) =
131
+ Base. copyto! (dest:: AbstractGPUArray , src:: AbstractGPUArray ) =
132
132
copyto! (dest, CartesianIndices (dest), src, CartesianIndices (src))
133
133
134
134
function copy_kernel! (state, dest, dest_offsets, src, src_offsets, shape, shape_dest, shape_source, length)
@@ -143,8 +143,8 @@ function copy_kernel!(state, dest, dest_offsets, src, src_offsets, shape, shape_
143
143
return
144
144
end
145
145
146
- function Base. copyto! (dest:: GPUArray {T, N} , destcrange:: CartesianIndices{N} ,
147
- src:: GPUArray {U, N} , srccrange:: CartesianIndices{N} ) where {T, U, N}
146
+ function Base. copyto! (dest:: AbstractGPUArray {T, N} , destcrange:: CartesianIndices{N} ,
147
+ src:: AbstractGPUArray {U, N} , srccrange:: CartesianIndices{N} ) where {T, U, N}
148
148
shape = size (destcrange)
149
149
if shape != size (srccrange)
150
150
throw (DimensionMismatch (" Ranges don't match their size. Found: $shape , $(size (srccrange)) " ))
@@ -159,7 +159,7 @@ function Base.copyto!(dest::GPUArray{T, N}, destcrange::CartesianIndices{N},
159
159
dest
160
160
end
161
161
162
- function Base. copyto! (dest:: GPUArray {T, N} , destcrange:: CartesianIndices{N} ,
162
+ function Base. copyto! (dest:: AbstractGPUArray {T, N} , destcrange:: CartesianIndices{N} ,
163
163
src:: AbstractArray{T, N} , srccrange:: CartesianIndices{N} ) where {T, N}
164
164
# Is this efficient? Maybe!
165
165
# TODO : compare to a pure intrinsic copyto implementation!
@@ -172,7 +172,7 @@ function Base.copyto!(dest::GPUArray{T, N}, destcrange::CartesianIndices{N},
172
172
end
173
173
174
174
function Base. copyto! (dest:: AbstractArray{T, N} , destcrange:: CartesianIndices{N} ,
175
- src:: GPUArray {T, N} , srccrange:: CartesianIndices{N} ) where {T, N}
175
+ src:: AbstractGPUArray {T, N} , srccrange:: CartesianIndices{N} ) where {T, N}
176
176
# Is this efficient? Maybe!
177
177
dest_gpu = similar (src, size (destcrange))
178
178
nrange = CartesianIndices (size (dest_gpu))
183
183
184
184
# # other
185
185
186
- Base. copy (x:: GPUArray ) = identity .(x)
186
+ Base. copy (x:: AbstractGPUArray ) = identity .(x)
187
187
188
- Base. deepcopy (x:: GPUArray ) = copy (x)
188
+ Base. deepcopy (x:: AbstractGPUArray ) = copy (x)
189
189
190
190
191
191
# reinterpret
@@ -221,20 +221,20 @@ This makes it easier to do checks just on the high level.
221
221
"""
222
222
function unsafe_reinterpret end
223
223
224
- function reinterpret (:: Type{T} , a:: GPUArray {S,1} ) where T where S
224
+ function reinterpret (:: Type{T} , a:: AbstractGPUArray {S,1} ) where T where S
225
225
nel = (length (a)* sizeof (S)) ÷ sizeof (T)
226
226
# TODO : maybe check that remainder is zero?
227
227
return reinterpret (T, a, (nel,))
228
228
end
229
229
230
- function reinterpret (:: Type{T} , a:: GPUArray {S} ) where T where S
230
+ function reinterpret (:: Type{T} , a:: AbstractGPUArray {S} ) where T where S
231
231
if sizeof (S) != sizeof (T)
232
232
throw (ArgumentError (" result shape not specified" ))
233
233
end
234
234
reinterpret (T, a, size (a))
235
235
end
236
236
237
- function reinterpret (:: Type{T} , a:: GPUArray {S} , dims:: NTuple{N, Integer} ) where T where S where N
237
+ function reinterpret (:: Type{T} , a:: AbstractGPUArray {S} , dims:: NTuple{N, Integer} ) where T where S where N
238
238
if ! isbitstype (T)
239
239
throw (ArgumentError (" cannot reinterpret Array{$(S) } to ::Type{Array{$(T) }}, type $(T) is not a bits type" ))
240
240
end
@@ -248,13 +248,13 @@ function reinterpret(::Type{T}, a::GPUArray{S}, dims::NTuple{N, Integer}) where
248
248
unsafe_reinterpret (T, a, dims)
249
249
end
250
250
251
- function Base. _reshape (A:: GPUArray {T} , dims:: Dims ) where T
251
+ function Base. _reshape (A:: AbstractGPUArray {T} , dims:: Dims ) where T
252
252
n = length (A)
253
253
prod (dims) == n || throw (DimensionMismatch (" parent has $n elements, which is incompatible with size $dims " ))
254
254
return unsafe_reinterpret (T, A, dims)
255
255
end
256
256
# ambig
257
- function Base. _reshape (A:: GPUArray {T, 1} , dims:: Tuple{Integer} ) where T
257
+ function Base. _reshape (A:: AbstractGPUArray {T, 1} , dims:: Tuple{Integer} ) where T
258
258
n = Base. _length (A)
259
259
prod (dims) == n || throw (DimensionMismatch (" parent has $n elements, which is incompatible with size $dims " ))
260
260
return unsafe_reinterpret (T, A, dims)
266
266
# TODO : filter!
267
267
268
268
# revert of JuliaLang/julia#31929
269
- Base. filter (f, As:: GPUArray ) = As[map (f, As):: GPUArray {Bool} ]
269
+ Base. filter (f, As:: AbstractGPUArray ) = As[map (f, As):: AbstractGPUArray {Bool} ]
0 commit comments