Skip to content

Commit 962d98a

Browse files
Enable MemoryInfo for platforms without local mem
Query for memory regions on all platforms. Fix createPaddedAllocation when input allocation was made by KMD Resolves: NEO-6472 Signed-off-by: Szymon Morek <[email protected]>
1 parent 3599e7a commit 962d98a

File tree

5 files changed

+62
-38
lines changed

5 files changed

+62
-38
lines changed

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,6 @@
1818

1919
using namespace NEO;
2020

21-
TEST(MemoryInfo, givenNotSupportedLocalMemoryQueryingMemoryInfoThenMemoryInfoIsNotCreated) {
22-
DebugManagerStateRestore restorer;
23-
DebugManager.flags.EnableLocalMemory.set(0);
24-
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
25-
executionEnvironment->prepareRootDeviceEnvironments(1);
26-
27-
auto drm = std::make_unique<DrmTipMock>(*executionEnvironment->rootDeviceEnvironments[0]);
28-
ASSERT_NE(nullptr, drm);
29-
30-
auto ret = drm->queryMemoryInfo();
31-
auto memoryInfo = drm->getMemoryInfo();
32-
33-
EXPECT_EQ(0u, drm->ioctlCallsCount);
34-
EXPECT_TRUE(ret);
35-
EXPECT_EQ(nullptr, memoryInfo);
36-
}
37-
3821
TEST(MemoryInfo, givenMemoryRegionQuerySupportedWhenQueryingMemoryInfoThenMemoryInfoIsCreatedWithRegions) {
3922
DebugManagerStateRestore restorer;
4023
DebugManager.flags.EnableLocalMemory.set(1);

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -865,17 +865,6 @@ TEST_F(DrmMemoryManagerTestImpl, givenDrmMemoryManagerWhenGetLocalMemorySizeIsCa
865865
EXPECT_EQ(memoryInfo->getMemoryRegionSize(MemoryBanks::getBankForLocalMemory(0)), memoryManager.getLocalMemorySize(0u, 0xF));
866866
}
867867

868-
TEST_F(DrmMemoryManagerTestImpl, givenLocalMemoryDisabledWhenQueryMemoryInfoThenReturnTrueAndDontCreateMemoryInfo) {
869-
DebugManagerStateRestore restorer;
870-
DebugManager.flags.EnableLocalMemory.set(0);
871-
MockExecutionEnvironment executionEnvironment;
872-
executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();
873-
auto drm = std::make_unique<DrmMock>(*executionEnvironment.rootDeviceEnvironments[0]);
874-
auto ret = drm->queryMemoryInfo();
875-
EXPECT_TRUE(ret);
876-
EXPECT_EQ(nullptr, drm->memoryInfo);
877-
}
878-
879868
TEST_F(DrmMemoryManagerTestImpl, givenDrmMemoryManagerWhenGetLocalMemorySizeIsCalledForMemoryInfoAndInvalidDeviceBitfieldThenReturnZero) {
880869
MockExecutionEnvironment executionEnvironment;
881870
executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5710,4 +5710,49 @@ TEST_F(DrmMemoryManagerTest, givenDrmWhenRetrieveMmapOffsetForBufferObjectIsCall
57105710
}
57115711
}
57125712

5713+
TEST_F(DrmMemoryManagerTest, whenCallPaddedAllocationWithoutMmapPtrThenOnlyUserptrCalled) {
5714+
mock->ioctl_expected.gemUserptr = 1;
5715+
mock->ioctl_expected.gemClose = 1;
5716+
5717+
void *cpuPtr = (void *)0x30000;
5718+
size_t size = 0x1000;
5719+
DrmAllocation gfxAllocation(rootDeviceIndex, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, cpuPtr, size, (osHandle)1u, MemoryPool::MemoryNull);
5720+
auto gfxPaddedAllocation = memoryManager->createPaddedAllocation(&gfxAllocation, size);
5721+
ASSERT_NE(nullptr, gfxPaddedAllocation);
5722+
memoryManager->freeGraphicsMemoryImpl(gfxPaddedAllocation);
5723+
}
5724+
5725+
TEST_F(DrmMemoryManagerTest, whenCallPaddedAllocationWithMmapPtrThenMmapCalled) {
5726+
mock->ioctl_expected.gemMmap = 1;
5727+
mock->ioctl_expected.gemUserptr = 1;
5728+
mock->ioctl_expected.gemClose = 1;
5729+
BufferObject bo(mock, 1, 1024, 0);
5730+
5731+
void *cpuPtr = (void *)0x30000;
5732+
size_t size = 0x1000;
5733+
DrmAllocation gfxAllocation(rootDeviceIndex, GraphicsAllocation::AllocationType::UNKNOWN, &bo, cpuPtr, size, (osHandle)1u, MemoryPool::MemoryNull);
5734+
gfxAllocation.setMmapPtr(cpuPtr);
5735+
gfxAllocation.setMmapSize(size);
5736+
auto gfxPaddedAllocation = memoryManager->createPaddedAllocation(&gfxAllocation, size);
5737+
ASSERT_NE(nullptr, gfxPaddedAllocation);
5738+
EXPECT_TRUE(gfxAllocation.isLocked());
5739+
memoryManager->freeGraphicsMemoryImpl(gfxPaddedAllocation);
5740+
}
5741+
5742+
TEST_F(DrmMemoryManagerTest, whenCallPaddedAllocationWithMmapPtrAndFailedMmapCalledThenReturnNullptr) {
5743+
mock->ioctl_expected.gemMmap = 1;
5744+
mock->ioctl_res = -1;
5745+
5746+
BufferObject bo(mock, 1, 1024, 0);
5747+
5748+
void *cpuPtr = (void *)0x30000;
5749+
size_t size = 0x1000;
5750+
DrmAllocation gfxAllocation(rootDeviceIndex, GraphicsAllocation::AllocationType::UNKNOWN, &bo, cpuPtr, size, (osHandle)1u, MemoryPool::MemoryNull);
5751+
gfxAllocation.setMmapPtr(cpuPtr);
5752+
gfxAllocation.setMmapSize(size);
5753+
auto gfxPaddedAllocation = memoryManager->createPaddedAllocation(&gfxAllocation, size);
5754+
ASSERT_EQ(nullptr, gfxPaddedAllocation);
5755+
mock->ioctl_res = 0;
5756+
}
5757+
57135758
} // namespace NEO

shared/source/os_interface/linux/drm_memory_manager.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -705,11 +705,25 @@ GraphicsAllocation *DrmMemoryManager::createPaddedAllocation(GraphicsAllocation
705705
auto rootDeviceIndex = inputGraphicsAllocation->getRootDeviceIndex();
706706
gpuRange = acquireGpuRange(sizeWithPadding, rootDeviceIndex, HeapIndex::HEAP_STANDARD);
707707

708-
auto srcPtr = inputGraphicsAllocation->getUnderlyingBuffer();
708+
void *srcPtr = nullptr;
709+
auto drmInputAllocation = static_cast<DrmAllocation *>(inputGraphicsAllocation);
710+
if (drmInputAllocation->getMmapPtr()) {
711+
auto bo = drmInputAllocation->getBO();
712+
drm_i915_gem_mmap mmap_arg = {};
713+
mmap_arg.handle = bo->peekHandle();
714+
mmap_arg.size = bo->peekSize();
715+
if (getDrm(rootDeviceIndex).ioctl(DRM_IOCTL_I915_GEM_MMAP, &mmap_arg) != 0) {
716+
return nullptr;
717+
}
718+
srcPtr = addrToPtr(mmap_arg.addr_ptr);
719+
inputGraphicsAllocation->lock(srcPtr);
720+
} else {
721+
srcPtr = inputGraphicsAllocation->getUnderlyingBuffer();
722+
}
709723
auto srcSize = inputGraphicsAllocation->getUnderlyingBufferSize();
710724
auto alignedSrcSize = alignUp(srcSize, MemoryConstants::pageSize);
711-
auto alignedPtr = (uintptr_t)alignDown(srcPtr, MemoryConstants::pageSize);
712-
auto offset = (uintptr_t)srcPtr - alignedPtr;
725+
auto alignedPtr = reinterpret_cast<uintptr_t>(alignDown(srcPtr, MemoryConstants::pageSize));
726+
auto offset = ptrDiff(srcPtr, alignedPtr);
713727

714728
std::unique_ptr<BufferObject, BufferObject::Deleter> bo(allocUserptr(alignedPtr, alignedSrcSize, 0, rootDeviceIndex));
715729
if (!bo) {

shared/source/os_interface/linux/drm_query.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88
#include "shared/source/execution_environment/root_device_environment.h"
9-
#include "shared/source/helpers/hw_helper.h"
109
#include "shared/source/helpers/string.h"
1110
#include "shared/source/os_interface/linux/cache_info_impl.h"
1211
#include "shared/source/os_interface/linux/drm_engine_mapper.h"
@@ -49,12 +48,6 @@ std::unique_ptr<uint8_t[]> Drm::getMemoryRegions() {
4948
}
5049

5150
bool Drm::queryMemoryInfo() {
52-
auto pHwInfo = getRootDeviceEnvironment().getHardwareInfo();
53-
auto isLocalMemSupported = HwHelper::get(pHwInfo->platform.eRenderCoreFamily).getEnableLocalMemory(*pHwInfo);
54-
if (!isLocalMemSupported) {
55-
return true;
56-
}
57-
5851
auto length = 0;
5952
auto dataQuery = this->query(DRM_I915_QUERY_MEMORY_REGIONS, DrmQueryItemFlags::empty, length);
6053
if (dataQuery) {

0 commit comments

Comments
 (0)