53
53
# Host abstractions
54
54
#
55
55
56
-
57
56
mutable struct ROCArray{T,N} <: AbstractGPUArray{T,N}
58
57
buf:: Mem.Buffer
59
58
own:: Bool
60
59
61
60
dims:: Dims{N}
62
61
offset:: Int
63
62
63
+ syncstate:: SyncState
64
+
64
65
function ROCArray {T,N} (buf:: Mem.Buffer , dims:: Dims{N} ; offset:: Integer = 0 , own:: Bool = true ) where {T,N}
65
66
@assert isbitstype (T) " ROCArray only supports bits types"
66
- xs = new {T,N} (buf, own, dims, offset)
67
+ xs = new {T,N} (buf, own, dims, offset, SyncState () )
67
68
if own
68
69
hsaref! ()
69
70
Mem. retain (buf)
@@ -79,6 +80,21 @@ function unsafe_free!(xs::ROCArray)
79
80
return
80
81
end
81
82
83
+ wait! (x:: ROCArray ) = wait! (x. syncstate)
84
+ mark! (x:: ROCArray , s) = mark! (x. syncstate, s)
85
+ wait! (xs:: Vector{<:ROCArray} ) = foreach (wait!, xs)
86
+ mark! (xs:: Vector{<:ROCArray} , s) = foreach (x-> mark! (x,s), xs)
87
+ wait! (xs:: NTuple{N,<:ROCArray} where N) = foreach (wait!, xs)
88
+ mark! (xs:: NTuple{N,<:ROCArray} where N, s) = foreach (x-> mark! (x,s), xs)
89
+ function Adapt. adapt_storage (:: WaitAdaptor , x:: ROCArray )
90
+ wait! (x. syncstate)
91
+ x
92
+ end
93
+ function Adapt. adapt_storage (ma:: MarkAdaptor , x:: ROCArray )
94
+ mark! (x. syncstate, ma. s)
95
+ x
96
+ end
97
+
82
98
# # aliases
83
99
84
100
const ROCVector{T} = ROCArray{T,1 }
@@ -154,6 +170,7 @@ function Base.copyto!(dest::Array{T}, d_offset::Integer,
154
170
amount == 0 && return dest
155
171
@boundscheck checkbounds (dest, d_offset+ amount- 1 )
156
172
@boundscheck checkbounds (source, s_offset+ amount- 1 )
173
+ wait! (source)
157
174
Mem. download! (pointer (dest, d_offset),
158
175
Mem. view (source. buf, (s_offset- 1 )* sizeof (T)),
159
176
amount* sizeof (T))
@@ -165,6 +182,7 @@ function Base.copyto!(dest::ROCArray{T}, d_offset::Integer,
165
182
amount == 0 && return dest
166
183
@boundscheck checkbounds (dest, d_offset+ amount- 1 )
167
184
@boundscheck checkbounds (source, s_offset+ amount- 1 )
185
+ wait! (dest)
168
186
Mem. upload! (Mem. view (dest. buf, (d_offset- 1 )* sizeof (T)),
169
187
pointer (source, s_offset),
170
188
amount* sizeof (T))
@@ -176,6 +194,8 @@ function Base.copyto!(dest::ROCArray{T}, d_offset::Integer,
176
194
amount == 0 && return dest
177
195
@boundscheck checkbounds (dest, d_offset+ amount- 1 )
178
196
@boundscheck checkbounds (source, s_offset+ amount- 1 )
197
+ wait! (dest)
198
+ wait! (source)
179
199
Mem. transfer! (Mem. view (dest. buf, (d_offset- 1 )* sizeof (T)),
180
200
Mem. view (source. buf, (s_offset- 1 )* sizeof (T)),
181
201
amount* sizeof (T))
0 commit comments