Skip to content

Commit 3e743d6

Browse files
committed
Limit caching allocator tests to AbstractGPUArray
1 parent d0115fd commit 3e743d6

File tree

1 file changed

+46
-44
lines changed

1 file changed

+46
-44
lines changed
Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,58 @@
11
@testsuite "Caching Allocator" (AT, eltypes) -> begin
2-
device = GPUArrays.AllocCache.device(AT)
3-
pdcache = GPUArrays.AllocCache.cache_allocator(AT)
4-
named_cache = GPUArrays.AllocCache.named_cache_allocator!(pdcache, device, :cache)
2+
if AT <: AbstractGPUArray
3+
device = GPUArrays.AllocCache.device(AT)
4+
pdcache = GPUArrays.AllocCache.cache_allocator(AT)
5+
named_cache = GPUArrays.AllocCache.named_cache_allocator!(pdcache, device, :cache)
56

6-
T = Float32
7-
dims = (1, 2, 3)
7+
T = Float32
8+
dims = (1, 2, 3)
89

9-
GPUArrays.AllocCache.@enable AT :cache begin
10-
x1 = AT(zeros(T, dims))
11-
end
12-
@test sizeof(pdcache, device, :cache) == sizeof(Float32) * prod(dims)
13-
@test length(named_cache.free) == 1
10+
GPUArrays.AllocCache.@enable AT :cache begin
11+
x1 = AT(zeros(T, dims))
12+
end
13+
@test sizeof(pdcache, device, :cache) == sizeof(Float32) * prod(dims)
14+
@test length(named_cache.free) == 1
1415

15-
key = first(keys(named_cache.free))
16-
@test length(named_cache.free[key]) == 1
17-
@test length(named_cache.busy[key]) == 0
18-
@test x1 === named_cache.free[key][1]
16+
key = first(keys(named_cache.free))
17+
@test length(named_cache.free[key]) == 1
18+
@test length(named_cache.busy[key]) == 0
19+
@test x1 === named_cache.free[key][1]
1920

20-
# Second allocation does not allocate - cache stays the same in size.
21+
# Second allocation does not allocate - cache stays the same in size.
2122

22-
GPUArrays.AllocCache.@enable AT :cache begin
23-
x2 = AT(zeros(T, dims))
23+
GPUArrays.AllocCache.@enable AT :cache begin
24+
x2 = AT(zeros(T, dims))
2425

25-
# Does not go to cache.
26-
GPUArrays.AllocCache.@disable begin
27-
x_free = AT(zeros(T, dims))
26+
# Does not go to cache.
27+
GPUArrays.AllocCache.@disable begin
28+
x_free = AT(zeros(T, dims))
29+
end
2830
end
29-
end
30-
@test sizeof(pdcache, device, :cache) == sizeof(Float32) * prod(dims)
31-
@test length(named_cache.free[key]) == 1
32-
@test length(named_cache.busy[key]) == 0
33-
@test x2 === x1
34-
@test x2 === named_cache.free[key][1]
35-
@test x_free !== x2
36-
37-
# Third allocation of different type - cache grows.
38-
39-
T2 = Int32
40-
key2 = hash((T2, dims))
41-
GPUArrays.AllocCache.@enable AT :cache begin
42-
x3 = AT(zeros(T2, dims))
43-
end
44-
@test sizeof(pdcache, device, :cache) == (sizeof(Float32) + sizeof(Int32)) * prod(dims)
31+
@test sizeof(pdcache, device, :cache) == sizeof(Float32) * prod(dims)
32+
@test length(named_cache.free[key]) == 1
33+
@test length(named_cache.busy[key]) == 0
34+
@test x2 === x1
35+
@test x2 === named_cache.free[key][1]
36+
@test x_free !== x2
37+
38+
# Third allocation of different type - cache grows.
39+
40+
T2 = Int32
41+
key2 = hash((T2, dims))
42+
GPUArrays.AllocCache.@enable AT :cache begin
43+
x3 = AT(zeros(T2, dims))
44+
end
45+
@test sizeof(pdcache, device, :cache) == (sizeof(Float32) + sizeof(Int32)) * prod(dims)
4546

46-
_keys = collect(keys(named_cache.free))
47-
key2 = _keys[findfirst(i -> i != key, _keys)]
48-
@test length(named_cache.free[key]) == 1
49-
@test length(named_cache.free[key2]) == 1
50-
@test x3 === named_cache.free[key2][1]
47+
_keys = collect(keys(named_cache.free))
48+
key2 = _keys[findfirst(i -> i != key, _keys)]
49+
@test length(named_cache.free[key]) == 1
50+
@test length(named_cache.free[key2]) == 1
51+
@test x3 === named_cache.free[key2][1]
5152

52-
# Freeing all memory held by cache.
53+
# Freeing all memory held by cache.
5354

54-
GPUArrays.AllocCache.invalidate!(AT, :cache)
55-
@test sizeof(pdcache, device, :cache) == 0
55+
GPUArrays.AllocCache.invalidate!(AT, :cache)
56+
@test sizeof(pdcache, device, :cache) == 0
57+
end
5658
end

0 commit comments

Comments
 (0)