@@ -74,7 +74,7 @@ Base.unlock(c::BidirectionalChannel) = unlock(c.cond_take)
7474# the synchronization, when it returns true (indicating that the object is synchronized)
7575# the actual synchronization API should be called again.
7676
77- function fast_synchronization (f, obj)
77+ function spinning_synchronization (f, obj)
7878 # fast path
7979 f (obj) && return true
8080
@@ -164,9 +164,9 @@ function nonblocking_synchronize(val)
164164 return
165165end
166166
167- function device_synchronize ()
168- if use_nonblocking_synchronization
169- if fast_synchronization (isdone, legacy_stream ())
167+ function device_synchronize (; blocking :: Bool = false , spin :: Bool = true )
168+ if use_nonblocking_synchronization && ! blocking
169+ if spin && spinning_synchronization (isdone, legacy_stream ())
170170 cuCtxSynchronize ()
171171 else
172172 nonblocking_synchronize (context ())
@@ -178,9 +178,9 @@ function device_synchronize()
178178 check_exceptions ()
179179end
180180
181- function synchronize (stream:: CuStream = stream ())
182- if use_nonblocking_synchronization
183- if fast_synchronization (isdone, stream)
181+ function synchronize (stream:: CuStream = stream (); blocking :: Bool = false , spin :: Bool = true )
182+ if use_nonblocking_synchronization && ! blocking
183+ if spin && spinning_synchronization (isdone, stream)
184184 cuStreamSynchronize (stream)
185185 else
186186 nonblocking_synchronize (stream)
@@ -192,9 +192,9 @@ function synchronize(stream::CuStream=stream())
192192 check_exceptions ()
193193end
194194
195- function synchronize (event:: CuEvent )
196- if use_nonblocking_synchronization
197- if fast_synchronization (isdone, event)
195+ function synchronize (event:: CuEvent ; blocking :: Bool = false , spin :: Bool = true )
196+ if use_nonblocking_synchronization && ! blocking
197+ if spin && spinning_synchronization (isdone, event)
198198 cuEventSynchronize (event)
199199 else
200200 nonblocking_synchronize (event)
@@ -249,10 +249,10 @@ function nonblocking_synchronize(stream::CuStream)
249249 return
250250end
251251
252- function device_synchronize ()
253- if use_nonblocking_synchronization
252+ function device_synchronize (; blocking :: Bool = false , spin :: Bool = true )
253+ if use_nonblocking_synchronization && ! blocking
254254 stream = legacy_stream ()
255- if ! fast_synchronization (isdone, stream)
255+ if ! spin || ! spinning_synchronization (isdone, stream)
256256 nonblocking_synchronize (stream)
257257 end
258258 end
@@ -261,9 +261,9 @@ function device_synchronize()
261261 check_exceptions ()
262262end
263263
264- function synchronize (stream:: CuStream = stream ())
265- if use_nonblocking_synchronization
266- if ! fast_synchronization (isdone, stream)
264+ function synchronize (stream:: CuStream = stream (); blocking :: Bool = false , spin :: Bool = true )
265+ if use_nonblocking_synchronization && ! blocking
266+ if ! spin || ! spinning_synchronization (isdone, stream)
267267 nonblocking_synchronize (stream)
268268 end
269269 end
@@ -272,9 +272,9 @@ function synchronize(stream::CuStream=stream())
272272 check_exceptions ()
273273end
274274
275- function synchronize (event:: CuEvent )
276- if use_nonblocking_synchronization
277- fast_synchronization (isdone, event)
275+ function synchronize (event:: CuEvent ; blocking :: Bool = false , spin :: Bool = true )
276+ if use_nonblocking_synchronization && ! blocking
277+ spin && spinning_synchronization (isdone, event)
278278 end
279279 cuEventSynchronize (event)
280280end
0 commit comments