Skip to content

Commit 1301f77

Browse files
Move createDrmAllocation to common file
Related-To: NEO-6149 Signed-off-by: Szymon Morek <[email protected]>
1 parent 8b16874 commit 1301f77

File tree

4 files changed

+66
-30
lines changed

4 files changed

+66
-30
lines changed

opencl/test/unit_test/os_interface/linux/drm_memory_manager_local_memory_tests_dg1.cpp

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ TEST_F(DrmMemoryManagerLocalMemoryMemoryBankTest, givenDeviceMemoryWhenGraphicsA
599599
allocData.flags.useSystemMemory = false;
600600
allocData.type = GraphicsAllocation::AllocationType::BUFFER;
601601
allocData.rootDeviceIndex = rootDeviceIndex;
602-
602+
allocData.storageInfo.memoryBanks = 1u;
603603
memoryManager->allocateGraphicsMemoryInDevicePool(allocData, status);
604604
EXPECT_TRUE(memoryManager->memoryBankIsOne);
605605
}
@@ -1682,10 +1682,43 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, givenAllocationWithLargeBufferWhenAlloca
16821682
EXPECT_EQ(boSize, bo->peekSize());
16831683
EXPECT_EQ(boSize, 3 * MemoryConstants::pageSize64k);
16841684
}
1685-
16861685
memoryManager->freeGraphicsMemory(allocation);
16871686
}
16881687

1688+
TEST_F(DrmMemoryManagerLocalMemoryTest, givenAllocationWithKernelIsaWhenAllocationInDevicePoolAndDeviceBitfieldWithHolesThenCorrectAllocationCreated) {
1689+
MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success;
1690+
AllocationData allocData;
1691+
allocData.allFlags = 0;
1692+
allocData.size = MemoryConstants::pageSize;
1693+
allocData.flags.allocateMemory = true;
1694+
allocData.type = GraphicsAllocation::AllocationType::KERNEL_ISA;
1695+
allocData.storageInfo.memoryBanks = 0b1011;
1696+
allocData.storageInfo.multiStorage = false;
1697+
allocData.rootDeviceIndex = rootDeviceIndex;
1698+
1699+
auto kernelIsaAllocation = static_cast<DrmAllocation *>(memoryManager->allocateGraphicsMemoryInDevicePool(allocData, status));
1700+
1701+
EXPECT_NE(nullptr, kernelIsaAllocation);
1702+
1703+
auto gpuAddress = kernelIsaAllocation->getGpuAddress();
1704+
auto &bos = kernelIsaAllocation->getBOs();
1705+
1706+
EXPECT_NE(nullptr, bos[0]);
1707+
EXPECT_EQ(gpuAddress, bos[0]->peekAddress());
1708+
EXPECT_NE(nullptr, bos[1]);
1709+
EXPECT_EQ(gpuAddress, bos[1]->peekAddress());
1710+
1711+
EXPECT_EQ(nullptr, bos[2]);
1712+
1713+
EXPECT_NE(nullptr, bos[3]);
1714+
EXPECT_EQ(gpuAddress, bos[3]->peekAddress());
1715+
1716+
auto &storageInfo = kernelIsaAllocation->storageInfo;
1717+
EXPECT_EQ(0b1011u, storageInfo.memoryBanks.to_ulong());
1718+
1719+
memoryManager->freeGraphicsMemory(kernelIsaAllocation);
1720+
}
1721+
16891722
TEST_F(DrmMemoryManagerLocalMemoryTest, givenAllocationWithInvalidCacheRegionWhenAllocatingInDevicePoolThenReturnNullptr) {
16901723
MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success;
16911724
AllocationData allocData;

shared/source/os_interface/linux/drm_memory_manager.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,4 +1316,35 @@ BufferObject *DrmMemoryManager::createBufferObjectInMemoryRegion(Drm *drm,
13161316
return bo;
13171317
}
13181318

1319+
bool DrmMemoryManager::createDrmAllocation(Drm *drm, DrmAllocation *allocation, uint64_t gpuAddress, size_t maxOsContextCount) {
1320+
std::array<std::unique_ptr<BufferObject>, EngineLimits::maxHandleCount> bos{};
1321+
auto &storageInfo = allocation->storageInfo;
1322+
auto boAddress = gpuAddress;
1323+
auto currentBank = 0u;
1324+
for (auto handleId = 0u; handleId < storageInfo.getNumBanks(); handleId++, currentBank++) {
1325+
uint32_t memoryBanks = static_cast<uint32_t>(storageInfo.memoryBanks.to_ulong());
1326+
if (storageInfo.getNumBanks() > 1) {
1327+
//check if we have this bank, if not move to next one
1328+
//we may have holes in memoryBanks that we need to skip i.e. memoryBanks 1101 and 3 handle allocation
1329+
while (!(memoryBanks & (1u << currentBank))) {
1330+
currentBank++;
1331+
}
1332+
memoryBanks &= 1u << currentBank;
1333+
}
1334+
auto boSize = alignUp(allocation->getGmm(handleId)->gmmResourceInfo->getSizeAllocation(), MemoryConstants::pageSize64k);
1335+
bos[handleId] = std::unique_ptr<BufferObject>(createBufferObjectInMemoryRegion(drm, boAddress, boSize, memoryBanks, maxOsContextCount));
1336+
if (nullptr == bos[handleId]) {
1337+
return false;
1338+
}
1339+
allocation->getBufferObjectToModify(currentBank) = bos[handleId].get();
1340+
if (storageInfo.multiStorage) {
1341+
boAddress += boSize;
1342+
}
1343+
}
1344+
for (auto &bo : bos) {
1345+
bo.release();
1346+
}
1347+
return true;
1348+
}
1349+
13191350
} // namespace NEO

shared/source/os_interface/linux/drm_memory_manager_local_memory.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
#include "shared/source/os_interface/linux/drm_memory_manager.h"
1010

1111
namespace NEO {
12-
bool DrmMemoryManager::createDrmAllocation(Drm *drm, DrmAllocation *allocation, uint64_t gpuAddress, size_t maxOsContextCount) {
13-
return false;
14-
}
1512

1613
DrmAllocation *DrmMemoryManager::createUSMHostAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool hasMappedPtr) {
1714
drm_prime_handle openFd = {0, 0, 0};

shared/source/os_interface/linux/drm_memory_manager_local_memory_dg1.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -112,31 +112,6 @@ DrmAllocation *DrmMemoryManager::createAllocWithAlignment(const AllocationData &
112112
}
113113
}
114114

115-
bool DrmMemoryManager::createDrmAllocation(Drm *drm, DrmAllocation *allocation, uint64_t gpuAddress, size_t maxOsContextCount) {
116-
std::array<std::unique_ptr<BufferObject>, EngineLimits::maxHandleCount> bos{};
117-
auto &storageInfo = allocation->storageInfo;
118-
auto boAddress = gpuAddress;
119-
for (auto handleId = 0u; handleId < storageInfo.getNumBanks(); handleId++) {
120-
uint32_t memoryBanks = 1u;
121-
if (storageInfo.getNumBanks() > 1) {
122-
memoryBanks &= 1u << handleId;
123-
}
124-
auto boSize = alignUp(allocation->getGmm(handleId)->gmmResourceInfo->getSizeAllocation(), MemoryConstants::pageSize64k);
125-
bos[handleId] = std::unique_ptr<BufferObject>(createBufferObjectInMemoryRegion(drm, boAddress, boSize, memoryBanks, maxOsContextCount));
126-
if (nullptr == bos[handleId]) {
127-
return false;
128-
}
129-
allocation->getBufferObjectToModify(handleId) = bos[handleId].get();
130-
if (storageInfo.multiStorage) {
131-
boAddress += boSize;
132-
}
133-
}
134-
for (auto &bo : bos) {
135-
bo.release();
136-
}
137-
return true;
138-
}
139-
140115
void *DrmMemoryManager::lockResourceInLocalMemoryImpl(BufferObject *bo) {
141116
if (bo == nullptr)
142117
return nullptr;

0 commit comments

Comments
 (0)