-
Notifications
You must be signed in to change notification settings - Fork 1
/
timing.t
59 lines (49 loc) · 1.04 KB
/
timing.t
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
-- SPDX-FileCopyrightText: 2024 René Hiemstra <[email protected]>
-- SPDX-FileCopyrightText: 2024 Torsten Keßler <[email protected]>
--
-- SPDX-License-Identifier: MIT
local time = terralib.includec("time.h")
local omp = terralib.includec("omp.h")
local interface = require("interface")
local Timer = interface.Interface:new{
start = {} -> {},
stop = {} -> double
}
local struct default {
old: double
}
do
local now = quote
var now: time.timespec
var res = time.clock_gettime(time.CLOCK_REALTIME, &now)
in
1.0 * now.tv_sec + 1e-9 * now.tv_nsec
end
terra default:start()
self.old = [now]
end
terra default:stop()
var cur = [now]
return cur - self.old
end
end
assert(Timer:isimplemented(default))
local struct omp_timer {
old: double
}
do
local now = `omp.omp_get_wtime()
terra omp_timer:start()
self.old = [now]
end
terra omp_timer:stop()
var cur = [now]
return cur - self.old
end
end
assert(Timer:isimplemented(omp_timer))
return {
default_timer = default,
parallel_timer = omp_timer,
Timer = Timer,
}