Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
330 changes: 3 additions & 327 deletions conformance_tests/tools/metrics/src/test_metric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1588,336 +1588,12 @@ LZT_TEST_F(
}
}

void metric_validate_stall_sampling_data(
std::vector<zet_metric_properties_t> &metricProperties,
std::vector<zet_typed_value_t> &totalMetricValues,
std::vector<uint32_t> &metricValueSets) {

uint32_t activeOffset = UINT32_MAX;
uint32_t controlStallOffset = UINT32_MAX;
uint32_t pipeStallOffset = UINT32_MAX;
uint32_t sendStallOffset = UINT32_MAX;
uint32_t distStallOffset = UINT32_MAX;
uint32_t sbidStallOffset = UINT32_MAX;
uint32_t syncStallOffset = UINT32_MAX;
uint32_t instrFetchStallOffset = UINT32_MAX;
uint32_t otherStallOffset = UINT32_MAX;

for (size_t i = 0; i < metricProperties.size(); i++) {

if (strcmp("Active", metricProperties[i].name) == 0) {
activeOffset = i;
continue;
}
if (strcmp("ControlStall", metricProperties[i].name) == 0) {
controlStallOffset = i;
continue;
}
if (strcmp("PipeStall", metricProperties[i].name) == 0) {
pipeStallOffset = i;
continue;
}
if (strcmp("SendStall", metricProperties[i].name) == 0) {
sendStallOffset = i;
continue;
}
if (strcmp("DistStall", metricProperties[i].name) == 0) {
distStallOffset = i;
continue;
}
if (strcmp("SbidStall", metricProperties[i].name) == 0) {
sbidStallOffset = i;
continue;
}
if (strcmp("SyncStall", metricProperties[i].name) == 0) {
syncStallOffset = i;
continue;
}
if (strcmp("InstrFetchStall", metricProperties[i].name) == 0) {
instrFetchStallOffset = i;
continue;
}
if (strcmp("OtherStall", metricProperties[i].name) == 0) {
otherStallOffset = i;
continue;
}
}

uint32_t ActiveCount = 0;
uint32_t ControlStallCount = 0;
uint32_t PipeStallCount = 0;
uint32_t SendStallCount = 0;
uint32_t DistStallCount = 0;
uint32_t SbidStallCount = 0;
uint32_t SyncStallCount = 0;
uint32_t InstrFetchStallCount = 0;
uint32_t OtherStallCount = 0;

uint32_t metricSetStartIndex = 0;

EXPECT_GT(metricValueSets.size(), 0u);
for (uint32_t metricValueSetIndex = 0;
metricValueSetIndex < metricValueSets.size(); metricValueSetIndex++) {

const uint32_t metricCountForDataIndex =
metricValueSets[metricValueSetIndex];
const uint32_t reportCount =
metricCountForDataIndex / metricProperties.size();

LOG_INFO << "for metricValueSetIndex " << metricValueSetIndex
<< " metricCountForDataIndex " << metricCountForDataIndex
<< " reportCount " << reportCount;

EXPECT_GT(reportCount, 1);

uint32_t tmpStallCount;
bool reportCompleteFlag;

for (uint32_t report = 0; report < reportCount; report++) {

tmpStallCount = 0;
reportCompleteFlag = false;

auto getStallCount = [&totalMetricValues](uint32_t metricReport,
uint32_t metricPropertiesSize,
uint32_t metricOffset,
uint32_t metricStartIndex) {
uint32_t metricIndex =
metricReport * metricPropertiesSize + metricOffset;
zet_typed_value_t metricTypedValue =
totalMetricValues[metricStartIndex + metricIndex];
uint64_t metricValue = metricTypedValue.value.ui64;
return metricValue;
};

tmpStallCount = getStallCount(report, metricProperties.size(),
activeOffset, metricSetStartIndex);
reportCompleteFlag |= (tmpStallCount != 0);
ActiveCount += tmpStallCount;

tmpStallCount = getStallCount(report, metricProperties.size(),
controlStallOffset, metricSetStartIndex);
reportCompleteFlag |= (tmpStallCount != 0);
ControlStallCount += tmpStallCount;

tmpStallCount = getStallCount(report, metricProperties.size(),
pipeStallOffset, metricSetStartIndex);
reportCompleteFlag |= (tmpStallCount != 0);
PipeStallCount += tmpStallCount;

tmpStallCount = getStallCount(report, metricProperties.size(),
sendStallOffset, metricSetStartIndex);
reportCompleteFlag |= (tmpStallCount != 0);
SendStallCount += tmpStallCount;

tmpStallCount = getStallCount(report, metricProperties.size(),
distStallOffset, metricSetStartIndex);
reportCompleteFlag |= (tmpStallCount != 0);
DistStallCount += tmpStallCount;

tmpStallCount = getStallCount(report, metricProperties.size(),
sbidStallOffset, metricSetStartIndex);
reportCompleteFlag |= (tmpStallCount != 0);
SbidStallCount += tmpStallCount;

tmpStallCount = getStallCount(report, metricProperties.size(),
syncStallOffset, metricSetStartIndex);
reportCompleteFlag |= (tmpStallCount != 0);
SyncStallCount += tmpStallCount;

tmpStallCount = getStallCount(report, metricProperties.size(),
instrFetchStallOffset, metricSetStartIndex);
reportCompleteFlag |= (tmpStallCount != 0);
InstrFetchStallCount += tmpStallCount;

tmpStallCount = getStallCount(report, metricProperties.size(),
otherStallOffset, metricSetStartIndex);
reportCompleteFlag |= (tmpStallCount != 0);
OtherStallCount += tmpStallCount;

EXPECT_TRUE(reportCompleteFlag)
<< "Report number " << report << " has zero for all stall counts";
}

metricSetStartIndex += metricCountForDataIndex;
}

LOG_DEBUG << "ActiveCount " << ActiveCount;
LOG_DEBUG << "ControlStallCount " << ControlStallCount;
LOG_DEBUG << "PipeStallCount " << PipeStallCount;
LOG_DEBUG << "SendStallCount " << SendStallCount;
LOG_DEBUG << "DistStallCount " << DistStallCount;
LOG_DEBUG << "SbidStallCount " << SbidStallCount;
LOG_DEBUG << "SyncStallCount " << SyncStallCount;
LOG_DEBUG << "InstrFetchStallCount " << InstrFetchStallCount;
LOG_DEBUG << "OtherStallCount " << OtherStallCount;
}

void run_ip_sampling_with_validation(
bool enableOverflow, const std::vector<ze_device_handle_t> &devices,
uint32_t notifyEveryNReports, uint32_t samplingPeriod,
uint32_t timeForNReportsComplete) {

uint32_t numberOfFunctionCalls;
if (enableOverflow) {
numberOfFunctionCalls = 8;
} else {
numberOfFunctionCalls = 1;
}

typedef struct _function_data {
ze_kernel_handle_t function;
ze_group_count_t tg;
void *a_buffer, *b_buffer, *c_buffer;
} function_data_t;

std::vector<function_data_t> functionDataBuf(numberOfFunctionCalls);

for (auto device : devices) {

ze_device_properties_t deviceProperties = {
ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES, nullptr};
zeDeviceGetProperties(device, &deviceProperties);

LOG_INFO << "test device name " << deviceProperties.name << " uuid "
<< lzt::to_string(deviceProperties.uuid);
if (deviceProperties.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE) {
LOG_INFO << "test subdevice id " << deviceProperties.subdeviceId;
} else {
LOG_INFO << "test device is a root device";
}

ze_command_queue_handle_t commandQueue = lzt::create_command_queue(device);
zet_command_list_handle_t commandList = lzt::create_command_list(device);

auto metricGroupInfo = lzt::get_metric_type_ip_group_info(
device, ZET_METRIC_GROUP_SAMPLING_TYPE_FLAG_TIME_BASED);
if (metricGroupInfo.size() == 0) {
GTEST_SKIP()
<< "No IP metric groups are available to test on this platform";
}
metricGroupInfo = lzt::optimize_metric_group_info_list(metricGroupInfo);

for (auto groupInfo : metricGroupInfo) {

LOG_INFO << "test metricGroup name " << groupInfo.metricGroupName;

lzt::activate_metric_groups(device, 1, &groupInfo.metricGroupHandle);

ze_event_handle_t eventHandle;
lzt::zeEventPool eventPool;
eventPool.create_event(eventHandle, ZE_EVENT_SCOPE_FLAG_HOST,
ZE_EVENT_SCOPE_FLAG_HOST);

for (auto &fData : functionDataBuf) {
fData.function = get_matrix_multiplication_kernel(
device, &fData.tg, &fData.a_buffer, &fData.b_buffer,
&fData.c_buffer, 8192);
zeCommandListAppendLaunchKernel(commandList, fData.function, &fData.tg,
nullptr, 0, nullptr);
}

lzt::close_command_list(commandList);
std::chrono::steady_clock::time_point startTime =
std::chrono::steady_clock::now();

zet_metric_streamer_handle_t metricStreamerHandle =
lzt::metric_streamer_open_for_device(
device, groupInfo.metricGroupHandle, eventHandle,
notifyEveryNReports, samplingPeriod);
ASSERT_NE(nullptr, metricStreamerHandle);

lzt::execute_command_lists(commandQueue, 1, &commandList, nullptr);
lzt::synchronize(commandQueue, std::numeric_limits<uint64_t>::max());

std::chrono::steady_clock::time_point endTime =
std::chrono::steady_clock::now();
uint64_t elapsedTime =
std::chrono::duration_cast<std::chrono::nanoseconds>(endTime -
startTime)
.count();

LOG_INFO << "elapsed time for workload completion " << elapsedTime
<< " time for NReports to complete " << timeForNReportsComplete;
if (elapsedTime < timeForNReportsComplete) {
LOG_WARNING << "elapsed time for workload completion is too short";
}

const char *sleep_in_buffer_overflow_test_environment_variable =
std::getenv("LZT_METRICS_BUFFER_OVERFLOW_SLEEP_MS");

if (sleep_in_buffer_overflow_test_environment_variable != nullptr) {
uint32_t value =
atoi(sleep_in_buffer_overflow_test_environment_variable);
std::this_thread::sleep_for(std::chrono::milliseconds(value));
}

size_t rawDataSize = 0;
std::vector<uint8_t> rawData;
rawDataSize = lzt::metric_streamer_read_data_size(metricStreamerHandle,
notifyEveryNReports);
EXPECT_GT(rawDataSize, 0);
rawData.resize(rawDataSize);
lzt::metric_streamer_read_data(metricStreamerHandle, notifyEveryNReports,
rawDataSize, &rawData);
lzt::validate_metrics(groupInfo.metricGroupHandle, rawDataSize,
rawData.data(), false);
rawData.resize(rawDataSize);

std::vector<zet_typed_value_t> metricValues;
std::vector<uint32_t> metricValueSets;
ze_result_t result =
level_zero_tests::metric_calculate_metric_values_from_raw_data(
groupInfo.metricGroupHandle, rawData, metricValues,
metricValueSets);

if (enableOverflow) {
ASSERT_EQ(ZE_RESULT_WARNING_DROPPED_DATA, result);
} else {
ASSERT_ZE_RESULT_SUCCESS(result);
}

std::vector<zet_metric_handle_t> metricHandles;
lzt::metric_get_metric_handles_from_metric_group(
groupInfo.metricGroupHandle, metricHandles);
std::vector<zet_metric_properties_t> metricProperties(
metricHandles.size());
lzt::metric_get_metric_properties_for_metric_group(metricHandles,
metricProperties);

metric_validate_stall_sampling_data(metricProperties, metricValues,
metricValueSets);

lzt::metric_streamer_close(metricStreamerHandle);
lzt::deactivate_metric_groups(device);

for (auto &fData : functionDataBuf) {
lzt::destroy_function(fData.function);
lzt::free_memory(fData.a_buffer);
lzt::free_memory(fData.b_buffer);
lzt::free_memory(fData.c_buffer);
}

eventPool.destroy_event(eventHandle);
lzt::reset_command_list(commandList);
}
lzt::destroy_command_queue(commandQueue);
lzt::destroy_command_list(commandList);
}
}

LZT_TEST_F(
zetMetricStreamerTest,
GivenValidTypeIpMetricGroupWhenTimerBasedStreamerIsCreatedAndOverflowTriggeredThenExpectStreamerValidateError) {
run_ip_sampling_with_validation(true, devices, notifyEveryNReports,
samplingPeriod, TimeForNReportsComplete);
}

LZT_TEST_F(
zetMetricStreamerTest,
GivenValidTypeIpMetricGroupWhenTimerBasedStreamerIsCreatedWithNoOverflowThenValidateStallSampleData) {
run_ip_sampling_with_validation(false, devices, notifyEveryNReports,
samplingPeriod, TimeForNReportsComplete);
metric_run_ip_sampling_with_validation(false, devices, notifyEveryNReports,
samplingPeriod,
TimeForNReportsComplete);
}

LZT_TEST_F(
Expand Down
Loading
Loading