Skip to content

Commit e060536

Browse files
Add check in allocateGraphicsMemory64kb to not use cpuPtr
when isRenderCompressed Related-To: NEO-4532 Signed-off-by: Katarzyna Cencelewska <katarzyna.cencelewska@intel.com>
1 parent 4ce7c0e commit e060536

File tree

7 files changed

+152
-8
lines changed

7 files changed

+152
-8
lines changed

opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ struct GmmTests : public MockExecutionEnvironmentGmmFixtureTest {
4545
void SetUp() override {
4646
MockExecutionEnvironmentGmmFixture::SetUp();
4747
rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[0].get();
48+
localPlatformDevice = rootDeviceEnvironment->getMutableHardwareInfo();
4849
}
4950
RootDeviceEnvironment *rootDeviceEnvironment = nullptr;
51+
HardwareInfo *localPlatformDevice = nullptr;
5052
};
5153

5254
TEST(GmmGlTests, givenGmmWhenAskedforCubeFaceIndexThenProperValueIsReturned) {
@@ -811,4 +813,70 @@ TEST(GmmHelperTest, givenValidGmmFunctionsWhenCreateGmmHelperWithoutOsInterfaceT
811813
EXPECT_EQ(GMM_CLIENT::GMM_OCL_VISTA, passedInputArgs.ClientType);
812814
}
813815

816+
using GmmCompressionTest = GmmTests;
817+
TEST_F(GmmCompressionTest, givenEnabledAndPreferredE2ECWhenApplyingForBuffersThenSetValidFlags) {
818+
std::unique_ptr<Gmm> gmm(new Gmm(getGmmClientContext(), nullptr, 1, false));
819+
gmm->resourceParams = {};
820+
821+
localPlatformDevice->capabilityTable.ftrRenderCompressedBuffers = true;
822+
823+
gmm->applyAuxFlagsForBuffer(true);
824+
EXPECT_EQ(1u, gmm->resourceParams.Flags.Info.RenderCompressed);
825+
EXPECT_EQ(1u, gmm->resourceParams.Flags.Gpu.CCS);
826+
EXPECT_EQ(1u, gmm->resourceParams.Flags.Gpu.UnifiedAuxSurface);
827+
EXPECT_TRUE(gmm->isRenderCompressed);
828+
}
829+
830+
TEST_F(GmmCompressionTest, givenDisabledE2ECAndEnabledDebugFlagWhenApplyingForBuffersThenSetValidFlags) {
831+
DebugManagerStateRestore restore;
832+
Gmm gmm(getGmmClientContext(), nullptr, 1, false);
833+
gmm.resourceParams = {};
834+
835+
DebugManager.flags.RenderCompressedBuffersEnabled.set(1);
836+
localPlatformDevice->capabilityTable.ftrRenderCompressedBuffers = false;
837+
838+
gmm.applyAuxFlagsForBuffer(true);
839+
EXPECT_EQ(1u, gmm.resourceParams.Flags.Info.RenderCompressed);
840+
EXPECT_EQ(1u, gmm.resourceParams.Flags.Gpu.CCS);
841+
EXPECT_EQ(1u, gmm.resourceParams.Flags.Gpu.UnifiedAuxSurface);
842+
EXPECT_TRUE(gmm.isRenderCompressed);
843+
844+
gmm.resourceParams = {};
845+
gmm.isRenderCompressed = false;
846+
DebugManager.flags.RenderCompressedBuffersEnabled.set(0);
847+
localPlatformDevice->capabilityTable.ftrRenderCompressedBuffers = true;
848+
849+
gmm.applyAuxFlagsForBuffer(true);
850+
EXPECT_EQ(0u, gmm.resourceParams.Flags.Info.RenderCompressed);
851+
EXPECT_EQ(0u, gmm.resourceParams.Flags.Gpu.CCS);
852+
EXPECT_EQ(0u, gmm.resourceParams.Flags.Gpu.UnifiedAuxSurface);
853+
EXPECT_FALSE(gmm.isRenderCompressed);
854+
}
855+
856+
TEST_F(GmmCompressionTest, givenEnabledAndNotPreferredE2ECWhenApplyingForBuffersThenDontSetValidFlags) {
857+
std::unique_ptr<Gmm> gmm(new Gmm(getGmmClientContext(), nullptr, 1, false));
858+
gmm->resourceParams = {};
859+
860+
localPlatformDevice->capabilityTable.ftrRenderCompressedBuffers = true;
861+
862+
gmm->applyAuxFlagsForBuffer(false);
863+
EXPECT_EQ(0u, gmm->resourceParams.Flags.Info.RenderCompressed);
864+
EXPECT_EQ(0u, gmm->resourceParams.Flags.Gpu.CCS);
865+
EXPECT_EQ(0u, gmm->resourceParams.Flags.Gpu.UnifiedAuxSurface);
866+
EXPECT_FALSE(gmm->isRenderCompressed);
867+
}
868+
869+
TEST_F(GmmCompressionTest, givenDisabledAndPreferredE2ECWhenApplyingForBuffersThenDontSetValidFlags) {
870+
std::unique_ptr<Gmm> gmm(new Gmm(getGmmClientContext(), nullptr, 1, false));
871+
gmm->resourceParams = {};
872+
873+
localPlatformDevice->capabilityTable.ftrRenderCompressedBuffers = false;
874+
875+
gmm->applyAuxFlagsForBuffer(true);
876+
EXPECT_EQ(0u, gmm->resourceParams.Flags.Info.RenderCompressed);
877+
EXPECT_EQ(0u, gmm->resourceParams.Flags.Gpu.CCS);
878+
EXPECT_EQ(0u, gmm->resourceParams.Flags.Gpu.UnifiedAuxSurface);
879+
EXPECT_FALSE(gmm->isRenderCompressed);
880+
}
881+
814882
} // namespace NEO

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ class MockWddmMemoryManager : public MemoryManagerCreate<WddmMemoryManager> {
1818
using BaseClass = WddmMemoryManager;
1919

2020
public:
21-
using BaseClass::allocateGraphicsMemory64kb;
2221
using BaseClass::allocateGraphicsMemoryForNonSvmHostPtr;
23-
using BaseClass::allocateGraphicsMemoryInDevicePool;
2422
using BaseClass::allocateGraphicsMemoryWithGpuVa;
2523
using BaseClass::allocateGraphicsMemoryWithProperties;
2624
using BaseClass::allocateShareableMemory;
@@ -33,6 +31,18 @@ class MockWddmMemoryManager : public MemoryManagerCreate<WddmMemoryManager> {
3331
using MemoryManagerCreate<WddmMemoryManager>::MemoryManagerCreate;
3432
using BaseClass::getHugeGfxMemoryChunkSize;
3533

34+
GraphicsAllocation *allocateGraphicsMemory64kb(const AllocationData &allocationData) override {
35+
allocationGraphicsMemory64kbCreated = true;
36+
return BaseClass::allocateGraphicsMemory64kb(allocationData);
37+
}
38+
GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override {
39+
if (allocateGraphicsMemoryInNonDevicePool) {
40+
status = AllocationStatus::RetryInNonDevicePool;
41+
return nullptr;
42+
}
43+
return BaseClass::allocateGraphicsMemoryInDevicePool(allocationData, status);
44+
}
45+
3646
size_t hugeGfxMemoryChunkSize = BaseClass::getHugeGfxMemoryChunkSize();
3747
size_t getHugeGfxMemoryChunkSize() const override { return hugeGfxMemoryChunkSize; }
3848

@@ -63,5 +73,7 @@ class MockWddmMemoryManager : public MemoryManagerCreate<WddmMemoryManager> {
6373
}
6474

6575
uint32_t freeGraphicsMemoryImplCalled = 0u;
76+
bool allocationGraphicsMemory64kbCreated = false;
77+
bool allocateGraphicsMemoryInNonDevicePool = false;
6678
};
6779
} // namespace NEO

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#include "opencl/test/unit_test/mocks/mock_platform.h"
3636
#include "opencl/test/unit_test/os_interface/windows/mock_wddm_allocation.h"
3737

38+
#include "mock_gmm_client_context.h"
39+
3840
using namespace NEO;
3941
using namespace ::testing;
4042

@@ -679,6 +681,59 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerSizeZeroWhenCreateFromShared
679681
memoryManager->freeGraphicsMemory(gpuAllocation);
680682
}
681683

684+
HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenAllocateGraphicsMemoryWithSetAllocattionPropertisWithAllocationTypeBufferCompressedIsCalledThenIsRendeCompressedTrueAndGpuMappingIsSetWithGoodAddressRange) {
685+
void *ptr = reinterpret_cast<void *>(0x1001);
686+
auto size = MemoryConstants::pageSize;
687+
HardwareInfo hwInfo = *defaultHwInfo;
688+
hwInfo.capabilityTable.ftrRenderCompressedBuffers = true;
689+
rootDeviceEnvironment->setHwInfo(&hwInfo);
690+
691+
auto memoryManager = std::make_unique<MockWddmMemoryManager>(true, false, *executionEnvironment);
692+
memoryManager->allocateGraphicsMemoryInNonDevicePool = true;
693+
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{mockRootDeviceIndex, true, size, GraphicsAllocation::AllocationType::BUFFER_COMPRESSED, mockDeviceBitfield}, ptr);
694+
695+
auto gfxPartition = memoryManager->getGfxPartition(mockRootDeviceIndex);
696+
D3DGPU_VIRTUAL_ADDRESS standard64kbRangeMinimumAddress = gfxPartition->getHeapMinimalAddress(HeapIndex::HEAP_STANDARD64KB);
697+
D3DGPU_VIRTUAL_ADDRESS standard64kbRangeMaximumAddress = gfxPartition->getHeapLimit(HeapIndex::HEAP_STANDARD64KB);
698+
699+
ASSERT_NE(nullptr, allocation);
700+
EXPECT_TRUE(memoryManager->allocationGraphicsMemory64kbCreated);
701+
EXPECT_TRUE(allocation->getDefaultGmm()->isRenderCompressed);
702+
if ((is32bit || rootDeviceEnvironment->isFullRangeSvm()) &&
703+
allocation->getDefaultGmm()->gmmResourceInfo->is64KBPageSuitable()) {
704+
EXPECT_GE(GmmHelper::decanonize(allocation->getGpuAddress()), standard64kbRangeMinimumAddress);
705+
EXPECT_LE(GmmHelper::decanonize(allocation->getGpuAddress()), standard64kbRangeMaximumAddress);
706+
}
707+
708+
memoryManager->freeGraphicsMemory(allocation);
709+
}
710+
711+
HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenAllocateGraphicsMemoryWithSetAllocattionPropertisWithAllocationTypeBufferIsCalledThenIsRendeCompressedFalseAndCorrectAddressRange) {
712+
void *ptr = reinterpret_cast<void *>(0x1001);
713+
auto size = MemoryConstants::pageSize;
714+
HardwareInfo hwInfo = *defaultHwInfo;
715+
hwInfo.capabilityTable.ftrRenderCompressedBuffers = true;
716+
rootDeviceEnvironment->setHwInfo(&hwInfo);
717+
718+
auto memoryManager = std::make_unique<MockWddmMemoryManager>(false, false, *executionEnvironment);
719+
memoryManager->allocateGraphicsMemoryInNonDevicePool = true;
720+
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{mockRootDeviceIndex, true, size, GraphicsAllocation::AllocationType::BUFFER, mockDeviceBitfield}, ptr);
721+
722+
auto gfxPartition = memoryManager->getGfxPartition(mockRootDeviceIndex);
723+
D3DGPU_VIRTUAL_ADDRESS svmRangeMinimumAddress = gfxPartition->getHeapMinimalAddress(HeapIndex::HEAP_SVM);
724+
D3DGPU_VIRTUAL_ADDRESS svmRangeMaximumAddress = gfxPartition->getHeapLimit(HeapIndex::HEAP_SVM);
725+
726+
ASSERT_NE(nullptr, allocation);
727+
EXPECT_FALSE(memoryManager->allocationGraphicsMemory64kbCreated);
728+
EXPECT_FALSE(allocation->getDefaultGmm()->isRenderCompressed);
729+
if (is32bit || rootDeviceEnvironment->isFullRangeSvm()) {
730+
731+
EXPECT_GE(GmmHelper::decanonize(allocation->getGpuAddress()), svmRangeMinimumAddress);
732+
EXPECT_LE(GmmHelper::decanonize(allocation->getGpuAddress()), svmRangeMaximumAddress);
733+
}
734+
memoryManager->freeGraphicsMemory(allocation);
735+
}
736+
682737
TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromSharedHandleFailsThenReturnNull) {
683738
auto osHandle = 1u;
684739
auto size = 4096u;

shared/source/gmm_helper/gmm.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ void Gmm::setupImageResourceParams(ImageInfo &imgInfo) {
123123
applyAuxFlagsForImage(imgInfo);
124124
}
125125

126+
void Gmm::applyAuxFlagsForBuffer(bool preferRenderCompression) {
127+
bool allowRenderCompression = HwHelper::renderCompressedBuffersSupported(*clientContext->getHardwareInfo()) &&
128+
preferRenderCompression;
129+
130+
if (allowRenderCompression) {
131+
resourceParams.Flags.Info.RenderCompressed = 1;
132+
resourceParams.Flags.Gpu.CCS = 1;
133+
resourceParams.Flags.Gpu.UnifiedAuxSurface = 1;
134+
isRenderCompressed = true;
135+
}
136+
}
137+
126138
void Gmm::queryImageParams(ImageInfo &imgInfo) {
127139
auto imageCount = this->gmmResourceInfo->getArraySize();
128140
imgInfo.size = this->gmmResourceInfo->getSizeAllocation();

shared/source/gmm_helper/gmm_utils.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,4 @@
1212
using namespace NEO;
1313

1414
void Gmm::applyAuxFlagsForImage(ImageInfo &imgInfo) {}
15-
void Gmm::applyAuxFlagsForBuffer(bool preferRenderCompression) {}
16-
1715
void Gmm::applyMemoryFlags(bool systemMemoryPool, StorageInfo &storageInfo) { this->useSystemMemoryPool = systemMemoryPool; }

shared/source/memory_manager/memory_manager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemory(const AllocationData &
476476
return allocation;
477477
}
478478
bool use32Allocator = heapAssigner.use32BitHeap(allocationData.type);
479+
479480
if (use32Allocator ||
480481
(force32bitAllocations && allocationData.flags.allow32Bit && is64bit)) {
481482
auto hwInfo = executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getHardwareInfo();

shared/source/os_interface/windows/wddm_memory_manager.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,11 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory64kb(const Allocati
115115
return nullptr;
116116
}
117117

118-
auto cpuPtr = lockResource(wddmAllocation.get());
118+
auto cpuPtr = gmm->isRenderCompressed ? nullptr : lockResource(wddmAllocation.get());
119119

120-
// 64kb map is not needed
121120
auto status = mapGpuVirtualAddress(wddmAllocation.get(), cpuPtr);
122121
DEBUG_BREAK_IF(!status);
123122
wddmAllocation->setCpuAddress(cpuPtr);
124-
125123
return wddmAllocation.release();
126124
}
127125

@@ -204,7 +202,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryWithAlignment(const
204202
maxOsContextCount);
205203
wddmAllocation->setDriverAllocatedCpuPtr(pSysMem);
206204

207-
gmm = new Gmm(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmClientContext(), pSysMem, sizeAligned, allocationData.flags.uncacheable);
205+
gmm = new Gmm(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmClientContext(), pSysMem, sizeAligned, allocationData.flags.uncacheable, allocationData.flags.preferRenderCompressed, true, allocationData.storageInfo);
208206

209207
wddmAllocation->setDefaultGmm(gmm);
210208
void *mapPtr = wddmAllocation->getAlignedCpuPtr();

0 commit comments

Comments
 (0)