From 8ec072d39c581fbd816b114d70e4c98d41d3c9d5 Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Tue, 11 Dec 2018 18:56:37 +0100 Subject: [PATCH] Simplify Memory Manager API [3/4] - remove method allocateGraphicsMemory(size_t size) - pass allocation type in allocation properties - set allocation type in allocateGraphicsMemoryInPreferredPool Change-Id: Ia9296d0ab2f711b7d78aff615cb56b3a246b60ec Signed-off-by: Mateusz Jablonski --- runtime/command_queue/command_queue.cpp | 2 +- runtime/command_queue/enqueue_fill_buffer.h | 3 +- runtime/command_queue/enqueue_svm.h | 2 +- .../command_stream_receiver.cpp | 10 +- .../experimental_command_buffer.cpp | 6 +- .../scratch_space_controller_base.cpp | 2 +- runtime/device/device.cpp | 2 +- runtime/device_queue/device_queue.cpp | 14 +-- runtime/device_queue/device_queue_hw.inl | 2 +- .../helpers/flat_batch_buffer_helper_hw.inl | 4 +- runtime/kernel/kernel.cpp | 6 +- runtime/mem_obj/buffer.cpp | 8 +- runtime/mem_obj/mem_obj_helper.cpp | 4 +- runtime/mem_obj/mem_obj_helper.h | 2 +- runtime/mem_obj/pipe.cpp | 4 +- runtime/memory_manager/memory_manager.cpp | 35 ++++-- runtime/memory_manager/memory_manager.h | 20 +--- .../os_agnostic_memory_manager.cpp | 2 +- .../os_interface/linux/drm_memory_manager.cpp | 2 +- .../windows/wddm_memory_manager.cpp | 2 +- runtime/program/printf_handler.cpp | 3 +- runtime/program/process_gen_binary.cpp | 4 +- runtime/program/program.cpp | 2 +- runtime/utilities/tag_allocator.h | 3 +- .../command_queue/command_queue_hw_tests.cpp | 6 +- .../command_queue/command_queue_tests.cpp | 4 +- .../enqueue_fill_buffer_tests.cpp | 14 +-- .../command_queue/enqueue_map_image_tests.cpp | 2 +- .../get_size_required_buffer_tests.cpp | 2 +- .../multiple_map_buffer_tests.cpp | 2 +- .../multiple_map_image_tests.cpp | 2 +- .../aub_command_stream_receiver_1_tests.cpp | 37 +++--- .../aub_command_stream_receiver_2_tests.cpp | 22 ++-- ...and_stream_receiver_flush_task_3_tests.cpp | 8 +- .../command_stream_receiver_tests.cpp | 2 +- ...nd_stream_receiver_with_aub_dump_tests.cpp | 11 +- .../experimental_command_buffer_tests.cpp | 4 +- .../tbx_command_stream_tests.cpp | 14 +-- unit_tests/event/user_events_tests.cpp | 2 +- .../enqueue_execution_model_kernel_tests.cpp | 4 +- unit_tests/gen10/coherency_tests_gen10.cpp | 2 +- unit_tests/helpers/kernel_commands_tests.cpp | 2 +- unit_tests/kernel/kernel_image_arg_tests.cpp | 2 +- .../kernel_reflection_surface_tests.cpp | 12 +- unit_tests/kernel/kernel_tests.cpp | 2 +- unit_tests/mem_obj/buffer_tests.cpp | 2 +- unit_tests/mem_obj/image_set_arg_tests.cpp | 6 +- .../mem_obj/mem_obj_destruction_tests.cpp | 4 +- unit_tests/mem_obj/mem_obj_tests.cpp | 16 +-- .../deferrable_allocation_deletion_tests.cpp | 15 +-- .../internal_allocation_storage_tests.cpp | 13 ++- ...nager_allocate_in_preferred_pool_tests.inl | 109 ++++++++++-------- .../memory_manager/memory_manager_tests.cpp | 39 +++---- unit_tests/mocks/CMakeLists.txt | 1 + .../mocks/linux/mock_drm_memory_manager.h | 1 + unit_tests/mocks/mock_allocation_properties.h | 19 +++ unit_tests/mocks/mock_aub_csr.h | 2 +- unit_tests/mocks/mock_device.h | 3 +- .../linux/drm_command_stream_tests.cpp | 50 ++++---- .../linux/drm_memory_manager_tests.cpp | 30 ++--- .../windows/device_command_stream_tests.cpp | 72 ++++++------ .../windows/mock_wddm_memory_manager.h | 1 + .../windows/wddm_memory_manager_tests.cpp | 23 ++-- unit_tests/program/program_tests.cpp | 4 +- 64 files changed, 371 insertions(+), 339 deletions(-) create mode 100644 unit_tests/mocks/mock_allocation_properties.h diff --git a/runtime/command_queue/command_queue.cpp b/runtime/command_queue/command_queue.cpp index d68c207338..c33909af3a 100644 --- a/runtime/command_queue/command_queue.cpp +++ b/runtime/command_queue/command_queue.cpp @@ -212,7 +212,7 @@ LinearStream &CommandQueue::getCS(size_t minRequiredSize) { GraphicsAllocation *allocation = storageForAllocation->obtainReusableAllocation(requiredSize, false).release(); if (!allocation) { - allocation = memoryManager->allocateGraphicsMemory(requiredSize); + allocation = memoryManager->allocateGraphicsMemoryWithProperties({requiredSize, GraphicsAllocation::AllocationType::LINEAR_STREAM}); } allocation->setAllocationType(GraphicsAllocation::AllocationType::LINEAR_STREAM); diff --git a/runtime/command_queue/enqueue_fill_buffer.h b/runtime/command_queue/enqueue_fill_buffer.h index defdb73d5b..5eb56b47e3 100644 --- a/runtime/command_queue/enqueue_fill_buffer.h +++ b/runtime/command_queue/enqueue_fill_buffer.h @@ -32,8 +32,7 @@ cl_int CommandQueueHw::enqueueFillBuffer( auto memoryManager = getDevice().getMemoryManager(); DEBUG_BREAK_IF(nullptr == memoryManager); - auto patternAllocation = memoryManager->allocateGraphicsMemory(alignUp(patternSize, MemoryConstants::cacheLineSize)); - patternAllocation->setAllocationType(GraphicsAllocation::AllocationType::FILL_PATTERN); + auto patternAllocation = memoryManager->allocateGraphicsMemoryWithProperties({alignUp(patternSize, MemoryConstants::cacheLineSize), GraphicsAllocation::AllocationType::FILL_PATTERN}); if (patternSize == 1) { int patternInt = (uint32_t)((*(uint8_t *)pattern << 24) | (*(uint8_t *)pattern << 16) | (*(uint8_t *)pattern << 8) | *(uint8_t *)pattern); diff --git a/runtime/command_queue/enqueue_svm.h b/runtime/command_queue/enqueue_svm.h index d7a051d8c6..0d7206d038 100644 --- a/runtime/command_queue/enqueue_svm.h +++ b/runtime/command_queue/enqueue_svm.h @@ -228,7 +228,7 @@ cl_int CommandQueueHw::enqueueSVMMemFill(void *svmPtr, commandStreamReceieverOwnership.unlock(); if (!patternAllocation) { - patternAllocation = memoryManager->allocateGraphicsMemory(patternSize); + patternAllocation = memoryManager->allocateGraphicsMemoryWithProperties({patternSize, GraphicsAllocation::AllocationType::FILL_PATTERN}); } patternAllocation->setAllocationType(GraphicsAllocation::AllocationType::FILL_PATTERN); diff --git a/runtime/command_stream/command_stream_receiver.cpp b/runtime/command_stream/command_stream_receiver.cpp index 671e73afb7..dd029be8e3 100644 --- a/runtime/command_stream/command_stream_receiver.cpp +++ b/runtime/command_stream/command_stream_receiver.cpp @@ -135,7 +135,7 @@ LinearStream &CommandStreamReceiver::getCS(size_t minRequiredSize) { auto allocation = internalAllocationStorage->obtainReusableAllocation(requiredSize, false).release(); if (!allocation) { - allocation = getMemoryManager()->allocateGraphicsMemory(requiredSize); + allocation = getMemoryManager()->allocateGraphicsMemoryWithProperties({requiredSize, GraphicsAllocation::AllocationType::LINEAR_STREAM}); } allocation->setAllocationType(GraphicsAllocation::AllocationType::LINEAR_STREAM); @@ -243,7 +243,7 @@ void CommandStreamReceiver::activateAubSubCapture(const MultiDispatchInfo &dispa GraphicsAllocation *CommandStreamReceiver::allocateDebugSurface(size_t size) { UNRECOVERABLE_IF(debugSurface != nullptr); - debugSurface = getMemoryManager()->allocateGraphicsMemory(size); + debugSurface = getMemoryManager()->allocateGraphicsMemoryWithProperties({size, GraphicsAllocation::AllocationType::UNDECIDED}); return debugSurface; } @@ -291,7 +291,7 @@ void CommandStreamReceiver::allocateHeapMemory(IndirectHeap::Type heapType, if (requireInternalHeap) { heapMemory = getMemoryManager()->allocate32BitGraphicsMemory(finalHeapSize, nullptr, AllocationOrigin::INTERNAL_ALLOCATION); } else { - heapMemory = getMemoryManager()->allocateGraphicsMemory(finalHeapSize); + heapMemory = getMemoryManager()->allocateGraphicsMemoryWithProperties({finalHeapSize, GraphicsAllocation::AllocationType::LINEAR_STREAM}); } } else { finalHeapSize = std::max(heapMemory->getUnderlyingBufferSize(), finalHeapSize); @@ -332,7 +332,7 @@ void CommandStreamReceiver::setExperimentalCmdBuffer(std::unique_ptrallocateGraphicsMemory(sizeof(uint32_t)); + auto tagAllocation = getMemoryManager()->allocateGraphicsMemoryWithProperties({MemoryConstants::pageSize, GraphicsAllocation::AllocationType::UNDECIDED}); if (!tagAllocation) { return false; } @@ -355,7 +355,7 @@ bool CommandStreamReceiver::createAllocationForHostSurface(HostPtrSurface &surfa allocation = memoryManager->allocateGraphicsMemoryForHostPtr(surface.getSurfaceSize(), surface.getMemoryPointer(), device.isFullRangeSvm(), requiresL3Flush); if (allocation == nullptr && surface.peekIsPtrCopyAllowed()) { // Try with no host pointer allocation and copy - AllocationProperties properties(true, surface.getSurfaceSize()); + AllocationProperties properties(true, surface.getSurfaceSize(), GraphicsAllocation::AllocationType::UNDECIDED); properties.alignment = MemoryConstants::pageSize; allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties); diff --git a/runtime/command_stream/experimental_command_buffer.cpp b/runtime/command_stream/experimental_command_buffer.cpp index 296a120db5..6524685676 100644 --- a/runtime/command_stream/experimental_command_buffer.cpp +++ b/runtime/command_stream/experimental_command_buffer.cpp @@ -22,9 +22,9 @@ ExperimentalCommandBuffer::ExperimentalCommandBuffer(CommandStreamReceiver *csr, experimentalAllocationOffset(0), defaultPrint(true), timerResolution(profilingTimerResolution) { - timestamps = csr->getMemoryManager()->allocateGraphicsMemory(MemoryConstants::pageSize); + timestamps = csr->getMemoryManager()->allocateGraphicsMemoryWithProperties({MemoryConstants::pageSize, GraphicsAllocation::AllocationType::UNDECIDED}); memset(timestamps->getUnderlyingBuffer(), 0, timestamps->getUnderlyingBufferSize()); - experimentalAllocation = csr->getMemoryManager()->allocateGraphicsMemory(MemoryConstants::pageSize); + experimentalAllocation = csr->getMemoryManager()->allocateGraphicsMemoryWithProperties({MemoryConstants::pageSize, GraphicsAllocation::AllocationType::UNDECIDED}); memset(experimentalAllocation->getUnderlyingBuffer(), 0, experimentalAllocation->getUnderlyingBufferSize()); } @@ -61,7 +61,7 @@ void ExperimentalCommandBuffer::getCS(size_t minRequiredSize) { auto storageWithAllocations = commandStreamReceiver->getInternalAllocationStorage(); GraphicsAllocation *allocation = storageWithAllocations->obtainReusableAllocation(requiredSize, false).release(); if (!allocation) { - allocation = memoryManager->allocateGraphicsMemory(requiredSize); + allocation = memoryManager->allocateGraphicsMemoryWithProperties({requiredSize, GraphicsAllocation::AllocationType::LINEAR_STREAM}); } allocation->setAllocationType(GraphicsAllocation::AllocationType::LINEAR_STREAM); // Deallocate the old block, if not null diff --git a/runtime/command_stream/scratch_space_controller_base.cpp b/runtime/command_stream/scratch_space_controller_base.cpp index 0e4241afe1..46d2ad91a0 100644 --- a/runtime/command_stream/scratch_space_controller_base.cpp +++ b/runtime/command_stream/scratch_space_controller_base.cpp @@ -42,7 +42,7 @@ void ScratchSpaceControllerBase::setRequiredScratchSpace(void *sshBaseAddress, } void ScratchSpaceControllerBase::createScratchSpaceAllocation() { - scratchAllocation = getMemoryManager()->allocateGraphicsMemoryInPreferredPool(AllocationProperties(true, scratchSizeBytes), 0, nullptr, GraphicsAllocation::AllocationType::SCRATCH_SURFACE); + scratchAllocation = getMemoryManager()->allocateGraphicsMemoryWithProperties({scratchSizeBytes, GraphicsAllocation::AllocationType::SCRATCH_SURFACE}); UNRECOVERABLE_IF(scratchAllocation == nullptr); } diff --git a/runtime/device/device.cpp b/runtime/device/device.cpp index f74bf7f5d2..cf03775ac9 100644 --- a/runtime/device/device.cpp +++ b/runtime/device/device.cpp @@ -143,7 +143,7 @@ bool Device::createDeviceImpl(const HardwareInfo *pHwInfo, Device &outDevice) { outDevice.executionEnvironment->memoryManager->setForce32BitAllocations(outDevice.getDeviceInfo().force32BitAddressess); if (outDevice.preemptionMode == PreemptionMode::MidThread || outDevice.isSourceLevelDebuggerActive()) { - AllocationProperties properties(true, pHwInfo->capabilityTable.requiredPreemptionSurfaceSize); + AllocationProperties properties(true, pHwInfo->capabilityTable.requiredPreemptionSurfaceSize, GraphicsAllocation::AllocationType::UNDECIDED); properties.flags.uncacheable = outDevice.getWaTable()->waCSRUncachable; properties.alignment = 256 * MemoryConstants::kiloByte; outDevice.preemptionAllocation = outDevice.executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(properties); diff --git a/runtime/device_queue/device_queue.cpp b/runtime/device_queue/device_queue.cpp index bb8bcff0f0..7065a33f1c 100644 --- a/runtime/device_queue/device_queue.cpp +++ b/runtime/device_queue/device_queue.cpp @@ -98,32 +98,32 @@ void DeviceQueue::allocateResources() { auto &caps = device->getDeviceInfo(); uint32_t alignedQueueSize = alignUp(queueSize, MemoryConstants::pageSize); - queueBuffer = device->getMemoryManager()->allocateGraphicsMemory(alignedQueueSize); + queueBuffer = device->getMemoryManager()->allocateGraphicsMemoryWithProperties({alignedQueueSize, GraphicsAllocation::AllocationType::UNDECIDED}); auto eventPoolBufferSize = static_cast(caps.maxOnDeviceEvents) * sizeof(IGIL_DeviceEvent) + sizeof(IGIL_EventPool); eventPoolBufferSize = alignUp(eventPoolBufferSize, MemoryConstants::pageSize); - eventPoolBuffer = device->getMemoryManager()->allocateGraphicsMemory(eventPoolBufferSize); + eventPoolBuffer = device->getMemoryManager()->allocateGraphicsMemoryWithProperties({eventPoolBufferSize, GraphicsAllocation::AllocationType::UNDECIDED}); auto maxEnqueue = static_cast(alignedQueueSize) / sizeof(IGIL_CommandHeader); auto expectedStackSize = maxEnqueue * sizeof(uint32_t) * 3; // 3 full loads of commands expectedStackSize = alignUp(expectedStackSize, MemoryConstants::pageSize); - stackBuffer = device->getMemoryManager()->allocateGraphicsMemory(expectedStackSize); + stackBuffer = device->getMemoryManager()->allocateGraphicsMemoryWithProperties({expectedStackSize, GraphicsAllocation::AllocationType::UNDECIDED}); memset(stackBuffer->getUnderlyingBuffer(), 0, stackBuffer->getUnderlyingBufferSize()); auto queueStorageSize = alignedQueueSize * 2; // place for 2 full loads of queue_t queueStorageSize = alignUp(queueStorageSize, MemoryConstants::pageSize); - queueStorageBuffer = device->getMemoryManager()->allocateGraphicsMemory(queueStorageSize); + queueStorageBuffer = device->getMemoryManager()->allocateGraphicsMemoryWithProperties({queueStorageSize, GraphicsAllocation::AllocationType::UNDECIDED}); memset(queueStorageBuffer->getUnderlyingBuffer(), 0, queueStorageBuffer->getUnderlyingBufferSize()); auto &hwHelper = HwHelper::get(device->getHardwareInfo().pPlatform->eRenderCoreFamily); const size_t IDTSize = numberOfIDTables * interfaceDescriptorEntries * hwHelper.getInterfaceDescriptorDataSize(); // Additional padding of PAGE_SIZE for PageFaults just after DSH to satisfy hw requirements - auto dshSize = (PARALLEL_SCHEDULER_HW_GROUPS + 2) * MAX_DSH_SIZE_PER_ENQUEUE * 8 + IDTSize + colorCalcStateSize + 4096; + auto dshSize = (PARALLEL_SCHEDULER_HW_GROUPS + 2) * MAX_DSH_SIZE_PER_ENQUEUE * 8 + IDTSize + colorCalcStateSize + MemoryConstants::pageSize; dshSize = alignUp(dshSize, MemoryConstants::pageSize); - dshBuffer = device->getMemoryManager()->allocateGraphicsMemory(dshSize); + dshBuffer = device->getMemoryManager()->allocateGraphicsMemoryWithProperties({dshSize, GraphicsAllocation::AllocationType::UNDECIDED}); - debugQueue = device->getMemoryManager()->allocateGraphicsMemory(4096); + debugQueue = device->getMemoryManager()->allocateGraphicsMemoryWithProperties({MemoryConstants::pageSize, GraphicsAllocation::AllocationType::UNDECIDED}); debugData = (DebugDataBuffer *)debugQueue->getUnderlyingBuffer(); memset(debugQueue->getUnderlyingBuffer(), 0, debugQueue->getUnderlyingBufferSize()); } diff --git a/runtime/device_queue/device_queue_hw.inl b/runtime/device_queue/device_queue_hw.inl index 2a00fa99f2..52e27d3596 100644 --- a/runtime/device_queue/device_queue_hw.inl +++ b/runtime/device_queue/device_queue_hw.inl @@ -25,7 +25,7 @@ void DeviceQueueHw::allocateSlbBuffer() { slbSize += (4 * MemoryConstants::pageSize); // +4 pages spec restriction slbSize = alignUp(slbSize, MemoryConstants::pageSize); - slbBuffer = device->getMemoryManager()->allocateGraphicsMemory(slbSize); + slbBuffer = device->getMemoryManager()->allocateGraphicsMemoryWithProperties({slbSize, GraphicsAllocation::AllocationType::UNDECIDED}); } template diff --git a/runtime/helpers/flat_batch_buffer_helper_hw.inl b/runtime/helpers/flat_batch_buffer_helper_hw.inl index 5487589cac..abf9f861a1 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(true, alignedMainBatchBufferSize); + AllocationProperties flatBatchBufferProperties(alignedMainBatchBufferSize, GraphicsAllocation::AllocationType::UNDECIDED); 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(true, static_cast(flatBatchBufferSize)); + AllocationProperties flatBatchBufferProperties(static_cast(flatBatchBufferSize), GraphicsAllocation::AllocationType::UNDECIDED); 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 89deda757d..bc810ebac3 100644 --- a/runtime/kernel/kernel.cpp +++ b/runtime/kernel/kernel.cpp @@ -255,7 +255,7 @@ cl_int Kernel::initialize() { retVal = CL_OUT_OF_RESOURCES; break; } - privateSurface = device.getMemoryManager()->allocateGraphicsMemoryInPreferredPool(AllocationProperties(true, static_cast(privateSurfaceSize)), 0, nullptr, GraphicsAllocation::AllocationType::PRIVATE_SURFACE); + privateSurface = device.getMemoryManager()->allocateGraphicsMemoryWithProperties({static_cast(privateSurfaceSize), GraphicsAllocation::AllocationType::PRIVATE_SURFACE}); if (privateSurface == nullptr) { retVal = CL_OUT_OF_RESOURCES; break; @@ -1474,7 +1474,7 @@ void Kernel::createReflectionSurface() { kernelReflectionSize += blockCount * alignUp(maxConstantBufferSize, sizeof(void *)); kernelReflectionSize += parentImageCount * sizeof(IGIL_ImageParamters); kernelReflectionSize += parentSamplerCount * sizeof(IGIL_ParentSamplerParams); - kernelReflectionSurface = device.getMemoryManager()->allocateGraphicsMemory(kernelReflectionSize); + kernelReflectionSurface = device.getMemoryManager()->allocateGraphicsMemoryWithProperties({kernelReflectionSize, GraphicsAllocation::AllocationType::UNDECIDED}); for (uint32_t i = 0; i < blockCount; i++) { const KernelInfo *pBlockInfo = blockManager->getBlockKernelInfo(i); @@ -1548,7 +1548,7 @@ void Kernel::createReflectionSurface() { if (DebugManager.flags.ForceDispatchScheduler.get()) { if (this->isSchedulerKernel && kernelReflectionSurface == nullptr) { - kernelReflectionSurface = device.getMemoryManager()->allocateGraphicsMemory(MemoryConstants::pageSize); + kernelReflectionSurface = device.getMemoryManager()->allocateGraphicsMemoryWithProperties({MemoryConstants::pageSize, GraphicsAllocation::AllocationType::UNDECIDED}); } } } diff --git a/runtime/mem_obj/buffer.cpp b/runtime/mem_obj/buffer.cpp index f35d8bc941..f248d2a0d4 100644 --- a/runtime/mem_obj/buffer.cpp +++ b/runtime/mem_obj/buffer.cpp @@ -192,9 +192,9 @@ Buffer *Buffer::create(Context *context, } if (!memory) { - AllocationProperties allocProperties = MemObjHelper::getAllocationProperties(properties.flags_intel, allocateMemory, size); + AllocationProperties allocProperties = MemObjHelper::getAllocationProperties(properties.flags_intel, allocateMemory, size, allocationType); DevicesBitfield devices = MemObjHelper::getDevicesBitfield(properties); - memory = memoryManager->allocateGraphicsMemoryInPreferredPool(allocProperties, devices, hostPtr, allocationType); + memory = memoryManager->allocateGraphicsMemoryInPreferredPool(allocProperties, devices, hostPtr); } if (allocateMemory && memory && MemoryPool::isSystemMemoryPool(memory->getMemoryPool())) { @@ -207,9 +207,9 @@ Buffer *Buffer::create(Context *context, allocationType = GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY; zeroCopyAllowed = false; copyMemoryFromHostPtr = true; - AllocationProperties allocProperties = MemObjHelper::getAllocationProperties(properties.flags_intel, true, size); + AllocationProperties allocProperties = MemObjHelper::getAllocationProperties(properties.flags_intel, true, size, allocationType); DevicesBitfield devices = MemObjHelper::getDevicesBitfield(properties); - memory = memoryManager->allocateGraphicsMemoryInPreferredPool(allocProperties, devices, nullptr, allocationType); + memory = memoryManager->allocateGraphicsMemoryInPreferredPool(allocProperties, devices, nullptr); } if (!memory) { diff --git a/runtime/mem_obj/mem_obj_helper.cpp b/runtime/mem_obj/mem_obj_helper.cpp index 56357750c8..477ac1dfae 100644 --- a/runtime/mem_obj/mem_obj_helper.cpp +++ b/runtime/mem_obj/mem_obj_helper.cpp @@ -33,8 +33,8 @@ bool MemObjHelper::validateExtraMemoryProperties(const MemoryProperties &propert return true; } -AllocationProperties MemObjHelper::getAllocationProperties(cl_mem_flags_intel flags, bool allocateMemory, size_t size) { - return AllocationProperties(allocateMemory, size); +AllocationProperties MemObjHelper::getAllocationProperties(cl_mem_flags_intel flags, bool allocateMemory, size_t size, GraphicsAllocation::AllocationType type) { + return AllocationProperties(allocateMemory, size, type); } DevicesBitfield MemObjHelper::getDevicesBitfield(const MemoryProperties &properties) { diff --git a/runtime/mem_obj/mem_obj_helper.h b/runtime/mem_obj/mem_obj_helper.h index 2dd516aaf5..20f9b48f62 100644 --- a/runtime/mem_obj/mem_obj_helper.h +++ b/runtime/mem_obj/mem_obj_helper.h @@ -50,7 +50,7 @@ class MemObjHelper { static bool validateExtraMemoryProperties(const MemoryProperties &properties); - static AllocationProperties getAllocationProperties(cl_mem_flags_intel flags, bool allocateMemory, size_t size); + static AllocationProperties getAllocationProperties(cl_mem_flags_intel flags, bool allocateMemory, size_t size, GraphicsAllocation::AllocationType type); static DevicesBitfield getDevicesBitfield(const MemoryProperties &properties); diff --git a/runtime/mem_obj/pipe.cpp b/runtime/mem_obj/pipe.cpp index a997f932dc..b66a0e21ef 100644 --- a/runtime/mem_obj/pipe.cpp +++ b/runtime/mem_obj/pipe.cpp @@ -51,9 +51,9 @@ Pipe *Pipe::create(Context *context, memoryProperties.flags = flags; while (true) { auto size = static_cast(packetSize * (maxPackets + 1) + intelPipeHeaderReservedSpace); - AllocationProperties allocProperties = MemObjHelper::getAllocationProperties(flags, true, size); + AllocationProperties allocProperties = MemObjHelper::getAllocationProperties(flags, true, size, GraphicsAllocation::AllocationType::PIPE); DevicesBitfield devices = MemObjHelper::getDevicesBitfield(memoryProperties); - GraphicsAllocation *memory = memoryManager->allocateGraphicsMemoryInPreferredPool(allocProperties, devices, nullptr, GraphicsAllocation::AllocationType::PIPE); + GraphicsAllocation *memory = memoryManager->allocateGraphicsMemoryInPreferredPool(allocProperties, devices, nullptr); if (!memory) { errcodeRet = CL_OUT_OF_HOST_MEMORY; break; diff --git a/runtime/memory_manager/memory_manager.cpp b/runtime/memory_manager/memory_manager.cpp index 03bbca7ca5..4af1d76ea6 100644 --- a/runtime/memory_manager/memory_manager.cpp +++ b/runtime/memory_manager/memory_manager.cpp @@ -75,7 +75,7 @@ void *MemoryManager::allocateSystemMemory(size_t size, size_t alignment) { GraphicsAllocation *MemoryManager::allocateGraphicsMemoryForSVM(size_t size, bool coherent) { GraphicsAllocation *graphicsAllocation = nullptr; - graphicsAllocation = allocateGraphicsMemoryInPreferredPool(AllocationProperties(true, size), 0u, nullptr, GraphicsAllocation::AllocationType::SVM); + graphicsAllocation = allocateGraphicsMemoryWithProperties({size, GraphicsAllocation::AllocationType::SVM}); if (graphicsAllocation) { graphicsAllocation->setCoherent(coherent); } @@ -101,13 +101,13 @@ void MemoryManager::cleanGraphicsMemoryCreatedFromHostPtr(GraphicsAllocation *gr GraphicsAllocation *MemoryManager::createGraphicsAllocationWithPadding(GraphicsAllocation *inputGraphicsAllocation, size_t sizeWithPadding) { if (!paddingAllocation) { - paddingAllocation = allocateGraphicsMemory(paddingBufferSize); + paddingAllocation = allocateGraphicsMemoryWithProperties({paddingBufferSize, GraphicsAllocation::AllocationType::UNDECIDED}); } return createPaddedAllocation(inputGraphicsAllocation, sizeWithPadding); } GraphicsAllocation *MemoryManager::createPaddedAllocation(GraphicsAllocation *inputGraphicsAllocation, size_t sizeWithPadding) { - return allocateGraphicsMemory(sizeWithPadding); + return allocateGraphicsMemoryWithProperties({sizeWithPadding, GraphicsAllocation::AllocationType::UNDECIDED}); } void MemoryManager::freeSystemMemory(void *ptr) { @@ -184,7 +184,7 @@ OsContext *MemoryManager::createAndRegisterOsContext(EngineInstanceT engineType, } bool MemoryManager::getAllocationData(AllocationData &allocationData, const AllocationProperties &properties, const DevicesBitfield devicesBitfield, - const void *hostPtr, GraphicsAllocation::AllocationType type) { + const void *hostPtr) { UNRECOVERABLE_IF(hostPtr == nullptr && !properties.flags.allocateMemory); bool allow64KbPages = false; @@ -193,7 +193,7 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo bool uncacheable = properties.flags.uncacheable; bool mustBeZeroCopy = false; - switch (type) { + switch (properties.allocationType) { case GraphicsAllocation::AllocationType::BUFFER: case GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY: case GraphicsAllocation::AllocationType::BUFFER_COMPRESSED: @@ -211,7 +211,7 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo break; } - switch (type) { + switch (properties.allocationType) { case GraphicsAllocation::AllocationType::BUFFER: case GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY: case GraphicsAllocation::AllocationType::BUFFER_COMPRESSED: @@ -221,7 +221,7 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo break; } - switch (type) { + switch (properties.allocationType) { case GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY: case GraphicsAllocation::AllocationType::PIPE: case GraphicsAllocation::AllocationType::PRINTF_SURFACE: @@ -234,6 +234,16 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo break; } + switch (properties.allocationType) { + case GraphicsAllocation::AllocationType::UNDECIDED: + case GraphicsAllocation::AllocationType::LINEAR_STREAM: + case GraphicsAllocation::AllocationType::FILL_PATTERN: + allocationData.flags.useSystemMemory = true; + break; + default: + break; + } + allocationData.flags.mustBeZeroCopy = mustBeZeroCopy; allocationData.flags.allocateMemory = properties.flags.allocateMemory; allocationData.flags.allow32Bit = allow32Bit; @@ -241,7 +251,7 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo allocationData.flags.forcePin = forcePin; allocationData.flags.uncacheable = uncacheable; allocationData.flags.flushL3 = properties.flags.flushL3RequiredForRead | properties.flags.flushL3RequiredForWrite; - allocationData.flags.preferRenderCompressed = GraphicsAllocation::AllocationType::BUFFER_COMPRESSED == type; + allocationData.flags.preferRenderCompressed = GraphicsAllocation::AllocationType::BUFFER_COMPRESSED == properties.allocationType; if (allocationData.flags.mustBeZeroCopy) { allocationData.flags.useSystemMemory = true; @@ -249,7 +259,7 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo allocationData.hostPtr = hostPtr; allocationData.size = properties.size; - allocationData.type = type; + allocationData.type = properties.allocationType; allocationData.devicesBitfield = devicesBitfield; allocationData.alignment = properties.alignment ? properties.alignment : MemoryConstants::preferredAlignment; @@ -259,11 +269,11 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo return true; } -GraphicsAllocation *MemoryManager::allocateGraphicsMemoryInPreferredPool(AllocationProperties properties, DevicesBitfield devicesBitfield, const void *hostPtr, GraphicsAllocation::AllocationType type) { +GraphicsAllocation *MemoryManager::allocateGraphicsMemoryInPreferredPool(AllocationProperties properties, DevicesBitfield devicesBitfield, const void *hostPtr) { AllocationData allocationData; AllocationStatus status = AllocationStatus::Error; - getAllocationData(allocationData, properties, devicesBitfield, hostPtr, type); + getAllocationData(allocationData, properties, devicesBitfield, hostPtr); UNRECOVERABLE_IF(allocationData.type == GraphicsAllocation::AllocationType::IMAGE || allocationData.type == GraphicsAllocation::AllocationType::SHARED_RESOURCE); GraphicsAllocation *allocation = nullptr; @@ -271,6 +281,9 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemoryInPreferredPool(Allocat if (!allocation && status == AllocationStatus::RetryInNonDevicePool) { allocation = allocateGraphicsMemory(allocationData); } + if (allocation) { + allocation->setAllocationType(properties.allocationType); + } return allocation; } diff --git a/runtime/memory_manager/memory_manager.h b/runtime/memory_manager/memory_manager.h index 26bd034072..c024ba8c24 100644 --- a/runtime/memory_manager/memory_manager.h +++ b/runtime/memory_manager/memory_manager.h @@ -52,14 +52,10 @@ struct AllocationProperties { static_assert(sizeof(AllocationProperties::flags) == sizeof(AllocationProperties::allFlags), ""); size_t size = 0; size_t alignment = 0; + GraphicsAllocation::AllocationType allocationType = GraphicsAllocation::AllocationType::UNKNOWN; - AllocationProperties() { - allFlags = 0; - flags.flushL3RequiredForRead = 1; - flags.flushL3RequiredForWrite = 1; - } - - AllocationProperties(bool allocateMemory, size_t size) : size(size) { + AllocationProperties(size_t size, GraphicsAllocation::AllocationType allocationType) : AllocationProperties(true, size, allocationType) {} + AllocationProperties(bool allocateMemory, size_t size, GraphicsAllocation::AllocationType allocationType) : size(size), allocationType(allocationType) { allFlags = 0; flags.flushL3RequiredForRead = 1; flags.flushL3RequiredForWrite = 1; @@ -93,12 +89,8 @@ class MemoryManager { virtual void addAllocationToHostPtrManager(GraphicsAllocation *memory) = 0; virtual void removeAllocationFromHostPtrManager(GraphicsAllocation *memory) = 0; - GraphicsAllocation *allocateGraphicsMemory(size_t size) { - return allocateGraphicsMemoryInPreferredPool(AllocationProperties(true, size), 0u, nullptr, GraphicsAllocation::AllocationType::UNDECIDED); - } - GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) { - return allocateGraphicsMemoryInPreferredPool(properties, 0u, nullptr, GraphicsAllocation::AllocationType::UNDECIDED); + return allocateGraphicsMemoryInPreferredPool(properties, 0u, nullptr); } virtual GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(size_t size, void *cpuPtr) = 0; @@ -126,7 +118,7 @@ class MemoryManager { virtual GraphicsAllocation *allocateGraphicsMemoryForImage(ImageInfo &imgInfo, Gmm *gmm) = 0; - GraphicsAllocation *allocateGraphicsMemoryInPreferredPool(AllocationProperties properties, DevicesBitfield devicesBitfield, const void *hostPtr, GraphicsAllocation::AllocationType type); + GraphicsAllocation *allocateGraphicsMemoryInPreferredPool(AllocationProperties properties, DevicesBitfield devicesBitfield, const void *hostPtr); GraphicsAllocation *allocateGraphicsMemoryForSVM(size_t size, bool coherent); @@ -227,7 +219,7 @@ class MemoryManager { }; static bool getAllocationData(AllocationData &allocationData, const AllocationProperties &properties, const DevicesBitfield devicesBitfield, - const void *hostPtr, GraphicsAllocation::AllocationType type); + const void *hostPtr); GraphicsAllocation *allocateGraphicsMemory(const AllocationData &allocationData); virtual GraphicsAllocation *allocateGraphicsMemoryWithHostPtr(const AllocationData &allocationData); diff --git a/runtime/memory_manager/os_agnostic_memory_manager.cpp b/runtime/memory_manager/os_agnostic_memory_manager.cpp index 166a22a0a4..ade610c948 100644 --- a/runtime/memory_manager/os_agnostic_memory_manager.cpp +++ b/runtime/memory_manager/os_agnostic_memory_manager.cpp @@ -233,7 +233,7 @@ void OsAgnosticMemoryManager::cleanOsHandles(OsHandleStorage &handleStorage) { GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryForImage(ImageInfo &imgInfo, Gmm *gmm) { GraphicsAllocation *alloc = nullptr; if (!GmmHelper::allowTiling(*imgInfo.imgDesc) && imgInfo.mipCount == 0) { - alloc = allocateGraphicsMemory(imgInfo.size); + alloc = allocateGraphicsMemoryWithProperties({imgInfo.size, GraphicsAllocation::AllocationType::UNDECIDED}); } else { auto ptr = allocateSystemMemory(alignUp(imgInfo.size, MemoryConstants::pageSize), MemoryConstants::pageSize); if (ptr != nullptr) { diff --git a/runtime/os_interface/linux/drm_memory_manager.cpp b/runtime/os_interface/linux/drm_memory_manager.cpp index b258ce45ee..923047cc95 100644 --- a/runtime/os_interface/linux/drm_memory_manager.cpp +++ b/runtime/os_interface/linux/drm_memory_manager.cpp @@ -282,7 +282,7 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemory64kb(AllocationData alloc GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryForImage(ImageInfo &imgInfo, Gmm *gmm) { if (!GmmHelper::allowTiling(*imgInfo.imgDesc)) { - auto alloc = MemoryManager::allocateGraphicsMemory(imgInfo.size); + auto alloc = MemoryManager::allocateGraphicsMemoryWithProperties({imgInfo.size, GraphicsAllocation::AllocationType::UNDECIDED}); if (alloc) { alloc->gmm = gmm; } diff --git a/runtime/os_interface/windows/wddm_memory_manager.cpp b/runtime/os_interface/windows/wddm_memory_manager.cpp index 027d5b6e1e..385e797380 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.cpp +++ b/runtime/os_interface/windows/wddm_memory_manager.cpp @@ -43,7 +43,7 @@ WddmMemoryManager::WddmMemoryManager(bool enable64kbPages, bool enableLocalMemor GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryForImage(ImageInfo &imgInfo, Gmm *gmm) { if (!GmmHelper::allowTiling(*imgInfo.imgDesc) && imgInfo.mipCount == 0) { delete gmm; - return allocateGraphicsMemory(imgInfo.size); + return allocateGraphicsMemoryWithProperties({imgInfo.size, GraphicsAllocation::AllocationType::UNDECIDED}); } auto allocation = std::make_unique(nullptr, imgInfo.size, nullptr, MemoryPool::SystemCpuInaccessible, getOsContextCount(), false); allocation->gmm = gmm; diff --git a/runtime/program/printf_handler.cpp b/runtime/program/printf_handler.cpp index 3482ff67c8..1d4492f971 100644 --- a/runtime/program/printf_handler.cpp +++ b/runtime/program/printf_handler.cpp @@ -37,8 +37,7 @@ void PrintfHandler::prepareDispatch(const MultiDispatchInfo &multiDispatchInfo) return; } kernel = multiDispatchInfo.peekMainKernel(); - printfSurface = device.getMemoryManager()->allocateGraphicsMemoryInPreferredPool(AllocationProperties(true, printfSurfaceSize), 0, nullptr, GraphicsAllocation::AllocationType::PRINTF_SURFACE); - + printfSurface = device.getMemoryManager()->allocateGraphicsMemoryWithProperties({printfSurfaceSize, GraphicsAllocation::AllocationType::PRINTF_SURFACE}); *reinterpret_cast(printfSurface->getUnderlyingBuffer()) = printfSurfaceInitialDataSize; auto printfPatchAddress = ptrOffset(reinterpret_cast(kernel->getCrossThreadData()), diff --git a/runtime/program/process_gen_binary.cpp b/runtime/program/process_gen_binary.cpp index 38dd83e6fd..6fa0a23e25 100644 --- a/runtime/program/process_gen_binary.cpp +++ b/runtime/program/process_gen_binary.cpp @@ -855,7 +855,7 @@ cl_int Program::parseProgramScopePatchList() { surfaceSize = patch.InlineDataSize; headerSize = sizeof(SPatchAllocateConstantMemorySurfaceProgramBinaryInfo); - constantSurface = pDevice->getMemoryManager()->allocateGraphicsMemoryInPreferredPool(AllocationProperties(true, surfaceSize), 0, nullptr, GraphicsAllocation::AllocationType::CONSTANT_SURFACE); + constantSurface = pDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties({surfaceSize, GraphicsAllocation::AllocationType::CONSTANT_SURFACE}); memcpy_s(constantSurface->getUnderlyingBuffer(), surfaceSize, (cl_char *)pPatch + headerSize, surfaceSize); pCurPatchListPtr = ptrOffset(pCurPatchListPtr, surfaceSize); @@ -877,7 +877,7 @@ cl_int Program::parseProgramScopePatchList() { surfaceSize = patch.InlineDataSize; globalVarTotalSize += (size_t)surfaceSize; headerSize = sizeof(SPatchAllocateGlobalMemorySurfaceProgramBinaryInfo); - globalSurface = pDevice->getMemoryManager()->allocateGraphicsMemoryInPreferredPool(AllocationProperties(true, surfaceSize), 0, nullptr, GraphicsAllocation::AllocationType::GLOBAL_SURFACE); + globalSurface = pDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties({surfaceSize, GraphicsAllocation::AllocationType::GLOBAL_SURFACE}); memcpy_s(globalSurface->getUnderlyingBuffer(), surfaceSize, (cl_char *)pPatch + headerSize, surfaceSize); pCurPatchListPtr = ptrOffset(pCurPatchListPtr, surfaceSize); diff --git a/runtime/program/program.cpp b/runtime/program/program.cpp index ab808c55a7..7688f31872 100644 --- a/runtime/program/program.cpp +++ b/runtime/program/program.cpp @@ -374,7 +374,7 @@ void Program::allocateBlockPrivateSurfaces() { if (privateSize > 0 && blockKernelManager->getPrivateSurface(i) == nullptr) { privateSize *= getDevice(0).getDeviceInfo().computeUnitsUsedForScratch * info->getMaxSimdSize(); - auto *privateSurface = this->executionEnvironment.memoryManager->allocateGraphicsMemoryInPreferredPool(AllocationProperties(true, privateSize), 0, nullptr, GraphicsAllocation::AllocationType::PRIVATE_SURFACE); + auto *privateSurface = this->executionEnvironment.memoryManager->allocateGraphicsMemoryWithProperties({privateSize, GraphicsAllocation::AllocationType::PRIVATE_SURFACE}); blockKernelManager->pushPrivateSurface(privateSurface, i); } } diff --git a/runtime/utilities/tag_allocator.h b/runtime/utilities/tag_allocator.h index d667a0c063..dd08b4ed10 100644 --- a/runtime/utilities/tag_allocator.h +++ b/runtime/utilities/tag_allocator.h @@ -128,8 +128,7 @@ class TagAllocator { size_t tagSize = alignUp(sizeof(TagType), tagAlignment); size_t allocationSizeRequired = tagCount * tagSize; - GraphicsAllocation *graphicsAllocation = memoryManager->allocateGraphicsMemory(allocationSizeRequired); - graphicsAllocation->setAllocationType(GraphicsAllocation::AllocationType::TIMESTAMP_TAG_BUFFER); + GraphicsAllocation *graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties({allocationSizeRequired, GraphicsAllocation::AllocationType::TIMESTAMP_TAG_BUFFER}); gfxAllocations.push_back(graphicsAllocation); uintptr_t Size = graphicsAllocation->getUnderlyingBufferSize(); diff --git a/unit_tests/command_queue/command_queue_hw_tests.cpp b/unit_tests/command_queue/command_queue_hw_tests.cpp index fbc9b07f9e..0012c55f3e 100644 --- a/unit_tests/command_queue/command_queue_hw_tests.cpp +++ b/unit_tests/command_queue/command_queue_hw_tests.cpp @@ -338,11 +338,11 @@ HWTEST_F(CommandQueueHwTest, GivenNotCompleteUserEventPassedToEnqueueWhenEventIs size_t offset = 0; size_t size = 1; - GraphicsAllocation *constantSurface = mockCSR->getMemoryManager()->allocateGraphicsMemory(10); + GraphicsAllocation *constantSurface = mockCSR->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); mockProgram->setConstantSurface(constantSurface); - GraphicsAllocation *printfSurface = mockCSR->getMemoryManager()->allocateGraphicsMemory(10); - GraphicsAllocation *privateSurface = mockCSR->getMemoryManager()->allocateGraphicsMemory(10); + GraphicsAllocation *printfSurface = mockCSR->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + GraphicsAllocation *privateSurface = mockCSR->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); mockKernel->setPrivateSurface(privateSurface, 10); diff --git a/unit_tests/command_queue/command_queue_tests.cpp b/unit_tests/command_queue/command_queue_tests.cpp index 60934252a4..1edec7ba35 100644 --- a/unit_tests/command_queue/command_queue_tests.cpp +++ b/unit_tests/command_queue/command_queue_tests.cpp @@ -330,7 +330,7 @@ TEST_F(CommandQueueCommandStreamTest, givenCommandStreamReceiverWithReusableAllo auto memoryManager = pDevice->getMemoryManager(); size_t requiredSize = alignUp(100, MemoryConstants::pageSize) + CSRequirements::csOverfetchSize; - auto allocation = memoryManager->allocateGraphicsMemory(requiredSize); + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{requiredSize}); auto &commandStreamReceiver = cmdQ.getCommandStreamReceiver(); commandStreamReceiver.getInternalAllocationStorage()->storeAllocation(std::unique_ptr(allocation), REUSABLE_ALLOCATION); @@ -491,7 +491,7 @@ TEST_P(CommandQueueIndirectHeapTest, givenCommandStreamReceiverWithReusableAlloc if (this->GetParam() == IndirectHeap::INDIRECT_OBJECT) { allocation = memoryManager->allocate32BitGraphicsMemory(allocationSize, nullptr, AllocationOrigin::INTERNAL_ALLOCATION); } else { - allocation = memoryManager->allocateGraphicsMemory(allocationSize); + allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{allocationSize}); } if (this->GetParam() == IndirectHeap::SURFACE_STATE) { allocation->setSize(commandStreamReceiver.defaultSshSize * 2); diff --git a/unit_tests/command_queue/enqueue_fill_buffer_tests.cpp b/unit_tests/command_queue/enqueue_fill_buffer_tests.cpp index 53f4793b69..4998d12054 100644 --- a/unit_tests/command_queue/enqueue_fill_buffer_tests.cpp +++ b/unit_tests/command_queue/enqueue_fill_buffer_tests.cpp @@ -84,7 +84,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, EnqueueFillBufferCmdTests, GPGPUWalker) { } HWTEST_F(EnqueueFillBufferCmdTests, addsIndirectData) { - auto patternAllocation = context.getMemoryManager()->allocateGraphicsMemory(EnqueueFillBufferTraits::patternSize); + auto patternAllocation = context.getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{EnqueueFillBufferTraits::patternSize}); auto dshBefore = pDSH->getUsed(); auto iohBefore = pIOH->getUsed(); @@ -120,7 +120,7 @@ HWTEST_F(EnqueueFillBufferCmdTests, addsIndirectData) { } HWTEST_F(EnqueueFillBufferCmdTests, FillBufferRightLeftover) { - auto patternAllocation = context.getMemoryManager()->allocateGraphicsMemory(EnqueueFillBufferTraits::patternSize); + auto patternAllocation = context.getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{EnqueueFillBufferTraits::patternSize}); EnqueueFillBufferHelper<>::enqueueFillBuffer(pCmdQ, buffer); @@ -147,7 +147,7 @@ HWTEST_F(EnqueueFillBufferCmdTests, FillBufferRightLeftover) { } HWTEST_F(EnqueueFillBufferCmdTests, FillBufferMiddle) { - auto patternAllocation = context.getMemoryManager()->allocateGraphicsMemory(EnqueueFillBufferTraits::patternSize); + auto patternAllocation = context.getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{EnqueueFillBufferTraits::patternSize}); EnqueueFillBufferHelper<>::enqueueFillBuffer(pCmdQ, buffer); @@ -174,7 +174,7 @@ HWTEST_F(EnqueueFillBufferCmdTests, FillBufferMiddle) { } HWTEST_F(EnqueueFillBufferCmdTests, FillBufferLeftLeftover) { - auto patternAllocation = context.getMemoryManager()->allocateGraphicsMemory(EnqueueFillBufferTraits::patternSize); + auto patternAllocation = context.getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{EnqueueFillBufferTraits::patternSize}); EnqueueFillBufferHelper<>::enqueueFillBuffer(pCmdQ, buffer); @@ -266,7 +266,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, EnqueueFillBufferCmdTests, MediaVFEState) { } HWTEST_F(EnqueueFillBufferCmdTests, argumentZeroShouldMatchDestAddress) { - auto patternAllocation = context.getMemoryManager()->allocateGraphicsMemory(EnqueueFillBufferTraits::patternSize); + auto patternAllocation = context.getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{EnqueueFillBufferTraits::patternSize}); enqueueFillBuffer(); @@ -302,7 +302,7 @@ HWTEST_F(EnqueueFillBufferCmdTests, argumentZeroShouldMatchDestAddress) { // This could happen if KernelInfo.kernelArgInfo was accessible given a Kernel. Just need an offset // into CrossThreadData. HWTEST_F(EnqueueFillBufferCmdTests, DISABLED_argumentOneShouldMatchOffset) { - auto patternAllocation = context.getMemoryManager()->allocateGraphicsMemory(EnqueueFillBufferTraits::patternSize); + auto patternAllocation = context.getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{EnqueueFillBufferTraits::patternSize}); enqueueFillBuffer(); @@ -335,7 +335,7 @@ HWTEST_F(EnqueueFillBufferCmdTests, DISABLED_argumentOneShouldMatchOffset) { } HWTEST_F(EnqueueFillBufferCmdTests, argumentTwoShouldMatchPatternPtr) { - auto patternAllocation = context.getMemoryManager()->allocateGraphicsMemory(EnqueueFillBufferTraits::patternSize); + auto patternAllocation = context.getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{EnqueueFillBufferTraits::patternSize}); enqueueFillBuffer(); diff --git a/unit_tests/command_queue/enqueue_map_image_tests.cpp b/unit_tests/command_queue/enqueue_map_image_tests.cpp index eb6a3985f9..958459a2cd 100644 --- a/unit_tests/command_queue/enqueue_map_image_tests.cpp +++ b/unit_tests/command_queue/enqueue_map_image_tests.cpp @@ -919,7 +919,7 @@ TEST_F(EnqueueMapImageTest, givenImage1DArrayWhenEnqueueMapImageIsCalledThenRetu imageFormat.image_channel_data_type = CL_UNSIGNED_INT16; const SurfaceFormatInfo *surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat); - auto allocation = context->getMemoryManager()->allocateGraphicsMemory(imgSize); + auto allocation = context->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{imgSize}); ASSERT_NE(allocation, nullptr); MockImage image(context, flags, allocation, *surfaceFormat, imageFormat, imageDesc); diff --git a/unit_tests/command_queue/get_size_required_buffer_tests.cpp b/unit_tests/command_queue/get_size_required_buffer_tests.cpp index dbe2f2538f..b78f5d2e37 100644 --- a/unit_tests/command_queue/get_size_required_buffer_tests.cpp +++ b/unit_tests/command_queue/get_size_required_buffer_tests.cpp @@ -43,7 +43,7 @@ struct GetSizeRequiredBufferTest : public CommandEnqueueFixture, BufferDefaults::context = new MockContext; srcBuffer = BufferHelper<>::create(); dstBuffer = BufferHelper<>::create(); - patternAllocation = context->getMemoryManager()->allocateGraphicsMemory(EnqueueFillBufferTraits::patternSize); + patternAllocation = context->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{EnqueueFillBufferTraits::patternSize}); pDevice->setPreemptionMode(PreemptionMode::Disabled); } diff --git a/unit_tests/command_queue/multiple_map_buffer_tests.cpp b/unit_tests/command_queue/multiple_map_buffer_tests.cpp index 88934ea84c..9040de403d 100644 --- a/unit_tests/command_queue/multiple_map_buffer_tests.cpp +++ b/unit_tests/command_queue/multiple_map_buffer_tests.cpp @@ -85,7 +85,7 @@ struct MultipleMapBufferTest : public DeviceFixture, public ::testing::Test { template std::unique_ptr> createMockBuffer(bool mapOnGpu) { - auto mockAlloc = pDevice->getMemoryManager()->allocateGraphicsMemory(1024); + auto mockAlloc = pDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); auto buffer = new MockBuffer(context, 0, 1024, mockAlloc->getUnderlyingBuffer(), mockAlloc->getUnderlyingBuffer(), mockAlloc, false, false, false); if (mapOnGpu) { diff --git a/unit_tests/command_queue/multiple_map_image_tests.cpp b/unit_tests/command_queue/multiple_map_image_tests.cpp index 4c7a2095c6..3363e50b3c 100644 --- a/unit_tests/command_queue/multiple_map_image_tests.cpp +++ b/unit_tests/command_queue/multiple_map_image_tests.cpp @@ -89,7 +89,7 @@ struct MultipleMapImageTest : public DeviceFixture, public ::testing::Test { template std::unique_ptr> createMockImage() { auto allocationSize = Traits::imageDesc.image_width * 4 * Traits::imageDesc.image_height * Traits::imageDesc.image_depth; - auto mockAlloc = pDevice->getMemoryManager()->allocateGraphicsMemory(allocationSize); + auto mockAlloc = pDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{allocationSize}); auto tiledImage = GmmHelper::allowTiling(Traits::imageDesc); auto surfaceFormat = Image::getSurfaceFormatFromTable(Traits::flags, &Traits::imageFormat); diff --git a/unit_tests/command_stream/aub_command_stream_receiver_1_tests.cpp b/unit_tests/command_stream/aub_command_stream_receiver_1_tests.cpp index a0960f8f5b..fa50d7f08e 100644 --- a/unit_tests/command_stream/aub_command_stream_receiver_1_tests.cpp +++ b/unit_tests/command_stream/aub_command_stream_receiver_1_tests.cpp @@ -236,7 +236,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationWhenMakeResidentC std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], "", true, *pDevice->executionEnvironment)); memoryManager.reset(aubCsr->createMemoryManager(false, false)); aubCsr->setOsContext(*pDevice->getDefaultEngine().osContext); - auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); auto osContextId = aubCsr->getOsContext().getContextId(); @@ -542,7 +542,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon auto commandBuffer = aubExecutionEnvironment->commandBuffer; LinearStream cs(commandBuffer); - auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, gfxAllocation); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; @@ -576,7 +576,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInNonStanda auto commandBuffer = aubExecutionEnvironment->commandBuffer; LinearStream cs(commandBuffer); - auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; @@ -613,7 +613,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon aubCsr->subCaptureManager.reset(aubSubCaptureManagerMock); ASSERT_TRUE(aubCsr->subCaptureManager->isSubCaptureEnabled()); - auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, gfxAllocation); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; @@ -644,7 +644,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenGraphic auto aubExecutionEnvironment = getEnvironment>(false, false, true); auto memoryManager = aubExecutionEnvironment->executionEnvironment->memoryManager.get(); - auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); EXPECT_TRUE(gfxAllocation->isAubWritable()); @@ -656,7 +656,8 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenProcess auto aubCsr = aubExecutionEnvironment->template getCsr>(); auto memoryManager = aubExecutionEnvironment->executionEnvironment->memoryManager.get(); - auto gfxDefaultAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); + auto gfxDefaultAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + ; ResidencyContainer allocationsForResidency = {gfxDefaultAllocation}; aubCsr->processResidency(allocationsForResidency); @@ -671,7 +672,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenWriteMe std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], "", true, *pDevice->executionEnvironment)); memoryManager.reset(aubCsr->createMemoryManager(false, false)); - auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); GraphicsAllocation::AllocationType onlyOneTimeAubWritableTypes[] = { GraphicsAllocation::AllocationType::BUFFER, @@ -696,10 +697,12 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenProcess memoryManager.reset(aubCsr->createMemoryManager(false, false)); aubCsr->setOsContext(*pDevice->getDefaultEngine().osContext); - auto gfxBufferAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); + auto gfxBufferAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + ; gfxBufferAllocation->setAllocationType(GraphicsAllocation::AllocationType::BUFFER); - auto gfxImageAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); + auto gfxImageAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + ; gfxImageAllocation->setAllocationType(GraphicsAllocation::AllocationType::IMAGE); ResidencyContainer allocationsForResidency = {gfxBufferAllocation, gfxImageAllocation}; @@ -719,11 +722,13 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptur memoryManager.reset(aubCsr->createMemoryManager(false, false)); aubCsr->setOsContext(*pDevice->getDefaultEngine().osContext); - auto gfxBufferAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); + auto gfxBufferAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + ; gfxBufferAllocation->setAllocationType(GraphicsAllocation::AllocationType::BUFFER); gfxBufferAllocation->setAubWritable(false); - auto gfxImageAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); + auto gfxImageAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + ; gfxImageAllocation->setAllocationType(GraphicsAllocation::AllocationType::IMAGE); gfxImageAllocation->setAubWritable(false); @@ -746,11 +751,13 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenProcess memoryManager.reset(aubCsr->createMemoryManager(false, false)); aubCsr->setOsContext(*pDevice->getDefaultEngine().osContext); - auto gfxBufferAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); + auto gfxBufferAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + ; gfxBufferAllocation->setAllocationType(GraphicsAllocation::AllocationType::BUFFER); gfxBufferAllocation->setAubWritable(false); - auto gfxImageAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); + auto gfxImageAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + ; gfxImageAllocation->setAllocationType(GraphicsAllocation::AllocationType::IMAGE); gfxImageAllocation->setAubWritable(false); @@ -771,7 +778,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenGraphic std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], "", true, *pDevice->executionEnvironment)); memoryManager.reset(aubCsr->createMemoryManager(false, false)); - auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); EXPECT_TRUE(aubCsr->writeMemory(*gfxAllocation)); @@ -783,7 +790,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenGraphic std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], "", true, *pDevice->executionEnvironment)); memoryManager.reset(aubCsr->createMemoryManager(false, false)); - auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); gfxAllocation->setAubWritable(false); EXPECT_FALSE(aubCsr->writeMemory(*gfxAllocation)); diff --git a/unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp b/unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp index 776a40fab7..ad83258d3d 100644 --- a/unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp +++ b/unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp @@ -48,11 +48,11 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedB auto flatBatchBufferHelper = new FlatBatchBufferHelperHw(*pDevice->executionEnvironment); aubCsr->overwriteFlatBatchBufferHelper(flatBatchBufferHelper); - auto chainedBatchBuffer = memoryManager->allocateGraphicsMemory(128u); - auto otherAllocation = memoryManager->allocateGraphicsMemory(128u); + auto chainedBatchBuffer = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{128u}); + auto otherAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{128u}); ASSERT_NE(nullptr, chainedBatchBuffer); - GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{128u}); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); @@ -64,7 +64,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedB aubCsr->getFlatBatchBufferHelper().flattenBatchBuffer(batchBuffer, sizeBatchBuffer, DispatchMode::ImmediateDispatch), [&](GraphicsAllocation *ptr) { memoryManager->freeGraphicsMemory(ptr); }); EXPECT_NE(nullptr, flatBatchBuffer->getUnderlyingBuffer()); - EXPECT_EQ(alignUp(128u + 128u, 0x1000), sizeBatchBuffer); + EXPECT_EQ(alignUp(128u + 128u, MemoryConstants::pageSize), sizeBatchBuffer); memoryManager->freeGraphicsMemory(commandBuffer); memoryManager->freeGraphicsMemory(chainedBatchBuffer); @@ -78,7 +78,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedB auto flatBatchBufferHelper = new FlatBatchBufferHelperHw(*pDevice->executionEnvironment); aubCsr->overwriteFlatBatchBufferHelper(flatBatchBufferHelper); - GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); @@ -102,11 +102,11 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedB auto flatBatchBufferHelper = new FlatBatchBufferHelperHw(*pDevice->executionEnvironment); aubCsr->overwriteFlatBatchBufferHelper(flatBatchBufferHelper); - auto chainedBatchBuffer = memoryManager->allocateGraphicsMemory(128u); - auto otherAllocation = memoryManager->allocateGraphicsMemory(128u); + auto chainedBatchBuffer = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + auto otherAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, chainedBatchBuffer); - GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); @@ -278,7 +278,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedF auto mockHelper = new MockFlatBatchBufferHelper(*aubExecutionEnvironment->executionEnvironment); aubCsr->overwriteFlatBatchBufferHelper(mockHelper); - auto chainedBatchBuffer = aubExecutionEnvironment->executionEnvironment->memoryManager->allocateGraphicsMemory(128u); + auto chainedBatchBuffer = aubExecutionEnvironment->executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, chainedBatchBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 128u, chainedBatchBuffer, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; @@ -286,7 +286,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedF aubCsr->makeResident(*chainedBatchBuffer); std::unique_ptr> ptr( - aubExecutionEnvironment->executionEnvironment->memoryManager->allocateGraphicsMemory(4096), + aubExecutionEnvironment->executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}), [&](GraphicsAllocation *ptr) { aubExecutionEnvironment->executionEnvironment->memoryManager->freeGraphicsMemory(ptr); }); auto expectedAllocation = ptr.get(); @@ -665,7 +665,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenWriteMe aubCsr->ppgtt.reset(ppgttMock); - auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); gfxAllocation->setAubWritable(true); auto gmm = new Gmm(nullptr, 1, false); diff --git a/unit_tests/command_stream/command_stream_receiver_flush_task_3_tests.cpp b/unit_tests/command_stream/command_stream_receiver_flush_task_3_tests.cpp index e3fe8c3a2a..1dc649c923 100644 --- a/unit_tests/command_stream/command_stream_receiver_flush_task_3_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_flush_task_3_tests.cpp @@ -1185,11 +1185,11 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrWhenTemporaryAndReusableAl auto &commandStreamReceiver = pDevice->getUltCommandStreamReceiver(); auto memoryManager = pDevice->getMemoryManager(); - auto temporaryToClean = memoryManager->allocateGraphicsMemory(4096u); - auto temporaryToHold = memoryManager->allocateGraphicsMemory(4096u); + auto temporaryToClean = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + auto temporaryToHold = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); - auto reusableToClean = memoryManager->allocateGraphicsMemory(4096u); - auto reusableToHold = memoryManager->allocateGraphicsMemory(4096u); + auto reusableToClean = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + auto reusableToHold = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); commandStreamReceiver.getInternalAllocationStorage()->storeAllocation(std::unique_ptr(temporaryToClean), TEMPORARY_ALLOCATION); commandStreamReceiver.getInternalAllocationStorage()->storeAllocation(std::unique_ptr(temporaryToHold), TEMPORARY_ALLOCATION); diff --git a/unit_tests/command_stream/command_stream_receiver_tests.cpp b/unit_tests/command_stream/command_stream_receiver_tests.cpp index 30d9d655e4..8246385855 100644 --- a/unit_tests/command_stream/command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_tests.cpp @@ -197,7 +197,7 @@ HWTEST_F(CommandStreamReceiverTest, givenCommandStreamReceiverWhenCheckedForInit TEST_F(CommandStreamReceiverTest, makeResidentPushesAllocationToMemoryManagerResidencyList) { auto *memoryManager = commandStreamReceiver->getMemoryManager(); - GraphicsAllocation *graphicsAllocation = memoryManager->allocateGraphicsMemory(0x1000); + GraphicsAllocation *graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, graphicsAllocation); diff --git a/unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp b/unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp index efc265077a..ce44cf35dd 100644 --- a/unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp @@ -12,6 +12,7 @@ #include "runtime/execution_environment/execution_environment.h" #include "runtime/helpers/dispatch_info.h" #include "runtime/os_interface/os_context.h" +#include "unit_tests/mocks/mock_allocation_properties.h" #include "test.h" @@ -150,7 +151,7 @@ HWTEST_P(CommandStreamReceiverWithAubDumpTest, givenCommandStreamReceiverWithAub } HWTEST_P(CommandStreamReceiverWithAubDumpTest, givenCommandStreamReceiverWithAubDumpWhenFlushIsCalledThenBaseCsrFlushStampIsReturned) { - GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); @@ -177,7 +178,7 @@ HWTEST_P(CommandStreamReceiverWithAubDumpTest, givenCommandStreamReceiverWithAub } HWTEST_P(CommandStreamReceiverWithAubDumpTest, givenCommandStreamReceiverWithAubDumpWhenMakeResidentIsCalledThenBaseCsrMakeResidentIsCalled) { - auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, gfxAllocation); csrWithAubDump->makeResident(*gfxAllocation); @@ -194,12 +195,12 @@ HWTEST_P(CommandStreamReceiverWithAubDumpTest, givenCommandStreamReceiverWithAub } HWTEST_P(CommandStreamReceiverWithAubDumpTest, givenCommandStreamReceiverWithAubDumpWhenFlushIsCalledThenBothBaseAndAubCsrProcessResidencyIsCalled) { - GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); + 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 gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, gfxAllocation); ResidencyContainer allocationsForResidency = {gfxAllocation}; @@ -219,7 +220,7 @@ HWTEST_P(CommandStreamReceiverWithAubDumpTest, givenCommandStreamReceiverWithAub } HWTEST_P(CommandStreamReceiverWithAubDumpTest, givenCommandStreamReceiverWithAubDumpWhenMakeNonResidentIsCalledThenBothBaseAndAubCsrMakeNonResidentIsCalled) { - auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, gfxAllocation); csrWithAubDump->makeResident(*gfxAllocation); diff --git a/unit_tests/command_stream/experimental_command_buffer_tests.cpp b/unit_tests/command_stream/experimental_command_buffer_tests.cpp index 5c923daa5e..c8a4a6a8ac 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->allocateGraphicsMemory(3 * MemoryConstants::pageSize); + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{3 * MemoryConstants::pageSize}); storage->storeAllocation(std::unique_ptr(allocation), REUSABLE_ALLOCATION); - allocation = memoryManager->allocateGraphicsMemory(3 * MemoryConstants::pageSize); + allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{3 * MemoryConstants::pageSize}); storage->storeAllocation(std::unique_ptr(allocation), REUSABLE_ALLOCATION); MockExperimentalCommandBuffer *mockExCmdBuffer = static_cast(commandStreamReceiver.experimentalCmdBuffer.get()); diff --git a/unit_tests/command_stream/tbx_command_stream_tests.cpp b/unit_tests/command_stream/tbx_command_stream_tests.cpp index b4523312e4..9636bfa4fc 100644 --- a/unit_tests/command_stream/tbx_command_stream_tests.cpp +++ b/unit_tests/command_stream/tbx_command_stream_tests.cpp @@ -167,7 +167,7 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenMakeResidentIsC TbxMemoryManager *memoryManager = tbxCsr->getMemoryManager(); ASSERT_NE(nullptr, memoryManager); - auto graphicsAllocation = memoryManager->allocateGraphicsMemory(4096); + auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, graphicsAllocation); EXPECT_EQ(0u, tbxCsr->getResidencyAllocations().size()); @@ -184,7 +184,7 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenMakeResidentHas TbxMemoryManager *memoryManager = tbxCsr->getMemoryManager(); ASSERT_NE(nullptr, memoryManager); - auto graphicsAllocation = memoryManager->allocateGraphicsMemory(4096); + auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, graphicsAllocation); EXPECT_EQ(0u, tbxCsr->getResidencyAllocations().size()); @@ -205,7 +205,7 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenWriteMemoryIsCa TbxMemoryManager *memoryManager = tbxCsr->getMemoryManager(); ASSERT_NE(nullptr, memoryManager); - auto graphicsAllocation = memoryManager->allocateGraphicsMemory(4096); + auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, graphicsAllocation); EXPECT_TRUE(tbxCsr->writeMemory(*graphicsAllocation)); @@ -225,7 +225,7 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenProcessResidenc TbxMemoryManager *memoryManager = tbxCsr->getMemoryManager(); ASSERT_NE(nullptr, memoryManager); - auto graphicsAllocation = memoryManager->allocateGraphicsMemory(4096); + auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, graphicsAllocation); EXPECT_FALSE(graphicsAllocation->isResident(tbxCsr->getOsContext().getContextId())); @@ -244,7 +244,7 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenProcessResidenc TbxMemoryManager *memoryManager = tbxCsr->getMemoryManager(); ASSERT_NE(nullptr, memoryManager); - auto graphicsAllocation = memoryManager->allocateGraphicsMemory(4096); + auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, graphicsAllocation); EXPECT_FALSE(graphicsAllocation->isResident(tbxCsr->getOsContext().getContextId())); @@ -263,10 +263,10 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenFlushIsCalledTh TbxMemoryManager *memoryManager = tbxCsr->getMemoryManager(); ASSERT_NE(nullptr, memoryManager); - auto graphicsAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); + auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, graphicsAllocation); - GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); diff --git a/unit_tests/event/user_events_tests.cpp b/unit_tests/event/user_events_tests.cpp index 5f5d8359d3..cb83ad58d9 100644 --- a/unit_tests/event/user_events_tests.cpp +++ b/unit_tests/event/user_events_tests.cpp @@ -912,7 +912,7 @@ TEST_F(EventTests, waitForEventsDestroysTemporaryAllocations) { EXPECT_TRUE(csr.getTemporaryAllocations().peekIsEmpty()); - GraphicsAllocation *temporaryAllocation = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize); + GraphicsAllocation *temporaryAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); csr.getInternalAllocationStorage()->storeAllocation(std::unique_ptr(temporaryAllocation), TEMPORARY_ALLOCATION); EXPECT_EQ(temporaryAllocation, csr.getTemporaryAllocations().peekHead()); diff --git a/unit_tests/execution_model/enqueue_execution_model_kernel_tests.cpp b/unit_tests/execution_model/enqueue_execution_model_kernel_tests.cpp index 8fc5de9863..2f3bffb2b3 100644 --- a/unit_tests/execution_model/enqueue_execution_model_kernel_tests.cpp +++ b/unit_tests/execution_model/enqueue_execution_model_kernel_tests.cpp @@ -110,7 +110,7 @@ HWTEST_P(ParentKernelEnqueueTest, GivenParentKernelWithPrivateSurfaceWhenEnqueue int32_t executionStamp = 0; auto mockCSR = new MockCsr(executionStamp, *pDevice->executionEnvironment); pDevice->resetCommandStreamReceiver(mockCSR); - GraphicsAllocation *privateSurface = mockCSR->getMemoryManager()->allocateGraphicsMemory(10); + GraphicsAllocation *privateSurface = mockCSR->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); pKernel->getProgram()->getBlockKernelManager()->pushPrivateSurface(privateSurface, 0); pCmdQ->enqueueKernel(pKernel, 1, offset, gws, gws, 0, nullptr, nullptr); @@ -128,7 +128,7 @@ HWTEST_P(ParentKernelEnqueueTest, GivenBlocksWithPrivateMemoryWhenEnqueueKernelT auto &csr = pDevice->getUltCommandStreamReceiver(); csr.storeMakeResidentAllocations = true; - auto privateAllocation = csr.getMemoryManager()->allocateGraphicsMemory(10); + auto privateAllocation = csr.getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); blockKernelManager->pushPrivateSurface(privateAllocation, 0); UserEvent uEvent(pContext); diff --git a/unit_tests/gen10/coherency_tests_gen10.cpp b/unit_tests/gen10/coherency_tests_gen10.cpp index 6dc3fef593..d27c31c03f 100644 --- a/unit_tests/gen10/coherency_tests_gen10.cpp +++ b/unit_tests/gen10/coherency_tests_gen10.cpp @@ -93,7 +93,7 @@ struct Gen10CoherencyProgramingTest : public Gen10CoherencyRequirements { void flushTask(bool coherencyRequired) { flags.requiresCoherency = coherencyRequired; - auto graphicAlloc = csr->getMemoryManager()->allocateGraphicsMemory(MemoryConstants::pageSize); + auto graphicAlloc = csr->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); IndirectHeap stream(graphicAlloc); startOffset = csr->commandStream.getUsed(); diff --git a/unit_tests/helpers/kernel_commands_tests.cpp b/unit_tests/helpers/kernel_commands_tests.cpp index 13ea1bd067..53e23c4f18 100644 --- a/unit_tests/helpers/kernel_commands_tests.cpp +++ b/unit_tests/helpers/kernel_commands_tests.cpp @@ -199,7 +199,7 @@ HWTEST_F(KernelCommandsTest, givenSendCrossThreadDataWhenWhenAddPatchInfoComment } HWTEST_F(KernelCommandsTest, givenIndirectHeapNotAllocatedFromInternalPoolWhenSendCrossThreadDataIsCalledThenOffsetZeroIsReturned) { - auto nonInternalAllocation = pDevice->getMemoryManager()->allocateGraphicsMemory(4096); + auto nonInternalAllocation = pDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); IndirectHeap indirectHeap(nonInternalAllocation, false); MockKernelWithInternals mockKernelWithInternal(*pDevice); diff --git a/unit_tests/kernel/kernel_image_arg_tests.cpp b/unit_tests/kernel/kernel_image_arg_tests.cpp index 3b0436af3a..9fda80a318 100644 --- a/unit_tests/kernel/kernel_image_arg_tests.cpp +++ b/unit_tests/kernel/kernel_image_arg_tests.cpp @@ -184,7 +184,7 @@ HWTEST_F(KernelImageArgTest, givenImgWithMcsAllocWhenMakeResidentThenMakeMcsAllo auto surfaceFormat = Image::getSurfaceFormatFromTable(0, &imgFormat); auto img = Image::create(context.get(), 0, surfaceFormat, &imgDesc, nullptr, retVal); EXPECT_EQ(CL_SUCCESS, retVal); - auto mcsAlloc = context->getMemoryManager()->allocateGraphicsMemory(4096); + auto mcsAlloc = context->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); img->setMcsAllocation(mcsAlloc); cl_mem memObj = img; pKernel->setArg(0, sizeof(memObj), &memObj); diff --git a/unit_tests/kernel/kernel_reflection_surface_tests.cpp b/unit_tests/kernel/kernel_reflection_surface_tests.cpp index dbc2200975..09a987c63f 100644 --- a/unit_tests/kernel/kernel_reflection_surface_tests.cpp +++ b/unit_tests/kernel/kernel_reflection_surface_tests.cpp @@ -1965,12 +1965,12 @@ TEST_F(ReflectionSurfaceConstantValuesPatchingTest, GivenBlockWithGlobalMemoryWh MockParentKernel *parentKernel = MockParentKernel::create(context, false, true, false); // graphicsMemory is released by Program - GraphicsAllocation *globalMemory = pDevice->getMemoryManager()->allocateGraphicsMemory(4096); + GraphicsAllocation *globalMemory = pDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); parentKernel->mockProgram->setGlobalSurface(globalMemory); // Allocte reflectionSurface, 2 * 4096 should be enough - GraphicsAllocation *reflectionSurface = pDevice->getMemoryManager()->allocateGraphicsMemory(2 * 4096); + GraphicsAllocation *reflectionSurface = pDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{2 * MemoryConstants::pageSize}); parentKernel->setReflectionSurface(reflectionSurface); memset(reflectionSurface->getUnderlyingBuffer(), 0, reflectionSurface->getUnderlyingBufferSize()); @@ -2004,7 +2004,7 @@ TEST_F(ReflectionSurfaceConstantValuesPatchingTest, GivenBlockWithGlobalMemoryAn } // Allocte reflectionSurface, 2 * 4096 should be enough - GraphicsAllocation *reflectionSurface = pDevice->getMemoryManager()->allocateGraphicsMemory(2 * 4096); + GraphicsAllocation *reflectionSurface = pDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{2 * MemoryConstants::pageSize}); parentKernel->setReflectionSurface(reflectionSurface); memset(reflectionSurface->getUnderlyingBuffer(), 0, reflectionSurface->getUnderlyingBufferSize()); @@ -2032,12 +2032,12 @@ TEST_F(ReflectionSurfaceConstantValuesPatchingTest, GivenBlockWithConstantMemory MockParentKernel *parentKernel = MockParentKernel::create(context, false, false, true); // graphicsMemory is released by Program - GraphicsAllocation *constantMemory = pDevice->getMemoryManager()->allocateGraphicsMemory(4096); + GraphicsAllocation *constantMemory = pDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); parentKernel->mockProgram->setConstantSurface(constantMemory); // Allocte reflectionSurface, 2 * 4096 should be enough - GraphicsAllocation *reflectionSurface = pDevice->getMemoryManager()->allocateGraphicsMemory(2 * 4096); + GraphicsAllocation *reflectionSurface = pDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{2 * MemoryConstants::pageSize}); parentKernel->setReflectionSurface(reflectionSurface); memset(reflectionSurface->getUnderlyingBuffer(), 0, reflectionSurface->getUnderlyingBufferSize()); @@ -2080,7 +2080,7 @@ TEST_F(ReflectionSurfaceConstantValuesPatchingTest, GivenBlockWithConstantMemory } // Allocte reflectionSurface, 2 * 4096 should be enough - GraphicsAllocation *reflectionSurface = pDevice->getMemoryManager()->allocateGraphicsMemory(2 * 4096); + GraphicsAllocation *reflectionSurface = pDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{2 * MemoryConstants::pageSize}); parentKernel->setReflectionSurface(reflectionSurface); memset(reflectionSurface->getUnderlyingBuffer(), 0, reflectionSurface->getUnderlyingBufferSize()); diff --git a/unit_tests/kernel/kernel_tests.cpp b/unit_tests/kernel/kernel_tests.cpp index a808f3bccb..93539f67d0 100644 --- a/unit_tests/kernel/kernel_tests.cpp +++ b/unit_tests/kernel/kernel_tests.cpp @@ -1656,7 +1656,7 @@ HWTEST_F(KernelResidencyTest, givenKernelWhenMakeResidentIsCalledThenKernelIsaIs commandStreamReceiver.storeMakeResidentAllocations = true; auto memoryManager = commandStreamReceiver.getMemoryManager(); - pKernelInfo->kernelAllocation = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize); + pKernelInfo->kernelAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); // setup kernel arg offsets KernelArgPatchInfo kernelArgPatchInfo; diff --git a/unit_tests/mem_obj/buffer_tests.cpp b/unit_tests/mem_obj/buffer_tests.cpp index 5624cad333..3ba0e1a25f 100644 --- a/unit_tests/mem_obj/buffer_tests.cpp +++ b/unit_tests/mem_obj/buffer_tests.cpp @@ -1027,7 +1027,7 @@ TEST(SharedBuffersTest, whenBuffersIsCreatedWithSharingHandlerThenItIsSharedBuff MockContext context; auto memoryManager = context.getDevice(0)->getMemoryManager(); auto handler = new SharingHandler(); - auto graphicsAlloaction = memoryManager->allocateGraphicsMemory(4096); + auto graphicsAlloaction = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); auto buffer = Buffer::createSharedBuffer(&context, CL_MEM_READ_ONLY, handler, graphicsAlloaction); ASSERT_NE(nullptr, buffer); EXPECT_EQ(handler, buffer->peekSharingHandler()); diff --git a/unit_tests/mem_obj/image_set_arg_tests.cpp b/unit_tests/mem_obj/image_set_arg_tests.cpp index 1df78478f5..ca2e8ad519 100644 --- a/unit_tests/mem_obj/image_set_arg_tests.cpp +++ b/unit_tests/mem_obj/image_set_arg_tests.cpp @@ -403,7 +403,7 @@ HWTEST_F(ImageSetArgTest, clSetKernelArgImage1Darray) { HWTEST_F(ImageSetArgTest, givenMcsAllocationWhenSetArgIsCalledWithoutUnifiedAuxCapabilityThenProgramAuxFieldsForMultisamples) { typedef typename FamilyType::RENDER_SURFACE_STATE RENDER_SURFACE_STATE; McsSurfaceInfo msi = {10, 20, 3}; - auto mcsAlloc = context->getMemoryManager()->allocateGraphicsMemory(4096); + auto mcsAlloc = context->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); mcsAlloc->gmm = new Gmm(nullptr, 1, false); cl_image_desc imgDesc = Image2dDefaults::imageDesc; imgDesc.num_samples = 8; @@ -502,7 +502,7 @@ HWTEST_F(ImageSetArgTest, givenMultisampledR32Floatx8x24DepthStencilFormatWhenSe HWTEST_F(ImageSetArgTest, givenMcsAllocationAndRenderCompressionWhenSetArgOnMultisampledImgIsCalledThenProgramAuxFieldsWithMcsParams) { typedef typename FamilyType::RENDER_SURFACE_STATE RENDER_SURFACE_STATE; McsSurfaceInfo msi = {10, 20, 3}; - auto mcsAlloc = context->getMemoryManager()->allocateGraphicsMemory(4096); + auto mcsAlloc = context->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); mcsAlloc->gmm = new Gmm(nullptr, 1, false); cl_image_desc imgDesc = Image2dDefaults::imageDesc; imgDesc.num_samples = 8; @@ -563,7 +563,7 @@ HWTEST_F(ImageSetArgTest, givenMcsAllocationWhenSetArgIsCalledWithUnifiedAuxCapa using AUXILIARY_SURFACE_MODE = typename RENDER_SURFACE_STATE::AUXILIARY_SURFACE_MODE; McsSurfaceInfo msi = {10, 20, 3}; - auto mcsAlloc = context->getMemoryManager()->allocateGraphicsMemory(4096); + auto mcsAlloc = context->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); mcsAlloc->gmm = new Gmm(nullptr, 1, false); cl_image_desc imgDesc = Image2dDefaults::imageDesc; imgDesc.num_samples = 8; diff --git a/unit_tests/mem_obj/mem_obj_destruction_tests.cpp b/unit_tests/mem_obj/mem_obj_destruction_tests.cpp index 93f0cd03e2..a2e659b186 100644 --- a/unit_tests/mem_obj/mem_obj_destruction_tests.cpp +++ b/unit_tests/mem_obj/mem_obj_destruction_tests.cpp @@ -36,7 +36,7 @@ class MemObjDestructionTest : public ::testing::TestWithParam { device.reset(MockDevice::create(*platformDevices, executionEnvironment.get(), 0)); context.reset(new MockContext(device.get())); - allocation = memoryManager->allocateGraphicsMemory(size); + allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{size}); memObj = new MemObj(context.get(), CL_MEM_OBJECT_BUFFER, CL_MEM_READ_WRITE, size, @@ -190,7 +190,7 @@ HWTEST_P(MemObjAsyncDestructionTest, givenUsedMemObjWithAsyncDestructionsEnabled if (!hasAllocatedMappedPtr) { delete memObj; - allocation = memoryManager->allocateGraphicsMemory(size); + allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{size}); MemObjOffsetArray origin = {{0, 0, 0}}; MemObjSizeArray region = {{1, 1, 1}}; cl_map_flags mapFlags = CL_MAP_READ; diff --git a/unit_tests/mem_obj/mem_obj_tests.cpp b/unit_tests/mem_obj/mem_obj_tests.cpp index 45cb992643..ff13b88512 100644 --- a/unit_tests/mem_obj/mem_obj_tests.cpp +++ b/unit_tests/mem_obj/mem_obj_tests.cpp @@ -149,7 +149,7 @@ TEST(MemObj, givenNotReadyGraphicsAllocationWhenMemObjDestroysAllocationAsyncThe context.setMemoryManager(&memoryManager); - auto allocation = memoryManager.allocateGraphicsMemory(MemoryConstants::pageSize); + auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); allocation->updateTaskCount(2, context.getDevice(0)->getDefaultEngine().osContext->getContextId()); *(memoryManager.getDefaultCommandStreamReceiver(0)->getTagAddress()) = 1; MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, CL_MEM_COPY_HOST_PTR, @@ -168,7 +168,7 @@ TEST(MemObj, givenReadyGraphicsAllocationWhenMemObjDestroysAllocationAsyncThenAl MockContext context(device.get()); auto memoryManager = executionEnvironment.memoryManager.get(); - auto allocation = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize); + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); allocation->updateTaskCount(1, device->getDefaultEngine().osContext->getContextId()); *device->getDefaultEngine().commandStreamReceiver->getTagAddress() = 1; MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, CL_MEM_COPY_HOST_PTR, @@ -187,7 +187,7 @@ TEST(MemObj, givenNotUsedGraphicsAllocationWhenMemObjDestroysAllocationAsyncThen context.setMemoryManager(&memoryManager); - auto allocation = memoryManager.allocateGraphicsMemory(MemoryConstants::pageSize); + auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, CL_MEM_COPY_HOST_PTR, MemoryConstants::pageSize, nullptr, nullptr, nullptr, true, false, false); @@ -204,7 +204,7 @@ TEST(MemObj, givenMemoryManagerWithoutDeviceWhenMemObjDestroysAllocationAsyncThe context.setMemoryManager(&memoryManager); - auto allocation = memoryManager.allocateGraphicsMemory(MemoryConstants::pageSize); + auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, CL_MEM_COPY_HOST_PTR, MemoryConstants::pageSize, nullptr, nullptr, nullptr, true, false, false); @@ -292,7 +292,7 @@ TEST(MemObj, givenRenderCompressedGmmWhenAskingForMappingOnCpuThenDisallow) { context.setMemoryManager(&memoryManager); - auto allocation = memoryManager.allocateGraphicsMemory(1); + auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); allocation->gmm = new Gmm(nullptr, 1, false); MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, CL_MEM_READ_WRITE, @@ -310,7 +310,7 @@ TEST(MemObj, givenDefaultWhenAskedForCpuMappingThenReturnTrue) { context.setMemoryManager(&memoryManager); - auto allocation = memoryManager.allocateGraphicsMemory(64); + auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, CL_MEM_COPY_HOST_PTR, 64, allocation->getUnderlyingBuffer(), nullptr, allocation, true, false, false); @@ -326,7 +326,7 @@ TEST(MemObj, givenNonCpuAccessibleMemoryWhenAskingForMappingOnCpuThenDisallow) { context.setMemoryManager(&memoryManager); - auto allocation = memoryManager.allocateGraphicsMemory(1); + auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); allocation->gmm = new Gmm(nullptr, 1, false); MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, CL_MEM_READ_WRITE, @@ -343,7 +343,7 @@ TEST(MemObj, givenMultipleMemObjectsWithReusedGraphicsAllocationWhenDestroyedThe MockContext context; context.setMemoryManager(&memoryManager); - auto allocation = memoryManager.allocateGraphicsMemory(1); + auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); std::unique_ptr memObj1(new MemObj(&context, CL_MEM_OBJECT_BUFFER, 0, 1, nullptr, nullptr, allocation, true, false, false)); memObj1->setSharingHandler(new MySharingHandler(allocation)); diff --git a/unit_tests/memory_manager/deferrable_allocation_deletion_tests.cpp b/unit_tests/memory_manager/deferrable_allocation_deletion_tests.cpp index bb8593f607..ab869c0572 100644 --- a/unit_tests/memory_manager/deferrable_allocation_deletion_tests.cpp +++ b/unit_tests/memory_manager/deferrable_allocation_deletion_tests.cpp @@ -11,6 +11,7 @@ #include "runtime/memory_manager/deferrable_allocation_deletion.h" #include "runtime/os_interface/os_context.h" +#include "unit_tests/mocks/mock_allocation_properties.h" #include "unit_tests/mocks/mock_memory_manager.h" #include "gtest/gtest.h" @@ -56,7 +57,7 @@ struct DeferrableAllocationDeletionTest : ::testing::Test { TEST_F(DeferrableAllocationDeletionTest, givenDeferrableAllocationWhenApplyThenWaitForEachTaskCount) { EXPECT_EQ(gpgpuEngineInstances.size(), memoryManager->getOsContextCount()); - auto allocation = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize); + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); allocation->updateTaskCount(1u, device1ContextId); *hwTag = 0u; asyncDeleter->deferDeletion(new DeferrableAllocationDeletion(*memoryManager, *allocation)); @@ -79,7 +80,7 @@ TEST_F(DeferrableAllocationDeletionTest, givenAllocationUsedByTwoOsContextsWhenA std::unique_ptr device2(Device::create(nullptr, device1->getExecutionEnvironment(), 1u)); auto device2ContextId = device2->getDefaultEngine().osContext->getContextId(); EXPECT_EQ(gpgpuEngineInstances.size() * 2, memoryManager->getOsContextCount()); - auto allocation = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize); + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); *hwTag = 0u; *device2->getDefaultEngine().commandStreamReceiver->getTagAddress() = 1u; allocation->updateTaskCount(1u, device1ContextId); @@ -96,7 +97,7 @@ TEST_F(DeferrableAllocationDeletionTest, givenAllocationUsedByTwoOsContextsWhenA } TEST_F(DeferrableAllocationDeletionTest, givenNotUsedAllocationWhenApplyDeletionThenDontWait) { EXPECT_EQ(gpgpuEngineInstances.size(), memoryManager->getOsContextCount()); - auto allocation = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize); + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); EXPECT_FALSE(allocation->isUsed()); EXPECT_EQ(0u, memoryManager->freeGraphicsMemoryCalled); while (!asyncDeleter->doWorkInBackground) @@ -111,8 +112,8 @@ TEST_F(DeferrableAllocationDeletionTest, givenNotUsedAllocationWhenApplyDeletion } TEST_F(DeferrableAllocationDeletionTest, givenTwoAllocationsUsedByOneOsContextsEnqueuedToAsyncDeleterWhenOneAllocationIsCompletedThenReleaseThatAllocation) { - auto allocation1 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize); - auto allocation2 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize); + auto allocation1 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + auto allocation2 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); *hwTag = 1u; allocation1->updateTaskCount(2u, device1ContextId); allocation2->updateTaskCount(1u, device1ContextId); @@ -129,7 +130,7 @@ TEST_F(DeferrableAllocationDeletionTest, givenTwoAllocationsUsedByOneOsContextsE } TEST_F(DeferrableAllocationDeletionTest, givenNotCompletedAllocationWhenDeletionIsAppliedThenReturnFalse) { - auto allocation = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize); + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); *hwTag = 0u; allocation->updateTaskCount(1u, device1ContextId); EXPECT_EQ(0u, memoryManager->freeGraphicsMemoryCalled); @@ -142,7 +143,7 @@ TEST_F(DeferrableAllocationDeletionTest, givenNotCompletedAllocationWhenDeletion } TEST_F(DeferrableAllocationDeletionTest, givenNotUsedAllocationWhenDeletionIsAppliedThenReturnTrue) { - auto allocation = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize); + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); EXPECT_FALSE(allocation->isUsed()); DeferrableAllocationDeletion deletion{*memoryManager, *allocation}; EXPECT_TRUE(deletion.apply()); diff --git a/unit_tests/memory_manager/internal_allocation_storage_tests.cpp b/unit_tests/memory_manager/internal_allocation_storage_tests.cpp index b193e938df..77912b7ef9 100644 --- a/unit_tests/memory_manager/internal_allocation_storage_tests.cpp +++ b/unit_tests/memory_manager/internal_allocation_storage_tests.cpp @@ -9,6 +9,7 @@ #include "runtime/os_interface/os_context.h" #include "unit_tests/fixtures/memory_allocator_fixture.h" #include "unit_tests/helpers/debug_manager_state_restore.h" +#include "unit_tests/mocks/mock_allocation_properties.h" #include "unit_tests/utilities/containers_tests_helpers.h" #include "test.h" @@ -134,9 +135,9 @@ TEST_F(InternalAllocationStorageTest, whenObtainAllocationFromMidlleOfReusableLi auto &reusableAllocations = csr->getAllocationsForReuse(); EXPECT_TRUE(reusableAllocations.peekIsEmpty()); - auto allocation = memoryManager->allocateGraphicsMemory(1); - auto allocation2 = memoryManager->allocateGraphicsMemory(10000); - auto allocation3 = memoryManager->allocateGraphicsMemory(1); + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{1}); + auto allocation2 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{10000}); + auto allocation3 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{1}); EXPECT_TRUE(reusableAllocations.peekIsEmpty()); EXPECT_EQ(nullptr, allocation2->next); @@ -187,7 +188,7 @@ TEST_F(InternalAllocationStorageTest, whenObtainAllocationFromMidlleOfReusableLi TEST_F(InternalAllocationStorageTest, givenNonInternalAllocationWhenItIsPutOnReusableListWhenInternalAllocationIsRequestedThenNullIsReturned) { EXPECT_TRUE(csr->getAllocationsForReuse().peekIsEmpty()); - auto allocation = memoryManager->allocateGraphicsMemory(4096); + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); storage->storeAllocation(std::unique_ptr(allocation), REUSABLE_ALLOCATION); EXPECT_FALSE(csr->getAllocationsForReuse().peekIsEmpty()); @@ -199,7 +200,7 @@ TEST_F(InternalAllocationStorageTest, givenNonInternalAllocationWhenItIsPutOnReu TEST_F(InternalAllocationStorageTest, givenInternalAllocationWhenItIsPutOnReusableListWhenNonInternalAllocationIsRequestedThenNullIsReturned) { EXPECT_TRUE(csr->getAllocationsForReuse().peekIsEmpty()); - auto allocation = memoryManager->allocateGraphicsMemory(4096); + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); allocation->is32BitAllocation = true; storage->storeAllocation(std::unique_ptr(allocation), REUSABLE_ALLOCATION); @@ -213,7 +214,7 @@ TEST_F(InternalAllocationStorageTest, givenInternalAllocationWhenItIsPutOnReusab TEST_F(InternalAllocationStorageTest, givenInternalAllocationWhenItIsPutOnReusableListWhenInternalAllocationIsRequestedThenItIsReturned) { EXPECT_TRUE(csr->getAllocationsForReuse().peekIsEmpty()); - auto allocation = memoryManager->allocateGraphicsMemory(4096); + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); allocation->is32BitAllocation = true; storage->storeAllocation(std::unique_ptr(allocation), REUSABLE_ALLOCATION); 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 d8c7a0b601..9dbdf9da9b 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 @@ -7,6 +7,7 @@ #include "runtime/execution_environment/execution_environment.h" #include "runtime/memory_manager/os_agnostic_memory_manager.h" +#include "unit_tests/mocks/mock_allocation_properties.h" #include "unit_tests/mocks/mock_memory_manager.h" #include "test.h" @@ -21,8 +22,8 @@ class MemoryManagerGetAlloctionDataTest : public testing::TestWithParamgetMemoryPool()); @@ -329,7 +330,7 @@ TEST(MemoryManagerTest, givenMemoryManagerWhenGraphicsMemoryAllocationInDevicePo TEST(MemoryManagerTest, givenMemoryManagerWhenBufferTypeIsPassedThenAllocateGraphicsMemoryInPreferredPoolCanAllocateInDevicePool) { MockMemoryManager memoryManager(false); - auto allocation = memoryManager.allocateGraphicsMemoryInPreferredPool(AllocationProperties(true, MemoryConstants::pageSize), 0, nullptr, GraphicsAllocation::AllocationType::BUFFER); + auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER}); EXPECT_NE(nullptr, allocation); memoryManager.freeGraphicsMemory(allocation); } @@ -339,7 +340,7 @@ TEST(MemoryManagerTest, givenMemoryManagerWhenBufferTypeIsPassedAndAllocateInDev memoryManager.failInDevicePoolWithError = true; - auto allocation = memoryManager.allocateGraphicsMemoryInPreferredPool(AllocationProperties(true, MemoryConstants::pageSize), 0, nullptr, GraphicsAllocation::AllocationType::BUFFER); + auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER}); ASSERT_EQ(nullptr, allocation); EXPECT_FALSE(memoryManager.allocationInDevicePoolCreated); @@ -347,10 +348,26 @@ TEST(MemoryManagerTest, givenMemoryManagerWhenBufferTypeIsPassedAndAllocateInDev } TEST(MemoryManagerTest, givenSvmAllocationTypeWhenGetAllocationDataIsCalledThenZeroCopyIsRequested) { - MockMemoryManager memoryManager(false); AllocationData allocData; - AllocationProperties properties(true, 1); - MockMemoryManager::getAllocationData(allocData, properties, 0, nullptr, GraphicsAllocation::AllocationType::SVM); + MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::SVM}, 0, nullptr); EXPECT_TRUE(allocData.flags.mustBeZeroCopy); EXPECT_TRUE(allocData.flags.allocateMemory); } + +TEST(MemoryManagerTest, givenUndecidedTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsRequested) { + AllocationData allocData; + MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::UNDECIDED}, 0, nullptr); + EXPECT_TRUE(allocData.flags.useSystemMemory); +} + +TEST(MemoryManagerTest, givenFillPatternTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsRequested) { + AllocationData allocData; + MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::FILL_PATTERN}, 0, nullptr); + EXPECT_TRUE(allocData.flags.useSystemMemory); +} + +TEST(MemoryManagerTest, givenLinearStreamTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsRequested) { + AllocationData allocData; + MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::LINEAR_STREAM}, 0, nullptr); + EXPECT_TRUE(allocData.flags.useSystemMemory); +} diff --git a/unit_tests/memory_manager/memory_manager_tests.cpp b/unit_tests/memory_manager/memory_manager_tests.cpp index ef0b1bb8a2..56702c3ef8 100644 --- a/unit_tests/memory_manager/memory_manager_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_tests.cpp @@ -197,7 +197,7 @@ TEST_F(MemoryAllocatorTest, allocateGraphics) { unsigned int alignment = 4096; memoryManager->createAndRegisterOsContext(gpgpuEngineInstances[0], PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0])); - auto allocation = memoryManager->allocateGraphicsMemory(sizeof(char)); + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, allocation); // initial taskCount must be -1. if not, we may kill allocation before it will be used @@ -215,7 +215,7 @@ TEST_F(MemoryAllocatorTest, allocateGraphics) { TEST_F(MemoryAllocatorTest, allocateGraphicsPageAligned) { unsigned int alignment = 4096; - auto allocation = memoryManager->allocateGraphicsMemory(sizeof(char)); + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); EXPECT_NE(nullptr, allocation); EXPECT_EQ(0u, reinterpret_cast(allocation->getUnderlyingBuffer()) & (alignment - 1)); memoryManager->freeGraphicsMemory(allocation); @@ -573,7 +573,7 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerAndUnifiedAuxCapableAlloc OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); auto gmm = new Gmm(nullptr, 123, false); - auto allocation = memoryManager.allocateGraphicsMemory(123); + auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); allocation->gmm = gmm; auto mockGmmRes = reinterpret_cast(gmm->gmmResourceInfo.get()); @@ -589,14 +589,7 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryIsCall OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); auto size = 4096u; - auto allocation = memoryManager.allocateGraphicsMemory(size); - EXPECT_NE(nullptr, allocation); - EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); - memoryManager.freeGraphicsMemory(allocation); - - AllocationProperties properties(true, size); - properties.alignment = MemoryConstants::preferredAlignment; - allocation = memoryManager.allocateGraphicsMemoryWithProperties(properties); + auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{size}); EXPECT_NE(nullptr, allocation); EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); memoryManager.freeGraphicsMemory(allocation); @@ -765,7 +758,7 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenCreateAllocationFromNtHandle TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenLockUnlockCalledThenReturnCpuPtr) { ExecutionEnvironment executionEnvironment; OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); - auto allocation = memoryManager.allocateGraphicsMemory(1); + auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, allocation); auto ptr = memoryManager.lockResource(allocation); @@ -779,7 +772,7 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenGraphicsAllocationCon ExecutionEnvironment executionEnvironment; OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); - auto graphicsAllocation = memoryManager.allocateGraphicsMemory(4096u); + auto graphicsAllocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); auto graphicsAddress = graphicsAllocation->getGpuAddress(); auto graphicsAddressToPatch = graphicsAllocation->getGpuAddressToPatch(); @@ -798,7 +791,7 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenGraphicsAllocationCon TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenGraphicsAllocationIsPaddedThenNewGraphicsAllocationIsCreated) { ExecutionEnvironment executionEnvironment; OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); - auto graphicsAllocation = memoryManager.allocateGraphicsMemory(4096u); + auto graphicsAllocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); auto sizeWithPadding = 8192; auto paddedGraphicsAllocation = memoryManager.createGraphicsAllocationWithPadding(graphicsAllocation, sizeWithPadding); @@ -817,7 +810,7 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenGraphicsAllocationIsP TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenTwoGraphicsAllocationArePaddedThenOnlyOnePaddingBufferIsUsed) { ExecutionEnvironment executionEnvironment; OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); - auto graphicsAllocation = memoryManager.allocateGraphicsMemory(4096u); + auto graphicsAllocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); auto sizeWithPadding = 8192; auto paddedGraphicsAllocation = memoryManager.createGraphicsAllocationWithPadding(graphicsAllocation, sizeWithPadding); @@ -841,7 +834,7 @@ TEST(OsAgnosticMemoryManager, pleaseDetectLeak) { TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocateMemoryWithNoAlignmentProvidedThenAllocationIsAlignedToPageSize) { ExecutionEnvironment executionEnvironment; OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); - AllocationProperties properties(true, MemoryConstants::pageSize >> 1); + MockAllocationProperties properties(MemoryConstants::pageSize >> 1); properties.alignment = 0; auto ga = memoryManager.allocateGraphicsMemoryWithProperties(properties); uintptr_t ptr = reinterpret_cast(ga->getUnderlyingBuffer()); @@ -854,7 +847,7 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocateMemoryWithNoAlignmen TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocateMemoryWithAlignmentNotAlignedToPageSizeThenAlignmentIsAlignedUp) { ExecutionEnvironment executionEnvironment; OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); - AllocationProperties properties(true, MemoryConstants::pageSize >> 1); + MockAllocationProperties properties(MemoryConstants::pageSize >> 1); properties.alignment = MemoryConstants::pageSize - 1; auto ga = memoryManager.allocateGraphicsMemoryWithProperties(properties); uintptr_t ptr = reinterpret_cast(ga->getUnderlyingBuffer()); @@ -961,11 +954,11 @@ TEST(OsAgnosticMemoryManager, GivenEnabled64kbPagesWhenHostMemoryAllocationIsCre ExecutionEnvironment executionEnvironment; OsAgnosticMemoryManager memoryManager(true, false, executionEnvironment); - GraphicsAllocation *galloc = memoryManager.allocateGraphicsMemoryInPreferredPool(AllocationProperties(true, 64 * 1024), 0, nullptr, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY); + GraphicsAllocation *galloc = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize64k, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY}); EXPECT_NE(nullptr, galloc); memoryManager.freeGraphicsMemory(galloc); - galloc = memoryManager.allocateGraphicsMemoryInPreferredPool(AllocationProperties(true, 64 * 1024), 0, nullptr, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY); + galloc = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize64k, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY}); EXPECT_NE(nullptr, galloc); EXPECT_NE(nullptr, galloc->getUnderlyingBuffer()); EXPECT_EQ(0u, (uintptr_t)galloc->getUnderlyingBuffer() % MemoryConstants::pageSize64k); @@ -1177,13 +1170,13 @@ TEST_F(MemoryManagerWithCsrTest, GivenAllocationsInHostPtrManagerReadyForCleanin } TEST_F(MemoryManagerWithCsrTest, givenAllocationThatWasNotUsedWhencheckGpuUsageAndDestroyGraphicsAllocationsIsCalledThenItIsDestroyedInPlace) { - auto notUsedAllocation = memoryManager->allocateGraphicsMemory(4096); + auto notUsedAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); memoryManager->checkGpuUsageAndDestroyGraphicsAllocations(notUsedAllocation); EXPECT_TRUE(csr->getTemporaryAllocations().peekIsEmpty()); } TEST_F(MemoryManagerWithCsrTest, givenAllocationThatWasUsedAndIsCompletedWhencheckGpuUsageAndDestroyGraphicsAllocationsIsCalledThenItIsDestroyedInPlace) { - auto usedAllocationButGpuCompleted = memoryManager->allocateGraphicsMemory(4096); + auto usedAllocationButGpuCompleted = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); auto tagAddress = csr->getTagAddress(); ASSERT_NE(0u, *tagAddress); @@ -1196,7 +1189,7 @@ TEST_F(MemoryManagerWithCsrTest, givenAllocationThatWasUsedAndIsCompletedWhenche TEST_F(MemoryManagerWithCsrTest, givenAllocationThatWasUsedAndIsNotCompletedWhencheckGpuUsageAndDestroyGraphicsAllocationsIsCalledThenItIsAddedToTemporaryAllocationList) { memoryManager->createAndRegisterOsContext(gpgpuEngineInstances[0], PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0])); - auto usedAllocationAndNotGpuCompleted = memoryManager->allocateGraphicsMemory(4096); + auto usedAllocationAndNotGpuCompleted = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); auto tagAddress = csr->getTagAddress(); @@ -1368,7 +1361,7 @@ HWTEST_F(GraphicsAllocationTests, givenAllocationUsedByNonDefaultCsrWhenChecking defaultOsContext->getEngineType().type == nonDefaultOsContext->getEngineType().type); auto memoryManager = device->getExecutionEnvironment()->memoryManager.get(); - auto graphicsAllocation = memoryManager->allocateGraphicsMemory(1); + auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); nonDefaultCsr->taskCount = *nonDefaultCsr->getTagAddress() + 1; nonDefaultCsr->latestFlushedTaskCount = *nonDefaultCsr->getTagAddress() + 1; diff --git a/unit_tests/mocks/CMakeLists.txt b/unit_tests/mocks/CMakeLists.txt index 415c7c8a34..57e940ea2e 100644 --- a/unit_tests/mocks/CMakeLists.txt +++ b/unit_tests/mocks/CMakeLists.txt @@ -7,6 +7,7 @@ set(IGDRCL_SRCS_tests_mocks ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/mock_32bitAllocator.h + ${CMAKE_CURRENT_SOURCE_DIR}/mock_allocation_properties.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_async_event_handler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_async_event_handler.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_aub_center.h diff --git a/unit_tests/mocks/linux/mock_drm_memory_manager.h b/unit_tests/mocks/linux/mock_drm_memory_manager.h index e65d38391b..05d0e9b1dd 100644 --- a/unit_tests/mocks/linux/mock_drm_memory_manager.h +++ b/unit_tests/mocks/linux/mock_drm_memory_manager.h @@ -36,6 +36,7 @@ int closeMock(int) { class TestedDrmMemoryManager : public DrmMemoryManager { public: + using DrmMemoryManager::allocateGraphicsMemory; using DrmMemoryManager::allocateGraphicsMemory64kb; using DrmMemoryManager::allocateGraphicsMemoryWithHostPtr; using DrmMemoryManager::AllocationData; diff --git a/unit_tests/mocks/mock_allocation_properties.h b/unit_tests/mocks/mock_allocation_properties.h new file mode 100644 index 0000000000..2b20e31886 --- /dev/null +++ b/unit_tests/mocks/mock_allocation_properties.h @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2018 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once +#include "runtime/memory_manager/memory_manager.h" + +namespace OCLRT { +struct MockAllocationProperties : public AllocationProperties { + public: + using AllocationProperties::AllocationProperties; + + MockAllocationProperties(size_t size) : AllocationProperties(size, GraphicsAllocation::AllocationType::UNDECIDED) {} + MockAllocationProperties(bool allocateMemory, size_t size) : AllocationProperties(allocateMemory, size, GraphicsAllocation::AllocationType::UNDECIDED) {} +}; +} // namespace OCLRT diff --git a/unit_tests/mocks/mock_aub_csr.h b/unit_tests/mocks/mock_aub_csr.h index b3d833bae8..34b6141259 100644 --- a/unit_tests/mocks/mock_aub_csr.h +++ b/unit_tests/mocks/mock_aub_csr.h @@ -160,7 +160,7 @@ std::unique_ptr getEnvironment(bool createTagAllocation std::unique_ptr aubExecutionEnvironment(new AubExecutionEnvironment); if (allocateCommandBuffer) { - aubExecutionEnvironment->commandBuffer = executionEnvironment->memoryManager->allocateGraphicsMemory(4096); + aubExecutionEnvironment->commandBuffer = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); } aubExecutionEnvironment->executionEnvironment = std::move(executionEnvironment); return aubExecutionEnvironment; diff --git a/unit_tests/mocks/mock_device.h b/unit_tests/mocks/mock_device.h index b501a118b9..27fa614055 100644 --- a/unit_tests/mocks/mock_device.h +++ b/unit_tests/mocks/mock_device.h @@ -8,6 +8,7 @@ #pragma once #include "runtime/device/device.h" #include "unit_tests/libult/ult_command_stream_receiver.h" +#include "unit_tests/mocks/mock_allocation_properties.h" namespace OCLRT { class OSTime; @@ -95,7 +96,7 @@ class MockDevice : public Device { void allocatePreemptionAllocationIfNotPresent() { if (this->preemptionAllocation == nullptr) { if (preemptionMode == PreemptionMode::MidThread || isSourceLevelDebuggerActive()) { - AllocationProperties allocationProperties(true, hwInfo.capabilityTable.requiredPreemptionSurfaceSize); + MockAllocationProperties allocationProperties(hwInfo.capabilityTable.requiredPreemptionSurfaceSize); allocationProperties.flags.uncacheable = getWaTable()->waCSRUncachable; allocationProperties.alignment = 256 * MemoryConstants::kiloByte; this->preemptionAllocation = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(allocationProperties); diff --git a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp index 1626482fc9..bfc88ec342 100644 --- a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp +++ b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp @@ -621,7 +621,7 @@ TEST_F(DrmCommandStreamGemWorkerTests, givenDefaultDrmCSRWhenItIsCreatedThenGemC } TEST_F(DrmCommandStreamGemWorkerTests, givenCommandStreamWhenItIsFlushedWithGemCloseWorkerInDefaultModeThenWorkerDecreasesTheRefCount) { - auto commandBuffer = mm->allocateGraphicsMemory(static_cast(1024)); + auto commandBuffer = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); @@ -654,11 +654,11 @@ TEST_F(DrmCommandStreamGemWorkerTests, givenTaskThatRequiresLargeResourceCountWh execStorage.resize(0); for (auto id = 0; id < 10; id++) { - auto graphicsAllocation = mm->allocateGraphicsMemory(1); + auto graphicsAllocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); csr->makeResident(*graphicsAllocation); graphicsAllocations.push_back(graphicsAllocation); } - auto commandBuffer = mm->allocateGraphicsMemory(1024); + auto commandBuffer = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); LinearStream cs(commandBuffer); @@ -676,7 +676,7 @@ TEST_F(DrmCommandStreamGemWorkerTests, givenTaskThatRequiresLargeResourceCountWh } TEST_F(DrmCommandStreamGemWorkerTests, givenGemCloseWorkerInactiveModeWhenMakeResidentIsCalledThenRefCountsAreNotUpdated) { - auto dummyAllocation = static_cast(mm->allocateGraphicsMemory(1024)); + auto dummyAllocation = static_cast(mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize})); auto bo = dummyAllocation->getBO(); EXPECT_EQ(1u, bo->getRefCount()); @@ -693,8 +693,8 @@ TEST_F(DrmCommandStreamGemWorkerTests, givenGemCloseWorkerInactiveModeWhenMakeRe } TEST_F(DrmCommandStreamGemWorkerTests, GivenTwoAllocationsWhenBackingStorageIsDifferentThenMakeResidentShouldAddTwoLocations) { - auto allocation = static_cast(mm->allocateGraphicsMemory(1024)); - auto allocation2 = static_cast(mm->allocateGraphicsMemory(1024)); + auto allocation = static_cast(mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize})); + auto allocation2 = static_cast(mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize})); csr->makeResident(*allocation); csr->makeResident(*allocation2); @@ -723,8 +723,8 @@ TEST_F(DrmCommandStreamGemWorkerTests, GivenTwoAllocationsWhenBackingStorageIsDi } TEST_F(DrmCommandStreamGemWorkerTests, givenCommandStreamWithDuplicatesWhenItIsFlushedWithGemCloseWorkerInactiveModeThenCsIsNotNulled) { - auto commandBuffer = static_cast(mm->allocateGraphicsMemory(1024)); - auto dummyAllocation = static_cast(mm->allocateGraphicsMemory(1024)); + auto commandBuffer = static_cast(mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize})); + auto dummyAllocation = static_cast(mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize})); ASSERT_NE(nullptr, commandBuffer); ASSERT_EQ(0u, reinterpret_cast(commandBuffer->getUnderlyingBuffer()) & 0xFFF); LinearStream cs(commandBuffer); @@ -768,7 +768,7 @@ class DrmCommandStreamBatchingTests : public TestgetAllocation(); - GlobalMockSipProgram::sipProgram->resetAllocation(device->getMemoryManager()->allocateGraphicsMemory(1024)); + GlobalMockSipProgram::sipProgram->resetAllocation(device->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize})); } tagAllocation = static_cast(device->getDefaultEngine().commandStreamReceiver->getTagAllocation()); preemptionAllocation = static_cast(device->getPreemptionAllocation()); @@ -784,8 +784,8 @@ class DrmCommandStreamBatchingTests : public Testreset(); - auto commandBuffer = mm->allocateGraphicsMemory(1024); - auto dummyAllocation = mm->allocateGraphicsMemory(1024); + auto commandBuffer = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + auto dummyAllocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, commandBuffer); ASSERT_EQ(0u, reinterpret_cast(commandBuffer->getUnderlyingBuffer()) & 0xFFF); LinearStream cs(commandBuffer); @@ -819,8 +819,8 @@ TEST_F(DrmCommandStreamBatchingTests, givenCsrWhenDispatchPolicyIsSetToBatchingT auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); tCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); - auto commandBuffer = mm->allocateGraphicsMemory(1024); - auto dummyAllocation = mm->allocateGraphicsMemory(1024); + auto commandBuffer = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + auto dummyAllocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, commandBuffer); ASSERT_EQ(0u, reinterpret_cast(commandBuffer->getUnderlyingBuffer()) & 0xFFF); IndirectHeap cs(commandBuffer); @@ -876,7 +876,7 @@ TEST_F(DrmCommandStreamBatchingTests, givenRecordedCommandBufferWhenItIsSubmitte auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); tCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); - auto commandBuffer = mm->allocateGraphicsMemory(1024); + auto commandBuffer = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); IndirectHeap cs(commandBuffer); tCsr->setTagAllocation(tagAllocation); @@ -1288,8 +1288,8 @@ TEST_F(DrmCommandStreamLeaksTest, Flush) { } TEST_F(DrmCommandStreamLeaksTest, ClearResidencyWhenFlushNotCalled) { - auto allocation1 = static_cast(mm->allocateGraphicsMemory(1024)); - auto allocation2 = static_cast(mm->allocateGraphicsMemory(1024)); + auto allocation1 = static_cast(mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize})); + auto allocation2 = static_cast(mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize})); ASSERT_NE(nullptr, allocation1); ASSERT_NE(nullptr, allocation2); @@ -1335,9 +1335,9 @@ TEST_F(DrmCommandStreamLeaksTest, FlushMultipleTimes) { BatchBuffer batchBuffer2{cs.getGraphicsAllocation(), 8, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; csr->flush(batchBuffer2, csr->getResidencyAllocations()); - auto allocation = mm->allocateGraphicsMemory(1024); + auto allocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, allocation); - auto allocation2 = mm->allocateGraphicsMemory(1024); + auto allocation2 = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, allocation2); csr->makeResident(*allocation); @@ -1345,7 +1345,7 @@ TEST_F(DrmCommandStreamLeaksTest, FlushMultipleTimes) { csr->getInternalAllocationStorage()->storeAllocation(std::unique_ptr(commandBuffer), REUSABLE_ALLOCATION); - auto commandBuffer2 = mm->allocateGraphicsMemory(1024); + auto commandBuffer2 = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, commandBuffer2); cs.replaceBuffer(commandBuffer2->getUnderlyingBuffer(), commandBuffer2->getUnderlyingBufferSize()); cs.replaceGraphicsAllocation(commandBuffer2); @@ -1358,7 +1358,7 @@ TEST_F(DrmCommandStreamLeaksTest, FlushMultipleTimes) { mm->freeGraphicsMemory(allocation2); csr->getInternalAllocationStorage()->storeAllocation(std::unique_ptr(commandBuffer2), REUSABLE_ALLOCATION); - commandBuffer2 = mm->allocateGraphicsMemory(1024); + commandBuffer2 = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, commandBuffer2); cs.replaceBuffer(commandBuffer2->getUnderlyingBuffer(), commandBuffer2->getUnderlyingBufferSize()); cs.replaceGraphicsAllocation(commandBuffer2); @@ -1416,7 +1416,7 @@ TEST_F(DrmCommandStreamLeaksTest, CheckDrmFree) { ASSERT_NE(0u, (reinterpret_cast(commandBuffer->getUnderlyingBuffer()) + 4) & 0xFFF); ASSERT_EQ(4u, (reinterpret_cast(commandBuffer->getUnderlyingBuffer()) + 4) & 0x7F); - auto allocation = mm->allocateGraphicsMemory(1024); + auto allocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); csr->makeResident(*allocation); csr->addBatchBufferEnd(cs, nullptr); @@ -1428,8 +1428,8 @@ TEST_F(DrmCommandStreamLeaksTest, CheckDrmFree) { } TEST_F(DrmCommandStreamLeaksTest, MakeResidentClearResidencyAllocationsInCommandStreamReceiver) { - auto allocation1 = mm->allocateGraphicsMemory(1024); - auto allocation2 = mm->allocateGraphicsMemory(1024); + auto allocation1 = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + auto allocation2 = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, allocation1); ASSERT_NE(nullptr, allocation2); @@ -1447,7 +1447,7 @@ TEST_F(DrmCommandStreamLeaksTest, MakeResidentClearResidencyAllocationsInCommand } TEST_F(DrmCommandStreamLeaksTest, givenMultipleMakeResidentWhenMakeNonResidentIsCalledOnlyOnceThenSurfaceIsMadeNonResident) { - auto allocation1 = mm->allocateGraphicsMemory(1024); + auto allocation1 = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, allocation1); @@ -1466,7 +1466,7 @@ TEST_F(DrmCommandStreamLeaksTest, givenMultipleMakeResidentWhenMakeNonResidentIs } TEST_F(DrmCommandStreamLeaksTest, makeNonResidentOnMemObjectCallsDrmCSMakeNonResidentWithGraphicsAllocation) { - auto allocation1 = mm->allocateGraphicsMemory(0x1000); + auto allocation1 = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{0x1000}); ASSERT_NE(nullptr, allocation1); tCsr->makeResident(*allocation1); diff --git a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp index 0a46ae0ec0..2d44fa81a1 100644 --- a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp @@ -48,7 +48,7 @@ using namespace OCLRT; AllocationProperties createAllocationProperties(size_t size, bool forcePin) { - AllocationProperties properties(true, size); + MockAllocationProperties properties(size); properties.alignment = MemoryConstants::preferredAlignment; properties.flags.forcePin = forcePin; return properties; @@ -371,7 +371,7 @@ TEST_F(DrmMemoryManagerTest, AllocateThenFree) { mock->ioctl_expected.gemWait = 1; mock->ioctl_expected.gemClose = 1; - auto alloc = static_cast(memoryManager->allocateGraphicsMemory(1024)); + auto alloc = static_cast(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize})); ASSERT_NE(nullptr, alloc); EXPECT_NE(nullptr, alloc->getBO()); @@ -383,7 +383,7 @@ TEST_F(DrmMemoryManagerTest, AllocateNewFail) { mock->ioctl_expected.total = -1; //don't care InjectedFunction method = [this](size_t failureIndex) { - auto ptr = memoryManager->allocateGraphicsMemory(1024); + auto ptr = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); if (nonfailingAllocation != failureIndex) { EXPECT_EQ(nullptr, ptr); @@ -400,7 +400,7 @@ TEST_F(DrmMemoryManagerTest, Allocate0Bytes) { mock->ioctl_expected.gemWait = 1; mock->ioctl_expected.gemClose = 1; - auto ptr = memoryManager->allocateGraphicsMemory(static_cast(0)); + auto ptr = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{0u}); ASSERT_NE(nullptr, ptr); EXPECT_NE(nullptr, ptr->getUnderlyingBuffer()); @@ -412,7 +412,7 @@ TEST_F(DrmMemoryManagerTest, Allocate3Bytes) { mock->ioctl_expected.gemWait = 1; mock->ioctl_expected.gemClose = 1; - auto ptr = memoryManager->allocateGraphicsMemory(3); + auto ptr = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, ptr); EXPECT_NE(nullptr, ptr->getUnderlyingBuffer()); @@ -423,7 +423,7 @@ TEST_F(DrmMemoryManagerTest, AllocateUserptrFail) { mock->ioctl_expected.gemUserptr = 1; mock->ioctl_res = -1; - auto ptr = memoryManager->allocateGraphicsMemory(3); + auto ptr = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); EXPECT_EQ(nullptr, ptr); mock->ioctl_res = 0; } @@ -1693,7 +1693,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenLockUnlockIsCalledThenRetu mock->ioctl_expected.gemWait = 1; mock->ioctl_expected.gemClose = 1; - auto allocation = memoryManager->allocateGraphicsMemory(1); + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, allocation); auto ptr = memoryManager->lockResource(allocation); @@ -1709,7 +1709,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenLockUnlockIsCalledOnAlloca mock->ioctl_expected.gemWait = 1; mock->ioctl_expected.gemClose = 1; - auto allocation = memoryManager->allocateGraphicsMemory(1); + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, allocation); EXPECT_NE(nullptr, allocation->getUnderlyingBuffer()); @@ -1866,7 +1866,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndUnifiedAuxCapableAllocation mock->ioctl_expected.gemClose = 1; auto gmm = new Gmm(nullptr, 123, false); - auto allocation = memoryManager->allocateGraphicsMemory(123); + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); allocation->gmm = gmm; auto mockGmmRes = reinterpret_cast(gmm->gmmResourceInfo.get()); @@ -1940,7 +1940,7 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerSupportingVirutalPaddingWhenItIsR mock->ioctl_expected.gemClose = 3; //first let's create normal buffer auto bufferSize = MemoryConstants::pageSize; - auto buffer = memoryManager->allocateGraphicsMemory(bufferSize); + auto buffer = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{bufferSize}); //buffer should have size 16 EXPECT_EQ(bufferSize, buffer->getUnderlyingBufferSize()); @@ -2054,7 +2054,7 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerSupportingVirutalPaddingWhenAlloc //first let's create normal buffer auto bufferSize = MemoryConstants::pageSize; - auto buffer = memoryManager->allocateGraphicsMemory(bufferSize); + auto buffer = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{bufferSize}); //buffer should have size 16 EXPECT_EQ(bufferSize, buffer->getUnderlyingBufferSize()); @@ -2414,14 +2414,8 @@ TEST(DrmMemoryManager, givenEnabledHostMemoryValidationAndForcePinWhenMemoryMana TEST(DrmMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryIsCalledThenMemoryPoolIsSystem4KBPages) { ExecutionEnvironment executionEnvironment; std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true, executionEnvironment)); - auto size = 4096u; - auto allocation = memoryManager->allocateGraphicsMemory(size); - EXPECT_NE(nullptr, allocation); - EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); - memoryManager->freeGraphicsMemory(allocation); - - allocation = memoryManager->allocateGraphicsMemoryWithProperties(createAllocationProperties(size, false)); + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(createAllocationProperties(MemoryConstants::pageSize, false)); EXPECT_NE(nullptr, allocation); EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); memoryManager->freeGraphicsMemory(allocation); 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 1c3dcd1db3..f295d2cf2b 100644 --- a/unit_tests/os_interface/windows/device_command_stream_tests.cpp +++ b/unit_tests/os_interface/windows/device_command_stream_tests.cpp @@ -134,7 +134,7 @@ class WddmCommandStreamWithMockGdiFixture { ASSERT_NE(nullptr, device); this->csr->overrideRecorededCommandBuffer(*device); if (device->getPreemptionMode() == PreemptionMode::MidThread) { - preemptionAllocation = memoryManager->allocateGraphicsMemory(1024); + preemptionAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); } } @@ -182,7 +182,7 @@ TEST_F(WddmCommandStreamTest, givenFlushStampWhenWaitCalledThenWaitForSpecifiedM } TEST_F(WddmCommandStreamTest, Flush) { - GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); + 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}; @@ -196,7 +196,7 @@ TEST_F(WddmCommandStreamTest, Flush) { } TEST_F(WddmCommandStreamTest, givenGraphicsAllocationWithDifferentGpuAddressThenCpuAddressWhenSubmitIsCalledThenGpuAddressIsUsed) { - GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); auto cpuAddress = commandBuffer->getUnderlyingBuffer(); uint64_t mockGpuAddres = 1337; @@ -210,7 +210,7 @@ TEST_F(WddmCommandStreamTest, givenGraphicsAllocationWithDifferentGpuAddressThen } TEST_F(WddmCommandStreamTest, FlushWithOffset) { auto offset = 128u; - GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); @@ -224,7 +224,7 @@ TEST_F(WddmCommandStreamTest, FlushWithOffset) { } TEST_F(WddmCommandStreamTest, givenWdmmWhenSubmitIsCalledThenCoherencyRequiredFlagIsSetToFalse) { - GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); @@ -252,7 +252,7 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOf OsContext osContext(executionEnvironment->osInterface.get(), 0u, gpgpuEngineInstances[0], PreemptionHelper::getDefaultPreemptionMode(*hwInfo)); executionEnvironment->commandStreamReceivers[0][0]->setOsContext(osContext); - auto commandBuffer = executionEnvironment->memoryManager->allocateGraphicsMemory(4096); + auto commandBuffer = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; @@ -277,7 +277,7 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOn OsContext osContext(executionEnvironment->osInterface.get(), 0u, gpgpuEngineInstances[0], PreemptionHelper::getDefaultPreemptionMode(*hwInfo)); executionEnvironment->commandStreamReceivers[0][0]->setOsContext(osContext); - auto commandBuffer = executionEnvironment->memoryManager->allocateGraphicsMemory(4096); + auto commandBuffer = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; @@ -311,7 +311,7 @@ TEST(WddmPreemptionHeaderTests, givenDevicenotSupportingPreemptionWhenCommandStr } TEST_F(WddmCommandStreamTest, givenWdmmWhenSubmitIsCalledAndThrottleIsToLowThenSetHeaderFieldsProperly) { - GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); @@ -329,7 +329,7 @@ TEST_F(WddmCommandStreamTest, givenWdmmWhenSubmitIsCalledAndThrottleIsToLowThenS } TEST_F(WddmCommandStreamTest, givenWdmmWhenSubmitIsCalledAndThrottleIsToMediumThenSetHeaderFieldsProperly) { - GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); @@ -347,7 +347,7 @@ TEST_F(WddmCommandStreamTest, givenWdmmWhenSubmitIsCalledAndThrottleIsToMediumTh } TEST_F(WddmCommandStreamTest, givenWdmmWhenSubmitIsCalledAndThrottleIsToHighThenSetHeaderFieldsProperly) { - GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); @@ -365,12 +365,12 @@ TEST_F(WddmCommandStreamTest, givenWdmmWhenSubmitIsCalledAndThrottleIsToHighThen } TEST_F(WddmCommandStreamTest, givenWddmWithKmDafDisabledWhenFlushIsCalledWithAllocationsForResidencyThenNoneAllocationShouldBeKmDafLocked) { - GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); + 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 linearStreamAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); + auto linearStreamAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, linearStreamAllocation); linearStreamAllocation->setAllocationType(GraphicsAllocation::AllocationType::LINEAR_STREAM); ResidencyContainer allocationsForResidency = {linearStreamAllocation}; @@ -386,7 +386,7 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafDisabledWhenFlushIsCalledWithAll } TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithoutAllocationsForResidencyThenNoneAllocationShouldBeKmDafLocked) { - GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); + 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}; @@ -401,12 +401,12 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithoutA } TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithResidencyAllocationsInMemoryManagerThenLinearStreamAllocationsShouldBeKmDafLocked) { - GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); + 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 linearStreamAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); + auto linearStreamAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, linearStreamAllocation); linearStreamAllocation->setAllocationType(GraphicsAllocation::AllocationType::LINEAR_STREAM); @@ -426,12 +426,12 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithResi } TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllocationsForResidencyThenLinearStreamAllocationsShouldBeKmDafLocked) { - GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); + 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 linearStreamAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); + auto linearStreamAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, linearStreamAllocation); linearStreamAllocation->setAllocationType(GraphicsAllocation::AllocationType::LINEAR_STREAM); ResidencyContainer allocationsForResidency = {linearStreamAllocation}; @@ -448,12 +448,12 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllo } TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllocationsForResidencyThenFillPatternAllocationsShouldBeKmDafLocked) { - GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); + 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 fillPatternAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); + auto fillPatternAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, fillPatternAllocation); fillPatternAllocation->setAllocationType(GraphicsAllocation::AllocationType::FILL_PATTERN); ResidencyContainer allocationsForResidency = {fillPatternAllocation}; @@ -470,12 +470,12 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllo } TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllocationsForResidencyThenNonLinearStreamAllocationShouldNotBeKmDafLocked) { - GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); + 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 nonLinearStreamAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); + auto nonLinearStreamAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, nonLinearStreamAllocation); ResidencyContainer allocationsForResidency = {nonLinearStreamAllocation}; @@ -492,7 +492,7 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllo TEST_F(WddmCommandStreamTest, makeResident) { WddmMemoryManager *wddmMM = reinterpret_cast(memoryManager); - GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); @@ -508,7 +508,7 @@ TEST_F(WddmCommandStreamTest, makeResident) { TEST_F(WddmCommandStreamTest, makeNonResidentPutsAllocationInEvictionAllocations) { WddmMemoryManager *wddmMM = reinterpret_cast(memoryManager); - GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); @@ -524,8 +524,8 @@ TEST_F(WddmCommandStreamTest, makeNonResidentPutsAllocationInEvictionAllocations TEST_F(WddmCommandStreamTest, processEvictionPlacesAllAllocationsOnTrimCandidateList) { WddmMemoryManager *wddmMM = reinterpret_cast(memoryManager); - GraphicsAllocation *allocation = memoryManager->allocateGraphicsMemory(4096); - GraphicsAllocation *allocation2 = memoryManager->allocateGraphicsMemory(4096); + GraphicsAllocation *allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + GraphicsAllocation *allocation2 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, allocation); ASSERT_NE(nullptr, allocation2); @@ -545,7 +545,7 @@ TEST_F(WddmCommandStreamTest, processEvictionPlacesAllAllocationsOnTrimCandidate TEST_F(WddmCommandStreamTest, processEvictionClearsEvictionAllocations) { WddmMemoryManager *wddmMM = reinterpret_cast(memoryManager); - GraphicsAllocation *allocation = memoryManager->allocateGraphicsMemory(4096); + GraphicsAllocation *allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, allocation); csr->getEvictionAllocations().push_back(allocation); @@ -560,7 +560,7 @@ TEST_F(WddmCommandStreamTest, processEvictionClearsEvictionAllocations) { } TEST_F(WddmCommandStreamTest, makeResidentNonResidentMemObj) { - GraphicsAllocation *gfxAllocation = memoryManager->allocateGraphicsMemory(256); + GraphicsAllocation *gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); Buffer *buffer = new AlignedBuffer(gfxAllocation); WddmMemoryManager *wddmMM = reinterpret_cast(memoryManager); @@ -645,7 +645,7 @@ TEST_F(WddmCommandStreamTest, givenTwoTemporaryAllocationsWhenCleanTemporaryAllo } TEST_F(WddmCommandStreamMockGdiTest, FlushCallsWddmMakeResidentForResidencyAllocations) { - GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); @@ -664,7 +664,7 @@ TEST_F(WddmCommandStreamMockGdiTest, FlushCallsWddmMakeResidentForResidencyAlloc } TEST_F(WddmCommandStreamMockGdiTest, makeResidentClearsResidencyAllocations) { - GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); @@ -694,7 +694,7 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt if (device->getPreemptionMode() == PreemptionMode::MidThread) { csrSurfaceCount = 2; tmpAllocation = GlobalMockSipProgram::sipProgram->getAllocation(); - GlobalMockSipProgram::sipProgram->resetAllocation(memoryManager->allocateGraphicsMemory(1024)); + GlobalMockSipProgram::sipProgram->resetAllocation(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize})); } csr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); @@ -702,10 +702,10 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); csr->overrideSubmissionAggregator(mockedSubmissionsAggregator); - auto commandBuffer = memoryManager->allocateGraphicsMemory(1024); - auto dshAlloc = memoryManager->allocateGraphicsMemory(1024); - auto iohAlloc = memoryManager->allocateGraphicsMemory(1024); - auto sshAlloc = memoryManager->allocateGraphicsMemory(1024); + auto commandBuffer = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + auto dshAlloc = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + auto iohAlloc = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + auto sshAlloc = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); auto tagAllocation = csr->getTagAllocation(); csr->setPreemptionCsrAllocation(preemptionAllocation); @@ -890,7 +890,7 @@ HWTEST_F(WddmCsrCompressionTests, givenEnabledCompressionWhenFlushingThenInitTra auto &csrCS = mockWddmCsr->getCS(); - auto graphicsAllocation = memoryManager->allocateGraphicsMemory(1024); + auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); IndirectHeap cs(graphicsAllocation); EXPECT_FALSE(mockWddmCsr->pageTableManagerInitialized); @@ -931,7 +931,7 @@ HWTEST_F(WddmCsrCompressionTests, givenDisabledCompressionWhenFlushingThenDontIn EXPECT_EQ(nullptr, myMockWddm->getPageTableManager()); - auto graphicsAllocation = memoryManager->allocateGraphicsMemory(1024); + auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); IndirectHeap cs(graphicsAllocation); EXPECT_FALSE(mockWddmCsr->pageTableManagerInitialized); diff --git a/unit_tests/os_interface/windows/mock_wddm_memory_manager.h b/unit_tests/os_interface/windows/mock_wddm_memory_manager.h index f631b5fc1d..4fe5807c69 100644 --- a/unit_tests/os_interface/windows/mock_wddm_memory_manager.h +++ b/unit_tests/os_interface/windows/mock_wddm_memory_manager.h @@ -15,6 +15,7 @@ class MockWddmMemoryManager : public WddmMemoryManager { using BaseClass = WddmMemoryManager; public: + using BaseClass::allocateGraphicsMemory; using BaseClass::allocateGraphicsMemory64kb; using BaseClass::createWddmAllocation; using BaseClass::WddmMemoryManager; diff --git a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp index c63c49ce34..2d191f2fa7 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp @@ -114,9 +114,8 @@ TEST(WddmMemoryManagerWithDeferredDeleterTest, givenWMMWhenAsyncDeleterIsEnabled TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemoryIsCalledThenMemoryPoolIsSystem4KBPages) { memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, executionEnvironment)); - auto size = 4096u; - auto allocation = memoryManager->allocateGraphicsMemory(size); + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); EXPECT_NE(nullptr, allocation); EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); EXPECT_TRUE(allocation->gmm->useSystemMemoryPool); @@ -225,12 +224,6 @@ TEST_F(WddmMemoryManagerTest, memoryManager->freeGraphicsMemory(allocation); } -TEST_F(WddmMemoryManagerTest, AllocateAndFree) { - auto *ptr = memoryManager->allocateGraphicsMemory(0x1000); - EXPECT_NE(nullptr, ptr); - memoryManager->freeGraphicsMemory(ptr); -} - TEST_F(WddmMemoryManagerTest, givenDefaultWddmMemoryManagerWhenAskedForVirtualPaddingSupportThenFalseIsReturned) { EXPECT_FALSE(memoryManager->peekVirtualPaddingSupport()); } @@ -288,7 +281,7 @@ TEST_F(WddmMemoryManagerTest, AllocateGpuMemHostPtr) { } TEST_F(WddmMemoryManagerTest, givenDefaultMemoryManagerWhenAllocateWithSizeIsCalledThenResourceHandleIsZero) { - auto *gpuAllocation = memoryManager->allocateGraphicsMemory(0x1000); + auto *gpuAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); auto wddmAllocation = static_cast(gpuAllocation); @@ -331,7 +324,7 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromNTHandleIsCall } TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenLockUnlockIsCalledThenReturnPtr) { - auto alloc = memoryManager->allocateGraphicsMemory(1); + auto alloc = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); auto ptr = memoryManager->lockResource(alloc); EXPECT_NE(nullptr, ptr); @@ -1151,7 +1144,7 @@ TEST_F(MockWddmMemoryManagerTest, givenEnabled64kbpagesWhenCreatingGraphicsMemor WddmMemoryManager memoryManager64k(true, false, wddm.get(), executionEnvironment); EXPECT_EQ(0, wddm->createAllocationResult.called); - GraphicsAllocation *galloc = memoryManager64k.allocateGraphicsMemoryInPreferredPool(AllocationProperties(true, MemoryConstants::pageSize64k), 0, nullptr, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY); + GraphicsAllocation *galloc = memoryManager64k.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize64k, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY}); EXPECT_EQ(1, wddm->createAllocationResult.called); EXPECT_NE(nullptr, galloc); EXPECT_EQ(true, galloc->isLocked()); @@ -1252,7 +1245,7 @@ TEST_F(MockWddmMemoryManagerTest, givenPageTableManagerWhenMapAuxGpuVaCalledThen auto mockMngr = new NiceMock(); myWddm->resetPageTableManager(mockMngr); - auto allocation = memoryManager.allocateGraphicsMemory(4096); + auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); GMM_DDI_UPDATEAUXTABLE givenDdiUpdateAuxTable = {}; GMM_DDI_UPDATEAUXTABLE expectedDdiUpdateAuxTable = {}; @@ -1313,7 +1306,7 @@ TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedAllocationWhenReleaseingT auto mockMngr = new NiceMock(); wddm->resetPageTableManager(mockMngr); - auto wddmAlloc = static_cast(memoryManager.allocateGraphicsMemory(4096u)); + auto wddmAlloc = static_cast(memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize})); wddmAlloc->gpuPtr = gpuVa; wddmAlloc->gmm->isRenderCompressed = true; @@ -1338,7 +1331,7 @@ TEST_F(MockWddmMemoryManagerTest, givenNonRenderCompressedAllocationWhenReleasei auto mockMngr = new NiceMock(); wddm->resetPageTableManager(mockMngr); - auto wddmAlloc = static_cast(memoryManager.allocateGraphicsMemory(4096u)); + auto wddmAlloc = static_cast(memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize})); wddmAlloc->gmm->isRenderCompressed = false; EXPECT_CALL(*mockMngr, updateAuxTable(_)).Times(0); @@ -1386,7 +1379,7 @@ TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedFlagSetWhenInternalIsUnse myGmm->isRenderCompressed = false; myGmm->gmmResourceInfo->getResourceFlags()->Info.RenderCompressed = 1; - auto wddmAlloc = static_cast(memoryManager.allocateGraphicsMemory(4096u)); + auto wddmAlloc = static_cast(memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize})); delete wddmAlloc->gmm; wddmAlloc->gmm = myGmm; diff --git a/unit_tests/program/program_tests.cpp b/unit_tests/program/program_tests.cpp index c89676e961..f39433bec9 100644 --- a/unit_tests/program/program_tests.cpp +++ b/unit_tests/program/program_tests.cpp @@ -2469,7 +2469,7 @@ TEST_F(ProgramTests, givenProgramWithBlockKernelsWhenfreeBlockResourcesisCalledT program->addBlockKernel(infoBlock); - GraphicsAllocation *privateSurface = program->getDevice(0).getMemoryManager()->allocateGraphicsMemory(4096); + GraphicsAllocation *privateSurface = program->getDevice(0).getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); EXPECT_NE(nullptr, privateSurface); program->getBlockKernelManager()->pushPrivateSurface(privateSurface, 0); @@ -2805,7 +2805,7 @@ TEST(ProgramDestructionTests, givenProgramUsingDeviceWhenItIsDestroyedAfterPlatf auto device = platformImpl->getDevice(0); MockContext *context = new MockContext(device, false); MockProgram *pProgram = new MockProgram(*device->getExecutionEnvironment(), context, false); - auto globalAllocation = device->getMemoryManager()->allocateGraphicsMemory(MemoryConstants::pageSize); + auto globalAllocation = device->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); pProgram->setGlobalSurface(globalAllocation); platformImpl.reset(nullptr);