Skip to content

Commit 766d56e

Browse files
jchodorCompute-Runtime-Automation
authored andcommitted
WSL - fixing allocation alignment
Signed-off-by: Jaroslaw Chodor <[email protected]>
1 parent 2fab8cc commit 766d56e

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

opencl/test/unit_test/os_interface/windows/mock_wddm_memory_manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class MockWddmMemoryManager : public MemoryManagerCreate<WddmMemoryManager> {
2020
public:
2121
using BaseClass::alignmentSelector;
2222
using BaseClass::allocateGraphicsMemoryForNonSvmHostPtr;
23+
using BaseClass::allocateGraphicsMemoryWithAlignment;
2324
using BaseClass::allocateGraphicsMemoryWithGpuVa;
2425
using BaseClass::allocateGraphicsMemoryWithProperties;
2526
using BaseClass::allocateShareableMemory;

opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,3 +2290,46 @@ TEST_F(WddmMemoryManagerSimpleTest, givenWddmMemoryManagerWhenGettingGlobalMemor
22902290
uint32_t rootDeviceIndex = 0u;
22912291
EXPECT_EQ(memoryManager.getPercentOfGlobalMemoryAvailable(rootDeviceIndex), 0.8);
22922292
}
2293+
2294+
TEST_F(WddmMemoryManagerSimpleTest, whenAlignmentRequirementExceedsPageSizeThenAllocateGraphicsMemoryFromSystemPtr) {
2295+
struct MockWddmMemoryManagerAllocateWithAlignment : MockWddmMemoryManager {
2296+
using MockWddmMemoryManager::MockWddmMemoryManager;
2297+
2298+
GraphicsAllocation *allocateSystemMemoryAndCreateGraphicsAllocationFromIt(const AllocationData &allocationData) override {
2299+
++callCount.allocateSystemMemoryAndCreateGraphicsAllocationFromIt;
2300+
return nullptr;
2301+
}
2302+
GraphicsAllocation *allocateGraphicsMemoryUsingKmdAndMapItToCpuVA(const AllocationData &allocationData, bool allowLargePages) override {
2303+
++callCount.allocateGraphicsMemoryUsingKmdAndMapItToCpuVA;
2304+
return nullptr;
2305+
}
2306+
2307+
struct {
2308+
int allocateSystemMemoryAndCreateGraphicsAllocationFromIt = 0;
2309+
int allocateGraphicsMemoryUsingKmdAndMapItToCpuVA = 0;
2310+
} callCount;
2311+
};
2312+
2313+
MockWddmMemoryManagerAllocateWithAlignment memoryManager(true, true, *executionEnvironment);
2314+
2315+
AllocationData allocData = {};
2316+
allocData.size = 1024;
2317+
allocData.alignment = MemoryConstants::pageSize64k * 4;
2318+
memoryManager.allocateGraphicsMemoryWithAlignment(allocData);
2319+
EXPECT_EQ(1U, memoryManager.callCount.allocateSystemMemoryAndCreateGraphicsAllocationFromIt);
2320+
EXPECT_EQ(0U, memoryManager.callCount.allocateGraphicsMemoryUsingKmdAndMapItToCpuVA);
2321+
2322+
memoryManager.callCount.allocateSystemMemoryAndCreateGraphicsAllocationFromIt = 0;
2323+
memoryManager.callCount.allocateGraphicsMemoryUsingKmdAndMapItToCpuVA = 0;
2324+
2325+
allocData.size = 1024;
2326+
allocData.alignment = MemoryConstants::pageSize;
2327+
memoryManager.allocateGraphicsMemoryWithAlignment(allocData);
2328+
if (preferredAllocationMethod == GfxMemoryAllocationMethod::AllocateByKmd) {
2329+
EXPECT_EQ(0U, memoryManager.callCount.allocateSystemMemoryAndCreateGraphicsAllocationFromIt);
2330+
EXPECT_EQ(1U, memoryManager.callCount.allocateGraphicsMemoryUsingKmdAndMapItToCpuVA);
2331+
} else {
2332+
EXPECT_EQ(1U, memoryManager.callCount.allocateSystemMemoryAndCreateGraphicsAllocationFromIt);
2333+
EXPECT_EQ(0U, memoryManager.callCount.allocateGraphicsMemoryUsingKmdAndMapItToCpuVA);
2334+
}
2335+
}

shared/source/os_interface/windows/wddm_memory_manager.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ GraphicsAllocation *WddmMemoryManager::allocateUSMHostGraphicsMemory(const Alloc
199199
}
200200

201201
GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) {
202-
if (preferredAllocationMethod == GfxMemoryAllocationMethod::UseUmdSystemPtr) {
202+
auto pageSize = NEO::OSInterface::osEnabled64kbPages ? MemoryConstants::pageSize64k : MemoryConstants::pageSize;
203+
bool requiresNonStandardAlignment = allocationData.alignment > pageSize;
204+
if ((preferredAllocationMethod == GfxMemoryAllocationMethod::UseUmdSystemPtr) || requiresNonStandardAlignment) {
203205
return allocateSystemMemoryAndCreateGraphicsAllocationFromIt(allocationData);
204206
} else {
205207
return allocateGraphicsMemoryUsingKmdAndMapItToCpuVA(allocationData, NEO::OSInterface::osEnabled64kbPages);

shared/source/os_interface/windows/wddm_memory_manager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ class WddmMemoryManager : public MemoryManager {
8484
GraphicsAllocation *allocateGraphicsMemoryWithGpuVa(const AllocationData &allocationData) override { return nullptr; }
8585

8686
GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override;
87-
GraphicsAllocation *allocateSystemMemoryAndCreateGraphicsAllocationFromIt(const AllocationData &allocationData);
88-
GraphicsAllocation *allocateGraphicsMemoryUsingKmdAndMapItToCpuVA(const AllocationData &allocationData, bool allowLargePages);
87+
MOCKABLE_VIRTUAL GraphicsAllocation *allocateSystemMemoryAndCreateGraphicsAllocationFromIt(const AllocationData &allocationData);
88+
MOCKABLE_VIRTUAL GraphicsAllocation *allocateGraphicsMemoryUsingKmdAndMapItToCpuVA(const AllocationData &allocationData, bool allowLargePages);
8989

9090
void *lockResourceImpl(GraphicsAllocation &graphicsAllocation) override;
9191
void unlockResourceImpl(GraphicsAllocation &graphicsAllocation) override;

0 commit comments

Comments
 (0)