Skip to content

Commit 425a2a6

Browse files
fix: set NotLockable flag when resource does not need to be lockable
disable compression preference when resource is lockable Signed-off-by: Mateusz Jablonski <[email protected]>
1 parent 56b167f commit 425a2a6

16 files changed

+70
-15
lines changed

opencl/test/unit_test/command_queue/command_queue_tests_pvc_and_later.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ HWTEST2_F(CommandQueuePvcAndLaterTests, whenPrepareHostPtrSurfaceForSplitThenSet
292292
HostPtrSurface hostPtrSurf(ptr, ptrSize);
293293
queue->getGpgpuCommandStreamReceiver().createAllocationForHostSurface(hostPtrSurf, false);
294294

295+
EXPECT_EQ(1u, hostPtrSurf.getAllocation()->hostPtrTaskCountAssignment.load());
296+
hostPtrSurf.getAllocation()->hostPtrTaskCountAssignment--;
297+
295298
queue->prepareHostPtrSurfaceForSplit(false, *hostPtrSurf.getAllocation());
296299

297300
for (auto i = static_cast<uint32_t>(aub_stream::EngineType::ENGINE_BCS1); i <= static_cast<uint32_t>(aub_stream::EngineType::ENGINE_BCS8); i++) {

opencl/test/unit_test/command_stream/cl_command_stream_receiver_tests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,6 @@ TEST_F(CommandStreamReceiverMultiRootDeviceTest, WhenCreatingCommandStreamGraphi
133133
EXPECT_TRUE(commandStreamReceiver->createAllocationForHostSurface(surface, false));
134134
ASSERT_NE(nullptr, surface.getAllocation());
135135
EXPECT_EQ(expectedRootDeviceIndex, surface.getAllocation()->getRootDeviceIndex());
136+
EXPECT_EQ(1u, surface.getAllocation()->hostPtrTaskCountAssignment.load());
137+
surface.getAllocation()->hostPtrTaskCountAssignment--;
136138
}

opencl/test/unit_test/command_stream/command_stream_receiver_hw_1_tests.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,10 +1090,14 @@ struct RelaxedOrderingBcsTests : public BcsTests {
10901090
}
10911091

10921092
BlitProperties generateBlitProperties(CommandStreamReceiver &csr, Buffer *clBuffer) {
1093-
return BlitProperties::constructPropertiesForReadWrite(BlitterConstants::BlitDirection::HostPtrToBuffer,
1094-
csr, clBuffer->getGraphicsAllocation(pDevice->getRootDeviceIndex()), nullptr, hostPtr,
1095-
clBuffer->getGraphicsAllocation(pDevice->getRootDeviceIndex())->getGpuAddress(), 0,
1096-
0, 0, {1, 1, 1}, 0, 0, 0, 0);
1093+
auto properties = BlitProperties::constructPropertiesForReadWrite(BlitterConstants::BlitDirection::HostPtrToBuffer,
1094+
csr, clBuffer->getGraphicsAllocation(pDevice->getRootDeviceIndex()), nullptr, hostPtr,
1095+
clBuffer->getGraphicsAllocation(pDevice->getRootDeviceIndex())->getGpuAddress(), 0,
1096+
0, 0, {1, 1, 1}, 0, 0, 0, 0);
1097+
EXPECT_EQ(1u, properties.srcAllocation->hostPtrTaskCountAssignment.load());
1098+
properties.srcAllocation->hostPtrTaskCountAssignment--;
1099+
1100+
return properties;
10971101
}
10981102

10991103
std::unique_ptr<VariableBackup<UltHwConfig>> ultHwConfigBackup;

opencl/test/unit_test/command_stream/command_stream_receiver_hw_2_tests.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,6 +1748,9 @@ HWTEST_F(BcsTests, givenHostPtrToImageWhenConstructPropertiesIsCalledThenValuesA
17481748
EXPECT_EQ(dstRowPitchExpected, blitProperties.dstRowPitch);
17491749
EXPECT_EQ(srcSlicePitchExpected, blitProperties.srcSlicePitch);
17501750
EXPECT_EQ(dstSlicePitchExpected, blitProperties.dstSlicePitch);
1751+
1752+
EXPECT_EQ(1u, blitProperties.srcAllocation->hostPtrTaskCountAssignment.load());
1753+
blitProperties.srcAllocation->hostPtrTaskCountAssignment--;
17511754
}
17521755

17531756
HWTEST_F(BcsTests, givenImageToHostPtrWhenConstructPropertiesIsCalledThenValuesAreSetCorrectly) {
@@ -1786,6 +1789,9 @@ HWTEST_F(BcsTests, givenImageToHostPtrWhenConstructPropertiesIsCalledThenValuesA
17861789
EXPECT_EQ(dstRowPitchExpected, blitProperties.dstRowPitch);
17871790
EXPECT_EQ(srcSlicePitchExpected, blitProperties.srcSlicePitch);
17881791
EXPECT_EQ(dstSlicePitchExpected, blitProperties.dstSlicePitch);
1792+
1793+
EXPECT_EQ(1u, blitProperties.dstAllocation->hostPtrTaskCountAssignment.load());
1794+
blitProperties.dstAllocation->hostPtrTaskCountAssignment--;
17891795
}
17901796

17911797
HWTEST_F(BcsTests, givenHostPtrToImageWithInputRowSlicePitchesWhenConstructPropertiesIsCalledThenValuesAreSetCorrectly) {
@@ -1816,6 +1822,9 @@ HWTEST_F(BcsTests, givenHostPtrToImageWithInputRowSlicePitchesWhenConstructPrope
18161822
EXPECT_EQ(dstRowPitchExpected, blitProperties.dstRowPitch);
18171823
EXPECT_EQ(inputSlicePitch, blitProperties.srcSlicePitch);
18181824
EXPECT_EQ(dstSlicePitchExpected, blitProperties.dstSlicePitch);
1825+
1826+
EXPECT_EQ(1u, blitProperties.srcAllocation->hostPtrTaskCountAssignment.load());
1827+
blitProperties.srcAllocation->hostPtrTaskCountAssignment--;
18191828
}
18201829

18211830
HWTEST_F(BcsTests, givenImageToHostPtrWithInputRowSlicePitchesWhenConstructPropertiesIsCalledThenValuesAreSetCorrectly) {
@@ -1847,6 +1856,9 @@ HWTEST_F(BcsTests, givenImageToHostPtrWithInputRowSlicePitchesWhenConstructPrope
18471856
EXPECT_EQ(inputRowPitch, blitProperties.dstRowPitch);
18481857
EXPECT_EQ(srcSlicePitchExpected, blitProperties.srcSlicePitch);
18491858
EXPECT_EQ(inputSlicePitch, blitProperties.dstSlicePitch);
1859+
1860+
EXPECT_EQ(1u, blitProperties.dstAllocation->hostPtrTaskCountAssignment.load());
1861+
blitProperties.dstAllocation->hostPtrTaskCountAssignment--;
18501862
}
18511863

18521864
HWTEST_F(BcsTests, givenHostPtrToImageWhenBlitBufferIsCalledThenBlitCmdIsFound) {

opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ TEST_F(GmmLocalMemoryTests, givenFtrLocalMemoryWhenUsingLocalMemoryAndAllocation
14731473
EXPECT_EQ(0u, gmm->resourceParams.Flags.Info.NotLockable);
14741474
}
14751475

1476-
TEST_F(GmmLocalMemoryTests, givenFtrLocalMemoryWhenUsingLocalMemoryFalseAndAllocationIsNotLockableThenNotLockableFlagsIsSetAndLocalAndNonLocalOnlyAreNotSet) {
1476+
TEST_F(GmmHelperTests, givenNotLockableAllocationWhenCreatingGmmThenNotLockableFlagsIsSetAndLocalAndNonLocalOnlyAreNotSet) {
14771477
StorageInfo storageInfo{};
14781478
storageInfo.isLockable = false;
14791479
storageInfo.memoryBanks.set(1);
@@ -1530,7 +1530,7 @@ TEST_F(GmmLocalMemoryTests, givenLocalMemoryAndStorageInfoWithoutLocalOnlyRequir
15301530
EXPECT_EQ(0u, gmm->resourceParams.Flags.Info.LocalOnly);
15311531
}
15321532

1533-
TEST_F(GmmLocalMemoryTests, givenFtrLocalMemoryAndCompressionEnabledWhenUsingLocalMemoryAndAllocationIsNotLockableThenNotLockableAndLocalOnlyFlagsAreSetAndNonLocalOnlyIsNotSet) {
1533+
TEST_F(GmmHelperTests, givenCompressionEnabledWhenUsingLocalMemoryAndAllocationIsNotLockableThenNotLockableAndLocalOnlyFlagsAreSetAndNonLocalOnlyIsNotSet) {
15341534
DebugManagerStateRestore restorer;
15351535
DebugManager.flags.RenderCompressedBuffersEnabled.set(1);
15361536
StorageInfo storageInfo{};
@@ -1541,10 +1541,23 @@ TEST_F(GmmLocalMemoryTests, givenFtrLocalMemoryAndCompressionEnabledWhenUsingLoc
15411541
auto gmm = std::make_unique<Gmm>(getGmmHelper(), nullptr, 1, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, true, storageInfo, true);
15421542
EXPECT_TRUE(gmm->isCompressionEnabled);
15431543
EXPECT_EQ(0u, gmm->resourceParams.Flags.Info.NonLocalOnly);
1544-
EXPECT_EQ(1u, gmm->resourceParams.Flags.Info.LocalOnly);
1544+
EXPECT_EQ(defaultHwInfo->featureTable.flags.ftrLocalMemory, gmm->resourceParams.Flags.Info.LocalOnly);
15451545
EXPECT_EQ(1u, gmm->resourceParams.Flags.Info.NotLockable);
15461546
}
15471547

1548+
TEST_F(GmmHelperTests, givenCompressionSupportedWhenAllocationIsLockableThenGmmHasNoCompression) {
1549+
DebugManagerStateRestore restorer;
1550+
DebugManager.flags.RenderCompressedBuffersEnabled.set(1);
1551+
StorageInfo storageInfo{};
1552+
storageInfo.isLockable = true;
1553+
storageInfo.systemMemoryPlacement = false;
1554+
storageInfo.memoryBanks.set(1);
1555+
1556+
auto gmm = std::make_unique<Gmm>(getGmmHelper(), nullptr, 1, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, true, storageInfo, true);
1557+
EXPECT_FALSE(gmm->isCompressionEnabled);
1558+
EXPECT_EQ(0u, gmm->resourceParams.Flags.Info.NotLockable);
1559+
}
1560+
15481561
TEST_F(GmmLocalMemoryTests, givenFtrLocalMemoryWhenUseSystemMemoryIsFalseAndAllocationIsNotLockableThenLocalAndNonLocalOnlyAndNotLockableFlagsAreNotSet) {
15491562
DebugManagerStateRestore restorer;
15501563
for (auto csrMode = static_cast<int32_t>(CommandStreamReceiverType::CSR_HW); csrMode < static_cast<int32_t>(CommandStreamReceiverType::CSR_TYPES_NUM); csrMode++) {

opencl/test/unit_test/mem_obj/buffer_tests.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,11 +1973,14 @@ HWTEST_F(BufferCreateTests, givenClMemCopyHostPointerPassedToBufferCreateWhenAll
19731973
DebugManagerStateRestore subTestRestorer;
19741974
DebugManager.flags.RenderCompressedBuffersEnabled.set(1);
19751975
DebugManager.flags.OverrideBufferSuitableForRenderCompression.set(1);
1976+
19761977
cl_int retVal;
19771978
cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR;
19781979
auto writeBufferCounter = commandQueue->writeBufferCounter;
19791980
size_t lockResourceCalled = memoryManager->lockResourceCalled;
19801981

1982+
static_cast<MockGfxCoreHelperHwWithSetIsLockable<FamilyType> *>(executionEnvironment->rootDeviceEnvironments[0]->gfxCoreHelper.get())->setIsLockable = false;
1983+
19811984
std::unique_ptr<Buffer> buffer(Buffer::create(&context, flags, sizeof(memory), memory, retVal));
19821985
ASSERT_NE(nullptr, buffer.get());
19831986
EXPECT_EQ(commandQueue->writeBufferCounter, writeBufferCounter + 1);

opencl/test/unit_test/memory_manager/migraton_controller_tests.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ HWTEST2_F(MigrationControllerTests, givenMultiGraphicsAllocationUsedInOneCsrWhen
184184

185185
ASSERT_TRUE(pImage->getMultiGraphicsAllocation().requiresMigrations());
186186

187+
pImage->getMultiGraphicsAllocation().getGraphicsAllocation(0)->getDefaultGmm()->resourceParams.Flags.Info.NotLockable = false;
188+
pImage->getMultiGraphicsAllocation().getGraphicsAllocation(1)->getDefaultGmm()->resourceParams.Flags.Info.NotLockable = false;
189+
187190
auto migrationSyncData = static_cast<MockMigrationSyncData *>(pImage->getMultiGraphicsAllocation().getMigrationSyncData());
188191

189192
EXPECT_EQ(0u, migrationSyncData->waitOnCpuCalled);

opencl/test/unit_test/program/printf_handler_tests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ HWTEST_F(PrintfHandlerTests, givenGpuHangOnFlushBcsStreamAndEnabledStatelessComp
191191
EXPECT_FALSE(printfHandler->printEnqueueOutput());
192192
EXPECT_EQ(1u, bcsCsr->blitBufferCalled);
193193
EXPECT_EQ(BlitterConstants::BlitDirection::BufferToHostPtr, bcsCsr->receivedBlitProperties[0].blitDirection);
194+
EXPECT_EQ(1u, bcsCsr->receivedBlitProperties[0].dstAllocation->hostPtrTaskCountAssignment.load());
195+
bcsCsr->receivedBlitProperties[0].dstAllocation->hostPtrTaskCountAssignment--;
194196
}
195197

196198
HWTEST_F(PrintfHandlerTests, givenDisallowedLocalMemoryCpuAccessWhenPrintEnqueueOutputIsCalledThenBCSEngineIsUsedToCopyPrintfOutput) {

shared/source/gmm_helper/gmm.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ Gmm::Gmm(GmmHelper *gmmHelper, const void *alignedPtr, size_t alignedSize, size_
5454
resourceParams.Flags.Gpu.NoRestriction = 1;
5555
}
5656

57+
preferCompressed &= !storageInfo.isLockable;
58+
5759
applyAuxFlagsForBuffer(preferCompressed);
5860
applyMemoryFlags(storageInfo);
5961
applyAppResource(storageInfo);
@@ -73,6 +75,7 @@ Gmm::~Gmm() = default;
7375

7476
Gmm::Gmm(GmmHelper *gmmHelper, ImageInfo &inputOutputImgInfo, const StorageInfo &storageInfo, bool preferCompressed) : gmmHelper(gmmHelper) {
7577
this->resourceParams = {};
78+
preferCompressed &= !storageInfo.isLockable;
7679
setupImageResourceParams(inputOutputImgInfo, preferCompressed);
7780
applyMemoryFlags(storageInfo);
7881
applyAppResource(storageInfo);
@@ -346,13 +349,15 @@ void Gmm::applyMemoryFlags(const StorageInfo &storageInfo) {
346349
if (extraMemoryFlagsRequired()) {
347350
applyExtraMemoryFlags(storageInfo);
348351
} else if (!storageInfo.isLockable) {
349-
resourceParams.Flags.Info.NotLockable = 1;
350352
if (isCompressionEnabled || storageInfo.localOnlyRequired) {
351353
resourceParams.Flags.Info.LocalOnly = 1;
352354
}
353355
}
354356
}
355357
}
358+
if (!storageInfo.isLockable) {
359+
resourceParams.Flags.Info.NotLockable = 1;
360+
}
356361

357362
if (hardwareInfo->featureTable.flags.ftrMultiTileArch) {
358363
resourceParams.MultiTileArch.Enable = 1;

shared/test/common/libult/ult_command_stream_receiver.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,7 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw<GfxFamily>, publ
363363
bool createAllocationForHostSurface(HostPtrSurface &surface, bool requiresL3Flush) override {
364364
createAllocationForHostSurfaceCalled++;
365365
cpuCopyForHostPtrSurfaceAllowed = surface.peekIsPtrCopyAllowed();
366-
auto status = BaseClass::createAllocationForHostSurface(surface, requiresL3Flush);
367-
if (status)
368-
surface.getAllocation()->hostPtrTaskCountAssignment--;
369-
return status;
366+
return BaseClass::createAllocationForHostSurface(surface, requiresL3Flush);
370367
}
371368

372369
void ensureCommandBufferAllocation(LinearStream &commandStream, size_t minimumRequiredSize, size_t additionalAllocationSize) override {

shared/test/unit_test/command_stream/aub_command_stream_receiver_2_tests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ class OsAgnosticMemoryManagerForImagesWithNoHostPtr : public OsAgnosticMemoryMan
586586
};
587587

588588
using AubCommandStreamReceiverNoHostPtrTests = ::testing::Test;
589-
HWTEST_F(AubCommandStreamReceiverNoHostPtrTests, givenAubCommandStreamReceiverWhenWriteMemoryIsCalledOnImageWithNoHostPtrThenResourceShouldBeLockedToGetCpuAddress) {
589+
HWTEST_F(AubCommandStreamReceiverNoHostPtrTests, givenAubCommandStreamReceiverWhenWriteMemoryIsCalledOnLockableImageWithNoHostPtrThenResourceShouldBeLockedToGetCpuAddress) {
590590
ExecutionEnvironment *executionEnvironment = new MockExecutionEnvironment();
591591
auto memoryManager = new OsAgnosticMemoryManagerForImagesWithNoHostPtr(*executionEnvironment);
592592
executionEnvironment->memoryManager.reset(memoryManager);
@@ -611,6 +611,7 @@ HWTEST_F(AubCommandStreamReceiverNoHostPtrTests, givenAubCommandStreamReceiverWh
611611

612612
auto imageAllocation = memoryManager->allocateGraphicsMemoryInPreferredPool(allocProperties, nullptr);
613613
ASSERT_NE(nullptr, imageAllocation);
614+
imageAllocation->getDefaultGmm()->resourceParams.Flags.Info.NotLockable = false;
614615

615616
EXPECT_TRUE(aubCsr->writeMemory(*imageAllocation));
616617

shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,9 @@ TEST_F(CreateAllocationForHostSurfaceTest, givenReadOnlyHostPointerWhenAllocatio
17991799
auto allocation = surface.getAllocation();
18001800
ASSERT_NE(nullptr, allocation);
18011801

1802+
EXPECT_EQ(1u, allocation->hostPtrTaskCountAssignment.load());
1803+
allocation->hostPtrTaskCountAssignment--;
1804+
18021805
EXPECT_NE(memory, allocation->getUnderlyingBuffer());
18031806
EXPECT_EQ(0, memcmp(allocation->getUnderlyingBuffer(), memory, size));
18041807

shared/test/unit_test/helpers/blit_commands_helper_tests.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ TEST(BlitCommandsHelperTest, GivenBufferParamsWhenConstructingPropertiesForReadW
6666
EXPECT_EQ(blitProperties.dstSlicePitch, dstSlicePitch);
6767
EXPECT_EQ(blitProperties.srcRowPitch, srcRowPitch);
6868
EXPECT_EQ(blitProperties.srcSlicePitch, srcSlicePitch);
69+
70+
EXPECT_EQ(1u, blitProperties.dstAllocation->hostPtrTaskCountAssignment.load());
71+
blitProperties.dstAllocation->hostPtrTaskCountAssignment--;
6972
}
7073

7174
TEST(BlitCommandsHelperTest, GivenBufferParamsWhenConstructingPropertiesForBufferRegionsThenPropertiesCreatedCorrectly) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ TEST_F(WddmMemoryManagerTests, GivenNotCompressedAndNotLockableAllocationTypeWhe
107107

108108
EXPECT_NE(nullptr, graphicsAllocation);
109109

110-
EXPECT_TRUE(graphicsAllocation->storageInfo.isLockable);
110+
EXPECT_TRUE(graphicsAllocation->isAllocationLockable());
111111

112112
memoryManager->freeGraphicsMemory(graphicsAllocation);
113113
}
@@ -126,7 +126,7 @@ TEST_F(WddmMemoryManagerTests, GivenCompressedAndNotLockableAllocationTypeWhenAl
126126

127127
EXPECT_NE(nullptr, graphicsAllocation);
128128

129-
EXPECT_FALSE(graphicsAllocation->storageInfo.isLockable);
129+
EXPECT_FALSE(graphicsAllocation->isAllocationLockable());
130130

131131
memoryManager->freeGraphicsMemory(graphicsAllocation);
132132
}

shared/test/unit_test/os_interface/windows/wddm_special_heap_test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ TEST_F(WddmFrontWindowPoolAllocatorTests, givenAllocateInFrontWindowPoolFlagWhen
5858

5959
if (preferredAllocationMethod == GfxMemoryAllocationMethod::AllocateByKmd) {
6060
EXPECT_TRUE(allocation->isAllocationLockable());
61+
} else {
62+
EXPECT_FALSE(allocation->isAllocationLockable());
6163
}
6264
memManager->freeGraphicsMemory(allocation);
6365
}

shared/test/unit_test/program/program_initialization_tests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreNotExportedTh
6767
}
6868

6969
TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreExportedThenMemoryIsAllocatedAsUsmDeviceAllocation) {
70+
DebugManagerStateRestore restorer;
71+
DebugManager.flags.ForceLocalMemoryAccessMode.set(0);
7072
MockDevice device{};
7173
REQUIRE_SVM_OR_SKIP(&device);
7274
device.injectMemoryManager(new MockMemoryManager());

0 commit comments

Comments
 (0)