-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpapi-high.go
99 lines (89 loc) · 3.12 KB
/
papi-high.go
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
// This file provides an interface to PAPI's high-level functions.
package papi
// #include <papi.h>
import "C"
// NumCounters is the number of hardware counters available on the
// system. Consequently, the slice passed to functions such as
// StartCounters() should contain no more than NumCounters elements.
var NumCounters int
// Return the total real time, total process time, total
// floating-point instructions, and average Mflip/s since the previous
// call to PAPI.Flips().
func Flips() (rtime, ptime float32, flpins int64, mflips float32, err error) {
var c_rtime, c_ptime, c_mflips C.float
var c_flpins C.longlong
errno := Errno(C.PAPI_flips(&c_rtime, &c_ptime, &c_flpins, &c_mflips))
if errno == papi_ok {
rtime, ptime, flpins, mflips = float32(c_rtime), float32(c_ptime), int64(c_flpins), float32(c_mflips)
} else {
err = errno
}
return
}
// Return the total real time, total process time, total
// floating-point operations, and average Mflop/s since the previous
// call to PAPI.Flops().
func Flops() (rtime, ptime float32, flpops int64, mflops float32, err error) {
var c_rtime, c_ptime, c_mflops C.float
var c_flpops C.longlong
errno := Errno(C.PAPI_flops(&c_rtime, &c_ptime, &c_flpops, &c_mflops))
if errno == papi_ok {
rtime, ptime, flpops, mflops = float32(c_rtime), float32(c_ptime), int64(c_flpops), float32(c_mflops)
} else {
err = errno
}
return
}
// Return the total real time, total process time, total number of
// instructions, and average instructions per cycle since the previous
// call to PAPI.Ipc().
func Ipc() (rtime, ptime float32, ins int64, ipc float32, err error) {
var c_rtime, c_ptime, c_ipc C.float
var c_ins C.longlong
errno := Errno(C.PAPI_ipc(&c_rtime, &c_ptime, &c_ins, &c_ipc))
if errno == papi_ok {
rtime, ptime, ins, ipc = float32(c_rtime), float32(c_ptime), int64(c_ins), float32(c_ipc)
} else {
err = errno
}
return
}
// Given a slice of event codes, start counting the corresponding events.
func StartCounters(evcodes []Event) (err error) {
events := (*C.int)(&evcodes[0])
numEvents := C.int(len(evcodes))
if errno := Errno(C.PAPI_start_counters(events, numEvents)); errno != papi_ok {
err = errno
}
return
}
// Store the current event counts in a given slice and reset the
// counters to zero.
func ReadCounters(values []int64) (err error) {
valuePtr := (*C.longlong)(&values[0])
numValues := C.int(len(values))
if errno := Errno(C.PAPI_read_counters(valuePtr, numValues)); errno != papi_ok {
err = errno
}
return
}
// Add the current event counts to those in a given slice and reset
// the counters to zero.
func AccumCounters(values []int64) (err error) {
valuePtr := (*C.longlong)(&values[0])
numValues := C.int(len(values))
if errno := Errno(C.PAPI_accum_counters(valuePtr, numValues)); errno != papi_ok {
err = errno
}
return
}
// Store the current event counts in a given slice, reset the
// counters to zero, and stop counting the events.
func StopCounters(values []int64) (err error) {
valuePtr := (*C.longlong)(&values[0])
numValues := C.int(len(values))
if errno := Errno(C.PAPI_stop_counters(valuePtr, numValues)); errno != papi_ok {
err = errno
}
return
}