diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_local_memory_tests_dg1.cpp b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_local_memory_tests_dg1.cpp index 2260e8ccf6..333333ec20 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_local_memory_tests_dg1.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_local_memory_tests_dg1.cpp @@ -599,7 +599,7 @@ TEST_F(DrmMemoryManagerLocalMemoryMemoryBankTest, givenDeviceMemoryWhenGraphicsA allocData.flags.useSystemMemory = false; allocData.type = GraphicsAllocation::AllocationType::BUFFER; allocData.rootDeviceIndex = rootDeviceIndex; - + allocData.storageInfo.memoryBanks = 1u; memoryManager->allocateGraphicsMemoryInDevicePool(allocData, status); EXPECT_TRUE(memoryManager->memoryBankIsOne); } @@ -1682,10 +1682,43 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, givenAllocationWithLargeBufferWhenAlloca EXPECT_EQ(boSize, bo->peekSize()); EXPECT_EQ(boSize, 3 * MemoryConstants::pageSize64k); } - memoryManager->freeGraphicsMemory(allocation); } +TEST_F(DrmMemoryManagerLocalMemoryTest, givenAllocationWithKernelIsaWhenAllocationInDevicePoolAndDeviceBitfieldWithHolesThenCorrectAllocationCreated) { + MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success; + AllocationData allocData; + allocData.allFlags = 0; + allocData.size = MemoryConstants::pageSize; + allocData.flags.allocateMemory = true; + allocData.type = GraphicsAllocation::AllocationType::KERNEL_ISA; + allocData.storageInfo.memoryBanks = 0b1011; + allocData.storageInfo.multiStorage = false; + allocData.rootDeviceIndex = rootDeviceIndex; + + auto kernelIsaAllocation = static_cast(memoryManager->allocateGraphicsMemoryInDevicePool(allocData, status)); + + EXPECT_NE(nullptr, kernelIsaAllocation); + + auto gpuAddress = kernelIsaAllocation->getGpuAddress(); + auto &bos = kernelIsaAllocation->getBOs(); + + EXPECT_NE(nullptr, bos[0]); + EXPECT_EQ(gpuAddress, bos[0]->peekAddress()); + EXPECT_NE(nullptr, bos[1]); + EXPECT_EQ(gpuAddress, bos[1]->peekAddress()); + + EXPECT_EQ(nullptr, bos[2]); + + EXPECT_NE(nullptr, bos[3]); + EXPECT_EQ(gpuAddress, bos[3]->peekAddress()); + + auto &storageInfo = kernelIsaAllocation->storageInfo; + EXPECT_EQ(0b1011u, storageInfo.memoryBanks.to_ulong()); + + memoryManager->freeGraphicsMemory(kernelIsaAllocation); +} + TEST_F(DrmMemoryManagerLocalMemoryTest, givenAllocationWithInvalidCacheRegionWhenAllocatingInDevicePoolThenReturnNullptr) { MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success; AllocationData allocData; diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index ce2f3c08d8..b176c8fe94 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -1316,4 +1316,35 @@ BufferObject *DrmMemoryManager::createBufferObjectInMemoryRegion(Drm *drm, return bo; } +bool DrmMemoryManager::createDrmAllocation(Drm *drm, DrmAllocation *allocation, uint64_t gpuAddress, size_t maxOsContextCount) { + std::array, EngineLimits::maxHandleCount> bos{}; + auto &storageInfo = allocation->storageInfo; + auto boAddress = gpuAddress; + auto currentBank = 0u; + for (auto handleId = 0u; handleId < storageInfo.getNumBanks(); handleId++, currentBank++) { + uint32_t memoryBanks = static_cast(storageInfo.memoryBanks.to_ulong()); + if (storageInfo.getNumBanks() > 1) { + //check if we have this bank, if not move to next one + //we may have holes in memoryBanks that we need to skip i.e. memoryBanks 1101 and 3 handle allocation + while (!(memoryBanks & (1u << currentBank))) { + currentBank++; + } + memoryBanks &= 1u << currentBank; + } + auto boSize = alignUp(allocation->getGmm(handleId)->gmmResourceInfo->getSizeAllocation(), MemoryConstants::pageSize64k); + bos[handleId] = std::unique_ptr(createBufferObjectInMemoryRegion(drm, boAddress, boSize, memoryBanks, maxOsContextCount)); + if (nullptr == bos[handleId]) { + return false; + } + allocation->getBufferObjectToModify(currentBank) = bos[handleId].get(); + if (storageInfo.multiStorage) { + boAddress += boSize; + } + } + for (auto &bo : bos) { + bo.release(); + } + return true; +} + } // namespace NEO diff --git a/shared/source/os_interface/linux/drm_memory_manager_local_memory.cpp b/shared/source/os_interface/linux/drm_memory_manager_local_memory.cpp index 0907ec8fbe..0cb61f0d43 100644 --- a/shared/source/os_interface/linux/drm_memory_manager_local_memory.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager_local_memory.cpp @@ -9,9 +9,6 @@ #include "shared/source/os_interface/linux/drm_memory_manager.h" namespace NEO { -bool DrmMemoryManager::createDrmAllocation(Drm *drm, DrmAllocation *allocation, uint64_t gpuAddress, size_t maxOsContextCount) { - return false; -} DrmAllocation *DrmMemoryManager::createUSMHostAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool hasMappedPtr) { drm_prime_handle openFd = {0, 0, 0}; diff --git a/shared/source/os_interface/linux/drm_memory_manager_local_memory_dg1.cpp b/shared/source/os_interface/linux/drm_memory_manager_local_memory_dg1.cpp index c671d13828..720251fa7e 100644 --- a/shared/source/os_interface/linux/drm_memory_manager_local_memory_dg1.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager_local_memory_dg1.cpp @@ -112,31 +112,6 @@ DrmAllocation *DrmMemoryManager::createAllocWithAlignment(const AllocationData & } } -bool DrmMemoryManager::createDrmAllocation(Drm *drm, DrmAllocation *allocation, uint64_t gpuAddress, size_t maxOsContextCount) { - std::array, EngineLimits::maxHandleCount> bos{}; - auto &storageInfo = allocation->storageInfo; - auto boAddress = gpuAddress; - for (auto handleId = 0u; handleId < storageInfo.getNumBanks(); handleId++) { - uint32_t memoryBanks = 1u; - if (storageInfo.getNumBanks() > 1) { - memoryBanks &= 1u << handleId; - } - auto boSize = alignUp(allocation->getGmm(handleId)->gmmResourceInfo->getSizeAllocation(), MemoryConstants::pageSize64k); - bos[handleId] = std::unique_ptr(createBufferObjectInMemoryRegion(drm, boAddress, boSize, memoryBanks, maxOsContextCount)); - if (nullptr == bos[handleId]) { - return false; - } - allocation->getBufferObjectToModify(handleId) = bos[handleId].get(); - if (storageInfo.multiStorage) { - boAddress += boSize; - } - } - for (auto &bo : bos) { - bo.release(); - } - return true; -} - void *DrmMemoryManager::lockResourceInLocalMemoryImpl(BufferObject *bo) { if (bo == nullptr) return nullptr;