diff --git a/perf_tests/ze_peer/CMakeLists.txt b/perf_tests/ze_peer/CMakeLists.txt index 6b62d768d..7bd5faa0b 100644 --- a/perf_tests/ze_peer/CMakeLists.txt +++ b/perf_tests/ze_peer/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2019-2023 Intel Corporation +# Copyright (C) 2019-2026 Intel Corporation # SPDX-License-Identifier: MIT if(UNIX) @@ -23,3 +23,27 @@ add_lzt_test( LINK_LIBRARIES ${OS_SPECIFIC_LIBS} KERNELS ze_peer_benchmarks ) + +# These run without a GPU: options are parsed before any device is opened. +if(TARGET ze_peer) + add_test(NAME ze_peer_help_lists_remote_wait COMMAND ze_peer --help) + set_tests_properties(ze_peer_help_lists_remote_wait + PROPERTIES PASS_REGULAR_EXPRESSION "--remote_wait") + + function(add_ze_peer_remote_wait_reject_test name) + add_test(NAME ze_peer_remote_wait_rejects_${name} + COMMAND ze_peer ${ARGN} --remote_wait) + set_tests_properties(ze_peer_remote_wait_rejects_${name} + PROPERTIES PASS_REGULAR_EXPRESSION "--remote_wait is not supported" + TIMEOUT 30) + endfunction() + + add_ze_peer_remote_wait_reject_test(bidirectional -b) + add_ze_peer_remote_wait_reject_test(ipc --ipc) + add_ze_peer_remote_wait_reject_test(parallel_single_target + --parallel_single_target) + add_ze_peer_remote_wait_reject_test(parallel_multiple_targets + --parallel_multiple_targets) + add_ze_peer_remote_wait_reject_test(parallel_pair_targets + --parallel_pair_targets 0:1) +endif() diff --git a/perf_tests/ze_peer/README.md b/perf_tests/ze_peer/README.md index b3df0d584..a994167cf 100644 --- a/perf_tests/ze_peer/README.md +++ b/perf_tests/ze_peer/README.md @@ -63,6 +63,13 @@ first compute engine in the device. --ipc perform a copy between two devices, specified by options -s and -d, with each device being managed by a separate process. + --remote_wait for unidirectional tests, append a wait on each copy's + completion event, and an event reset, to engine 0 of the + remote device. On some platforms this keeps the remote device + out of a low power state that limits the transfer. Timing + includes the extra submission, wait, reset and synchronization. + Not supported with --ipc, -b or parallel tests. Default: Not set. + --version display version -h, --help display help message ``` @@ -124,6 +131,17 @@ Run latency tests, for 64B, between devices 1 and 3 (assuming the system has suc ./ze_peer -t latency -z 64 -s 1 -d 3 ``` +Run BW test for 256 MB with the remote device waiting on each copy's completion event. +In a unidirectional test only the local device submits work, so the remote device can stay +in a low power state for the whole run. On some platforms the transfer rate depends on that +state, so results can vary with the remote device's recent activity. With `--remote_wait` the +remote device has a wait pending on each copy, similar to a framework that orders cross-device +work with events. Results include that extra work, so compare them with other `--remote_wait` +runs rather than with the default mode. +``` +./ze_peer -t transfer_bw -z 268435456 -s 0 -d 1 --remote_wait +``` + Run parallel_single_target test, between devices 0 and 1, using engines 2 and 3, for a size of 256 MB. In this case, the buffer is divided into the number of engines (2), for a resulting chunk size of 128MB. Then, two copies are submitted in parallel, per chunk, and per engine. diff --git a/perf_tests/ze_peer/include/ze_peer.h b/perf_tests/ze_peer/include/ze_peer.h index 95a118bbf..50c0e80bb 100644 --- a/perf_tests/ze_peer/include/ze_peer.h +++ b/perf_tests/ze_peer/include/ze_peer.h @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2019-2023 Intel Corporation + * Copyright (C) 2019-2026 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -20,6 +20,7 @@ #include #include #include +#include #include "common.hpp" #include "ze_app.hpp" #include @@ -39,9 +40,11 @@ typedef enum _peer_test_t { PEER_TEST_MAX } peer_test_t; +using ze_peer_engine_t = + std::pair; + typedef struct _ze_peer_device_t { - std::vector> - engines; + std::vector engines; } ze_peer_device_t; // clang-format off @@ -116,6 +119,13 @@ first compute engine in the device. --regular_cmdlist use regular command list instead of immediate + --remote_wait for unidirectional tests, append a wait on each copy's + completion event, and an event reset, to engine 0 of the + remote device. On some platforms this keeps the remote device + out of a low power state that limits the transfer. Timing + includes the extra submission, wait, reset and synchronization. + Not supported with --ipc, -b or parallel tests. Default: Not set. + --version display version -h, --help display help message )HELP"; @@ -223,12 +233,14 @@ class ZePeer { void perform_copy(peer_test_t test_type, ze_command_list_handle_t command_list, ze_command_queue_handle_t command_queue, void *dst_buffer, - void *src_buffer, size_t buffer_size); + void *src_buffer, size_t buffer_size, + std::optional remote_engine = {}); - void perform_copy_immediate(peer_test_t test_type, - ze_command_list_handle_t command_list, - void *dst_buffer, void *src_buffer, - size_t buffer_size); + void + perform_copy_immediate(peer_test_t test_type, + ze_command_list_handle_t command_list, + void *dst_buffer, void *src_buffer, size_t buffer_size, + std::optional remote_engine = {}); void bidirectional_perform_copy(uint32_t dst_device_id, uint32_t src_device_id, uint32_t queue_index, @@ -321,6 +333,9 @@ class ZePeer { ze_event_pool_handle_t event_pool = {}; ze_event_handle_t event = {}; + ze_event_pool_handle_t remote_wait_event_pool = {}; + ze_event_handle_t remote_wait_event = {}; + static bool use_queue_in_destination; static bool run_continuously; static bool bidirectional; @@ -330,6 +345,7 @@ class ZePeer { static bool parallel_copy_to_pair_targets; static bool parallel_divide_buffers; static bool use_immediate_cmdlist; + static bool remote_wait; static uint32_t number_iterations; uint32_t warm_up_iterations = number_iterations / 5; diff --git a/perf_tests/ze_peer/src/ze_peer.cpp b/perf_tests/ze_peer/src/ze_peer.cpp index 982eb7cbc..16ea6e384 100644 --- a/perf_tests/ze_peer/src/ze_peer.cpp +++ b/perf_tests/ze_peer/src/ze_peer.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2019-2023 Intel Corporation + * Copyright (C) 2019-2026 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -19,6 +19,7 @@ bool ZePeer::parallel_copy_to_multiple_targets = false; bool ZePeer::parallel_copy_to_pair_targets = false; bool ZePeer::parallel_divide_buffers = false; bool ZePeer::use_immediate_cmdlist = true; +bool ZePeer::remote_wait = false; uint32_t ZePeer::number_iterations = 50; const size_t max_elems = 268435456; /* 256 MB */ @@ -467,12 +468,24 @@ int main(int argc, char **argv) { ZePeer::validate_results = true; } else if (strcmp(argv[i], "--regular_cmdlist") == 0) { ZePeer::use_immediate_cmdlist = false; + } else if (strcmp(argv[i], "--remote_wait") == 0) { + ZePeer::remote_wait = true; } else { std::cout << usage_str; exit(-1); } } + // Only bandwidth_latency() implements the remote wait. + if (ZePeer::remote_wait && (run_ipc || ZePeer::bidirectional || + ZePeer::parallel_copy_to_single_target || + ZePeer::parallel_copy_to_multiple_targets || + ZePeer::parallel_copy_to_pair_targets)) { + std::cerr << "[ERROR] --remote_wait is not supported with --ipc, -b or " + "parallel tests\n"; + exit(-1); + } + if (run_ipc == false) { // Detect number of devices ZePeer peerQueryDevices(&num_devices); @@ -494,6 +507,9 @@ int main(int argc, char **argv) { << "tests\n" << "=============================================================" "===================\n"; + if (ZePeer::remote_wait) { + std::cout << "Remote device waits on each copy (--remote_wait)\n"; + } if (ZePeer::parallel_copy_to_multiple_targets || ZePeer::parallel_copy_to_pair_targets || @@ -764,6 +780,22 @@ ZePeer::ZePeer(std::vector &remote_device_ids, ze_event_desc_t event_desc = {ZE_STRUCTURE_TYPE_EVENT_DESC}; event_desc.signal = ZE_EVENT_SCOPE_FLAG_HOST; SUCCESS_OR_TERMINATE(zeEventCreate(event_pool, &event_desc, &event)); + + if (ZePeer::remote_wait) { + ze_event_pool_desc_t remote_wait_pool_desc = { + ZE_STRUCTURE_TYPE_EVENT_POOL_DESC}; + remote_wait_pool_desc.count = 1; + remote_wait_pool_desc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE; + SUCCESS_OR_TERMINATE(zeEventPoolCreate(benchmark->context, + &remote_wait_pool_desc, 0, nullptr, + &remote_wait_event_pool)); + + ze_event_desc_t remote_wait_desc = {ZE_STRUCTURE_TYPE_EVENT_DESC}; + remote_wait_desc.signal = ZE_EVENT_SCOPE_FLAG_HOST; + remote_wait_desc.wait = ZE_EVENT_SCOPE_FLAG_HOST; + SUCCESS_OR_TERMINATE(zeEventCreate(remote_wait_event_pool, + &remote_wait_desc, &remote_wait_event)); + } } ZePeer::~ZePeer() { @@ -779,6 +811,10 @@ ZePeer::~ZePeer() { SUCCESS_OR_TERMINATE(zeEventDestroy(event)); SUCCESS_OR_TERMINATE(zeEventPoolDestroy(event_pool)); } + if (remote_wait_event) { + SUCCESS_OR_TERMINATE(zeEventDestroy(remote_wait_event)); + SUCCESS_OR_TERMINATE(zeEventPoolDestroy(remote_wait_event_pool)); + } benchmark->allDevicesCleanup(); delete benchmark; } diff --git a/perf_tests/ze_peer/src/ze_peer_unidirectional.cpp b/perf_tests/ze_peer/src/ze_peer_unidirectional.cpp index 6bdae7f7d..8b9bdafe1 100644 --- a/perf_tests/ze_peer/src/ze_peer_unidirectional.cpp +++ b/perf_tests/ze_peer/src/ze_peer_unidirectional.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2019-2021 Intel Corporation + * Copyright (C) 2019-2026 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -11,29 +11,49 @@ void ZePeer::perform_copy(peer_test_t test_type, ze_command_list_handle_t command_list, ze_command_queue_handle_t command_queue, void *dst_buffer, void *src_buffer, - size_t buffer_size) { - - SUCCESS_OR_TERMINATE(zeCommandListAppendMemoryCopy( - command_list, dst_buffer, src_buffer, buffer_size, nullptr, 0, nullptr)); + size_t buffer_size, + std::optional remote_engine) { + const ze_event_handle_t signal_event = + remote_engine ? remote_wait_event : nullptr; + + SUCCESS_OR_TERMINATE(zeCommandListAppendMemoryCopy(command_list, dst_buffer, + src_buffer, buffer_size, + signal_event, 0, nullptr)); SUCCESS_OR_TERMINATE(zeCommandListClose(command_list)); + if (remote_engine) { + SUCCESS_OR_TERMINATE(zeCommandListAppendWaitOnEvents( + remote_engine->second, 1, &remote_wait_event)); + SUCCESS_OR_TERMINATE(zeCommandListAppendEventReset(remote_engine->second, + remote_wait_event)); + SUCCESS_OR_TERMINATE(zeCommandListClose(remote_engine->second)); + } - Timer timer; - - /* Warm up */ - for (uint32_t i = 0U; i < warm_up_iterations; i++) { + const auto execute_and_synchronize = [&]() { SUCCESS_OR_TERMINATE(zeCommandQueueExecuteCommandLists( command_queue, 1, &command_list, nullptr)); + if (remote_engine) { + SUCCESS_OR_TERMINATE(zeCommandQueueExecuteCommandLists( + remote_engine->first, 1, &remote_engine->second, nullptr)); + } SUCCESS_OR_TERMINATE(zeCommandQueueSynchronize( command_queue, std::numeric_limits::max())); + if (remote_engine) { + SUCCESS_OR_TERMINATE(zeCommandQueueSynchronize( + remote_engine->first, std::numeric_limits::max())); + } + }; + + Timer timer; + + /* Warm up */ + for (uint32_t i = 0U; i < warm_up_iterations; i++) { + execute_and_synchronize(); } do { timer.start(); for (uint32_t i = 0U; i < number_iterations; i++) { - SUCCESS_OR_TERMINATE(zeCommandQueueExecuteCommandLists( - command_queue, 1, &command_list, nullptr)); - SUCCESS_OR_TERMINATE(zeCommandQueueSynchronize( - command_queue, std::numeric_limits::max())); + execute_and_synchronize(); } timer.end(); @@ -41,31 +61,47 @@ void ZePeer::perform_copy(peer_test_t test_type, } while (run_continuously); SUCCESS_OR_TERMINATE(zeCommandListReset(command_list)); + if (remote_engine) { + SUCCESS_OR_TERMINATE(zeCommandListReset(remote_engine->second)); + } } -void ZePeer::perform_copy_immediate(peer_test_t test_type, - ze_command_list_handle_t command_list, - void *dst_buffer, void *src_buffer, - size_t buffer_size) { +void ZePeer::perform_copy_immediate( + peer_test_t test_type, ze_command_list_handle_t command_list, + void *dst_buffer, void *src_buffer, size_t buffer_size, + std::optional remote_engine) { + const ze_event_handle_t signal_event = + remote_engine ? remote_wait_event : nullptr; + + const auto copy_and_synchronize = [&]() { + SUCCESS_OR_TERMINATE( + zeCommandListAppendMemoryCopy(command_list, dst_buffer, src_buffer, + buffer_size, signal_event, 0, nullptr)); + if (remote_engine) { + SUCCESS_OR_TERMINATE(zeCommandListAppendWaitOnEvents( + remote_engine->second, 1, &remote_wait_event)); + SUCCESS_OR_TERMINATE(zeCommandListAppendEventReset(remote_engine->second, + remote_wait_event)); + } + SUCCESS_OR_TERMINATE(zeCommandListHostSynchronize( + command_list, std::numeric_limits::max())); + if (remote_engine) { + SUCCESS_OR_TERMINATE(zeCommandListHostSynchronize( + remote_engine->second, std::numeric_limits::max())); + } + }; + Timer timer; /* Warm up */ for (uint32_t i = 0U; i < warm_up_iterations; i++) { - SUCCESS_OR_TERMINATE(zeCommandListAppendMemoryCopy(command_list, dst_buffer, - src_buffer, buffer_size, - nullptr, 0, nullptr)); - SUCCESS_OR_TERMINATE(zeCommandListHostSynchronize( - command_list, std::numeric_limits::max())); + copy_and_synchronize(); } do { timer.start(); for (uint32_t i = 0U; i < number_iterations; i++) { - SUCCESS_OR_TERMINATE( - zeCommandListAppendMemoryCopy(command_list, dst_buffer, src_buffer, - buffer_size, nullptr, 0, nullptr)); - SUCCESS_OR_TERMINATE(zeCommandListHostSynchronize( - command_list, std::numeric_limits::max())); + copy_and_synchronize(); } timer.end(); @@ -103,12 +139,18 @@ void ZePeer::bandwidth_latency(peer_test_t test_type, initialize_buffers(remote_device_ids, local_device_ids, ze_host_buffer, buffer_size); + // Engine 0 always exists; the power effect of a wait is device specific. + const std::optional remote_engine = + ZePeer::remote_wait + ? std::make_optional(ze_peer_devices[remote_device_id].engines[0]) + : std::nullopt; + if (ZePeer::use_immediate_cmdlist) { perform_copy_immediate(test_type, command_list, dst_buffer, src_buffer, - buffer_size); + buffer_size, remote_engine); } else { perform_copy(test_type, command_list, command_queue, dst_buffer, src_buffer, - buffer_size); + buffer_size, remote_engine); } if (validate_results) {