-
Notifications
You must be signed in to change notification settings - Fork 124
Fix adding event to queue cache #1549
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
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| // Copyright (C) 2024 Intel Corporation | ||
| // Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See LICENSE.TXT | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #include "ur_print.hpp" | ||
| #include "uur/fixtures.h" | ||
| #include "uur/raii.h" | ||
|
|
||
| #include <map> | ||
| #include <string> | ||
|
|
||
| template <typename... Args> auto combineFlags(std::tuple<Args...> tuple) { | ||
| return std::apply([](auto... args) { return (... |= args); }, tuple); | ||
| } | ||
|
|
||
| extern std::map<std::string, int> *ZeCallCount; | ||
|
|
||
| using FlagsTupleType = std::tuple<ur_queue_flags_t, ur_queue_flags_t, | ||
| ur_queue_flags_t, ur_queue_flags_t>; | ||
|
|
||
| struct urEventCacheTest : uur::urContextTestWithParam<FlagsTupleType> { | ||
| void SetUp() override { | ||
| UUR_RETURN_ON_FATAL_FAILURE(urContextTestWithParam::SetUp()); | ||
|
|
||
| flags = combineFlags(getParam()); | ||
|
|
||
| ur_queue_properties_t props; | ||
| props.flags = flags; | ||
| ASSERT_SUCCESS(urQueueCreate(context, device, &props, &queue)); | ||
| ASSERT_NE(queue, nullptr); | ||
|
|
||
| ASSERT_SUCCESS(urMemBufferCreate(context, UR_MEM_FLAG_WRITE_ONLY, size, | ||
| nullptr, &buffer)); | ||
|
|
||
| (*ZeCallCount)["zeEventCreate"] = 0; | ||
| (*ZeCallCount)["zeEventDestroy"] = 0; | ||
| } | ||
|
|
||
| void TearDown() override { | ||
| if (buffer) { | ||
| EXPECT_SUCCESS(urMemRelease(buffer)); | ||
| } | ||
| if (queue) { | ||
| UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urQueueRelease(queue)); | ||
| } | ||
| UUR_RETURN_ON_FATAL_FAILURE(urContextTestWithParam::TearDown()); | ||
| } | ||
|
|
||
| auto enqueueWork(ur_event_handle_t *hEvent, int data) { | ||
| input.assign(count, data); | ||
| UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urEnqueueMemBufferWrite( | ||
| queue, buffer, false, 0, size, input.data(), 0, nullptr, hEvent)); | ||
| } | ||
|
|
||
| void verifyData() { | ||
| std::vector<uint32_t> output(count, 1); | ||
| UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urEnqueueMemBufferRead( | ||
| queue, buffer, true, 0, size, output.data(), 0, nullptr, nullptr)); | ||
|
|
||
| if (!(flags & UR_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE)) { | ||
| ASSERT_EQ(input, output); | ||
| } | ||
| } | ||
|
|
||
| const size_t count = 1024; | ||
| const size_t size = sizeof(uint32_t) * count; | ||
| ur_mem_handle_t buffer = nullptr; | ||
| ur_queue_handle_t queue = nullptr; | ||
| std::vector<uint32_t> input; | ||
| ur_queue_flags_t flags; | ||
| }; | ||
|
|
||
| TEST_P(urEventCacheTest, eventsReuseNoVisibleEvent) { | ||
| static constexpr int numIters = 16; | ||
| static constexpr int numEnqueues = 128; | ||
|
|
||
| for (int i = 0; i < numIters; i++) { | ||
| for (int j = 0; j < numEnqueues; j++) { | ||
| enqueueWork(nullptr, i * numEnqueues + j); | ||
| } | ||
| UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urQueueFinish(queue)); | ||
| verifyData(); | ||
| } | ||
|
|
||
| // TODO: why events are not reused for UR_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE? | ||
| if ((flags & UR_QUEUE_FLAG_DISCARD_EVENTS) && | ||
| !(flags & UR_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE)) { | ||
| ASSERT_EQ((*ZeCallCount)["zeEventCreate"], 2); | ||
| } else { | ||
| ASSERT_GE((*ZeCallCount)["zeEventCreate"], numIters * numEnqueues); | ||
| } | ||
| } | ||
|
|
||
| TEST_P(urEventCacheTest, eventsReuseWithVisibleEvent) { | ||
| static constexpr int numIters = 16; | ||
| static constexpr int numEnqueues = 128; | ||
|
|
||
| for (int i = 0; i < numIters; i++) { | ||
| std::vector<uur::raii::Event> events(numEnqueues); | ||
| for (int j = 0; j < numEnqueues; j++) { | ||
| enqueueWork(events[j].ptr(), i * numEnqueues + j); | ||
| } | ||
| UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urQueueFinish(queue)); | ||
| verifyData(); | ||
| } | ||
|
|
||
| ASSERT_LT((*ZeCallCount)["zeEventCreate"], numIters * numEnqueues); | ||
| } | ||
|
|
||
| TEST_P(urEventCacheTest, eventsReuseWithVisibleEventAndWait) { | ||
| static constexpr int numIters = 16; | ||
| static constexpr int numEnqueues = 128; | ||
| static constexpr int waitEveryN = 16; | ||
|
|
||
| for (int i = 0; i < numIters; i++) { | ||
| std::vector<uur::raii::Event> events; | ||
| for (int j = 0; j < numEnqueues; j++) { | ||
| events.emplace_back(); | ||
| enqueueWork(events.back().ptr(), i * numEnqueues + j); | ||
|
|
||
| if (j > 0 && j % waitEveryN == 0) { | ||
| ASSERT_SUCCESS(urEventWait(waitEveryN, | ||
| (ur_event_handle_t *)events.data())); | ||
| verifyData(); | ||
| events.clear(); | ||
| } | ||
| } | ||
| UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urQueueFinish(queue)); | ||
| } | ||
|
|
||
| ASSERT_GE((*ZeCallCount)["zeEventCreate"], waitEveryN); | ||
| // TODO: why there are more events than this? | ||
| // ASSERT_LE((*ZeCallCount)["zeEventCreate"], waitEveryN * 2 + 2); | ||
| } | ||
|
|
||
| template <typename T> | ||
| inline std::string | ||
| printFlags(const testing::TestParamInfo<typename T::ParamType> &info) { | ||
| const auto device_handle = std::get<0>(info.param); | ||
| const auto platform_device_name = | ||
| uur::GetPlatformAndDeviceName(device_handle); | ||
| auto flags = combineFlags(std::get<1>(info.param)); | ||
|
|
||
| std::stringstream ss; | ||
| ur::details::printFlag<ur_queue_flag_t>(ss, flags); | ||
|
|
||
| auto str = ss.str(); | ||
| std::replace(str.begin(), str.end(), ' ', '_'); | ||
| std::replace(str.begin(), str.end(), '|', '_'); | ||
| return platform_device_name + "__" + str; | ||
| } | ||
|
|
||
| UUR_TEST_SUITE_P( | ||
| urEventCacheTest, | ||
| ::testing::Combine( | ||
| testing::Values(0, UR_QUEUE_FLAG_DISCARD_EVENTS), | ||
| testing::Values(0, UR_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE), | ||
| // TODO: why the test fails with UR_QUEUE_FLAG_SUBMISSION_BATCHED? | ||
|
Contributor
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. with what combination of the flags? The discard events path doesn't seem that well tested, so it's not inconceivable that's its broken when a few different flags are set.
Contributor
Author
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. Well... every combination. Now, I'm getting a segfault from
Contributor
Author
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. I rerun this on the latest driver and everything works fine there so I guess we can just uncomment this once we switch our CI to the newer driver. |
||
| testing::Values( | ||
| UR_QUEUE_FLAG_SUBMISSION_IMMEDIATE /*, UR_QUEUE_FLAG_SUBMISSION_BATCHED */), | ||
| testing::Values(0, UR_QUEUE_FLAG_PROFILING_ENABLE)), | ||
| printFlags<urEventCacheTest>); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // Copyright (C) 2024 Intel Corporation | ||
| // Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See LICENSE.TXT | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #include <map> | ||
| #include <string> | ||
|
|
||
| // Map used by L0 adapter to count the number of calls to each L0 function | ||
| // Lifetime is managed by the adapter, this variable is defined here | ||
| // only so that we can read it from the tests. | ||
| std::map<std::string, int> *ZeCallCount = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't like this. #1454 is meant to give programmatic access to internals like this in tests. So please add a TODO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.