File tree Expand file tree Collapse file tree 1 file changed +17
-15
lines changed Expand file tree Collapse file tree 1 file changed +17
-15
lines changed Original file line number Diff line number Diff line change 20
20
# Possible improvements
21
21
# - Add a background task that occasionally scans all streams
22
22
# - Add a hysterisis by checking a "since last scanned" timestamp
23
- # - Add locking
23
+ const STREAM_GC_LOCK = Threads . ReentrantLock ()
24
24
function next_stream ()
25
- if ! isempty (FREE_STREAMS)
26
- return pop! (FREE_STREAMS)
27
- end
25
+ lock (STREAM_GC_LOCK) do
26
+ if ! isempty (FREE_STREAMS)
27
+ return pop! (FREE_STREAMS)
28
+ end
28
29
29
- if length (STREAMS) > STREAM_GC_THRESHOLD[]
30
- for stream in STREAMS
31
- if CUDA. query (stream)
32
- push! (FREE_STREAMS, stream)
30
+ if length (STREAMS) > STREAM_GC_THRESHOLD[]
31
+ for stream in STREAMS
32
+ if CUDA. query (stream)
33
+ push! (FREE_STREAMS, stream)
34
+ end
33
35
end
34
36
end
35
- end
36
37
37
- if ! isempty (FREE_STREAMS)
38
- return pop! (FREE_STREAMS)
38
+ if ! isempty (FREE_STREAMS)
39
+ return pop! (FREE_STREAMS)
40
+ end
41
+ stream = CUDA. CuStream (flags = CUDA. STREAM_NON_BLOCKING)
42
+ push! (STREAMS, stream)
43
+ return stream
39
44
end
40
- stream = CUDA. CuStream (flags = CUDA. STREAM_NON_BLOCKING)
41
- push! (STREAMS, stream)
42
- return stream
43
45
end
44
46
45
47
struct CudaEvent <: Event
321
323
# GPU implementation of const memory
322
324
# ##
323
325
324
- Adapt. adapt_storage (to:: ConstAdaptor , a:: CUDA.CuDeviceArray ) = Base. Experimental. Const (a)
326
+ Adapt. adapt_storage (to:: ConstAdaptor , a:: CUDA.CuDeviceArray ) = Base. Experimental. Const (a)
You can’t perform that action at this time.
0 commit comments