-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL] Fix USM event clearing when calling queue::wait() #1959
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
add_sycl_unittest(QueueTests OBJECT | ||
wait.cpp | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
//==----------------- wait.cpp --- queue wait unit test --------------------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include <CL/sycl.hpp> | ||
#include <detail/context_impl.hpp> | ||
#include <gtest/gtest.h> | ||
#include <helpers/PiMock.hpp> | ||
|
||
using namespace cl::sycl; | ||
|
||
struct TestCtx { | ||
TestCtx(context &Ctx) : Ctx{Ctx} {}; | ||
|
||
context &Ctx; | ||
int NEventsWaitedFor = 0; | ||
}; | ||
|
||
std::unique_ptr<TestCtx> TestContext; | ||
|
||
pi_result redefinedUSMEnqueueMemset(pi_queue queue, void *ptr, pi_int32 value, | ||
size_t count, | ||
pi_uint32 num_events_in_waitlist, | ||
const pi_event *events_waitlist, | ||
pi_event *event) { | ||
// Provide a dummy non-nullptr value | ||
*event = reinterpret_cast<pi_event>(1); | ||
return PI_SUCCESS; | ||
} | ||
|
||
pi_result redefinedEventsWait(pi_uint32 num_events, | ||
const pi_event *event_list) { | ||
++TestContext->NEventsWaitedFor; | ||
return PI_SUCCESS; | ||
} | ||
|
||
pi_result redefinedEventGetInfo(pi_event event, pi_event_info param_name, | ||
size_t param_value_size, void *param_value, | ||
size_t *param_value_size_ret) { | ||
EXPECT_EQ(param_name, PI_EVENT_INFO_CONTEXT) | ||
<< "Unexpected event info requested"; | ||
auto *Result = reinterpret_cast<RT::PiContext *>(param_value); | ||
RT::PiContext PiCtx = | ||
detail::getSyclObjImpl(TestContext->Ctx)->getHandleRef(); | ||
*Result = PiCtx; | ||
return PI_SUCCESS; | ||
} | ||
|
||
pi_result redefinedEventRetain(pi_event event) { return PI_SUCCESS; } | ||
|
||
pi_result redefinedEventRelease(pi_event event) { return PI_SUCCESS; } | ||
|
||
// Check that the USM events are cleared from the queue upon call to wait(), | ||
// so that they are not waited for multiple times. | ||
TEST(QueueWaitTest, USMEventClear) { | ||
platform Plt{default_selector()}; | ||
if (Plt.is_host()) { | ||
std::cout << "Not run on host - no PI events created in that case" | ||
<< std::endl; | ||
return; | ||
} | ||
|
||
// TODO: Skip test for CUDA temporarily | ||
if (detail::getSyclObjImpl(Plt)->getPlugin().getBackend() == backend::cuda) { | ||
alexbatashev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
std::cout << "Not run on CUDA - usm is not supported for CUDA backend yet" | ||
<< std::endl; | ||
return; | ||
} | ||
|
||
unittest::PiMock Mock{Plt}; | ||
Mock.redefine<detail::PiApiKind::piextUSMEnqueueMemset>( | ||
redefinedUSMEnqueueMemset); | ||
Mock.redefine<detail::PiApiKind::piEventsWait>(redefinedEventsWait); | ||
Mock.redefine<detail::PiApiKind::piEventGetInfo>(redefinedEventGetInfo); | ||
Mock.redefine<detail::PiApiKind::piEventRetain>(redefinedEventRetain); | ||
Mock.redefine<detail::PiApiKind::piEventRelease>(redefinedEventRelease); | ||
|
||
context Ctx{Plt}; | ||
TestContext.reset(new TestCtx(Ctx)); | ||
queue Q{Ctx, default_selector()}; | ||
|
||
unsigned char *HostAlloc = (unsigned char *)malloc_host(1, Ctx); | ||
Q.memset(HostAlloc, 42, 1); | ||
sergey-semenov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Q.wait(); | ||
ASSERT_EQ(TestContext->NEventsWaitedFor, 1); | ||
Q.wait(); | ||
ASSERT_EQ(TestContext->NEventsWaitedFor, 1); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.