Skip to content

Commit 8255f7c

Browse files
Keep StorageInitHelper::MEvents in pool.
1 parent a555257 commit 8255f7c

File tree

9 files changed

+69
-15
lines changed

9 files changed

+69
-15
lines changed

sycl/source/detail/cg.hpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <assert.h> // for assert
2323
#include <memory> // for shared_ptr, unique_ptr
24+
#include <memory_resource> // for std::pmr
2425
#include <stddef.h> // for size_t
2526
#include <stdint.h> // for int32_t
2627
#include <string> // for string
@@ -166,14 +167,24 @@ class CG {
166167
std::vector<detail::AccessorImplPtr> AccStorage,
167168
std::vector<std::shared_ptr<const void>> SharedPtrStorage,
168169
std::vector<AccessorImplHost *> Requirements,
169-
std::vector<detail::EventImplPtr> Events)
170+
std::pmr::vector<detail::EventImplPtr> Events)
170171
: MArgsStorage(std::move(ArgsStorage)),
171172
MAccStorage(std::move(AccStorage)),
172173
MSharedPtrStorage(std::move(SharedPtrStorage)),
173174
MRequirements(std::move(Requirements)), MEvents(std::move(Events)) {}
174-
StorageInitHelper(StorageInitHelper &&) = default;
175-
StorageInitHelper(const StorageInitHelper &) = default;
176-
// The following storages are needed to ensure that arguments won't die
175+
StorageInitHelper(StorageInitHelper &&SIH)
176+
: MArgsStorage(std::move(SIH.MArgsStorage)),
177+
MAccStorage(std::move(SIH.MAccStorage)),
178+
MSharedPtrStorage(std::move(SIH.MSharedPtrStorage)),
179+
MRequirements(std::move(SIH.MRequirements)),
180+
MEvents(SIH.MEvents.begin(), SIH.MEvents.end()) {}
181+
StorageInitHelper(const StorageInitHelper &SIH)
182+
: MArgsStorage(SIH.MArgsStorage),
183+
MAccStorage(SIH.MAccStorage),
184+
MSharedPtrStorage(SIH.MSharedPtrStorage),
185+
MRequirements(SIH.MRequirements),
186+
MEvents(SIH.MEvents.begin(), SIH.MEvents.end()) {}
187+
// The following storages are needed to ensure that arguments won't die
177188
// while we are using them.
178189
/// Storage for standard layout arguments.
179190
std::vector<std::vector<char>> MArgsStorage;
@@ -185,8 +196,13 @@ class CG {
185196
/// List of requirements that specify which memory is needed for the command
186197
/// group to be executed.
187198
std::vector<AccessorImplHost *> MRequirements;
199+
200+
std::array<std::byte, 4 * 1024> MEventsBuf;
201+
std::pmr::monotonic_buffer_resource MEventsBufRes{
202+
MEventsBuf.data(), MEventsBuf.size()};
203+
188204
/// List of events that order the execution of this CG
189-
std::vector<detail::EventImplPtr> MEvents;
205+
std::pmr::vector<detail::EventImplPtr> MEvents{&MEventsBufRes};
190206
};
191207

192208
CG(CGType Type, StorageInitHelper D, detail::code_location loc = {},
@@ -222,7 +238,7 @@ class CG {
222238
std::vector<AccessorImplHost *> &getRequirements() {
223239
return MData.MRequirements;
224240
}
225-
std::vector<detail::EventImplPtr> &getEvents() { return MData.MEvents; }
241+
std::pmr::vector<detail::EventImplPtr> &getEvents() { return MData.MEvents; }
226242

227243
virtual std::vector<std::shared_ptr<const void>>
228244
getAuxiliaryResources() const {

sycl/source/detail/graph_impl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,14 +983,14 @@ exec_graph_impl::enqueue(const std::shared_ptr<sycl::detail::queue_impl> &Queue,
983983
sycl::detail::EventImplPtr NewEvent;
984984
std::vector<sycl::detail::EventImplPtr> BackupCGDataMEvents;
985985
if (MPartitions.size() > 1) {
986-
BackupCGDataMEvents = CGData.MEvents;
986+
BackupCGDataMEvents.assign(CGData.MEvents.begin(), CGData.MEvents.end());
987987
}
988988
for (uint32_t currentPartitionsNum = 0;
989989
currentPartitionsNum < MPartitions.size(); currentPartitionsNum++) {
990990
auto CurrentPartition = MPartitions[currentPartitionsNum];
991991
// restore initial MEvents to add only needed additional depenencies
992992
if (currentPartitionsNum > 0) {
993-
CGData.MEvents = BackupCGDataMEvents;
993+
CGData.MEvents.assign(BackupCGDataMEvents.begin(), BackupCGDataMEvents.end());
994994
}
995995

996996
for (auto const &DepPartition : CurrentPartition->MPredecessors) {

sycl/source/detail/jit_compiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ jit_compiler::fuseKernels(QueueImplPtr Queue,
786786
std::vector<std::vector<char>> &ArgsStorage = CGData.MArgsStorage;
787787
std::vector<detail::AccessorImplPtr> &AccStorage = CGData.MAccStorage;
788788
std::vector<Requirement *> &Requirements = CGData.MRequirements;
789-
std::vector<detail::EventImplPtr> &Events = CGData.MEvents;
789+
std::pmr::vector<detail::EventImplPtr> &Events = CGData.MEvents;
790790
std::vector<::jit_compiler::NDRange> Ranges;
791791
ur_kernel_cache_config_t KernelCacheConfig = UR_KERNEL_CACHE_CONFIG_DEFAULT;
792792
unsigned KernelIndex = 0;

sycl/source/detail/scheduler/commands.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,26 @@ Command::getUrEvents(const std::vector<EventImplPtr> &EventImpls,
243243
}
244244

245245
std::vector<ur_event_handle_t>
246-
Command::getUrEvents(const std::vector<EventImplPtr> &EventImpls) const {
247-
return getUrEvents(EventImpls, MWorkerQueue, isHostTask());
246+
Command::getUrEvents(const std::pmr::vector<EventImplPtr> &EventImpls,
247+
const QueueImplPtr &CommandQueue, bool IsHostTaskCommand) {
248+
std::vector<ur_event_handle_t> RetUrEvents;
249+
for (auto &EventImpl : EventImpls) {
250+
auto Handle = EventImpl->getHandle();
251+
if (Handle == nullptr)
252+
continue;
253+
254+
// Do not add redundant event dependencies for in-order queues.
255+
// At this stage dependency is definitely ur task and need to check if
256+
// current one is a host task. In this case we should not skip ur event due
257+
// to different sync mechanisms for different task types on in-order queue.
258+
if (CommandQueue && EventImpl->getWorkerQueue() == CommandQueue &&
259+
CommandQueue->isInOrder() && !IsHostTaskCommand)
260+
continue;
261+
262+
RetUrEvents.push_back(Handle);
263+
}
264+
265+
return RetUrEvents;
248266
}
249267

250268
// This function is implemented (duplicating getUrEvents a lot) as short term

sycl/source/detail/scheduler/commands.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,19 @@ class Command {
238238

239239
/// Collect UR events from EventImpls and filter out some of them in case of
240240
/// in order queue
241+
template <typename ContT>
241242
std::vector<ur_event_handle_t>
242-
getUrEvents(const std::vector<EventImplPtr> &EventImpls) const;
243-
243+
getUrEvents(const ContT &EventImpls) const {
244+
return getUrEvents(EventImpls, MWorkerQueue, isHostTask());
245+
}
246+
244247
static std::vector<ur_event_handle_t>
245248
getUrEvents(const std::vector<EventImplPtr> &EventImpls,
246249
const QueueImplPtr &CommandQueue, bool IsHostTaskCommand);
250+
static std::vector<ur_event_handle_t>
251+
getUrEvents(const std::pmr::vector<EventImplPtr> &EventImpls,
252+
const QueueImplPtr &CommandQueue, bool IsHostTaskCommand);
253+
247254
/// Collect UR events from EventImpls and filter out some of them in case of
248255
/// in order queue. Does blocking enqueue if event is expected to produce ur
249256
/// event but has empty native handle.

sycl/source/detail/scheduler/graph_builder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ Command *Scheduler::GraphBuilder::addCG(
926926
ur_exp_command_buffer_handle_t CommandBuffer,
927927
const std::vector<ur_exp_command_buffer_sync_point_t> &Dependencies) {
928928
std::vector<Requirement *> &Reqs = CommandGroup->getRequirements();
929-
std::vector<detail::EventImplPtr> &Events = CommandGroup->getEvents();
929+
std::pmr::vector<detail::EventImplPtr> &Events = CommandGroup->getEvents();
930930

931931
auto NewCmd = std::make_unique<ExecCGCommand>(std::move(CommandGroup), Queue,
932932
EventNeeded, CommandBuffer,

sycl/source/detail/scheduler/scheduler.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,15 @@ bool Scheduler::areEventsSafeForSchedulerBypass(
688688
});
689689
}
690690

691+
bool Scheduler::areEventsSafeForSchedulerBypass(
692+
const std::pmr::vector<EventImplPtr> &DepEvents, ContextImplPtr Context) {
693+
694+
return std::all_of(DepEvents.begin(), DepEvents.end(),
695+
[&Context](const EventImplPtr &SyclEventImplPtr) {
696+
return CheckEventReadiness(Context, SyclEventImplPtr);
697+
});
698+
}
699+
691700
} // namespace detail
692701
} // namespace _V1
693702
} // namespace sycl

sycl/source/detail/scheduler/scheduler.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,10 @@ class Scheduler {
484484
areEventsSafeForSchedulerBypass(const std::vector<EventImplPtr> &DepEvents,
485485
const ContextImplPtr &Context);
486486

487+
static bool
488+
areEventsSafeForSchedulerBypass(const std::pmr::vector<EventImplPtr> &DepEvents,
489+
ContextImplPtr Context);
490+
487491
protected:
488492
using RWLockT = std::shared_timed_mutex;
489493
using ReadLockT = std::shared_lock<RWLockT>;

sycl/unittests/scheduler/SchedulerTestUtils.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class MockHandler : public sycl::handler {
248248
std::vector<sycl::detail::Requirement *> &getRequirements() {
249249
return impl->CGData.MRequirements;
250250
}
251-
std::vector<sycl::detail::EventImplPtr> &getEvents() {
251+
std::pmr::vector<sycl::detail::EventImplPtr> &getEvents() {
252252
return impl->CGData.MEvents;
253253
}
254254
std::vector<sycl::detail::ArgDesc> &getArgs() { return impl->MArgs; }

0 commit comments

Comments
 (0)