4
4
5
5
Base. copyto! (
6
6
dest:: AbstractData ,
7
- bc:: Union{AbstractData, Base.Broadcast.Broadcasted} ,
8
- ) = Base. copyto! (dest, bc, device_dispatch (dest))
7
+ @nospecialize ( bc:: Union{AbstractData, Base.Broadcast.Broadcasted} ) ,
8
+ ) = Base. copyto! (dest, bc, device_dispatch (parent ( dest) ))
9
9
10
10
# Specialize on non-Broadcasted objects
11
11
function Base. copyto! (dest:: D , src:: D ) where {D <: AbstractData }
15
15
16
16
# broadcasting scalar assignment
17
17
# Performance optimization for the common identity scalar case: dest .= val
18
- # And this is valid for the CPU or GPU, since the broadcasted object
19
- # is a scalar type.
20
18
function Base. copyto! (
21
19
dest:: AbstractData ,
22
20
bc:: Base.Broadcast.Broadcasted{Style} ,
@@ -51,10 +49,9 @@ function Base.copyto!(
51
49
:: ToCPU ,
52
50
) where {S, Nij}
53
51
(_, _, _, _, Nh) = size (dest)
54
- @inbounds for h in 1 : Nh
55
- slab_dest = slab (dest, h)
56
- slab_bc = slab (bc, h)
57
- copyto! (slab_dest, slab_bc)
52
+ @inbounds for h in 1 : Nh, j in 1 : Nij, i in 1 : Nij
53
+ idx = CartesianIndex (i, j, 1 , 1 , h)
54
+ dest[idx] = convert (S, bc[idx])
58
55
end
59
56
return dest
60
57
end
@@ -65,10 +62,9 @@ function Base.copyto!(
65
62
:: ToCPU ,
66
63
) where {S, Ni}
67
64
(_, _, _, _, Nh) = size (dest)
68
- @inbounds for h in 1 : Nh
69
- slab_dest = slab (dest, h)
70
- slab_bc = slab (bc, h)
71
- copyto! (slab_dest, slab_bc)
65
+ @inbounds for h in 1 : Nh, i in 1 : Ni
66
+ idx = CartesianIndex (i, 1 , 1 , 1 , h)
67
+ dest[idx] = convert (S, bc[idx])
72
68
end
73
69
return dest
74
70
end
@@ -131,10 +127,9 @@ function Base.copyto!(
131
127
) where {S, Nv, Ni}
132
128
# copy contiguous columns
133
129
(_, _, _, _, Nh) = size (dest)
134
- @inbounds for h in 1 : Nh, i in 1 : Ni
135
- col_dest = column (dest, i, h)
136
- col_bc = column (bc, i, h)
137
- copyto! (col_dest, col_bc)
130
+ @inbounds for h in 1 : Nh, i in 1 : Ni, v in 1 : Nv
131
+ idx = CartesianIndex (i, 1 , 1 , v, h)
132
+ dest[idx] = convert (S, bc[idx])
138
133
end
139
134
return dest
140
135
end
@@ -146,10 +141,9 @@ function Base.copyto!(
146
141
) where {S, Nv, Nij}
147
142
# copy contiguous columns
148
143
(_, _, _, _, Nh) = size (dest)
149
- @inbounds for h in 1 : Nh, j in 1 : Nij, i in 1 : Nij
150
- col_dest = column (dest, i, j, h)
151
- col_bc = column (bc, i, j, h)
152
- copyto! (col_dest, col_bc)
144
+ @inbounds for h in 1 : Nh, j in 1 : Nij, i in 1 : Nij, v in 1 : Nv
145
+ idx = CartesianIndex (i, j, 1 , v, h)
146
+ dest[idx] = convert (S, bc[idx])
153
147
end
154
148
return dest
155
149
end
0 commit comments