Skip to content

Commit 171a614

Browse files
Fix reset border color offset when replacing heap buffer
Signed-off-by: Maciej Plewka <[email protected]>
1 parent 6bd7fed commit 171a614

File tree

5 files changed

+68
-0
lines changed

5 files changed

+68
-0
lines changed

opencl/test/unit_test/command_queue/command_queue_tests.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,19 @@ TEST_P(CommandQueueIndirectHeapTest, WhenGettingIndirectHeapWithNewSizeThenMaxAv
571571
}
572572
}
573573

574+
TEST_P(CommandQueueIndirectHeapTest, WhenGettingIndirectHeapWithNewSizeThenBorderColorOffsetIsSetToMaxUint) {
575+
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
576+
MockCommandQueue cmdQ(context.get(), pClDevice, props);
577+
578+
auto &indirectHeapInitial = cmdQ.getIndirectHeap(this->GetParam(), 10);
579+
indirectHeapInitial.setBorderColor(nullptr, 0);
580+
EXPECT_NE(indirectHeapInitial.getBorderColorOffset(), std::numeric_limits<uint32_t>::max());
581+
size_t requiredSize = indirectHeapInitial.getMaxAvailableSpace() + 42;
582+
583+
const auto &indirectHeap = cmdQ.getIndirectHeap(this->GetParam(), requiredSize);
584+
EXPECT_EQ(indirectHeap.getBorderColorOffset(), std::numeric_limits<uint32_t>::max());
585+
}
586+
574587
TEST_P(CommandQueueIndirectHeapTest, WhenGettingIndirectHeapThenSizeIsAlignedToCacheLine) {
575588
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
576589
MockCommandQueue cmdQ(context.get(), pClDevice, props);
@@ -707,6 +720,27 @@ TEST_P(CommandQueueIndirectHeapTest, GivenCommandQueueWithHeapAllocatedWhenIndir
707720
EXPECT_EQ(0u, indirectHeap.getMaxAvailableSpace());
708721
}
709722

723+
TEST_P(CommandQueueIndirectHeapTest, GivenCommandQueueWithHeapAllocatedWhenIndirectHeapIsReleasedThenBorderColorOffsetResetWasCalled) {
724+
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
725+
MockCommandQueue cmdQ(context.get(), pClDevice, props);
726+
727+
EXPECT_TRUE(pDevice->getDefaultEngine().commandStreamReceiver->getAllocationsForReuse().peekIsEmpty());
728+
729+
const auto &indirectHeap = cmdQ.getIndirectHeap(this->GetParam(), 100);
730+
auto heapSize = indirectHeap.getMaxAvailableSpace();
731+
732+
EXPECT_NE(0u, heapSize);
733+
734+
auto graphicsAllocation = indirectHeap.getGraphicsAllocation();
735+
EXPECT_NE(nullptr, graphicsAllocation);
736+
737+
auto &csr = pDevice->getUltCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>();
738+
csr.indirectHeap[this->GetParam()]->setBorderColor(nullptr, 0);
739+
EXPECT_NE(csr.indirectHeap[this->GetParam()]->getBorderColorOffset(), std::numeric_limits<uint32_t>::max());
740+
cmdQ.releaseIndirectHeap(this->GetParam());
741+
EXPECT_EQ(csr.indirectHeap[this->GetParam()]->getBorderColorOffset(), std::numeric_limits<uint32_t>::max());
742+
}
743+
710744
TEST_P(CommandQueueIndirectHeapTest, GivenCommandQueueWithoutHeapAllocatedWhenIndirectHeapIsReleasedThenIndirectHeapAllocationStaysNull) {
711745
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
712746
MockCommandQueue cmdQ(context.get(), pClDevice, props);

shared/source/command_container/cmdcontainer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ IndirectHeap *CommandContainer::getHeapWithRequiredSizeAndAlignment(HeapType hea
203203
getResidencyContainer().push_back(newAlloc);
204204
getDeallocationContainer().push_back(oldAlloc);
205205
setIndirectHeapAllocation(heapType, newAlloc);
206+
indirectHeap->resetBorderColorOffset();
206207
if (oldBase != newBase) {
207208
setHeapDirty(heapType);
208209
}

shared/source/command_stream/command_stream_receiver.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ void CommandStreamReceiver::allocateHeapMemory(IndirectHeap::Type heapType,
420420
if (indirectHeap) {
421421
indirectHeap->replaceBuffer(heapMemory->getUnderlyingBuffer(), finalHeapSize);
422422
indirectHeap->replaceGraphicsAllocation(heapMemory);
423+
indirectHeap->resetBorderColorOffset();
423424
} else {
424425
indirectHeap = new IndirectHeap(heapMemory, requireInternalHeap);
425426
indirectHeap->overrideMaxSize(finalHeapSize);
@@ -437,6 +438,7 @@ void CommandStreamReceiver::releaseIndirectHeap(IndirectHeap::Type heapType) {
437438
internalAllocationStorage->storeAllocation(std::unique_ptr<GraphicsAllocation>(heapMemory), REUSABLE_ALLOCATION);
438439
heap->replaceBuffer(nullptr, 0);
439440
heap->replaceGraphicsAllocation(nullptr);
441+
heap->resetBorderColorOffset();
440442
}
441443
}
442444

shared/source/indirect_heap/indirect_heap.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class IndirectHeap : public LinearStream {
4747
uint32_t getHeapSizeInPages() const;
4848
uint32_t getBorderColorOffset() const;
4949
void setBorderColor(void *borderColor, size_t size);
50+
void resetBorderColorOffset();
5051

5152
protected:
5253
bool canBeUtilizedAs4GbHeap = false;
@@ -90,4 +91,7 @@ inline void IndirectHeap::setBorderColor(void *borderColor, size_t size) {
9091
auto ptr = getSpace(size);
9192
memcpy_s(ptr, size, borderColor, size);
9293
}
94+
inline void IndirectHeap::resetBorderColorOffset() {
95+
borderColorOffset = std::numeric_limits<uint32_t>::max();
96+
}
9397
} // namespace NEO

shared/test/unit_test/command_container/command_container_tests.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,33 @@ TEST_F(CommandContainerTest, givenNotEnoughSpaceWhenGetHeapWithRequiredSizeAndAl
367367
cmdContainer->getDeallocationContainer().clear();
368368
}
369369

370+
TEST_F(CommandContainerTest, givenNotEnoughSpaceWhenGetHeapWithRequiredSizeAndAlignmentCalledThenBorderColorOffestHasBeenReset) {
371+
std::unique_ptr<CommandContainer> cmdContainer(new CommandContainer);
372+
cmdContainer->initialize(pDevice);
373+
cmdContainer->setDirtyStateForAllHeaps(false);
374+
HeapType types[] = {HeapType::SURFACE_STATE,
375+
HeapType::DYNAMIC_STATE};
376+
377+
for (auto type : types) {
378+
auto heap = cmdContainer->getIndirectHeap(type);
379+
heap->setBorderColor(nullptr, 0);
380+
EXPECT_NE(heap->getBorderColorOffset(), std::numeric_limits<uint32_t>::max());
381+
const size_t sizeRequested = 32;
382+
const size_t alignment = 32;
383+
size_t availableSize = heap->getAvailableSpace();
384+
385+
heap->getSpace(availableSize - sizeRequested / 2);
386+
387+
EXPECT_LT(heap->getAvailableSpace(), sizeRequested + alignment);
388+
auto heapRequested = cmdContainer->getHeapWithRequiredSizeAndAlignment(type, sizeRequested, alignment);
389+
EXPECT_EQ(heapRequested->getBorderColorOffset(), std::numeric_limits<uint32_t>::max());
390+
}
391+
for (auto deallocation : cmdContainer->getDeallocationContainer()) {
392+
cmdContainer->getDevice()->getMemoryManager()->freeGraphicsMemory(deallocation);
393+
}
394+
cmdContainer->getDeallocationContainer().clear();
395+
}
396+
370397
TEST_F(CommandContainerTest, givenNotEnoughSpaceWhenCreatedAlocationHaveDifferentBaseThenHeapIsDirty) {
371398
std::unique_ptr<CommandContainer> cmdContainer(new CommandContainer);
372399
cmdContainer->initialize(pDevice);

0 commit comments

Comments
 (0)