mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-08 14:02:58 +08:00
refactor: remove not needed arguments in adjustGpuPtrToHostAddressSpace
- add also tests to confirm that proper alignment is applied Signed-off-by: Katarzyna Cencelewska <katarzyna.cencelewska@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
8e07dd30cb
commit
33a5dd486b
@@ -104,7 +104,6 @@ class WddmAllocation : public GraphicsAllocation {
|
||||
|
||||
std::string getAllocationInfoString() const override;
|
||||
uint64_t &getGpuAddressToModify() { return gpuAddress; }
|
||||
bool isLocalMemoryPool() { return memoryPool == MemoryPool::LocalMemory; }
|
||||
|
||||
// OS assigned fields
|
||||
D3DKMT_HANDLE resourceHandle = 0u; // used by shared resources
|
||||
|
||||
@@ -210,7 +210,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryUsingKmdAndMapItToC
|
||||
if ((!(alignGpuAddressTo64KB) && executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getHardwareInfo()->capabilityTable.gpuAddressSpace >= MemoryConstants::max64BitAppAddress) || is32bit) {
|
||||
void *requiredGpuVa = cpuPtr;
|
||||
if (!cpuPtr) {
|
||||
adjustGpuPtrToHostAddressSpace(allocationData, *wddmAllocation.get(), sizeAligned, requiredGpuVa);
|
||||
adjustGpuPtrToHostAddressSpace(*wddmAllocation.get(), requiredGpuVa);
|
||||
}
|
||||
status = mapGpuVirtualAddress(wddmAllocation.get(), requiredGpuVa);
|
||||
} else {
|
||||
@@ -1330,7 +1330,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryInDevicePool(const
|
||||
|
||||
auto &wddm = getWddm(allocationData.rootDeviceIndex);
|
||||
|
||||
adjustGpuPtrToHostAddressSpace(allocationData, *wddmAllocation.get(), sizeAligned, requiredGpuVa);
|
||||
adjustGpuPtrToHostAddressSpace(*wddmAllocation.get(), requiredGpuVa);
|
||||
|
||||
if (!createWddmAllocation(wddmAllocation.get(), requiredGpuVa)) {
|
||||
for (auto handleId = 0u; handleId < allocationData.storageInfo.getNumBanks(); handleId++) {
|
||||
@@ -1399,22 +1399,30 @@ void WddmMemoryManager::registerAllocationInOs(GraphicsAllocation *allocation) {
|
||||
}
|
||||
}
|
||||
|
||||
bool WddmMemoryManager::isStatelessAccessRequired(AllocationType type) {
|
||||
if (type == AllocationType::BUFFER ||
|
||||
type == AllocationType::SHARED_BUFFER ||
|
||||
type == AllocationType::SCRATCH_SURFACE ||
|
||||
type == AllocationType::LINEAR_STREAM ||
|
||||
type == AllocationType::PRIVATE_SURFACE) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <bool Is32Bit>
|
||||
void WddmMemoryManager::adjustGpuPtrToHostAddressSpace(const AllocationData &allocationData, WddmAllocation &wddmAllocation, size_t sizeAligned, void *&requiredGpuVa) {
|
||||
void WddmMemoryManager::adjustGpuPtrToHostAddressSpace(WddmAllocation &wddmAllocation, void *&requiredGpuVa) {
|
||||
if constexpr (Is32Bit) {
|
||||
if (executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->isFullRangeSvm()) {
|
||||
if (allocationData.type == AllocationType::BUFFER ||
|
||||
allocationData.type == AllocationType::SHARED_BUFFER ||
|
||||
allocationData.type == AllocationType::SCRATCH_SURFACE ||
|
||||
allocationData.type == AllocationType::LINEAR_STREAM ||
|
||||
allocationData.type == AllocationType::PRIVATE_SURFACE) {
|
||||
size_t reserveSizeAligned = sizeAligned;
|
||||
auto isLocalMemory = wddmAllocation.isLocalMemoryPool();
|
||||
auto rootDeviceIndex = wddmAllocation.getRootDeviceIndex();
|
||||
if (executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->isFullRangeSvm()) {
|
||||
if (isStatelessAccessRequired(wddmAllocation.getAllocationType())) {
|
||||
size_t reserveSizeAligned = wddmAllocation.getUnderlyingBufferSize();
|
||||
auto isLocalMemory = wddmAllocation.getMemoryPool() == MemoryPool::LocalMemory;
|
||||
if (isLocalMemory) {
|
||||
// add 2MB padding to make sure there are no overlaps between system and local memory
|
||||
reserveSizeAligned += 2 * MemoryConstants::megaByte;
|
||||
}
|
||||
auto &wddm = getWddm(allocationData.rootDeviceIndex);
|
||||
auto &wddm = getWddm(rootDeviceIndex);
|
||||
wddm.reserveValidAddressRange(reserveSizeAligned, requiredGpuVa);
|
||||
wddmAllocation.setReservedAddressRange(requiredGpuVa, reserveSizeAligned);
|
||||
requiredGpuVa = isLocalMemory ? alignUp(requiredGpuVa, 2 * MemoryConstants::megaByte) : requiredGpuVa;
|
||||
|
||||
@@ -115,7 +115,8 @@ class WddmMemoryManager : public MemoryManager {
|
||||
bool mapMultiHandleAllocationWithRetry(WddmAllocation *allocation, const void *requiredGpuPtr);
|
||||
bool createGpuAllocationsWithRetry(WddmAllocation *graphicsAllocation);
|
||||
template <bool Is32Bit = is32bit>
|
||||
void adjustGpuPtrToHostAddressSpace(const AllocationData &allocationData, WddmAllocation &wddmAllocation, size_t sizeAligned, void *&requiredGpuVa);
|
||||
void adjustGpuPtrToHostAddressSpace(WddmAllocation &wddmAllocation, void *&requiredGpuVa);
|
||||
bool isStatelessAccessRequired(AllocationType type);
|
||||
AlignedMallocRestrictions mallocRestrictions;
|
||||
|
||||
Wddm &getWddm(uint32_t rootDeviceIndex) const;
|
||||
|
||||
@@ -37,6 +37,7 @@ class MockWddmMemoryManager : public MemoryManagerCreate<WddmMemoryManager> {
|
||||
using BaseClass::unMapPhysicalToVirtualMemory;
|
||||
using MemoryManagerCreate<WddmMemoryManager>::MemoryManagerCreate;
|
||||
using BaseClass::getHugeGfxMemoryChunkSize;
|
||||
using BaseClass::isStatelessAccessRequired;
|
||||
|
||||
GraphicsAllocation *allocateGraphicsMemory64kb(const AllocationData &allocationData) override {
|
||||
allocationGraphicsMemory64kbCreated = true;
|
||||
|
||||
@@ -165,6 +165,7 @@ TEST_F(WddmMemoryManagerTests, givenAllocateGraphicsMemory64kbWhen32bitThenAddre
|
||||
|
||||
class MockAllocateGraphicsMemoryUsingKmdAndMapItToCpuVAWddm : public MemoryManagerCreate<WddmMemoryManager> {
|
||||
public:
|
||||
using WddmMemoryManager::adjustGpuPtrToHostAddressSpace;
|
||||
using WddmMemoryManager::allocateGraphicsMemoryUsingKmdAndMapItToCpuVA;
|
||||
using WddmMemoryManager::mapGpuVirtualAddress;
|
||||
MockAllocateGraphicsMemoryUsingKmdAndMapItToCpuVAWddm(ExecutionEnvironment &executionEnvironment) : MemoryManagerCreate(false, false, executionEnvironment) {}
|
||||
@@ -355,3 +356,122 @@ TEST_F(WddmMemoryManagerAllocPathTests, givenAllocateGraphicsMemoryUsingKmdAndMa
|
||||
|
||||
memoryManager->freeGraphicsMemory(graphicsAllocation);
|
||||
}
|
||||
|
||||
class MockWddmReserveValidAddressRange : public WddmMock {
|
||||
public:
|
||||
MockWddmReserveValidAddressRange(RootDeviceEnvironment &rootDeviceEnvironment) : WddmMock(rootDeviceEnvironment){};
|
||||
bool reserveValidAddressRange(size_t size, void *&reservedMem) override {
|
||||
reserveValidAddressRangeResult.called++;
|
||||
reservedMem = dummyAddress;
|
||||
return true;
|
||||
}
|
||||
void *dummyAddress = reinterpret_cast<void *>(0x43211111);
|
||||
};
|
||||
|
||||
TEST_F(WddmMemoryManagerAllocPathTests, givenLocalMemoryWhen32bitAndCallAdjustGpuPtrToHostAddressSpaceThenProperAlignmentIsApplied) {
|
||||
if constexpr (is64bit) {
|
||||
GTEST_SKIP();
|
||||
}
|
||||
auto mockWddm = std::make_unique<MockWddmReserveValidAddressRange>(*executionEnvironment->rootDeviceEnvironments[0].get());
|
||||
auto addressWithoutAligment = reinterpret_cast<uint64_t>(mockWddm->dummyAddress);
|
||||
uint32_t rootDeviceIndex = 0u;
|
||||
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface->setDriverModel(std::move(mockWddm));
|
||||
size_t size = 10;
|
||||
|
||||
auto wddmAllocation = std::make_unique<WddmAllocation>(rootDeviceIndex,
|
||||
1u, // numGmms
|
||||
NEO::AllocationType::BUFFER, nullptr, 0,
|
||||
size, nullptr, MemoryPool::LocalMemory,
|
||||
0u, // shareable
|
||||
0u);
|
||||
void *addressPtr;
|
||||
memoryManager->adjustGpuPtrToHostAddressSpace(*wddmAllocation.get(), addressPtr);
|
||||
|
||||
EXPECT_NE(nullptr, addressPtr);
|
||||
auto address = reinterpret_cast<uint64_t>(addressPtr);
|
||||
uint64_t alignmentMask = 2 * MemoryConstants::megaByte - 1;
|
||||
EXPECT_FALSE(address & alignmentMask);
|
||||
EXPECT_NE(addressWithoutAligment, address);
|
||||
}
|
||||
|
||||
TEST_F(WddmMemoryManagerAllocPathTests, givenSystemMemoryWhen32bitAndCallAdjustGpuPtrToHostAddressSpaceThenThereIsNoExtraAlignment) {
|
||||
if constexpr (is64bit) {
|
||||
GTEST_SKIP();
|
||||
}
|
||||
auto mockWddm = std::make_unique<MockWddmReserveValidAddressRange>(*executionEnvironment->rootDeviceEnvironments[0].get());
|
||||
auto expectedAddress = reinterpret_cast<uint64_t>(mockWddm->dummyAddress);
|
||||
uint32_t rootDeviceIndex = 0u;
|
||||
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface->setDriverModel(std::move(mockWddm));
|
||||
size_t size = 10;
|
||||
|
||||
auto wddmAllocation = std::make_unique<WddmAllocation>(rootDeviceIndex,
|
||||
1u, // numGmms
|
||||
NEO::AllocationType::BUFFER, nullptr, 0,
|
||||
size, nullptr, MemoryPool::System64KBPages,
|
||||
0u, // shareable
|
||||
0u);
|
||||
void *addressPtr;
|
||||
memoryManager->adjustGpuPtrToHostAddressSpace(*wddmAllocation.get(), addressPtr);
|
||||
|
||||
EXPECT_NE(nullptr, addressPtr);
|
||||
auto address = reinterpret_cast<uint64_t>(addressPtr);
|
||||
|
||||
EXPECT_EQ(expectedAddress, address);
|
||||
}
|
||||
|
||||
TEST_F(WddmMemoryManagerTests, givenTypeWhenCallIsStatelessAccessRequiredThenProperValueIsReturned) {
|
||||
|
||||
auto wddmMemoryManager = std::make_unique<MockWddmMemoryManager>(*executionEnvironment);
|
||||
|
||||
for (auto type : {AllocationType::BUFFER,
|
||||
AllocationType::SHARED_BUFFER,
|
||||
AllocationType::SCRATCH_SURFACE,
|
||||
AllocationType::LINEAR_STREAM,
|
||||
AllocationType::PRIVATE_SURFACE}) {
|
||||
EXPECT_TRUE(wddmMemoryManager->isStatelessAccessRequired(type));
|
||||
}
|
||||
for (auto type : {AllocationType::BUFFER_HOST_MEMORY,
|
||||
AllocationType::COMMAND_BUFFER,
|
||||
AllocationType::CONSTANT_SURFACE,
|
||||
AllocationType::EXTERNAL_HOST_PTR,
|
||||
AllocationType::FILL_PATTERN,
|
||||
AllocationType::GLOBAL_SURFACE,
|
||||
AllocationType::IMAGE,
|
||||
AllocationType::INDIRECT_OBJECT_HEAP,
|
||||
AllocationType::INSTRUCTION_HEAP,
|
||||
AllocationType::INTERNAL_HEAP,
|
||||
AllocationType::INTERNAL_HOST_MEMORY,
|
||||
AllocationType::KERNEL_ARGS_BUFFER,
|
||||
AllocationType::KERNEL_ISA,
|
||||
AllocationType::KERNEL_ISA_INTERNAL,
|
||||
AllocationType::MAP_ALLOCATION,
|
||||
AllocationType::MCS,
|
||||
AllocationType::PIPE,
|
||||
AllocationType::PREEMPTION,
|
||||
AllocationType::PRINTF_SURFACE,
|
||||
AllocationType::PROFILING_TAG_BUFFER,
|
||||
AllocationType::SHARED_CONTEXT_IMAGE,
|
||||
AllocationType::SHARED_IMAGE,
|
||||
AllocationType::SHARED_RESOURCE_COPY,
|
||||
AllocationType::SURFACE_STATE_HEAP,
|
||||
AllocationType::SVM_CPU,
|
||||
AllocationType::SVM_GPU,
|
||||
AllocationType::SVM_ZERO_COPY,
|
||||
AllocationType::TAG_BUFFER,
|
||||
AllocationType::GLOBAL_FENCE,
|
||||
AllocationType::TIMESTAMP_PACKET_TAG_BUFFER,
|
||||
AllocationType::WRITE_COMBINED,
|
||||
AllocationType::RING_BUFFER,
|
||||
AllocationType::SEMAPHORE_BUFFER,
|
||||
AllocationType::DEBUG_CONTEXT_SAVE_AREA,
|
||||
AllocationType::DEBUG_SBA_TRACKING_BUFFER,
|
||||
AllocationType::DEBUG_MODULE_AREA,
|
||||
AllocationType::UNIFIED_SHARED_MEMORY,
|
||||
AllocationType::WORK_PARTITION_SURFACE,
|
||||
AllocationType::GPU_TIMESTAMP_DEVICE_BUFFER,
|
||||
AllocationType::SW_TAG_BUFFER,
|
||||
AllocationType::DEFERRED_TASKS_LIST,
|
||||
AllocationType::ASSERT_BUFFER}) {
|
||||
EXPECT_FALSE(wddmMemoryManager->isStatelessAccessRequired(type));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user