Skip to content

Commit d6a74b0

Browse files
committed
Minor cleanups
1 parent d20e5dc commit d6a74b0

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

lib/JLArrays/src/JLArrays.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ mutable struct JLArray{T, N} <: AbstractGPUArray{T, N}
9898
finalizer(unsafe_free!, obj)
9999
end
100100

101-
name = GPUArrays.CacheAllocatorName[]
102-
return name == :none ?
101+
name = GPUArrays.AllocCache.CacheAllocatorName[]
102+
return name nothing ?
103103
_alloc_f() :
104-
GPUArrays.alloc!(_alloc_f, JLBackend(), name, T, dims)::JLArray{T, N}
104+
GPUArrays.AllocCache.alloc!(_alloc_f, JLArray, name, (T, dims))::JLArray{T, N}
105105
end
106106

107107
# low-level constructor for wrapping existing data
@@ -397,10 +397,10 @@ Adapt.adapt_storage(::KernelAbstractions.CPU, a::JLArrays.JLArray) = convert(Arr
397397

398398
# Caching Allocator.
399399

400-
const JLACacheAllocator = GPUArrays.PerDeviceCacheAllocator(JLArray; free_immediately=false)
400+
const JLACacheAllocator = GPUArrays.AllocCache.PerDeviceCacheAllocator(JLArray; free_immediately=false)
401401

402-
GPUArrays.cache_allocator(::JLBackend) = JLACacheAllocator
402+
GPUArrays.AllocCache.cache_allocator(::Type{<: JLArray}) = JLACacheAllocator
403403

404-
GPUArrays.device(::JLBackend) = 1
404+
GPUArrays.AllocCache.device(::Type{<: JLArray}) = 1
405405

406406
end

src/host/allocations_cache.jl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ else
99
using Base.ScopedValues
1010
end
1111

12-
const CacheAllocatorName = ScopedValue(:none)
12+
const CacheAllocatorName = ScopedValue{Union{Nothing, Symbol}}(nothing)
1313

1414
struct CacheAllocator{T <: AbstractGPUArray}
1515
lock::ReentrantLock
@@ -178,14 +178,13 @@ end
178178
"""
179179
@enable AT name expr
180180
181-
Evaluate expression `expr` using `name`d caching allocator
182-
for the given array type `AT`.
181+
Evaluate expression `expr` using `name`d caching allocator for the given array type `AT`.
183182
184183
When gpu allocation is requested during execution of `expr`,
185184
allocator will try to use its "free" cache instead of doing an actual allocation.
186185
If no "free" allocation exists, an actual allocation is performed.
187186
Before returning allocation to the user, it is marked as busy and
188-
will not be used by allocation in the scope defined by `@cache_scope`.
187+
will not be used by allocation in the scope defined by `@enable`.
189188
190189
**After** the execution of `expr` all "busy" allocations are marked as "free"
191190
thus they can be re-used next time the program enters this scope.
@@ -194,17 +193,16 @@ This is useful to apply in a repeating block of code to avoid relying on
194193
GC to free gpu memory in time.
195194
196195
`name` is a `Symbol` that defines which allocator to use
197-
(`:none` is reserved and means no allocator).
196+
(`nothing`, which is a default, disables it).
198197
199198
# Example
200199
201-
In the following example, each iteration of the for-loop requires `2 GiB`
202-
of gpu memory.
200+
In the following example, each iteration of the for-loop requires `2 GiB` of gpu memory.
203201
Without caching allocator GC wouldn't be able to free arrays in time
204202
resulting in higher memory usage.
205203
With caching allocator, memory usage stays at exactly `2 GiB`.
206204
207-
See [`@no_cache_scope`](@ref), [`invalidate_cache_allocator!`](@ref).
205+
See [`@disable`](@ref), [`invalidate!`](@ref).
208206
```julia
209207
n = 1024^3
210208
for i in 1:1000
@@ -231,7 +229,7 @@ This is useful to call from within `@enable` to avoid caching arrays.
231229
"""
232230
macro disable(expr)
233231
quote
234-
@with $(esc(CacheAllocatorName)) => :none $(esc(expr))
232+
@with $(esc(CacheAllocatorName)) => nothing $(esc(expr))
235233
end
236234
end
237235

0 commit comments

Comments
 (0)