Skip to content
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

[SYCL] Host task implementation #1471

Merged
merged 195 commits into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
195 commits
Select commit Hold shift + click to select a range
b31cb8e
[SYCL] Allow for creating host accessor without blocked event.
Mar 2, 2020
f3bf37a
[SYCL] Tests for host/interop task
Feb 26, 2020
faded84
[SYCL] Remove unused parameter
Mar 2, 2020
253086f
[SYCL] Some syntax improvements
Mar 3, 2020
cacb056
[SYCL] Sample impl of host task through event
Mar 4, 2020
37106ea
Merge branch 'sycl' into private/s-kanaev/interop-task
Mar 5, 2020
1a79e3f
[SYCL] Sample implementation without OpenCL specific calls.
Mar 6, 2020
9057a23
Merge branch 'sycl' into private/s-kanaev/interop-task
Mar 6, 2020
93cffcc
[SYCL] Only leave event-callback
Mar 6, 2020
3790b3a
[SYCL] Fix typo
Mar 10, 2020
4255434
Merge branch 'sycl' into private/s-kanaev/event-callback
Mar 10, 2020
dc0ab02
[SYCL] Allow for running lit-tests with threads.
Mar 10, 2020
0d95eaa
Merge branch 'sycl' into private/s-kanaev/event-callback
Mar 11, 2020
f0df349
[SYCL] A more sophisticated thread pool impl
Mar 11, 2020
ea577f6
[SYCL] Proper use of fork() in assertion test
Mar 12, 2020
99f64fb
[SYCL] Fix style issue
Mar 12, 2020
9c8b1a1
Merge branch 'sycl' into private/s-kanaev/event-callback
Mar 12, 2020
529d4dc
[SYCL] Fix some typos. Lazy initialization of thread pool.
Mar 12, 2020
4d04655
[SYCL] Employ event::when_complete instead of piEventSetCallback
Mar 13, 2020
1e3bfe4
[SYCL] Host-task test
Mar 13, 2020
fc70b03
[SYCL] Remove unwanted include
Mar 13, 2020
1429f9d
Merge branch 'sycl' into private/s-kanaev/event-callback
Mar 16, 2020
eaaefd3
[SYCL] Worked on host-task
Mar 18, 2020
1172ca1
Merge branch 'sycl' into private/s-kanaev/event-callback
Mar 20, 2020
9f3d2d4
[SYCL] Reimplement event::when_complete through host_task
Mar 23, 2020
92917a0
[SYCL] Worked on host task
Mar 26, 2020
578d422
Merge branch 'sycl' into private/s-kanaev/event-callback
Mar 26, 2020
8e3dcd8
[SYCL] Fix merge issue
Mar 27, 2020
2c2c713
Merge branch 'sycl' into private/s-kanaev/event-callback
Mar 27, 2020
14458e3
[SYCL] Fix assert test
Mar 29, 2020
a9ad4df
Merge branch 'sycl' into private/s-kanaev/event-callback
Mar 29, 2020
dde6af5
[SYCL] Event for host-task
Mar 30, 2020
e4c6764
[SYCL] Add test stub
Mar 30, 2020
eb71004
[SYCL] Distinct command for host task representation.
Mar 31, 2020
90cac7c
[SYCL] Depend device alloca cmd on cg's operating with linked host al…
Apr 1, 2020
1473f5d
[SYCL] Remove spare code. Wait for dependency events.
Apr 1, 2020
bfb0572
[SYCL] Remove spare code
Apr 1, 2020
9f68320
[SYCL] Fix code-style issue
Apr 1, 2020
442f905
[SYCL] Move handling of multiple contexts out of Command::prepareEven…
Apr 2, 2020
380b009
[SYCL] Output values in test
Apr 3, 2020
cee7e47
[SYCL] Add CHECK-sequence to test
Apr 3, 2020
b9003dc
[SYCL] Eliminate use of event callback during glue-ing of events from…
Apr 3, 2020
667729d
[SYCL] Fix some comments
Apr 3, 2020
072a850
[SYCL] Eliminate HostTaskCommand
Apr 3, 2020
c65759d
Merge branch 'sycl' into private/s-kanaev/event-callback
Apr 3, 2020
40f4a32
[SYCL] Fix codestyle issues
Apr 6, 2020
d7fe436
[SYCL] Fix runtime issue
Apr 7, 2020
89d6b44
[SYCL] Fix codestyle issue
Apr 7, 2020
08b31f5
Merge branch 'sycl' into private/s-kanaev/event-callback
Apr 8, 2020
9f97076
Merge branch 'sycl' into private/s-kanaev/event-callback
Apr 9, 2020
6537bb4
[SYCL] Fix typo in sycl/source/detail/queue_impl.hpp
s-kanaev Apr 9, 2020
5388fd4
Merge branch 'sycl' into private/s-kanaev/event-callback
Apr 13, 2020
7ce22fe
[SYCL] Fix some review comments
Apr 13, 2020
a23c167
[SYCL] Fix indentation
Apr 13, 2020
fc10c6a
[SYCL] Remove unrelated change
Apr 14, 2020
e326ed0
[SYCL] Eliminate Command::prepareEvents()
Apr 14, 2020
d046775
[SYCL] Add empty command/node right after host-task
Apr 15, 2020
cf3bbf3
[NFC] [SYCL] Shift DispatchHostTask lambda to functor to reduce size …
Apr 15, 2020
35fdcde
[SYCL] Eliminate use of addCG when connecting multiple context.
Apr 15, 2020
427c81d
[SYCL] Fix indentation
Apr 15, 2020
1cc0885
Merge branch 'sycl' into private/s-kanaev/event-callback
Apr 15, 2020
9a936ee
[SYCL] Fix build issue
Apr 16, 2020
82296ec
Merge branch 'sycl' into private/s-kanaev/event-callback
Apr 16, 2020
a1c23d5
[SYCL] Add empty command for connecting command
Apr 16, 2020
8427b4a
[NFC] [SYCL] Split method into smaller ones
Apr 16, 2020
ff03307
[SYCL] Fix build issue
Apr 16, 2020
49ed81e
[SYCL] Remove unneeded line
Apr 16, 2020
d3a5cf9
[SYCL] Worked on fixing of race condition.
Apr 17, 2020
32f2f1b
[SYCL] Fix runtime issue. Remove debug outputs.
Apr 19, 2020
cb10eca
[SYCL] Remove '#if 1'
Apr 19, 2020
58246a7
[SYCL] Don't store context in CGHostTask. Remove commented code
Apr 19, 2020
96e4d4b
[SYCL] Fix some review comments.
Apr 19, 2020
30156f2
[SYCL] Remove unneeded code.
Apr 19, 2020
269319d
[NFC] [SYCL] Fix codestyle issues
Apr 19, 2020
212a484
[NFC] [SYCL] Remove unused code
Apr 19, 2020
881f5c9
Merge branch 'sycl' into private/s-kanaev/event-callback
Apr 19, 2020
07133a7
[NFC] [SYCL] Fix codestyle issues
Apr 19, 2020
8a6ee30
[NFC] [SYCL] Fix codestyle issue
Apr 20, 2020
ff5023c
[SYCL] Employ a hack to prevent invalid read in some cases
Apr 20, 2020
8a567ba
[SYCL] Enqueue dependant commands.
Apr 20, 2020
dd4ac89
[SYCL] Worked on fixing runtime issue
Apr 21, 2020
0724914
[SYCL] Modify test
Apr 21, 2020
2e3fbe1
[SYCL] Worked on fixing runtime issue
Apr 21, 2020
0465f2a
[SYCL] Fix test
Apr 21, 2020
c4ab0f1
[SYCL] Fix codestyle issue
Apr 21, 2020
741e257
[SYCL] Fix test
Apr 22, 2020
d00f031
[SYCL] Slight fix
Apr 22, 2020
2f2abf3
Merge branch 'sycl' into private/s-kanaev/event-callback
Apr 22, 2020
b4a2a47
[SYCL] Revert patch of test for assert
Apr 22, 2020
092d887
[NFC] [SYCL] Add description of new environment variable.
Apr 22, 2020
05a6558
[SYCL] Fix windows build.
Apr 22, 2020
b193031
[SYCL] Init buffer with proper data
Apr 22, 2020
a04c01f
[SYCL] Convert back to single MBlockedCmd in requirement
Apr 24, 2020
410654b
[SYCL] Address comments:
Apr 24, 2020
bad3845
[SYCL] Remove unused code
Apr 24, 2020
6ae8754
[SYCL] Throw 'out of host memory' exception upon failed allocation of…
Apr 24, 2020
67a98e0
[SYCL] Fix typo
Apr 24, 2020
b12d9ee
[SYCL] Don't store empty command in blocked cmds of requirement upon …
Apr 24, 2020
931128b
[SYCL] Fix runtime issue. Make code look cleaner.
Apr 24, 2020
72dbfa3
Merge branch 'sycl' into private/s-kanaev/event-callback
Apr 24, 2020
5ee3ba5
[SYCL] Fix style issue
Apr 24, 2020
14a47a2
[SYCL] Add comment
Apr 27, 2020
038495f
[SYCL] Eliminate explicit calls to setComplete() in users of EmptyCom…
Apr 27, 2020
083abeb
[SYCL] Enforce asserts in event_impl::setComplete()
Apr 27, 2020
c929d8b
[SYCL] Employ piEventSetStatus in event_impl::setComplete().
Apr 27, 2020
1674878
[SYCL] Address some review comments.
Apr 27, 2020
f41a605
[SYCL] Move some mthods from Command to Scheduler::GraphBuilder
Apr 27, 2020
857d433
[SYCL] Simpify DispatchHostTask::findUserEmptyCommand() method.
Apr 28, 2020
faf3fa1
[SYCL] Simplify loop
Apr 28, 2020
02c4cad
[SYCL] Remove unwanted changes from lit.cfg.py
Apr 28, 2020
5d15247
[SYCL] Remove unwanted change.
Apr 28, 2020
e366310
[SYCL] Resolve style issues
Apr 28, 2020
2b1335b
[SYCL] Rename HOST_TASK_CODEPLAY to CODEPLAY_HOST_TASK
Apr 28, 2020
d9ec78a
[SYCL] Fix build issue
Apr 28, 2020
0e38582
[SYCL] Move changes in addCG to distinct function.
Apr 28, 2020
1b62aed
[SYCL] Fix build issue
Apr 28, 2020
deb3e67
[SYCL] Remove unneeded comment
Apr 28, 2020
eaa8005
[SYCL] Fix runtime issue.
Apr 28, 2020
36dffd9
[SYCL] Remove unwanted changes
Apr 28, 2020
37917a7
[SYCL] Wait for host events in first place
Apr 28, 2020
eab005d
[SYCL] Employ common wait mechanism upon enqueueing command for waiting.
Apr 28, 2020
239afd8
Revert "[SYCL] Remove unwanted changes"
Apr 28, 2020
e73f49f
[SYCL] Stylistic issue
Apr 28, 2020
c96566d
[SYCL] Update state of event upon setting of context
Apr 28, 2020
68c6cc8
[SYCL] Fix race-condition
Apr 28, 2020
13fa22b
[SYCL] Fix sporadic segfault in scheduler
Apr 28, 2020
c77f7f9
[SYCL] Properly release resources in scheduler unit-test
Apr 28, 2020
9d3d186
Merge branch 'sycl' into private/s-kanaev/event-callback
Apr 28, 2020
78e032c
[SYCL] Fix style issue
Apr 28, 2020
4216af1
[SYCL] Fix build issue (merge glitch).
Apr 29, 2020
ece3bcb
[SYCL] Fix build issue (merge glitch).
Apr 29, 2020
565bd83
[SYCL] Fix build issue (merge glitch).
Apr 29, 2020
30321a1
[SYCL] Employ C++14 feature in thread pool.
Apr 29, 2020
14c9476
[SYCL] Fix ABI test
Apr 29, 2020
a17d607
[SYCL] Set pi trace level
Apr 29, 2020
7caf17b
[SYCL] Fix ABI test.
Apr 29, 2020
b6b924c
Revert "Revert "[SYCL] Remove unwanted changes""
Apr 29, 2020
a30c3a0
[SYCL] Remove redundant test
Apr 29, 2020
fc847dd
Merge branch 'sycl' into private/s-kanaev/event-callback
Apr 29, 2020
b3efd81
[SYCL] Fix style issue
Apr 29, 2020
17a9faf
[SYCL] Update test
Apr 29, 2020
2f6af3b
[SYCL] Runtime fixes
Apr 29, 2020
c309777
Revert "[SYCL] Remove unwanted changes"
Apr 30, 2020
aa4c679
[SYCL] Fix runtime issue for linked alloca deps
Apr 30, 2020
8b6b04e
Merge branch 'sycl' into private/s-kanaev/event-callback2
Apr 30, 2020
a4bc8f0
[SYCL] Fix merge glitch
Apr 30, 2020
462163e
Merge branch 'sycl' into private/s-kanaev/event-callback
May 6, 2020
4a8de92
[SYCL] Fix merge glitch
May 6, 2020
16ca481
[SYCL] Fix typo
May 6, 2020
294bd9d
[SYCL] A more proper way to unchaining deps of linked alloca's
May 6, 2020
c094e9a
[SYCL] Fix another race-condition.
May 6, 2020
06f3c5e
Merge branch 'sycl' into private/s-kanaev/event-callback
May 7, 2020
ba3d009
[SYCL] Address some review comments.
May 7, 2020
6052e85
[SYCL] Set proper target tripple in test
May 7, 2020
471fb78
[SYCL] Employ std::future properly in the test
May 7, 2020
ab49e2a
[SYCL] Store command in DispatchHostTask instead of a lot of fields.
May 7, 2020
e44ad31
[SYCL] Resolve style issue
May 7, 2020
b2aaee1
[SYCL] Employ addEmptyCmd whilst creating host accessor.
May 8, 2020
bc2a4df
[SYCL] Pass less arguments to GraphBuilder::connectDepEvent
May 8, 2020
68da219
[SYCL] Fix build issue
May 8, 2020
126cc32
[SYCL] Rewrite GraphBuilder::connectDepEvent in a clearer way.
May 8, 2020
45df093
[SYCL] Fix build issue
May 8, 2020
1542f8a
[SYCL] Add comment on work of GraphBuilder::connectDepEvent.
May 8, 2020
3d8b054
[SYCL] Uplift dev version
May 8, 2020
1cdc04f
[SYCL] Fix style issue
May 8, 2020
f900e6e
[SYCL] Removed reset
May 8, 2020
76da746
Revert "[SYCL] Removed reset"
May 8, 2020
168beb2
[SYCL] Address review comments.
May 10, 2020
14b9232
[SYCL] Address review comments.
May 11, 2020
e47a093
[SYCL] Address review comments.
May 11, 2020
2c28361
Merge branch 'sycl' into private/s-kanaev/event-callback
May 11, 2020
2aab6a1
[SYCL] Employ only read-lock while enqueueing recently added command.
May 12, 2020
053a4c3
[SYCL] Fix race-condition
May 12, 2020
89bd48b
[SYCL] Remove unneeded code.
May 12, 2020
5fa2789
[SYCL] Set proper reason for blocking of empty cmd
May 8, 2020
2dc3564
[SYCL] Make ConnectCmd depend on requirement
May 8, 2020
316e983
[SYCL] Don't depend on host task command explicitly.
May 13, 2020
b93675c
[SYCL] Fix deadlock.
May 13, 2020
52456ce
[SYCL] Add another test
May 13, 2020
40659d7
Merge branch 'sycl' into private/s-kanaev/event-callback
May 13, 2020
b8f47ce
[SYCL] Fix style issues
May 13, 2020
5b0d040
[SYCL] Fix style issue
May 14, 2020
f7c890e
[SYCL] Remove FileCheck use.
May 14, 2020
0480731
[SYCL] Fix segfault caused by missed dependency
May 14, 2020
066504e
[SYCL] Fix assertion triggering. Return reference to command group in…
May 14, 2020
9e76b68
[SYCL] Update test
May 14, 2020
6e123c4
[SYCL] Fix style issue
May 14, 2020
74282e0
[SYCL] Address comments.
May 15, 2020
90f73c4
Merge branch 'sycl' into private/s-kanaev/event-callback
May 18, 2020
b4ab2f2
[SYCL] Eliminate for-loop whilst constructing deps of connect-cmd
May 18, 2020
64d6ba8
[SYCL] Reword construction of a vector
May 18, 2020
692bf79
[SYCL] Reword comments
May 18, 2020
6f3b4d7
[SYCL] Eliminate const_cast
May 18, 2020
5d2635b
[SYCL] Fix style issues
May 18, 2020
efd1495
[SYCL] Fix style issues
May 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sycl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ option(SYCL_ADD_DEV_VERSION_POSTFIX "Adds -V postfix to version string" ON)
set(SYCL_MAJOR_VERSION 1)
set(SYCL_MINOR_VERSION 0)
set(SYCL_PATCH_VERSION 0)
set(SYCL_DEV_ABI_VERSION 2)
set(SYCL_DEV_ABI_VERSION 1)
if (SYCL_ADD_DEV_VERSION_POSTFIX)
set(SYCL_VERSION_POSTFIX "-${SYCL_DEV_ABI_VERSION}")
endif()
Expand Down
5 changes: 3 additions & 2 deletions sycl/include/CL/sycl/detail/cg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ class HostTask {
std::function<void()> MHostTask;

public:
HostTask() : MHostTask([]() {}) {}
HostTask(std::function<void()> &&Func) : MHostTask(Func) {}

void call() { MHostTask(); }
Expand Down Expand Up @@ -400,8 +401,8 @@ class CG {
COPY_USM,
FILL_USM,
PREFETCH_USM,
INTEROP_TASK_CODEPLAY,
HOST_TASK_CODEPLAY
CODEPLAY_INTEROP_TASK,
CODEPLAY_HOST_TASK
s-kanaev marked this conversation as resolved.
Show resolved Hide resolved
};

CG(CGTYPE Type, vector_class<vector_class<char>> ArgsStorage,
Expand Down
4 changes: 2 additions & 2 deletions sycl/include/CL/sycl/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ class __SYCL_EXPORT handler {

MHostTask.reset(new detail::HostTask(std::move(Func)));

MCGType = detail::CG::HOST_TASK_CODEPLAY;
MCGType = detail::CG::CODEPLAY_HOST_TASK;
}

/// Defines and invokes a SYCL kernel function for the specified range and
Expand Down Expand Up @@ -1161,7 +1161,7 @@ class __SYCL_EXPORT handler {
template <typename FuncT> void interop_task(FuncT Func) {

MInteropTask.reset(new detail::InteropTask(std::move(Func)));
MCGType = detail::CG::INTEROP_TASK_CODEPLAY;
MCGType = detail::CG::CODEPLAY_INTEROP_TASK;
}

/// Defines and invokes a SYCL kernel function for the specified range.
Expand Down
53 changes: 21 additions & 32 deletions sycl/source/detail/scheduler/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,55 +186,44 @@ class DispatchHostTask {
}
}

// Lookup for empty command amongst users of this cmd
static EmptyCommand *findUserEmptyCommand(Command *ThisCmd) {
assert(ThisCmd->MUsers.size() == 1 &&
"Only a single user is expected for host task command");

Command *User = *ThisCmd->MUsers.begin();

assert(User->getType() == Command::CommandType::EMPTY_TASK &&
"Expected empty command as single user of host task command");
assert(User->MIsBlockable && "Empty command is expected to be blockable");
assert(User->MBlockReason == Command::BlockReason::HostTask &&
"Empty command is expected to be blocked due to host task");

return static_cast<EmptyCommand *>(User);
}

public:
DispatchHostTask(ExecCGCommand *ThisCmd) : MThisCmd{ThisCmd} {}

void operator()() const {
waitForEvents();

assert(MThisCmd->getCG().get());
assert(MThisCmd->getCG()->getType() == CG::CGTYPE::HOST_TASK_CODEPLAY);
assert(MThisCmd->getCG().getType() == CG::CGTYPE::CODEPLAY_HOST_TASK);

CGHostTask *HostTask = static_cast<CGHostTask *>(MThisCmd->getCG().get());
CGHostTask &HostTask = static_cast<CGHostTask &>(MThisCmd->getCG());

// we're ready to call the user-defined lambda now
HostTask->MHostTask->call();
HostTask->MHostTask.reset();
HostTask.MHostTask->call();
HostTask.MHostTask.reset();

// unblock user empty command here
EmptyCommand *EmptyCmd = findUserEmptyCommand(MThisCmd);
EmptyCommand *EmptyCmd = MThisCmd->MEmptyCmd;
assert(EmptyCmd && "No empty command found");

// Completing command's event along with unblocking enqueue readiness of
// empty command may lead to quick deallocation of MThisCmd by some cleanup
// process. Thus we'll copy deps prior to completing of event and unblocking
// of empty command.
// Also, it's possible to have record deallocated prior to enqueue process.
// Thus we employ read-lock of graph.
{
Scheduler &Sched = Scheduler::getInstance();
std::shared_lock<std::shared_timed_mutex> Lock(Sched.MGraphLock);

std::vector<DepDesc> Deps = MThisCmd->MDeps;
std::vector<DepDesc> Deps = MThisCmd->MDeps;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this copy necessary?


// update self-event status
MThisCmd->MEvent->setComplete();
// update self-event status
MThisCmd->MEvent->setComplete();

EmptyCmd->MEnqueueStatus = EnqueueResultT::SyclEnqueueReady;
EmptyCmd->MEnqueueStatus = EnqueueResultT::SyclEnqueueReady;

for (const DepDesc &Dep : Deps)
Scheduler::getInstance().enqueueLeavesOfReq(Dep.MDepRequirement);
for (const DepDesc &Dep : Deps)
Scheduler::enqueueLeavesOfReqUnlocked(Dep.MDepRequirement);
}
}
};

Expand Down Expand Up @@ -1396,7 +1385,7 @@ static std::string cgTypeToString(detail::CG::CGTYPE Type) {
case detail::CG::PREFETCH_USM:
return "prefetch usm";
break;
case detail::CG::HOST_TASK_CODEPLAY:
case detail::CG::CODEPLAY_HOST_TASK:
return "host task";
break;
default:
Expand Down Expand Up @@ -1877,7 +1866,7 @@ cl_int ExecCGCommand::enqueueImp() {

return CL_SUCCESS;
}
case CG::CGTYPE::INTEROP_TASK_CODEPLAY: {
case CG::CGTYPE::CODEPLAY_INTEROP_TASK: {
const detail::plugin &Plugin = MQueue->getPlugin();
CGInteropTask *ExecInterop = (CGInteropTask *)MCommandGroup.get();
// Wait for dependencies to complete before dispatching work on the host
Expand Down Expand Up @@ -1907,7 +1896,7 @@ cl_int ExecCGCommand::enqueueImp() {

return CL_SUCCESS;
}
case CG::CGTYPE::HOST_TASK_CODEPLAY: {
case CG::CGTYPE::CODEPLAY_HOST_TASK: {
CGHostTask *HostTask = static_cast<CGHostTask *>(MCommandGroup.get());

for (ArgDesc &Arg : HostTask->MArgs) {
Expand All @@ -1920,7 +1909,7 @@ cl_int ExecCGCommand::enqueueImp() {
break;
}
default:
throw std::runtime_error("Yet unsupported arg type");
throw runtime_error("Unsupported arg type", PI_INVALID_VALUE);
}
}

Expand Down
14 changes: 13 additions & 1 deletion sycl/source/detail/scheduler/commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ class Command {
/// Instance ID tracked for the command.
uint64_t MInstanceID = 0;

// This flag allows to control whether host event should be set complete
// after successfull enqueue of command. Event is considered as host event if
// either it's is_host() return true or there is no backend representation
// of event (i.e. getHandleRef() return reference to nullptr value).
// By default the flag is set to true due to most of host operations are
// synchronous. The only asynchronous operation currently is host-task.
bool MShouldCompleteEventIfPossible = true;
s-kanaev marked this conversation as resolved.
Show resolved Hide resolved
};

Expand Down Expand Up @@ -463,7 +469,13 @@ class ExecCGCommand : public Command {
void printDot(std::ostream &Stream) const final;
void emitInstrumentationData();

const std::unique_ptr<detail::CG> &getCG() const { return MCommandGroup; }
detail::CG &getCG() const { return *MCommandGroup; }

// MEmptyCmd one is only employed if this command refers to host-task.
// MEmptyCmd due to unreliable mechanism of lookup for single EmptyCommand
// amongst users of host-task-representing command. This unreliability roots
// in cleanup process.
EmptyCommand *MEmptyCmd = nullptr;

private:
cl_int enqueueImp() final;
Expand Down
89 changes: 66 additions & 23 deletions sycl/source/detail/scheduler/graph_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,8 @@ Command *Scheduler::GraphBuilder::addHostAccessor(Requirement *Req,
Command *UpdateHostAccCmd = insertUpdateHostReqCmd(Record, Req, HostQueue);

// Need empty command to be blocked until host accessor is destructed
EmptyCommand *EmptyCmd = addEmptyCmd(UpdateHostAccCmd, {Req}, HostQueue);
EmptyCommand *EmptyCmd = addEmptyCmd(UpdateHostAccCmd, {Req}, HostQueue,
Command::BlockReason::HostAccessor);

Req->MBlockedCmd = EmptyCmd;

Expand Down Expand Up @@ -639,10 +640,9 @@ void Scheduler::GraphBuilder::markModifiedIfWrite(MemObjRecord *Record,
}
}

EmptyCommand *
Scheduler::GraphBuilder::addEmptyCmd(Command *Cmd,
const std::vector<Requirement *> &Reqs,
const QueueImplPtr &Queue) {
EmptyCommand *Scheduler::GraphBuilder::addEmptyCmd(
Command *Cmd, const std::vector<Requirement *> &Reqs,
const QueueImplPtr &Queue, Command::BlockReason Reason) {
EmptyCommand *EmptyCmd =
new EmptyCommand(Scheduler::getInstance().getDefaultHostQueue());

Expand All @@ -651,7 +651,7 @@ Scheduler::GraphBuilder::addEmptyCmd(Command *Cmd,

EmptyCmd->MIsBlockable = true;
EmptyCmd->MEnqueueStatus = EnqueueResultT::SyclEnqueueBlocked;
EmptyCmd->MBlockReason = Command::BlockReason::HostTask;
EmptyCmd->MBlockReason = Reason;

for (Requirement *Req : Reqs) {
MemObjRecord *Record = getOrInsertMemObjRecord(Queue, Req);
Expand Down Expand Up @@ -734,8 +734,9 @@ Scheduler::GraphBuilder::addCG(std::unique_ptr<detail::CG> CommandGroup,
NewCmd->addDep(e);
}

if (CGType == CG::CGTYPE::HOST_TASK_CODEPLAY)
addEmptyCmd(NewCmd.get(), NewCmd->getCG()->MRequirements, Queue);
if (CGType == CG::CGTYPE::CODEPLAY_HOST_TASK)
NewCmd->MEmptyCmd = addEmptyCmd(NewCmd.get(), NewCmd->getCG().MRequirements,
Queue, Command::BlockReason::HostTask);

if (MPrintOptionsArray[AfterAddCG])
printGraphAsDot("after_addCG");
Expand Down Expand Up @@ -899,11 +900,11 @@ void Scheduler::GraphBuilder::removeRecordForMemObj(SYCLMemObjI *MemObject) {
// Make Cmd depend on DepEvent from different context. Connection is performed
// via distinct ConnectCmd with host task command group on host queue. Cmd will
// depend on ConnectCmd's host event.
// DepEvent may not have an associated with it command in at least two cases:
// DepEvent may not have a command associated with it in at least two cases:
// - the command was deleted upon cleanup process;
// - DepEvent is user event.
// In both these cases the only thing we can do is to make ConnectCmd depend on
// DepEvent.
// In both of these cases the only thing we can do is to make ConnectCmd depend
// on DepEvent.
// Otherwise, when there is a command associated with DepEvent, we make
// ConnectCmd depend on on this command. If there is valid, i.e. non-nil,
// requirement in Dep we make ConnectCmd depend on DepEvent's command with this
Expand All @@ -920,14 +921,12 @@ void Scheduler::GraphBuilder::connectDepEvent(Command *const Cmd,
ExecCGCommand *ConnectCmd = nullptr;

{
std::function<void(void)> Func = []() {};

std::unique_ptr<detail::HostTask> HT(new detail::HostTask(std::move(Func)));
std::unique_ptr<detail::HostTask> HT(new detail::HostTask);
std::unique_ptr<detail::CG> ConnectCG(new detail::CGHostTask(
std::move(HT), /* Args = */ {}, /* ArgsStorage = */ {},
/* AccStorage = */ {}, /* SharedPtrStorage = */ {},
/* Requirements = */ {}, /* DepEvents = */ {DepEvent},
CG::HOST_TASK_CODEPLAY, /* Payload */ {}));
CG::CODEPLAY_HOST_TASK, /* Payload */ {}));
ConnectCmd = new ExecCGCommand(
std::move(ConnectCG), Scheduler::getInstance().getDefaultHostQueue());
}
Expand All @@ -938,25 +937,71 @@ void Scheduler::GraphBuilder::connectDepEvent(Command *const Cmd,
if (Command *DepCmd = reinterpret_cast<Command *>(DepEvent->getCommand()))
DepCmd->addUser(ConnectCmd);

ConnectCmd->addDep(DepEvent);

EmptyCommand *EmptyCmd = nullptr;

if (Dep.MDepRequirement) {
const auto &Reqs = std::vector<Requirement *>(
1, const_cast<Requirement *>(Dep.MDepRequirement));
Requirement *Req = const_cast<Requirement *>(Dep.MDepRequirement);
s-kanaev marked this conversation as resolved.
Show resolved Hide resolved

// make ConnectCmd depend on requirement
{
MemObjRecord *Record = getMemObjRecord(Req->MSYCLMemObj);
Dep.MDepCommand->addUser(ConnectCmd);

AllocaCommandBase *AllocaCmd =
findAllocaForReq(Record, Req, DepEventContext);
s-kanaev marked this conversation as resolved.
Show resolved Hide resolved
assert(AllocaCmd && "There must be alloca for requirement!");

std::set<Command *> Deps = findDepsForReq(Record, Req, DepEventContext);
assert(Deps.size() && "There must be some deps");

for (Command *ReqDepCmd : Deps) {
// we don't want to depend on any host task as the only "entry point" to
// host task is its empty cmd which is in Deps anyway
if (ReqDepCmd->getType() == Command::CommandType::RUN_CG) {
auto *Cmd = static_cast<ExecCGCommand *>(ReqDepCmd);
if (Cmd->getCG().getType() == CG::CGTYPE::CODEPLAY_HOST_TASK)
continue;
}

ConnectCmd->addDep(DepDesc{ReqDepCmd, Req, AllocaCmd});
ReqDepCmd->addUser(ConnectCmd);
s-kanaev marked this conversation as resolved.
Show resolved Hide resolved
}

updateLeaves(Deps, Record, Req->MAccessMode);
addNodeToLeaves(Record, ConnectCmd, Req->MAccessMode);
}

const auto &Reqs = std::vector<Requirement *>(1, Req);
s-kanaev marked this conversation as resolved.
Show resolved Hide resolved
EmptyCmd = addEmptyCmd(ConnectCmd, Reqs,
Scheduler::getInstance().getDefaultHostQueue());
Scheduler::getInstance().getDefaultHostQueue(),
Command::BlockReason::HostTask);
// Dependencies for EmptyCmd are set in addEmptyCmd for provided Reqs.

// Depend Cmd on empty command
{
DepDesc CmdDep = Dep;
CmdDep.MDepCommand = EmptyCmd;

Cmd->addDep(CmdDep);
}
} else {
EmptyCmd = addEmptyCmd(ConnectCmd, {},
Scheduler::getInstance().getDefaultHostQueue());
Scheduler::getInstance().getDefaultHostQueue(),
Command::BlockReason::HostTask);

// There is no requirement thus, empty command will only depend on
// ConnectCmd via its event.
EmptyCmd->addDep(ConnectCmd->getEvent());
ConnectCmd->addDep(DepEvent);

// Depend Cmd on empty command
Cmd->addDep(EmptyCmd->getEvent());
}

EmptyCmd->addUser(Cmd);

ConnectCmd->MEmptyCmd = EmptyCmd;

// FIXME graph builder shouldn't really enqueue commands. We're in the middle
s-kanaev marked this conversation as resolved.
Show resolved Hide resolved
// of enqueue process for some command Cmd. We're going to add a dependency
// for it. Need some nice and cute solution to enqueue ConnectCmd via standard
Expand All @@ -966,8 +1011,6 @@ void Scheduler::GraphBuilder::connectDepEvent(Command *const Cmd,
if (!Enqueued && EnqueueResultT::SyclEnqueueFailed == Res.MResult)
throw runtime_error("Failed to enqueue a sync event between two contexts",
PI_INVALID_OPERATION);

Cmd->addDep(ConnectCmd->getEvent());
}
s-kanaev marked this conversation as resolved.
Show resolved Hide resolved

} // namespace detail
Expand Down
11 changes: 5 additions & 6 deletions sycl/source/detail/scheduler/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,16 @@ EventImplPtr Scheduler::addCG(std::unique_ptr<detail::CG> CommandGroup,
NewCmd = MGraphBuilder.addCGUpdateHost(std::move(CommandGroup),
DefaultHostQueue);
break;
case CG::HOST_TASK_CODEPLAY:
case CG::CODEPLAY_HOST_TASK:
NewCmd = MGraphBuilder.addCG(std::move(CommandGroup), DefaultHostQueue);
break;
default:
NewCmd = MGraphBuilder.addCG(std::move(CommandGroup), std::move(Queue));
}
}

{
std::shared_lock<std::shared_timed_mutex> Lock(MGraphLock);

// TODO: Check if lazy mode.
EnqueueResultT Res;
Expand Down Expand Up @@ -190,11 +194,6 @@ void Scheduler::releaseHostAccessor(Requirement *Req) {
enqueueLeavesOfReqUnlocked(Req);
}

void Scheduler::enqueueLeavesOfReq(const Requirement *const Req) {
std::shared_lock<std::shared_timed_mutex> Lock(MGraphLock);
enqueueLeavesOfReqUnlocked(Req);
}

// static
void Scheduler::enqueueLeavesOfReqUnlocked(const Requirement *const Req) {
MemObjRecord *Record = Req->MSYCLMemObj->MRecord.get();
s-kanaev marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
4 changes: 2 additions & 2 deletions sycl/source/detail/scheduler/scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,6 @@ class Scheduler {
static Scheduler instance;

static void enqueueLeavesOfReqUnlocked(const Requirement *const Req);
void enqueueLeavesOfReq(const Requirement *const Req);

/// Graph builder class.
///
Expand Down Expand Up @@ -552,7 +551,8 @@ class Scheduler {

EmptyCommand *addEmptyCmd(Command *Cmd,
const std::vector<Requirement *> &Req,
const QueueImplPtr &Queue);
const QueueImplPtr &Queue,
Command::BlockReason Reason);

protected:
/// Finds a command dependency corresponding to the record.
Expand Down
Loading