From 969e3de7c62b0ee45ff25d7252e60418d55c007f Mon Sep 17 00:00:00 2001 From: Aviral Nigam Date: Mon, 2 Jun 2025 20:51:10 +0530 Subject: [PATCH 1/5] test(Sysman): Test to validate memory bandwidth counters with workload Related-To: VLCLJ-2505 Signed-off-by: Aviral Nigam --- .../src/test_sysman_memory.cpp | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/conformance_tests/sysman/test_sysman_memory/src/test_sysman_memory.cpp b/conformance_tests/sysman/test_sysman_memory/src/test_sysman_memory.cpp index b43c6b64..96961337 100644 --- a/conformance_tests/sysman/test_sysman_memory/src/test_sysman_memory.cpp +++ b/conformance_tests/sysman/test_sysman_memory/src/test_sysman_memory.cpp @@ -408,4 +408,76 @@ TEST_F( memoryThread.join(); } } + +TEST_F(MEMORY_TEST, + GivenWorkloadWhenQueryingMemoryBandwidthCountersThenCountersIncrease) { + for (auto device : devices) { + uint32_t count = 0; + auto mem_handles = lzt::get_mem_handles(device, count); + + if (count == 0) { + LOG_WARNING << "No memory handles found on this device!"; + continue; + } + + ze_device_properties_t deviceProperties = { + ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES, nullptr}; +#ifdef USE_ZESINIT + auto sysman_device_properties = lzt::get_sysman_device_properties(device); + ze_device_handle_t core_device = + lzt::get_core_device_by_uuid(sysman_device_properties.core.uuid.id); + EXPECT_NE(core_device, nullptr); + device = core_device; +#endif // USE_ZESINIT + EXPECT_EQ(ZE_RESULT_SUCCESS, + zeDeviceGetProperties(device, &deviceProperties)); + if (deviceProperties.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE) { + std::cout << "test subdevice id " << deviceProperties.subdeviceId; + } else { + std::cout << "test device is a root device" << std::endl; + } + + // Allocate device memory for workload + const size_t buffer_size = 32 * 1024 * 1024; + ze_device_mem_alloc_desc_t device_desc = {}; + device_desc.stype = ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC; + device_desc.ordinal = 0; + device_desc.flags = 0; + + void *src_ptr = lzt::allocate_device_memory(buffer_size, 1, 0, device, + lzt::get_default_context()); + void *dst_ptr = lzt::allocate_device_memory(buffer_size, 1, 0, device, + lzt::get_default_context()); + + ASSERT_NE(src_ptr, nullptr); + ASSERT_NE(dst_ptr, nullptr); + + for (auto mem_handle : mem_handles) { + ASSERT_NE(nullptr, mem_handle); + + // Get initial bandwidth counters + auto bandwidth_before = lzt::get_mem_bandwidth(mem_handle); + + // Run the workload + ze_result_t result = copy_workload(device, &device_desc, src_ptr, dst_ptr, + static_cast(buffer_size)); + EXPECT_EQ(result, ZE_RESULT_SUCCESS); + + // Get bandwidth counters after workload + auto bandwidth_after = lzt::get_mem_bandwidth(mem_handle); + + // Validate that read/write counters have increased after workload + EXPECT_GE(bandwidth_after.readCounter, bandwidth_before.readCounter) + << "Read counter did not increase after workload"; + EXPECT_GE(bandwidth_after.writeCounter, bandwidth_before.writeCounter) + << "Write counter did not increase after workload"; + EXPECT_GE(bandwidth_after.maxBandwidth, bandwidth_before.maxBandwidth) + << "Max bandwidth did not increase after workload"; + } + + // Free device memory + lzt::free_memory(src_ptr); + lzt::free_memory(dst_ptr); + } +} } // namespace From d9939a439a5804b7d8876869fd4754acb97d4776 Mon Sep 17 00:00:00 2001 From: Aviral Nigam Date: Mon, 2 Jun 2025 20:51:10 +0530 Subject: [PATCH 2/5] test(Sysman): Test to validate memory bandwidth counters with workload Related-To: VLCLJ-2505 Signed-off-by: Aviral Nigam --- .../src/test_sysman_memory.cpp | 148 +++++++++--------- 1 file changed, 70 insertions(+), 78 deletions(-) diff --git a/conformance_tests/sysman/test_sysman_memory/src/test_sysman_memory.cpp b/conformance_tests/sysman/test_sysman_memory/src/test_sysman_memory.cpp index 96961337..0c6c6c89 100644 --- a/conformance_tests/sysman/test_sysman_memory/src/test_sysman_memory.cpp +++ b/conformance_tests/sysman/test_sysman_memory/src/test_sysman_memory.cpp @@ -160,7 +160,7 @@ TEST_F( TEST_F( MEMORY_TEST, - GivenValidMemHandleWhenRetrievingMemBandWidthThenValidBandWidthCountersAreReturned) { + GivenValidMemHandleAndWorkloadWhenRetrievingMemBandWidthThenBandWidthCountersAreValidAndIncreaseAfterWorkload) { for (auto device : devices) { uint32_t count = 0; auto mem_handles = lzt::get_mem_handles(device, count); @@ -169,14 +169,78 @@ TEST_F( << _ze_result_t(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); } + ze_device_properties_t deviceProperties = { + ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES, nullptr}; +#ifdef USE_ZESINIT + auto sysman_device_properties = lzt::get_sysman_device_properties(device); + ze_device_handle_t core_device = + lzt::get_core_device_by_uuid(sysman_device_properties.core.uuid.id); + EXPECT_NE(core_device, nullptr); + device = core_device; +#endif // USE_ZESINIT + EXPECT_EQ(ZE_RESULT_SUCCESS, + zeDeviceGetProperties(device, &deviceProperties)); + if (deviceProperties.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE) { + std::cout << "test subdevice id " << deviceProperties.subdeviceId; + } else { + std::cout << "test device is a root device" << std::endl; + } + + // Allocate device memory for workload + const size_t buffer_size = 32 * 1024 * 1024; + ze_device_mem_alloc_desc_t device_desc = {}; + device_desc.stype = ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC; + device_desc.ordinal = 0; + device_desc.flags = 0; + + void *src_ptr = lzt::allocate_device_memory(buffer_size, 1, 0, device, + lzt::get_default_context()); + void *dst_ptr = lzt::allocate_device_memory(buffer_size, 1, 0, device, + lzt::get_default_context()); + + ASSERT_NE(src_ptr, nullptr); + ASSERT_NE(dst_ptr, nullptr); + for (auto mem_handle : mem_handles) { ASSERT_NE(nullptr, mem_handle); - auto bandwidth = lzt::get_mem_bandwidth(mem_handle); - EXPECT_LT(bandwidth.readCounter, UINT64_MAX); - EXPECT_LT(bandwidth.writeCounter, UINT64_MAX); - EXPECT_LT(bandwidth.maxBandwidth, UINT64_MAX); - EXPECT_LT(bandwidth.timestamp, UINT64_MAX); + + // Get initial bandwidth counters + auto bandwidth_before = lzt::get_mem_bandwidth(mem_handle); + EXPECT_LT(bandwidth_before.readCounter, UINT64_MAX); + EXPECT_LT(bandwidth_before.writeCounter, UINT64_MAX); + EXPECT_LT(bandwidth_before.maxBandwidth, UINT64_MAX); + EXPECT_LT(bandwidth_before.timestamp, UINT64_MAX); + // Run the workload + ze_result_t result = copy_workload(device, &device_desc, src_ptr, dst_ptr, + static_cast(buffer_size)); + EXPECT_EQ(result, ZE_RESULT_SUCCESS); + + // Get bandwidth counters after workload + auto bandwidth_after = lzt::get_mem_bandwidth(mem_handle); + + // Validate that read/write counters have increased after workload + EXPECT_GE(bandwidth_after.readCounter, bandwidth_before.readCounter) + << "Read counter did not increase after workload"; + EXPECT_GE(bandwidth_after.writeCounter, bandwidth_before.writeCounter) + << "Write counter did not increase after workload"; + EXPECT_GE(bandwidth_after.maxBandwidth, bandwidth_before.maxBandwidth) + << "Max bandwidth did not increase after workload"; + + auto percentage_bandwidth = + 1000000 * + ((bandwidth_after.readCounter - bandwidth_before.readCounter) + + (bandwidth_after.writeCounter - bandwidth_before.writeCounter)) / + (bandwidth_after.maxBandwidth * + (bandwidth_after.timestamp - bandwidth_before.timestamp)); + // Validate that percentage bandwidth is greater than zero + LOG_INFO << "Percentage Bandwidth: " << percentage_bandwidth << "%"; + EXPECT_GT(percentage_bandwidth, 0.0) + << "Percentage bandwidth is not greater than zero"; + EXPECT_LT(percentage_bandwidth, 100.0); } + // Free device memory + lzt::free_memory(src_ptr); + lzt::free_memory(dst_ptr); } } @@ -408,76 +472,4 @@ TEST_F( memoryThread.join(); } } - -TEST_F(MEMORY_TEST, - GivenWorkloadWhenQueryingMemoryBandwidthCountersThenCountersIncrease) { - for (auto device : devices) { - uint32_t count = 0; - auto mem_handles = lzt::get_mem_handles(device, count); - - if (count == 0) { - LOG_WARNING << "No memory handles found on this device!"; - continue; - } - - ze_device_properties_t deviceProperties = { - ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES, nullptr}; -#ifdef USE_ZESINIT - auto sysman_device_properties = lzt::get_sysman_device_properties(device); - ze_device_handle_t core_device = - lzt::get_core_device_by_uuid(sysman_device_properties.core.uuid.id); - EXPECT_NE(core_device, nullptr); - device = core_device; -#endif // USE_ZESINIT - EXPECT_EQ(ZE_RESULT_SUCCESS, - zeDeviceGetProperties(device, &deviceProperties)); - if (deviceProperties.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE) { - std::cout << "test subdevice id " << deviceProperties.subdeviceId; - } else { - std::cout << "test device is a root device" << std::endl; - } - - // Allocate device memory for workload - const size_t buffer_size = 32 * 1024 * 1024; - ze_device_mem_alloc_desc_t device_desc = {}; - device_desc.stype = ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC; - device_desc.ordinal = 0; - device_desc.flags = 0; - - void *src_ptr = lzt::allocate_device_memory(buffer_size, 1, 0, device, - lzt::get_default_context()); - void *dst_ptr = lzt::allocate_device_memory(buffer_size, 1, 0, device, - lzt::get_default_context()); - - ASSERT_NE(src_ptr, nullptr); - ASSERT_NE(dst_ptr, nullptr); - - for (auto mem_handle : mem_handles) { - ASSERT_NE(nullptr, mem_handle); - - // Get initial bandwidth counters - auto bandwidth_before = lzt::get_mem_bandwidth(mem_handle); - - // Run the workload - ze_result_t result = copy_workload(device, &device_desc, src_ptr, dst_ptr, - static_cast(buffer_size)); - EXPECT_EQ(result, ZE_RESULT_SUCCESS); - - // Get bandwidth counters after workload - auto bandwidth_after = lzt::get_mem_bandwidth(mem_handle); - - // Validate that read/write counters have increased after workload - EXPECT_GE(bandwidth_after.readCounter, bandwidth_before.readCounter) - << "Read counter did not increase after workload"; - EXPECT_GE(bandwidth_after.writeCounter, bandwidth_before.writeCounter) - << "Write counter did not increase after workload"; - EXPECT_GE(bandwidth_after.maxBandwidth, bandwidth_before.maxBandwidth) - << "Max bandwidth did not increase after workload"; - } - - // Free device memory - lzt::free_memory(src_ptr); - lzt::free_memory(dst_ptr); - } -} } // namespace From d7a0c576dfaa5ab0decd5a7aabce669afab07e4d Mon Sep 17 00:00:00 2001 From: Aviral Nigam Date: Mon, 2 Jun 2025 20:51:10 +0530 Subject: [PATCH 3/5] test(Sysman): Test to validate memory bandwidth counters with workload Related-To: VLCLJ-2505 Signed-off-by: Aviral Nigam --- .../src/test_sysman_memory.cpp | 52 ------------------- 1 file changed, 52 deletions(-) diff --git a/conformance_tests/sysman/test_sysman_memory/src/test_sysman_memory.cpp b/conformance_tests/sysman/test_sysman_memory/src/test_sysman_memory.cpp index 0c6c6c89..6d447264 100644 --- a/conformance_tests/sysman/test_sysman_memory/src/test_sysman_memory.cpp +++ b/conformance_tests/sysman/test_sysman_memory/src/test_sysman_memory.cpp @@ -288,58 +288,6 @@ uint64_t get_free_memory_state(ze_device_handle_t device) { return total_free_memory; } -ze_result_t copy_workload(ze_device_handle_t device, - ze_device_mem_alloc_desc_t *device_desc, - void *src_ptr, void *dst_ptr, int32_t local_size) { - - ze_result_t result = ZE_RESULT_SUCCESS; - void *src_buffer = src_ptr; - void *dst_buffer = dst_ptr; - int32_t offset = 0; - - ze_module_handle_t module = lzt::create_module( - device, "copy_module.spv", ZE_MODULE_FORMAT_IL_SPIRV, nullptr, nullptr); - ze_kernel_handle_t function = lzt::create_function(module, "copy_data"); - - lzt::set_group_size(function, 1, 1, 1); - lzt::set_argument_value(function, 0, sizeof(src_buffer), &src_buffer); - lzt::set_argument_value(function, 1, sizeof(dst_buffer), &dst_buffer); - lzt::set_argument_value(function, 2, sizeof(int32_t), &offset); - lzt::set_argument_value(function, 3, sizeof(int32_t), &local_size); - - ze_command_list_handle_t cmd_list = lzt::create_command_list(device); - - const int32_t group_count_x = 1; - const int32_t group_count_y = 1; - ze_group_count_t tg; - tg.groupCountX = group_count_x; - tg.groupCountY = group_count_y; - tg.groupCountZ = 1; - - result = zeCommandListAppendLaunchKernel(cmd_list, function, &tg, nullptr, 0, - nullptr); - if (result != ZE_RESULT_SUCCESS) { - return result; - } - - lzt::append_barrier(cmd_list, nullptr, 0, nullptr); - lzt::close_command_list(cmd_list); - ze_command_queue_handle_t cmd_q = lzt::create_command_queue(device); - - result = zeCommandQueueExecuteCommandLists(cmd_q, 1, &cmd_list, nullptr); - if (result != ZE_RESULT_SUCCESS) { - return result; - } - - lzt::synchronize(cmd_q, UINT64_MAX); - lzt::destroy_command_queue(cmd_q); - lzt::destroy_command_list(cmd_list); - lzt::destroy_function(function); - lzt::destroy_module(module); - - return result; -} - TEST_F( MEMORY_TEST, GivenValidMemHandleWhenAllocatingMemoryUptoMaxCapacityThenOutOfDeviceMemoryErrorIsReturned) { From ec18ff9b51c20c4b97ed7ceee0e156f6826a0b72 Mon Sep 17 00:00:00 2001 From: Aviral Nigam Date: Mon, 2 Jun 2025 20:51:10 +0530 Subject: [PATCH 4/5] test(Sysman): Test to validate memory bandwidth counters with workload Related-To: VLCLJ-2505 Signed-off-by: Aviral Nigam --- .../src/test_sysman_memory.cpp | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/conformance_tests/sysman/test_sysman_memory/src/test_sysman_memory.cpp b/conformance_tests/sysman/test_sysman_memory/src/test_sysman_memory.cpp index 6d447264..38e29d57 100644 --- a/conformance_tests/sysman/test_sysman_memory/src/test_sysman_memory.cpp +++ b/conformance_tests/sysman/test_sysman_memory/src/test_sysman_memory.cpp @@ -27,6 +27,58 @@ class MemoryModuleTest : public lzt::SysmanCtsClass {}; #define MEMORY_TEST MemoryModuleTest #endif // USE_ZESINIT +ze_result_t copy_workload(ze_device_handle_t device, + ze_device_mem_alloc_desc_t *device_desc, + void *src_ptr, void *dst_ptr, int32_t local_size) { + + ze_result_t result = ZE_RESULT_SUCCESS; + void *src_buffer = src_ptr; + void *dst_buffer = dst_ptr; + int32_t offset = 0; + + ze_module_handle_t module = lzt::create_module( + device, "copy_module.spv", ZE_MODULE_FORMAT_IL_SPIRV, nullptr, nullptr); + ze_kernel_handle_t function = lzt::create_function(module, "copy_data"); + + lzt::set_group_size(function, 1, 1, 1); + lzt::set_argument_value(function, 0, sizeof(src_buffer), &src_buffer); + lzt::set_argument_value(function, 1, sizeof(dst_buffer), &dst_buffer); + lzt::set_argument_value(function, 2, sizeof(int32_t), &offset); + lzt::set_argument_value(function, 3, sizeof(int32_t), &local_size); + + ze_command_list_handle_t cmd_list = lzt::create_command_list(device); + + const int32_t group_count_x = 1; + const int32_t group_count_y = 1; + ze_group_count_t tg; + tg.groupCountX = group_count_x; + tg.groupCountY = group_count_y; + tg.groupCountZ = 1; + + result = zeCommandListAppendLaunchKernel(cmd_list, function, &tg, nullptr, 0, + nullptr); + if (result != ZE_RESULT_SUCCESS) { + return result; + } + + lzt::append_barrier(cmd_list, nullptr, 0, nullptr); + lzt::close_command_list(cmd_list); + ze_command_queue_handle_t cmd_q = lzt::create_command_queue(device); + + result = zeCommandQueueExecuteCommandLists(cmd_q, 1, &cmd_list, nullptr); + if (result != ZE_RESULT_SUCCESS) { + return result; + } + + lzt::synchronize(cmd_q, UINT64_MAX); + lzt::destroy_command_queue(cmd_q); + lzt::destroy_command_list(cmd_list); + lzt::destroy_function(function); + lzt::destroy_module(module); + + return result; +} + TEST_F( MEMORY_TEST, GivenComponentCountZeroWhenRetrievingSysmanHandlesThenNonZeroCountIsReturned) { From 991049c83ff246db76d0aa9f2133c0159115a7e5 Mon Sep 17 00:00:00 2001 From: Aviral Nigam Date: Mon, 2 Jun 2025 20:51:10 +0530 Subject: [PATCH 5/5] test(Sysman): Test to validate memory bandwidth counters with workload Related-To: VLCLJ-2505 Signed-off-by: Aviral Nigam --- .../src/test_sysman_memory.cpp | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/conformance_tests/sysman/test_sysman_memory/src/test_sysman_memory.cpp b/conformance_tests/sysman/test_sysman_memory/src/test_sysman_memory.cpp index 38e29d57..6c679df3 100644 --- a/conformance_tests/sysman/test_sysman_memory/src/test_sysman_memory.cpp +++ b/conformance_tests/sysman/test_sysman_memory/src/test_sysman_memory.cpp @@ -233,9 +233,9 @@ TEST_F( EXPECT_EQ(ZE_RESULT_SUCCESS, zeDeviceGetProperties(device, &deviceProperties)); if (deviceProperties.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE) { - std::cout << "test subdevice id " << deviceProperties.subdeviceId; + LOG_DEBUG << "test sub-device id: " << deviceProperties.subdeviceId; } else { - std::cout << "test device is a root device" << std::endl; + LOG_DEBUG << "test device is a root device"; } // Allocate device memory for workload @@ -258,10 +258,10 @@ TEST_F( // Get initial bandwidth counters auto bandwidth_before = lzt::get_mem_bandwidth(mem_handle); - EXPECT_LT(bandwidth_before.readCounter, UINT64_MAX); - EXPECT_LT(bandwidth_before.writeCounter, UINT64_MAX); - EXPECT_LT(bandwidth_before.maxBandwidth, UINT64_MAX); - EXPECT_LT(bandwidth_before.timestamp, UINT64_MAX); + EXPECT_GT(bandwidth_before.maxBandwidth, 0) + << "Max bandwidth is not greater than zero"; + EXPECT_GT(bandwidth_before.timestamp, 0) + << "Timestamp is not greater than zero"; // Run the workload ze_result_t result = copy_workload(device, &device_desc, src_ptr, dst_ptr, static_cast(buffer_size)); @@ -271,24 +271,25 @@ TEST_F( auto bandwidth_after = lzt::get_mem_bandwidth(mem_handle); // Validate that read/write counters have increased after workload - EXPECT_GE(bandwidth_after.readCounter, bandwidth_before.readCounter) + EXPECT_GT(bandwidth_after.readCounter, bandwidth_before.readCounter) << "Read counter did not increase after workload"; - EXPECT_GE(bandwidth_after.writeCounter, bandwidth_before.writeCounter) + EXPECT_GT(bandwidth_after.writeCounter, bandwidth_before.writeCounter) << "Write counter did not increase after workload"; - EXPECT_GE(bandwidth_after.maxBandwidth, bandwidth_before.maxBandwidth) - << "Max bandwidth did not increase after workload"; - - auto percentage_bandwidth = - 1000000 * + EXPECT_GT(bandwidth_after.timestamp, bandwidth_before.timestamp) + << "Timestamp did not increase after workload"; + double percentage_bandwidth = + 1000000.0 * ((bandwidth_after.readCounter - bandwidth_before.readCounter) + (bandwidth_after.writeCounter - bandwidth_before.writeCounter)) / - (bandwidth_after.maxBandwidth * - (bandwidth_after.timestamp - bandwidth_before.timestamp)); + (static_cast(bandwidth_after.maxBandwidth) * + (static_cast(bandwidth_after.timestamp) - + static_cast(bandwidth_before.timestamp))); // Validate that percentage bandwidth is greater than zero LOG_INFO << "Percentage Bandwidth: " << percentage_bandwidth << "%"; EXPECT_GT(percentage_bandwidth, 0.0) << "Percentage bandwidth is not greater than zero"; - EXPECT_LT(percentage_bandwidth, 100.0); + EXPECT_LE(percentage_bandwidth, 100.0) + << "Percentage bandwidth is greater than 100%"; } // Free device memory lzt::free_memory(src_ptr);