Skip to content

Commit 4c4054b

Browse files
author
Ivan Karachun
authored
[SYCL] Fixed sub-buffer memory allocation update (#1486)
In some cases parent`s memory allocation might change (e.g., after map/unmap operations). If parent`s memory allocation changes, sub-buffer memory allocation should be changed as well. Signed-off-by: Ivan Karachun <[email protected]>
1 parent c7afc22 commit 4c4054b

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

sycl/source/detail/scheduler/commands.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,18 @@ void AllocaSubBufCommand::emitInstrumentationData() {
694694
#endif
695695
}
696696

697+
void *AllocaSubBufCommand::getMemAllocation() const {
698+
// In some cases parent`s memory allocation might change (e.g., after
699+
// map/unmap operations). If parent`s memory allocation changes, sub-buffer
700+
// memory allocation should be changed as well.
701+
if (MQueue->is_host()) {
702+
return static_cast<void *>(
703+
static_cast<char *>(MParentAlloca->getMemAllocation()) +
704+
MRequirement.MOffsetInBytes);
705+
}
706+
return MMemAllocation;
707+
}
708+
697709
cl_int AllocaSubBufCommand::enqueueImp() {
698710
std::vector<EventImplPtr> EventImpls =
699711
Command::prepareEvents(detail::getSyclObjImpl(MQueue->get_context()));

sycl/source/detail/scheduler/commands.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class AllocaCommandBase : public Command {
264264

265265
SYCLMemObjI *getSYCLMemObj() const { return MRequirement.MSYCLMemObj; }
266266

267-
void *getMemAllocation() const { return MMemAllocation; }
267+
virtual void *getMemAllocation() const = 0;
268268

269269
const Requirement *getRequirement() const final { return &MRequirement; }
270270

@@ -298,6 +298,7 @@ class AllocaCommand : public AllocaCommandBase {
298298
bool InitFromUserData = true,
299299
AllocaCommandBase *LinkedAllocaCmd = nullptr);
300300

301+
void *getMemAllocation() const final { return MMemAllocation; }
301302
void printDot(std::ostream &Stream) const final;
302303
void emitInstrumentationData();
303304

@@ -314,6 +315,7 @@ class AllocaSubBufCommand : public AllocaCommandBase {
314315
AllocaSubBufCommand(QueueImplPtr Queue, Requirement Req,
315316
AllocaCommandBase *ParentAlloca);
316317

318+
void *getMemAllocation() const final;
317319
void printDot(std::ostream &Stream) const final;
318320
AllocaCommandBase *getParentAlloca() { return MParentAlloca; }
319321
void emitInstrumentationData();

sycl/source/detail/scheduler/graph_builder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ AllocaCommandBase *Scheduler::GraphBuilder::findAllocaForReq(
533533
bool Res = sameCtx(AllocaCmd->getQueue()->getContextImplPtr(), Context);
534534
if (IsSuitableSubReq(Req)) {
535535
const Requirement *TmpReq = AllocaCmd->getRequirement();
536+
Res &= AllocaCmd->getType() == Command::CommandType::ALLOCA_SUB_BUF;
536537
Res &= TmpReq->MOffsetInBytes == Req->MOffsetInBytes;
537538
Res &= TmpReq->MSYCLMemObj->getSize() == Req->MSYCLMemObj->getSize();
538539
}

sycl/test/basic_tests/buffer/subbuffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ void checkMultipleContexts() {
280280
{
281281
sycl::queue queue1;
282282
sycl::buffer<int, 1> buf(a, sycl::range<1>(N));
283-
sycl::buffer<int, 1> subbuf1(buf, sycl::id<1>(0), sycl::range<1>(N / 2));
283+
sycl::buffer<int, 1> subbuf1(buf, sycl::id<1>(N / 2), sycl::range<1>(N / 2));
284284
queue1.submit([&](sycl::handler &cgh) {
285285
auto bufacc = subbuf1.get_access<sycl::access::mode::read_write>(cgh);
286286
cgh.parallel_for<class sub_buffer_3>(

0 commit comments

Comments
 (0)