diff --git a/runtime/command_stream/command_stream_receiver.cpp b/runtime/command_stream/command_stream_receiver.cpp index 90c011e83c..bb4b547bf0 100644 --- a/runtime/command_stream/command_stream_receiver.cpp +++ b/runtime/command_stream/command_stream_receiver.cpp @@ -355,7 +355,10 @@ 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 - allocation = memoryManager->allocateGraphicsMemory(surface.getSurfaceSize(), MemoryConstants::pageSize, false, false); + AllocationProperties properties; + properties.alignment = MemoryConstants::pageSize; + properties.size = surface.getSurfaceSize(); + allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties); if (allocation) { memcpy_s(allocation->getUnderlyingBuffer(), allocation->getUnderlyingBufferSize(), surface.getMemoryPointer(), surface.getSurfaceSize()); diff --git a/runtime/device/device.cpp b/runtime/device/device.cpp index aec3e0b247..8b53229d95 100644 --- a/runtime/device/device.cpp +++ b/runtime/device/device.cpp @@ -143,10 +143,11 @@ bool Device::createDeviceImpl(const HardwareInfo *pHwInfo, Device &outDevice) { outDevice.executionEnvironment->memoryManager->setForce32BitAllocations(outDevice.getDeviceInfo().force32BitAddressess); if (outDevice.preemptionMode == PreemptionMode::MidThread || outDevice.isSourceLevelDebuggerActive()) { - size_t requiredSize = pHwInfo->capabilityTable.requiredPreemptionSurfaceSize; - size_t alignment = 256 * MemoryConstants::kiloByte; - bool uncacheable = outDevice.getWaTable()->waCSRUncachable; - outDevice.preemptionAllocation = outDevice.executionEnvironment->memoryManager->allocateGraphicsMemory(requiredSize, alignment, false, uncacheable); + AllocationProperties properties; + properties.size = pHwInfo->capabilityTable.requiredPreemptionSurfaceSize; + properties.flags.uncacheable = outDevice.getWaTable()->waCSRUncachable; + properties.alignment = 256 * MemoryConstants::kiloByte; + outDevice.preemptionAllocation = outDevice.executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(properties); if (!outDevice.preemptionAllocation) { return false; } diff --git a/runtime/helpers/flat_batch_buffer_helper_hw.inl b/runtime/helpers/flat_batch_buffer_helper_hw.inl index 1027f29e82..6cb25d0a51 100644 --- a/runtime/helpers/flat_batch_buffer_helper_hw.inl +++ b/runtime/helpers/flat_batch_buffer_helper_hw.inl @@ -31,9 +31,11 @@ GraphicsAllocation *FlatBatchBufferHelperHw::flattenBatchBuffer(Batch batchBuffer.chainedBatchBuffer->setAubWritable(false); auto sizeMainBatchBuffer = batchBuffer.chainedBatchBufferStartOffset - batchBuffer.startOffset; - auto flatBatchBufferSize = alignUp(sizeMainBatchBuffer + indirectPatchCommandsSize + batchBuffer.chainedBatchBuffer->getUnderlyingBufferSize(), MemoryConstants::pageSize); + AllocationProperties flatBatchBufferProperties; + flatBatchBufferProperties.alignment = MemoryConstants::pageSize; + flatBatchBufferProperties.size = alignUp(sizeMainBatchBuffer + indirectPatchCommandsSize + batchBuffer.chainedBatchBuffer->getUnderlyingBufferSize(), MemoryConstants::pageSize); flatBatchBuffer = - getMemoryManager()->allocateGraphicsMemory(flatBatchBufferSize, MemoryConstants::pageSize, false, false); + getMemoryManager()->allocateGraphicsMemoryWithProperties(flatBatchBufferProperties); UNRECOVERABLE_IF(flatBatchBuffer == nullptr); // Copy main batchbuffer memcpy_s(flatBatchBuffer->getUnderlyingBuffer(), sizeMainBatchBuffer, @@ -46,7 +48,7 @@ GraphicsAllocation *FlatBatchBufferHelperHw::flattenBatchBuffer(Batch memcpy_s(ptrOffset(flatBatchBuffer->getUnderlyingBuffer(), sizeMainBatchBuffer + indirectPatchCommandsSize), batchBuffer.chainedBatchBuffer->getUnderlyingBufferSize(), batchBuffer.chainedBatchBuffer->getUnderlyingBuffer(), batchBuffer.chainedBatchBuffer->getUnderlyingBufferSize()); - sizeBatchBuffer = flatBatchBufferSize; + sizeBatchBuffer = flatBatchBufferProperties.size; patchInfoCollection.insert(std::end(patchInfoCollection), std::begin(indirectPatchInfo), std::end(indirectPatchInfo)); } } else if (dispatchMode == DispatchMode::BatchedDispatch) { @@ -108,8 +110,10 @@ GraphicsAllocation *FlatBatchBufferHelperHw::flattenBatchBuffer(Batch flatBatchBufferSize = alignUp(flatBatchBufferSize, MemoryConstants::pageSize); flatBatchBufferSize += CSRequirements::csOverfetchSize; - flatBatchBuffer = getMemoryManager()->allocateGraphicsMemory(static_cast(flatBatchBufferSize), - MemoryConstants::pageSize, false, false); + AllocationProperties flatBatchBufferProperties; + flatBatchBufferProperties.size = static_cast(flatBatchBufferSize); + flatBatchBufferProperties.alignment = MemoryConstants::pageSize; + flatBatchBuffer = getMemoryManager()->allocateGraphicsMemoryWithProperties(flatBatchBufferProperties); UNRECOVERABLE_IF(flatBatchBuffer == nullptr); char *ptr = reinterpret_cast(flatBatchBuffer->getUnderlyingBuffer()); diff --git a/runtime/memory_manager/memory_manager.cpp b/runtime/memory_manager/memory_manager.cpp index 3e80cdab6d..1e676ff8f4 100644 --- a/runtime/memory_manager/memory_manager.cpp +++ b/runtime/memory_manager/memory_manager.cpp @@ -86,14 +86,14 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemoryForSVM(size_t size, boo return graphicsAllocation; } -GraphicsAllocation *MemoryManager::allocateGraphicsMemory(size_t size, const void *ptr, bool forcePin) { +GraphicsAllocation *MemoryManager::allocateGraphicsMemoryWithHostPtr(const AllocationData &allocationData) { if (deferredDeleter) { deferredDeleter->drain(true); } GraphicsAllocation *graphicsAllocation = nullptr; - auto osStorage = hostPtrManager->prepareOsStorageForAllocation(*this, size, ptr); + auto osStorage = hostPtrManager->prepareOsStorageForAllocation(*this, allocationData.size, allocationData.hostPtr); if (osStorage.fragmentCount > 0) { - graphicsAllocation = createGraphicsAllocation(osStorage, size, ptr); + graphicsAllocation = createGraphicsAllocation(osStorage, allocationData.size, allocationData.hostPtr); } return graphicsAllocation; } @@ -239,6 +239,7 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo allocationData.size = size; allocationData.type = type; allocationData.devicesBitfield = devicesBitfield; + allocationData.alignment = MemoryConstants::pageSize; if (allocationData.flags.allocateMemory) { allocationData.hostPtr = nullptr; @@ -266,13 +267,13 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemory(const AllocationData & return allocate32BitGraphicsMemory(allocationData.size, allocationData.hostPtr, AllocationOrigin::EXTERNAL_ALLOCATION); } if (allocationData.hostPtr) { - return allocateGraphicsMemory(allocationData.size, allocationData.hostPtr, allocationData.flags.forcePin); + return allocateGraphicsMemoryWithHostPtr(allocationData); } if (peek64kbPagesEnabled() && allocationData.flags.allow64kbPages) { bool preferRenderCompressed = (allocationData.type == GraphicsAllocation::AllocationType::BUFFER_COMPRESSED); return allocateGraphicsMemory64kb(allocationData.size, MemoryConstants::pageSize64k, allocationData.flags.forcePin, preferRenderCompressed); } - return allocateGraphicsMemory(allocationData.size, MemoryConstants::pageSize, allocationData.flags.forcePin, allocationData.flags.uncacheable); + return allocateGraphicsMemoryWithAlignment(allocationData); } const CsrContainer &MemoryManager::getCommandStreamReceivers() const { diff --git a/runtime/memory_manager/memory_manager.h b/runtime/memory_manager/memory_manager.h index 7cd2887b17..99977e74f3 100644 --- a/runtime/memory_manager/memory_manager.h +++ b/runtime/memory_manager/memory_manager.h @@ -42,26 +42,29 @@ enum AllocationOrigin { INTERNAL_ALLOCATION }; -struct AllocationFlags { +struct AllocationProperties { union { struct { uint32_t allocateMemory : 1; uint32_t flushL3RequiredForRead : 1; uint32_t flushL3RequiredForWrite : 1; - uint32_t reserved : 29; + uint32_t forcePin : 1; + uint32_t uncacheable : 1; + uint32_t reserved : 27; } flags; - uint32_t allFlags; + uint32_t allFlags = 0; }; + static_assert(sizeof(AllocationProperties::flags) == sizeof(AllocationProperties::allFlags), ""); + size_t size = 0; + size_t alignment = 0; - static_assert(sizeof(AllocationFlags::flags) == sizeof(AllocationFlags::allFlags), ""); - - AllocationFlags() { + AllocationProperties() { allFlags = 0; flags.flushL3RequiredForRead = 1; flags.flushL3RequiredForWrite = 1; } - AllocationFlags(bool allocateMemory) { + AllocationProperties(bool allocateMemory) { allFlags = 0; flags.flushL3RequiredForRead = 1; flags.flushL3RequiredForWrite = 1; @@ -69,6 +72,8 @@ struct AllocationFlags { } }; +using AllocationFlags = AllocationProperties; + struct AllocationData { union { struct { @@ -85,10 +90,10 @@ struct AllocationData { uint32_t allFlags = 0; }; static_assert(sizeof(AllocationData::flags) == sizeof(AllocationData::allFlags), ""); - GraphicsAllocation::AllocationType type = GraphicsAllocation::AllocationType::UNKNOWN; const void *hostPtr = nullptr; size_t size = 0; + size_t alignment = 0; DevicesBitfield devicesBitfield = 0; }; @@ -119,18 +124,30 @@ class MemoryManager { virtual void removeAllocationFromHostPtrManager(GraphicsAllocation *memory) = 0; GraphicsAllocation *allocateGraphicsMemory(size_t size) { - return allocateGraphicsMemory(size, MemoryConstants::preferredAlignment, false, false); + AllocationData allocationData; + allocationData.size = size; + allocationData.alignment = MemoryConstants::preferredAlignment; + return allocateGraphicsMemoryWithAlignment(allocationData); } - virtual GraphicsAllocation *allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) = 0; + GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) { + AllocationData allocationData; + allocationData.alignment = properties.alignment; + allocationData.size = properties.size; + allocationData.flags.uncacheable = properties.flags.uncacheable; + allocationData.flags.forcePin = properties.flags.forcePin; + return allocateGraphicsMemoryWithAlignment(allocationData); + } virtual GraphicsAllocation *allocateGraphicsMemory64kb(size_t size, size_t alignment, bool forcePin, bool preferRenderCompressed) = 0; virtual GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(size_t size, void *cpuPtr) = 0; virtual GraphicsAllocation *allocateGraphicsMemory(size_t size, const void *ptr) { - return MemoryManager::allocateGraphicsMemory(size, ptr, false); + AllocationData allocationData; + allocationData.hostPtr = ptr; + allocationData.size = size; + return MemoryManager::allocateGraphicsMemoryWithHostPtr(allocationData); } - virtual GraphicsAllocation *allocateGraphicsMemory(size_t size, const void *ptr, bool forcePin); GraphicsAllocation *allocateGraphicsMemoryForHostPtr(size_t size, void *ptr, bool fullRangeSvm, bool requiresL3Flush) { if (fullRangeSvm) { @@ -243,6 +260,9 @@ class MemoryManager { const void *hostPtr, size_t size, GraphicsAllocation::AllocationType type); GraphicsAllocation *allocateGraphicsMemory(const AllocationData &allocationData); + virtual GraphicsAllocation *allocateGraphicsMemoryWithHostPtr(const AllocationData &allocationData); + virtual GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) = 0; + bool force32bitAllocations = false; bool virtualPaddingAvailable = false; GraphicsAllocation *paddingAllocation = nullptr; diff --git a/runtime/memory_manager/os_agnostic_memory_manager.cpp b/runtime/memory_manager/os_agnostic_memory_manager.cpp index 1b364ce031..208e80d2bb 100644 --- a/runtime/memory_manager/os_agnostic_memory_manager.cpp +++ b/runtime/memory_manager/os_agnostic_memory_manager.cpp @@ -30,27 +30,27 @@ OsAgnosticMemoryManager::~OsAgnosticMemoryManager() { struct OsHandle { }; -GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) { +GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) { - auto sizeAligned = alignUp(size, MemoryConstants::pageSize); + auto sizeAligned = alignUp(allocationData.size, MemoryConstants::pageSize); MemoryAllocation *memoryAllocation = nullptr; - if (fakeBigAllocations && size > bigAllocation) { - memoryAllocation = new MemoryAllocation(nullptr, (void *)dummyAddress, static_cast(dummyAddress), size, counter, + if (fakeBigAllocations && allocationData.size > bigAllocation) { + memoryAllocation = new MemoryAllocation(nullptr, (void *)dummyAddress, static_cast(dummyAddress), allocationData.size, counter, MemoryPool::System4KBPages, this->getOsContextCount(), false); counter++; - memoryAllocation->uncacheable = uncacheable; + memoryAllocation->uncacheable = allocationData.flags.uncacheable; return memoryAllocation; } - auto ptr = allocateSystemMemory(sizeAligned, alignment ? alignUp(alignment, MemoryConstants::pageSize) : MemoryConstants::pageSize); + auto ptr = allocateSystemMemory(sizeAligned, allocationData.alignment ? alignUp(allocationData.alignment, MemoryConstants::pageSize) : MemoryConstants::pageSize); if (ptr != nullptr) { - memoryAllocation = new MemoryAllocation(ptr, ptr, reinterpret_cast(ptr), size, counter, MemoryPool::System4KBPages, + memoryAllocation = new MemoryAllocation(ptr, ptr, reinterpret_cast(ptr), allocationData.size, counter, MemoryPool::System4KBPages, this->getOsContextCount(), false); if (!memoryAllocation) { alignedFreeWrapper(ptr); return nullptr; } - memoryAllocation->uncacheable = uncacheable; + memoryAllocation->uncacheable = allocationData.flags.uncacheable; } counter++; return memoryAllocation; @@ -72,7 +72,11 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryForNonSvmHost } GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemory64kb(size_t size, size_t alignment, bool forcePin, bool preferRenderCompressed) { - auto memoryAllocation = allocateGraphicsMemory(alignUp(size, MemoryConstants::pageSize64k), MemoryConstants::pageSize64k, forcePin, false); + AllocationProperties properties; + properties.size = alignUp(size, MemoryConstants::pageSize64k); + properties.flags.forcePin = forcePin; + properties.alignment = MemoryConstants::pageSize64k; + auto memoryAllocation = allocateGraphicsMemoryWithProperties(properties); if (memoryAllocation) { reinterpret_cast(memoryAllocation)->overrideMemoryPool(MemoryPool::System64KBPages); } diff --git a/runtime/memory_manager/os_agnostic_memory_manager.h b/runtime/memory_manager/os_agnostic_memory_manager.h index dc683ce84b..1496975175 100644 --- a/runtime/memory_manager/os_agnostic_memory_manager.h +++ b/runtime/memory_manager/os_agnostic_memory_manager.h @@ -44,7 +44,6 @@ class OsAgnosticMemoryManager : public MemoryManager { }; ~OsAgnosticMemoryManager() override; - GraphicsAllocation *allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) override; GraphicsAllocation *allocateGraphicsMemory64kb(size_t size, size_t alignment, bool forcePin, bool preferRenderCompressed) override; GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(size_t size, void *cpuPtr) override; GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, const void *ptr, AllocationOrigin allocationOrigin) override; @@ -72,6 +71,9 @@ class OsAgnosticMemoryManager : public MemoryManager { Allocator32bit *create32BitAllocator(bool enableLocalMemory); + protected: + GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override; + private: unsigned long long counter = 0; bool fakeBigAllocations = false; diff --git a/runtime/os_interface/linux/drm_memory_manager.cpp b/runtime/os_interface/linux/drm_memory_manager.cpp index da7fe18173..3544f3fb80 100644 --- a/runtime/os_interface/linux/drm_memory_manager.cpp +++ b/runtime/os_interface/linux/drm_memory_manager.cpp @@ -203,12 +203,12 @@ DrmAllocation *DrmMemoryManager::createGraphicsAllocation(OsHandleStorage &handl return allocation; } -DrmAllocation *DrmMemoryManager::allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) { +DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) { const size_t minAlignment = MemoryConstants::allocationAlignment; - size_t cAlignment = alignUp(std::max(alignment, minAlignment), minAlignment); + size_t cAlignment = alignUp(std::max(allocationData.alignment, minAlignment), minAlignment); // When size == 0 allocate allocationAlignment // It's needed to prevent overlapping pages with user pointers - size_t cSize = std::max(alignUp(size, minAlignment), minAlignment); + size_t cSize = std::max(alignUp(allocationData.size, minAlignment), minAlignment); auto res = alignedMallocWrapper(cSize, cAlignment); @@ -223,16 +223,16 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemory(size_t size, size_t alig } bo->isAllocated = true; - if (forcePinEnabled && pinBB != nullptr && forcePin && size >= this->pinThreshold) { + if (forcePinEnabled && pinBB != nullptr && allocationData.flags.forcePin && allocationData.size >= this->pinThreshold) { pinBB->pin(&bo, 1); } return new DrmAllocation(bo, res, cSize, MemoryPool::System4KBPages, getOsContextCount(), false); } -DrmAllocation *DrmMemoryManager::allocateGraphicsMemory(size_t size, const void *ptr, bool forcePin) { - auto res = static_cast(MemoryManager::allocateGraphicsMemory(size, const_cast(ptr), forcePin)); +DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryWithHostPtr(const AllocationData &allocationData) { + auto res = static_cast(MemoryManager::allocateGraphicsMemoryWithHostPtr(allocationData)); - bool forcePinAllowed = res != nullptr && pinBB != nullptr && forcePinEnabled && forcePin && size >= this->pinThreshold; + bool forcePinAllowed = res != nullptr && pinBB != nullptr && forcePinEnabled && allocationData.flags.forcePin && allocationData.size >= this->pinThreshold; if (!validateHostPtrMemory && forcePinAllowed) { BufferObject *boArray[] = {res->getBO()}; pinBB->pin(boArray, 1); diff --git a/runtime/os_interface/linux/drm_memory_manager.h b/runtime/os_interface/linux/drm_memory_manager.h index ad772a765e..81d3f6b9b5 100644 --- a/runtime/os_interface/linux/drm_memory_manager.h +++ b/runtime/os_interface/linux/drm_memory_manager.h @@ -31,13 +31,14 @@ class DrmMemoryManager : public MemoryManager { void addAllocationToHostPtrManager(GraphicsAllocation *gfxAllocation) override; void removeAllocationFromHostPtrManager(GraphicsAllocation *gfxAllocation) override; void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) override; - DrmAllocation *allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) override; DrmAllocation *allocateGraphicsMemory64kb(size_t size, size_t alignment, bool forcePin, bool preferRenderCompressed) override; DrmAllocation *allocateGraphicsMemoryForNonSvmHostPtr(size_t size, void *cpuPtr) override; DrmAllocation *allocateGraphicsMemory(size_t size, const void *ptr) override { - return allocateGraphicsMemory(size, ptr, false); + AllocationData allocationData; + allocationData.hostPtr = ptr; + allocationData.size = size; + return allocateGraphicsMemoryWithHostPtr(allocationData); } - DrmAllocation *allocateGraphicsMemory(size_t size, const void *ptr, bool forcePin) override; GraphicsAllocation *allocateGraphicsMemoryForImage(ImageInfo &imgInfo, Gmm *gmm) override; DrmAllocation *allocate32BitGraphicsMemory(size_t size, const void *ptr, AllocationOrigin allocationOrigin) override; GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) override; @@ -74,6 +75,9 @@ class DrmMemoryManager : public MemoryManager { void releaseGpuRange(void *address, size_t unmapSize, StorageAllocatorType allocatorType); void initInternalRangeAllocator(size_t range); + DrmAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override; + DrmAllocation *allocateGraphicsMemoryWithHostPtr(const AllocationData &allocationData) override; + Drm *drm; BufferObject *pinBB; size_t pinThreshold = 8 * 1024 * 1024; diff --git a/runtime/os_interface/windows/wddm_memory_manager.cpp b/runtime/os_interface/windows/wddm_memory_manager.cpp index a81c53ac98..c13d4d4769 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.cpp +++ b/runtime/os_interface/windows/wddm_memory_manager.cpp @@ -79,9 +79,9 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory64kb(size_t size, s return wddmAllocation.release(); } -GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) { - size_t newAlignment = alignment ? alignUp(alignment, MemoryConstants::pageSize) : MemoryConstants::pageSize; - size_t sizeAligned = size ? alignUp(size, MemoryConstants::pageSize) : MemoryConstants::pageSize; +GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) { + size_t newAlignment = allocationData.alignment ? alignUp(allocationData.alignment, MemoryConstants::pageSize) : MemoryConstants::pageSize; + size_t sizeAligned = allocationData.size ? alignUp(allocationData.size, MemoryConstants::pageSize) : MemoryConstants::pageSize; void *pSysMem = allocateSystemMemory(sizeAligned, newAlignment); Gmm *gmm = nullptr; @@ -92,7 +92,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory(size_t size, size_ auto wddmAllocation = std::make_unique(pSysMem, sizeAligned, nullptr, MemoryPool::System4KBPages, getOsContextCount(), false); wddmAllocation->driverAllocatedCpuPointer = pSysMem; - gmm = new Gmm(pSysMem, sizeAligned, uncacheable); + gmm = new Gmm(pSysMem, sizeAligned, allocationData.flags.uncacheable); wddmAllocation->gmm = gmm; diff --git a/runtime/os_interface/windows/wddm_memory_manager.h b/runtime/os_interface/windows/wddm_memory_manager.h index a80080f65d..d11df49edd 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.h +++ b/runtime/os_interface/windows/wddm_memory_manager.h @@ -35,7 +35,6 @@ class WddmMemoryManager : public MemoryManager { void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) override; GraphicsAllocation *allocateGraphicsMemory64kb(size_t size, size_t alignment, bool forcePin, bool preferRenderCompressed) override; - GraphicsAllocation *allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) override; GraphicsAllocation *allocateGraphicsMemory(size_t size, const void *ptr) override; GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(size_t size, void *cpuPtr) override; GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, const void *ptr, AllocationOrigin allocationOrigin) override; @@ -74,6 +73,8 @@ class WddmMemoryManager : public MemoryManager { AlignedMallocRestrictions *getAlignedMallocRestrictions() override; protected: + GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override; + GraphicsAllocation *createAllocationFromHandle(osHandle handle, bool requireSpecificBitness, bool ntHandle); static bool validateAllocation(WddmAllocation *alloc); bool createWddmAllocation(WddmAllocation *allocation, AllocationOrigin origin); 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 01621581f7..1c99270698 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), sizeof(uint32_t), false, false); + auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); auto osContextId = aubCsr->getOsContext().getContextId(); @@ -540,7 +540,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon auto commandBuffer = aubExecutionEnvironment->commandBuffer; LinearStream cs(commandBuffer); - auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); ASSERT_NE(nullptr, gfxAllocation); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; @@ -574,7 +574,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInNonStanda auto commandBuffer = aubExecutionEnvironment->commandBuffer; LinearStream cs(commandBuffer); - auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; @@ -611,7 +611,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon aubCsr->subCaptureManager.reset(aubSubCaptureManagerMock); ASSERT_TRUE(aubCsr->subCaptureManager->isSubCaptureEnabled()); - auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); ASSERT_NE(nullptr, gfxAllocation); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; @@ -642,7 +642,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenGraphic auto aubExecutionEnvironment = getEnvironment>(false, false, true); auto memoryManager = aubExecutionEnvironment->executionEnvironment->memoryManager.get(); - auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); EXPECT_TRUE(gfxAllocation->isAubWritable()); @@ -654,7 +654,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenProcess auto aubCsr = aubExecutionEnvironment->template getCsr>(); auto memoryManager = aubExecutionEnvironment->executionEnvironment->memoryManager.get(); - auto gfxDefaultAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + auto gfxDefaultAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); ResidencyContainer allocationsForResidency = {gfxDefaultAllocation}; aubCsr->processResidency(allocationsForResidency); @@ -669,7 +669,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), sizeof(uint32_t), false, false); + auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); GraphicsAllocation::AllocationType onlyOneTimeAubWritableTypes[] = { GraphicsAllocation::AllocationType::BUFFER, @@ -694,10 +694,10 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenProcess memoryManager.reset(aubCsr->createMemoryManager(false, false)); aubCsr->setOsContext(*pDevice->getDefaultEngine().osContext); - auto gfxBufferAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + auto gfxBufferAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); gfxBufferAllocation->setAllocationType(GraphicsAllocation::AllocationType::BUFFER); - auto gfxImageAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + auto gfxImageAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); gfxImageAllocation->setAllocationType(GraphicsAllocation::AllocationType::IMAGE); ResidencyContainer allocationsForResidency = {gfxBufferAllocation, gfxImageAllocation}; @@ -717,11 +717,11 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptur memoryManager.reset(aubCsr->createMemoryManager(false, false)); aubCsr->setOsContext(*pDevice->getDefaultEngine().osContext); - auto gfxBufferAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + auto gfxBufferAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); gfxBufferAllocation->setAllocationType(GraphicsAllocation::AllocationType::BUFFER); gfxBufferAllocation->setAubWritable(false); - auto gfxImageAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + auto gfxImageAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); gfxImageAllocation->setAllocationType(GraphicsAllocation::AllocationType::IMAGE); gfxImageAllocation->setAubWritable(false); @@ -744,11 +744,11 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenProcess memoryManager.reset(aubCsr->createMemoryManager(false, false)); aubCsr->setOsContext(*pDevice->getDefaultEngine().osContext); - auto gfxBufferAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + auto gfxBufferAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); gfxBufferAllocation->setAllocationType(GraphicsAllocation::AllocationType::BUFFER); gfxBufferAllocation->setAubWritable(false); - auto gfxImageAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + auto gfxImageAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); gfxImageAllocation->setAllocationType(GraphicsAllocation::AllocationType::IMAGE); gfxImageAllocation->setAubWritable(false); @@ -769,7 +769,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), sizeof(uint32_t), false, false); + auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); EXPECT_TRUE(aubCsr->writeMemory(*gfxAllocation)); @@ -781,7 +781,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), sizeof(uint32_t), false, false); + auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); 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 61341e30ee..0d7d71da75 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,8 +48,8 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedB auto flatBatchBufferHelper = new FlatBatchBufferHelperHw(*pDevice->executionEnvironment); aubCsr->overwriteFlatBatchBufferHelper(flatBatchBufferHelper); - auto chainedBatchBuffer = memoryManager->allocateGraphicsMemory(128u, 64u, false, false); - auto otherAllocation = memoryManager->allocateGraphicsMemory(128u, 64u, false, false); + auto chainedBatchBuffer = memoryManager->allocateGraphicsMemory(128u); + auto otherAllocation = memoryManager->allocateGraphicsMemory(128u); ASSERT_NE(nullptr, chainedBatchBuffer); GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); @@ -102,8 +102,8 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedB auto flatBatchBufferHelper = new FlatBatchBufferHelperHw(*pDevice->executionEnvironment); aubCsr->overwriteFlatBatchBufferHelper(flatBatchBufferHelper); - auto chainedBatchBuffer = memoryManager->allocateGraphicsMemory(128u, 64u, false, false); - auto otherAllocation = memoryManager->allocateGraphicsMemory(128u, 64u, false, false); + auto chainedBatchBuffer = memoryManager->allocateGraphicsMemory(128u); + auto otherAllocation = memoryManager->allocateGraphicsMemory(128u); ASSERT_NE(nullptr, chainedBatchBuffer); GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); @@ -278,7 +278,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedF auto mockHelper = new MockFlatBatchBufferHelper(*aubExecutionEnvironment->executionEnvironment); aubCsr->overwriteFlatBatchBufferHelper(mockHelper); - auto chainedBatchBuffer = aubExecutionEnvironment->executionEnvironment->memoryManager->allocateGraphicsMemory(128u, 64u, false, false); + auto chainedBatchBuffer = aubExecutionEnvironment->executionEnvironment->memoryManager->allocateGraphicsMemory(128u); 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, 4096, false, false), + aubExecutionEnvironment->executionEnvironment->memoryManager->allocateGraphicsMemory(4096), [&](GraphicsAllocation *ptr) { aubExecutionEnvironment->executionEnvironment->memoryManager->freeGraphicsMemory(ptr); }); auto expectedAllocation = ptr.get(); @@ -663,7 +663,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenWriteMe aubCsr->ppgtt.reset(ppgttMock); - auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); gfxAllocation->setAubWritable(true); auto gmm = new Gmm(nullptr, 1, false); 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 ff111861f1..8c4577821a 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 @@ -175,7 +175,7 @@ HWTEST_P(CommandStreamReceiverWithAubDumpTest, givenCommandStreamReceiverWithAub } HWTEST_P(CommandStreamReceiverWithAubDumpTest, givenCommandStreamReceiverWithAubDumpWhenMakeResidentIsCalledThenBaseCsrMakeResidentIsCalled) { - auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); ASSERT_NE(nullptr, gfxAllocation); csrWithAubDump->makeResident(*gfxAllocation); @@ -197,7 +197,7 @@ HWTEST_P(CommandStreamReceiverWithAubDumpTest, givenCommandStreamReceiverWithAub LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); ASSERT_NE(nullptr, gfxAllocation); ResidencyContainer allocationsForResidency = {gfxAllocation}; @@ -217,7 +217,7 @@ HWTEST_P(CommandStreamReceiverWithAubDumpTest, givenCommandStreamReceiverWithAub } HWTEST_P(CommandStreamReceiverWithAubDumpTest, givenCommandStreamReceiverWithAubDumpWhenMakeNonResidentIsCalledThenBothBaseAndAubCsrMakeNonResidentIsCalled) { - auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); ASSERT_NE(nullptr, gfxAllocation); csrWithAubDump->makeResident(*gfxAllocation); diff --git a/unit_tests/command_stream/tbx_command_stream_tests.cpp b/unit_tests/command_stream/tbx_command_stream_tests.cpp index ce8864539b..b4523312e4 100644 --- a/unit_tests/command_stream/tbx_command_stream_tests.cpp +++ b/unit_tests/command_stream/tbx_command_stream_tests.cpp @@ -263,7 +263,7 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenFlushIsCalledTh TbxMemoryManager *memoryManager = tbxCsr->getMemoryManager(); ASSERT_NE(nullptr, memoryManager); - auto graphicsAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + auto graphicsAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); ASSERT_NE(nullptr, graphicsAllocation); GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); diff --git a/unit_tests/mem_obj/buffer_pin_tests.cpp b/unit_tests/mem_obj/buffer_pin_tests.cpp index 5c9fb9da1c..1b34d0ca81 100644 --- a/unit_tests/mem_obj/buffer_pin_tests.cpp +++ b/unit_tests/mem_obj/buffer_pin_tests.cpp @@ -21,24 +21,24 @@ using namespace OCLRT; class TestedMemoryManager : public OsAgnosticMemoryManager { public: using OsAgnosticMemoryManager::OsAgnosticMemoryManager; - GraphicsAllocation *allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) override { + GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override { EXPECT_NE(0u, expectedSize); - if (expectedSize == size) { - EXPECT_TRUE(forcePin); + if (expectedSize == allocationData.size) { + EXPECT_TRUE(allocationData.flags.forcePin); allocCount++; } - return OsAgnosticMemoryManager::allocateGraphicsMemory(size, alignment, forcePin, uncacheable); + return OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment(allocationData); }; GraphicsAllocation *allocateGraphicsMemory64kb(size_t size, size_t alignment, bool forcePin, bool preferRenderCompressed) override { return nullptr; }; - GraphicsAllocation *allocateGraphicsMemory(size_t size, const void *ptr, bool forcePin) override { + GraphicsAllocation *allocateGraphicsMemoryWithHostPtr(const AllocationData &properties) override { EXPECT_NE(0u, HPExpectedSize); - if (HPExpectedSize == size) { - EXPECT_TRUE(forcePin); + if (HPExpectedSize == properties.size) { + EXPECT_TRUE(properties.flags.forcePin); HPAllocCount++; } - return OsAgnosticMemoryManager::allocateGraphicsMemory(size, ptr, forcePin); + return OsAgnosticMemoryManager::allocateGraphicsMemoryWithHostPtr(properties); } size_t expectedSize = 0; diff --git a/unit_tests/mem_obj/buffer_tests.cpp b/unit_tests/mem_obj/buffer_tests.cpp index 972b286a66..357a4df7a5 100644 --- a/unit_tests/mem_obj/buffer_tests.cpp +++ b/unit_tests/mem_obj/buffer_tests.cpp @@ -211,7 +211,7 @@ TEST(Buffer, givenNullptrPassedToBufferCreateWhenAllocationIsNotSystemMemoryPool MockContext ctx(device.get()); auto allocateNonSystemGraphicsAllocation = [memoryManager](AllocationFlags flags, DevicesBitfield devicesBitfield, const void *hostPtr, size_t size, GraphicsAllocation::AllocationType type) -> GraphicsAllocation * { - auto allocation = memoryManager->allocateGraphicsMemory(size, MemoryConstants::pageSize, false, false); + auto allocation = memoryManager->allocateGraphicsMemory(size); reinterpret_cast(allocation)->overrideMemoryPool(MemoryPool::SystemCpuInaccessible); return allocation; }; @@ -236,7 +236,7 @@ TEST(Buffer, givenNullptrPassedToBufferCreateWhenAllocationIsNotSystemMemoryPool MockContext ctx(device.get()); auto allocateNonSystemGraphicsAllocation = [memoryManager](AllocationFlags flags, DevicesBitfield devicesBitfield, const void *hostPtr, size_t size, GraphicsAllocation::AllocationType type) -> GraphicsAllocation * { - auto allocation = memoryManager->allocateGraphicsMemory(size, MemoryConstants::pageSize, false, false); + auto allocation = memoryManager->allocateGraphicsMemory(size); reinterpret_cast(allocation)->overrideMemoryPool(MemoryPool::SystemCpuInaccessible); return allocation; }; @@ -363,7 +363,7 @@ TEST(Buffer, givenClMemCopyHostPointerPassedToBufferCreateWhenAllocationIsNotInS MockContext ctx(device.get()); auto allocateNonSystemGraphicsAllocation = [memoryManager](AllocationFlags flags, DevicesBitfield devicesBitfield, const void *hostPtr, size_t size, GraphicsAllocation::AllocationType type) -> GraphicsAllocation * { - auto allocation = memoryManager->allocateGraphicsMemory(size, MemoryConstants::pageSize, false, false); + auto allocation = memoryManager->allocateGraphicsMemory(size); reinterpret_cast(allocation)->overrideMemoryPool(MemoryPool::SystemCpuInaccessible); return allocation; }; diff --git a/unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.cpp b/unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.cpp index 456d48f399..1c1f50699c 100644 --- a/unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.cpp @@ -13,7 +13,6 @@ TEST(MemoryManagerTest, givenNotSetUseSystemMemoryWhenGraphicsAllocationInDevice MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Error; AllocationData allocData; - allocData.allFlags = 0; allocData.size = MemoryConstants::pageSize; allocData.flags.allocateMemory = true; diff --git a/unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.inl b/unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.inl index 689719157a..dd1b1486f2 100644 --- a/unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.inl +++ b/unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.inl @@ -18,7 +18,6 @@ TEST(MemoryManagerTest, givenSetUseSytemMemoryWhenGraphicsAllocationInDevicePool OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success; AllocationData allocData; - allocData.allFlags = 0; allocData.size = MemoryConstants::pageSize; allocData.flags.useSystemMemory = true; allocData.flags.allocateMemory = true; @@ -35,7 +34,6 @@ TEST(MemoryManagerTest, givenAllowed32BitAndFroce32BitWhenGraphicsAllocationInDe MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success; AllocationData allocData; - allocData.allFlags = 0; allocData.size = MemoryConstants::pageSize; allocData.flags.allow32Bit = true; allocData.flags.allocateMemory = true; diff --git a/unit_tests/memory_manager/memory_manager_tests.cpp b/unit_tests/memory_manager/memory_manager_tests.cpp index 6258a2ae84..edd5d34461 100644 --- a/unit_tests/memory_manager/memory_manager_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_tests.cpp @@ -220,15 +220,6 @@ TEST_F(MemoryAllocatorTest, allocateGraphicsPageAligned) { memoryManager->freeGraphicsMemory(allocation); } -TEST_F(MemoryAllocatorTest, allocateGraphicsMoreThanPageAligned) { - unsigned int alignment = 6144; - - auto allocation = memoryManager->allocateGraphicsMemory(sizeof(char), 6144, false, false); - EXPECT_NE(nullptr, allocation); - EXPECT_EQ(0u, reinterpret_cast(allocation->getUnderlyingBuffer()) & (alignment - 1)); - memoryManager->freeGraphicsMemory(allocation); -} - TEST_F(MemoryAllocatorTest, AlignedHostPtrWithAlignedSizeWhenAskedForGraphicsAllocationReturnsNullStorageFromHostPtrManager) { auto ptr = (void *)0x1000; MockMemoryManager mockMemoryManager(*executionEnvironment); @@ -602,7 +593,10 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryIsCall EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); memoryManager.freeGraphicsMemory(allocation); - allocation = memoryManager.allocateGraphicsMemory(size, MemoryConstants::preferredAlignment, false, false); + AllocationProperties properties; + properties.size = size; + properties.alignment = MemoryConstants::preferredAlignment; + allocation = memoryManager.allocateGraphicsMemoryWithProperties(properties); EXPECT_NE(nullptr, allocation); EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); memoryManager.freeGraphicsMemory(allocation); @@ -624,7 +618,7 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledWhenAllocate public: MockOsAgnosticManagerWithFailingAllocate(bool enable64kbPages, ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(enable64kbPages, false, executionEnvironment) {} - GraphicsAllocation *allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) override { + GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override { return nullptr; } }; @@ -643,7 +637,7 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryWithPt void *ptr = reinterpret_cast(0x1001); auto size = MemoryConstants::pageSize; - auto allocation = memoryManager.allocateGraphicsMemory(size, ptr, false); + auto allocation = memoryManager.allocateGraphicsMemory(size, ptr); ASSERT_NE(nullptr, allocation); EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); @@ -843,11 +837,27 @@ TEST(OsAgnosticMemoryManager, pleaseDetectLeak) { MemoryManagement::fastLeaksDetectionMode = MemoryManagement::LeakDetectionMode::EXPECT_TO_LEAK; } -TEST(OsAgnosticMemoryManager, alignmentIsCorrect) { +TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocateMemoryWithNoAlignmentProvidedThenAllocationIsAlignedToPageSize) { ExecutionEnvironment executionEnvironment; OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); - const size_t alignment = 0; - auto ga = memoryManager.allocateGraphicsMemory(MemoryConstants::pageSize >> 1, alignment, false, false); + AllocationProperties properties; + properties.size = MemoryConstants::pageSize >> 1; + properties.alignment = 0; + auto ga = memoryManager.allocateGraphicsMemoryWithProperties(properties); + uintptr_t ptr = reinterpret_cast(ga->getUnderlyingBuffer()); + ptr &= (MemoryConstants::allocationAlignment - 1); + EXPECT_EQ(ptr, 0u); + + memoryManager.freeGraphicsMemory(ga); +} + +TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocateMemoryWithAlignmentNotAlignedToPageSizeThenAlignmentIsAlignedUp) { + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); + AllocationProperties properties; + properties.size = MemoryConstants::pageSize >> 1; + properties.alignment = MemoryConstants::pageSize - 1; + auto ga = memoryManager.allocateGraphicsMemoryWithProperties(properties); uintptr_t ptr = reinterpret_cast(ga->getUnderlyingBuffer()); ptr &= (MemoryConstants::allocationAlignment - 1); EXPECT_EQ(ptr, 0u); diff --git a/unit_tests/memory_manager/svm_memory_manager.cpp b/unit_tests/memory_manager/svm_memory_manager.cpp index 04caa990ee..40f0715db9 100644 --- a/unit_tests/memory_manager/svm_memory_manager.cpp +++ b/unit_tests/memory_manager/svm_memory_manager.cpp @@ -110,7 +110,7 @@ TEST_F(SVMMemoryAllocatorTest, WhenCouldNotAllocateInMemoryManagerThenReturnsNul public: MockMemManager(ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(false, false, executionEnvironment){}; - GraphicsAllocation *allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) override { + GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override { return nullptr; } }; diff --git a/unit_tests/mocks/linux/mock_drm_memory_manager.h b/unit_tests/mocks/linux/mock_drm_memory_manager.h index 799a4a7dc0..870d8fa258 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::allocateGraphicsMemoryWithHostPtr; using DrmMemoryManager::allocUserptr; using DrmMemoryManager::setDomainCpu; using DrmMemoryManager::sharingBufferObjects; diff --git a/unit_tests/mocks/mock_device.h b/unit_tests/mocks/mock_device.h index 7890a7e98a..0ed0f0bd42 100644 --- a/unit_tests/mocks/mock_device.h +++ b/unit_tests/mocks/mock_device.h @@ -95,10 +95,11 @@ class MockDevice : public Device { void allocatePreemptionAllocationIfNotPresent() { if (this->preemptionAllocation == nullptr) { if (preemptionMode == PreemptionMode::MidThread || isSourceLevelDebuggerActive()) { - size_t requiredSize = hwInfo.capabilityTable.requiredPreemptionSurfaceSize; - size_t alignment = 256 * MemoryConstants::kiloByte; - bool uncacheable = getWaTable()->waCSRUncachable; - this->preemptionAllocation = executionEnvironment->memoryManager->allocateGraphicsMemory(requiredSize, alignment, false, uncacheable); + AllocationProperties allocationProperties; + allocationProperties.size = hwInfo.capabilityTable.requiredPreemptionSurfaceSize; + allocationProperties.flags.uncacheable = getWaTable()->waCSRUncachable; + allocationProperties.alignment = 256 * MemoryConstants::kiloByte; + this->preemptionAllocation = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(allocationProperties); this->engines[defaultEngineIndex].commandStreamReceiver->setPreemptionCsrAllocation(preemptionAllocation); } } diff --git a/unit_tests/mocks/mock_memory_manager.cpp b/unit_tests/mocks/mock_memory_manager.cpp index e26db56637..4547f482c6 100644 --- a/unit_tests/mocks/mock_memory_manager.cpp +++ b/unit_tests/mocks/mock_memory_manager.cpp @@ -63,12 +63,12 @@ GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryInDevicePool(const return allocation; } -GraphicsAllocation *MockMemoryManager::allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) { +GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) { if (failInAllocateWithSizeAndAlignment) { return nullptr; } allocationCreated = true; - return OsAgnosticMemoryManager::allocateGraphicsMemory(size, alignment, forcePin, uncacheable); + return OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment(allocationData); } FailMemoryManager::FailMemoryManager(int32_t fail) { diff --git a/unit_tests/mocks/mock_memory_manager.h b/unit_tests/mocks/mock_memory_manager.h index 4d6b082c3b..0ee9e7d66d 100644 --- a/unit_tests/mocks/mock_memory_manager.h +++ b/unit_tests/mocks/mock_memory_manager.h @@ -38,7 +38,7 @@ class MockMemoryManager : public OsAgnosticMemoryManager { int redundancyRatio = 1; GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override; - GraphicsAllocation *allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) override; + GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override; void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) override { freeGraphicsMemoryCalled++; @@ -98,12 +98,17 @@ class FailMemoryManager : public MockMemoryManager { delete agnostic; } }; - GraphicsAllocation *allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) override { + GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override { if (fail <= 0) { return nullptr; } fail--; - GraphicsAllocation *alloc = agnostic->allocateGraphicsMemory(size, alignment, forcePin, uncacheable); + AllocationProperties properties; + properties.alignment = allocationData.alignment; + properties.size = allocationData.size; + properties.flags.forcePin = allocationData.flags.forcePin; + properties.flags.uncacheable = allocationData.flags.uncacheable; + GraphicsAllocation *alloc = agnostic->allocateGraphicsMemoryWithProperties(properties); allocations.push_back(alloc); return alloc; }; 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 7c9853ce8a..b3107c01f8 100644 --- a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp @@ -46,6 +46,14 @@ using namespace OCLRT; +AllocationProperties createAllocationProperties(size_t size, bool forcePin) { + AllocationProperties properties; + properties.size = size; + properties.alignment = MemoryConstants::preferredAlignment; + properties.flags.forcePin = forcePin; + return properties; +} + class DrmMemoryManagerFixture : public MemoryManagementFixture { public: TestedDrmMemoryManager *memoryManager = nullptr; @@ -78,6 +86,7 @@ class DrmMemoryManagerFixture : public MemoryManagementFixture { protected: ExecutionEnvironment *executionEnvironment; DrmMockCustom::IoctlResExt ioctlResExt = {0, 0}; + AllocationData allocationData; }; class DrmMemoryManagerFixtureWithoutQuietIoctlExpectation : public MemoryManagementFixture { @@ -187,7 +196,7 @@ TEST_F(DrmMemoryManagerTest, pinAfterAllocateWhenAskedAndAllowedAndBigAllocation auto memoryManager = std::make_unique(this->mock, true, false, *executionEnvironment); ASSERT_NE(nullptr, memoryManager->getPinBB()); - auto alloc = memoryManager->allocateGraphicsMemory(10 * 1014 * 1024, 1024, true, false); + auto alloc = static_cast(memoryManager->allocateGraphicsMemoryWithProperties(createAllocationProperties(10 * MemoryConstants::megaByte, true))); ASSERT_NE(nullptr, alloc); EXPECT_NE(nullptr, alloc->getBO()); @@ -203,7 +212,7 @@ TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenAskedAndAllowedButSmallAll ASSERT_NE(nullptr, memoryManager->getPinBB()); // one page is too small for early pinning - auto alloc = memoryManager->allocateGraphicsMemory(4 * 1024, 1024, true, false); + auto alloc = static_cast(memoryManager->allocateGraphicsMemoryWithProperties(createAllocationProperties(MemoryConstants::pageSize, true))); ASSERT_NE(nullptr, alloc); EXPECT_NE(nullptr, alloc->getBO()); @@ -218,7 +227,7 @@ TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenNotAskedButAllowed) { auto memoryManager = std::make_unique(this->mock, true, false, *executionEnvironment); ASSERT_NE(nullptr, memoryManager->getPinBB()); - auto alloc = memoryManager->allocateGraphicsMemory(1024, 1024, false, false); + auto alloc = static_cast(memoryManager->allocateGraphicsMemoryWithProperties(createAllocationProperties(MemoryConstants::pageSize, false))); ASSERT_NE(nullptr, alloc); EXPECT_NE(nullptr, alloc->getBO()); @@ -232,7 +241,7 @@ TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenAskedButNotAllowed) { auto memoryManager = std::make_unique(this->mock, false, false, *executionEnvironment); - auto alloc = memoryManager->allocateGraphicsMemory(1024, 1024, true, false); + auto alloc = static_cast(memoryManager->allocateGraphicsMemoryWithProperties(createAllocationProperties(MemoryConstants::pageSize, true))); ASSERT_NE(nullptr, alloc); EXPECT_NE(nullptr, alloc->getBO()); @@ -249,14 +258,15 @@ TEST_F(DrmMemoryManagerTest, pinAfterAllocateWhenAskedAndAllowedAndBigAllocation auto memoryManager = std::make_unique(this->mock, true, false, *executionEnvironment); ASSERT_NE(nullptr, memoryManager->getPinBB()); - size_t size = 10 * 1024 * 1024; - void *ptr = ::alignedMalloc(size, 4096); - auto alloc = memoryManager->allocateGraphicsMemory(size, ptr, true); + allocationData.size = 10 * 1024 * 1024; + allocationData.hostPtr = ::alignedMalloc(allocationData.size, 4096); + allocationData.flags.forcePin = true; + auto alloc = memoryManager->allocateGraphicsMemoryWithHostPtr(allocationData); ASSERT_NE(nullptr, alloc); EXPECT_NE(nullptr, alloc->getBO()); memoryManager->freeGraphicsMemory(alloc); - ::alignedFree(ptr); + ::alignedFree(const_cast(allocationData.hostPtr)); } TEST_F(DrmMemoryManagerTest, givenSmallAllocationHostPtrAllocationWhenForcePinIsTrueThenBufferObjectIsNotPinned) { @@ -268,15 +278,16 @@ TEST_F(DrmMemoryManagerTest, givenSmallAllocationHostPtrAllocationWhenForcePinIs ASSERT_NE(nullptr, memoryManager->getPinBB()); // one page is too small for early pinning - size_t size = 4 * 1024; - void *ptr = ::alignedMalloc(size, 4096); - auto alloc = memoryManager->allocateGraphicsMemory(size, ptr, true); + allocationData.size = 4 * 1024; + allocationData.hostPtr = ::alignedMalloc(allocationData.size, 4096); + allocationData.flags.forcePin = true; + auto alloc = memoryManager->allocateGraphicsMemoryWithHostPtr(allocationData); ASSERT_NE(nullptr, alloc); EXPECT_NE(nullptr, alloc->getBO()); memoryManager->freeGraphicsMemory(alloc); - ::alignedFree(ptr); + ::alignedFree(const_cast(allocationData.hostPtr)); } TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenNotAskedButAllowedHostPtr) { @@ -287,15 +298,15 @@ TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenNotAskedButAllowedHostPtr) auto memoryManager = std::make_unique(this->mock, true, false, *executionEnvironment); ASSERT_NE(nullptr, memoryManager->getPinBB()); - size_t size = 4 * 1024; - void *ptr = ::alignedMalloc(size, 4096); - auto alloc = memoryManager->allocateGraphicsMemory(size, ptr, false); + allocationData.size = 4 * 1024; + allocationData.hostPtr = ::alignedMalloc(allocationData.size, 4096); + auto alloc = memoryManager->allocateGraphicsMemoryWithHostPtr(allocationData); ASSERT_NE(nullptr, alloc); EXPECT_NE(nullptr, alloc->getBO()); memoryManager->freeGraphicsMemory(alloc); - ::alignedFree(ptr); + ::alignedFree(const_cast(allocationData.hostPtr)); } TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenAskedButNotAllowedHostPtr) { @@ -305,15 +316,16 @@ TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenAskedButNotAllowedHostPtr) auto memoryManager = std::make_unique(this->mock, false, false, *executionEnvironment); - size_t size = 4 * 1024; - void *ptr = ::alignedMalloc(size, 4096); - auto alloc = memoryManager->allocateGraphicsMemory(size, ptr, true); + allocationData.size = 4 * 1024; + allocationData.hostPtr = ::alignedMalloc(allocationData.size, 4096); + allocationData.flags.forcePin = true; + auto alloc = memoryManager->allocateGraphicsMemoryWithHostPtr(allocationData); ASSERT_NE(nullptr, alloc); EXPECT_NE(nullptr, alloc->getBO()); memoryManager->freeGraphicsMemory(alloc); - ::alignedFree(ptr); + ::alignedFree(const_cast(allocationData.hostPtr)); } TEST_F(DrmMemoryManagerTest, unreference) { @@ -2394,7 +2406,7 @@ TEST(DrmMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryIsCalledThenM EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); memoryManager->freeGraphicsMemory(allocation); - allocation = memoryManager->allocateGraphicsMemory(size, MemoryConstants::preferredAlignment, false, false); + allocation = memoryManager->allocateGraphicsMemoryWithProperties(createAllocationProperties(size, false)); EXPECT_NE(nullptr, allocation); EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); memoryManager->freeGraphicsMemory(allocation); @@ -2405,7 +2417,7 @@ TEST(DrmMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryWithPtrIsCall std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true, executionEnvironment)); void *ptr = reinterpret_cast(0x1001); auto size = 4096u; - auto allocation = memoryManager->allocateGraphicsMemory(size, ptr, false); + auto allocation = memoryManager->allocateGraphicsMemory(size, ptr); ASSERT_NE(nullptr, allocation); EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); memoryManager->freeGraphicsMemory(allocation); @@ -2578,7 +2590,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenValidateHostPtrMemoryE size_t size = 10 * 1024 * 1024; void *ptr = ::alignedMalloc(size, 4096); - auto alloc = memoryManager->allocateGraphicsMemory(size, ptr, false); + auto alloc = memoryManager->allocateGraphicsMemory(size, ptr); ASSERT_NE(nullptr, alloc); EXPECT_NE(nullptr, alloc->getBO()); @@ -2610,14 +2622,14 @@ TEST_F(DrmMemoryManagerTest, givenForcePinAndHostMemoryValidationEnabledWhenSmal ASSERT_NE(nullptr, memoryManager->getPinBB()); // one page is too small for early pinning but pinning is used for host memory validation - size_t size = 4 * 1024; - void *ptr = ::alignedMalloc(size, 4096); - auto alloc = memoryManager->allocateGraphicsMemory(size, ptr, false); + allocationData.size = 4 * 1024; + allocationData.hostPtr = ::alignedMalloc(allocationData.size, 4096); + auto alloc = memoryManager->allocateGraphicsMemoryWithHostPtr(allocationData); ASSERT_NE(nullptr, alloc); EXPECT_NE(nullptr, alloc->getBO()); memoryManager->freeGraphicsMemory(alloc); - ::alignedFree(ptr); + ::alignedFree(const_cast(allocationData.hostPtr)); } TEST_F(DrmMemoryManagerTest, givenForcePinAllowedAndNoPinBBInMemoryManagerWhenAllocationWithForcePinFlagTrueIsCreatedThenAllocationIsNotPinned) { @@ -2629,7 +2641,7 @@ TEST_F(DrmMemoryManagerTest, givenForcePinAllowedAndNoPinBBInMemoryManagerWhenAl EXPECT_EQ(nullptr, memoryManager->getPinBB()); mock->ioctl_res = 0; - auto allocation = memoryManager->allocateGraphicsMemory(4096, 4096, true, false); + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(createAllocationProperties(MemoryConstants::pageSize, true)); EXPECT_NE(nullptr, allocation); memoryManager->freeGraphicsMemory(allocation); } @@ -2694,16 +2706,18 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenForcePinNotAllowedAndH mock->ioctl_expected.gemClose = 1; mock->ioctl_expected.gemWait = 1; - size_t size = 1024; - void *ptr = ::alignedMalloc(size, 4096); - auto alloc = memoryManager->allocateGraphicsMemory(size, ptr, true); + AllocationData allocationData; + allocationData.size = 4 * 1024; + allocationData.hostPtr = ::alignedMalloc(allocationData.size, 4096); + allocationData.flags.forcePin = true; + auto alloc = memoryManager->allocateGraphicsMemoryWithHostPtr(allocationData); ASSERT_NE(nullptr, alloc); EXPECT_NE(nullptr, alloc->getBO()); memoryManager->freeGraphicsMemory(alloc); mock->testIoctls(); - ::alignedFree(ptr); + ::alignedFree(const_cast(allocationData.hostPtr)); } TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenForcePinNotAllowedAndHostMemoryValidationDisabledWhenAllocationIsCreatedThenBufferObjectIsNotPinned) { @@ -2713,16 +2727,18 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenForcePinNotAllowedAndH mock->ioctl_expected.gemClose = 1; mock->ioctl_expected.gemWait = 1; - size_t size = 10 * 1024 * 1024; // bigger than threshold - void *ptr = ::alignedMalloc(size, 4096); - auto alloc = memoryManager->allocateGraphicsMemory(size, ptr, true); + AllocationData allocationData; + allocationData.size = 10 * 1024 * 1024; // bigger than threshold + allocationData.hostPtr = ::alignedMalloc(allocationData.size, 4096); + allocationData.flags.forcePin = true; + auto alloc = memoryManager->allocateGraphicsMemoryWithHostPtr(allocationData); ASSERT_NE(nullptr, alloc); EXPECT_NE(nullptr, alloc->getBO()); memoryManager->freeGraphicsMemory(alloc); mock->testIoctls(); - ::alignedFree(ptr); + ::alignedFree(const_cast(allocationData.hostPtr)); } TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledValidateHostMemoryWhenReadOnlyPointerCausesPinningFailWithEfaultThenPopulateOsHandlesMarksFragmentsToFree) { 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 90eed7f14f..f1d9d05362 100644 --- a/unit_tests/os_interface/windows/device_command_stream_tests.cpp +++ b/unit_tests/os_interface/windows/device_command_stream_tests.cpp @@ -370,7 +370,7 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafDisabledWhenFlushIsCalledWithAll LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - auto linearStreamAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + auto linearStreamAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); ASSERT_NE(nullptr, linearStreamAllocation); linearStreamAllocation->setAllocationType(GraphicsAllocation::AllocationType::LINEAR_STREAM); ResidencyContainer allocationsForResidency = {linearStreamAllocation}; @@ -406,7 +406,7 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithResi LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - auto linearStreamAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + auto linearStreamAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); ASSERT_NE(nullptr, linearStreamAllocation); linearStreamAllocation->setAllocationType(GraphicsAllocation::AllocationType::LINEAR_STREAM); @@ -431,7 +431,7 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllo LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - auto linearStreamAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + auto linearStreamAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); ASSERT_NE(nullptr, linearStreamAllocation); linearStreamAllocation->setAllocationType(GraphicsAllocation::AllocationType::LINEAR_STREAM); ResidencyContainer allocationsForResidency = {linearStreamAllocation}; @@ -453,7 +453,7 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllo LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - auto fillPatternAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + auto fillPatternAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); ASSERT_NE(nullptr, fillPatternAllocation); fillPatternAllocation->setAllocationType(GraphicsAllocation::AllocationType::FILL_PATTERN); ResidencyContainer allocationsForResidency = {fillPatternAllocation}; @@ -475,7 +475,7 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllo LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - auto nonLinearStreamAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + auto nonLinearStreamAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t)); ASSERT_NE(nullptr, nonLinearStreamAllocation); ResidencyContainer allocationsForResidency = {nonLinearStreamAllocation}; diff --git a/unit_tests/os_interface/windows/wddm_memory_manager_allocate_in_device_pool_tests.inl b/unit_tests/os_interface/windows/wddm_memory_manager_allocate_in_device_pool_tests.inl index c629961a1c..2fe69505a2 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_allocate_in_device_pool_tests.inl +++ b/unit_tests/os_interface/windows/wddm_memory_manager_allocate_in_device_pool_tests.inl @@ -15,7 +15,6 @@ TEST_F(WddmMemoryManagerSimpleTest, givenUseSystemMemorySetToTrueWhenAllocateInD memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, executionEnvironment)); MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success; AllocationData allocData; - allocData.allFlags = 0; allocData.size = MemoryConstants::pageSize; allocData.flags.useSystemMemory = true; allocData.flags.allocateMemory = true; 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 6db79beee9..c9992a1ae2 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp @@ -121,7 +121,10 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemory EXPECT_TRUE(allocation->gmm->useSystemMemoryPool); memoryManager->freeGraphicsMemory(allocation); - allocation = memoryManager->allocateGraphicsMemory(size, MemoryConstants::preferredAlignment, false, false); + AllocationProperties properties; + properties.size = size; + properties.alignment = sizeof(uint32_t); + allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties); EXPECT_NE(nullptr, allocation); EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); EXPECT_TRUE(allocation->gmm->useSystemMemoryPool); @@ -142,7 +145,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemory memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, executionEnvironment)); void *ptr = reinterpret_cast(0x1001); auto size = 4096u; - auto allocation = memoryManager->allocateGraphicsMemory(size, ptr, false); + auto allocation = memoryManager->allocateGraphicsMemory(size, ptr); ASSERT_NE(nullptr, allocation); EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); for (size_t i = 0; i < allocation->fragmentsStorage.fragmentCount; i++) { diff --git a/unit_tests/preemption/preemption_tests.cpp b/unit_tests/preemption/preemption_tests.cpp index 9fd926878b..9da369a393 100644 --- a/unit_tests/preemption/preemption_tests.cpp +++ b/unit_tests/preemption/preemption_tests.cpp @@ -467,11 +467,11 @@ HWTEST_F(MidThreadPreemptionTests, givenMidThreadPreemptionWhenFailingOnCsrSurfa public: FailingMemoryManager(ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(false, false, executionEnvironment) {} - GraphicsAllocation *allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) override { + GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override { if (++allocateGraphicsMemoryCount > gpgpuEngineInstances.size()) { return nullptr; } - return OsAgnosticMemoryManager::allocateGraphicsMemory(size, alignment, forcePin, uncacheable); + return OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment(allocationData); } uint32_t allocateGraphicsMemoryCount = 0;