forked from JuliaGPU/CUDA.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.jl
123 lines (83 loc) · 2.29 KB
/
context.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
@testset "context" begin
ctx = CuCurrentContext()
dev = device()
let ctx2 = CuContext(dev)
@test ctx2 == CuCurrentContext() # ctor implicitly pushes
activate(ctx)
@test ctx == CuCurrentContext()
@test device(ctx2) == dev
CUDA.unsafe_destroy!(ctx2)
end
let global_ctx2 = nothing
CuContext(dev) do ctx2
@test ctx2 == CuCurrentContext()
@test ctx != ctx2
global_ctx2 = ctx2
end
@test !CUDA.isvalid(global_ctx2)
@test ctx == CuCurrentContext()
@test device(ctx) == dev
@test device() == dev
synchronize()
end
end
@testset "primary context" begin
# FIXME: these trample over our globally-managed context
# pctx = CuPrimaryContext(device())
# @test !isactive(pctx)
# unsafe_reset!(pctx)
# @test !isactive(pctx)
# @test flags(pctx) == 0
# setflags!(pctx, CUDA.CTX_SCHED_BLOCKING_SYNC)
# @test flags(pctx) == CUDA.CTX_SCHED_BLOCKING_SYNC
# let global_ctx = nothing
# CuContext(pctx) do ctx
# @test CUDA.isvalid(ctx)
# @test isactive(pctx)
# global_ctx = ctx
# end
# @test !isactive(pctx)
# @test !CUDA.isvalid(global_ctx)
# end
# CuContext(pctx) do ctx
# @test CUDA.isvalid(ctx)
# @test isactive(pctx)
# unsafe_reset!(pctx)
# @test !isactive(pctx)
# @test !CUDA.isvalid(ctx)
# end
# let
# @test !isactive(pctx)
# ctx1 = CuContext(pctx)
# @test isactive(pctx)
# @test CUDA.isvalid(ctx1)
# unsafe_reset!(pctx)
# @test !isactive(pctx)
# @test !CUDA.isvalid(ctx1)
# CUDA.valid_contexts
# ctx2 = CuContext(pctx)
# @test isactive(pctx)
# @test !CUDA.isvalid(ctx1)
# @test CUDA.isvalid(ctx2)
# unsafe_reset!(pctx)
# end
end
@testset "cache config" begin
config = cache_config()
cache_config!(CUDA.FUNC_CACHE_PREFER_L1)
@test cache_config() == CUDA.FUNC_CACHE_PREFER_L1
cache_config!(config)
end
@testset "shmem config" begin
config = shmem_config()
shmem_config!(CUDA.SHARED_MEM_CONFIG_FOUR_BYTE_BANK_SIZE)
@test shmem_config() == CUDA.SHARED_MEM_CONFIG_FOUR_BYTE_BANK_SIZE
shmem_config!(config)
end
@testset "limits" begin
lim = limit(CUDA.LIMIT_DEV_RUNTIME_SYNC_DEPTH)
lim += 1
limit!(CUDA.LIMIT_DEV_RUNTIME_SYNC_DEPTH, lim)
@test lim == limit(CUDA.LIMIT_DEV_RUNTIME_SYNC_DEPTH)
limit!(CUDA.LIMIT_DEV_RUNTIME_SYNC_DEPTH, lim)
end