Skip to content

Commit 6aae0a8

Browse files
authored
Merge branch 'master' into yoyoyo_rebase_time
2 parents 0c7e26b + 13ee44c commit 6aae0a8

File tree

3 files changed

+38
-19
lines changed

3 files changed

+38
-19
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "GPUArrays"
22
uuid = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
3-
version = "10.3.0"
3+
version = "10.3.1"
44

55
[deps]
66
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
@@ -17,7 +17,7 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1717
[compat]
1818
Adapt = "4.0"
1919
GPUArraysCore = "= 0.1.6"
20-
LLVM = "3.9, 4, 5, 6, 7, 8"
20+
LLVM = "3.9, 4, 5, 6, 7, 8, 9"
2121
LinearAlgebra = "1"
2222
Printf = "1"
2323
Random = "1"

src/host/abstractarray.jl

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,15 @@ Base.collect(X::AnyGPUArray) = collect_to_cpu(X)
134134

135135
# memory copying
136136

137+
# expects the GPU array type to have linear `copyto!` methods (i.e. accepting an integer
138+
# offset and length) from and to CPU arrays and between GPU arrays.
139+
137140
function Base.copy!(dst::AbstractGPUVector, src::AbstractGPUVector)
138141
axes(dst) == axes(src) || throw(ArgumentError(
139142
"arrays must have the same axes for `copy!`. consider using `copyto!` instead"))
140143
copyto!(dst, src)
141144
end
142145

143-
## basic linear copies of identically-typed memory
144-
145-
# expects the GPU array type to have linear `copyto!` methods (i.e. accepting an integer
146-
# offset and length) from and to CPU arrays and between GPU arrays.
147-
148146
for (D, S) in ((AnyGPUArray, Array),
149147
(Array, AnyGPUArray),
150148
(AnyGPUArray, AnyGPUArray))
@@ -156,18 +154,6 @@ for (D, S) in ((AnyGPUArray, Array),
156154
copyto!(dest, drange, src, srange)
157155
end
158156

159-
function Base.copyto!(dest::$D, d_range::CartesianIndices{1},
160-
src::$S, s_range::CartesianIndices{1})
161-
len = length(d_range)
162-
if length(s_range) != len
163-
throw(ArgumentError("Copy range needs same length. Found: dest: $len, src: $(length(s_range))"))
164-
end
165-
len == 0 && return dest
166-
d_offset = first(d_range)[1]
167-
s_offset = first(s_range)[1]
168-
copyto!(dest, d_offset, src, s_offset, len)
169-
end
170-
171157
Base.copyto!(dest::$D, src::$S) = copyto!(dest, 1, src, 1, length(src))
172158
end
173159
end
@@ -253,6 +239,13 @@ function Base.copyto!(dest::AnyGPUArray{<:Any, N}, destcrange::CartesianIndices{
253239
len = length(destcrange)
254240
len == 0 && return dest
255241

242+
# linear copy if we can
243+
if N == 1
244+
d_offset = first(destcrange)[1]
245+
s_offset = first(srccrange)[1]
246+
return copyto!(dest, d_offset, src, s_offset, len)
247+
end
248+
256249
dest_offsets = first(destcrange) - oneunit(CartesianIndex{N})
257250
src_offsets = first(srccrange) - oneunit(CartesianIndex{N})
258251
kernel = cartesian_copy_kernel!(get_backend(dest))
@@ -267,6 +260,15 @@ for (dstTyp, srcTyp) in (AbstractGPUArray=>Array, Array=>AbstractGPUArray)
267260
if size(dstrange) != size(srcrange)
268261
throw(ArgumentError("source and destination must have same size (got $(size(srcrange)) and $(size(dstrange)))"))
269262
end
263+
len = length(dstrange)
264+
len == 0 && return dest
265+
266+
# linear copy if we can
267+
if N == 1
268+
d_offset = first(dstrange)[1]
269+
s_offset = first(srcrange)[1]
270+
return copyto!(dst, d_offset, src, s_offset, len)
271+
end
270272

271273
# figure out how many dimensions of the Cartesian ranges map onto contiguous memory
272274
# in both source and destination. we will copy these one by one as linear ranges.

test/testsuite/base.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,23 @@ end
3535
end
3636

3737
@testset "copyto!" begin
38+
x = fill(0f0, 1)
39+
y = rand(Float32, 1)
40+
a = AT(x)
41+
copyto!(x, 1:1, y, 1:1)
42+
copyto!(a, 1:1, y, 1:1)
43+
@test x == Array(a)
44+
45+
x = fill(0f0, 10)
46+
y = rand(Float32, 20)
47+
a = AT(x)
48+
b = AT(y)
49+
r1 = 1:7
50+
r2 = 11:17
51+
copyto!(x, r1, y, r2)
52+
copyto!(a, r1, b, r2)
53+
@test x == Array(a)
54+
3855
x = fill(0f0, (10, 10))
3956
y = rand(Float32, (20, 10))
4057
a = AT(x)

0 commit comments

Comments
 (0)