fix: use alignment when allocate by win kmd

Signed-off-by: Maciej Plewka <maciej.plewka@intel.com>
This commit is contained in:
Maciej Plewka
2025-07-29 11:19:35 +00:00
committed by Compute-Runtime-Automation
parent 99ee605410
commit ced6c55caf
4 changed files with 16 additions and 1 deletions

View File

@@ -169,7 +169,7 @@ GraphicsAllocation *WddmMemoryManager::allocateMemoryByKMD(const AllocationData
GmmRequirements gmmRequirements{};
gmmRequirements.allowLargePages = true;
gmmRequirements.preferCompressed = allocationData.flags.preferCompressed;
auto gmm = std::make_unique<Gmm>(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmHelper(), allocationData.hostPtr, allocationData.size, 0u,
auto gmm = std::make_unique<Gmm>(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmHelper(), allocationData.hostPtr, allocationData.size, allocationData.alignment,
CacheSettingsHelper::getGmmUsageType(allocationData.type, !!allocationData.flags.uncacheable, productHelper, hwInfo), systemMemoryStorageInfo, gmmRequirements);
auto allocation = std::make_unique<WddmAllocation>(allocationData.rootDeviceIndex,
1u, // numGmms

View File

@@ -9,6 +9,7 @@
#include "shared/source/execution_environment/execution_environment.h"
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/gmm_helper/gmm.h"
#include "shared/source/helpers/aligned_memory.h"
#include "shared/source/os_interface/windows/gdi_interface.h"
#include "shared/source/os_interface/windows/os_environment_win.h"
@@ -103,6 +104,7 @@ bool WddmMock::mapGpuVirtualAddress(Gmm *gmm, D3DKMT_HANDLE handle, D3DGPU_VIRTU
mapGpuVirtualAddressResult.called++;
mapGpuVirtualAddressResult.cpuPtrPassed = reinterpret_cast<void *>(preferredAddress);
mapGpuVirtualAddressResult.uint64ParamPassed = preferredAddress;
mapGpuVirtualAddressResult.alignment = gmm->resourceParams.BaseAlignment;
if (callBaseMapGpuVa) {
return mapGpuVirtualAddressResult.success = Wddm::mapGpuVirtualAddress(gmm, handle, minimumAddress, maximumAddress, preferredAddress, gpuPtr, type);
} else {

View File

@@ -18,6 +18,7 @@ namespace WddmMockHelpers {
struct CallResult {
uint32_t called = 0;
uint64_t uint64ParamPassed = -1;
size_t alignment = 0;
bool success = false;
void *cpuPtrPassed = nullptr;
};

View File

@@ -1183,6 +1183,18 @@ TEST_F(WddmMemoryManagerSimpleTest, GivenShareableEnabledAndHugeSizeWhenAskedToC
memoryManager->freeGraphicsMemory(allocation);
}
TEST_F(WddmMemoryManagerSimpleTest, GivenMemoryManagerWhenAllocateByKmdThenAlignmentIsCorrect) {
memoryManager.reset(new MockWddmMemoryManager(false, false, executionEnvironment));
AllocationData allocationData;
allocationData.size = 2ULL * MemoryConstants::pageSize64k;
allocationData.flags.shareable = true;
allocationData.alignment = 8388608;
auto allocation = memoryManager->allocateMemoryByKMD(allocationData);
EXPECT_NE(nullptr, allocation);
EXPECT_EQ(static_cast<WddmMock *>(&memoryManager->getWddm(0u))->mapGpuVirtualAddressResult.alignment, allocationData.alignment);
memoryManager->freeGraphicsMemory(allocation);
}
TEST_F(WddmMemoryManagerSimpleTest, GivenShareableEnabledAndSmallSizeWhenAskedToCreatePhysicalGraphicsAllocationThenValidAllocationIsReturned) {
memoryManager.reset(new MockWddmMemoryManager(false, false, executionEnvironment));
memoryManager->hugeGfxMemoryChunkSize = MemoryConstants::pageSize64k;