Skip to content

Commit 22e0906

Browse files
authored
Merge pull request #224 from JuliaGPU/tb/materialize
Improvements to array materialization
2 parents fc08102 + 7c86b41 commit 22e0906

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

.gitlab-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ cuarrays:
4242
tags:
4343
- nvidia
4444
- sm_75
45-
image: juliagpu/cuda:10.1-cudnn7-cutensor-devel-ubuntu18.04
45+
image: juliagpu/cuda:10.1-cudnn7-cutensor1-devel-ubuntu18.04
4646
script:
4747
- export CUARRAYS=".julia/dev/CuArrays"
4848
- julia -e 'using Pkg;

src/abstractarray.jl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,18 @@ end
8888

8989
## basic linear copies of identically-typed memory
9090

91+
# convert to something we can get a pointer to
9192
materialize(x::AbstractArray) = Array(x)
9293
materialize(x::GPUArray) = x
94+
materialize(x::Array) = x
95+
96+
# TODO: do we want to support `copyto(..., WrappedArray{GPUArray})`
97+
# if so (does not work due to lack of copy constructors):
98+
#for (W, ctor) in (:AT => (A,mut)->mut(A), Adapt.wrappers...)
99+
# @eval begin
100+
# materialize(X::$W) where {AT <: GPUArray} = AT(X)
101+
# end
102+
#end
93103

94104
for (D, S) in ((GPUArray, AbstractArray), (Array, GPUArray), (GPUArray, GPUArray))
95105
@eval begin
@@ -102,14 +112,14 @@ for (D, S) in ((GPUArray, AbstractArray), (Array, GPUArray), (GPUArray, GPUArray
102112

103113
function Base.copyto!(dest::$D{T}, d_range::CartesianIndices{1},
104114
src::$S{T}, s_range::CartesianIndices{1}) where T
105-
amount = length(d_range)
106-
if length(s_range) != amount
107-
throw(ArgumentError("Copy range needs same length. Found: dest: $amount, src: $(length(s_range))"))
115+
len = length(d_range)
116+
if length(s_range) != len
117+
throw(ArgumentError("Copy range needs same length. Found: dest: $len, src: $(length(s_range))"))
108118
end
109-
amount == 0 && return dest
119+
len == 0 && return dest
110120
d_offset = first(d_range)[1]
111121
s_offset = first(s_range)[1]
112-
copyto!(dest, d_offset, materialize(src), s_offset, amount)
122+
copyto!(dest, d_offset, materialize(src), s_offset, len)
113123
end
114124

115125
function Base.copyto!(dest::$D{T, N}, src::$S{T, N}) where {T, N}

0 commit comments

Comments
 (0)