@@ -1588,336 +1588,12 @@ LZT_TEST_F(
1588
1588
}
1589
1589
}
1590
1590
1591
- void metric_validate_stall_sampling_data (
1592
- std::vector<zet_metric_properties_t > &metricProperties,
1593
- std::vector<zet_typed_value_t > &totalMetricValues,
1594
- std::vector<uint32_t > &metricValueSets) {
1595
-
1596
- uint32_t activeOffset = UINT32_MAX;
1597
- uint32_t controlStallOffset = UINT32_MAX;
1598
- uint32_t pipeStallOffset = UINT32_MAX;
1599
- uint32_t sendStallOffset = UINT32_MAX;
1600
- uint32_t distStallOffset = UINT32_MAX;
1601
- uint32_t sbidStallOffset = UINT32_MAX;
1602
- uint32_t syncStallOffset = UINT32_MAX;
1603
- uint32_t instrFetchStallOffset = UINT32_MAX;
1604
- uint32_t otherStallOffset = UINT32_MAX;
1605
-
1606
- for (size_t i = 0 ; i < metricProperties.size (); i++) {
1607
-
1608
- if (strcmp (" Active" , metricProperties[i].name ) == 0 ) {
1609
- activeOffset = i;
1610
- continue ;
1611
- }
1612
- if (strcmp (" ControlStall" , metricProperties[i].name ) == 0 ) {
1613
- controlStallOffset = i;
1614
- continue ;
1615
- }
1616
- if (strcmp (" PipeStall" , metricProperties[i].name ) == 0 ) {
1617
- pipeStallOffset = i;
1618
- continue ;
1619
- }
1620
- if (strcmp (" SendStall" , metricProperties[i].name ) == 0 ) {
1621
- sendStallOffset = i;
1622
- continue ;
1623
- }
1624
- if (strcmp (" DistStall" , metricProperties[i].name ) == 0 ) {
1625
- distStallOffset = i;
1626
- continue ;
1627
- }
1628
- if (strcmp (" SbidStall" , metricProperties[i].name ) == 0 ) {
1629
- sbidStallOffset = i;
1630
- continue ;
1631
- }
1632
- if (strcmp (" SyncStall" , metricProperties[i].name ) == 0 ) {
1633
- syncStallOffset = i;
1634
- continue ;
1635
- }
1636
- if (strcmp (" InstrFetchStall" , metricProperties[i].name ) == 0 ) {
1637
- instrFetchStallOffset = i;
1638
- continue ;
1639
- }
1640
- if (strcmp (" OtherStall" , metricProperties[i].name ) == 0 ) {
1641
- otherStallOffset = i;
1642
- continue ;
1643
- }
1644
- }
1645
-
1646
- uint32_t ActiveCount = 0 ;
1647
- uint32_t ControlStallCount = 0 ;
1648
- uint32_t PipeStallCount = 0 ;
1649
- uint32_t SendStallCount = 0 ;
1650
- uint32_t DistStallCount = 0 ;
1651
- uint32_t SbidStallCount = 0 ;
1652
- uint32_t SyncStallCount = 0 ;
1653
- uint32_t InstrFetchStallCount = 0 ;
1654
- uint32_t OtherStallCount = 0 ;
1655
-
1656
- uint32_t metricSetStartIndex = 0 ;
1657
-
1658
- EXPECT_GT (metricValueSets.size (), 0u );
1659
- for (uint32_t metricValueSetIndex = 0 ;
1660
- metricValueSetIndex < metricValueSets.size (); metricValueSetIndex++) {
1661
-
1662
- const uint32_t metricCountForDataIndex =
1663
- metricValueSets[metricValueSetIndex];
1664
- const uint32_t reportCount =
1665
- metricCountForDataIndex / metricProperties.size ();
1666
-
1667
- LOG_INFO << " for metricValueSetIndex " << metricValueSetIndex
1668
- << " metricCountForDataIndex " << metricCountForDataIndex
1669
- << " reportCount " << reportCount;
1670
-
1671
- EXPECT_GT (reportCount, 1 );
1672
-
1673
- uint32_t tmpStallCount;
1674
- bool reportCompleteFlag;
1675
-
1676
- for (uint32_t report = 0 ; report < reportCount; report++) {
1677
-
1678
- tmpStallCount = 0 ;
1679
- reportCompleteFlag = false ;
1680
-
1681
- auto getStallCount = [&totalMetricValues](uint32_t metricReport,
1682
- uint32_t metricPropertiesSize,
1683
- uint32_t metricOffset,
1684
- uint32_t metricStartIndex) {
1685
- uint32_t metricIndex =
1686
- metricReport * metricPropertiesSize + metricOffset;
1687
- zet_typed_value_t metricTypedValue =
1688
- totalMetricValues[metricStartIndex + metricIndex];
1689
- uint64_t metricValue = metricTypedValue.value .ui64 ;
1690
- return metricValue;
1691
- };
1692
-
1693
- tmpStallCount = getStallCount (report, metricProperties.size (),
1694
- activeOffset, metricSetStartIndex);
1695
- reportCompleteFlag |= (tmpStallCount != 0 );
1696
- ActiveCount += tmpStallCount;
1697
-
1698
- tmpStallCount = getStallCount (report, metricProperties.size (),
1699
- controlStallOffset, metricSetStartIndex);
1700
- reportCompleteFlag |= (tmpStallCount != 0 );
1701
- ControlStallCount += tmpStallCount;
1702
-
1703
- tmpStallCount = getStallCount (report, metricProperties.size (),
1704
- pipeStallOffset, metricSetStartIndex);
1705
- reportCompleteFlag |= (tmpStallCount != 0 );
1706
- PipeStallCount += tmpStallCount;
1707
-
1708
- tmpStallCount = getStallCount (report, metricProperties.size (),
1709
- sendStallOffset, metricSetStartIndex);
1710
- reportCompleteFlag |= (tmpStallCount != 0 );
1711
- SendStallCount += tmpStallCount;
1712
-
1713
- tmpStallCount = getStallCount (report, metricProperties.size (),
1714
- distStallOffset, metricSetStartIndex);
1715
- reportCompleteFlag |= (tmpStallCount != 0 );
1716
- DistStallCount += tmpStallCount;
1717
-
1718
- tmpStallCount = getStallCount (report, metricProperties.size (),
1719
- sbidStallOffset, metricSetStartIndex);
1720
- reportCompleteFlag |= (tmpStallCount != 0 );
1721
- SbidStallCount += tmpStallCount;
1722
-
1723
- tmpStallCount = getStallCount (report, metricProperties.size (),
1724
- syncStallOffset, metricSetStartIndex);
1725
- reportCompleteFlag |= (tmpStallCount != 0 );
1726
- SyncStallCount += tmpStallCount;
1727
-
1728
- tmpStallCount = getStallCount (report, metricProperties.size (),
1729
- instrFetchStallOffset, metricSetStartIndex);
1730
- reportCompleteFlag |= (tmpStallCount != 0 );
1731
- InstrFetchStallCount += tmpStallCount;
1732
-
1733
- tmpStallCount = getStallCount (report, metricProperties.size (),
1734
- otherStallOffset, metricSetStartIndex);
1735
- reportCompleteFlag |= (tmpStallCount != 0 );
1736
- OtherStallCount += tmpStallCount;
1737
-
1738
- EXPECT_TRUE (reportCompleteFlag)
1739
- << " Report number " << report << " has zero for all stall counts" ;
1740
- }
1741
-
1742
- metricSetStartIndex += metricCountForDataIndex;
1743
- }
1744
-
1745
- LOG_DEBUG << " ActiveCount " << ActiveCount;
1746
- LOG_DEBUG << " ControlStallCount " << ControlStallCount;
1747
- LOG_DEBUG << " PipeStallCount " << PipeStallCount;
1748
- LOG_DEBUG << " SendStallCount " << SendStallCount;
1749
- LOG_DEBUG << " DistStallCount " << DistStallCount;
1750
- LOG_DEBUG << " SbidStallCount " << SbidStallCount;
1751
- LOG_DEBUG << " SyncStallCount " << SyncStallCount;
1752
- LOG_DEBUG << " InstrFetchStallCount " << InstrFetchStallCount;
1753
- LOG_DEBUG << " OtherStallCount " << OtherStallCount;
1754
- }
1755
-
1756
- void run_ip_sampling_with_validation (
1757
- bool enableOverflow, const std::vector<ze_device_handle_t > &devices,
1758
- uint32_t notifyEveryNReports, uint32_t samplingPeriod,
1759
- uint32_t timeForNReportsComplete) {
1760
-
1761
- uint32_t numberOfFunctionCalls;
1762
- if (enableOverflow) {
1763
- numberOfFunctionCalls = 8 ;
1764
- } else {
1765
- numberOfFunctionCalls = 1 ;
1766
- }
1767
-
1768
- typedef struct _function_data {
1769
- ze_kernel_handle_t function;
1770
- ze_group_count_t tg;
1771
- void *a_buffer, *b_buffer, *c_buffer;
1772
- } function_data_t ;
1773
-
1774
- std::vector<function_data_t > functionDataBuf (numberOfFunctionCalls);
1775
-
1776
- for (auto device : devices) {
1777
-
1778
- ze_device_properties_t deviceProperties = {
1779
- ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES, nullptr };
1780
- zeDeviceGetProperties (device, &deviceProperties);
1781
-
1782
- LOG_INFO << " test device name " << deviceProperties.name << " uuid "
1783
- << lzt::to_string (deviceProperties.uuid );
1784
- if (deviceProperties.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE) {
1785
- LOG_INFO << " test subdevice id " << deviceProperties.subdeviceId ;
1786
- } else {
1787
- LOG_INFO << " test device is a root device" ;
1788
- }
1789
-
1790
- ze_command_queue_handle_t commandQueue = lzt::create_command_queue (device);
1791
- zet_command_list_handle_t commandList = lzt::create_command_list (device);
1792
-
1793
- auto metricGroupInfo = lzt::get_metric_type_ip_group_info (
1794
- device, ZET_METRIC_GROUP_SAMPLING_TYPE_FLAG_TIME_BASED);
1795
- if (metricGroupInfo.size () == 0 ) {
1796
- GTEST_SKIP ()
1797
- << " No IP metric groups are available to test on this platform" ;
1798
- }
1799
- metricGroupInfo = lzt::optimize_metric_group_info_list (metricGroupInfo);
1800
-
1801
- for (auto groupInfo : metricGroupInfo) {
1802
-
1803
- LOG_INFO << " test metricGroup name " << groupInfo.metricGroupName ;
1804
-
1805
- lzt::activate_metric_groups (device, 1 , &groupInfo.metricGroupHandle );
1806
-
1807
- ze_event_handle_t eventHandle;
1808
- lzt::zeEventPool eventPool;
1809
- eventPool.create_event (eventHandle, ZE_EVENT_SCOPE_FLAG_HOST,
1810
- ZE_EVENT_SCOPE_FLAG_HOST);
1811
-
1812
- for (auto &fData : functionDataBuf) {
1813
- fData .function = get_matrix_multiplication_kernel (
1814
- device, &fData .tg , &fData .a_buffer , &fData .b_buffer ,
1815
- &fData .c_buffer , 8192 );
1816
- zeCommandListAppendLaunchKernel (commandList, fData .function , &fData .tg ,
1817
- nullptr , 0 , nullptr );
1818
- }
1819
-
1820
- lzt::close_command_list (commandList);
1821
- std::chrono::steady_clock::time_point startTime =
1822
- std::chrono::steady_clock::now ();
1823
-
1824
- zet_metric_streamer_handle_t metricStreamerHandle =
1825
- lzt::metric_streamer_open_for_device (
1826
- device, groupInfo.metricGroupHandle , eventHandle,
1827
- notifyEveryNReports, samplingPeriod);
1828
- ASSERT_NE (nullptr , metricStreamerHandle);
1829
-
1830
- lzt::execute_command_lists (commandQueue, 1 , &commandList, nullptr );
1831
- lzt::synchronize (commandQueue, std::numeric_limits<uint64_t >::max ());
1832
-
1833
- std::chrono::steady_clock::time_point endTime =
1834
- std::chrono::steady_clock::now ();
1835
- uint64_t elapsedTime =
1836
- std::chrono::duration_cast<std::chrono::nanoseconds>(endTime -
1837
- startTime)
1838
- .count ();
1839
-
1840
- LOG_INFO << " elapsed time for workload completion " << elapsedTime
1841
- << " time for NReports to complete " << timeForNReportsComplete;
1842
- if (elapsedTime < timeForNReportsComplete) {
1843
- LOG_WARNING << " elapsed time for workload completion is too short" ;
1844
- }
1845
-
1846
- const char *sleep_in_buffer_overflow_test_environment_variable =
1847
- std::getenv (" LZT_METRICS_BUFFER_OVERFLOW_SLEEP_MS" );
1848
-
1849
- if (sleep_in_buffer_overflow_test_environment_variable != nullptr ) {
1850
- uint32_t value =
1851
- atoi (sleep_in_buffer_overflow_test_environment_variable);
1852
- std::this_thread::sleep_for (std::chrono::milliseconds (value));
1853
- }
1854
-
1855
- size_t rawDataSize = 0 ;
1856
- std::vector<uint8_t > rawData;
1857
- rawDataSize = lzt::metric_streamer_read_data_size (metricStreamerHandle,
1858
- notifyEveryNReports);
1859
- EXPECT_GT (rawDataSize, 0 );
1860
- rawData.resize (rawDataSize);
1861
- lzt::metric_streamer_read_data (metricStreamerHandle, notifyEveryNReports,
1862
- rawDataSize, &rawData);
1863
- lzt::validate_metrics (groupInfo.metricGroupHandle , rawDataSize,
1864
- rawData.data (), false );
1865
- rawData.resize (rawDataSize);
1866
-
1867
- std::vector<zet_typed_value_t > metricValues;
1868
- std::vector<uint32_t > metricValueSets;
1869
- ze_result_t result =
1870
- level_zero_tests::metric_calculate_metric_values_from_raw_data (
1871
- groupInfo.metricGroupHandle , rawData, metricValues,
1872
- metricValueSets);
1873
-
1874
- if (enableOverflow) {
1875
- ASSERT_EQ (ZE_RESULT_WARNING_DROPPED_DATA, result);
1876
- } else {
1877
- ASSERT_ZE_RESULT_SUCCESS (result);
1878
- }
1879
-
1880
- std::vector<zet_metric_handle_t > metricHandles;
1881
- lzt::metric_get_metric_handles_from_metric_group (
1882
- groupInfo.metricGroupHandle , metricHandles);
1883
- std::vector<zet_metric_properties_t > metricProperties (
1884
- metricHandles.size ());
1885
- lzt::metric_get_metric_properties_for_metric_group (metricHandles,
1886
- metricProperties);
1887
-
1888
- metric_validate_stall_sampling_data (metricProperties, metricValues,
1889
- metricValueSets);
1890
-
1891
- lzt::metric_streamer_close (metricStreamerHandle);
1892
- lzt::deactivate_metric_groups (device);
1893
-
1894
- for (auto &fData : functionDataBuf) {
1895
- lzt::destroy_function (fData .function );
1896
- lzt::free_memory (fData .a_buffer );
1897
- lzt::free_memory (fData .b_buffer );
1898
- lzt::free_memory (fData .c_buffer );
1899
- }
1900
-
1901
- eventPool.destroy_event (eventHandle);
1902
- lzt::reset_command_list (commandList);
1903
- }
1904
- lzt::destroy_command_queue (commandQueue);
1905
- lzt::destroy_command_list (commandList);
1906
- }
1907
- }
1908
-
1909
- LZT_TEST_F (
1910
- zetMetricStreamerTest,
1911
- GivenValidTypeIpMetricGroupWhenTimerBasedStreamerIsCreatedAndOverflowTriggeredThenExpectStreamerValidateError) {
1912
- run_ip_sampling_with_validation (true , devices, notifyEveryNReports,
1913
- samplingPeriod, TimeForNReportsComplete);
1914
- }
1915
-
1916
1591
LZT_TEST_F (
1917
1592
zetMetricStreamerTest,
1918
1593
GivenValidTypeIpMetricGroupWhenTimerBasedStreamerIsCreatedWithNoOverflowThenValidateStallSampleData) {
1919
- run_ip_sampling_with_validation (false , devices, notifyEveryNReports,
1920
- samplingPeriod, TimeForNReportsComplete);
1594
+ metric_run_ip_sampling_with_validation (false , devices, notifyEveryNReports,
1595
+ samplingPeriod,
1596
+ TimeForNReportsComplete);
1921
1597
}
1922
1598
1923
1599
LZT_TEST_F (
0 commit comments