-
Notifications
You must be signed in to change notification settings - Fork 66
test(Sysman): Test to validate memory bandwidth counters with workload #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 5 commits
969e3de
0ac7789
d9939a4
d7a0c57
ec18ff9
991049c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
|
@@ -160,7 +212,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 +221,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) { | ||
aviralni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. readCounter & WriteCounter < UNIT64_MAX checks may not be useful. maxBandWidth & timestamp can be checked if it's greater than 0. (Instead of checking < UNIT64_MAX ) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, these checks were already present for counters validation, so did not modify these. IMO too we can modify these checks. |
||
EXPECT_LT(bandwidth_before.writeCounter, UINT64_MAX); | ||
EXPECT_LT(bandwidth_before.maxBandwidth, UINT64_MAX); | ||
EXPECT_LT(bandwidth_before.timestamp, UINT64_MAX); | ||
aviralni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Run the workload | ||
ze_result_t result = copy_workload(device, &device_desc, src_ptr, dst_ptr, | ||
static_cast<int32_t>(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) | ||
aviralni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<< "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) | ||
aviralni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<< "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); | ||
} | ||
} | ||
|
||
|
@@ -224,58 +340,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) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.