From 74ae06b131e4b5261720b585ceea92a0c4253e08 Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Tue, 16 Apr 2019 11:29:19 +0200 Subject: [PATCH] Add new allocation type for internal allocations in system memory Related-To: NEO-2733 Change-Id: I256d414c1e92647469dd2a80f83bdbfc8721cf43 Signed-off-by: Mateusz Jablonski --- runtime/command_stream/command_stream_receiver.cpp | 6 +++--- .../command_stream/experimental_command_buffer.cpp | 4 ++-- runtime/device_queue/device_queue_hw.inl | 2 +- runtime/helpers/flat_batch_buffer_helper_hw.inl | 4 ++-- runtime/kernel/kernel.cpp | 4 ++-- runtime/memory_manager/graphics_allocation.h | 1 + runtime/memory_manager/memory_manager.cpp | 5 +++-- runtime/os_interface/debug_settings_manager.cpp | 11 +++++++++++ ...emory_manager_allocate_in_preferred_pool_tests.inl | 6 ++++++ .../os_interface/debug_settings_manager_tests.cpp | 5 +++++ 10 files changed, 36 insertions(+), 12 deletions(-) diff --git a/runtime/command_stream/command_stream_receiver.cpp b/runtime/command_stream/command_stream_receiver.cpp index fbef4cb324..1415fbd151 100644 --- a/runtime/command_stream/command_stream_receiver.cpp +++ b/runtime/command_stream/command_stream_receiver.cpp @@ -250,7 +250,7 @@ void CommandStreamReceiver::addAubComment(const char *comment) {} GraphicsAllocation *CommandStreamReceiver::allocateDebugSurface(size_t size) { UNRECOVERABLE_IF(debugSurface != nullptr); - debugSurface = getMemoryManager()->allocateGraphicsMemoryWithProperties({size, GraphicsAllocation::AllocationType::UNDECIDED}); + debugSurface = getMemoryManager()->allocateGraphicsMemoryWithProperties({size, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY}); return debugSurface; } @@ -361,8 +361,8 @@ bool CommandStreamReceiver::createAllocationForHostSurface(HostPtrSurface &surfa auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, surface.getMemoryPointer()); if (allocation == nullptr && surface.peekIsPtrCopyAllowed()) { // Try with no host pointer allocation and copy - AllocationProperties copyProperties{surface.getSurfaceSize(), GraphicsAllocation::AllocationType::UNDECIDED}; - properties.alignment = MemoryConstants::pageSize; + AllocationProperties copyProperties{surface.getSurfaceSize(), GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY}; + copyProperties.alignment = MemoryConstants::pageSize; allocation = memoryManager->allocateGraphicsMemoryWithProperties(copyProperties); if (allocation) { memcpy_s(allocation->getUnderlyingBuffer(), allocation->getUnderlyingBufferSize(), surface.getMemoryPointer(), surface.getSurfaceSize()); diff --git a/runtime/command_stream/experimental_command_buffer.cpp b/runtime/command_stream/experimental_command_buffer.cpp index f8affaf29a..7a5bceb825 100644 --- a/runtime/command_stream/experimental_command_buffer.cpp +++ b/runtime/command_stream/experimental_command_buffer.cpp @@ -24,9 +24,9 @@ ExperimentalCommandBuffer::ExperimentalCommandBuffer(CommandStreamReceiver *csr, experimentalAllocationOffset(0), defaultPrint(true), timerResolution(profilingTimerResolution) { - timestamps = csr->getMemoryManager()->allocateGraphicsMemoryWithProperties({MemoryConstants::pageSize, GraphicsAllocation::AllocationType::UNDECIDED}); + timestamps = csr->getMemoryManager()->allocateGraphicsMemoryWithProperties({MemoryConstants::pageSize, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY}); memset(timestamps->getUnderlyingBuffer(), 0, timestamps->getUnderlyingBufferSize()); - experimentalAllocation = csr->getMemoryManager()->allocateGraphicsMemoryWithProperties({MemoryConstants::pageSize, GraphicsAllocation::AllocationType::UNDECIDED}); + experimentalAllocation = csr->getMemoryManager()->allocateGraphicsMemoryWithProperties({MemoryConstants::pageSize, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY}); memset(experimentalAllocation->getUnderlyingBuffer(), 0, experimentalAllocation->getUnderlyingBufferSize()); } diff --git a/runtime/device_queue/device_queue_hw.inl b/runtime/device_queue/device_queue_hw.inl index 0e7431a87c..e1c28c05b6 100644 --- a/runtime/device_queue/device_queue_hw.inl +++ b/runtime/device_queue/device_queue_hw.inl @@ -26,7 +26,7 @@ void DeviceQueueHw::allocateSlbBuffer() { slbSize += (4 * MemoryConstants::pageSize); // +4 pages spec restriction slbSize = alignUp(slbSize, MemoryConstants::pageSize); - slbBuffer = device->getMemoryManager()->allocateGraphicsMemoryWithProperties({slbSize, GraphicsAllocation::AllocationType::UNDECIDED}); + slbBuffer = device->getMemoryManager()->allocateGraphicsMemoryWithProperties({slbSize, GraphicsAllocation::AllocationType::DEVICE_QUEUE_BUFFER}); } template diff --git a/runtime/helpers/flat_batch_buffer_helper_hw.inl b/runtime/helpers/flat_batch_buffer_helper_hw.inl index 035bd129c8..db6f86859a 100644 --- a/runtime/helpers/flat_batch_buffer_helper_hw.inl +++ b/runtime/helpers/flat_batch_buffer_helper_hw.inl @@ -31,7 +31,7 @@ GraphicsAllocation *FlatBatchBufferHelperHw::flattenBatchBuffer(Batch batchBuffer.chainedBatchBuffer->setAubWritable(false); auto sizeMainBatchBuffer = batchBuffer.chainedBatchBufferStartOffset - batchBuffer.startOffset; auto alignedMainBatchBufferSize = alignUp(sizeMainBatchBuffer + indirectPatchCommandsSize + batchBuffer.chainedBatchBuffer->getUnderlyingBufferSize(), MemoryConstants::pageSize); - AllocationProperties flatBatchBufferProperties(alignedMainBatchBufferSize, GraphicsAllocation::AllocationType::UNDECIDED); + AllocationProperties flatBatchBufferProperties(alignedMainBatchBufferSize, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY); flatBatchBufferProperties.alignment = MemoryConstants::pageSize; flatBatchBuffer = getMemoryManager()->allocateGraphicsMemoryWithProperties(flatBatchBufferProperties); @@ -109,7 +109,7 @@ GraphicsAllocation *FlatBatchBufferHelperHw::flattenBatchBuffer(Batch flatBatchBufferSize = alignUp(flatBatchBufferSize, MemoryConstants::pageSize); flatBatchBufferSize += CSRequirements::csOverfetchSize; - AllocationProperties flatBatchBufferProperties(static_cast(flatBatchBufferSize), GraphicsAllocation::AllocationType::UNDECIDED); + AllocationProperties flatBatchBufferProperties(static_cast(flatBatchBufferSize), GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY); flatBatchBufferProperties.alignment = MemoryConstants::pageSize; flatBatchBuffer = getMemoryManager()->allocateGraphicsMemoryWithProperties(flatBatchBufferProperties); UNRECOVERABLE_IF(flatBatchBuffer == nullptr); diff --git a/runtime/kernel/kernel.cpp b/runtime/kernel/kernel.cpp index 7ae17b10d3..6c57b0ad72 100644 --- a/runtime/kernel/kernel.cpp +++ b/runtime/kernel/kernel.cpp @@ -1505,7 +1505,7 @@ void Kernel::createReflectionSurface() { kernelReflectionSize += blockCount * alignUp(maxConstantBufferSize, sizeof(void *)); kernelReflectionSize += parentImageCount * sizeof(IGIL_ImageParamters); kernelReflectionSize += parentSamplerCount * sizeof(IGIL_ParentSamplerParams); - kernelReflectionSurface = device.getMemoryManager()->allocateGraphicsMemoryWithProperties({kernelReflectionSize, GraphicsAllocation::AllocationType::UNDECIDED}); + kernelReflectionSurface = device.getMemoryManager()->allocateGraphicsMemoryWithProperties({kernelReflectionSize, GraphicsAllocation::AllocationType::DEVICE_QUEUE_BUFFER}); for (uint32_t i = 0; i < blockCount; i++) { const KernelInfo *pBlockInfo = blockManager->getBlockKernelInfo(i); @@ -1579,7 +1579,7 @@ void Kernel::createReflectionSurface() { if (DebugManager.flags.ForceDispatchScheduler.get()) { if (this->isSchedulerKernel && kernelReflectionSurface == nullptr) { - kernelReflectionSurface = device.getMemoryManager()->allocateGraphicsMemoryWithProperties({MemoryConstants::pageSize, GraphicsAllocation::AllocationType::UNDECIDED}); + kernelReflectionSurface = device.getMemoryManager()->allocateGraphicsMemoryWithProperties({MemoryConstants::pageSize, GraphicsAllocation::AllocationType::DEVICE_QUEUE_BUFFER}); } } } diff --git a/runtime/memory_manager/graphics_allocation.h b/runtime/memory_manager/graphics_allocation.h index 5a4fa40def..2f0615e945 100644 --- a/runtime/memory_manager/graphics_allocation.h +++ b/runtime/memory_manager/graphics_allocation.h @@ -53,6 +53,7 @@ class GraphicsAllocation : public IDNode { INDIRECT_OBJECT_HEAP, INSTRUCTION_HEAP, INTERNAL_HEAP, + INTERNAL_HOST_MEMORY, KERNEL_ISA, LINEAR_STREAM, PIPE, diff --git a/runtime/memory_manager/memory_manager.cpp b/runtime/memory_manager/memory_manager.cpp index 9676eb1b66..30904271a5 100644 --- a/runtime/memory_manager/memory_manager.cpp +++ b/runtime/memory_manager/memory_manager.cpp @@ -110,13 +110,13 @@ void MemoryManager::cleanGraphicsMemoryCreatedFromHostPtr(GraphicsAllocation *gr GraphicsAllocation *MemoryManager::createGraphicsAllocationWithPadding(GraphicsAllocation *inputGraphicsAllocation, size_t sizeWithPadding) { if (!paddingAllocation) { - paddingAllocation = allocateGraphicsMemoryWithProperties({paddingBufferSize, GraphicsAllocation::AllocationType::UNDECIDED}); + paddingAllocation = allocateGraphicsMemoryWithProperties({paddingBufferSize, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY}); } return createPaddedAllocation(inputGraphicsAllocation, sizeWithPadding); } GraphicsAllocation *MemoryManager::createPaddedAllocation(GraphicsAllocation *inputGraphicsAllocation, size_t sizeWithPadding) { - return allocateGraphicsMemoryWithProperties({sizeWithPadding, GraphicsAllocation::AllocationType::UNDECIDED}); + return allocateGraphicsMemoryWithProperties({sizeWithPadding, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY}); } void MemoryManager::freeSystemMemory(void *ptr) { @@ -280,6 +280,7 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo case GraphicsAllocation::AllocationType::SVM_CPU: case GraphicsAllocation::AllocationType::SVM_ZERO_COPY: case GraphicsAllocation::AllocationType::TAG_BUFFER: + case GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY: case GraphicsAllocation::AllocationType::UNDECIDED: allocationData.flags.useSystemMemory = true; default: diff --git a/runtime/os_interface/debug_settings_manager.cpp b/runtime/os_interface/debug_settings_manager.cpp index edb6e1afcc..912fa6c07d 100644 --- a/runtime/os_interface/debug_settings_manager.cpp +++ b/runtime/os_interface/debug_settings_manager.cpp @@ -331,6 +331,12 @@ const char *DebugSettingsManager::getAllocationTypeString(GraphicsAl return "INDIRECT_OBJECT_HEAP"; case GraphicsAllocation::AllocationType::INSTRUCTION_HEAP: return "INSTRUCTION_HEAP"; + case GraphicsAllocation::AllocationType::INTERNAL_HEAP: + return "INTERNAL_HEAP"; + case GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY: + return "INTERNAL_HOST_MEMORY"; + case GraphicsAllocation::AllocationType::KERNEL_ISA: + return "KERNEL_ISA"; case GraphicsAllocation::AllocationType::LINEAR_STREAM: return "LINEAR_STREAM"; case GraphicsAllocation::AllocationType::PIPE: @@ -343,6 +349,10 @@ const char *DebugSettingsManager::getAllocationTypeString(GraphicsAl return "PROFILING_TAG_BUFFER"; case GraphicsAllocation::AllocationType::SCRATCH_SURFACE: return "SCRATCH_SURFACE"; + case GraphicsAllocation::AllocationType::SHARED_BUFFER: + return "SHARED_BUFFER"; + case GraphicsAllocation::AllocationType::SHARED_IMAGE: + return "SHARED_IMAGE"; case GraphicsAllocation::AllocationType::SHARED_RESOURCE_COPY: return "SHARED_RESOURCE_COPY"; case GraphicsAllocation::AllocationType::SURFACE_STATE_HEAP: @@ -361,6 +371,7 @@ const char *DebugSettingsManager::getAllocationTypeString(GraphicsAl return "UNDECIDED"; case GraphicsAllocation::AllocationType::UNKNOWN: return "UNKNOWN"; + default: return "ILLEGAL_VALUE"; } diff --git a/unit_tests/memory_manager/memory_manager_allocate_in_preferred_pool_tests.inl b/unit_tests/memory_manager/memory_manager_allocate_in_preferred_pool_tests.inl index a61e3abe2b..e4d4bea55e 100644 --- a/unit_tests/memory_manager/memory_manager_allocate_in_preferred_pool_tests.inl +++ b/unit_tests/memory_manager/memory_manager_allocate_in_preferred_pool_tests.inl @@ -374,6 +374,12 @@ TEST(MemoryManagerTest, givenDeviceQueueBufferTypeWhenGetAllocationDataIsCalledT EXPECT_TRUE(allocData.flags.useSystemMemory); } +TEST(MemoryManagerTest, givenInternalHostMemoryTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsRequested) { + AllocationData allocData; + MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY}, {}, nullptr); + EXPECT_TRUE(allocData.flags.useSystemMemory); +} + TEST(MemoryManagerTest, givenFillPatternTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsRequested) { AllocationData allocData; MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::FILL_PATTERN}, {}, nullptr); diff --git a/unit_tests/os_interface/debug_settings_manager_tests.cpp b/unit_tests/os_interface/debug_settings_manager_tests.cpp index 757815454e..ad2d065ff6 100644 --- a/unit_tests/os_interface/debug_settings_manager_tests.cpp +++ b/unit_tests/os_interface/debug_settings_manager_tests.cpp @@ -904,12 +904,17 @@ AllocationTypeTestCase allocationTypeValues[] = { {GraphicsAllocation::AllocationType::IMAGE, "IMAGE"}, {GraphicsAllocation::AllocationType::INDIRECT_OBJECT_HEAP, "INDIRECT_OBJECT_HEAP"}, {GraphicsAllocation::AllocationType::INSTRUCTION_HEAP, "INSTRUCTION_HEAP"}, + {GraphicsAllocation::AllocationType::INTERNAL_HEAP, "INTERNAL_HEAP"}, + {GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, "INTERNAL_HOST_MEMORY"}, + {GraphicsAllocation::AllocationType::KERNEL_ISA, "KERNEL_ISA"}, {GraphicsAllocation::AllocationType::LINEAR_STREAM, "LINEAR_STREAM"}, {GraphicsAllocation::AllocationType::PIPE, "PIPE"}, {GraphicsAllocation::AllocationType::PRINTF_SURFACE, "PRINTF_SURFACE"}, {GraphicsAllocation::AllocationType::PRIVATE_SURFACE, "PRIVATE_SURFACE"}, {GraphicsAllocation::AllocationType::PROFILING_TAG_BUFFER, "PROFILING_TAG_BUFFER"}, {GraphicsAllocation::AllocationType::SCRATCH_SURFACE, "SCRATCH_SURFACE"}, + {GraphicsAllocation::AllocationType::SHARED_BUFFER, "SHARED_BUFFER"}, + {GraphicsAllocation::AllocationType::SHARED_IMAGE, "SHARED_IMAGE"}, {GraphicsAllocation::AllocationType::SHARED_RESOURCE_COPY, "SHARED_RESOURCE_COPY"}, {GraphicsAllocation::AllocationType::SURFACE_STATE_HEAP, "SURFACE_STATE_HEAP"}, {GraphicsAllocation::AllocationType::SVM_CPU, "SVM_CPU"},