Skip to content

Commit 354beef

Browse files
joshuaranjanpbg-intel
authored andcommitted
add support for metrics and groups to export memory
Signed-off-by: Joshua Santosh Ranjan <[email protected]>
1 parent b825b42 commit 354beef

File tree

4 files changed

+165
-0
lines changed

4 files changed

+165
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<%
2+
import re
3+
from templates import helper as th
4+
%><%
5+
OneApi=tags['$OneApi']
6+
x=tags['$x']
7+
X=x.upper()
8+
t=tags['$t']
9+
T=t.upper()
10+
%>
11+
:orphan:
12+
13+
.. _ZET_experimental_metric_export_memory:
14+
15+
==============================================
16+
MetricGroup and Metric Export Memory Extension
17+
==============================================
18+
19+
API
20+
----
21+
22+
* Enumerations
23+
24+
* ${t}_metric_group_type_exp_flags_t
25+
26+
* Structures
27+
28+
* ${t}_metric_group_type_exp_t
29+
* ${t}_export_dma_buf_exp_properties_t
30+
31+
Sample Code
32+
------------
33+
34+
The following pseudo-code demonstrates how to map memory exported by metric groups:
35+
36+
.. parsed-literal::
37+
38+
// Request Metric group type using `pNext` of ${t}_metric_group_properties_t
39+
zet_metric_group_type_exp_t metricGroupType;
40+
metricGroupType.stype = ${T}_STRUCTURE_TYPE_METRIC_GROUP_TYPE_EXP;
41+
42+
zet_metric_group_properties_t metricGroupProperties;
43+
metricGroupProperties.stype = ${T}_STRUCTURE_TYPE_METRIC_GROUP_PROPERTIES;
44+
metricGroupProperties.pNext = &metricGroupType;
45+
zetMetricGroupGetProperties(hMetricGroup, &metricGroupProperties);
46+
47+
if(metricGroupType.type == ZET_METRIC_GROUP_TYPE_EXP_EXPORT_DMA_BUF){
48+
zet_export_dma_buf_exp_properties_t dmaBufProperties;
49+
dmaBufProperties.stype = ${T}_STRUCTURE_TYPE_EXPORT_DMA_EXP_PROPERTIES;
50+
metricGroupProperties.pNext = &dmaBufProperties;
51+
zetMetricGroupGetProperties(hMetricGroup, &metricGroupProperties);
52+
53+
// Import the dma buf
54+
ze_external_memory_import_fd_t importDmaBuf = {
55+
.stype = ZE_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMPORT_FD,
56+
.flags = ZE_EXTERNAL_MEMORY_TYPE_FLAG_DMA_BUF,
57+
.fd = dmaBufProperties.fd;
58+
};
59+
60+
ze_device_mem_alloc_desc_t allocDesc = {
61+
.stype = ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC,
62+
.pNext = &importDmaBuf,
63+
.flags = 0,
64+
.ordinal = 0
65+
};
66+
67+
void * pMappedAddress = nullptr;
68+
zeMemAllocDevice(hContext, &allocDesc, dmaBufProperties.size, 4096, hDevice, &pMappedAddress);
69+
}
70+
71+
The following pseudo-code demonstrates how to map memory exported by metrics:
72+
73+
.. parsed-literal::
74+
75+
// Request Metric group type using `pNext` of ${t}_metric_properties_t
76+
77+
zet_metric_properties_t metricProperties;
78+
metricProperties.stype = ${T}_STRUCTURE_TYPE_METRIC_PROPERTIES;
79+
zetMetricGetProperties(hMetric, &metricProperties);
80+
81+
if(metricProperties.metricType == ZET_METRIC_TYPE_EXPORT_DMA_BUF){
82+
zet_export_dma_buf_exp_properties_t dmaBufProperties;
83+
dmaBufProperties.stype = ${T}_STRUCTURE_TYPE_EXPORT_DMA_EXP_PROPERTIES;
84+
metricProperties.pNext = &dmaBufProperties;
85+
zetMetricGetProperties(hMetricGroup, &metricProperties);
86+
87+
// Import the dma buf
88+
ze_external_memory_import_fd_t importDmaBuf = {
89+
.stype = ZE_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMPORT_FD,
90+
.flags = ZE_EXTERNAL_MEMORY_TYPE_FLAG_DMA_BUF,
91+
.fd = dmaBufProperties.fd;
92+
};
93+
94+
ze_device_mem_alloc_desc_t allocDesc = {
95+
.stype = ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC,
96+
.pNext = &importDmaBuf,
97+
.flags = 0,
98+
.ordinal = 0
99+
};
100+
101+
void * pMappedAddress = nullptr;
102+
zeMemAllocDevice(hContext, &allocDesc, dmaBufProperties.size, 4096, hDevice, &pMappedAddress);
103+
}

scripts/tools/common.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@ etors:
137137
desc: $t_metric_programmable_param_value_info_exp_t
138138
version: "1.9"
139139
value: "0x00010005"
140+
- name: METRIC_GROUP_TYPE_EXP
141+
desc: $t_metric_group_type_exp_t
142+
version: "1.11"
143+
value: "0x00010006"
144+
- name: EXPORT_DMA_EXP_PROPERTIES
145+
desc: $t_export_dma_buf_exp_properties_t
146+
version: "1.11"
147+
value: "0x00010007"
140148
- name: METRIC_TRACER_EXP_DESC
141149
desc: $t_metric_tracer_exp_desc_t
142150
version: "1.10"

scripts/tools/metric.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ etors:
114114
desc: "Metric type: ratio"
115115
- name: RAW
116116
desc: "Metric type: raw"
117+
- name: EXPORT_DMA_BUF
118+
desc: "Metric which exports linux dma_buf, which could be imported/mapped to the host process"
119+
version: "1.11"
120+
value: "0x7ffffffd"
117121
- name: IP_EXP
118122
desc:
119123
"1.6": "Metric type: instruction pointer"
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#
2+
# Copyright (C) 2024 Intel Corporation
3+
#
4+
# SPDX-License-Identifier: MIT
5+
#
6+
# See YaML.md for syntax definition
7+
#
8+
--- #--------------------------------------------------------------------------
9+
type: header
10+
desc: "Intel $OneApi Level-Zero Tool Experimental Extension for Metrics/Metric Groups which export Memory"
11+
version: "1.11"
12+
--- #--------------------------------------------------------------------------
13+
type: enum
14+
desc: "Metric group type"
15+
class: $tMetricGroup
16+
name: $t_metric_group_type_exp_flags_t
17+
etors:
18+
- name: EXPORT_DMA_BUF
19+
desc:
20+
Metric group and metrics exports memory using linux dma-buf, which could be imported/mapped to the host process.
21+
Properties of the dma_buf could be queried using $t_export_dma_buf_exp_properties_t.
22+
- name: USER_CREATED
23+
desc: "Metric group created using $tMetricGroupCreateExp"
24+
- name: OTHER
25+
desc: "Metric group which has a collection of metrics"
26+
--- #--------------------------------------------------------------------------
27+
type: struct
28+
desc: "Query the metric group type using `pNext` of $t_metric_group_properties_t"
29+
class: $tMetricGroup
30+
name: $t_metric_group_type_exp_t
31+
base: $t_base_properties_t
32+
members:
33+
- type: "$t_metric_group_type_exp_flags_t"
34+
name: "type"
35+
desc: |
36+
[out] metric group type.
37+
returns a combination of $t_metric_group_type_exp_flags_t.
38+
--- #--------------------------------------------------------------------------
39+
type: struct
40+
desc: "Exported dma_buf properties queried using `pNext` of $t_metric_group_properties_t or $t_metric_properties_t"
41+
class: $tMetric
42+
name: $t_export_dma_buf_exp_properties_t
43+
base: $t_base_properties_t
44+
members:
45+
- type: int
46+
name: "fd"
47+
desc: "[out] the file descriptor handle that could be used to import the memory by the host process."
48+
- type: size_t
49+
name: "size"
50+
desc: "[out] size in bytes of the dma_buf"

0 commit comments

Comments
 (0)