forked from JuliaGPU/CUDA.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.jl
33 lines (23 loc) · 936 Bytes
/
events.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
# Events for timing
export CuEvent, record, synchronize, elapsed
typealias CuEvent_t Ptr{Void}
immutable CuEvent
handle::CuEvent_t
function CuEvent()
handle_ref = Ref{CuEvent_t}()
@apicall(:cuEventCreate, (Ptr{CuEvent_t}, Cuint), handle_ref, 0)
return new(handle_ref[])
end
end
Base.unsafe_convert(::Type{CuEvent_t}, e::CuEvent) = e.handle
Base.:(==)(a::CuEvent, b::CuEvent) = a.handle == b.handle
record(e::CuEvent, stream::CuStream=CuDefaultStream()) =
@apicall(:cuEventRecord, (CuEvent_t, CuStream_t), e, stream)
synchronize(e::CuEvent) = @apicall(:cuEventSynchronize, (CuEvent_t,), e)
function elapsed(start::CuEvent, stop::CuEvent)
time_ref = Ref{Cfloat}()
@apicall(:cuEventElapsedTime, (Ptr{Cfloat}, CuEvent_t, CuEvent_t),
time_ref, start, stop)
return time_ref[]
end
destroy(e::CuEvent) = @apicall(:cuEventDestroy, (CuEvent_t,), e)