File: genpapifdef.c

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 (293 lines) | stat: -rw-r--r-- 11,215 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/* This file generates the #defines needed for Fortran examples of PAPI. 
   Its output is usually directed to fpapi.h. See Makefile.inc for details. 
*/

/* Modified to produce any of cpp, f77, or f90-style include files.
   Accepts an optional command-line argument, one of -c, -f77, or -f90 
      (-c default, as in original version of the program).
   The Fortran versions are fixed-format (source starts in column 7)
   Note: No check is made to ensure that lines don't extend past 72 columns.
   Date: 1/26/02 
   Rick Kufrin, NCSA/Univ of Illinois <rkufrin@ncsa.uiuc.edu> 
*/

/* Modified to eliminate reliance on libpapi.a.
   Now it relies only on a small collection of papi header files.
*/

/* Modified to always generate a symbolic representation for the
   maximum negative number. This is a work-around for a compiler
   limitation that first showed up on Cray X1 and then spread to
   GNU Fortran 4.3.2. Thanks to Jim Rosinski (ORNL) for
   identification and testing on this issue.
   Date: 06/03/08
*/

#include <stdlib.h>
#include <stdio.h>

#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <memory.h>

#include "papi.h"

#undef NDEBUG
#include <assert.h>

#define PAPI_EVENTS_IN_DERIVED_EVENT 8	/* to satisfy papi_preset.h */
#include "papi_preset.h"
#include "papi_common_strings.h"
/*
	The following array is used to create a series of defines
	for use with PAPI in Fortran programs.
	The value/name pairs come straight from papi.h. 
   They should be manually synchronized with papi.h when changes are made.
   The definition of hwi_describe_t is in papi_preset.h
*/

const hwi_describe_t _papi_def[] = {
	{PAPI_NULL, "PAPI_NULL", NULL},
	{PAPI_VER_CURRENT, "PAPI_VER_CURRENT", NULL},
	{PAPI_VERSION, "PAPI_VERSION", NULL},
	{PAPI_MAX_PRESET_EVENTS, "PAPI_MAX_PRESET_EVENTS", NULL},

	{PAPI_NOT_INITED, "PAPI_NOT_INITED", NULL},
	{PAPI_LOW_LEVEL_INITED, "PAPI_LOW_LEVEL_INITED", NULL},
	{PAPI_HIGH_LEVEL_INITED, "PAPI_HIGH_LEVEL_INITED", NULL},
	{PAPI_THREAD_LEVEL_INITED, "PAPI_THREAD_LEVEL_INITED", NULL},

	{PAPI_DOM_USER, "PAPI_DOM_USER", NULL},
	{PAPI_DOM_KERNEL, "PAPI_DOM_KERNEL", NULL},
	{PAPI_DOM_OTHER, "PAPI_DOM_OTHER", NULL},
	{PAPI_DOM_SUPERVISOR, "PAPI_DOM_SUPERVISOR", NULL},
	{PAPI_DOM_ALL, "PAPI_DOM_ALL", NULL},
	{PAPI_DOM_MIN, "PAPI_DOM_MIN", NULL},
	{PAPI_DOM_MAX, "PAPI_DOM_MAX", NULL},
	{PAPI_DOM_HWSPEC, "PAPI_DOM_HWSPEC", NULL},

	{PAPI_STOPPED, "PAPI_STOPPED", NULL},
	{PAPI_RUNNING, "PAPI_RUNNING", NULL},
	{PAPI_PAUSED, "PAPI_PAUSED", NULL},
	{PAPI_NOT_INIT, "PAPI_NOT_INIT", NULL},
	{PAPI_OVERFLOWING, "PAPI_OVERFLOWING", NULL},
	{PAPI_PROFILING, "PAPI_PROFILING", NULL},
	{PAPI_MULTIPLEXING, "PAPI_MULTIPLEXING", NULL},
	{PAPI_ATTACHED, "PAPI_ATTACHED", NULL},
	{PAPI_CPU_ATTACHED, "PAPI_CPU_ATTACHED", NULL},

	{PAPI_QUIET, "PAPI_QUIET", NULL},
	{PAPI_VERB_ECONT, "PAPI_VERB_ECONT", NULL},
	{PAPI_VERB_ESTOP, "PAPI_VERB_ESTOP", NULL},

	{PAPI_MIN_STR_LEN, "PAPI_MIN_STR_LEN", NULL},
	{PAPI_HUGE_STR_LEN, "PAPI_HUGE_STR_LEN", NULL},
	{PAPI_MAX_STR_LEN, "PAPI_MAX_STR_LEN", NULL},
	{PAPI_NUM_ERRORS, "PAPI_NUM_ERRORS", NULL},

	{PAPI_MULTIPLEX_DEFAULT, "PAPI_MULTIPLEX_DEFAULT", NULL},
	{PAPI_MULTIPLEX_FORCE_SW, "PAPI_MULTIPLEX_FORCE_SW", NULL},

	{PAPI_DEBUG, "PAPI_DEBUG", NULL},
	{PAPI_MULTIPLEX, "PAPI_MULTIPLEX", NULL},
	{PAPI_DEFDOM, "PAPI_DEFDOM", NULL},
	{PAPI_DOMAIN, "PAPI_DOMAIN", NULL},
	{PAPI_DEFGRN, "PAPI_DEFGRN", NULL},
	{PAPI_GRANUL, "PAPI_GRANUL", NULL},
	{PAPI_DEF_MPX_NS, "PAPI_DEF_MPX_NS", NULL},
	//	{PAPI_EDGE_DETECT, "PAPI_EDGE_DETECT", NULL},
	//{PAPI_INVERT, "PAPI_INVERT", NULL},
	{PAPI_MAX_MPX_CTRS, "PAPI_MAX_MPX_CTRS", NULL},
	{PAPI_PROFIL, "PAPI_PROFIL", NULL},
	{PAPI_PRELOAD, "PAPI_PRELOAD", NULL},
	{PAPI_CLOCKRATE, "PAPI_CLOCKRATE", NULL},
	{PAPI_MAX_HWCTRS, "PAPI_MAX_HWCTRS", NULL},
	{PAPI_HWINFO, "PAPI_HWINFO", NULL},
	{PAPI_EXEINFO, "PAPI_EXEINFO", NULL},
	{PAPI_MAX_CPUS, "PAPI_MAX_CPUS", NULL},
	{PAPI_ATTACH, "PAPI_ATTACH", NULL},
	{PAPI_SHLIBINFO, "PAPI_SHLIBINFO", NULL},
	{PAPI_LIB_VERSION, "PAPI_LIB_VERSION", NULL},
	{PAPI_COMPONENTINFO, "PAPI_COMPONENTINFO", NULL},
	{PAPI_DETACH, "PAPI_DETACH", NULL},

	{PAPI_GRN_THR, "PAPI_GRN_THR", NULL},
	{PAPI_GRN_MIN, "PAPI_GRN_MIN", NULL},
	{PAPI_GRN_PROC, "PAPI_GRN_PROC", NULL},
	{PAPI_GRN_PROCG, "PAPI_GRN_PROCG", NULL},
	{PAPI_GRN_SYS, "PAPI_GRN_SYS", NULL},
	{PAPI_GRN_SYS_CPU, "PAPI_GRN_SYS_CPU", NULL},
	{PAPI_GRN_MAX, "PAPI_GRN_MAX", NULL},

	{PAPI_DERIVED, "PAPI_DERIVED", NULL},

	{PAPI_PROFIL_POSIX, "PAPI_PROFIL_POSIX", NULL},
	{PAPI_PROFIL_RANDOM, "PAPI_PROFIL_RANDOM", NULL},
	{PAPI_PROFIL_WEIGHTED, "PAPI_PROFIL_WEIGHTED", NULL},
	{PAPI_PROFIL_COMPRESS, "PAPI_PROFIL_COMPRESS", NULL},
	{PAPI_PROFIL_BUCKET_16, "PAPI_PROFIL_BUCKET_16", NULL},
	{PAPI_PROFIL_BUCKET_32, "PAPI_PROFIL_BUCKET_32", NULL},
	{PAPI_PROFIL_BUCKET_64, "PAPI_PROFIL_BUCKET_64", NULL},

	{PAPI_USR1_LOCK, "PAPI_USR1_LOCK", NULL},
	{PAPI_USR2_LOCK, "PAPI_USR2_LOCK", NULL},
	{PAPI_LOCK_USR1, "PAPI_LOCK_USR1", NULL},
	{PAPI_LOCK_USR2, "PAPI_LOCK_USR2", NULL},
	{PAPI_LOCK_NUM, "PAPI_LOCK_NUM", NULL},

	{PAPI_MH_MAX_LEVELS, "PAPI_MH_MAX_LEVELS", NULL},

	{PAPI_USR1_TLS, "PAPI_USR1_TLS", NULL},
	{PAPI_USR2_TLS, "PAPI_USR2_TLS", NULL},
	{PAPI_TLS_USR1, "PAPI_TLS_USR1", NULL},
	{PAPI_TLS_USR2, "PAPI_TLS_USR2", NULL},
	{PAPI_TLS_HIGH_LEVEL, "PAPI_TLS_HIGH_LEVEL", NULL},
	{PAPI_TLS_NUM, "PAPI_TLS_NUM", NULL},

/* Fortran offsets into PAPI_dmem_info_t structure. */
	{PAPIF_DMEM_VMSIZE, "PAPIF_DMEM_VMSIZE", NULL},
	{PAPIF_DMEM_RESIDENT, "PAPIF_DMEM_RESIDENT", NULL},
	{PAPIF_DMEM_HIGH_WATER, "PAPIF_DMEM_HIGH_WATER", NULL},
	{PAPIF_DMEM_SHARED, "PAPIF_DMEM_SHARED", NULL},
	{PAPIF_DMEM_TEXT, "PAPIF_DMEM_TEXT", NULL},
	{PAPIF_DMEM_LIBRARY, "PAPIF_DMEM_LIBRARY", NULL},
	{PAPIF_DMEM_HEAP, "PAPIF_DMEM_HEAP", NULL},
	{PAPIF_DMEM_LOCKED, "PAPIF_DMEM_LOCKED", NULL},
	{PAPIF_DMEM_STACK, "PAPIF_DMEM_STACK", NULL},
	{PAPIF_DMEM_PAGESIZE, "PAPIF_DMEM_PAGESIZE", NULL},
	{PAPIF_DMEM_MAXVAL, "PAPIF_DMEM_MAXVAL", NULL},

/* PAPI error defines */
 /* 0 */ {PAPI_OK, "PAPI_OK", "No error"},
    /* 1 */ {PAPI_EINVAL, "PAPI_EINVAL", "Invalid argument"},
    /* 2 */ {PAPI_ENOMEM, "PAPI_ENOMEM", "Insufficient memory"},
    /* 3 */ {PAPI_ESYS, "PAPI_ESYS", "A System/C library call failed"},
    /* 4 */ {PAPI_ECMP, "PAPI_ECMP", "Not supported by component"},
    /* 5 */ {PAPI_ECLOST, "PAPI_ECLOST", "Access to the counters was lost or interrupted"},
    /* 6 */ {PAPI_EBUG, "PAPI_EBUG", "Internal error, please send mail to the developers"},
    /* 7 */ {PAPI_ENOEVNT, "PAPI_ENOEVNT", "Event does not exist"},
    /* 8 */ {PAPI_ECNFLCT, "PAPI_ECNFLCT", "Event exists, but cannot be counted due to hardware resource limits"},
    /* 9 */ {PAPI_ENOTRUN, "PAPI_ENOTRUN", "EventSet is currently not running"},
    /*10 */ {PAPI_EISRUN, "PAPI_EISRUN", "EventSet is currently counting"},
    /*11 */ {PAPI_ENOEVST, "PAPI_ENOEVST", "No such EventSet available"},
    /*12 */ {PAPI_ENOTPRESET, "PAPI_ENOTPRESET", "Event in argument is not a valid preset"},
    /*13 */ {PAPI_ENOCNTR, "PAPI_ENOCNTR", "Hardware does not support performance counters"},
    /*14 */ {PAPI_EMISC, "PAPI_EMISC", "Unknown error code"},
    /*15 */ {PAPI_EPERM, "PAPI_EPERM", "Permission level does not permit operation"},
    /*16 */ {PAPI_ENOINIT, "PAPI_ENOINIT", "PAPI hasn't been initialized yet"},
    /*17 */ {PAPI_ENOCMP, "PAPI_ENOCMP", "Component Index isn't set"},
    /*18 */ {PAPI_ENOSUPP, "PAPI_ENOSUPP", "Not supported"},
    /*19 */ {PAPI_ENOIMPL, "PAPI_ENOIMPL", "Not implemented"},
    /*20 */ {PAPI_EBUF, "PAPI_EBUF", "Buffer size exceeded"},
    /*21 */ {PAPI_EINVAL_DOM, "PAPI_EINVAL_DOM", "EventSet domain is not supported for the operation"},
    /*22 */ {PAPI_EATTR, "PAPI_EATTR", "Invalid or missing event attributes"},
    /*23 */ {PAPI_ECOUNT, "PAPI_ECOUNT", "Too many events or attributes"},
    /*24 */ {PAPI_ECOMBO, "PAPI_ECOMBO", "Bad combination of features"},
    /*25 */ {PAPI_ECMP_DISABLED, "PAPI_ECMP_DISABLED", "Component containing event is disabled"}
};


enum deftype_t
{ CDEFINE, F77DEFINE, F90DEFINE };
static char comment_char = 'C';

static void
define_val( const char *val_string, int val, enum deftype_t deftype )
{
	char value[20];
	/* The Fortran spec defines negative numbers as the negation of a positive number.
	   Because of that definition, the largest possible 2's complement negative
	   number cannot be legally expressed in Fortran. Compiler behavior is undefined
	   and unpredictable on this issue.
	   Several FORTRAN compilers (GNU Fortran (GCC) > 4.2.3, others?)
	   will throw errors or warnings for an explicit numeric value of -2147483648,
	   However, they don't object to an arithmetic evaluation that produces the
	   desired value. This value happens to be used for the PAPI preset
	   PAPI_L1_DCM, and PAPI_DOM_HWSPEC. 
	   The hack below works around that limitation.
	 */
	if ( ( ( unsigned ) val ) == 0x80000000 ) {
		sprintf( value, "((-2147483647) - 1)" );
	} else {
		sprintf( value, "%d", val );
	}

	switch ( deftype ) {
	case CDEFINE:
		printf( "#define %-18s %s\n", val_string, value );
		break;
	case F77DEFINE:
		printf( "      INTEGER %-18s\n      PARAMETER (%s=%s)\n", val_string,
				val_string, value );
		break;
	case F90DEFINE:
		printf( "      INTEGER, PARAMETER :: %-18s = %s\n", val_string, value );
		break;
	}
}

static void
createDef( char *title, const hwi_describe_t * descr, int size,
		   enum deftype_t deftype )
{
	int i, j;
	/* compute the size of the predefined array */
	j = size / sizeof ( hwi_describe_t );

	/* create defines for each line in the general arrays */
	printf( "\n%c\n%c  %s\n%c\n\n", comment_char, comment_char, title,
			comment_char );
	for ( i = 0; i < j; i++ )
		define_val( descr[i].name, descr[i].value, deftype );
}


int
main( int argc, char **argv )
{
	int i;
	enum deftype_t deftype = CDEFINE;

	if ( argc > 1 ) {
		if ( strcmp( argv[1], "-f77" ) == 0 ) {
			deftype = F77DEFINE;
			comment_char = '!';
		} else if ( strcmp( argv[1], "-f90" ) == 0 ) {
			deftype = F90DEFINE;
			comment_char = '!';
		} else if ( strcmp( argv[1], "-c" ) == 0 ) {
			deftype = CDEFINE;
			comment_char = 'C';
		} else {
			fprintf( stderr, "Usage: %s [ -c | -f77 | -f90 ]\n", argv[0] );
			exit( 1 );
		}
	}

	/* print a file header block */
	printf
		( "%c\n%c  This file contains defines required by the PAPI Fortran interface.\n",
		  comment_char, comment_char );
	printf( "%c  It is automagically generated by genpapifdef.c\n",
			comment_char );
	printf( "%c  DO NOT modify its contents and expect the changes to stick.\n",
			comment_char );
	printf( "%c  Changes MUST be made in genpapifdef.c instead.\n%c\n\n",
			comment_char, comment_char );

	/* create defines for the internal array pairs */
	createDef( "General purpose defines.", _papi_def, sizeof ( _papi_def ),
			   deftype );
	/* create defines for each member of the PRESET array */
	printf( "\n%c\n%c  PAPI preset event values.\n%c\n\n", comment_char,
			comment_char, comment_char );

	for ( i = 0; i < PAPI_MAX_PRESET_EVENTS; i++ ) {
		if ( _papi_hwi_presets[i].symbol ) {	/* if the event is in the preset table */
			define_val( _papi_hwi_presets[i].symbol,
						( i | PAPI_PRESET_MASK ), deftype );
		}
	}
	exit( 0 );
}