PAPI 7.1.0.0
Loading...
Searching...
No Matches
GPUMetricInterface.h
Go to the documentation of this file.
1/*
2 * GPUMetricInterface.h: IntelĀ® Graphics Component for PAPI
3 *
4 * Copyright (c) 2020 Intel Corp. All rights reserved
5 * Contributed by Peinan Zhang <peinan.zhang@intel.com>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
11 * of the Software, and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
18 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
19 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
21 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
22 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25#ifndef _GPUMETRICINTERFACE_H
26#define _GPUMETRICINTERFACE_H
27
28#include <stdio.h>
29#include <stdint.h>
30
31#pragma once
32
33#if defined(__cplusplus)
34extern "C" {
35#endif
36
37#ifndef MAX_STR_LEN
38#define MAX_STR_LEN 256
39#endif
40
41//metric group type
42#define TIME_BASED 0
43#define EVENT_BASED 1
44
45//metric type
46#define M_ACCUMULATE 0x0
47#define M_AVERAGE 0x1
48#define M_RAW 0x2
49
50typedef int DEVICE_HANDLE;
51
52typedef char NAMESTR[MAX_STR_LEN];
53
54typedef struct MetricInfo_S MetricInfo;
55
57 uint32_t code;
58 uint32_t dataType;
59 uint32_t metricType; // 0 accumulate 1 average, 2 raw (static)
63 MetricInfo *infoEntries;
64};
65
66/* define GPU device info */
67typedef struct DeviceInfo_S {
69 uint32_t driverId;
70 uint32_t deviceId;
71 uint32_t subdeviceId;
72 uint32_t numSubdevices;
73 uint32_t index;
75 MetricInfo *metricGroups;
77
78typedef struct DataEntry_S {
79 uint32_t code;
80 uint32_t type;
81 union {
82 long long ival;
83 double fpval;
84 } value;
85} DataEntry;
86
87/* Metric data for each device
88 * Data can contain multiple set, one set per subdevice
89 */
90typedef struct MetricData_S {
91 int id;
92 uint32_t grpCode;
93 uint32_t numDataSets; // num of data set per device
94 uint32_t metricCount; // metrics per data set
95 uint32_t numEntries; // total data entries allocated
96 int *dataSetStartIdx; // start index per each data set, -1 mean no data available
99
100typedef struct MetricNode_S {
102 int code;
103} MetricNode;
104
105
106/* index code for a handle
107 * resv(4) + drv (4) + dev(4) + subdev(4) + index(16)
108 */
109#define DRV_BITS 4
110#define DEV_BITS 4
111#define SDEV_BITS 4
112#define IDX_BITS 16
113#define DMASK 0xf
114#define DCODE_MASK 0xfff
115#define IDX_MASK 0xffff
116
117#define CreateDeviceCode(drv, dev, sdev) \
118 ((((drv)&DMASK)<<(SDEV_BITS+DEV_BITS)) | \
119 (((dev)&DMASK)<<SDEV_BITS) | \
120 ((sdev)&DMASK))
121
122/* this macro is used for creating index code for device and event.
123 * The idx can be device index or event idx
124 */
125#define CreateIdxCode(devcode, idx) ((((devcode)&DCODE_MASK)<<IDX_BITS)|((idx)&IDX_MASK))
126
127#define GetDeviceCode(handle) (((handle) >> IDX_BITS) & DCODE_MASK)
128#define GetIdx(handle) ((handle) & IDX_MASK)
129#define GetSDev(handle) (((handle) >> IDX_BITS) & DMASK)
130#define GetDev(handle) (((handle) >> (IDX_BITS+SDEV_BITS)) & DMASK)
131#define GetDrv(handle) (((handle) >> (IDX_BITS+SDEV_BITS+DEV_BITS)) & DMASK)
132#define IsDeviceHandle(devcode, handle) ((devcode) == (((handle)>>IDX_BITS)&DCODE_MASK))
133
134/*
135 * metric code: group(8) + metrics(8)
136 */
137#define METRIC_BITS 8
138#define METRIC_GROUP_MASK 0xff00
139#define METRIC_MASK 0x00ff
140
141#define CreateGroupCode(mGroupId) (((mGroupId+1)<<METRIC_BITS) & METRIC_GROUP_MASK)
142#define CreateMetricCode(mGroupId, mId) ((CreateGroupCode(mGroupId)) | ((mId+1)&METRIC_MASK))
143#define GetGroupIdx(code) (((code) & METRIC_GROUP_MASK) >> METRIC_BITS)
144#define GetMetricIdx(code) ((code) & METRIC_MASK)
145
146
147#define MAX_METRICS 128
148
149#define MAX_NUM_REPORTS 20
150
151/* collection modes */
152#define METRIC_SAMPLE 0x1
153#define METRIC_SUMMARY 0x2
154#define METRIC_RESET 0x4
155
156MetricInfo *GPUAllocMetricInfo(uint32_t count);
157void GPUFreeMetricInfo(MetricInfo *info, uint32_t count);
158MetricData *GPUAllocMetricData(uint32_t count, uint32_t numSets, uint32_t numMetrics);
159void GPUFreeMetricData(MetricData *data, uint32_t count);
160
161extern void
162strncpy_se(char *dest, size_t destSize, char *src, size_t count);
163
164
165/* ------------------------------------------------------------------------- */
166
167/* ------------------------------------------------------------------------- */
178
179
180/* ------------------------------------------------------------------------- */
191int GPUGetDeviceInfo(DEVICE_HANDLE handle, MetricInfo *data);
192
193/* ------------------------------------------------------------------------- */
205
206
207/* ------------------------------------------------------------------------- */
219int GPUGetMetricGroups(DEVICE_HANDLE handle, uint32_t mtype, MetricInfo *data);
220
221/* ------------------------------------------------------------------------- */
236int GPUGetMetricList(DEVICE_HANDLE handle, char *groupName, uint32_t mtype, MetricInfo *data);
237
238/* ------------------------------------------------------------------------- */
255 char *metricGroupName, uint32_t metricGroupCode, uint32_t mtype,
256 uint32_t period, uint32_t numReports);
257
258/* ------------------------------------------------------------------------- */
275int GPUEnableMetrics(DEVICE_HANDLE handle, char **metricNameList,
276 uint32_t numMetrics, uint32_t mtype,
277 uint32_t period, uint32_t numReports);
278
279/* ------------------------------------------------------------------------- */
291
292
293/*------------------------------------------------------------------------- */
304
305
306/* ------------------------------------------------------------------------- */
319
320
321
322/* ------------------------------------------------------------------------- */
334MetricData *GPUReadMetricData(DEVICE_HANDLE handle, uint32_t mode, uint32_t *reportCounts);
335
336/* ------------------------------------------------------------------------- */
348
349
350/* ------------------------------------------------------------------------- */
360//void GPUFreeDevice();
362
363#if defined(__cplusplus)
364}
365#endif
366
367#endif
int GPUGetMetricList(DEVICE_HANDLE handle, char *groupName, uint32_t mtype, MetricInfo *data)
list available metrics in the named group. If name is "", list all available metrics in all groups
void strncpy_se(char *dest, size_t destSize, char *src, size_t count)
int GPUEnableMetricGroup(DEVICE_HANDLE handle, char *metricGroupName, uint32_t metricGroupCode, uint32_t mtype, uint32_t period, uint32_t numReports)
MetricInfo * GPUAllocMetricInfo(uint32_t count)
int GPUGetMetricGroups(DEVICE_HANDLE handle, uint32_t mtype, MetricInfo *data)
list available metric groups for the selected type
void GPUFreeMetricInfo(MetricInfo *info, uint32_t count)
char NAMESTR[MAX_STR_LEN]
#define MAX_STR_LEN
int GPUEnableMetrics(DEVICE_HANDLE handle, char **metricNameList, uint32_t numMetrics, uint32_t mtype, uint32_t period, uint32_t numReports)
int GPUStop(DEVICE_HANDLE handle)
int GPUDisableMetricGroup(DEVICE_HANDLE handle, uint32_t mtype)
int GPUDetectDevice(DEVICE_HANDLE **handle, uint32_t *numDevice)
Detect the named device which has performance monitoring feature availale.
MetricData * GPUReadMetricData(DEVICE_HANDLE handle, uint32_t mode, uint32_t *reportCounts)
read metric data
int GPUPrintDeviceInfo(DEVICE_HANDLE handle, FILE *stream)
Get the device properties, which is mainly in <name, value> format.
void GPUFreeMetricData(MetricData *data, uint32_t count)
int GPUSetMetricControl(DEVICE_HANDLE handle, uint32_t mode)
set control for metric data collection
int DEVICE_HANDLE
int GPUGetDeviceInfo(DEVICE_HANDLE handle, MetricInfo *data)
Get the device properties, which is mainly in <name, value> format.
MetricData * GPUAllocMetricData(uint32_t count, uint32_t numSets, uint32_t numMetrics)
int GPUStart(DEVICE_HANDLE handle)
start collection
void GPUFreeDevice(DEVICE_HANDLE handle)
free the resouce related this device handle
static papi_handle_t handle
Definition: Gamum.c:21
static long count
int numDevice
const char * name
Definition: rocs.c:225
long long ival
uint32_t driverId
uint32_t deviceId
DEVICE_HANDLE handle
uint32_t numSubdevices
uint32_t subdeviceId
MetricInfo * metricGroups
uint32_t metricCount
uint32_t numEntries
DataEntry * dataEntries
uint32_t grpCode
uint32_t numDataSets
MetricInfo * infoEntries
char desc[MAX_STR_LEN]
char name[MAX_STR_LEN]