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 all 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
1 change: 1 addition & 0 deletions sycl/doc/EnvironmentVariables.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ subject to change. Do not rely on these variables in production code.
| SYCL_THROW_ON_BLOCK | Any(\*) | Throw an exception on attempt to wait for a blocked command. |
| SYCL_DEVICELIB_INHIBIT_NATIVE | String of device library extensions (separated by a whitespace) | Do not rely on device native support for devicelib extensions listed in this option. |
| SYCL_DEVICE_ALLOWLIST | A list of devices and their minimum driver version following the pattern: DeviceName:{{XXX}},DriverVersion:{{X.Y.Z.W}}. Also may contain PlatformName and PlatformVersion | Filter out devices that do not match the pattern specified. Regular expression can be passed and the DPC++ runtime will select only those devices which satisfy the regex. |
| SYCL_QUEUE_THREAD_POOL_SIZE | Positive integer | Number of threads in thread pool of queue. |
`(*) Note: Any means this environment variable is effective when set to any non-null value.`

### SYCL_PRINT_EXECUTION_GRAPH Options
Expand Down
8 changes: 4 additions & 4 deletions sycl/include/CL/sycl/accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ class accessor :
template <int Dims = Dimensions, typename AllocatorT,
typename = typename detail::enable_if_t<
(Dims == 0) &&
(!IsPlaceH && (IsGlobalBuf || IsConstantBuf))>
(!IsPlaceH && (IsGlobalBuf || IsConstantBuf || IsHostBuf))>
>
accessor(buffer<DataT,1,AllocatorT> &BufferRef,
handler &CommandGroupHandler)
Expand Down Expand Up @@ -817,9 +817,9 @@ class accessor :
#endif

template <int Dims = Dimensions, typename AllocatorT,
typename = detail::enable_if_t<(Dims > 0) && (Dims == Dimensions) &&
(!IsPlaceH &&
(IsGlobalBuf || IsConstantBuf))>>
typename = detail::enable_if_t<
(Dims > 0) && (Dims == Dimensions) &&
(!IsPlaceH && (IsGlobalBuf || IsConstantBuf || IsHostBuf))>>
accessor(buffer<DataT, Dims, AllocatorT> &BufferRef,
handler &CommandGroupHandler)
#ifdef __SYCL_DEVICE_ONLY__
Expand Down
31 changes: 30 additions & 1 deletion sycl/include/CL/sycl/detail/cg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,16 @@ class InteropTask {
void call(cl::sycl::interop_handler &h) { MFunc(h); }
};

class HostTask {
std::function<void()> MHostTask;

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

void call() { MHostTask(); }
};

// Class which stores specific lambda object.
template <class KernelType, class KernelArgType, int Dims>
class HostKernel : public HostKernelBase {
Expand Down Expand Up @@ -391,7 +401,8 @@ class CG {
COPY_USM,
FILL_USM,
PREFETCH_USM,
INTEROP_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 Expand Up @@ -631,6 +642,24 @@ class CGInteropTask : public CG {
MInteropTask(std::move(InteropTask)) {}
};

class CGHostTask : public CG {
public:
std::unique_ptr<HostTask> MHostTask;
vector_class<ArgDesc> MArgs;

CGHostTask(std::unique_ptr<HostTask> HostTask, vector_class<ArgDesc> Args,
std::vector<std::vector<char>> ArgsStorage,
std::vector<detail::AccessorImplPtr> AccStorage,
std::vector<std::shared_ptr<const void>> SharedPtrStorage,
std::vector<Requirement *> Requirements,
std::vector<detail::EventImplPtr> Events, CGTYPE Type,
detail::code_location loc = {})
: CG(Type, std::move(ArgsStorage), std::move(AccStorage),
std::move(SharedPtrStorage), std::move(Requirements),
std::move(Events), std::move(loc)),
MHostTask(std::move(HostTask)), MArgs(std::move(Args)) {}
};

} // namespace detail
} // namespace sycl
} // __SYCL_INLINE_NAMESPACE(cl)
39 changes: 38 additions & 1 deletion sycl/include/CL/sycl/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,27 @@ template <typename Type> struct get_kernel_name_t<detail::auto_name, Type> {
using name = Type;
};

template <typename, typename T> struct check_fn_signature {
static_assert(std::integral_constant<T, false>::value,
"Second template parameter is required to be of function type");
};

template <typename F, typename RetT, typename... Args>
struct check_fn_signature<F, RetT(Args...)> {
private:
template <typename T>
static constexpr auto check(T *) -> typename std::is_same<
decltype(std::declval<T>().operator()(std::declval<Args>()...)),
RetT>::type;

template <typename> static constexpr std::false_type check(...);

using type = decltype(check<F>(0));

public:
static constexpr bool value = type::value;
};

__SYCL_EXPORT device getDeviceFromHandler(handler &);

} // namespace detail
Expand Down Expand Up @@ -802,6 +823,20 @@ class __SYCL_EXPORT handler {
MCGType = detail::CG::RUN_ON_HOST_INTEL;
}

template <typename FuncT>
typename std::enable_if<detail::check_fn_signature<
typename std::remove_reference<FuncT>::type, void()>::value>::type
codeplay_host_task(FuncT Func) {
s-kanaev marked this conversation as resolved.
Show resolved Hide resolved
throwIfActionIsCreated();

MNDRDesc.set(range<1>(1));
MArgs = std::move(MAssociatedAccesors);

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

MCGType = detail::CG::CODEPLAY_HOST_TASK;
}

/// Defines and invokes a SYCL kernel function for the specified range and
/// offset.
///
Expand Down Expand Up @@ -1128,7 +1163,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 Expand Up @@ -1586,6 +1621,8 @@ class __SYCL_EXPORT handler {
vector_class<char> MPattern;
/// Storage for a lambda or function object.
unique_ptr_class<detail::HostKernelBase> MHostKernel;
/// Storage for lambda/function when using HostTask
unique_ptr_class<detail::HostTask> MHostTask;
detail::OSModuleHandle MOSModuleHandle;
// Storage for a lambda or function when using InteropTasks
std::unique_ptr<detail::InteropTask> MInteropTask;
Expand Down
49 changes: 40 additions & 9 deletions sycl/source/detail/event_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,31 @@ event_impl::~event_impl() {
}

void event_impl::waitInternal() const {
if (!MHostEvent) {
if (!MHostEvent && MEvent) {
getPlugin().call<PiApiKind::piEventsWait>(1, &MEvent);
return;
}
// Waiting of host events is NOP so far as all operations on host device
// are blocking.

while (MState != HES_Complete)
;
}

void event_impl::setComplete() {
if (MHostEvent || !MEvent) {
s-kanaev marked this conversation as resolved.
Show resolved Hide resolved
#ifndef NDEBUG
int Expected = HES_NotComplete;
int Desired = HES_Complete;

bool Succeeded = MState.compare_exchange_strong(Expected, Desired);

assert(Succeeded && "Unexpected state of event");
#else
MState.store(static_cast<int>(HES_Complete));
#endif
return;
}

assert(false && "setComplete is not supported for non-host event");
}

const RT::PiEvent &event_impl::getHandleRef() const { return MEvent; }
Expand All @@ -68,11 +88,15 @@ void event_impl::setContextImpl(const ContextImplPtr &Context) {
MHostEvent = Context->is_host();
MOpenCLInterop = !MHostEvent;
MContext = Context;

MState = HES_NotComplete;
}

event_impl::event_impl() : MState(HES_Complete) {}

event_impl::event_impl(RT::PiEvent Event, const context &SyclContext)
: MEvent(Event), MContext(detail::getSyclObjImpl(SyclContext)),
MOpenCLInterop(true), MHostEvent(false) {
MOpenCLInterop(true), MHostEvent(false), MState(HES_Complete) {

if (MContext->is_host()) {
throw cl::sycl::invalid_parameter_error(
Expand All @@ -96,12 +120,19 @@ event_impl::event_impl(RT::PiEvent Event, const context &SyclContext)
}

event_impl::event_impl(QueueImplPtr Queue) : MQueue(Queue) {
if (Queue->is_host() &&
Queue->has_property<property::queue::enable_profiling>()) {
MHostProfilingInfo.reset(new HostProfilingInfo());
if (!MHostProfilingInfo)
throw runtime_error("Out of host memory", PI_OUT_OF_HOST_MEMORY);
if (Queue->is_host()) {
MState.store(HES_NotComplete);

if (Queue->has_property<property::queue::enable_profiling>()) {
MHostProfilingInfo.reset(new HostProfilingInfo());
if (!MHostProfilingInfo)
throw runtime_error("Out of host memory", PI_OUT_OF_HOST_MEMORY);
}

return;
}

MState.store(HES_Complete);
}

void *event_impl::instrumentationProlog(string_class &Name, int32_t StreamID,
Expand Down
10 changes: 9 additions & 1 deletion sycl/source/detail/event_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <CL/sycl/info/info_desc.hpp>
#include <CL/sycl/stl.hpp>

#include <atomic>
#include <cassert>

__SYCL_INLINE_NAMESPACE(cl) {
Expand All @@ -32,7 +33,7 @@ class event_impl {
/// Constructs a ready SYCL event.
///
/// If the constructed SYCL event is waited on it will complete immediately.
event_impl() = default;
event_impl();
/// Constructs an event instance from a plug-in event handle.
///
/// The SyclContext must match the plug-in context associated with the
Expand Down Expand Up @@ -166,6 +167,13 @@ class event_impl {
bool MHostEvent = true;
std::unique_ptr<HostProfilingInfo> MHostProfilingInfo;
void *MCommand = nullptr;

enum HostEventState : int { HES_NotComplete = 0, HES_Complete };

// State of host event. Employed only for host events and event with no
// backend's representation (e.g. alloca). Used values are listed in
// HostEventState enum.
std::atomic<int> MState;
};

} // namespace detail
Expand Down
24 changes: 24 additions & 0 deletions sycl/source/detail/queue_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,30 @@ void queue_impl::wait(const detail::code_location &CodeLoc) {
#endif
}

void queue_impl::initHostTaskAndEventCallbackThreadPool() {
s-kanaev marked this conversation as resolved.
Show resolved Hide resolved
if (MHostTaskThreadPool)
return;

int Size = 1;

if (const char *val = std::getenv("SYCL_QUEUE_THREAD_POOL_SIZE"))
sergey-semenov marked this conversation as resolved.
Show resolved Hide resolved
try {
Size = std::stoi(val);
} catch (...) {
throw invalid_parameter_error(
"Invalid value for SYCL_QUEUE_THREAD_POOL_SIZE environment variable",
PI_INVALID_VALUE);
}

if (Size < 1)
throw invalid_parameter_error(
"Invalid value for SYCL_QUEUE_THREAD_POOL_SIZE environment variable",
PI_INVALID_VALUE);

MHostTaskThreadPool.reset(new ThreadPool(Size));
s-kanaev marked this conversation as resolved.
Show resolved Hide resolved
MHostTaskThreadPool->start();
}

pi_native_handle queue_impl::getNative() const {
auto Plugin = getPlugin();
pi_native_handle Handle;
Expand Down
14 changes: 14 additions & 0 deletions sycl/source/detail/queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <detail/event_impl.hpp>
#include <detail/plugin.hpp>
#include <detail/scheduler/scheduler.hpp>
#include <detail/thread_pool.hpp>

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {
Expand Down Expand Up @@ -348,6 +349,13 @@ class queue_impl {
MExceptions.PushBack(ExceptionPtr);
}

ThreadPool &getThreadPool() {
if (!MHostTaskThreadPool)
initHostTaskAndEventCallbackThreadPool();

return *MHostTaskThreadPool;
}

/// Gets the native handle of the SYCL queue.
///
/// \return a native handle.
Expand Down Expand Up @@ -380,6 +388,8 @@ class queue_impl {
void instrumentationEpilog(void *TelementryEvent, string_class &Name,
int32_t StreamID, uint64_t IId);

void initHostTaskAndEventCallbackThreadPool();

/// Stores a USM operation event that should be associated with the queue
///
/// \param Event is the event to be stored
Expand Down Expand Up @@ -414,6 +424,10 @@ class queue_impl {
const bool MOpenCLInterop = false;
// Assume OOO support by default.
bool MSupportOOO = true;

// Thread pool for host task and event callbacks execution.
// The thread pool is instantiated upon the very first call to getThreadPool()
std::unique_ptr<ThreadPool> MHostTaskThreadPool;
};

} // namespace detail
Expand Down
Loading