-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL] Add unit test for PR 5414 #5450
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
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
//==------------ Regression.cpp --- Scheduler unit tests -------------------==// | ||
// | ||
// 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 "SchedulerTest.hpp" | ||
#include "SchedulerTestUtils.hpp" | ||
|
||
#include <helpers/CommonRedefinitions.hpp> | ||
#include <helpers/PiMock.hpp> | ||
|
||
using namespace sycl; | ||
|
||
static std::tuple<detail::NDRDescT, detail::Requirement> initializeRefValues() { | ||
detail::NDRDescT NDRDesc; | ||
NDRDesc.GlobalSize = range<3>(1, 2, 3); | ||
NDRDesc.LocalSize = range<3>(1, 1, 1); | ||
|
||
int val; | ||
buffer<int, 1> Buf(&val, range<1>(1)); | ||
detail::Requirement MockReq = getMockRequirement(Buf); | ||
return {NDRDesc, MockReq}; | ||
} | ||
|
||
static pi_result redefinedEnqueueNativeKernel( | ||
pi_queue queue, void (*user_func)(void *), void *args, size_t cb_args, | ||
pi_uint32 num_mem_objects, const pi_mem *mem_list, | ||
const void **args_mem_loc, pi_uint32 num_events_in_wait_list, | ||
const pi_event *event_wait_list, pi_event *event) { | ||
void **CastedBlob = (void **)args; | ||
auto [NDRDesc, MockReq] = initializeRefValues(); | ||
|
||
std::vector<detail::Requirement *> Reqs = | ||
*(static_cast<std::vector<detail::Requirement *> *>(CastedBlob[0])); | ||
EXPECT_EQ(Reqs[0]->MAccessRange[0], MockReq.MAccessRange[0]); | ||
EXPECT_EQ(Reqs[0]->MAccessRange[1], MockReq.MAccessRange[1]); | ||
EXPECT_EQ(Reqs[0]->MAccessRange[2], MockReq.MAccessRange[2]); | ||
|
||
std::unique_ptr<detail::HostKernelBase> *HostKernel = | ||
static_cast<std::unique_ptr<detail::HostKernelBase> *>(CastedBlob[1]); | ||
testing::internal::CaptureStdout(); | ||
(*HostKernel)->call(NDRDesc, nullptr); | ||
std::string Output = testing::internal::GetCapturedStdout(); | ||
EXPECT_EQ(Output, "Blablabla"); | ||
|
||
detail::NDRDescT *NDRDescActual = | ||
static_cast<detail::NDRDescT *>(CastedBlob[2]); | ||
EXPECT_EQ(NDRDescActual->GlobalSize[0], NDRDesc.GlobalSize[0]); | ||
EXPECT_EQ(NDRDescActual->GlobalSize[1], NDRDesc.GlobalSize[1]); | ||
EXPECT_EQ(NDRDescActual->GlobalSize[2], NDRDesc.GlobalSize[2]); | ||
|
||
return PI_SUCCESS; | ||
} | ||
|
||
TEST_F(SchedulerTest, CheckArgsBlobInPiEnqueueNativeKernelIsValid) { | ||
default_selector Selector; | ||
platform Plt{default_selector()}; | ||
if (Plt.is_host()) { | ||
std::cout << "Not run due to host-only environment\n"; | ||
return; | ||
} | ||
|
||
unittest::PiMock Mock{Plt}; | ||
setupDefaultMockAPIs(Mock); | ||
Mock.redefine<detail::PiApiKind::piEnqueueNativeKernel>( | ||
redefinedEnqueueNativeKernel); | ||
|
||
auto Kernel = []() { std::cout << "Blablabla"; }; | ||
detail::HostKernel<decltype(Kernel), void, 1> HKernel(Kernel); | ||
auto [NDRDesc, MockReq] = initializeRefValues(); | ||
|
||
std::unique_ptr<detail::CG> CG{new detail::CGExecKernel( | ||
/*NDRDesc*/ NDRDesc, | ||
/*HKernel*/ | ||
std::make_unique<detail::HostKernel<decltype(Kernel), void, 1>>(HKernel), | ||
/*SyclKernel*/ nullptr, | ||
/*ArgsStorage*/ {}, | ||
/*AccStorage*/ {}, | ||
/*SharedPtrStorage*/ {}, | ||
/*Requirements*/ {&MockReq}, | ||
/*Events*/ {}, | ||
/*Args*/ {}, | ||
/*KernelName*/ "", | ||
/*OSModuleHandle*/ detail::OSUtil::ExeModuleHandle, | ||
/*Streams*/ {}, | ||
/*Type*/ detail::CG::RunOnHostIntel)}; | ||
|
||
context Ctx{Plt}; | ||
queue Queue{Ctx, Selector}; | ||
detail::QueueImplPtr QueueImpl = detail::getSyclObjImpl(Queue); | ||
|
||
detail::ExecCGCommand ExecCGCmd{std::move(CG), QueueImpl}; | ||
detail::EnqueueResultT EnqueueResult = detail::EnqueueResultT( | ||
detail::EnqueueResultT::SyclEnqueueReady, &ExecCGCmd); | ||
std::vector<cl::sycl::detail::Command *> ToCleanUp; | ||
ExecCGCmd.enqueue(EnqueueResult, detail::BlockingT::NON_BLOCKING, ToCleanUp); | ||
} |
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.
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.
Suggest renaming to some descriptive name.
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 think it will be good to have the separate file for all scheduler regressions similar to the folder https://github.com/intel/llvm/tree/sycl/sycl/test/regression
Does it make sense? In this case the file has name Regression.cpp.
Do you have other ideas regarding the name?
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.
the change/fix was to ensure the context was restored when cleaning up when using run-on-host-intel correct? So maybe instead of "regression.cpp" we should call it "RunOnHostIntelCleanupCorrect.cpp" or similar.