PAPI 7.1.0.0
Loading...
Searching...
No Matches
gpu_metric_list.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Intel Corp. All rights reserved
3 * Contributed by Peinan Zhang <peinan.zhang@intel.com>
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
17 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
20 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Based on Intel Software Optimization Guide 2015
23 */
24
25
26/*
27 * This test case reports all available Intel GPU performance metrics.
28 *
29 * @brief list all available metrics groups, all metrics or the metrics in a certain metrics group
30 *
31 * @option:
32 * [-a (all metrics)] [-g <metricGroupName>] [-m <metricName>]
33 *
34 * Example:
35 * metricGroupName "ComputeBasic"
36 * metricName "ComputeBasic.GpuTime"
37 *
38 **/
39
40#include <stdio.h>
41#include <stdlib.h>
42#include <unistd.h>
43#include <string.h>
44
45#include "papi.h"
46
47#define COMP_NAME "intel_gpu"
48
49int numDevice = 0;
50
51#define MAX_NUM_METRICS 40
52#define MAX_STRLEN 128
53
55
56#define TEST_METRIC "ComputeBasic.GpuTime"
57
58int
59main(int argc, char ** argv) {
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
int numDevice
long long metric_values[MAX_NUM_METRICS]
#define COMP_NAME
#define TEST_METRIC
#define MAX_NUM_METRICS
#define PAPI_NATIVE_MASK
Return codes and api definitions.
FILE * stderr
int main()
Definition: pernode.c:20
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