@@ -160,7 +160,7 @@ TEST_F(
160160
161161TEST_F (
162162 MEMORY_TEST,
163- GivenValidMemHandleWhenRetrievingMemBandWidthThenValidBandWidthCountersAreReturned ) {
163+ GivenValidMemHandleAndWorkloadWhenRetrievingMemBandWidthThenBandWidthCountersAreValidAndIncreaseAfterWorkload ) {
164164 for (auto device : devices) {
165165 uint32_t count = 0 ;
166166 auto mem_handles = lzt::get_mem_handles (device, count);
@@ -169,14 +169,78 @@ TEST_F(
169169 << _ze_result_t (ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
170170 }
171171
172+ ze_device_properties_t deviceProperties = {
173+ ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES, nullptr };
174+ #ifdef USE_ZESINIT
175+ auto sysman_device_properties = lzt::get_sysman_device_properties (device);
176+ ze_device_handle_t core_device =
177+ lzt::get_core_device_by_uuid (sysman_device_properties.core .uuid .id );
178+ EXPECT_NE (core_device, nullptr );
179+ device = core_device;
180+ #endif // USE_ZESINIT
181+ EXPECT_EQ (ZE_RESULT_SUCCESS,
182+ zeDeviceGetProperties (device, &deviceProperties));
183+ if (deviceProperties.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE) {
184+ std::cout << " test subdevice id " << deviceProperties.subdeviceId ;
185+ } else {
186+ std::cout << " test device is a root device" << std::endl;
187+ }
188+
189+ // Allocate device memory for workload
190+ const size_t buffer_size = 32 * 1024 * 1024 ;
191+ ze_device_mem_alloc_desc_t device_desc = {};
192+ device_desc.stype = ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC;
193+ device_desc.ordinal = 0 ;
194+ device_desc.flags = 0 ;
195+
196+ void *src_ptr = lzt::allocate_device_memory (buffer_size, 1 , 0 , device,
197+ lzt::get_default_context ());
198+ void *dst_ptr = lzt::allocate_device_memory (buffer_size, 1 , 0 , device,
199+ lzt::get_default_context ());
200+
201+ ASSERT_NE (src_ptr, nullptr );
202+ ASSERT_NE (dst_ptr, nullptr );
203+
172204 for (auto mem_handle : mem_handles) {
173205 ASSERT_NE (nullptr , mem_handle);
174- auto bandwidth = lzt::get_mem_bandwidth (mem_handle);
175- EXPECT_LT (bandwidth.readCounter , UINT64_MAX);
176- EXPECT_LT (bandwidth.writeCounter , UINT64_MAX);
177- EXPECT_LT (bandwidth.maxBandwidth , UINT64_MAX);
178- EXPECT_LT (bandwidth.timestamp , UINT64_MAX);
206+
207+ // Get initial bandwidth counters
208+ auto bandwidth_before = lzt::get_mem_bandwidth (mem_handle);
209+ EXPECT_LT (bandwidth_before.readCounter , UINT64_MAX);
210+ EXPECT_LT (bandwidth_before.writeCounter , UINT64_MAX);
211+ EXPECT_LT (bandwidth_before.maxBandwidth , UINT64_MAX);
212+ EXPECT_LT (bandwidth_before.timestamp , UINT64_MAX);
213+ // Run the workload
214+ ze_result_t result = copy_workload (device, &device_desc, src_ptr, dst_ptr,
215+ static_cast <int32_t >(buffer_size));
216+ EXPECT_EQ (result, ZE_RESULT_SUCCESS);
217+
218+ // Get bandwidth counters after workload
219+ auto bandwidth_after = lzt::get_mem_bandwidth (mem_handle);
220+
221+ // Validate that read/write counters have increased after workload
222+ EXPECT_GE (bandwidth_after.readCounter , bandwidth_before.readCounter )
223+ << " Read counter did not increase after workload" ;
224+ EXPECT_GE (bandwidth_after.writeCounter , bandwidth_before.writeCounter )
225+ << " Write counter did not increase after workload" ;
226+ EXPECT_GE (bandwidth_after.maxBandwidth , bandwidth_before.maxBandwidth )
227+ << " Max bandwidth did not increase after workload" ;
228+
229+ auto percentage_bandwidth =
230+ 1000000 *
231+ ((bandwidth_after.readCounter - bandwidth_before.readCounter ) +
232+ (bandwidth_after.writeCounter - bandwidth_before.writeCounter )) /
233+ (bandwidth_after.maxBandwidth *
234+ (bandwidth_after.timestamp - bandwidth_before.timestamp ));
235+ // Validate that percentage bandwidth is greater than zero
236+ LOG_INFO << " Percentage Bandwidth: " << percentage_bandwidth << " %" ;
237+ EXPECT_GT (percentage_bandwidth, 0.0 )
238+ << " Percentage bandwidth is not greater than zero" ;
239+ EXPECT_LT (percentage_bandwidth, 100.0 );
179240 }
241+ // Free device memory
242+ lzt::free_memory (src_ptr);
243+ lzt::free_memory (dst_ptr);
180244 }
181245}
182246
@@ -408,76 +472,4 @@ TEST_F(
408472 memoryThread.join ();
409473 }
410474}
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- ze_device_properties_t deviceProperties = {
424- ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES, nullptr };
425- #ifdef USE_ZESINIT
426- auto sysman_device_properties = lzt::get_sysman_device_properties (device);
427- ze_device_handle_t core_device =
428- lzt::get_core_device_by_uuid (sysman_device_properties.core .uuid .id );
429- EXPECT_NE (core_device, nullptr );
430- device = core_device;
431- #endif // USE_ZESINIT
432- EXPECT_EQ (ZE_RESULT_SUCCESS,
433- zeDeviceGetProperties (device, &deviceProperties));
434- if (deviceProperties.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE) {
435- std::cout << " test subdevice id " << deviceProperties.subdeviceId ;
436- } else {
437- std::cout << " test device is a root device" << std::endl;
438- }
439-
440- // Allocate device memory for workload
441- const size_t buffer_size = 32 * 1024 * 1024 ;
442- ze_device_mem_alloc_desc_t device_desc = {};
443- device_desc.stype = ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC;
444- device_desc.ordinal = 0 ;
445- device_desc.flags = 0 ;
446-
447- void *src_ptr = lzt::allocate_device_memory (buffer_size, 1 , 0 , device,
448- lzt::get_default_context ());
449- void *dst_ptr = lzt::allocate_device_memory (buffer_size, 1 , 0 , device,
450- lzt::get_default_context ());
451-
452- ASSERT_NE (src_ptr, nullptr );
453- ASSERT_NE (dst_ptr, nullptr );
454-
455- for (auto mem_handle : mem_handles) {
456- ASSERT_NE (nullptr , mem_handle);
457-
458- // Get initial bandwidth counters
459- auto bandwidth_before = lzt::get_mem_bandwidth (mem_handle);
460-
461- // Run the workload
462- ze_result_t result = copy_workload (device, &device_desc, src_ptr, dst_ptr,
463- static_cast <int32_t >(buffer_size));
464- EXPECT_EQ (result, ZE_RESULT_SUCCESS);
465-
466- // Get bandwidth counters after workload
467- auto bandwidth_after = lzt::get_mem_bandwidth (mem_handle);
468-
469- // Validate that read/write counters have increased after workload
470- EXPECT_GE (bandwidth_after.readCounter , bandwidth_before.readCounter )
471- << " Read counter did not increase after workload" ;
472- EXPECT_GE (bandwidth_after.writeCounter , bandwidth_before.writeCounter )
473- << " Write counter did not increase after workload" ;
474- EXPECT_GE (bandwidth_after.maxBandwidth , bandwidth_before.maxBandwidth )
475- << " Max bandwidth did not increase after workload" ;
476- }
477-
478- // Free device memory
479- lzt::free_memory (src_ptr);
480- lzt::free_memory (dst_ptr);
481- }
482- }
483475} // namespace
0 commit comments