File: PAPI_Matlab.readme

package info (click to toggle)
papi 5.7.0+dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 9,856 kB
  • sloc: ansic: 93,265; fortran: 3,338; xml: 2,460; makefile: 815; sh: 290
file content (184 lines) | stat: -rwxr-xr-x 6,395 bytes parent folder | download
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
Running PAPI's High Level API in the MATLAB Environment

If you have the desire to do this, you most likely already
know why you want to make calls to PAPI inside of a 
MATLAB environment.

If you don't know much about what composes PAPI's high 
level API, you should probably take a look at this:

http://icl.cs.utk.edu/projects/papi/files/documentation/PAPI_USER_GUIDE_23.htm#WHAT_IS_HIGH_LEVEL_API

This section of the PAPI user guide covers C and FORTRAN
calls, but at the moment, you can only make C calls
from the MATLAB environment.

There is one overall function to call from Matlab; from there,
you specify which of the 6 specific functions you want to call, 
and then the arguments to each.  Here are some examples:

PAPI_num_counters - Returns the number of available
  hardware counters on the system.

Ex:  num_counters = PAPI('num')


PAPI_flips - Has 3 possibilities:
  Initialize FLIP counting with:
    PAPI('flips')
  Record the number of floating point instructions since
  initialization:
    ops = PAPI('flips')
  Record the number of floating point instructions and
  the incremental rate of floating point execution
  since initialization:
    [ops, mflips] = PAPI('flips')
  Use PAPI_stop_counters to stop counting flips and reset the counters.

PAPI_flops - Identical to PAPI_flips,
  but counts floating point *operations* rather than instructions.
  In most cases, these two are identical, but some instructions
  (e.g. FMA) might contain multiple operations or vice versa.

PAPI_ipc - Has 3 possibilities:
  Initialize instruction per cycle counting with:
    PAPI('ipc', 0)
  Record the number of instructions since
  initialization:
    ins = PAPI('ipc')
  Record the number of instructions and
  the incremental rate of instructions per cycle
  since initialization:
    [ins, ipc] = PAPI('ipc')
  

PAPI_start_counters - Specify the events to count
  (in text form or the actual numeric code; NOTE: make sure
  to not confuse normal decimal and hexadecimal.) You cannot
  specify more events than there are hardware counters.

  To begin counting cycles and instructions:
    PAPI('start', 'PAPI_TOT_CYC', 'PAPI_TOT_INS');


PAPI_read_counters - Simply specify the variables to read
  the values into.  You cannot specify more variables
  than there are hardware counters.  This will reset the
  counters.

  To read the above events you just started:
    [cycles, instructions] = PAPI('read');


PAPI_accum_counters - This function adds the value you
  pass to the readings in the hardware counter.  You
  cannot specify more variables than there are hardware
  counters.  This function will reset the counters.

  To add the values currently in the counters to the
  previously read values:
    [cycles, instructions] = PAPI('accum', cycles, instructions);


PAPI_stop_counters - This function reads the value of
  the running hardware counters into the variables
  you specify.  You cannot specify more variables than
  there are hardware counters.

  To stop the running counters you previously started
  and record their values:
    [cycles, instructions] = PAPI('stop');


PAPI_Matlab.c, when compiled, functions simply as a
wrapper.  In order to use the calls, you need to know a little
about mex.  mex is simply the compiler you use to make your
code run in the MATLAB environment.  If you don't know
how to use mex, you might want to acquaint yourself a bit.

"mex -setup "might be needed if you encounter problems, but
the simplest explanation might be to substitute "mex" for 
"gcc" and you are on your way.

All the other rules for compiling PAPI are the same.  mex
compilations can de done inside or outside of the Matlab
environment, but in this case, it is recommended that you
compile outside of Matlab.  For some reason, compiling 
inside does not work on some systems.

So far, the Linux environment and the Windows environment
have been tested, but _in theory_ this code should work anywhere 
PAPI and Matlab both work.

The following instructions are for a Linux/Unix environment:

Assuming papi.h is present in /usr/local/include and libpapi.so
is present in /usr/local/lib, the below should work.  If not,
you may need to alter the compile strings and/or the #include
statement in PAPI_Matlab.c.  Also, the compile string will be
different for different platforms.

For instance, if I want to compile and run on a linux
machine assuming PAPI_Matlab.c is in your current working
directory (you'll have a different compile string on a 
different architecture):

1. Compile the wrapper:
mex -I/usr/local/include PAPI_Matlab.c /usr/local/lib/libpapi.so -output PAPI

2.  Start Matlab:
matlab

3.  Run the code:
a.  Find the number of hardware counters on your system:
num_counters = PAPI('num')


b.  Play with flips - the first makes sure the counters are stopped and clear;
    the second initializes the counting;
    the third returns the number of floating point instructions
    since the first call, and the fourth line does the same as the
    second AND reports the incremental rate of floating point
    execution since the last call:
PAPI('stop')
PAPI('flips')
ins = PAPI('flips')
[ins, mflips] = PAPI('flips')

c.  Play with instructions per cycle - the first makes sure the 
    counters are stopped and clear; the second initializes counting;
    the third returns the number of instructions
    since the first call, and the fourth line does the same as the
    second AND reports the incremental rate of instructions per
    cycle since the last call:
PAPI('stop')
PAPI('ipc')
ins = PAPI('ipc')
[ins, ipc] = PAPI('ipc')

d. Try the example m files included with the distribution:
PAPIInnerProduct.m
PAPIMatrixVector.m
PAPIMatrixMatrix.m

e.  Start counting:
PAPI('start', 'PAPI_TOT_CYC', 'PAPI_TOT_INS')

f.  Read the counters and reset:
[cycles, instr] = PAPI('read')

g.  Add the current value of the counters to a previous read
    and reset:
[cycles, instr] = PAPI('accum', cycles, instr)

h.  Read the counters and stop them:
[cycles, instr] = PAPI('stop')

You can pass as many events as you like to be counted or
recorded, as long as that number does not exceed the number
of available hardware counters.

Contact ralph@eecs.utk.edu or/and ptools-perfapi@icl.utk.edu
with any questions regarding PAPI calls in Matlab - either errors or questions.
Also, this has just been implemented, so changes could
be coming..........