@@ -224,6 +224,53 @@ uint64_t get_free_memory_state(ze_device_handle_t device) {
224224 return total_free_memory;
225225}
226226
227+ static void workload_for_device (ze_device_handle_t device) {
228+ int m, k, n;
229+ m = k = n = 5000 ;
230+ std::vector<float > a (m * k, 1 );
231+ std::vector<float > b (k * n, 1 );
232+ std::vector<float > c (m * n, 0 );
233+ void *a_buffer = lzt::allocate_host_memory (m * k * sizeof (float ));
234+ void *b_buffer = lzt::allocate_host_memory (k * n * sizeof (float ));
235+ void *c_buffer = lzt::allocate_host_memory (m * n * sizeof (float ));
236+ ze_module_handle_t module =
237+ lzt::create_module (device, " sysman_matrix_multiplication.spv" ,
238+ ZE_MODULE_FORMAT_IL_SPIRV, nullptr , nullptr );
239+ ze_kernel_handle_t function =
240+ lzt::create_function (module , " sysman_matrix_multiplication" );
241+ lzt::set_group_size (function, 16 , 16 , 1 );
242+ lzt::set_argument_value (function, 0 , sizeof (a_buffer), &a_buffer);
243+ lzt::set_argument_value (function, 1 , sizeof (b_buffer), &b_buffer);
244+ lzt::set_argument_value (function, 2 , sizeof (m), &m);
245+ lzt::set_argument_value (function, 3 , sizeof (k), &k);
246+ lzt::set_argument_value (function, 4 , sizeof (n), &n);
247+ lzt::set_argument_value (function, 5 , sizeof (c_buffer), &c_buffer);
248+ ze_command_list_handle_t cmd_list = lzt::create_command_list (device);
249+ std::memcpy (a_buffer, a.data (), a.size () * sizeof (float ));
250+ std::memcpy (b_buffer, b.data (), b.size () * sizeof (float ));
251+ lzt::append_barrier (cmd_list, nullptr , 0 , nullptr );
252+ const int group_count_x = m / 16 ;
253+ const int group_count_y = n / 16 ;
254+ ze_group_count_t tg;
255+ tg.groupCountX = group_count_x;
256+ tg.groupCountY = group_count_y;
257+ tg.groupCountZ = 1 ;
258+ zeCommandListAppendLaunchKernel (cmd_list, function, &tg, nullptr , 0 , nullptr );
259+ lzt::append_barrier (cmd_list, nullptr , 0 , nullptr );
260+ lzt::close_command_list (cmd_list);
261+ ze_command_queue_handle_t cmd_q = lzt::create_command_queue (device);
262+ lzt::execute_command_lists (cmd_q, 1 , &cmd_list, nullptr );
263+ lzt::synchronize (cmd_q, UINT64_MAX);
264+ std::memcpy (c.data (), c_buffer, c.size () * sizeof (float ));
265+ lzt::destroy_command_queue (cmd_q);
266+ lzt::destroy_command_list (cmd_list);
267+ lzt::destroy_function (function);
268+ lzt::free_memory (a_buffer);
269+ lzt::free_memory (b_buffer);
270+ lzt::free_memory (c_buffer);
271+ lzt::destroy_module (module );
272+ }
273+
227274ze_result_t copy_workload (ze_device_handle_t device,
228275 ze_device_mem_alloc_desc_t *device_desc,
229276 void *src_ptr, void *dst_ptr, int32_t local_size) {
@@ -408,4 +455,56 @@ TEST_F(
408455 memoryThread.join ();
409456 }
410457}
458+
459+ TEST_F (MEMORY_TEST,
460+ GivenWorkloadWhenQueryingMemoryBandwidthCountersThenCountersIncrease) {
461+ for (auto device : devices) {
462+ uint32_t count = 0 ;
463+ auto mem_handles = lzt::get_mem_handles (device, count);
464+
465+ if (count == 0 ) {
466+ LOG_WARNING << " No memory handles found on this device!" ;
467+ continue ;
468+ }
469+
470+ ze_device_properties_t deviceProperties = {
471+ ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES, nullptr };
472+ #ifdef USE_ZESINIT
473+ auto sysman_device_properties = lzt::get_sysman_device_properties (device);
474+ ze_device_handle_t core_device =
475+ lzt::get_core_device_by_uuid (sysman_device_properties.core .uuid .id );
476+ EXPECT_NE (core_device, nullptr );
477+ device = core_device;
478+ #endif // USE_ZESINIT
479+ EXPECT_EQ (ZE_RESULT_SUCCESS,
480+ zeDeviceGetProperties (device, &deviceProperties));
481+ std::cout << " test device name " << deviceProperties.name << " uuid "
482+ << lzt::to_string (deviceProperties.uuid );
483+
484+ for (auto mem_handle : mem_handles) {
485+ ASSERT_NE (nullptr , mem_handle);
486+
487+ // Get initial bandwidth counters
488+ zes_mem_bandwidth_t bandwidth_before = {};
489+ EXPECT_EQ (ZE_RESULT_SUCCESS,
490+ zesMemoryGetBandwidth (mem_handle, &bandwidth_before));
491+
492+ // Run the workload
493+ ze_result_t result = workload_for_device (device);
494+ EXPECT_EQ (result, ZE_RESULT_SUCCESS);
495+
496+ // Get bandwidth counters after workload
497+ zes_mem_bandwidth_t bandwidth_after = {};
498+ EXPECT_EQ (ZE_RESULT_SUCCESS,
499+ zesMemoryGetBandwidth (mem_handle, &bandwidth_after));
500+
501+ // Validate that read/write counters have increased
502+ EXPECT_GE (bandwidth_after.readCounter , bandwidth_before.readCounter )
503+ << " Read counter did not increase after workload" ;
504+ EXPECT_GE (bandwidth_after.writeCounter , bandwidth_before.writeCounter )
505+ << " Write counter did not increase after workload" ;
506+ EXPECT_GE (bandwidth_after.maxBandwidth , bandwidth_before.maxBandwidth );
507+ }
508+ }
509+ }
411510} // namespace
0 commit comments