Skip to content

Commit 2b7dbeb

Browse files
authored
Specialize Base.copy! for AbstractGPUArrays (#414)
1 parent d777d04 commit 2b7dbeb

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
*.jl.cov
22
*.jl.*.cov
33
*.jl.mem
4+
5+
# editor generated files
6+
.*.swp
7+
.*.swo
8+
*~

src/host/abstractarray.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ Base.collect(X::AnyGPUArray) = collect_to_cpu(X)
4242

4343
# memory copying
4444

45+
function Base.copy!(dst::AbstractGPUVector, src::AbstractGPUVector)
46+
axes(dst) == axes(src) || throw(ArgumentError(
47+
"arrays must have the same axes for `copy!`. consider using `copyto!` instead"))
48+
copyto!(dst, src)
49+
end
50+
4551
## basic linear copies of identically-typed memory
4652

4753
# expects the GPU array type to have linear `copyto!` methods (i.e. accepting an integer

test/testsuite/base.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ function ntuple_closure(ctx, result, ::Val{N}, testval) where N
2626
end
2727

2828
@testsuite "base" (AT, eltypes)->begin
29+
@testset "copy!" begin
30+
for (dst, src,) in (
31+
(rand(Float32, (10,)), rand(Float32, (10,))), # vectors
32+
(rand(Float32, (10,20)), rand(Float32, (10,20))), # multidim
33+
)
34+
dst = AT(dst)
35+
src = AT(src)
36+
37+
copy!(dst, src)
38+
@test dst == src
39+
end
40+
end
41+
2942
@testset "copyto!" begin
3043
x = fill(0f0, (10, 10))
3144
y = rand(Float32, (20, 10))

0 commit comments

Comments
 (0)