Skip to content
This repository was archived by the owner on Mar 12, 2021. It is now read-only.

Commit 7c11bbb

Browse files
committed
Don't always time allocations.
1 parent c1660dc commit 7c11bbb

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/memory.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function actual_alloc(bytes)::Union{Nothing,CuPtr{Nothing}}
5252
# try the actual allocation
5353
try
5454
alloc_stats.actual_time += Base.@elapsed begin
55-
@timeit alloc_to "alloc" buf = Mem.alloc(Mem.Device, bytes)
55+
@timeit_debug alloc_to "alloc" buf = Mem.alloc(Mem.Device, bytes)
5656
end
5757
@assert sizeof(buf) == bytes
5858
alloc_stats.actual_nalloc += 1
@@ -78,7 +78,7 @@ function actual_free(ptr::CuPtr{Nothing})
7878
alloc_stats.actual_free += bytes
7979
usage[] -= bytes
8080

81-
@timeit alloc_to "free" begin
81+
@timeit_debug alloc_to "free" begin
8282
alloc_stats.actual_time += Base.@elapsed Mem.free(buf)
8383
end
8484

@@ -91,7 +91,7 @@ end
9191
const pool_to = TimerOutput()
9292

9393
macro pool_timeit(args...)
94-
TimerOutputs.timer_expr(__module__, false, :($CuArrays.pool_to), args...)
94+
TimerOutputs.timer_expr(CuArrays, true, :($CuArrays.pool_to), args...)
9595
end
9696

9797
pool_timings() = (show(pool_to; allocations=false, sortby=:name); println())
@@ -279,6 +279,8 @@ end
279279

280280
## init
281281

282+
enable_timings() = (TimerOutputs.enable_debug_timings(CuArrays); return)
283+
282284
function __init_memory__()
283285
if haskey(ENV, "CUARRAYS_MEMORY_LIMIT")
284286
usage_limit[] = parse(Int, ENV["CUARRAYS_MEMORY_LIMIT"])

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ testf(f, xs...; kwargs...) = TestSuite.compare(f, CuArray, xs...; kwargs...)
2020
import CuArrays: allowscalar, @allowscalar
2121
allowscalar(false)
2222

23+
CuArrays.enable_timings()
24+
2325
@testset "CuArrays" begin
2426

2527
@testset "GPUArrays test suite" begin

0 commit comments

Comments
 (0)