PAPI 7.1.0.0
Loading...
Searching...
No Matches
gpu_metric_list.c File Reference
Include dependency graph for gpu_metric_list.c:

Go to the source code of this file.

Macros

#define COMP_NAME   "intel_gpu"
 
#define MAX_NUM_METRICS   40
 
#define MAX_STRLEN   128
 
#define TEST_METRIC   "ComputeBasic.GpuTime"
 

Functions

int main (int argc, char **argv)
 

Variables

int numDevice = 0
 
long long metric_values [MAX_NUM_METRICS]
 

Macro Definition Documentation

◆ COMP_NAME

#define COMP_NAME   "intel_gpu"

Definition at line 47 of file gpu_metric_list.c.

◆ MAX_NUM_METRICS

#define MAX_NUM_METRICS   40

Definition at line 51 of file gpu_metric_list.c.

◆ MAX_STRLEN

#define MAX_STRLEN   128

Definition at line 52 of file gpu_metric_list.c.

◆ TEST_METRIC

#define TEST_METRIC   "ComputeBasic.GpuTime"

Definition at line 56 of file gpu_metric_list.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 59 of file gpu_metric_list.c.

59 {
60
61 (void)argc;
62 (void)argv;
63
64 int i = 0;
65 int cid = -1;
66 int numMetrics = 0;
67 int numGroups = 0;
68 int selectedAll = 1;
69 int listGroupOnly = 0;
70 char *metricName = NULL;
71 char *metricGroupName = NULL;
72 int retVal = PAPI_OK;
74 char ch;
75
76 while ((ch=getopt(argc, argv, "ahm:g:")) != -1) {
77 switch(ch) {
78 case 'a':
79 listGroupOnly = 1;
80 if (metricGroupName) {
81 printf("list all groups, ignore group name\n");
82 metricGroupName = NULL;
83 }
84 break;
85 case 'h':
86 printf("usage: %s [-a] [-g <metricGroupName>] [-m <metricName>]\n", argv[0]);
87 return 0;
88 case 'm':
89 metricName = optarg;
90 selectedAll = 0;
91 break;
92 case 'g':
93 if (!listGroupOnly) {
94 metricGroupName = optarg;
95 } else {
96 printf("list all groups, ignore group name\n");
97 }
98 break;
99 default:
100 break;
101 }
102 }
103
104 PAPI_component_info_t *aComp = NULL;
105
107 if( retVal != PAPI_VER_CURRENT ) {
108 fprintf( stderr, "PAPI_library_init failed\n" );
109 exit(-1);
110 }
111
112 int numComps = PAPI_num_components();
113 for (i=0; i<numComps; i++) {
114 aComp = (PAPI_component_info_t*) PAPI_get_component_info(i); // get the component info.
115 if (aComp && (!strcmp(COMP_NAME, aComp->name))) {
116 cid=i;
117 break;
118 }
119 }
120 if (i == numComps) {
121 printf("Component %s is not supported\n", aComp->name);
122 return 1;
123 }
124
125 printf("Name: %s\n", aComp->name);
126 printf("Description: %s\n", aComp->description);
127
128 if (selectedAll || listGroupOnly) {
129 i = 0 | PAPI_NATIVE_MASK;
130 retVal=PAPI_enum_cmp_event( &i, PAPI_ENUM_FIRST, cid );
131 numMetrics = 0;
132 do {
133 memset( &info, 0, sizeof ( info ) );
134 retVal = PAPI_get_event_info( i, &info );
135 if (retVal == PAPI_OK) {
136 if (listGroupOnly) {
137 if (!metricGroupName || !strstr(info.symbol, metricGroupName)) {
138 char *pt = index(info.symbol, '.');
139 if (pt) {
140 *pt = '\0';
141 }
142 if (metricGroupName) {
143 free(metricGroupName);
144 }
145 metricGroupName = strdup(info.symbol);
146 printf("%s\n", metricGroupName);
147 numGroups++;
148 }
149 } else if ((!metricGroupName) || strstr(info.symbol, metricGroupName)) {
150 printf("%s\n\t%s\n", info.symbol, info.long_descr);
151 numMetrics++;
152 }
153 }
154 retVal = PAPI_enum_cmp_event( &i, PAPI_ENUM_EVENTS, cid );
155 } while (retVal == PAPI_OK);
156
157 retVal = PAPI_OK;
158 if (!numMetrics && !numGroups) {
159 fprintf(stderr, "Error on enum_cmp_event, abort.\n");
160 retVal = PAPI_ENOEVNT;
161 }
162 if (listGroupOnly) {
163 printf("Total %d metric groups are supported\n", numGroups);
164 } else {
165 printf("Total %d metrics are supported\n", numMetrics);
166 }
168 return retVal;
169 }
170
171 if (!metricName) {
172 metricName = TEST_METRIC;
173 }
174 printf("Query metric by name %s -- ", metricName);
175
176 retVal = PAPI_query_named_event(metricName);
177 if (retVal != PAPI_OK) {
178 printf("does not exist, abort.\n");
180 return retVal;
181 } else {
182 printf("is supported.\n");
183 }
184
185 int code = 0;
186 retVal = PAPI_event_name_to_code(metricName, &code);
187 if (retVal != PAPI_OK) {
188 printf("PAPI_event_name_to_code event %s dose not exist, abort.\n", metricName);
190 return retVal;
191 }
192 printf("Named metric %s is enumerated with code 0x%x.\n", metricName, code);
193 printf("Query metric by code 0x%x -- ", code);
194 retVal = PAPI_query_event(code);
195 if (retVal != PAPI_OK) {
196 printf("dose not exist, abort.\n");
198 return retVal;
199 } else {
200 printf("is supported.\n");
201 }
202
204 return 0;
205}
int i
Enumerate PAPI preset or native events for a given component.
Convert a name to a numeric hardware event code.
get information about a specific software component
Get the event's name and description info.
initialize the PAPI library.
Get the number of components available on the system.
Query if PAPI event exists.
Query if a named PAPI event exists.
Finish using PAPI and free all related resources.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_ENUM_EVENTS
Definition: f90papi.h:224
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_ENUM_FIRST
Definition: f90papi.h:85
#define PAPI_ENOEVNT
Definition: f90papi.h:139
#define COMP_NAME
#define TEST_METRIC
#define PAPI_NATIVE_MASK
FILE * stderr
char description[PAPI_MAX_STR_LEN]
Definition: papi.h:630
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:627
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:960
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:963

Variable Documentation

◆ metric_values

long long metric_values[MAX_NUM_METRICS]

Definition at line 54 of file gpu_metric_list.c.

◆ numDevice

int numDevice = 0

Definition at line 49 of file gpu_metric_list.c.