Skip to content

[SYCL] Enqueue dependencies of blocked command #2543

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

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
97e690c
[SYCL] Improve testing of host-task
Sep 25, 2020
14e9517
[SYCL] Disable test-case as it hangs now
Sep 25, 2020
299797b
Address style issues
Sep 25, 2020
5dc69f0
[SYCL] Check that host-tasks in test case don't wait for too long
Sep 25, 2020
7da4e26
[NFC][SYCL] Fix comment.
Sep 25, 2020
ddd382f
Merge branch 'private/s-kanaev/fix-comment' into private/s-kanaev/ht-…
Sep 25, 2020
9a56fc7
[SYCL] Enqueue dependencies of blocked command
Sep 25, 2020
e7797f4
[SYCL] Improve testing of host-task
Sep 25, 2020
f0fce8f
[SYCL] Remove unwanted include
Sep 25, 2020
c94a245
[SYCL] Use default C++ std
Sep 25, 2020
ba8e10d
Merge branch 'private/s-kanaev/ht-tests' into private/s-kanaev/ht-wor…
Sep 25, 2020
9ee2f6d
[SYCL] Enable test-case
Sep 25, 2020
97f5c5f
Adress comments
Sep 28, 2020
2e7e4cd
Merge branch 'sycl' into private/s-kanaev/ht-tests
Sep 28, 2020
8666752
[SYCL] Improve testing of host task
Sep 28, 2020
464f2a5
Merge branch 'sycl' into private/s-kanaev/ht-workaround-2
Sep 28, 2020
cf46110
Merge branch 'private/s-kanaev/fix-comment' into private/s-kanaev/ht-…
Sep 28, 2020
9d189c9
Merge branch 'private/s-kanaev/ht-tests' into private/s-kanaev/ht-wor…
Sep 28, 2020
d291557
Fix syntax issue
Sep 28, 2020
e6014ec
Merge branch 'private/s-kanaev/ht-tests' into private/s-kanaev/ht-wor…
Sep 28, 2020
a83d591
[SYCL] Enable disabled tests
Sep 28, 2020
5aba995
Fix style issues
Sep 29, 2020
ceb5410
Set name for magic constant
Sep 29, 2020
94982ee
Split tests to distinct files
Sep 29, 2020
993fcf2
Fix style issues
Sep 29, 2020
0802c26
Fix style issues
Sep 29, 2020
2b9b541
Fix build issues
Sep 29, 2020
66c3e92
Merge branch 'private/s-kanaev/ht-tests' into private/s-kanaev/ht-wor…
Sep 29, 2020
ca80623
Fix merge glitch
Sep 29, 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
8 changes: 4 additions & 4 deletions sycl/source/detail/scheduler/commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,10 +493,10 @@ class ExecCGCommand : public Command {

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.
// MEmptyCmd is only employed if this command refers to host-task.
// The mechanism of lookup for single EmptyCommand amongst users of
// host-task-representing command is unreliable. This unreliability roots in
// the cleanup process.
EmptyCommand *MEmptyCmd = nullptr;

private:
Expand Down
11 changes: 5 additions & 6 deletions sycl/source/detail/scheduler/graph_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,18 @@ bool Scheduler::GraphProcessor::enqueueCommand(Command *Cmd,
if (!Cmd || Cmd->isSuccessfullyEnqueued())
return true;

// Exit early if the command is blocked and the enqueue type is non-blocking
if (Cmd->isEnqueueBlocked() && !Blocking) {
EnqueueResult = EnqueueResultT(EnqueueResultT::SyclEnqueueBlocked, Cmd);
return false;
}

// Recursively enqueue all the dependencies first and
// exit immediately if any of the commands cannot be enqueued.
for (DepDesc &Dep : Cmd->MDeps) {
if (!enqueueCommand(Dep.MDepCommand, EnqueueResult, Blocking))
return false;
}

if (Cmd->isEnqueueBlocked() && !Blocking) {
EnqueueResult = EnqueueResultT(EnqueueResultT::SyclEnqueueBlocked, Cmd);
return false;
}

return Cmd->enqueue(EnqueueResult, Blocking);
}

Expand Down
97 changes: 97 additions & 0 deletions sycl/test/host-interop-task/host-task-dependency2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out

// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out

// RUN: %CPU_RUN_PLACEHOLDER %t.out 10
// RUN: %GPU_RUN_PLACEHOLDER %t.out 10
// RUN: %ACC_RUN_PLACEHOLDER %t.out 10

#include <CL/sycl.hpp>
#include <iostream>

using namespace cl::sycl;
using namespace cl::sycl::access;

static constexpr size_t BUFFER_SIZE = 1024;

static auto EH = [](exception_list EL) {
for (const std::exception_ptr &E : EL) {
throw E;
}
};

// Host-task depending on another host-task via handler::depends_on() only
// should not hang
void test(size_t Count) {
queue Q(EH);

static constexpr size_t BufferSize = 10 * 1024;

buffer<int, 1> B0{range<1>{BufferSize}};
buffer<int, 1> B1{range<1>{BufferSize}};
buffer<int, 1> B2{range<1>{BufferSize}};
buffer<int, 1> B3{range<1>{BufferSize}};
buffer<int, 1> B4{range<1>{BufferSize}};
buffer<int, 1> B5{range<1>{BufferSize}};

for (size_t Idx = 1; Idx <= Count; ++Idx) {
// This host task should be submitted without hesitation
event E1 = Q.submit([&](handler &CGH) {
std::cout << "Submit 1" << std::endl;

auto Acc0 = B0.get_access<mode::read_write, target::host_buffer>(CGH);
auto Acc1 = B1.get_access<mode::read_write, target::host_buffer>(CGH);
auto Acc2 = B2.get_access<mode::read_write, target::host_buffer>(CGH);

CGH.codeplay_host_task([=] {
Acc0[0] = 1 * Idx;
Acc1[0] = 2 * Idx;
Acc2[0] = 3 * Idx;
});
});

// This host task is going to depend on blocked empty node of the first
// host-task (via buffer #2). Still this one should be enqueued.
event E2 = Q.submit([&](handler &CGH) {
std::cout << "Submit 2" << std::endl;

auto Acc2 = B2.get_access<mode::read_write, target::host_buffer>(CGH);
auto Acc3 = B3.get_access<mode::read_write, target::host_buffer>(CGH);

CGH.codeplay_host_task([=] {
Acc2[1] = 1 * Idx;
Acc3[1] = 2 * Idx;
});
});

// This host-task only depends on the second host-task via
// handler::depends_on(). This one should not hang and should be eexecuted
// after host-task #2.
event E3 = Q.submit([&](handler &CGH) {
CGH.depends_on(E2);

std::cout << "Submit 3" << std::endl;

auto Acc4 = B4.get_access<mode::read_write, target::host_buffer>(CGH);
auto Acc5 = B5.get_access<mode::read_write, target::host_buffer>(CGH);

CGH.codeplay_host_task([=] {
Acc4[2] = 1 * Idx;
Acc5[2] = 2 * Idx;
});
});
}

Q.wait_and_throw();
}

int main(int Argc, const char *Argv[]) {
size_t Count = 1;
if (Argc > 1)
Count = std::stoi(Argv[1]);

test(Count);
return 0;
}
126 changes: 126 additions & 0 deletions sycl/test/host-interop-task/host-task-dependency3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out

// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out

// RUN: %CPU_RUN_PLACEHOLDER %t.out 10
// RUN: %GPU_RUN_PLACEHOLDER %t.out 10
// RUN: %ACC_RUN_PLACEHOLDER %t.out 10

#include <CL/sycl.hpp>
#include <chrono>
#include <iostream>
#include <thread>

using namespace cl::sycl;
using namespace cl::sycl::access;

static constexpr size_t BUFFER_SIZE = 1024;

static auto EH = [](exception_list EL) {
for (const std::exception_ptr &E : EL) {
throw E;
}
};

// Host-task depending on another host-task via handler::depends_on() only
// should not hang. A bit more complicated case with kernels depending on
// host-task being involved.
void test(size_t Count) {
queue Q(EH);

static constexpr size_t BufferSize = 10 * 1024;

buffer<int, 1> B0{range<1>{BufferSize}};
buffer<int, 1> B1{range<1>{BufferSize}};
buffer<int, 1> B2{range<1>{BufferSize}};
buffer<int, 1> B3{range<1>{BufferSize}};
buffer<int, 1> B4{range<1>{BufferSize}};
buffer<int, 1> B5{range<1>{BufferSize}};

using namespace std::chrono_literals;
constexpr auto SleepFor = 1s;

for (size_t Idx = 1; Idx <= Count; ++Idx) {
// This host task should be submitted without hesitation
Q.submit([&](handler &CGH) {
std::cout << "Submit HT-1" << std::endl;

auto Acc0 = B0.get_access<mode::read_write, target::host_buffer>(CGH);

CGH.codeplay_host_task([=] {
std::this_thread::sleep_for(SleepFor);
Acc0[0] = 1 * Idx;
});
});

Q.submit([&](handler &CGH) {
std::cout << "Submit Kernel-1" << std::endl;

auto Acc0 = B0.get_access<mode::read_write>(CGH);

CGH.single_task<class Test5_Kernel1>([=] { Acc0[1] = 1 * Idx; });
});

Q.submit([&](handler &CGH) {
std::cout << "Submit Kernel-2" << std::endl;

auto Acc1 = B1.get_access<mode::read_write>(CGH);

CGH.single_task<class Test5_Kernel2>([=] { Acc1[2] = 1 * Idx; });
});

Q.submit([&](handler &CGH) {
std::cout << "Submit HT-2" << std::endl;

auto Acc2 = B2.get_access<mode::read_write, target::host_buffer>(CGH);

CGH.codeplay_host_task([=] {
std::this_thread::sleep_for(SleepFor);
Acc2[3] = 1 * Idx;
});
});

// This host task is going to depend on blocked empty node of the second
// host-task (via buffer #0). Still this one should be enqueued.
event EHT3 = Q.submit([&](handler &CGH) {
std::cout << "Submit HT-3" << std::endl;

auto Acc0 = B0.get_access<mode::read_write, target::host_buffer>(CGH);
auto Acc1 = B1.get_access<mode::read_write, target::host_buffer>(CGH);
auto Acc2 = B2.get_access<mode::read_write, target::host_buffer>(CGH);

CGH.codeplay_host_task([=] {
std::this_thread::sleep_for(SleepFor);
Acc0[4] = 1 * Idx;
Acc1[4] = 2 * Idx;
Acc2[4] = 3 * Idx;
});
});

// This host-task only depends on the third host-task via
// handler::depends_on(). This one should not hang and should be executed
// after host-task #3.
Q.submit([&](handler &CGH) {
std::cout << "Submit HT-4" << std::endl;

CGH.depends_on(EHT3);

auto Acc5 = B5.get_access<mode::read_write, target::host_buffer>(CGH);

CGH.codeplay_host_task([=] { Acc5[5] = 1 * Idx; });
});
}

Q.wait_and_throw();
}

int main(int Argc, const char *Argv[]) {
size_t Count = 1;
if (Argc > 1)
Count = std::stoi(Argv[1]);

test(Count);
return 0;
}
30 changes: 30 additions & 0 deletions sycl/test/host-interop-task/host-task-dependency4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out

// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out

#include <CL/sycl.hpp>

cl::sycl::event submit(cl::sycl::queue &Q, cl::sycl::buffer<int> &B) {
return Q.submit([&](cl::sycl::handler &CGH) {
auto A = B.template get_access<cl::sycl::access::mode::read_write>(CGH);
CGH.codeplay_host_task([=]() { (void)A; });
});
}

int main() {
cl::sycl::queue Q;
int Status = 0;
cl::sycl::buffer<int> A{&Status, 1};
cl::sycl::vector_class<cl::sycl::event> Events;

Events.push_back(submit(Q, A));
Events.push_back(submit(Q, A));
Q.submit([&](sycl::handler &CGH) {
CGH.depends_on(Events);
CGH.codeplay_host_task([&] { printf("all done\n"); });
}).wait_and_throw();

return 0;
}
Loading