|
| 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 | + } |
0 commit comments