-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add experimental extension for metric tracer
Signed-off-by: Matias Cabral <[email protected]>
- Loading branch information
Showing
4 changed files
with
438 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.