Skip to content

Commit 6f7660d

Browse files
authored
Fix atomic increment of alloc stats. (#1885)
1 parent 4467dc6 commit 6f7660d

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/pool.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,10 @@ an [`OutOfGPUMemoryError`](@ref) if the allocation request cannot be satisfied.
393393
# (and using Base.@timed/gc_num to exclude that time is too expensive)
394394
buf, time = _alloc(B, sz; stream)
395395

396-
memory_use[] += sz
397-
alloc_stats.alloc_count[] += 1
398-
alloc_stats.alloc_bytes[] += sz
399-
alloc_stats.total_time[] += time
396+
Threads.atomic_add!(memory_use, sz)
397+
Threads.atomic_add!(alloc_stats.alloc_count, 1)
398+
Threads.atomic_add!(alloc_stats.alloc_bytes, sz)
399+
Threads.atomic_add!(alloc_stats.total_time, time)
400400
# NOTE: total_time might be an over-estimation if we trigger GC somewhere else
401401

402402
return buf
@@ -445,10 +445,10 @@ Releases a buffer `buf` to the memory pool.
445445
_free(buf; stream)
446446
end
447447

448-
memory_use[] -= sz
449-
alloc_stats.free_count[] += 1
450-
alloc_stats.free_bytes[] += sz
451-
alloc_stats.total_time[] += time
448+
Threads.atomic_sub!(memory_use, sz)
449+
Threads.atomic_add!(alloc_stats.free_count, 1)
450+
Threads.atomic_add!(alloc_stats.free_bytes, sz)
451+
Threads.atomic_add!(alloc_stats.total_time, time)
452452
catch ex
453453
Base.showerror_nostdio(ex, "WARNING: Error while freeing $buf")
454454
Base.show_backtrace(Core.stdout, catch_backtrace())

0 commit comments

Comments
 (0)