-
Notifications
You must be signed in to change notification settings - Fork 797
[SYCL] Test for fix of linked alloca's deps #1470
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
bader
merged 16 commits into
intel:sycl
from
s-kanaev:private/s-kanaev/fix-linked-allocacmd-deps
Aug 3, 2020
Merged
Changes from 12 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d8297bd
[SYCL] Fix linked AllocaCmd dependencies
0d10b3d
Merge branch 'sycl' into private/s-kanaev/fix-linked-allocacmd-deps
5a44580
[SYCL] Add test
49a8909
[SYCL] Fix test
462ee07
[SYCL] Fix test
c8960d8
Merge branch 'sycl' into private/s-kanaev/fix-linked-allocacmd-deps
704fdb0
[SYCL] Add unit-test
0abc928
[SYCL] Fix lit test
e84cad7
[SYCL] Fix style issue
fa0dda4
[SYCL] Fix style issue
658b057
[SYCL] Fix lit test
107fe7f
[SYCL] Apply suggestion
83e7688
Merge branch 'sycl' into private/s-kanaev/fix-linked-allocacmd-deps
897b1b1
[SYCL] Remove redundant test
b85c3df
Merge remote-tracking branch 'public/sycl' into private/s-kanaev/fix-…
ba8a54d
[SYCL] Fix testing
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,85 @@ | ||
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -I %sycl_source_dir %s -o %t.out | ||
// RUN: env SYCL_PRINT_EXECUTION_GRAPH=always %t.out | ||
// RUN: cat graph_7after_addHostAccessor.dot | ||
// RUN: cat graph_7after_addHostAccessor.dot | FileCheck %s | ||
|
||
#include <CL/sycl.hpp> | ||
|
||
namespace S = cl::sycl; | ||
|
||
void test() { | ||
auto EH = [](S::exception_list EL) { | ||
for (const std::exception_ptr &E : EL) { | ||
throw E; | ||
} | ||
}; | ||
|
||
S::queue Queue(EH); | ||
|
||
static const size_t BSIZE = 10; | ||
S::buffer<int, 1> Buf{BSIZE}; | ||
|
||
// 0. submit kernel | ||
Queue.submit([&](S::handler &CGH) { | ||
S::accessor<int, 1, S::access::mode::write, | ||
S::access::target::global_buffer> | ||
GeneratorAcc(Buf, CGH); | ||
|
||
auto GeneratorKernel = [GeneratorAcc]() { | ||
for (size_t Idx = 0; Idx < GeneratorAcc.get_count(); ++Idx) | ||
GeneratorAcc[Idx] = BSIZE - Idx; | ||
}; | ||
|
||
CGH.single_task<class GeneratorTask0>(GeneratorKernel); | ||
}); | ||
// 1. create host-accessor | ||
{ | ||
S::accessor<int, 1, S::access::mode::write, | ||
S::access::target::host_buffer> | ||
Acc(Buf); | ||
|
||
for (size_t Idx = 0; Idx < Acc.get_count(); ++Idx) | ||
Acc[Idx] = -1; | ||
} | ||
|
||
// 2. submit kernel | ||
Queue.submit([&](S::handler &CGH) { | ||
S::accessor<int, 1, S::access::mode::write, | ||
S::access::target::global_buffer> | ||
GeneratorAcc(Buf, CGH); | ||
|
||
auto GeneratorKernel = [GeneratorAcc]() { | ||
s-kanaev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for (size_t Idx = 0; Idx < GeneratorAcc.get_count(); ++Idx) | ||
GeneratorAcc[Idx] = Idx; | ||
}; | ||
|
||
CGH.single_task<class GeneratorTask>(GeneratorKernel); | ||
}); | ||
|
||
// 3. create host-accessor | ||
{ | ||
S::accessor<int, 1, S::access::mode::write, | ||
S::access::target::host_buffer> | ||
Acc(Buf); | ||
|
||
bool Failure = false; | ||
for (size_t Idx = 0; Idx < Acc.get_count(); ++Idx) { | ||
fprintf(stderr, "Buffer [%03zu] = %i\n", Idx, Acc[Idx]); | ||
Failure |= (Acc[Idx] != Idx); | ||
} | ||
|
||
assert(!Failure || "Invalid data in buffer"); | ||
} | ||
} | ||
|
||
int main(void) { | ||
test(); | ||
|
||
return 0; | ||
} | ||
|
||
// CHECK: {{^}}"[[MAP_OP:0x[0-9a-fA-F]+]]"{{.*}} MAP ON | ||
// CHECK-DAG: "[[MAP_OP]]" -> "[[MAP_DEP_1:0x[0-9a-fA-F]+]]" | ||
// CHECK-DAG: "[[MAP_OP]]" -> "[[MAP_DEP_2:0x[0-9a-fA-F]+]]" | ||
// CHECK-DAG: {{^}}"[[MAP_DEP_1]]"{{.*}}\nEXEC CG ON | ||
// CHECK-DAG: {{^}}"[[MAP_DEP_2]]"{{.*}}\nALLOCA ON HOST |
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,96 @@ | ||
//==------ LinkedAllocaDependencies.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" | ||
|
||
using namespace cl::sycl; | ||
|
||
class MemObjMock : public cl::sycl::detail::SYCLMemObjI { | ||
public: | ||
using ContextImplPtr = std::shared_ptr<cl::sycl::detail::context_impl>; | ||
|
||
MemObjMock(const std::shared_ptr<cl::sycl::detail::MemObjRecord> &Record) | ||
: SYCLMemObjI() { | ||
MRecord = Record; | ||
} | ||
|
||
~MemObjMock() = default; | ||
|
||
MemObjType getType() const override { return MemObjType::BUFFER; } | ||
|
||
void *allocateMem(ContextImplPtr, bool, void *, | ||
cl::sycl::detail::pi::PiEvent &) { | ||
return nullptr; | ||
} | ||
|
||
void *allocateHostMem() { return nullptr; } | ||
void releaseMem(ContextImplPtr, void *) {} | ||
void releaseHostMem(void *) {} | ||
size_t getSize() const override { return 10; } | ||
}; | ||
|
||
TEST_F(SchedulerTest, LinkedAllocaDependencies) { | ||
default_selector Selector{}; | ||
if (Selector.select_device().is_host()) { | ||
std::cerr << "Not run due to host-only environment\n"; | ||
return; | ||
} | ||
|
||
// 1. create two commands: alloca + alloca and link them | ||
// 2. call Scheduler::GraphBuilder::getOrCreateAllocaForReq | ||
detail::Requirement Req = getMockRequirement(); | ||
|
||
cl::sycl::queue Queue1; | ||
cl::sycl::detail::QueueImplPtr Q1 = cl::sycl::detail::getSyclObjImpl(Queue1); | ||
|
||
sycl::device HostDevice; | ||
std::shared_ptr<detail::queue_impl> DefaultHostQueue(new detail::queue_impl( | ||
detail::getSyclObjImpl(HostDevice), /*AsyncHandler=*/{}, | ||
detail::QueueOrder::Ordered, /*PropList=*/{})); | ||
|
||
std::shared_ptr<cl::sycl::detail::MemObjRecord> Record{ | ||
new cl::sycl::detail::MemObjRecord(DefaultHostQueue->getContextImplPtr(), | ||
10)}; | ||
|
||
MemObjMock MemObj(Record); | ||
Req.MSYCLMemObj = &MemObj; | ||
|
||
cl::sycl::detail::AllocaCommand AllocaCmd1(DefaultHostQueue, Req, false); | ||
Record->MAllocaCommands.push_back(&AllocaCmd1); | ||
|
||
MockCommand DepCmd(DefaultHostQueue, Req); | ||
MockCommand DepDepCmd(DefaultHostQueue, Req); | ||
DepCmd.MDeps.push_back({&DepDepCmd, DepDepCmd.getRequirement(), &AllocaCmd1}); | ||
DepDepCmd.MUsers.insert(&DepCmd); | ||
Record->MWriteLeaves.push_back(&DepCmd); | ||
|
||
MockScheduler MS; | ||
cl::sycl::detail::Command *AllocaCmd2 = | ||
MS.getOrCreateAllocaForReq(Record.get(), &Req, Q1); | ||
|
||
ASSERT_TRUE(!!AllocaCmd1.MLinkedAllocaCmd) | ||
<< "No link appeared in existing command"; | ||
ASSERT_EQ(AllocaCmd1.MLinkedAllocaCmd, AllocaCmd2) << "Invalid link appeared"; | ||
ASSERT_GT(AllocaCmd1.MUsers.count(AllocaCmd2), 0u) | ||
<< "New alloca isn't in users of the old one"; | ||
ASSERT_GT(AllocaCmd2->MDeps.size(), 1u) | ||
<< "No deps appeared in the new alloca"; | ||
ASSERT_GT(DepCmd.MUsers.count(AllocaCmd2), 0u) | ||
<< "No deps appeared for leaves of record (i.e. deps of existing alloca)"; | ||
ASSERT_TRUE(std::find_if(AllocaCmd2->MDeps.begin(), AllocaCmd2->MDeps.end(), | ||
[&](const cl::sycl::detail::DepDesc &Dep) -> bool { | ||
return Dep.MDepCommand == &AllocaCmd1; | ||
}) != AllocaCmd2->MDeps.end()) | ||
<< "No deps for existing alloca appeared in new alloca"; | ||
ASSERT_TRUE(std::find_if(AllocaCmd2->MDeps.begin(), AllocaCmd2->MDeps.end(), | ||
[&](const cl::sycl::detail::DepDesc &Dep) -> bool { | ||
return Dep.MDepCommand == &DepCmd; | ||
}) != AllocaCmd2->MDeps.end()) | ||
<< "No deps for leaves (deps of existing alloca) appeared in new alloca"; | ||
} |
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
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.