Skip to content

Commit 6c0962e

Browse files
committed
Rename enable to cached
1 parent 2709994 commit 6c0962e

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

docs/src/interface.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ There are numerous examples of potential interfaces for GPUArrays, such as with
3434
## Caching Allocator
3535

3636
```@docs
37-
GPUArrays.@enable
38-
GPUArrays.@disable
37+
GPUArrays.@cached
38+
GPUArrays.@uncached
3939
```

src/host/alloc_cache.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function unsafe_free!(cache::AllocCache)
6969
for (_, pool) in cache.busy
7070
isempty(pool) || error(
7171
"Invalidating allocations cache that's currently in use. " *
72-
"Invalidating inside `@enable` is not allowed."
72+
"Invalidating inside `@cached` is not allowed."
7373
)
7474
end
7575
for (_, pool) in cache.free
@@ -93,15 +93,15 @@ end
9393
const ALLOC_CACHE = ScopedValue{Union{Nothing, AllocCache}}(nothing)
9494

9595
"""
96-
@enable(cache, expr)
96+
@cached(cache, expr)
9797
9898
Evaluate expression `expr` using allocations cache `cache`.
9999
100100
When gpu allocation is requested during execution of `expr`,
101101
it will first check if there's "free" cache instead of performing an actual allocation.
102102
If no "free" allocation exists, an actual allocation is performed.
103103
Before returning allocation to the user, it is marked as busy and
104-
will not be used by allocation in the scope defined by `@enable`.
104+
will not be used by allocation in the scope defined by `@cached`.
105105
106106
**After** the execution of `expr` all "busy" allocations are marked as "free"
107107
thus they can be re-used next time the program enters this scope.
@@ -120,7 +120,7 @@ With caching allocator, memory usage stays at exactly `8 GiB`.
120120
cache = GPUArrays.AllocCache(CuArray)
121121
n = 1024^3
122122
for i in 1:1000
123-
GPUArrays.@enable cache begin
123+
GPUArrays.@cached cache begin
124124
sin.(CUDA.rand(Float32, n))
125125
end
126126
end
@@ -129,9 +129,9 @@ end
129129
GPUArrays.unsafe_free!(cache)
130130
```
131131
132-
See [`@disable`](@ref).
132+
See [`@uncached`](@ref).
133133
"""
134-
macro enable(cache, expr)
134+
macro cached(cache, expr)
135135
return quote
136136
res = @with $(esc(ALLOC_CACHE)) => $(esc(cache)) $(esc(expr))
137137
free_busy!($(esc(cache)))
@@ -140,12 +140,12 @@ macro enable(cache, expr)
140140
end
141141

142142
"""
143-
disable(expr)
143+
uncached(expr)
144144
145145
Evaluate expression `expr` without using allocations cache.
146-
This is useful to call from within `@enable` to avoid caching some allocations.
146+
This is useful to call from within `@cached` to avoid caching some allocations.
147147
"""
148-
macro disable(expr)
148+
macro uncached(expr)
149149
return quote
150150
@with $(esc(ALLOC_CACHE)) => nothing $(esc(expr))
151151
end

test/testsuite/caching_allocator.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
cache = GPUArrays.AllocCache(AT)
44

55
T, dims = Float32, (1, 2, 3)
6-
GPUArrays.@enable cache begin
6+
GPUArrays.@cached cache begin
77
x1 = AT(zeros(T, dims))
88
end
99
@test sizeof(cache) == sizeof(T) * prod(dims)
@@ -13,10 +13,10 @@
1313
@test x1 === cache.free[key][1]
1414

1515
# Second allocation hits cache.
16-
GPUArrays.@enable cache begin
16+
GPUArrays.@cached cache begin
1717
x2 = AT(zeros(T, dims))
1818
# Does not hit the cache.
19-
GPUArrays.@disable x_free = AT(zeros(T, dims))
19+
GPUArrays.@uncached x_free = AT(zeros(T, dims))
2020
end
2121
@test sizeof(cache) == sizeof(T) * prod(dims)
2222
key = first(keys(cache.free))
@@ -27,7 +27,7 @@
2727

2828
# Third allocation is of different shape - allocates.
2929
dims = (2, 2)
30-
GPUArrays.@enable cache begin
30+
GPUArrays.@cached cache begin
3131
x3 = AT(zeros(T, dims))
3232
end
3333
_keys = collect(keys(cache.free))

0 commit comments

Comments
 (0)