@@ -408,4 +408,82 @@ TEST_F(
408408 memoryThread.join ();
409409 }
410410}
411+
412+ TEST_F (MEMORY_TEST,
413+ GivenWorkloadWhenQueryingMemoryBandwidthCountersThenCountersIncrease) {
414+ for (auto device : devices) {
415+ uint32_t count = 0 ;
416+ auto mem_handles = lzt::get_mem_handles (device, count);
417+
418+ if (count == 0 ) {
419+ LOG_WARNING << " No memory handles found on this device!" ;
420+ continue ;
421+ }
422+
423+ #ifdef USE_ZESINIT
424+ auto sysman_device_properties = lzt::get_sysman_device_properties (device);
425+ ze_device_handle_t core_device =
426+ lzt::get_core_device_by_uuid (sysman_device_properties.core .uuid .id );
427+ EXPECT_NE (core_device, nullptr );
428+ ze_device_properties_t deviceProperties = {
429+ ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES, nullptr };
430+ EXPECT_EQ (ZE_RESULT_SUCCESS,
431+ zeDeviceGetProperties (core_device, &deviceProperties));
432+ std::cout << " test device name " << deviceProperties.name << " uuid "
433+ << lzt::to_string (deviceProperties.uuid );
434+ device = core_device;
435+ #else // USE_ZESINIT
436+ ze_device_properties_t deviceProperties = {
437+ ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES, nullptr };
438+ EXPECT_EQ (ZE_RESULT_SUCCESS,
439+ zeDeviceGetProperties (device, &deviceProperties));
440+ std::cout << " test device name " << deviceProperties.name << " uuid "
441+ << lzt::to_string (deviceProperties.uuid );
442+ #endif // USE_ZESINIT
443+
444+ // Allocate device memory for workload
445+ const size_t buffer_size = 32 * 1024 * 1024 ;
446+ ze_device_mem_alloc_desc_t device_desc = {};
447+ device_desc.stype = ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC;
448+ device_desc.ordinal = 0 ;
449+ device_desc.flags = 0 ;
450+
451+ void *src_ptr = lzt::allocate_device_memory (buffer_size, 1 , 0 , device,
452+ lzt::get_default_context ());
453+ void *dst_ptr = lzt::allocate_device_memory (buffer_size, 1 , 0 , device,
454+ lzt::get_default_context ());
455+
456+ ASSERT_NE (src_ptr, nullptr );
457+ ASSERT_NE (dst_ptr, nullptr );
458+
459+ for (auto mem_handle : mem_handles) {
460+ ASSERT_NE (nullptr , mem_handle);
461+
462+ // Get initial bandwidth counters
463+ zes_mem_bandwidth_t bandwidth_before = {};
464+ EXPECT_EQ (ZE_RESULT_SUCCESS,
465+ zesMemoryGetBandwidth (mem_handle, &bandwidth_before));
466+
467+ // Run the workload
468+ ze_result_t result = copy_workload (device, &device_desc, src_ptr, dst_ptr,
469+ static_cast <int32_t >(buffer_size));
470+ EXPECT_EQ (result, ZE_RESULT_SUCCESS);
471+
472+ // Get bandwidth counters after workload
473+ zes_mem_bandwidth_t bandwidth_after = {};
474+ EXPECT_EQ (ZE_RESULT_SUCCESS,
475+ zesMemoryGetBandwidth (mem_handle, &bandwidth_after));
476+
477+ // Validate that read/write counters have increased
478+ EXPECT_GE (bandwidth_after.readCounter , bandwidth_before.readCounter )
479+ << " Read counter did not increase after workload" ;
480+ EXPECT_GE (bandwidth_after.writeCounter , bandwidth_before.writeCounter )
481+ << " Write counter did not increase after workload" ;
482+ }
483+
484+ // Free device memory
485+ lzt::free_memory (src_ptr);
486+ lzt::free_memory (dst_ptr);
487+ }
488+ }
411489} // namespace
0 commit comments