Metric Api: Renamed MetricTracer to MetricStreamer

Change-Id: I7de16b230685201b0f91b227f17713c3cd49d497
Signed-off-by: Robert Krzemien <robert.krzemien@intel.com>
This commit is contained in:
Robert Krzemien
2020-07-09 14:21:33 +02:00
committed by sys_ocldev
parent 278505ca4d
commit f87f05bf8d
18 changed files with 1908 additions and 801 deletions

View File

@ -10,6 +10,8 @@
#include "level_zero/tools/source/metrics/metric.h"
#include <level_zero/zet_api.h>
#include "third_party/level_zero/zet_api_ext.h"
extern "C" {
__zedllexport ze_result_t __zecall
@ -93,6 +95,39 @@ zetMetricTracerReadData(
return L0::MetricTracer::fromHandle(hMetricTracer)->readData(maxReportCount, pRawDataSize, pRawData);
}
ZE_APIEXPORT ze_result_t ZE_APICALL
zetMetricStreamerOpen(
zet_device_handle_t hDevice,
zet_metric_group_handle_t hMetricGroup,
zet_metric_streamer_desc_t *pDesc,
ze_event_handle_t hNotificationEvent,
zet_metric_streamer_handle_t *phMetricStreamer) {
return L0::metricStreamerOpen(hDevice, hMetricGroup, pDesc, hNotificationEvent, phMetricStreamer);
}
ZE_APIEXPORT ze_result_t ZE_APICALL
zetCommandListAppendMetricStreamerMarker(
ze_command_list_handle_t hCommandList,
zet_metric_streamer_handle_t hMetricStreamer,
uint32_t value) {
return L0::CommandList::fromHandle(hCommandList)->appendMetricStreamerMarker(hMetricStreamer, value);
}
ZE_APIEXPORT ze_result_t ZE_APICALL
zetMetricStreamerClose(
zet_metric_streamer_handle_t hMetricStreamer) {
return L0::MetricStreamer::fromHandle(hMetricStreamer)->close();
}
ZE_APIEXPORT ze_result_t ZE_APICALL
zetMetricStreamerReadData(
zet_metric_streamer_handle_t hMetricStreamer,
uint32_t maxReportCount,
size_t *pRawDataSize,
uint8_t *pRawData) {
return L0::MetricStreamer::fromHandle(hMetricStreamer)->readData(maxReportCount, pRawDataSize, pRawData);
}
__zedllexport ze_result_t __zecall
zetMetricQueryPoolCreate(
zet_device_handle_t hDevice,

View File

@ -16,6 +16,8 @@
#include <level_zero/ze_api.h>
#include <level_zero/zet_api.h>
#include "third_party/level_zero/zet_api_ext.h"
#include <vector>
struct _ze_command_list_handle_t {};
@ -104,6 +106,8 @@ struct CommandList : _ze_command_list_handle_t {
virtual ze_result_t reset() = 0;
virtual ze_result_t appendMetricMemoryBarrier() = 0;
virtual ze_result_t appendMetricStreamerMarker(zet_metric_streamer_handle_t hMetricStreamer,
uint32_t value) = 0;
virtual ze_result_t appendMetricTracerMarker(zet_metric_tracer_handle_t hMetricTracer,
uint32_t value) = 0;
virtual ze_result_t appendMetricQueryBegin(zet_metric_query_handle_t hMetricQuery) = 0;

View File

@ -35,9 +35,17 @@ ze_result_t CommandListImp::appendMetricMemoryBarrier() {
return MetricQuery::appendMemoryBarrier(*this);
}
ze_result_t CommandListImp::appendMetricStreamerMarker(zet_metric_streamer_handle_t hMetricStreamer,
uint32_t value) {
return MetricQuery::appendStreamerMarker(*this, hMetricStreamer, value);
}
ze_result_t CommandListImp::appendMetricTracerMarker(zet_metric_tracer_handle_t hMetricTracer,
uint32_t value) {
return MetricQuery::appendTracerMarker(*this, hMetricTracer, value);
zet_metric_streamer_handle_t hMetricStreamer = reinterpret_cast<zet_metric_streamer_handle_t>(hMetricTracer);
return MetricQuery::appendStreamerMarker(*this, hMetricStreamer, value);
}
ze_result_t CommandListImp::appendMetricQueryBegin(zet_metric_query_handle_t hMetricQuery) {

View File

@ -18,6 +18,8 @@ struct CommandListImp : CommandList {
ze_result_t destroy() override;
ze_result_t appendMetricMemoryBarrier() override;
ze_result_t appendMetricStreamerMarker(zet_metric_streamer_handle_t hMetricStreamer,
uint32_t value) override;
ze_result_t appendMetricTracerMarker(zet_metric_tracer_handle_t hMetricTracer,
uint32_t value) override;
ze_result_t appendMetricQueryBegin(zet_metric_query_handle_t hMetricQuery) override;

View File

@ -42,8 +42,8 @@ struct EventImp : public Event {
uint64_t *hostAddr = static_cast<uint64_t *>(hostAddress);
uint32_t queryVal = Event::STATE_CLEARED;
if (metricTracer != nullptr) {
*hostAddr = metricTracer->getNotificationState();
if (metricStreamer != nullptr) {
*hostAddr = metricStreamer->getNotificationState();
}
this->csr->downloadAllocations();

View File

@ -19,7 +19,7 @@ struct _ze_event_pool_handle_t {};
namespace L0 {
typedef uint64_t FlushStamp;
struct EventPool;
struct MetricTracer;
struct MetricStreamer;
struct Event : _ze_event_handle_t {
virtual ~Event() = default;
@ -55,8 +55,8 @@ struct Event : _ze_event_handle_t {
bool isTimestampEvent = false;
// Metric tracer instance associated with the event.
MetricTracer *metricTracer = nullptr;
// Metric streamer instance associated with the event.
MetricStreamer *metricStreamer = nullptr;
NEO::CommandStreamReceiver *csr = nullptr;

View File

@ -239,6 +239,10 @@ struct MockCommandList : public CommandList {
ADDMETHOD_NOBASE(appendMetricMemoryBarrier, ze_result_t, ZE_RESULT_SUCCESS, ());
ADDMETHOD_NOBASE(appendMetricStreamerMarker, ze_result_t, ZE_RESULT_SUCCESS,
(zet_metric_streamer_handle_t hMetricStreamer,
uint32_t value));
ADDMETHOD_NOBASE(appendMetricTracerMarker, ze_result_t, ZE_RESULT_SUCCESS,
(zet_metric_tracer_handle_t hMetricTracer,
uint32_t value));

View File

@ -10,7 +10,7 @@ set(L0_SRCS_TOOLS_METRICS
list(APPEND L0_SRCS_TOOLS_METRICS
${CMAKE_CURRENT_SOURCE_DIR}/metric.cpp
${CMAKE_CURRENT_SOURCE_DIR}/metric_enumeration_imp.cpp
${CMAKE_CURRENT_SOURCE_DIR}/metric_tracer_imp.cpp
${CMAKE_CURRENT_SOURCE_DIR}/metric_streamer_imp.cpp
${CMAKE_CURRENT_SOURCE_DIR}/metric_query_imp.cpp)
if(UNIX)

View File

@ -53,8 +53,8 @@ struct MetricContextImp : public MetricContext {
Device &getDevice() override;
MetricsLibrary &getMetricsLibrary() override;
MetricEnumeration &getMetricEnumeration() override;
MetricTracer *getMetricTracer() override;
void setMetricTracer(MetricTracer *pMetricTracer) override;
MetricStreamer *getMetricStreamer() override;
void setMetricStreamer(MetricStreamer *pMetricStreamer) override;
void setMetricsLibrary(MetricsLibrary &metricsLibrary) override;
void setMetricEnumeration(MetricEnumeration &metricEnumeration) override;
@ -72,7 +72,7 @@ struct MetricContextImp : public MetricContext {
std::unique_ptr<MetricEnumeration> metricEnumeration = nullptr;
std::unique_ptr<MetricsLibrary> metricsLibrary = nullptr;
MetricGroupDomains metricGroupDomains;
MetricTracer *pMetricTracer = nullptr;
MetricStreamer *pMetricStreamer = nullptr;
bool useCompute = false;
};
@ -118,10 +118,10 @@ MetricsLibrary &MetricContextImp::getMetricsLibrary() { return *metricsLibrary;
MetricEnumeration &MetricContextImp::getMetricEnumeration() { return *metricEnumeration; }
MetricTracer *MetricContextImp::getMetricTracer() { return pMetricTracer; }
MetricStreamer *MetricContextImp::getMetricStreamer() { return pMetricStreamer; }
void MetricContextImp::setMetricTracer(MetricTracer *pMetricTracer) {
this->pMetricTracer = pMetricTracer;
void MetricContextImp::setMetricStreamer(MetricStreamer *pMetricStreamer) {
this->pMetricStreamer = pMetricStreamer;
}
void MetricContextImp::setMetricsLibrary(MetricsLibrary &metricsLibrary) {
@ -146,7 +146,7 @@ ze_result_t
MetricContextImp::activateMetricGroupsDeferred(const uint32_t count,
zet_metric_group_handle_t *phMetricGroups) {
// Activation: postpone until zetMetricTracerOpen or zeCommandQueueExecuteCommandLists
// Activation: postpone until zetMetricStreamerOpen or zeCommandQueueExecuteCommandLists
// Deactivation: execute immediately.
return phMetricGroups ? metricGroupDomains.activateDeferred(count, phMetricGroups)
: metricGroupDomains.deactivate();
@ -250,7 +250,7 @@ bool MetricGroupDomains::activateMetricGroupDeferred(const zet_metric_group_hand
// Associate metric group with domain and mark it as not active.
// Activation will be performed during zeCommandQueueExecuteCommandLists (query)
// or zetMetricTracerOpen (time based sampling).
// or zetMetricStreamerOpen (time based sampling).
domains[domain].first = hMetricGroup;
domains[domain].second = false;
@ -269,7 +269,7 @@ ze_result_t MetricGroupDomains::activate() {
ZET_METRIC_GROUP_SAMPLING_TYPE_EVENT_BASED;
// Activate only event based metric groups.
// Time based metric group will be activated during zetMetricTracerOpen.
// Time based metric group will be activated during zetMetricStreamerOpen.
if (metricGroupEventBased && !metricGroupActive) {
metricGroupActive = activateEventMetricGroup(hMetricGroup);
@ -347,11 +347,26 @@ ze_result_t metricGroupGet(zet_device_handle_t hDevice, uint32_t *pCount, zet_me
phMetricGroups);
}
ze_result_t metricStreamerOpen(zet_device_handle_t hDevice, zet_metric_group_handle_t hMetricGroup,
zet_metric_streamer_desc_t *pDesc, ze_event_handle_t hNotificationEvent,
zet_metric_streamer_handle_t *phMetricStreamer) {
return MetricStreamer::open(hDevice, hMetricGroup, *pDesc, hNotificationEvent, phMetricStreamer);
}
ze_result_t metricTracerOpen(zet_device_handle_t hDevice, zet_metric_group_handle_t hMetricGroup,
zet_metric_tracer_desc_t *pDesc, ze_event_handle_t hNotificationEvent,
zet_metric_tracer_handle_t *phMetricTracer) {
return MetricTracer::open(hDevice, hMetricGroup, *pDesc, hNotificationEvent, phMetricTracer);
zet_metric_streamer_handle_t *phMetricStreamer = reinterpret_cast<zet_metric_streamer_handle_t *>(phMetricTracer);
zet_metric_streamer_desc_t metricStreamerDesc = {};
metricStreamerDesc.notifyEveryNReports = pDesc->notifyEveryNReports;
metricStreamerDesc.samplingPeriod = pDesc->samplingPeriod;
metricStreamerDesc.stype = ZET_STRUCTURE_TYPE_METRIC_STREAMER_DESC;
metricStreamerDesc.pNext = nullptr;
return MetricStreamer::open(hDevice, hMetricGroup, metricStreamerDesc, hNotificationEvent, phMetricStreamer);
}
} // namespace L0

View File

@ -9,10 +9,13 @@
#include "level_zero/core/source/event/event.h"
#include <level_zero/zet_api.h>
#include "third_party/level_zero/zet_api_ext.h"
#include <vector>
struct _zet_metric_group_handle_t {};
struct _zet_metric_handle_t {};
struct _zet_metric_streamer_handle_t {};
struct _zet_metric_tracer_handle_t {};
struct _zet_metric_query_pool_handle_t {};
struct _zet_metric_query_handle_t {};
@ -26,7 +29,7 @@ namespace L0 {
struct MetricsLibrary;
struct CommandList;
struct MetricEnumeration;
struct MetricTracer;
struct MetricStreamer;
struct MetricContext {
virtual ~MetricContext() = default;
@ -38,8 +41,8 @@ struct MetricContext {
virtual Device &getDevice() = 0;
virtual MetricsLibrary &getMetricsLibrary() = 0;
virtual MetricEnumeration &getMetricEnumeration() = 0;
virtual MetricTracer *getMetricTracer() = 0;
virtual void setMetricTracer(MetricTracer *pMetricTracer) = 0;
virtual MetricStreamer *getMetricStreamer() = 0;
virtual void setMetricStreamer(MetricStreamer *pMetricStreamer) = 0;
virtual void setMetricsLibrary(MetricsLibrary &metricsLibrary) = 0;
virtual void setMetricEnumeration(MetricEnumeration &metricEnumeration) = 0;
@ -97,21 +100,29 @@ struct MetricGroup : _zet_metric_group_handle_t {
virtual ze_result_t closeIoStream() = 0;
};
struct MetricTracer : _zet_metric_tracer_handle_t {
virtual ~MetricTracer() = default;
struct MetricStreamer : _zet_metric_streamer_handle_t {
virtual ~MetricStreamer() = default;
virtual ze_result_t readData(uint32_t maxReportCount, size_t *pRawDataSize,
uint8_t *pRawData) = 0;
virtual ze_result_t close() = 0;
static ze_result_t open(zet_device_handle_t hDevice, zet_metric_group_handle_t hMetricGroup,
zet_metric_tracer_desc_t &desc, ze_event_handle_t hNotificationEvent, zet_metric_tracer_handle_t *phMetricTracer);
static MetricTracer *fromHandle(zet_metric_tracer_handle_t handle) {
return static_cast<MetricTracer *>(handle);
zet_metric_streamer_desc_t &desc, ze_event_handle_t hNotificationEvent, zet_metric_streamer_handle_t *phMetricStreamer);
static MetricStreamer *fromHandle(zet_metric_streamer_handle_t handle) {
return static_cast<MetricStreamer *>(handle);
}
virtual Event::State getNotificationState() = 0;
inline zet_metric_tracer_handle_t toHandle() { return this; }
inline zet_metric_streamer_handle_t toHandle() { return this; }
};
struct MetricTracer : _zet_metric_tracer_handle_t {
virtual ~MetricTracer() = default;
static MetricStreamer *fromHandle(zet_metric_tracer_handle_t handle) {
return MetricStreamer::fromHandle(reinterpret_cast<zet_metric_streamer_handle_t>(handle));
}
};
struct MetricQueryPool : _zet_metric_query_pool_handle_t {
@ -134,8 +145,8 @@ struct MetricQuery : _zet_metric_query_handle_t {
virtual ze_result_t appendEnd(CommandList &commandList, ze_event_handle_t hCompletionEvent) = 0;
static ze_result_t appendMemoryBarrier(CommandList &commandList);
static ze_result_t appendTracerMarker(CommandList &commandList,
zet_metric_tracer_handle_t hMetricTracer, uint32_t value);
static ze_result_t appendStreamerMarker(CommandList &commandList,
zet_metric_streamer_handle_t hMetricStreamer, uint32_t value);
virtual ze_result_t getData(size_t *pRawDataSize, uint8_t *pRawData) = 0;
@ -150,7 +161,11 @@ struct MetricQuery : _zet_metric_query_handle_t {
// MetricGroup.
ze_result_t metricGroupGet(zet_device_handle_t hDevice, uint32_t *pCount, zet_metric_group_handle_t *phMetricGroups);
// MetricTracer.
// MetricStreamer.
ze_result_t metricStreamerOpen(zet_device_handle_t hDevice, zet_metric_group_handle_t hMetricGroup,
zet_metric_streamer_desc_t *pDesc, ze_event_handle_t hNotificationEvent,
zet_metric_streamer_handle_t *phMetricStreamer);
ze_result_t metricTracerOpen(zet_device_handle_t hDevice, zet_metric_group_handle_t hMetricGroup,
zet_metric_tracer_desc_t *pDesc, ze_event_handle_t hNotificationEvent,
zet_metric_tracer_handle_t *phMetricTracer);

View File

@ -112,7 +112,7 @@ bool MetricsLibrary::destroyMetricQuery(QueryHandle_1_0 &query) {
}
// Unload metrics library if there are no active queries.
// It will allow to open metric tracer. Query and tracer cannot be used
// It will allow to open metric streamer. Query and streamer cannot be used
// simultaneously since they use the same exclusive resource (oa buffer).
if (queries.size() == 0) {
release();
@ -231,7 +231,7 @@ bool MetricsLibrary::createContext() {
clientOptions[0].Compute.Asynchronous = asyncComputeEngine != asyncComputeEngines.end();
clientOptions[1].Type = ClientOptionsType::Tbs;
clientOptions[1].Tbs.Enabled = metricContext.getMetricTracer() != nullptr;
clientOptions[1].Tbs.Enabled = metricContext.getMetricStreamer() != nullptr;
clientData.Linux.Adapter = &adapter;
clientData.ClientOptions = clientOptions;
@ -382,9 +382,9 @@ ze_result_t metricQueryPoolCreate(zet_device_handle_t hDevice, zet_metric_group_
auto device = Device::fromHandle(hDevice);
auto &metricContext = device->getMetricContext();
// Metric query cannot be used with tracer simultaneously
// Metric query cannot be used with streamer simultaneously
// (due to oa buffer usage constraints).
if (metricContext.getMetricTracer() != nullptr) {
if (metricContext.getMetricStreamer() != nullptr) {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
@ -574,9 +574,9 @@ ze_result_t MetricQuery::appendMemoryBarrier(CommandList &commandList) {
: ZE_RESULT_ERROR_UNKNOWN;
}
ze_result_t MetricQuery::appendTracerMarker(CommandList &commandList,
zet_metric_tracer_handle_t hMetricTracer,
uint32_t value) {
ze_result_t MetricQuery::appendStreamerMarker(CommandList &commandList,
zet_metric_streamer_handle_t hMetricStreamer,
uint32_t value) {
auto &metricContext = commandList.device->getMetricContext();
auto &metricsLibrary = metricContext.getMetricsLibrary();

View File

@ -5,7 +5,7 @@
*
*/
#include "level_zero/tools/source/metrics/metric_tracer_imp.h"
#include "level_zero/tools/source/metrics/metric_streamer_imp.h"
#include "shared/source/helpers/debug_helpers.h"
@ -14,8 +14,8 @@
namespace L0 {
ze_result_t MetricTracerImp::readData(uint32_t maxReportCount, size_t *pRawDataSize,
uint8_t *pRawData) {
ze_result_t MetricStreamerImp::readData(uint32_t maxReportCount, size_t *pRawDataSize,
uint8_t *pRawData) {
DEBUG_BREAK_IF(rawReportSize == 0);
auto metricGroup = MetricGroup::fromHandle(hMetricGroup);
@ -34,7 +34,7 @@ ze_result_t MetricTracerImp::readData(uint32_t maxReportCount, size_t *pRawDataS
// Retrieve the number of reports that fit into the buffer.
uint32_t reportCount = static_cast<uint32_t>(*pRawDataSize / rawReportSize);
// Read tracer data.
// Read streamer data.
const ze_result_t result = metricGroup->readIoStream(reportCount, *pRawData);
if (result == ZE_RESULT_SUCCESS) {
*pRawDataSize = reportCount * rawReportSize;
@ -43,7 +43,7 @@ ze_result_t MetricTracerImp::readData(uint32_t maxReportCount, size_t *pRawDataS
return result;
}
ze_result_t MetricTracerImp::close() {
ze_result_t MetricStreamerImp::close() {
const auto result = stopMeasurements();
if (result == ZE_RESULT_SUCCESS) {
@ -51,28 +51,28 @@ ze_result_t MetricTracerImp::close() {
auto &metricContext = device->getMetricContext();
auto &metricsLibrary = metricContext.getMetricsLibrary();
// Clear metric tracer reference in context.
// Another metric tracer instance or query can be used.
metricContext.setMetricTracer(nullptr);
// Clear metric streamer reference in context.
// Another metric streamer instance or query can be used.
metricContext.setMetricStreamer(nullptr);
// Close metrics library (if was used to generate tracer's marker gpu commands).
// Close metrics library (if was used to generate streamer's marker gpu commands).
// It will allow metric query to use Linux Tbs stream exclusively
// (to activate metric sets and to read context switch reports).
metricsLibrary.release();
// Release notification event.
if (pNotificationEvent != nullptr) {
pNotificationEvent->metricTracer = nullptr;
pNotificationEvent->metricStreamer = nullptr;
}
// Delete metric tracer.
// Delete metric streamer.
delete this;
}
return result;
}
ze_result_t MetricTracerImp::initialize(ze_device_handle_t hDevice,
zet_metric_group_handle_t hMetricGroup) {
ze_result_t MetricStreamerImp::initialize(ze_device_handle_t hDevice,
zet_metric_group_handle_t hMetricGroup) {
this->hDevice = hDevice;
this->hMetricGroup = hMetricGroup;
@ -82,9 +82,9 @@ ze_result_t MetricTracerImp::initialize(ze_device_handle_t hDevice,
return ZE_RESULT_SUCCESS;
}
ze_result_t MetricTracerImp::startMeasurements(uint32_t &notifyEveryNReports,
uint32_t &samplingPeriodNs,
ze_event_handle_t hNotificationEvent) {
ze_result_t MetricStreamerImp::startMeasurements(uint32_t &notifyEveryNReports,
uint32_t &samplingPeriodNs,
ze_event_handle_t hNotificationEvent) {
auto metricGroup = MetricGroup::fromHandle(hMetricGroup);
uint32_t requestedOaBufferSize = getOaBufferSize(notifyEveryNReports);
@ -96,16 +96,16 @@ ze_result_t MetricTracerImp::startMeasurements(uint32_t &notifyEveryNReports,
notifyEveryNReports = getNotifyEveryNReports(requestedOaBufferSize);
}
// Associate notification event with metric tracer.
// Associate notification event with metric streamer.
pNotificationEvent = Event::fromHandle(hNotificationEvent);
if (pNotificationEvent != nullptr) {
pNotificationEvent->metricTracer = this;
pNotificationEvent->metricStreamer = this;
}
return result;
}
ze_result_t MetricTracerImp::stopMeasurements() {
ze_result_t MetricStreamerImp::stopMeasurements() {
auto metricGroup = MetricGroup::fromHandle(hMetricGroup);
const ze_result_t result = metricGroup->closeIoStream();
@ -116,19 +116,19 @@ ze_result_t MetricTracerImp::stopMeasurements() {
return result;
}
uint32_t MetricTracerImp::getOaBufferSize(const uint32_t notifyEveryNReports) const {
uint32_t MetricStreamerImp::getOaBufferSize(const uint32_t notifyEveryNReports) const {
// Notification is on half full buffer, hence multiplication by 2.
return notifyEveryNReports * rawReportSize * 2;
}
uint32_t MetricTracerImp::getNotifyEveryNReports(const uint32_t oaBufferSize) const {
uint32_t MetricStreamerImp::getNotifyEveryNReports(const uint32_t oaBufferSize) const {
// Notification is on half full buffer, hence division by 2.
return rawReportSize
? oaBufferSize / (rawReportSize * 2)
: 0;
}
Event::State MetricTracerImp::getNotificationState() {
Event::State MetricStreamerImp::getNotificationState() {
auto metricGroup = MetricGroup::fromHandle(hMetricGroup);
bool reportsReady = metricGroup->waitForReports(0) == ZE_RESULT_SUCCESS;
@ -138,7 +138,7 @@ Event::State MetricTracerImp::getNotificationState() {
: Event::State::STATE_INITIAL;
}
uint32_t MetricTracerImp::getRequiredBufferSize(const uint32_t maxReportCount) const {
uint32_t MetricStreamerImp::getRequiredBufferSize(const uint32_t maxReportCount) const {
DEBUG_BREAK_IF(rawReportSize == 0);
uint32_t maxOaBufferReportCount = oaBufferSize / rawReportSize;
@ -147,20 +147,20 @@ uint32_t MetricTracerImp::getRequiredBufferSize(const uint32_t maxReportCount) c
: maxReportCount * rawReportSize;
}
ze_result_t MetricTracer::open(zet_device_handle_t hDevice, zet_metric_group_handle_t hMetricGroup,
zet_metric_tracer_desc_t &desc, ze_event_handle_t hNotificationEvent,
zet_metric_tracer_handle_t *phMetricTracer) {
ze_result_t MetricStreamer::open(zet_device_handle_t hDevice, zet_metric_group_handle_t hMetricGroup,
zet_metric_streamer_desc_t &desc, ze_event_handle_t hNotificationEvent,
zet_metric_streamer_handle_t *phMetricStreamer) {
auto pDevice = Device::fromHandle(hDevice);
auto &metricContext = pDevice->getMetricContext();
*phMetricTracer = nullptr;
*phMetricStreamer = nullptr;
// Check whether metric tracer is already open.
if (metricContext.getMetricTracer() != nullptr) {
// Check whether metric streamer is already open.
if (metricContext.getMetricStreamer() != nullptr) {
return ZE_RESULT_ERROR_HANDLE_OBJECT_IN_USE;
}
// Metric tracer cannot be used with query simultaneously
// metric streamer cannot be used with query simultaneously
// (oa buffer cannot be shared).
if (metricContext.getMetricsLibrary().getMetricQueryCount() > 0) {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
@ -177,21 +177,21 @@ ze_result_t MetricTracer::open(zet_device_handle_t hDevice, zet_metric_group_han
return ZE_RESULT_NOT_READY;
}
auto pMetricTracer = new MetricTracerImp();
UNRECOVERABLE_IF(pMetricTracer == nullptr);
pMetricTracer->initialize(hDevice, hMetricGroup);
auto pMetricStreamer = new MetricStreamerImp();
UNRECOVERABLE_IF(pMetricStreamer == nullptr);
pMetricStreamer->initialize(hDevice, hMetricGroup);
const ze_result_t result = pMetricTracer->startMeasurements(
const ze_result_t result = pMetricStreamer->startMeasurements(
desc.notifyEveryNReports, desc.samplingPeriod, hNotificationEvent);
if (result == ZE_RESULT_SUCCESS) {
metricContext.setMetricTracer(pMetricTracer);
metricContext.setMetricStreamer(pMetricStreamer);
} else {
delete pMetricTracer;
pMetricTracer = nullptr;
delete pMetricStreamer;
pMetricStreamer = nullptr;
return ZE_RESULT_ERROR_UNKNOWN;
}
*phMetricTracer = pMetricTracer->toHandle();
*phMetricStreamer = pMetricStreamer->toHandle();
return ZE_RESULT_SUCCESS;
}

View File

@ -13,8 +13,8 @@ struct Event;
namespace L0 {
struct MetricTracerImp : MetricTracer {
~MetricTracerImp() override{};
struct MetricStreamerImp : MetricStreamer {
~MetricStreamerImp() override{};
ze_result_t readData(uint32_t maxReportCount, size_t *pRawDataSize, uint8_t *pRawData) override;
ze_result_t close() override;

View File

@ -12,7 +12,7 @@ target_sources(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/mock_metric_enumeration.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_metric_enumeration.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_metric_query_pool.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_metric_tracer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_metric_streamer.cpp
)
if(UNIX)

File diff suppressed because it is too large Load Diff

View File

@ -1,723 +0,0 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "test.h"
#include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h"
#include "level_zero/core/test/unit_tests/mocks/mock_driver.h"
#include "level_zero/tools/test/unit_tests/sources/metrics/mock_metric.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using ::testing::_;
using ::testing::Return;
namespace L0 {
namespace ult {
using MetricTracerTest = Test<MetricDeviceFixture>;
TEST_F(MetricTracerTest, givenInvalidMetricGroupTypeWhenZetMetricTracerOpenIsCalledThenReturnsFail) {
// One api: device handle.
zet_device_handle_t metricDeviceHandle = device->toHandle();
// One api: event handle.
ze_event_handle_t eventHandle = {};
// One api: tracer handle.
zet_metric_tracer_handle_t tracerHandle = {};
zet_metric_tracer_desc_t tracerDesc = {};
// One api: metric group handle.
Mock<MetricGroup> metricGroup;
zet_metric_group_handle_t metricGroupHandle = metricGroup.toHandle();
zet_metric_group_properties_t metricGroupProperties = {};
metricGroupProperties.samplingType = ZET_METRIC_GROUP_SAMPLING_TYPE_EVENT_BASED;
EXPECT_CALL(metricGroup, getProperties(_))
.Times(1)
.WillOnce(DoAll(::testing::SetArgPointee<0>(metricGroupProperties), Return(ZE_RESULT_SUCCESS)));
// Metric tracer open.
EXPECT_EQ(zetMetricTracerOpen(metricDeviceHandle, metricGroupHandle, &tracerDesc, eventHandle, &tracerHandle), ZE_RESULT_ERROR_INVALID_ARGUMENT);
EXPECT_EQ(tracerHandle, nullptr);
}
TEST_F(MetricTracerTest, givenValidArgumentsWhenZetMetricTracerOpenIsCalledThenReturnsSuccess) {
// One api: device handle.
zet_device_handle_t metricDeviceHandle = device->toHandle();
// One api: event handle.
ze_event_handle_t eventHandle = {};
// One api: tracer handle.
zet_metric_tracer_handle_t tracerHandle = {};
zet_metric_tracer_desc_t tracerDesc = {};
tracerDesc.version = ZET_METRIC_TRACER_DESC_VERSION_CURRENT;
tracerDesc.notifyEveryNReports = 32768;
tracerDesc.samplingPeriod = 1000;
// One api: metric group handle.
Mock<MetricGroup> metricGroup;
zet_metric_group_handle_t metricGroupHandle = metricGroup.toHandle();
zet_metric_group_properties_t metricGroupProperties = {};
// Metrics Discovery device.
metricsDeviceParams.ConcurrentGroupsCount = 1;
// Metrics Discovery concurrent group.
Mock<IConcurrentGroup_1_5> metricsConcurrentGroup;
TConcurrentGroupParams_1_0 metricsConcurrentGroupParams = {};
metricsConcurrentGroupParams.MetricSetsCount = 1;
metricsConcurrentGroupParams.SymbolName = "OA";
metricsConcurrentGroupParams.Description = "OA description";
// Metrics Discovery metric set.
Mock<MetricsDiscovery::IMetricSet_1_5> metricsSet;
MetricsDiscovery::TMetricSetParams_1_4 metricsSetParams = {};
metricsSetParams.ApiMask = MetricsDiscovery::API_TYPE_IOSTREAM;
metricsSetParams.MetricsCount = 0;
metricsSetParams.SymbolName = "Metric set name";
metricsSetParams.ShortName = "Metric set description";
metricsSetParams.RawReportSize = 256;
EXPECT_CALL(*mockMetricEnumeration, loadMetricsDiscovery())
.Times(0);
EXPECT_CALL(*mockMetricEnumeration->g_mockApi, MockOpenMetricsDevice(_))
.Times(1)
.WillOnce(DoAll(::testing::SetArgPointee<0>(&metricsDevice), Return(TCompletionCode::CC_OK)));
EXPECT_CALL(*mockMetricEnumeration->g_mockApi, MockCloseMetricsDevice(_))
.Times(1)
.WillOnce(Return(TCompletionCode::CC_OK));
EXPECT_CALL(metricsDevice, GetParams())
.WillRepeatedly(Return(&metricsDeviceParams));
EXPECT_CALL(metricsDevice, GetConcurrentGroup(_))
.Times(1)
.WillOnce(Return(&metricsConcurrentGroup));
EXPECT_CALL(metricsConcurrentGroup, GetParams())
.Times(1)
.WillRepeatedly(Return(&metricsConcurrentGroupParams));
EXPECT_CALL(metricsConcurrentGroup, GetMetricSet(_))
.WillRepeatedly(Return(&metricsSet));
EXPECT_CALL(metricsSet, GetParams())
.WillRepeatedly(Return(&metricsSetParams));
EXPECT_CALL(metricsSet, SetApiFiltering(_))
.WillRepeatedly(Return(TCompletionCode::CC_OK));
EXPECT_CALL(metricsConcurrentGroup, OpenIoStream(_, _, _, _))
.Times(1)
.WillOnce(Return(TCompletionCode::CC_OK));
EXPECT_CALL(metricsConcurrentGroup, CloseIoStream())
.Times(1)
.WillOnce(Return(TCompletionCode::CC_OK));
// Metric group count.
uint32_t metricGroupCount = 0;
EXPECT_EQ(zetMetricGroupGet(metricDeviceHandle, &metricGroupCount, nullptr), ZE_RESULT_SUCCESS);
EXPECT_EQ(metricGroupCount, 1u);
// Metric group handle.
EXPECT_EQ(zetMetricGroupGet(metricDeviceHandle, &metricGroupCount, &metricGroupHandle), ZE_RESULT_SUCCESS);
EXPECT_EQ(metricGroupCount, 1u);
EXPECT_NE(metricGroupHandle, nullptr);
// Metric group properties.
EXPECT_EQ(zetMetricGroupGetProperties(metricGroupHandle, &metricGroupProperties), ZE_RESULT_SUCCESS);
EXPECT_EQ(metricGroupProperties.domain, 0u);
EXPECT_EQ(metricGroupProperties.samplingType, ZET_METRIC_GROUP_SAMPLING_TYPE_TIME_BASED);
EXPECT_EQ(metricGroupProperties.metricCount, metricsSetParams.MetricsCount);
EXPECT_EQ(strcmp(metricGroupProperties.description, metricsSetParams.ShortName), 0);
EXPECT_EQ(strcmp(metricGroupProperties.name, metricsSetParams.SymbolName), 0);
// Metric group activation.
EXPECT_EQ(zetDeviceActivateMetricGroups(metricDeviceHandle, 1, &metricGroupHandle), ZE_RESULT_SUCCESS);
// Metric tracer open.
EXPECT_EQ(zetMetricTracerOpen(metricDeviceHandle, metricGroupHandle, &tracerDesc, eventHandle, &tracerHandle), ZE_RESULT_SUCCESS);
EXPECT_NE(tracerHandle, nullptr);
// Metric tracer close.
EXPECT_EQ(zetMetricTracerClose(tracerHandle), ZE_RESULT_SUCCESS);
EXPECT_NE(tracerHandle, nullptr);
}
TEST_F(MetricTracerTest, givenInvalidArgumentsWhenZetMetricTracerReadDataIsCalledThenReturnsFail) {
// One api: device handle.
zet_device_handle_t metricDeviceHandle = device->toHandle();
// One api: event handle.
ze_event_handle_t eventHandle = {};
// One api: tracer handle.
zet_metric_tracer_handle_t tracerHandle = {};
zet_metric_tracer_desc_t tracerDesc = {};
tracerDesc.version = ZET_METRIC_TRACER_DESC_VERSION_CURRENT;
tracerDesc.notifyEveryNReports = 32768;
tracerDesc.samplingPeriod = 1000;
// One api: metric group handle.
Mock<MetricGroup> metricGroup;
zet_metric_group_handle_t metricGroupHandle = metricGroup.toHandle();
zet_metric_group_properties_t metricGroupProperties = {};
// Metrics Discovery device.
metricsDeviceParams.ConcurrentGroupsCount = 1;
// Metrics Discovery concurrent group.
Mock<IConcurrentGroup_1_5> metricsConcurrentGroup;
TConcurrentGroupParams_1_0 metricsConcurrentGroupParams = {};
metricsConcurrentGroupParams.MetricSetsCount = 1;
metricsConcurrentGroupParams.SymbolName = "OA";
metricsConcurrentGroupParams.Description = "OA description";
// Metrics Discovery metric set.
Mock<MetricsDiscovery::IMetricSet_1_5> metricsSet;
MetricsDiscovery::TMetricSetParams_1_4 metricsSetParams = {};
metricsSetParams.ApiMask = MetricsDiscovery::API_TYPE_IOSTREAM;
metricsSetParams.MetricsCount = 0;
metricsSetParams.SymbolName = "Metric set name";
metricsSetParams.ShortName = "Metric set description";
metricsSetParams.RawReportSize = 256;
EXPECT_CALL(*mockMetricEnumeration, loadMetricsDiscovery())
.Times(0);
EXPECT_CALL(*mockMetricEnumeration->g_mockApi, MockOpenMetricsDevice(_))
.Times(1)
.WillOnce(DoAll(::testing::SetArgPointee<0>(&metricsDevice), Return(TCompletionCode::CC_OK)));
EXPECT_CALL(*mockMetricEnumeration->g_mockApi, MockCloseMetricsDevice(_))
.Times(1)
.WillOnce(Return(TCompletionCode::CC_OK));
EXPECT_CALL(metricsDevice, GetParams())
.WillRepeatedly(Return(&metricsDeviceParams));
EXPECT_CALL(metricsDevice, GetConcurrentGroup(_))
.Times(1)
.WillOnce(Return(&metricsConcurrentGroup));
EXPECT_CALL(metricsConcurrentGroup, GetParams())
.Times(1)
.WillRepeatedly(Return(&metricsConcurrentGroupParams));
EXPECT_CALL(metricsConcurrentGroup, GetMetricSet(_))
.WillRepeatedly(Return(&metricsSet));
EXPECT_CALL(metricsSet, GetParams())
.WillRepeatedly(Return(&metricsSetParams));
EXPECT_CALL(metricsSet, SetApiFiltering(_))
.WillRepeatedly(Return(TCompletionCode::CC_OK));
EXPECT_CALL(metricsConcurrentGroup, OpenIoStream(_, _, _, _))
.Times(1)
.WillOnce(Return(TCompletionCode::CC_OK));
EXPECT_CALL(metricsConcurrentGroup, CloseIoStream())
.Times(1)
.WillOnce(Return(TCompletionCode::CC_OK));
// Metric group count.
uint32_t metricGroupCount = 0;
EXPECT_EQ(zetMetricGroupGet(metricDeviceHandle, &metricGroupCount, nullptr), ZE_RESULT_SUCCESS);
EXPECT_EQ(metricGroupCount, 1u);
// Metric group handle.
EXPECT_EQ(zetMetricGroupGet(metricDeviceHandle, &metricGroupCount, &metricGroupHandle), ZE_RESULT_SUCCESS);
EXPECT_EQ(metricGroupCount, 1u);
EXPECT_NE(metricGroupHandle, nullptr);
// Metric group properties.
EXPECT_EQ(zetMetricGroupGetProperties(metricGroupHandle, &metricGroupProperties), ZE_RESULT_SUCCESS);
EXPECT_EQ(metricGroupProperties.domain, 0u);
EXPECT_EQ(metricGroupProperties.samplingType, ZET_METRIC_GROUP_SAMPLING_TYPE_TIME_BASED);
EXPECT_EQ(metricGroupProperties.metricCount, metricsSetParams.MetricsCount);
EXPECT_EQ(strcmp(metricGroupProperties.description, metricsSetParams.ShortName), 0);
EXPECT_EQ(strcmp(metricGroupProperties.name, metricsSetParams.SymbolName), 0);
// Metric group activation.
EXPECT_EQ(zetDeviceActivateMetricGroups(metricDeviceHandle, 1, &metricGroupHandle), ZE_RESULT_SUCCESS);
// Metric tracer open.
EXPECT_EQ(zetMetricTracerOpen(metricDeviceHandle, metricGroupHandle, &tracerDesc, eventHandle, &tracerHandle), ZE_RESULT_SUCCESS);
EXPECT_NE(tracerHandle, nullptr);
// Metric tracer close.
EXPECT_EQ(zetMetricTracerClose(tracerHandle), ZE_RESULT_SUCCESS);
}
TEST_F(MetricTracerTest, givenValidArgumentsWhenZetMetricTracerReadDataIsCalledThenReturnsSuccess) {
// One api: device handle.
zet_device_handle_t metricDeviceHandle = device->toHandle();
// One api: event handle.
ze_event_handle_t eventHandle = {};
// One api: tracer handle.
zet_metric_tracer_handle_t tracerHandle = {};
zet_metric_tracer_desc_t tracerDesc = {};
tracerDesc.version = ZET_METRIC_TRACER_DESC_VERSION_CURRENT;
tracerDesc.notifyEveryNReports = 32768;
tracerDesc.samplingPeriod = 1000;
// One api: metric group handle.
Mock<MetricGroup> metricGroup;
zet_metric_group_handle_t metricGroupHandle = metricGroup.toHandle();
zet_metric_group_properties_t metricGroupProperties = {};
// Metrics Discovery device.
metricsDeviceParams.ConcurrentGroupsCount = 1;
// Metrics Discovery concurrent group.
Mock<IConcurrentGroup_1_5> metricsConcurrentGroup;
TConcurrentGroupParams_1_0 metricsConcurrentGroupParams = {};
metricsConcurrentGroupParams.MetricSetsCount = 1;
metricsConcurrentGroupParams.SymbolName = "OA";
metricsConcurrentGroupParams.Description = "OA description";
// Metrics Discovery metric set.
Mock<MetricsDiscovery::IMetricSet_1_5> metricsSet;
MetricsDiscovery::TMetricSetParams_1_4 metricsSetParams = {};
metricsSetParams.ApiMask = MetricsDiscovery::API_TYPE_IOSTREAM;
metricsSetParams.MetricsCount = 0;
metricsSetParams.SymbolName = "Metric set name";
metricsSetParams.ShortName = "Metric set description";
metricsSetParams.RawReportSize = 256;
EXPECT_CALL(*mockMetricEnumeration, loadMetricsDiscovery())
.Times(0);
EXPECT_CALL(*mockMetricEnumeration->g_mockApi, MockOpenMetricsDevice(_))
.Times(1)
.WillOnce(DoAll(::testing::SetArgPointee<0>(&metricsDevice), Return(TCompletionCode::CC_OK)));
EXPECT_CALL(*mockMetricEnumeration->g_mockApi, MockCloseMetricsDevice(_))
.Times(1)
.WillOnce(Return(TCompletionCode::CC_OK));
EXPECT_CALL(metricsDevice, GetParams())
.WillRepeatedly(Return(&metricsDeviceParams));
EXPECT_CALL(metricsDevice, GetConcurrentGroup(_))
.Times(1)
.WillOnce(Return(&metricsConcurrentGroup));
EXPECT_CALL(metricsConcurrentGroup, GetParams())
.Times(1)
.WillRepeatedly(Return(&metricsConcurrentGroupParams));
EXPECT_CALL(metricsConcurrentGroup, GetMetricSet(_))
.WillRepeatedly(Return(&metricsSet));
EXPECT_CALL(metricsSet, GetParams())
.WillRepeatedly(Return(&metricsSetParams));
EXPECT_CALL(metricsSet, SetApiFiltering(_))
.WillRepeatedly(Return(TCompletionCode::CC_OK));
EXPECT_CALL(metricsConcurrentGroup, OpenIoStream(_, _, _, _))
.Times(1)
.WillOnce(Return(TCompletionCode::CC_OK));
EXPECT_CALL(metricsConcurrentGroup, ReadIoStream(_, _, _))
.Times(1)
.WillOnce(Return(TCompletionCode::CC_OK));
EXPECT_CALL(metricsConcurrentGroup, CloseIoStream())
.Times(1)
.WillOnce(Return(TCompletionCode::CC_OK));
// Metric group count.
uint32_t metricGroupCount = 0;
EXPECT_EQ(zetMetricGroupGet(metricDeviceHandle, &metricGroupCount, nullptr), ZE_RESULT_SUCCESS);
EXPECT_EQ(metricGroupCount, 1u);
// Metric group handle.
EXPECT_EQ(zetMetricGroupGet(metricDeviceHandle, &metricGroupCount, &metricGroupHandle), ZE_RESULT_SUCCESS);
EXPECT_EQ(metricGroupCount, 1u);
EXPECT_NE(metricGroupHandle, nullptr);
// Metric group properties.
EXPECT_EQ(zetMetricGroupGetProperties(metricGroupHandle, &metricGroupProperties), ZE_RESULT_SUCCESS);
EXPECT_EQ(metricGroupProperties.domain, 0u);
EXPECT_EQ(metricGroupProperties.samplingType, ZET_METRIC_GROUP_SAMPLING_TYPE_TIME_BASED);
EXPECT_EQ(metricGroupProperties.metricCount, metricsSetParams.MetricsCount);
EXPECT_EQ(strcmp(metricGroupProperties.description, metricsSetParams.ShortName), 0);
EXPECT_EQ(strcmp(metricGroupProperties.name, metricsSetParams.SymbolName), 0);
// Metric group activation.
EXPECT_EQ(zetDeviceActivateMetricGroups(metricDeviceHandle, 1, &metricGroupHandle), ZE_RESULT_SUCCESS);
// Metric tracer open.
EXPECT_EQ(zetMetricTracerOpen(metricDeviceHandle, metricGroupHandle, &tracerDesc, eventHandle, &tracerHandle), ZE_RESULT_SUCCESS);
EXPECT_NE(tracerHandle, nullptr);
// Metric tracer: get desired raw data size.
size_t rawSize = 0;
uint32_t reportCount = 256;
EXPECT_EQ(zetMetricTracerReadData(tracerHandle, reportCount, &rawSize, nullptr), ZE_RESULT_SUCCESS);
// Metric tracer: read the data.
std::vector<uint8_t> rawData;
rawData.resize(rawSize);
EXPECT_EQ(zetMetricTracerReadData(tracerHandle, reportCount, &rawSize, rawData.data()), ZE_RESULT_SUCCESS);
// Metric tracer close.
EXPECT_EQ(zetMetricTracerClose(tracerHandle), ZE_RESULT_SUCCESS);
}
TEST_F(MetricTracerTest, givenInvalidArgumentsWhenZetCommandListAppendMetricTracerMarkerIsCalledThenReturnsFail) {
// One api: device handle.
zet_device_handle_t metricDeviceHandle = device->toHandle();
// One api: event handle.
ze_event_handle_t eventHandle = {};
// One api: tracer handle.
zet_metric_tracer_handle_t tracerHandle = {};
zet_metric_tracer_desc_t tracerDesc = {};
tracerDesc.version = ZET_METRIC_TRACER_DESC_VERSION_CURRENT;
tracerDesc.notifyEveryNReports = 32768;
tracerDesc.samplingPeriod = 1000;
// One api: metric group handle.
Mock<MetricGroup> metricGroup;
zet_metric_group_handle_t metricGroupHandle = metricGroup.toHandle();
zet_metric_group_properties_t metricGroupProperties = {};
// Metrics Discovery device.
metricsDeviceParams.ConcurrentGroupsCount = 1;
// Metrics Discovery concurrent group.
Mock<IConcurrentGroup_1_5> metricsConcurrentGroup;
TConcurrentGroupParams_1_0 metricsConcurrentGroupParams = {};
metricsConcurrentGroupParams.MetricSetsCount = 1;
metricsConcurrentGroupParams.SymbolName = "OA";
metricsConcurrentGroupParams.Description = "OA description";
// Metrics Discovery metric set.
Mock<MetricsDiscovery::IMetricSet_1_5> metricsSet;
MetricsDiscovery::TMetricSetParams_1_4 metricsSetParams = {};
metricsSetParams.ApiMask = MetricsDiscovery::API_TYPE_IOSTREAM;
metricsSetParams.MetricsCount = 0;
metricsSetParams.SymbolName = "Metric set name";
metricsSetParams.ShortName = "Metric set description";
metricsSetParams.RawReportSize = 256;
EXPECT_CALL(*mockMetricEnumeration, loadMetricsDiscovery())
.Times(0);
EXPECT_CALL(*mockMetricEnumeration->g_mockApi, MockOpenMetricsDevice(_))
.Times(1)
.WillOnce(DoAll(::testing::SetArgPointee<0>(&metricsDevice), Return(TCompletionCode::CC_OK)));
EXPECT_CALL(*mockMetricEnumeration->g_mockApi, MockCloseMetricsDevice(_))
.Times(1)
.WillOnce(Return(TCompletionCode::CC_OK));
EXPECT_CALL(metricsDevice, GetParams())
.WillRepeatedly(Return(&metricsDeviceParams));
EXPECT_CALL(metricsDevice, GetConcurrentGroup(_))
.Times(1)
.WillOnce(Return(&metricsConcurrentGroup));
EXPECT_CALL(metricsConcurrentGroup, GetParams())
.Times(1)
.WillRepeatedly(Return(&metricsConcurrentGroupParams));
EXPECT_CALL(metricsConcurrentGroup, GetMetricSet(_))
.WillRepeatedly(Return(&metricsSet));
EXPECT_CALL(metricsSet, GetParams())
.WillRepeatedly(Return(&metricsSetParams));
EXPECT_CALL(metricsSet, SetApiFiltering(_))
.WillRepeatedly(Return(TCompletionCode::CC_OK));
EXPECT_CALL(metricsConcurrentGroup, OpenIoStream(_, _, _, _))
.Times(1)
.WillOnce(Return(TCompletionCode::CC_OK));
EXPECT_CALL(metricsConcurrentGroup, CloseIoStream())
.Times(1)
.WillOnce(Return(TCompletionCode::CC_OK));
// Metric group count.
uint32_t metricGroupCount = 0;
EXPECT_EQ(zetMetricGroupGet(metricDeviceHandle, &metricGroupCount, nullptr), ZE_RESULT_SUCCESS);
EXPECT_EQ(metricGroupCount, 1u);
// Metric group handle.
EXPECT_EQ(zetMetricGroupGet(metricDeviceHandle, &metricGroupCount, &metricGroupHandle), ZE_RESULT_SUCCESS);
EXPECT_EQ(metricGroupCount, 1u);
EXPECT_NE(metricGroupHandle, nullptr);
// Metric group properties.
EXPECT_EQ(zetMetricGroupGetProperties(metricGroupHandle, &metricGroupProperties), ZE_RESULT_SUCCESS);
EXPECT_EQ(metricGroupProperties.domain, 0u);
EXPECT_EQ(metricGroupProperties.samplingType, ZET_METRIC_GROUP_SAMPLING_TYPE_TIME_BASED);
EXPECT_EQ(metricGroupProperties.metricCount, metricsSetParams.MetricsCount);
EXPECT_EQ(strcmp(metricGroupProperties.description, metricsSetParams.ShortName), 0);
EXPECT_EQ(strcmp(metricGroupProperties.name, metricsSetParams.SymbolName), 0);
// Metric group activation.
EXPECT_EQ(zetDeviceActivateMetricGroups(metricDeviceHandle, 1, &metricGroupHandle), ZE_RESULT_SUCCESS);
// Metric tracer open.
EXPECT_EQ(zetMetricTracerOpen(metricDeviceHandle, metricGroupHandle, &tracerDesc, eventHandle, &tracerHandle), ZE_RESULT_SUCCESS);
EXPECT_NE(tracerHandle, nullptr);
// Metric tracer close.
EXPECT_EQ(zetMetricTracerClose(tracerHandle), ZE_RESULT_SUCCESS);
}
TEST_F(MetricTracerTest, givenValidArgumentsWhenZetCommandListAppendMetricTracerMarkerIsCalledThenReturnsSuccess) {
// One api: device handle.
zet_device_handle_t metricDeviceHandle = device->toHandle();
// One api: event handle.
ze_event_handle_t eventHandle = {};
// One api: command list handle
MockCommandList commandList;
// One api: tracer handle.
zet_metric_tracer_handle_t tracerHandle = {};
zet_metric_tracer_desc_t tracerDesc = {};
tracerDesc.version = ZET_METRIC_TRACER_DESC_VERSION_CURRENT;
tracerDesc.notifyEveryNReports = 32768;
tracerDesc.samplingPeriod = 1000;
// One api: metric group handle.
Mock<MetricGroup> metricGroup;
zet_metric_group_handle_t metricGroupHandle = metricGroup.toHandle();
zet_metric_group_properties_t metricGroupProperties = {};
// Metrics Discovery device.
metricsDeviceParams.ConcurrentGroupsCount = 1;
// Metrics Discovery concurrent group.
Mock<IConcurrentGroup_1_5> metricsConcurrentGroup;
TConcurrentGroupParams_1_0 metricsConcurrentGroupParams = {};
metricsConcurrentGroupParams.MetricSetsCount = 1;
metricsConcurrentGroupParams.SymbolName = "OA";
metricsConcurrentGroupParams.Description = "OA description";
// Metrics Discovery metric set.
Mock<MetricsDiscovery::IMetricSet_1_5> metricsSet;
MetricsDiscovery::TMetricSetParams_1_4 metricsSetParams = {};
metricsSetParams.ApiMask = MetricsDiscovery::API_TYPE_IOSTREAM;
metricsSetParams.MetricsCount = 0;
metricsSetParams.SymbolName = "Metric set name";
metricsSetParams.ShortName = "Metric set description";
metricsSetParams.RawReportSize = 256;
EXPECT_CALL(*mockMetricEnumeration, loadMetricsDiscovery())
.Times(0);
EXPECT_CALL(*mockMetricEnumeration->g_mockApi, MockOpenMetricsDevice(_))
.Times(1)
.WillOnce(DoAll(::testing::SetArgPointee<0>(&metricsDevice), Return(TCompletionCode::CC_OK)));
EXPECT_CALL(*mockMetricEnumeration->g_mockApi, MockCloseMetricsDevice(_))
.Times(1)
.WillOnce(Return(TCompletionCode::CC_OK));
EXPECT_CALL(metricsDevice, GetParams())
.WillRepeatedly(Return(&metricsDeviceParams));
EXPECT_CALL(metricsDevice, GetConcurrentGroup(_))
.Times(1)
.WillOnce(Return(&metricsConcurrentGroup));
EXPECT_CALL(metricsConcurrentGroup, GetParams())
.Times(1)
.WillRepeatedly(Return(&metricsConcurrentGroupParams));
EXPECT_CALL(metricsConcurrentGroup, GetMetricSet(_))
.WillRepeatedly(Return(&metricsSet));
EXPECT_CALL(metricsSet, GetParams())
.WillRepeatedly(Return(&metricsSetParams));
EXPECT_CALL(metricsSet, SetApiFiltering(_))
.WillRepeatedly(Return(TCompletionCode::CC_OK));
EXPECT_CALL(metricsConcurrentGroup, OpenIoStream(_, _, _, _))
.Times(1)
.WillOnce(Return(TCompletionCode::CC_OK));
EXPECT_CALL(metricsConcurrentGroup, CloseIoStream())
.Times(1)
.WillOnce(Return(TCompletionCode::CC_OK));
// Metric group count.
uint32_t metricGroupCount = 0;
EXPECT_EQ(zetMetricGroupGet(metricDeviceHandle, &metricGroupCount, nullptr), ZE_RESULT_SUCCESS);
EXPECT_EQ(metricGroupCount, 1u);
// Metric group handle.
EXPECT_EQ(zetMetricGroupGet(metricDeviceHandle, &metricGroupCount, &metricGroupHandle), ZE_RESULT_SUCCESS);
EXPECT_EQ(metricGroupCount, 1u);
EXPECT_NE(metricGroupHandle, nullptr);
// Metric group properties.
EXPECT_EQ(zetMetricGroupGetProperties(metricGroupHandle, &metricGroupProperties), ZE_RESULT_SUCCESS);
EXPECT_EQ(metricGroupProperties.domain, 0u);
EXPECT_EQ(metricGroupProperties.samplingType, ZET_METRIC_GROUP_SAMPLING_TYPE_TIME_BASED);
EXPECT_EQ(metricGroupProperties.metricCount, metricsSetParams.MetricsCount);
EXPECT_EQ(strcmp(metricGroupProperties.description, metricsSetParams.ShortName), 0);
EXPECT_EQ(strcmp(metricGroupProperties.name, metricsSetParams.SymbolName), 0);
// Metric group activation.
EXPECT_EQ(zetDeviceActivateMetricGroups(metricDeviceHandle, 1, &metricGroupHandle), ZE_RESULT_SUCCESS);
// Metric tracer open.
EXPECT_EQ(zetMetricTracerOpen(metricDeviceHandle, metricGroupHandle, &tracerDesc, eventHandle, &tracerHandle), ZE_RESULT_SUCCESS);
EXPECT_NE(tracerHandle, nullptr);
// Metric tracer close.
EXPECT_EQ(zetMetricTracerClose(tracerHandle), ZE_RESULT_SUCCESS);
}
TEST_F(MetricTracerTest, givenMultipleMarkerInsertionsWhenZetCommandListAppendMetricTracerMarkerIsCalledThenReturnsSuccess) {
// One api: device handle.
zet_device_handle_t metricDeviceHandle = device->toHandle();
// One api: event handle.
ze_event_handle_t eventHandle = {};
// One api: command list handle
MockCommandList commandList;
// One api: tracer handle.
zet_metric_tracer_handle_t tracerHandle = {};
zet_metric_tracer_desc_t tracerDesc = {};
tracerDesc.version = ZET_METRIC_TRACER_DESC_VERSION_CURRENT;
tracerDesc.notifyEveryNReports = 32768;
tracerDesc.samplingPeriod = 1000;
// One api: metric group handle.
Mock<MetricGroup> metricGroup;
zet_metric_group_handle_t metricGroupHandle = metricGroup.toHandle();
zet_metric_group_properties_t metricGroupProperties = {};
// Metrics Discovery device.
metricsDeviceParams.ConcurrentGroupsCount = 1;
// Metrics Discovery concurrent group.
Mock<IConcurrentGroup_1_5> metricsConcurrentGroup;
TConcurrentGroupParams_1_0 metricsConcurrentGroupParams = {};
metricsConcurrentGroupParams.MetricSetsCount = 1;
metricsConcurrentGroupParams.SymbolName = "OA";
metricsConcurrentGroupParams.Description = "OA description";
// Metrics Discovery metric set.
Mock<MetricsDiscovery::IMetricSet_1_5> metricsSet;
MetricsDiscovery::TMetricSetParams_1_4 metricsSetParams = {};
metricsSetParams.ApiMask = MetricsDiscovery::API_TYPE_IOSTREAM;
metricsSetParams.MetricsCount = 0;
metricsSetParams.SymbolName = "Metric set name";
metricsSetParams.ShortName = "Metric set description";
metricsSetParams.RawReportSize = 256;
EXPECT_CALL(*mockMetricEnumeration, loadMetricsDiscovery())
.Times(0);
EXPECT_CALL(*mockMetricEnumeration->g_mockApi, MockOpenMetricsDevice(_))
.Times(1)
.WillOnce(DoAll(::testing::SetArgPointee<0>(&metricsDevice), Return(TCompletionCode::CC_OK)));
EXPECT_CALL(*mockMetricEnumeration->g_mockApi, MockCloseMetricsDevice(_))
.Times(1)
.WillOnce(Return(TCompletionCode::CC_OK));
EXPECT_CALL(metricsDevice, GetParams())
.WillRepeatedly(Return(&metricsDeviceParams));
EXPECT_CALL(metricsDevice, GetConcurrentGroup(_))
.Times(1)
.WillOnce(Return(&metricsConcurrentGroup));
EXPECT_CALL(metricsConcurrentGroup, GetParams())
.Times(1)
.WillRepeatedly(Return(&metricsConcurrentGroupParams));
EXPECT_CALL(metricsConcurrentGroup, GetMetricSet(_))
.WillRepeatedly(Return(&metricsSet));
EXPECT_CALL(metricsSet, GetParams())
.WillRepeatedly(Return(&metricsSetParams));
EXPECT_CALL(metricsSet, SetApiFiltering(_))
.WillRepeatedly(Return(TCompletionCode::CC_OK));
EXPECT_CALL(metricsConcurrentGroup, OpenIoStream(_, _, _, _))
.Times(1)
.WillOnce(Return(TCompletionCode::CC_OK));
EXPECT_CALL(metricsConcurrentGroup, CloseIoStream())
.Times(1)
.WillOnce(Return(TCompletionCode::CC_OK));
// Metric group count.
uint32_t metricGroupCount = 0;
EXPECT_EQ(zetMetricGroupGet(metricDeviceHandle, &metricGroupCount, nullptr), ZE_RESULT_SUCCESS);
EXPECT_EQ(metricGroupCount, 1u);
// Metric group handle.
EXPECT_EQ(zetMetricGroupGet(metricDeviceHandle, &metricGroupCount, &metricGroupHandle), ZE_RESULT_SUCCESS);
EXPECT_EQ(metricGroupCount, 1u);
EXPECT_NE(metricGroupHandle, nullptr);
// Metric group properties.
EXPECT_EQ(zetMetricGroupGetProperties(metricGroupHandle, &metricGroupProperties), ZE_RESULT_SUCCESS);
EXPECT_EQ(metricGroupProperties.domain, 0u);
EXPECT_EQ(metricGroupProperties.samplingType, ZET_METRIC_GROUP_SAMPLING_TYPE_TIME_BASED);
EXPECT_EQ(metricGroupProperties.metricCount, metricsSetParams.MetricsCount);
EXPECT_EQ(strcmp(metricGroupProperties.description, metricsSetParams.ShortName), 0);
EXPECT_EQ(strcmp(metricGroupProperties.name, metricsSetParams.SymbolName), 0);
// Metric group activation.
EXPECT_EQ(zetDeviceActivateMetricGroups(metricDeviceHandle, 1, &metricGroupHandle), ZE_RESULT_SUCCESS);
// Metric tracer open.
EXPECT_EQ(zetMetricTracerOpen(metricDeviceHandle, metricGroupHandle, &tracerDesc, eventHandle, &tracerHandle), ZE_RESULT_SUCCESS);
EXPECT_NE(tracerHandle, nullptr);
// Metric tracer close.
EXPECT_EQ(zetMetricTracerClose(tracerHandle), ZE_RESULT_SUCCESS);
}
} // namespace ult
} // namespace L0

View File

@ -921,6 +921,8 @@ zeCommandListCreateImmediateExt(
ze_command_list_handle_t *phCommandList ///< [out] pointer to handle of command list object created
);
} //extern C
#if defined(__cplusplus)
} // extern "C"
#endif
#endif // _ZE_API_EXT_H

173
third_party/level_zero/zet_api_ext.h vendored Normal file
View File

@ -0,0 +1,173 @@
/*
*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*
*/
#ifndef _ZET_API_EXT_H
#define _ZET_API_EXT_H
#if defined(__cplusplus)
#pragma once
#endif
// standard headers
#include "third_party/level_zero/ze_api_ext.h"
#include <stddef.h>
#include <stdint.h>
#if defined(__cplusplus)
extern "C" {
#endif
// Intel 'oneAPI' Level-Zero Tool API common types
///////////////////////////////////////////////////////////////////////////////
/// @brief Handle of metric streamer's object
typedef struct _zet_metric_streamer_handle_t *zet_metric_streamer_handle_t;
///////////////////////////////////////////////////////////////////////////////
/// @brief Defines structure types
typedef enum _zet_structure_type_t {
ZET_STRUCTURE_TYPE_METRIC_GROUP_PROPERTIES = 0x1, ///< ::zet_metric_group_properties_t
ZET_STRUCTURE_TYPE_METRIC_PROPERTIES = 0x2, ///< ::zet_metric_properties_t
ZET_STRUCTURE_TYPE_METRIC_STREAMER_DESC = 0x3, ///< ::zet_metric_streamer_desc_t
ZET_STRUCTURE_TYPE_METRIC_QUERY_POOL_DESC = 0x4, ///< ::zet_metric_query_pool_desc_t
ZET_STRUCTURE_TYPE_PROFILE_PROPERTIES = 0x5, ///< ::zet_profile_properties_t
ZET_STRUCTURE_TYPE_DEVICE_DEBUG_PROPERTIES = 0x6, ///< ::zet_device_debug_properties_t
ZET_STRUCTURE_TYPE_DEBUG_MEMORY_SPACE_DESC = 0x7, ///< ::zet_debug_memory_space_desc_t
ZET_STRUCTURE_TYPE_DEBUG_REGSET_PROPERTIES = 0x8, ///< ::zet_debug_regset_properties_t
ZET_STRUCTURE_TYPE_TRACER_EXP_DESC = 0x00010001, ///< ::zet_tracer_exp_desc_t
ZET_STRUCTURE_TYPE_FORCE_UINT32 = 0x7fffffff
} zet_structure_type_t;
///////////////////////////////////////////////////////////////////////////////
/// @brief Forward-declare zet_metric_streamer_desc_t
typedef struct _zet_metric_streamer_desc_t zet_metric_streamer_desc_t;
///////////////////////////////////////////////////////////////////////////////
/// @brief Metric streamer descriptor
typedef struct _zet_metric_streamer_desc_t {
zet_structure_type_t stype; ///< [in] type of this structure
const void *pNext; ///< [in][optional] pointer to extension-specific structure
uint32_t notifyEveryNReports; ///< [in,out] number of collected reports after which notification event
///< will be signalled
uint32_t samplingPeriod; ///< [in,out] streamer sampling period in nanoseconds
} zet_metric_streamer_desc_t;
///////////////////////////////////////////////////////////////////////////////
/// @brief Opens metric streamer for a device.
///
/// @details
/// - The notification event must have been created from an event pool that
/// was created using ::ZE_EVENT_POOL_FLAG_HOST_VISIBLE flag.
/// - The notification event must **not** have been created from an event
/// pool that was created using ::ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP
/// flag.
/// - The application must **not** call this function from simultaneous
/// threads with the same device handle.
///
/// @returns
/// - ::ZE_RESULT_SUCCESS
/// - ::ZE_RESULT_ERROR_UNINITIALIZED
/// - ::ZE_RESULT_ERROR_DEVICE_LOST
/// - ::ZE_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `nullptr == hContext`
/// + `nullptr == hDevice`
/// + `nullptr == hMetricGroup`
/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER
/// + `nullptr == desc`
/// + `nullptr == phMetricStreamer`
/// - ::ZE_RESULT_ERROR_INVALID_SYNCHRONIZATION_OBJECT
ZE_APIEXPORT ze_result_t ZE_APICALL
zetMetricStreamerOpen(
zet_device_handle_t hDevice, ///< [in] handle of the device
zet_metric_group_handle_t hMetricGroup, ///< [in] handle of the metric group
zet_metric_streamer_desc_t *desc, ///< [in,out] metric streamer descriptor
ze_event_handle_t hNotificationEvent, ///< [in][optional] event used for report availability notification
zet_metric_streamer_handle_t *phMetricStreamer ///< [out] handle of metric streamer
);
///////////////////////////////////////////////////////////////////////////////
/// @brief Append metric streamer marker into a command list.
///
/// @details
/// - The application must ensure the metric streamer is accessible by the
/// device on which the command list was created.
/// - The application must ensure the command list and metric streamer were
/// created on the same context.
/// - The application must **not** call this function from simultaneous
/// threads with the same command list handle.
/// - Allow to associate metric stream time based metrics with executed
/// workload.
///
/// @returns
/// - ::ZE_RESULT_SUCCESS
/// - ::ZE_RESULT_ERROR_UNINITIALIZED
/// - ::ZE_RESULT_ERROR_DEVICE_LOST
/// - ::ZE_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `nullptr == hCommandList`
/// + `nullptr == hMetricStreamer`
ZE_APIEXPORT ze_result_t ZE_APICALL
zetCommandListAppendMetricStreamerMarker(
zet_command_list_handle_t hCommandList, ///< [in] handle of the command list
zet_metric_streamer_handle_t hMetricStreamer, ///< [in] handle of the metric streamer
uint32_t value ///< [in] streamer marker value
);
///////////////////////////////////////////////////////////////////////////////
/// @brief Closes metric streamer.
///
/// @details
/// - The application must **not** call this function from simultaneous
/// threads with the same metric streamer handle.
///
/// @returns
/// - ::ZE_RESULT_SUCCESS
/// - ::ZE_RESULT_ERROR_UNINITIALIZED
/// - ::ZE_RESULT_ERROR_DEVICE_LOST
/// - ::ZE_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `nullptr == hMetricStreamer`
ZE_APIEXPORT ze_result_t ZE_APICALL
zetMetricStreamerClose(
zet_metric_streamer_handle_t hMetricStreamer ///< [in][release] handle of the metric streamer
);
///////////////////////////////////////////////////////////////////////////////
/// @brief Reads data from metric streamer.
///
/// @details
/// - The application may call this function from simultaneous threads.
///
/// @returns
/// - ::ZE_RESULT_SUCCESS
/// - ::ZE_RESULT_ERROR_UNINITIALIZED
/// - ::ZE_RESULT_ERROR_DEVICE_LOST
/// - ::ZE_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `nullptr == hMetricStreamer`
/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER
/// + `nullptr == pRawDataSize`
ZE_APIEXPORT ze_result_t ZE_APICALL
zetMetricStreamerReadData(
zet_metric_streamer_handle_t hMetricStreamer, ///< [in] handle of the metric streamer
uint32_t maxReportCount, ///< [in] the maximum number of reports the application wants to receive.
///< if UINT32_MAX, then function will retrieve all reports available
size_t *pRawDataSize, ///< [in,out] pointer to size in bytes of raw data requested to read.
///< if size is zero, then the driver will update the value with the total
///< size in bytes needed for all reports available.
///< if size is non-zero, then driver will only retrieve the number of
///< reports that fit into the buffer.
///< if size is larger than size needed for all reports, then driver will
///< update the value with the actual size needed.
uint8_t *pRawData ///< [in,out][optional][range(0, *pRawDataSize)] buffer containing streamer
///< reports in raw format
);
#if defined(__cplusplus)
} // extern "C"
#endif
#endif // _ZET_API_EXT_H