From 4139e88982823ccc22d4327f7c36a5aced24882b Mon Sep 17 00:00:00 2001 From: "Mrozek, Michal" Date: Wed, 20 Feb 2019 12:43:37 +0100 Subject: [PATCH] Allocate command buffers with proper allocation type. Change-Id: I912dd41cf68fa16ab481bb003c4f5ae63f1f04c4 --- runtime/command_queue/command_queue.cpp | 2 +- .../command_stream_receiver.cpp | 2 +- .../experimental_command_buffer.cpp | 2 +- runtime/memory_manager/graphics_allocation.h | 3 ++- .../windows/wddm_device_command_stream.inl | 5 +++-- .../command_queue/command_queue_tests.cpp | 6 ++--- .../command_stream_receiver_tests.cpp | 2 +- .../experimental_command_buffer_tests.cpp | 4 ++-- .../graphics_allocation_tests.cpp | 4 ++++ .../windows/device_command_stream_tests.cpp | 22 +++++++++++++++++++ 10 files changed, 40 insertions(+), 12 deletions(-) diff --git a/runtime/command_queue/command_queue.cpp b/runtime/command_queue/command_queue.cpp index a1bb63c958..924963eaa0 100644 --- a/runtime/command_queue/command_queue.cpp +++ b/runtime/command_queue/command_queue.cpp @@ -211,7 +211,7 @@ LinearStream &CommandQueue::getCS(size_t minRequiredSize) { minRequiredSize += CSRequirements::csOverfetchSize; minRequiredSize = alignUp(minRequiredSize, MemoryConstants::pageSize64k); - auto allocationType = GraphicsAllocation::AllocationType::LINEAR_STREAM; + auto allocationType = GraphicsAllocation::AllocationType::COMMAND_BUFFER; GraphicsAllocation *allocation = storageForAllocation->obtainReusableAllocation(minRequiredSize, allocationType).release(); if (!allocation) { diff --git a/runtime/command_stream/command_stream_receiver.cpp b/runtime/command_stream/command_stream_receiver.cpp index 1d46bb7d5f..310d178a31 100644 --- a/runtime/command_stream/command_stream_receiver.cpp +++ b/runtime/command_stream/command_stream_receiver.cpp @@ -130,7 +130,7 @@ LinearStream &CommandStreamReceiver::getCS(size_t minRequiredSize) { // If not, allocate a new block. allocate full pages minRequiredSize = alignUp(minRequiredSize, MemoryConstants::pageSize64k); - auto allocationType = GraphicsAllocation::AllocationType::LINEAR_STREAM; + auto allocationType = GraphicsAllocation::AllocationType::COMMAND_BUFFER; auto allocation = internalAllocationStorage->obtainReusableAllocation(minRequiredSize, allocationType).release(); if (!allocation) { allocation = getMemoryManager()->allocateGraphicsMemoryWithProperties({minRequiredSize, allocationType}); diff --git a/runtime/command_stream/experimental_command_buffer.cpp b/runtime/command_stream/experimental_command_buffer.cpp index 879ca5d086..1170a32800 100644 --- a/runtime/command_stream/experimental_command_buffer.cpp +++ b/runtime/command_stream/experimental_command_buffer.cpp @@ -59,7 +59,7 @@ void ExperimentalCommandBuffer::getCS(size_t minRequiredSize) { auto requiredSize = minRequiredSize + CSRequirements::csOverfetchSize; auto storageWithAllocations = commandStreamReceiver->getInternalAllocationStorage(); - auto allocationType = GraphicsAllocation::AllocationType::LINEAR_STREAM; + auto allocationType = GraphicsAllocation::AllocationType::COMMAND_BUFFER; GraphicsAllocation *allocation = storageWithAllocations->obtainReusableAllocation(requiredSize, allocationType).release(); if (!allocation) { allocation = memoryManager->allocateGraphicsMemoryWithProperties({requiredSize, allocationType}); diff --git a/runtime/memory_manager/graphics_allocation.h b/runtime/memory_manager/graphics_allocation.h index 5f0bc1b2a6..745f0c3188 100644 --- a/runtime/memory_manager/graphics_allocation.h +++ b/runtime/memory_manager/graphics_allocation.h @@ -168,7 +168,8 @@ class GraphicsAllocation : public IDNode { return allocationType == AllocationType::LINEAR_STREAM || allocationType == AllocationType::KERNEL_ISA || allocationType == AllocationType::INTERNAL_HEAP || - allocationType == AllocationType::TIMESTAMP_PACKET_TAG_BUFFER; + allocationType == AllocationType::TIMESTAMP_PACKET_TAG_BUFFER || + allocationType == AllocationType::COMMAND_BUFFER; } protected: diff --git a/runtime/os_interface/windows/wddm_device_command_stream.inl b/runtime/os_interface/windows/wddm_device_command_stream.inl index b5805246c1..6a49b52912 100644 --- a/runtime/os_interface/windows/wddm_device_command_stream.inl +++ b/runtime/os_interface/windows/wddm_device_command_stream.inl @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2018 Intel Corporation + * Copyright (C) 2017-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -193,7 +193,8 @@ template void WddmCommandStreamReceiver::kmDafLockAllocations(ResidencyContainer &allocationsForResidency) { for (auto &graphicsAllocation : allocationsForResidency) { if ((GraphicsAllocation::AllocationType::LINEAR_STREAM == graphicsAllocation->getAllocationType()) || - (GraphicsAllocation::AllocationType::FILL_PATTERN == graphicsAllocation->getAllocationType())) { + (GraphicsAllocation::AllocationType::FILL_PATTERN == graphicsAllocation->getAllocationType()) || + (GraphicsAllocation::AllocationType::COMMAND_BUFFER == graphicsAllocation->getAllocationType())) { wddm->kmDafLock(static_cast(graphicsAllocation)); } } diff --git a/unit_tests/command_queue/command_queue_tests.cpp b/unit_tests/command_queue/command_queue_tests.cpp index 9a66d786fe..7dd1121f65 100644 --- a/unit_tests/command_queue/command_queue_tests.cpp +++ b/unit_tests/command_queue/command_queue_tests.cpp @@ -332,7 +332,7 @@ TEST_F(CommandQueueCommandStreamTest, givenCommandStreamReceiverWithReusableAllo auto memoryManager = pDevice->getMemoryManager(); size_t requiredSize = alignUp(100 + CSRequirements::minCommandQueueCommandStreamSize + CSRequirements::csOverfetchSize, MemoryConstants::pageSize64k); - auto allocation = memoryManager->allocateGraphicsMemoryWithProperties({requiredSize, GraphicsAllocation::AllocationType::LINEAR_STREAM}); + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties({requiredSize, GraphicsAllocation::AllocationType::COMMAND_BUFFER}); auto &commandStreamReceiver = cmdQ.getCommandStreamReceiver(); commandStreamReceiver.getInternalAllocationStorage()->storeAllocation(std::unique_ptr(allocation), REUSABLE_ALLOCATION); @@ -376,7 +376,7 @@ TEST_F(CommandQueueCommandStreamTest, CommandQueueWhenAskedForNewCommandStreamSt EXPECT_TRUE(pDevice->getDefaultEngine().commandStreamReceiver->getAllocationsForReuse().peekContains(*graphicsAllocation)); } -TEST_F(CommandQueueCommandStreamTest, givenCommandQueueWhenGetCSIsCalledThenCommandStreamAllocationTypeShouldBeSetToLinearStream) { +TEST_F(CommandQueueCommandStreamTest, givenCommandQueueWhenGetCSIsCalledThenCommandStreamAllocationTypeShouldBeSetToCommandBuffer) { const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0}; CommandQueue cmdQ(context.get(), pDevice, props); @@ -384,7 +384,7 @@ TEST_F(CommandQueueCommandStreamTest, givenCommandQueueWhenGetCSIsCalledThenComm auto commandStreamAllocation = commandStream.getGraphicsAllocation(); ASSERT_NE(nullptr, commandStreamAllocation); - EXPECT_EQ(GraphicsAllocation::AllocationType::LINEAR_STREAM, commandStreamAllocation->getAllocationType()); + EXPECT_EQ(GraphicsAllocation::AllocationType::COMMAND_BUFFER, commandStreamAllocation->getAllocationType()); } struct CommandQueueIndirectHeapTest : public CommandQueueMemoryDevice, diff --git a/unit_tests/command_stream/command_stream_receiver_tests.cpp b/unit_tests/command_stream/command_stream_receiver_tests.cpp index faf43d46b4..9e3f582b26 100644 --- a/unit_tests/command_stream/command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_tests.cpp @@ -135,7 +135,7 @@ TEST_F(CommandStreamReceiverTest, givenCommandStreamReceiverWhenGetCSIsCalledThe auto commandStreamAllocation = commandStream.getGraphicsAllocation(); ASSERT_NE(nullptr, commandStreamAllocation); - EXPECT_EQ(GraphicsAllocation::AllocationType::LINEAR_STREAM, commandStreamAllocation->getAllocationType()); + EXPECT_EQ(GraphicsAllocation::AllocationType::COMMAND_BUFFER, commandStreamAllocation->getAllocationType()); } HWTEST_F(CommandStreamReceiverTest, givenPtrAndSizeThatMeetL3CriteriaWhenMakeResidentHostPtrThenCsrEnableL3) { diff --git a/unit_tests/command_stream/experimental_command_buffer_tests.cpp b/unit_tests/command_stream/experimental_command_buffer_tests.cpp index bd7d5e3acb..67c24796b5 100644 --- a/unit_tests/command_stream/experimental_command_buffer_tests.cpp +++ b/unit_tests/command_stream/experimental_command_buffer_tests.cpp @@ -247,9 +247,9 @@ HWTEST_F(MockExperimentalCommandBufferTest, givenEnabledExperimentalCmdBufferWhe MemoryManager *memoryManager = commandStreamReceiver.getMemoryManager(); //Make two allocations, since CSR will try to reuse it also - auto allocation = memoryManager->allocateGraphicsMemoryWithProperties({3 * MemoryConstants::pageSize64k, GraphicsAllocation::AllocationType::LINEAR_STREAM}); + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties({3 * MemoryConstants::pageSize64k, GraphicsAllocation::AllocationType::COMMAND_BUFFER}); storage->storeAllocation(std::unique_ptr(allocation), REUSABLE_ALLOCATION); - allocation = memoryManager->allocateGraphicsMemoryWithProperties({3 * MemoryConstants::pageSize64k, GraphicsAllocation::AllocationType::LINEAR_STREAM}); + allocation = memoryManager->allocateGraphicsMemoryWithProperties({3 * MemoryConstants::pageSize64k, GraphicsAllocation::AllocationType::COMMAND_BUFFER}); storage->storeAllocation(std::unique_ptr(allocation), REUSABLE_ALLOCATION); MockExperimentalCommandBuffer *mockExCmdBuffer = static_cast(commandStreamReceiver.experimentalCmdBuffer.get()); diff --git a/unit_tests/memory_manager/graphics_allocation_tests.cpp b/unit_tests/memory_manager/graphics_allocation_tests.cpp index ee54717694..42d49a7cd5 100644 --- a/unit_tests/memory_manager/graphics_allocation_tests.cpp +++ b/unit_tests/memory_manager/graphics_allocation_tests.cpp @@ -128,3 +128,7 @@ TEST(GraphicsAllocationTest, whenAllocationTypeIsInternalHeapThenCpuAccessIsRequ TEST(GraphicsAllocationTest, whenAllocationTypeIsTimestampPacketThenCpuAccessIsRequired) { EXPECT_TRUE(GraphicsAllocation::isCpuAccessRequired(GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER)); } + +TEST(GraphicsAllocationTest, whenAllocationTypeIsCommandBufferThenCpuAccessIsRequired) { + EXPECT_TRUE(GraphicsAllocation::isCpuAccessRequired(GraphicsAllocation::AllocationType::COMMAND_BUFFER)); +} 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 208e6a87d0..2cb31dee44 100644 --- a/unit_tests/os_interface/windows/device_command_stream_tests.cpp +++ b/unit_tests/os_interface/windows/device_command_stream_tests.cpp @@ -469,6 +469,28 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllo memoryManager->freeGraphicsMemory(fillPatternAllocation); } +TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllocationsForResidencyThenCommandBufferAllocationsShouldBeKmDafLocked) { + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + ASSERT_NE(nullptr, commandBuffer); + LinearStream cs(commandBuffer); + BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; + + auto commandBufferAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + ASSERT_NE(nullptr, commandBufferAllocation); + commandBufferAllocation->setAllocationType(GraphicsAllocation::AllocationType::COMMAND_BUFFER); + ResidencyContainer allocationsForResidency = {commandBufferAllocation}; + + wddm->setKmDafEnabled(true); + csr->flush(batchBuffer, allocationsForResidency); + + EXPECT_EQ(1u, wddm->kmDafLockResult.called); + EXPECT_EQ(1u, wddm->kmDafLockResult.lockedAllocations.size()); + EXPECT_EQ(commandBufferAllocation, wddm->kmDafLockResult.lockedAllocations[0]); + + memoryManager->freeGraphicsMemory(commandBuffer); + memoryManager->freeGraphicsMemory(commandBufferAllocation); +} + TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllocationsForResidencyThenNonLinearStreamAllocationShouldNotBeKmDafLocked) { GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, commandBuffer);