Skip to content

Commit 74d69c7

Browse files
[SYCL][NFC] Pass Requirement via ref (#19383)
Currently, we are passing `Requirement` object by value, but it's inefficient (Coverity says so) as requirement is a big DS. This PR makes passing `Requirement` by ref instead.
1 parent 5f86594 commit 74d69c7

File tree

2 files changed

+36
-34
lines changed

2 files changed

+36
-34
lines changed

sycl/source/detail/scheduler/commands.cpp

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,12 +1029,12 @@ void Command::copySubmissionCodeLocation() {
10291029
}
10301030

10311031
AllocaCommandBase::AllocaCommandBase(CommandType Type, queue_impl *Queue,
1032-
Requirement Req,
1032+
const Requirement &Req,
10331033
AllocaCommandBase *LinkedAllocaCmd,
10341034
bool IsConst)
10351035
: Command(Type, Queue), MLinkedAllocaCmd(LinkedAllocaCmd),
10361036
MIsLeaderAlloca(nullptr == LinkedAllocaCmd), MIsConst(IsConst),
1037-
MRequirement(std::move(Req)), MReleaseCmd(Queue, this) {
1037+
MRequirement(Req), MReleaseCmd(Queue, this) {
10381038
MRequirement.MAccessMode = access::mode::read_write;
10391039
emitInstrumentationDataProxy();
10401040
}
@@ -1071,11 +1071,11 @@ bool AllocaCommandBase::supportsPostEnqueueCleanup() const { return false; }
10711071

10721072
bool AllocaCommandBase::readyForCleanup() const { return false; }
10731073

1074-
AllocaCommand::AllocaCommand(queue_impl *Queue, Requirement Req,
1074+
AllocaCommand::AllocaCommand(queue_impl *Queue, const Requirement &Req,
10751075
bool InitFromUserData,
10761076
AllocaCommandBase *LinkedAllocaCmd, bool IsConst)
1077-
: AllocaCommandBase(CommandType::ALLOCA, Queue, std::move(Req),
1078-
LinkedAllocaCmd, IsConst),
1077+
: AllocaCommandBase(CommandType::ALLOCA, Queue, Req, LinkedAllocaCmd,
1078+
IsConst),
10791079
MInitFromUserData(InitFromUserData) {
10801080
// Node event must be created before the dependent edge is added to this
10811081
// node, so this call must be before the addDep() call.
@@ -1149,11 +1149,12 @@ void AllocaCommand::printDot(std::ostream &Stream) const {
11491149
}
11501150
}
11511151

1152-
AllocaSubBufCommand::AllocaSubBufCommand(queue_impl *Queue, Requirement Req,
1152+
AllocaSubBufCommand::AllocaSubBufCommand(queue_impl *Queue,
1153+
const Requirement &Req,
11531154
AllocaCommandBase *ParentAlloca,
11541155
std::vector<Command *> &ToEnqueue,
11551156
std::vector<Command *> &ToCleanUp)
1156-
: AllocaCommandBase(CommandType::ALLOCA_SUB_BUF, Queue, std::move(Req),
1157+
: AllocaCommandBase(CommandType::ALLOCA_SUB_BUF, Queue, Req,
11571158
/*LinkedAllocaCmd*/ nullptr, /*IsConst*/ false),
11581159
MParentAlloca(ParentAlloca) {
11591160
// Node event must be created before the dependent edge
@@ -1358,11 +1359,11 @@ bool ReleaseCommand::supportsPostEnqueueCleanup() const { return false; }
13581359

13591360
bool ReleaseCommand::readyForCleanup() const { return false; }
13601361

1361-
MapMemObject::MapMemObject(AllocaCommandBase *SrcAllocaCmd, Requirement Req,
1362-
void **DstPtr, queue_impl *Queue,
1363-
access::mode MapMode)
1362+
MapMemObject::MapMemObject(AllocaCommandBase *SrcAllocaCmd,
1363+
const Requirement &Req, void **DstPtr,
1364+
queue_impl *Queue, access::mode MapMode)
13641365
: Command(CommandType::MAP_MEM_OBJ, Queue), MSrcAllocaCmd(SrcAllocaCmd),
1365-
MSrcReq(std::move(Req)), MDstPtr(DstPtr), MMapMode(MapMode) {
1366+
MSrcReq(Req), MDstPtr(DstPtr), MMapMode(MapMode) {
13661367
emitInstrumentationDataProxy();
13671368
}
13681369

@@ -1421,10 +1422,11 @@ void MapMemObject::printDot(std::ostream &Stream) const {
14211422
}
14221423
}
14231424

1424-
UnMapMemObject::UnMapMemObject(AllocaCommandBase *DstAllocaCmd, Requirement Req,
1425-
void **SrcPtr, queue_impl *Queue)
1425+
UnMapMemObject::UnMapMemObject(AllocaCommandBase *DstAllocaCmd,
1426+
const Requirement &Req, void **SrcPtr,
1427+
queue_impl *Queue)
14261428
: Command(CommandType::UNMAP_MEM_OBJ, Queue), MDstAllocaCmd(DstAllocaCmd),
1427-
MDstReq(std::move(Req)), MSrcPtr(SrcPtr) {
1429+
MDstReq(Req), MSrcPtr(SrcPtr) {
14281430
emitInstrumentationDataProxy();
14291431
}
14301432

@@ -1504,9 +1506,9 @@ void UnMapMemObject::printDot(std::ostream &Stream) const {
15041506
}
15051507
}
15061508

1507-
MemCpyCommand::MemCpyCommand(Requirement SrcReq,
1509+
MemCpyCommand::MemCpyCommand(const Requirement &SrcReq,
15081510
AllocaCommandBase *SrcAllocaCmd,
1509-
Requirement DstReq,
1511+
const Requirement &DstReq,
15101512
AllocaCommandBase *DstAllocaCmd,
15111513
queue_impl *SrcQueue, queue_impl *DstQueue)
15121514
: Command(CommandType::COPY_MEMORY, DstQueue),
@@ -1678,14 +1680,14 @@ void UpdateHostRequirementCommand::printDot(std::ostream &Stream) const {
16781680
}
16791681
}
16801682

1681-
MemCpyCommandHost::MemCpyCommandHost(Requirement SrcReq,
1683+
MemCpyCommandHost::MemCpyCommandHost(const Requirement &SrcReq,
16821684
AllocaCommandBase *SrcAllocaCmd,
1683-
Requirement DstReq, void **DstPtr,
1685+
const Requirement &DstReq, void **DstPtr,
16841686
queue_impl *SrcQueue, queue_impl *DstQueue)
16851687
: Command(CommandType::COPY_MEMORY, DstQueue),
16861688
MSrcQueue(SrcQueue ? SrcQueue->shared_from_this() : nullptr),
1687-
MSrcReq(std::move(SrcReq)), MSrcAllocaCmd(SrcAllocaCmd),
1688-
MDstReq(std::move(DstReq)), MDstPtr(DstPtr) {
1689+
MSrcReq(SrcReq), MSrcAllocaCmd(SrcAllocaCmd), MDstReq(DstReq),
1690+
MDstPtr(DstPtr) {
16891691
if (MSrcQueue) {
16901692
MEvent->setContextImpl(MSrcQueue->getContextImpl());
16911693
}
@@ -1850,10 +1852,10 @@ void MemCpyCommandHost::printDot(std::ostream &Stream) const {
18501852
}
18511853

18521854
UpdateHostRequirementCommand::UpdateHostRequirementCommand(
1853-
queue_impl *Queue, Requirement Req, AllocaCommandBase *SrcAllocaCmd,
1855+
queue_impl *Queue, const Requirement &Req, AllocaCommandBase *SrcAllocaCmd,
18541856
void **DstPtr)
18551857
: Command(CommandType::UPDATE_REQUIREMENT, Queue),
1856-
MSrcAllocaCmd(SrcAllocaCmd), MDstReq(std::move(Req)), MDstPtr(DstPtr) {
1858+
MSrcAllocaCmd(SrcAllocaCmd), MDstReq(Req), MDstPtr(DstPtr) {
18571859

18581860
emitInstrumentationDataProxy();
18591861
}

sycl/source/detail/scheduler/commands.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ class ReleaseCommand : public Command {
453453
/// Base class for memory allocation commands.
454454
class AllocaCommandBase : public Command {
455455
public:
456-
AllocaCommandBase(CommandType Type, queue_impl *Queue, Requirement Req,
456+
AllocaCommandBase(CommandType Type, queue_impl *Queue, const Requirement &Req,
457457
AllocaCommandBase *LinkedAllocaCmd, bool IsConst);
458458

459459
ReleaseCommand *getReleaseCmd() { return &MReleaseCmd; }
@@ -498,7 +498,7 @@ class AllocaCommandBase : public Command {
498498
/// or underlying framework.
499499
class AllocaCommand : public AllocaCommandBase {
500500
public:
501-
AllocaCommand(queue_impl *Queue, Requirement Req,
501+
AllocaCommand(queue_impl *Queue, const Requirement &Req,
502502
bool InitFromUserData = true,
503503
AllocaCommandBase *LinkedAllocaCmd = nullptr,
504504
bool IsConst = false);
@@ -518,7 +518,7 @@ class AllocaCommand : public AllocaCommandBase {
518518
/// The AllocaSubBuf command enqueues creation of sub-buffer of memory object.
519519
class AllocaSubBufCommand : public AllocaCommandBase {
520520
public:
521-
AllocaSubBufCommand(queue_impl *Queue, Requirement Req,
521+
AllocaSubBufCommand(queue_impl *Queue, const Requirement &Req,
522522
AllocaCommandBase *ParentAlloca,
523523
std::vector<Command *> &ToEnqueue,
524524
std::vector<Command *> &ToCleanUp);
@@ -537,8 +537,8 @@ class AllocaSubBufCommand : public AllocaCommandBase {
537537
/// The map command enqueues mapping of device memory onto host memory.
538538
class MapMemObject : public Command {
539539
public:
540-
MapMemObject(AllocaCommandBase *SrcAllocaCmd, Requirement Req, void **DstPtr,
541-
queue_impl *Queue, access::mode MapMode);
540+
MapMemObject(AllocaCommandBase *SrcAllocaCmd, const Requirement &Req,
541+
void **DstPtr, queue_impl *Queue, access::mode MapMode);
542542

543543
void printDot(std::ostream &Stream) const final;
544544
const Requirement *getRequirement() const final { return &MSrcReq; }
@@ -556,7 +556,7 @@ class MapMemObject : public Command {
556556
/// The unmap command removes mapping of host memory onto device memory.
557557
class UnMapMemObject : public Command {
558558
public:
559-
UnMapMemObject(AllocaCommandBase *DstAllocaCmd, Requirement Req,
559+
UnMapMemObject(AllocaCommandBase *DstAllocaCmd, const Requirement &Req,
560560
void **SrcPtr, queue_impl *Queue);
561561

562562
void printDot(std::ostream &Stream) const final;
@@ -576,8 +576,8 @@ class UnMapMemObject : public Command {
576576
/// object.
577577
class MemCpyCommand : public Command {
578578
public:
579-
MemCpyCommand(Requirement SrcReq, AllocaCommandBase *SrcAllocaCmd,
580-
Requirement DstReq, AllocaCommandBase *DstAllocaCmd,
579+
MemCpyCommand(const Requirement &SrcReq, AllocaCommandBase *SrcAllocaCmd,
580+
const Requirement &DstReq, AllocaCommandBase *DstAllocaCmd,
581581
queue_impl *SrcQueue, queue_impl *DstQueue);
582582

583583
void printDot(std::ostream &Stream) const final;
@@ -600,9 +600,9 @@ class MemCpyCommand : public Command {
600600
/// memory object.
601601
class MemCpyCommandHost : public Command {
602602
public:
603-
MemCpyCommandHost(Requirement SrcReq, AllocaCommandBase *SrcAllocaCmd,
604-
Requirement DstReq, void **DstPtr, queue_impl *SrcQueue,
605-
queue_impl *DstQueue);
603+
MemCpyCommandHost(const Requirement &SrcReq, AllocaCommandBase *SrcAllocaCmd,
604+
const Requirement &DstReq, void **DstPtr,
605+
queue_impl *SrcQueue, queue_impl *DstQueue);
606606

607607
void printDot(std::ostream &Stream) const final;
608608
const Requirement *getRequirement() const final { return &MDstReq; }
@@ -696,7 +696,7 @@ std::pair<xpti_td *, uint64_t> emitKernelInstrumentationData(
696696

697697
class UpdateHostRequirementCommand : public Command {
698698
public:
699-
UpdateHostRequirementCommand(queue_impl *Queue, Requirement Req,
699+
UpdateHostRequirementCommand(queue_impl *Queue, const Requirement &Req,
700700
AllocaCommandBase *SrcAllocaCmd, void **DstPtr);
701701

702702
void printDot(std::ostream &Stream) const final;

0 commit comments

Comments
 (0)