mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 06:49:52 +08:00
feature usm: add debug flag to allocate shared USM in heap extended
Related-To: NEO-7665 Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
1a4dda57e7
commit
e4a446df58
@@ -105,6 +105,7 @@ else()
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/linux/mock_drm_memory_manager.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/linux/mock_drm_wrappers.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/linux/mock_drm_wrappers.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/linux/mock_ioctl_helper.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/linux/mock_os_time_linux.h
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -56,6 +56,7 @@ class TestedDrmMemoryManager : public MemoryManagerCreate<DrmMemoryManager> {
|
||||
using DrmMemoryManager::createAllocWithAlignmentFromUserptr;
|
||||
using DrmMemoryManager::createGraphicsAllocation;
|
||||
using DrmMemoryManager::createMultiHostAllocation;
|
||||
using DrmMemoryManager::createSharedUnifiedMemoryAllocation;
|
||||
using DrmMemoryManager::eraseSharedBoHandleWrapper;
|
||||
using DrmMemoryManager::eraseSharedBufferObject;
|
||||
using DrmMemoryManager::getDefaultDrmContextId;
|
||||
|
||||
27
shared/test/common/mocks/linux/mock_ioctl_helper.h
Normal file
27
shared/test/common/mocks/linux/mock_ioctl_helper.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/os_interface/linux/ioctl_helper.h"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
class MockIoctlHelper : public IoctlHelperPrelim20 {
|
||||
public:
|
||||
using IoctlHelperPrelim20::IoctlHelperPrelim20;
|
||||
unsigned int getIoctlRequestValue(DrmIoctl ioctlRequest) const override {
|
||||
return ioctlRequestValue;
|
||||
};
|
||||
|
||||
int getDrmParamValue(DrmParam drmParam) const override {
|
||||
return drmParamValue;
|
||||
}
|
||||
|
||||
unsigned int ioctlRequestValue = 1234u;
|
||||
int drmParamValue = 1234;
|
||||
};
|
||||
} // namespace NEO
|
||||
@@ -93,6 +93,7 @@ class DrmMockCustom : public Drm {
|
||||
using Drm::bindAvailable;
|
||||
using Drm::cacheInfo;
|
||||
using Drm::completionFenceSupported;
|
||||
using Drm::ioctlHelper;
|
||||
using Drm::memoryInfo;
|
||||
using Drm::setupIoctlHelper;
|
||||
|
||||
|
||||
@@ -509,3 +509,4 @@ ExperimentalCopyThroughLockWaitlistSizeThreshold= -1
|
||||
ForceDummyBlitWa = -1
|
||||
DetectIndirectAccessInKernel = -1
|
||||
OptimizeIoqBarriersHandling = -1
|
||||
AllocateSharedAllocationsInHeapExtended = 0
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "shared/test/common/mocks/linux/mock_drm_allocation.h"
|
||||
#include "shared/test/common/mocks/linux/mock_drm_command_stream_receiver.h"
|
||||
#include "shared/test/common/mocks/linux/mock_drm_memory_manager.h"
|
||||
#include "shared/test/common/mocks/linux/mock_ioctl_helper.h"
|
||||
#include "shared/test/common/mocks/linux/mock_os_context_linux.h"
|
||||
#include "shared/test/common/mocks/mock_allocation_properties.h"
|
||||
#include "shared/test/common/mocks/mock_execution_environment.h"
|
||||
@@ -6464,3 +6465,110 @@ TEST_F(DrmMemoryManagerTest, given48bAddressSpaceCpuAnd57bGpuWhenAllocatingHostU
|
||||
EXPECT_NE(hostUSM->getGpuAddress(), gpuAddress);
|
||||
memoryManager->freeGraphicsMemory(hostUSM);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, given57bAddressSpaceCpuAndGpuWhenAllocatingSharedUSMThenAddressFromExtendedHeapIsPassedAsHintAndSetAsGpuAddressAndReservedAddress) {
|
||||
if (defaultHwInfo->capabilityTable.gpuAddressSpace < maxNBitValue(57)) {
|
||||
GTEST_SKIP();
|
||||
}
|
||||
|
||||
DebugManagerStateRestore restorer;
|
||||
DebugManager.flags.AllocateSharedAllocationsInHeapExtended.set(true);
|
||||
VariableBackup<bool> backupCaptureExtendedPointers(&SysCalls::mmapCaptureExtendedPointers, true);
|
||||
VariableBackup<bool> backupAllowExtendedPointers(&SysCalls::mmapAllowExtendedPointers, true);
|
||||
SysCalls::mmapCapturedExtendedPointers.clear();
|
||||
std::vector<MemoryRegion> regionInfo(1);
|
||||
regionInfo[0].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_SYSTEM, 0};
|
||||
|
||||
auto &drm = static_cast<DrmMockCustom &>(memoryManager->getDrm(mockRootDeviceIndex));
|
||||
drm.memoryInfo.reset(new MemoryInfo(regionInfo, drm));
|
||||
drm.ioctlHelper = std::make_unique<MockIoctlHelper>(drm);
|
||||
|
||||
AllocationData allocationData{};
|
||||
allocationData.size = MemoryConstants::cacheLineSize;
|
||||
allocationData.rootDeviceIndex = mockRootDeviceIndex;
|
||||
allocationData.alignment = MemoryConstants::pageSize;
|
||||
allocationData.useMmapObject = true;
|
||||
|
||||
auto sharedUSM = memoryManager->createSharedUnifiedMemoryAllocation(allocationData);
|
||||
EXPECT_NE(nullptr, sharedUSM);
|
||||
|
||||
EXPECT_EQ(2u, SysCalls::mmapCapturedExtendedPointers.size());
|
||||
auto gpuAddress = reinterpret_cast<uint64_t>(SysCalls::mmapCapturedExtendedPointers[0]);
|
||||
SysCalls::mmapCapturedExtendedPointers.clear();
|
||||
auto gmmHelper = memoryManager->getGmmHelper(mockRootDeviceIndex);
|
||||
EXPECT_LE(memoryManager->getGfxPartition(mockRootDeviceIndex)->getHeapBase(HeapIndex::HEAP_EXTENDED), gmmHelper->decanonize(gpuAddress));
|
||||
EXPECT_GT(memoryManager->getGfxPartition(mockRootDeviceIndex)->getHeapLimit(HeapIndex::HEAP_EXTENDED), gmmHelper->decanonize(gpuAddress));
|
||||
|
||||
EXPECT_EQ(sharedUSM->getGpuAddress(), gpuAddress);
|
||||
EXPECT_EQ(sharedUSM->getReservedAddressPtr(), reinterpret_cast<void *>(gpuAddress));
|
||||
memoryManager->freeGraphicsMemory(sharedUSM);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, given48bAddressSpaceCpuAnd57bGpuWhenAllocatingSharedUSMThenAddressFromExtendedHeapIsPassedAsHintAndThenIgnored) {
|
||||
if (defaultHwInfo->capabilityTable.gpuAddressSpace < maxNBitValue(57)) {
|
||||
GTEST_SKIP();
|
||||
}
|
||||
DebugManagerStateRestore restorer;
|
||||
DebugManager.flags.AllocateSharedAllocationsInHeapExtended.set(true);
|
||||
VariableBackup<bool> backupCaptureExtendedPointers(&SysCalls::mmapCaptureExtendedPointers, true);
|
||||
VariableBackup<bool> backupAllowExtendedPointers(&SysCalls::mmapAllowExtendedPointers, false);
|
||||
SysCalls::mmapCapturedExtendedPointers.clear();
|
||||
std::vector<MemoryRegion> regionInfo(1);
|
||||
regionInfo[0].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_SYSTEM, 0};
|
||||
|
||||
auto &drm = static_cast<DrmMockCustom &>(memoryManager->getDrm(mockRootDeviceIndex));
|
||||
drm.memoryInfo.reset(new MemoryInfo(regionInfo, drm));
|
||||
drm.ioctlHelper = std::make_unique<MockIoctlHelper>(drm);
|
||||
|
||||
AllocationData allocationData{};
|
||||
allocationData.size = MemoryConstants::cacheLineSize;
|
||||
allocationData.rootDeviceIndex = mockRootDeviceIndex;
|
||||
allocationData.alignment = MemoryConstants::pageSize;
|
||||
allocationData.useMmapObject = true;
|
||||
|
||||
auto sharedUSM = memoryManager->createSharedUnifiedMemoryAllocation(allocationData);
|
||||
EXPECT_NE(nullptr, sharedUSM);
|
||||
|
||||
EXPECT_EQ(1u, SysCalls::mmapCapturedExtendedPointers.size());
|
||||
auto gpuAddress = reinterpret_cast<uint64_t>(SysCalls::mmapCapturedExtendedPointers[0]);
|
||||
SysCalls::mmapCapturedExtendedPointers.clear();
|
||||
auto gmmHelper = memoryManager->getGmmHelper(mockRootDeviceIndex);
|
||||
EXPECT_LE(memoryManager->getGfxPartition(mockRootDeviceIndex)->getHeapBase(HeapIndex::HEAP_EXTENDED), gmmHelper->decanonize(gpuAddress));
|
||||
EXPECT_GT(memoryManager->getGfxPartition(mockRootDeviceIndex)->getHeapLimit(HeapIndex::HEAP_EXTENDED), gmmHelper->decanonize(gpuAddress));
|
||||
|
||||
EXPECT_NE(sharedUSM->getGpuAddress(), gpuAddress);
|
||||
memoryManager->freeGraphicsMemory(sharedUSM);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, given57bAddressSpaceCpuAndGpuWhenAllocating48bResourceSharedUSMThenAddressFromExtendedHeapIsNotUsed) {
|
||||
if (defaultHwInfo->capabilityTable.gpuAddressSpace < maxNBitValue(57)) {
|
||||
GTEST_SKIP();
|
||||
}
|
||||
DebugManagerStateRestore restorer;
|
||||
DebugManager.flags.AllocateSharedAllocationsInHeapExtended.set(true);
|
||||
VariableBackup<bool> backupCaptureExtendedPointers(&SysCalls::mmapCaptureExtendedPointers, true);
|
||||
VariableBackup<bool> backupAllowExtendedPointers(&SysCalls::mmapAllowExtendedPointers, true);
|
||||
SysCalls::mmapCapturedExtendedPointers.clear();
|
||||
std::vector<MemoryRegion> regionInfo(1);
|
||||
regionInfo[0].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_SYSTEM, 0};
|
||||
|
||||
auto &drm = static_cast<DrmMockCustom &>(memoryManager->getDrm(mockRootDeviceIndex));
|
||||
drm.memoryInfo.reset(new MemoryInfo(regionInfo, drm));
|
||||
drm.ioctlHelper = std::make_unique<MockIoctlHelper>(drm);
|
||||
|
||||
AllocationData allocationData{};
|
||||
allocationData.size = MemoryConstants::cacheLineSize;
|
||||
allocationData.rootDeviceIndex = mockRootDeviceIndex;
|
||||
allocationData.alignment = MemoryConstants::pageSize;
|
||||
allocationData.useMmapObject = true;
|
||||
allocationData.flags.resource48Bit = true;
|
||||
|
||||
auto sharedUSM = memoryManager->createSharedUnifiedMemoryAllocation(allocationData);
|
||||
EXPECT_NE(nullptr, sharedUSM);
|
||||
|
||||
EXPECT_EQ(0u, SysCalls::mmapCapturedExtendedPointers.size());
|
||||
|
||||
EXPECT_LT(sharedUSM->getGpuAddress(), maxNBitValue(48));
|
||||
EXPECT_EQ(sharedUSM->getReservedAddressPtr(), nullptr);
|
||||
memoryManager->freeGraphicsMemory(sharedUSM);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "shared/test/common/helpers/test_files.h"
|
||||
#include "shared/test/common/helpers/variable_backup.h"
|
||||
#include "shared/test/common/libult/linux/drm_mock.h"
|
||||
#include "shared/test/common/mocks/linux/mock_ioctl_helper.h"
|
||||
#include "shared/test/common/mocks/mock_execution_environment.h"
|
||||
#include "shared/test/common/mocks/mock_memory_manager.h"
|
||||
#include "shared/test/common/os_interface/linux/sys_calls_linux_ult.h"
|
||||
@@ -1415,21 +1416,6 @@ TEST(DrmWrapperTest, WhenGettingRevisionParamValueThenIoctlHelperIsNotNeeded) {
|
||||
EXPECT_EQ(getDrmParamValue(DrmParam::ParamRevision, nullptr), static_cast<int>(I915_PARAM_REVISION));
|
||||
}
|
||||
|
||||
class MockIoctlHelper : public IoctlHelperPrelim20 {
|
||||
public:
|
||||
using IoctlHelperPrelim20::IoctlHelperPrelim20;
|
||||
unsigned int getIoctlRequestValue(DrmIoctl ioctlRequest) const override {
|
||||
return ioctlRequestValue;
|
||||
};
|
||||
|
||||
int getDrmParamValue(DrmParam drmParam) const override {
|
||||
return drmParamValue;
|
||||
}
|
||||
|
||||
unsigned int ioctlRequestValue = 1234u;
|
||||
int drmParamValue = 1234;
|
||||
};
|
||||
|
||||
TEST(DrmWrapperTest, whenGettingDrmParamOrIoctlRequestValueThenUseIoctlHelperWhenAvailable) {
|
||||
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
|
||||
DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
|
||||
|
||||
Reference in New Issue
Block a user