Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Added a new test to accurately check streamer event generation #107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
106 changes: 103 additions & 3 deletions conformance_tests/tools/metrics/src/test_metric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,11 @@ TEST_F(
for (auto &test_metric_group : test_metric_groups) {

lzt::activate_metric_groups(deviceh, 1, &test_metric_group);
uint32_t notifyEveryNReports = 100;
uint32_t samplingPeriod = 100000;
zet_metric_streamer_handle_t metric_streamer_handle =
lzt::metric_streamer_open_for_device(deviceh, test_metric_group,
nullptr, 100, 100000);
nullptr, notifyEveryNReports, samplingPeriod);
auto report_size =
lzt::metric_streamer_read_data_size(metric_streamer_handle, 1);
lzt::metric_streamer_close(metric_streamer_handle);
Expand Down Expand Up @@ -1231,6 +1233,7 @@ TEST_F(
zetMetricStreamerTest,
GivenValidMetricGroupWhenTimerBasedStreamerIsCreatedThenExpectStreamerToSucceed) {

notifyEveryNReports = 9000;
for (auto device : devices) {

ze_device_properties_t deviceProperties = {
Expand Down Expand Up @@ -1321,6 +1324,103 @@ TEST_F(
}
}

TEST_F(
zetMetricStreamerTest,
GivenValidMetricGroupWhenTimerBasedStreamerIsCreatedThenExpectStreamerToNotifyEventAtProperTimeAndSucceed) {

uint32_t notifyEveryNReports = 1000;
uint32_t samplingPeriod = 50000000;
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_group_info(
device, ZET_METRIC_GROUP_SAMPLING_TYPE_FLAG_TIME_BASED, true);
metricGroupInfo = lzt::optimize_metric_group_info_list(metricGroupInfo);

for (auto groupInfo : metricGroupInfo) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this test validated for EU stall ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is validated on PVC

gta@DUT7267PVC:~/cts/out$ sudo LZT_METRIC_GROUPS_TEST_SPECIFIC=EuStallSampling LD_LIBRARY_PATH=/home/gta/loader/build/lib:/home/gta/notify/neo/build/bin/:/home/gta/notify/gmmlib/lib:/home/gta/notify/igc/lib:/home/gta/notify/metrics/discovery/lib:/home/gta/notify/metrics/library/lib ./test_metric --gtest_filter="*GivenValidMetricGroupWhenTimerBasedStreamerIsCreatedThenExpectStre
amerToNotifyEventAtProperTimeAndSucceed*"
Note: Google Test filter = *GivenValidMetricGroupWhenTimerBasedStreamerIsCreatedThenExpectStreamerToNotifyEventAtProperTimeAndSucceed*
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from zetMetricStreamerTest
[ RUN      ] zetMetricStreamerTest.GivenValidMetricGroupWhenTimerBasedStreamerIsCreatedThenExpectStreamerToNotifyEventAtProperTimeAndSucceed
[2024-11-15 09:11:00] [info] Default Driver retrieved at index 0
[2024-11-15 09:11:00] [info] Default Device retrieved at index 0
[2024-11-15 09:11:00] [info] test device name Intel(R) Data Center GPU Max 1550 uuid 01000000-0000-0000-928d-55ba7d1b5d52
[2024-11-15 09:11:00] [info] test device is a root device
[2024-11-15 09:11:00] [info] specific group EuStallSampling
[2024-11-15 09:11:00] [info] specific name push_back EuStallSampling
[2024-11-15 09:11:00] [info] test metricGroup name EuStallSampling
[2024-11-15 09:11:08] [info] minimumTimeBeforeEventIsExpected 0.14056
[2024-11-15 09:11:08] [info] errorBuffer 0.007028
[2024-11-15 09:11:08] [info] additional sleep before expecting event to be ready 1
[       OK ] zetMetricStreamerTest.GivenValidMetricGroupWhenTimerBasedStreamerIsCreatedThenExpectStreamerToNotifyEventAtProperTimeAndSucceed (8903 ms)
[----------] 1 test from zetMetricStreamerTest (8903 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (8903 ms total)
[  PASSED  ] 1 test.


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);

void *a_buffer, *b_buffer, *c_buffer;
ze_group_count_t tg;
ze_kernel_handle_t function = get_matrix_multiplication_kernel(
device, &tg, &a_buffer, &b_buffer, &c_buffer, 8192);
zeCommandListAppendLaunchKernel(commandList, function, &tg, nullptr, 0,
nullptr);

lzt::close_command_list(commandList);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the above till 1360 could be moved outside the loop


auto startTime = std::chrono::system_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());

double minimumTimeBeforeEventIsExpected = notifyEveryNReports * (static_cast<double>(samplingPeriod) / 1000000000);
// Initializing a 5% error buffer to prevent corner cases
double errorBuffer = 0.05 * minimumTimeBeforeEventIsExpected;
LOG_INFO << "minimumTimeBeforeEventIsExpected " << minimumTimeBeforeEventIsExpected;
LOG_INFO << "errorBuffer " << errorBuffer;

ze_result_t eventResult;
while (true) {
auto currentTime = std::chrono::system_clock::now();
std::chrono::duration<double> elapsedSeconds = currentTime - startTime;
if (elapsedSeconds.count() >= (minimumTimeBeforeEventIsExpected - errorBuffer)) {
break;
}
eventResult = zeEventQueryStatus(eventHandle);
EXPECT_EQ(eventResult, ZE_RESULT_NOT_READY);
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}

// Sleep again for 2x the buffer time to ensure corner cases are avoided. 2x is the amount to maintain the timeline itself.
uint32_t sleep = std::ceil(2 * errorBuffer);
LOG_INFO << "additional sleep before expecting event to be ready " << sleep;
std::this_thread::sleep_for(std::chrono::seconds(sleep));

eventResult = zeEventQueryStatus(eventHandle);
EXPECT_EQ(eventResult, ZE_RESULT_SUCCESS);

lzt::metric_streamer_close(metricStreamerHandle);
lzt::deactivate_metric_groups(device);
lzt::destroy_function(function);
lzt::free_memory(a_buffer);
lzt::free_memory(b_buffer);
lzt::free_memory(c_buffer);
eventPool.destroy_event(eventHandle);
lzt::reset_command_list(commandList);
}
lzt::destroy_command_queue(commandQueue);
lzt::destroy_command_list(commandList);
}
}

void metric_validate_stall_sampling_data(
std::vector<zet_metric_properties_t> &metricProperties,
std::vector<zet_typed_value_t> &totalMetricValues,
Expand Down Expand Up @@ -2330,8 +2430,8 @@ void run_multi_device_streamer_test(
eventPool.create_event(eventHandle_1, ZE_EVENT_SCOPE_FLAG_HOST,
ZE_EVENT_SCOPE_FLAG_HOST);

auto notifyEveryNReports = 3000;
auto samplingPeriod = 1000000;
uint32_t notifyEveryNReports = 3000;
uint32_t samplingPeriod = 1000000;
auto metricStreamerHandle_0 = lzt::metric_streamer_open_for_device(
device_0, groupInfo_0.metricGroupHandle, eventHandle_0,
notifyEveryNReports, samplingPeriod);
Expand Down
4 changes: 2 additions & 2 deletions utils/test_harness/tools/include/test_harness_metric.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ void metric_query_get_data(zet_metric_query_handle_t metricQueryHandle,
std::vector<uint8_t> *metricData);
zet_metric_streamer_handle_t metric_streamer_open_for_device(
ze_device_handle_t device, zet_metric_group_handle_t matchedGroupHandle,
ze_event_handle_t eventHandle, uint32_t notifyEveryNReports,
uint32_t samplingPeriod);
ze_event_handle_t eventHandle, uint32_t &notifyEveryNReports,
uint32_t &samplingPeriod);
zet_metric_streamer_handle_t
metric_streamer_open(zet_metric_group_handle_t matchedGroupHandle,
ze_event_handle_t eventHandle,
Expand Down
6 changes: 4 additions & 2 deletions utils/test_harness/tools/src/test_harness_metric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,8 @@ metric_streamer_open(zet_metric_group_handle_t matchedGroupHandle,

zet_metric_streamer_handle_t metric_streamer_open_for_device(
ze_device_handle_t device, zet_metric_group_handle_t matchedGroupHandle,
ze_event_handle_t eventHandle, uint32_t notifyEveryNReports,
uint32_t samplingPeriod) {
ze_event_handle_t eventHandle, uint32_t &notifyEveryNReports,
uint32_t &samplingPeriod) {
zet_metric_streamer_handle_t metricStreamerHandle = nullptr;
zet_metric_streamer_desc_t metricStreamerDesc = {
ZET_STRUCTURE_TYPE_METRIC_STREAMER_DESC, nullptr, notifyEveryNReports,
Expand All @@ -527,6 +527,8 @@ zet_metric_streamer_handle_t metric_streamer_open_for_device(
matchedGroupHandle, &metricStreamerDesc,
eventHandle, &metricStreamerHandle));
EXPECT_NE(nullptr, metricStreamerHandle);
notifyEveryNReports = metricStreamerDesc.notifyEveryNReports;
samplingPeriod = metricStreamerDesc.samplingPeriod;
return metricStreamerHandle;
}

Expand Down
Loading