Skip to content

Commit

Permalink
Add experimental extension for metric tracer
Browse files Browse the repository at this point in the history
Signed-off-by: Matias Cabral <[email protected]>
  • Loading branch information
matcabral committed Mar 14, 2024
1 parent 74cb674 commit 7135a59
Show file tree
Hide file tree
Showing 4 changed files with 438 additions and 1 deletion.
164 changes: 164 additions & 0 deletions scripts/tools/EXT_Exp_MetricTracer.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<%
import re
from templates import helper as th
%><%
OneApi=tags['$OneApi']
x=tags['$x']
X=x.upper()
t=tags['$t']
T=t.upper()
%>
:orphan:

.. _ZET_experimental_metric_tracer:

==========================================
Metric Tracer Experimental Extension
==========================================

API
----
* Enumerations

* ${t}_metric_group_sampling_type_flags_t

New value ${T}_METRIC_GROUP_SAMPLING_TYPE_FLAG_EXP_TRACER_BASED

* ${t}_metric_type_t

New Values
${T}_METRIC_TYPE_EXP_EVENT_NO_VALUE
Metric type: have only timestamp and value has no meaning.
${T}_METRIC_TYPE_EXP_EVENT_START
Metric type: the first event of a start/stop event pair.
${T}_METRIC_TYPE_EXP_EVENT_END
Metric type: the second event of a start/stop event pair.
${T}_METRIC_TYPE_EXP_EVENT_MONOTONIC_WRAPS_VALUE
Metric type: value of the event is a monotonic increasing value that can wrap around.


* Structures

* ${t}_metric_tracer_exp_desc_t
* ${t}_metric_entry_exp_t

* Functions

* ${t}MetricTracerCreateExp
* ${t}MetricTracerDestroyExp
* ${t}MetricTracerEnableExp
* ${t}MetricTracerDisableExp
* ${t}MetricTracerReadDataExp
* ${t}MetricDecoderCreateExp
* ${t}MetricDecoderDestroyExp
* ${t}MetricDecoderGetDecodableMetricsExp
* ${t}MetricTracerDecodeExp

Metric MetricTracer
~~~~~~~~~~~~~~~~~~~

Support collection of metrics from events produced in an asynchronous mode. Application can use ${t}MetricGroupGet to enumerate the list of metric groups
and ${t}MetricGroupGetProperties to get metric group sampling type and search for ${T}_METRIC_GROUP_SAMPLING_TYPE_FLAG_EXP_TRACER_BASED

Sample Code
------------

The following pseudo-code demonstrates how to enumerate Tracer based metric groups and collect data.

.. parsed-literal::
${t}_metric_group_handle_t hMetricGroup = nullptr;
${x}_event_handle_t hNotificationEvent = nullptr;
${x}_event_pool_handle_t hEventPool = nullptr;
${x}_event_pool_desc_t eventPoolDesc = {${X}_STRUCTURE_TYPE_EVENT_POOL_DESC, nullptr, 0, 1};
${x}_event_desc_t eventDesc = {${X}_STRUCTURE_TYPE_EVENT_DESC};
${t}_metric_tracer_exp_handle_t hMetricTracer = nullptr;
${t}_metric_tracer_exp_desc_t tracerDescriptor = { ${T}_STRUCTURE_TYPE_METRIC_TRACER_EXP_DESC, nullptr, 1024};
${t}_metric_decoder_exp_handle_t hMetricDecoder = nullptr;
// Find the first metric group suitable for Tracer Based collection
FindMetricGroup(hDevice, ${T}_METRIC_GROUP_SAMPLING_TYPE_FLAG_EXP_TRACER_BASED, &hMetricGroup );
// Configure the HW
${t}ContextActivateMetricGroups( hContext, hDevice, /\* count= \*/ 1, &hMetricGroup );
// Create notification event
${x}EventPoolCreate( hContext, &eventPoolDesc, 1, &hDevice, &hEventPool );
eventDesc.index = 0;
eventDesc.signal = ${X}_EVENT_SCOPE_FLAG_HOST;
eventDesc.wait = ${X}_EVENT_SCOPE_FLAG_HOST;
${x}EventCreate( hEventPool, &eventDesc, &hNotificationEvent );
// Create tracer
${t}MetricTracerCreateExp(hContext, hDevice, 1, hMetricGroup , &tracerDescriptor, hNotificationEvent, &hMetricTracer);
// create decoder
${t}MetricDecoderCreateExp( hMetricTracer, &hMetricDecoder);
// Get decodable metrics
uint32_t numDecodableMetrics = 0;
${t}MetricDecoderGetDecodableMetricsExp(hMetricDecoder, &numDecodableMetrics, nullptr);
std::vector<zet_metric_handle_t>decodableMetrics(numDecodableMetrics);
${t}MetricDecoderGetDecodableMetricsExp(hMetricDecoder, &numDecodableMetrics, decodableMetrics.data());
// Run your workload
Workload(hDevice);
// Wait for data, optional in this example
${x}EventHostSynchronize( hNotificationEvent, 1000 /\*timeout\*/ );
// reset the event if it fired
// Read raw data
size_t rawDataSize = 0;
${t}MetricTracerReadDataExp(hMetricTracer, &rawDataSize, nullptr);
uint8_t* rawData = malloc(rawDataSize);
${t}MetricTracerReadDataExp(hMetricTracer, &rawDataSize, rawData.data());
// decode
uint32_t numEntries =0;
${t}MetricTracerDecodeExp(hMetricDecoder, &rawDataSize, rawData.data(), numDecodableMetrics, decodableMetrics.data(), &numEntries, nullptr);
std::vector<ze_metric_entry_exp_t> decodedEntries(numEntries)
${t}MetricTracerDecodeExp(hMetricDecoder, &rawDataSize, rawData.data(), numDecodableMetrics, decodableMetrics.data(), &numEntries, decodedEntries.data());
for (uint32_t index = 0; index < numEntries; index++) {
${t}_metric_entry_exp_t metricEntry = decodedEntries[index];
${t}_metric_properties_t metricProperties = {};
${t}MetricGetProperties(decodableMetrics[metricEntry.metricIndex], &metricProperties);
printf ("Component: %s .Decodable metric name: %s ", metricProperties.component, metricProperties.name);
switch (metricProperties.resultType) {
case ${T}_VALUE_TYPE_UINT32:
case ${T}_VALUE_TYPE_UINT8:
case ${T}_VALUE_TYPE_UINT16:
printf "\t value: %lu \n" << metricEntry.value.ui32;
break;
case ${T}_VALUE_TYPE_UINT64:
printf "\t value: %llu \n" << metricEntry.value.ui64;
break;
case ${T}_VALUE_TYPE_FLOAT32:
printf "\t value: %f \n" << metricEntry.value.fp32;
break;
case ${T}_VALUE_TYPE_FLOAT64:
printf "\t value: %f \n" << metricEntry.value.fp64;
break;
case ${T}_VALUE_TYPE_BOOL8:
if( metricEntry.value.b8 ){
printf(" Value: true\n" );
else
printf(" Value: false\n" );
}
break;
default:
break;
}
}
// Close metric tracer
${t}MetricTracerDisableExp(hMetricTracer, true);
${t}MetricDecoderDestroyExp(hMetricDecoder);
${t}MetricTracerDestroyExp(hMetricTracer);
${x}EventDestroy( hNotificationEvent );
${x}EventPoolDestroy( hEventPool );
// Clean device configuration and free memory
${t}ContextActivateMetricGroups( hContext, hDevice, 0, nullptr );
4 changes: 4 additions & 0 deletions scripts/tools/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ etors:
desc: $t_metric_programmable_param_value_info_exp_t
version: "1.9"
value: "0x00010005"
- name: METRIC_TRACER_EXP_DESC
desc: $t_metric_tracer_exp_desc_t
version: "1.10"
value: "0x00010006"
--- #--------------------------------------------------------------------------
type: struct
desc: "Base for all properties types"
Expand Down
16 changes: 15 additions & 1 deletion scripts/tools/metric.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ etors:
desc: "Event based sampling"
- name: TIME_BASED
desc: "Time based sampling"
- name: EXP_TRACER_BASED
desc: "Experimental Tracer based sampling"
version: "1.10"
--- #--------------------------------------------------------------------------
type: struct
desc: "Metric group properties queried using $tMetricGroupGetProperties"
Expand Down Expand Up @@ -115,10 +118,21 @@ etors:
desc:
"1.6": "Metric type: instruction pointer"
"1.7": "Metric type: instruction pointer. Deprecated, use $T_METRIC_TYPE_IP."
value: "0x7ffffffe"
- name: IP
desc: "Metric type: instruction pointer"
version: "1.7"
- name: EXP_EVENT_NO_VALUE
desc: "Metric type: event with only timestamp and value has no meaning"
version: "1.10"
- name: EXP_EVENT_START
desc: "Metric type: the first event of a start/end event pair"
version: "1.10"
- name: EXP_EVENT_END
desc: "Metric type: the second event of a start/end event pair"
version: "1.10"
- name: EXP_EVENT_MONOTONIC_WRAPS_VALUE
desc: "Metric type: value of the event is a monotonically increasing value that can wrap around"
version: "1.10"
value: "0x7ffffffe"
--- #--------------------------------------------------------------------------
type: enum
Expand Down
Loading

0 comments on commit 7135a59

Please sign in to comment.