Skip to content

Commit 3e85a76

Browse files
[NFC][SYCL] Change event_impl::MCommand's type void *->Command * (#19375)
1 parent 877f420 commit 3e85a76

7 files changed

Lines changed: 19 additions & 25 deletions

File tree

sycl/source/detail/event_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ bool event_impl::isCompleted() {
616616
info::event_command_status::complete;
617617
}
618618

619-
void event_impl::setCommand(void *Cmd) { MCommand = Cmd; }
619+
void event_impl::setCommand(Command *Cmd) { MCommand = Cmd; }
620620

621621
} // namespace detail
622622
} // namespace _V1

sycl/source/detail/event_impl.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class context_impl;
3232
class queue_impl;
3333
class event_impl;
3434
using EventImplPtr = std::shared_ptr<sycl::detail::event_impl>;
35+
class Command;
3536

3637
class event_impl {
3738
struct private_tag {
@@ -195,14 +196,14 @@ class event_impl {
195196
/// Scheduler mutex must be locked in read mode when this is called.
196197
///
197198
/// @return a generic pointer to Command object instance.
198-
void *getCommand() { return MCommand; }
199+
Command *getCommand() { return MCommand; }
199200

200201
/// Associates this event with the command.
201202
///
202203
/// Scheduler mutex must be locked in write mode when this is called.
203204
///
204205
/// @param Command is a generic pointer to Command object instance.
205-
void setCommand(void *Command);
206+
void setCommand(Command *Cmd);
206207

207208
/// Returns host profiling information.
208209
///
@@ -389,7 +390,7 @@ class event_impl {
389390
uint64_t MSubmitTime = 0;
390391
std::shared_ptr<context_impl> MContext;
391392
std::unique_ptr<HostProfilingInfo> MHostProfilingInfo;
392-
void *MCommand = nullptr;
393+
Command *MCommand = nullptr;
393394
std::weak_ptr<queue_impl> MQueue;
394395
bool MIsProfilingEnabled = false;
395396

sycl/source/detail/queue_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ sycl::detail::optional<event> queue_impl::getLastEvent() {
294294
void queue_impl::addEvent(const detail::EventImplPtr &EventImpl) {
295295
if (!EventImpl)
296296
return;
297-
auto *Cmd = static_cast<Command *>(EventImpl->getCommand());
297+
Command *Cmd = EventImpl->getCommand();
298298
if (Cmd != nullptr && EventImpl->getHandle() == nullptr) {
299299
std::weak_ptr<event_impl> EventWeakPtr{EventImpl};
300300
std::lock_guard<std::mutex> Lock{MMutex};

sycl/source/detail/scheduler/commands.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ Command::getUrEventsBlocking(const std::vector<EventImplPtr> &EventImpls,
282282
// they don't have an associated queue and command.
283283
if (!EventImpl->isInterop() && !EventImpl->isEnqueued()) {
284284
if (!EventImpl->getCommand() ||
285-
!static_cast<Command *>(EventImpl->getCommand())->producesPiEvent())
285+
!EventImpl->getCommand()->producesPiEvent())
286286
continue;
287287
std::vector<Command *> AuxCmds;
288288
Scheduler::getInstance().enqueueCommandForCG(EventImpl, AuxCmds,
@@ -766,7 +766,7 @@ Command *Command::processDepEvent(EventImplPtr DepEvent, const DepDesc &Dep,
766766
// distinction since the command might still be unenqueued at this point.
767767
bool PiEventExpected =
768768
(!DepEvent->isHost() && !DepEvent->isDefaultConstructed());
769-
if (auto *DepCmd = static_cast<Command *>(DepEvent->getCommand()))
769+
if (auto *DepCmd = DepEvent->getCommand())
770770
PiEventExpected &= DepCmd->producesPiEvent();
771771

772772
if (!PiEventExpected) {
@@ -835,7 +835,7 @@ Command *Command::addDep(EventImplPtr Event,
835835
#ifdef XPTI_ENABLE_INSTRUMENTATION
836836
// We need this for just the instrumentation, so guarding it will prevent
837837
// unused variable warnings when instrumentation is turned off
838-
Command *Cmd = (Command *)Event->getCommand();
838+
Command *Cmd = Event->getCommand();
839839
ur_event_handle_t UrEventAddr = Event->getHandle();
840840
// Now make an edge for the dependent event
841841
emitEdgeEventForEventDependence(Cmd, UrEventAddr);

sycl/source/detail/scheduler/graph_builder.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,8 +1246,7 @@ Command *Scheduler::GraphBuilder::connectDepEvent(
12461246
// Dismiss the result here as it's not a connection now,
12471247
// 'cause ConnectCmd is host one
12481248
(void)ConnectCmd->addDep(Dep, ToCleanUp);
1249-
assert(reinterpret_cast<Command *>(DepEvent->getCommand()) ==
1250-
Dep.MDepCommand);
1249+
assert(DepEvent->getCommand() == Dep.MDepCommand);
12511250
// add user to Dep.MDepCommand is already performed beyond this if branch
12521251
{
12531252
DepDesc DepOnConnect = Dep;
@@ -1260,7 +1259,7 @@ Command *Scheduler::GraphBuilder::connectDepEvent(
12601259
} else {
12611260
// It is required condition in another a path and addUser will be set in
12621261
// addDep
1263-
if (Command *DepCmd = reinterpret_cast<Command *>(DepEvent->getCommand()))
1262+
if (Command *DepCmd = DepEvent->getCommand())
12641263
DepCmd->addUser(ConnectCmd);
12651264

12661265
std::ignore = ConnectCmd->addDep(DepEvent, ToCleanUp);
@@ -1343,8 +1342,7 @@ Command *Scheduler::GraphBuilder::addCommandGraphUpdate(
13431342

13441343
// Register all the events as dependencies
13451344
for (detail::EventImplPtr e : Events) {
1346-
if (e->getCommand() &&
1347-
e->getCommand() == static_cast<Command *>(NewCmd.get())) {
1345+
if (e->getCommand() && e->getCommand() == NewCmd.get()) {
13481346
continue;
13491347
}
13501348
if (Command *ConnCmd = NewCmd->addDep(e, ToCleanUp))

sycl/source/detail/scheduler/graph_processor.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,11 @@ namespace sycl {
1717
inline namespace _V1 {
1818
namespace detail {
1919

20-
static Command *getCommand(const EventImplPtr &Event) {
21-
return (Command *)Event->getCommand();
22-
}
23-
2420
void Scheduler::GraphProcessor::waitForEvent(const EventImplPtr &Event,
2521
ReadLockT &GraphReadLock,
2622
std::vector<Command *> &ToCleanUp,
2723
bool LockTheLock, bool *Success) {
28-
Command *Cmd = getCommand(Event);
24+
Command *Cmd = Event->getCommand();
2925
// Command can be nullptr if user creates sycl::event explicitly or the
3026
// event has been waited on by another thread
3127
if (!Cmd)
@@ -87,7 +83,7 @@ bool Scheduler::GraphProcessor::enqueueCommand(
8783
// Recursively enqueue all the implicit + explicit backend level dependencies
8884
// first and exit immediately if any of the commands cannot be enqueued.
8985
for (const EventImplPtr &Event : Cmd->getPreparedDepsEvents()) {
90-
if (Command *DepCmd = static_cast<Command *>(Event->getCommand()))
86+
if (Command *DepCmd = Event->getCommand())
9187
if (!enqueueCommand(DepCmd, GraphReadLock, EnqueueResult, ToCleanUp,
9288
RootCommand, Blocking))
9389
return false;
@@ -100,7 +96,7 @@ bool Scheduler::GraphProcessor::enqueueCommand(
10096
// MHostDepsEvents. TO FIX: implement enqueue of blocked commands on host task
10197
// completion stage and eliminate this event waiting in enqueue.
10298
for (const EventImplPtr &Event : Cmd->getPreparedHostDepsEvents()) {
103-
if (Command *DepCmd = static_cast<Command *>(Event->getCommand()))
99+
if (Command *DepCmd = Event->getCommand())
104100
if (!enqueueCommand(DepCmd, GraphReadLock, EnqueueResult, ToCleanUp,
105101
RootCommand, Blocking))
106102
return false;

sycl/source/detail/scheduler/scheduler.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ void Scheduler::enqueueCommandForCG(EventImplPtr NewEvent,
159159
{
160160
ReadLockT Lock = acquireReadLock();
161161

162-
Command *NewCmd =
163-
(NewEvent) ? static_cast<Command *>(NewEvent->getCommand()) : nullptr;
162+
Command *NewCmd = (NewEvent) ? NewEvent->getCommand() : nullptr;
164163

165164
EnqueueResultT Res;
166165
bool Enqueued;
@@ -366,7 +365,7 @@ EventImplPtr Scheduler::addHostAccessor(Requirement *Req) {
366365
"Enqueue process failed.");
367366
}
368367

369-
if (Command *NewCmd = static_cast<Command *>(NewCmdEvent->getCommand())) {
368+
if (Command *NewCmd = NewCmdEvent->getCommand()) {
370369
Enqueued =
371370
GraphProcessor::enqueueCommand(NewCmd, Lock, Res, ToCleanUp, NewCmd);
372371
if (!Enqueued && EnqueueResultT::SyclEnqueueFailed == Res.MResult)
@@ -418,7 +417,7 @@ void Scheduler::enqueueUnblockedCommands(
418417
const std::vector<EventImplPtr> &ToEnqueue, ReadLockT &GraphReadLock,
419418
std::vector<Command *> &ToCleanUp) {
420419
for (auto &Event : ToEnqueue) {
421-
Command *Cmd = static_cast<Command *>(Event->getCommand());
420+
Command *Cmd = Event->getCommand();
422421
if (!Cmd)
423422
continue;
424423
EnqueueResultT Res;
@@ -674,7 +673,7 @@ EventImplPtr Scheduler::addCommandGraphUpdate(
674673
"Enqueue process failed.");
675674
}
676675

677-
if (Command *NewCmd = static_cast<Command *>(NewCmdEvent->getCommand())) {
676+
if (Command *NewCmd = NewCmdEvent->getCommand()) {
678677
Enqueued =
679678
GraphProcessor::enqueueCommand(NewCmd, Lock, Res, ToCleanUp, NewCmd);
680679
if (!Enqueued && EnqueueResultT::SyclEnqueueFailed == Res.MResult)

0 commit comments

Comments
 (0)