From a02c3cb781bbd6e3f05f7e3821ff70189448cef0 Mon Sep 17 00:00:00 2001 From: "Milczarek, Slawomir" Date: Tue, 27 Mar 2018 16:19:11 +0200 Subject: [PATCH] KM DAF AubCapture to recapture fill pattern allocations The commit introduces a recapture of fill pattern allocations on every submit. Change-Id: I634af075348dbc59c7809f58b8495326cab804e1 --- runtime/command_queue/enqueue_fill_buffer.h | 2 ++ runtime/command_queue/enqueue_svm.h | 2 ++ runtime/memory_manager/graphics_allocation.h | 1 + .../windows/wddm_device_command_stream.inl | 6 ++-- .../enqueue_fill_buffer_tests.cpp | 30 +++++++++++++++++++ .../command_queue/enqueue_svm_tests.cpp | 25 ++++++++++++++++ .../windows/device_command_stream_tests.cpp | 22 ++++++++++++++ 7 files changed, 86 insertions(+), 2 deletions(-) diff --git a/runtime/command_queue/enqueue_fill_buffer.h b/runtime/command_queue/enqueue_fill_buffer.h index 376b831ff5..820c77cdf5 100644 --- a/runtime/command_queue/enqueue_fill_buffer.h +++ b/runtime/command_queue/enqueue_fill_buffer.h @@ -53,6 +53,8 @@ cl_int CommandQueueHw::enqueueFillBuffer( patternAllocation = memoryManager->allocateGraphicsMemory(alignUp(patternSize, MemoryConstants::cacheLineSize), MemoryConstants::preferredAlignment); } + patternAllocation->setAllocationType(GraphicsAllocation::ALLOCATION_TYPE_FILL_PATTERN); + if (patternSize == 1) { int patternInt = (uint32_t)((*(uint8_t *)pattern << 24) | (*(uint8_t *)pattern << 16) | (*(uint8_t *)pattern << 8) | *(uint8_t *)pattern); memcpy_s(patternAllocation->getUnderlyingBuffer(), sizeof(int), &patternInt, sizeof(int)); diff --git a/runtime/command_queue/enqueue_svm.h b/runtime/command_queue/enqueue_svm.h index 8cca4f7e2f..5d3b7df09b 100644 --- a/runtime/command_queue/enqueue_svm.h +++ b/runtime/command_queue/enqueue_svm.h @@ -247,6 +247,8 @@ cl_int CommandQueueHw::enqueueSVMMemFill(void *svmPtr, patternAllocation = memoryManager->allocateGraphicsMemory(patternSize, MemoryConstants::preferredAlignment); } + patternAllocation->setAllocationType(GraphicsAllocation::ALLOCATION_TYPE_FILL_PATTERN); + if (patternSize == 1) { int patternInt = (uint32_t)((*(uint8_t *)pattern << 24) | (*(uint8_t *)pattern << 16) | (*(uint8_t *)pattern << 8) | *(uint8_t *)pattern); memcpy_s(patternAllocation->getUnderlyingBuffer(), sizeof(int), &patternInt, sizeof(int)); diff --git a/runtime/memory_manager/graphics_allocation.h b/runtime/memory_manager/graphics_allocation.h index 324c37b275..e53eb80fe6 100644 --- a/runtime/memory_manager/graphics_allocation.h +++ b/runtime/memory_manager/graphics_allocation.h @@ -58,6 +58,7 @@ class GraphicsAllocation : public IDNode { ALLOCATION_TYPE_IMAGE, ALLOCATION_TYPE_TAG_BUFFER, ALLOCATION_TYPE_LINEAR_STREAM, + ALLOCATION_TYPE_FILL_PATTERN, ALLOCATION_TYPE_NON_AUB_WRITABLE = 0x40000000, ALLOCATION_TYPE_WRITABLE = 0x80000000 }; diff --git a/runtime/os_interface/windows/wddm_device_command_stream.inl b/runtime/os_interface/windows/wddm_device_command_stream.inl index ff45682783..f1d865be8b 100644 --- a/runtime/os_interface/windows/wddm_device_command_stream.inl +++ b/runtime/os_interface/windows/wddm_device_command_stream.inl @@ -219,8 +219,10 @@ void WddmCommandStreamReceiver::kmDafLockAllocations(ResidencyContain auto &residencyAllocations = allocationsForResidency ? *allocationsForResidency : getMemoryManager()->getResidencyAllocations(); for (uint32_t i = 0; i < residencyAllocations.size(); i++) { - if (GraphicsAllocation::ALLOCATION_TYPE_LINEAR_STREAM == residencyAllocations[i]->getAllocationType()) { - wddm->kmDafLock(static_cast(residencyAllocations[i])); + auto graphicsAllocation = residencyAllocations[i]; + if ((GraphicsAllocation::ALLOCATION_TYPE_LINEAR_STREAM == graphicsAllocation->getAllocationType()) || + (GraphicsAllocation::ALLOCATION_TYPE_FILL_PATTERN == graphicsAllocation->getAllocationType())) { + wddm->kmDafLock(static_cast(graphicsAllocation)); } } } diff --git a/unit_tests/command_queue/enqueue_fill_buffer_tests.cpp b/unit_tests/command_queue/enqueue_fill_buffer_tests.cpp index 45b09ee81f..5b1f74f4ee 100644 --- a/unit_tests/command_queue/enqueue_fill_buffer_tests.cpp +++ b/unit_tests/command_queue/enqueue_fill_buffer_tests.cpp @@ -543,3 +543,33 @@ HWTEST_F(EnqueueFillBufferCmdTests, patternOfSizeTwoBytesShouldGetPreparedForMid EXPECT_EQ(0, memcmp(allocation->getUnderlyingBuffer(), output, size)); } + +HWTEST_F(EnqueueFillBufferCmdTests, givenEnqueueFillBufferWhenPatternAllocationIsObtainedThenItsTypeShouldBeSetToFillPattern) { + MemoryManager *mmgr = pCmdQ->getDevice().getMemoryManager(); + ASSERT_TRUE(mmgr->allocationsForReuse.peekIsEmpty()); + + auto dstBuffer = std::unique_ptr(BufferHelper<>::create()); + const uint8_t pattern[1] = {0x55}; + const size_t patternSize = sizeof(pattern); + const size_t offset = 0; + const size_t size = patternSize; + + auto retVal = clEnqueueFillBuffer( + pCmdQ, + dstBuffer.get(), + pattern, + patternSize, + offset, + size, + 0, + nullptr, + nullptr); + ASSERT_EQ(CL_SUCCESS, retVal); + + ASSERT_FALSE(mmgr->allocationsForReuse.peekIsEmpty()); + + GraphicsAllocation *patternAllocation = mmgr->allocationsForReuse.peekHead(); + ASSERT_NE(nullptr, patternAllocation); + + EXPECT_EQ(GraphicsAllocation::ALLOCATION_TYPE_FILL_PATTERN, patternAllocation->getAllocationType()); +} diff --git a/unit_tests/command_queue/enqueue_svm_tests.cpp b/unit_tests/command_queue/enqueue_svm_tests.cpp index 9966cbbebb..023b388bf7 100644 --- a/unit_tests/command_queue/enqueue_svm_tests.cpp +++ b/unit_tests/command_queue/enqueue_svm_tests.cpp @@ -445,6 +445,31 @@ TEST_F(EnqueueSvmTest, enqueueSVMMemFillDoubleToReuseAllocation_Success) { EXPECT_EQ(CL_SUCCESS, retVal); } +TEST_F(EnqueueSvmTest, givenEnqueueSVMMemFillWhenPatternAllocationIsObtainedThenItsTypeShouldBeSetToFillPattern) { + MemoryManager *mmgr = pCmdQ->getDevice().getMemoryManager(); + ASSERT_TRUE(mmgr->allocationsForReuse.peekIsEmpty()); + + const float pattern[1] = {1.2345f}; + const size_t patternSize = sizeof(pattern); + const size_t size = patternSize; + retVal = this->pCmdQ->enqueueSVMMemFill( + ptrSVM, + pattern, + patternSize, + size, + 0, + nullptr, + nullptr); + EXPECT_EQ(CL_SUCCESS, retVal); + + ASSERT_FALSE(mmgr->allocationsForReuse.peekIsEmpty()); + + GraphicsAllocation *patternAllocation = mmgr->allocationsForReuse.peekHead(); + ASSERT_NE(nullptr, patternAllocation); + + EXPECT_EQ(GraphicsAllocation::ALLOCATION_TYPE_FILL_PATTERN, patternAllocation->getAllocationType()); +} + TEST_F(EnqueueSvmTest, enqueueTaskWithKernelExecInfo_success) { GraphicsAllocation *pSvmAlloc = context->getSVMAllocsManager()->getSVMAlloc(ptrSVM); EXPECT_NE(nullptr, ptrSVM); diff --git a/unit_tests/os_interface/windows/device_command_stream_tests.cpp b/unit_tests/os_interface/windows/device_command_stream_tests.cpp index a6afe14543..24388281fb 100644 --- a/unit_tests/os_interface/windows/device_command_stream_tests.cpp +++ b/unit_tests/os_interface/windows/device_command_stream_tests.cpp @@ -389,6 +389,28 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllo memManager->freeGraphicsMemory(linearStreamAllocation); } +TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllocationsForResidencyThenFillPatternAllocationsShouldBeKmDafLocked) { + GraphicsAllocation *commandBuffer = memManager->allocateGraphicsMemory(4096, 4096); + ASSERT_NE(nullptr, commandBuffer); + LinearStream cs(commandBuffer); + BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; + + auto fillPatternAllocation = memManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + ASSERT_NE(nullptr, fillPatternAllocation); + fillPatternAllocation->setAllocationType(GraphicsAllocation::ALLOCATION_TYPE_FILL_PATTERN); + ResidencyContainer allocationsForResidency = {fillPatternAllocation}; + + wddm->setKmDafEnabled(true); + auto flushStamp = csr->flush(batchBuffer, EngineType::ENGINE_RCS, &allocationsForResidency); + + EXPECT_EQ(1u, wddm->kmDafLockResult.called); + EXPECT_EQ(1u, wddm->kmDafLockResult.lockedAllocations.size()); + EXPECT_EQ(fillPatternAllocation, wddm->kmDafLockResult.lockedAllocations[0]); + + memManager->freeGraphicsMemory(commandBuffer); + memManager->freeGraphicsMemory(fillPatternAllocation); +} + TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllocationsForResidencyThenNonLinearStreamAllocationShouldNotBeKmDafLocked) { GraphicsAllocation *commandBuffer = memManager->allocateGraphicsMemory(4096, 4096); ASSERT_NE(nullptr, commandBuffer);