Skip to content

Commit 516a905

Browse files
Mark Scratch and Private allocations for capture
Related-To: NEO-5237 Signed-off-by: Mateusz Hoppe <[email protected]>
1 parent 85b7256 commit 516a905

File tree

9 files changed

+83
-1
lines changed

9 files changed

+83
-1
lines changed

opencl/test/unit_test/memory_manager/memory_manager_tests.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2568,3 +2568,10 @@ TEST(MemoryManagerTest, givenDebugModuleAreaAllocationTypeWhenCallingGetAllocati
25682568
mockMemoryManager.getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties));
25692569
EXPECT_EQ(1u, allocData.flags.use32BitFrontWindow);
25702570
}
2571+
2572+
TEST(MemoryManagerTest, WhenCallingIsAllocationTypeToCaptureThenScratchAndPrivateTypesReturnTrue) {
2573+
MockMemoryManager mockMemoryManager;
2574+
2575+
EXPECT_TRUE(mockMemoryManager.isAllocationTypeToCapture(GraphicsAllocation::AllocationType::SCRATCH_SURFACE));
2576+
EXPECT_TRUE(mockMemoryManager.isAllocationTypeToCapture(GraphicsAllocation::AllocationType::PRIVATE_SURFACE));
2577+
}

opencl/test/unit_test/mocks/linux/mock_drm_allocation.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2020 Intel Corporation
2+
* Copyright (C) 2019-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -36,7 +36,13 @@ class MockDrmAllocation : public DrmAllocation {
3636
DrmAllocation::registerBOBindExtHandle(drm);
3737
}
3838

39+
void markForCapture() override {
40+
markedForCapture = true;
41+
DrmAllocation::markForCapture();
42+
}
43+
3944
bool registerBOBindExtHandleCalled = false;
45+
bool markedForCapture = false;
4046
};
4147

4248
} // namespace NEO

opencl/test/unit_test/mocks/mock_memory_manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
4949
using OsAgnosticMemoryManager::allocateGraphicsMemoryForImageFromHostPtr;
5050
using MemoryManagerCreate<OsAgnosticMemoryManager>::MemoryManagerCreate;
5151
using MemoryManager::enable64kbpages;
52+
using MemoryManager::isAllocationTypeToCapture;
5253
using MemoryManager::isCopyRequired;
5354
using MemoryManager::localMemorySupported;
5455
using MemoryManager::reservedMemory;

opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4081,6 +4081,32 @@ TEST(DrmMemoryManager, givenTrackedAllocationTypeAndDisabledRegistrationInDrmWhe
40814081
EXPECT_EQ(Drm::ResourceClass::MaxSize, mockDrm->registeredClass);
40824082
}
40834083

4084+
TEST(DrmMemoryManager, givenResourceRegistrationEnabledAndAllocTypeToCaptureWhenRegisteringAllocationInOsThenItIsMarkedForCapture) {
4085+
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
4086+
executionEnvironment->prepareRootDeviceEnvironments(1u);
4087+
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
4088+
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(false, false, false, *executionEnvironment);
4089+
auto mockDrm = new DrmMockResources(*executionEnvironment->rootDeviceEnvironments[0]);
4090+
executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();
4091+
executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setDrm(mockDrm);
4092+
4093+
// mock resource registration enabling by storing class handles
4094+
mockDrm->classHandles.push_back(1);
4095+
4096+
MockBufferObject bo(mockDrm, 0, 0, 1);
4097+
MockDrmAllocation allocation(GraphicsAllocation::AllocationType::SCRATCH_SURFACE, MemoryPool::System4KBPages);
4098+
allocation.bufferObjects[0] = &bo;
4099+
memoryManager->registerAllocationInOs(&allocation);
4100+
4101+
EXPECT_TRUE(allocation.markedForCapture);
4102+
4103+
MockDrmAllocation allocation2(GraphicsAllocation::AllocationType::BUFFER, MemoryPool::System4KBPages);
4104+
allocation2.bufferObjects[0] = &bo;
4105+
memoryManager->registerAllocationInOs(&allocation2);
4106+
4107+
EXPECT_FALSE(allocation2.markedForCapture);
4108+
}
4109+
40844110
TEST(DrmMemoryManager, givenTrackedAllocationTypeWhenAllocatingThenAllocationIsRegistered) {
40854111
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
40864112
executionEnvironment->prepareRootDeviceEnvironments(1u);
@@ -4279,6 +4305,22 @@ TEST(DrmAllocationTest, givenDrmAllocationWhenCacheRegionIsSetSuccessfullyThenSe
42794305
}
42804306
}
42814307

4308+
TEST(DrmAllocationTest, givenBoWhenMarkingForCaptureThenBosAreMarked) {
4309+
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
4310+
executionEnvironment->prepareRootDeviceEnvironments(1);
4311+
4312+
DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
4313+
4314+
MockBufferObject bo(&drm, 0, 0, 1);
4315+
MockDrmAllocation allocation(GraphicsAllocation::AllocationType::SCRATCH_SURFACE, MemoryPool::System4KBPages);
4316+
allocation.markForCapture();
4317+
4318+
allocation.bufferObjects[0] = &bo;
4319+
allocation.markForCapture();
4320+
4321+
EXPECT_TRUE(bo.isMarkedForCapture());
4322+
}
4323+
42824324
TEST_F(DrmMemoryManagerTest, givenDrmAllocationWithHostPtrWhenItIsCreatedWithCacheRegionThenSetRegionInBufferObject) {
42834325
mock->ioctl_expected.total = -1;
42844326
auto drm = static_cast<DrmMockCustom *>(executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface->get()->getDrm());

shared/source/memory_manager/memory_manager.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,17 @@ void MemoryManager::overrideAllocationData(AllocationData &allocationData, const
748748
}
749749
}
750750

751+
bool MemoryManager::isAllocationTypeToCapture(GraphicsAllocation::AllocationType type) const {
752+
switch (type) {
753+
case GraphicsAllocation::AllocationType::SCRATCH_SURFACE:
754+
case GraphicsAllocation::AllocationType::PRIVATE_SURFACE:
755+
return true;
756+
default:
757+
break;
758+
}
759+
return false;
760+
}
761+
751762
bool MemoryTransferHelper::transferMemoryToAllocation(bool useBlitter, const Device &device, GraphicsAllocation *dstAllocation, size_t dstOffset, const void *srcMemory, size_t srcSize) {
752763
if (useBlitter) {
753764
return (BlitHelperFunctions::blitMemoryToAllocation(device, dstAllocation, dstOffset, srcMemory, {srcSize, 1, 1}) == BlitOperationResult::Success);

shared/source/memory_manager/memory_manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ class MemoryManager {
223223
virtual void unlockResourceImpl(GraphicsAllocation &graphicsAllocation) = 0;
224224
virtual void freeAssociatedResourceImpl(GraphicsAllocation &graphicsAllocation) { return unlockResourceImpl(graphicsAllocation); };
225225
virtual void registerAllocationInOs(GraphicsAllocation *allocation) {}
226+
bool isAllocationTypeToCapture(GraphicsAllocation::AllocationType type) const;
226227

227228
bool initialized = false;
228229
bool forceNonSvmForExternalHostPtr = false;

shared/source/os_interface/linux/drm_allocation.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,13 @@ void DrmAllocation::freeRegisteredBOBindExtHandles(Drm *drm) {
147147
drm->unregisterResource(i);
148148
}
149149
}
150+
151+
void DrmAllocation::markForCapture() {
152+
auto &bos = getBOs();
153+
for (auto bo : bos) {
154+
if (bo) {
155+
bo->markForCapture();
156+
}
157+
}
158+
}
150159
} // namespace NEO

shared/source/os_interface/linux/drm_allocation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class DrmAllocation : public GraphicsAllocation {
7878
MOCKABLE_VIRTUAL void registerBOBindExtHandle(Drm *drm);
7979
void freeRegisteredBOBindExtHandles(Drm *drm);
8080
void linkWithRegisteredHandle(uint32_t handle);
81+
MOCKABLE_VIRTUAL void markForCapture();
8182

8283
protected:
8384
BufferObjects bufferObjects{};

shared/source/os_interface/linux/drm_memory_manager.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,10 @@ void DrmMemoryManager::registerAllocationInOs(GraphicsAllocation *allocation) {
995995
if (allocation && getDrm(allocation->getRootDeviceIndex()).resourceRegistrationEnabled()) {
996996
auto drmAllocation = static_cast<DrmAllocation *>(allocation);
997997
drmAllocation->registerBOBindExtHandle(&getDrm(drmAllocation->getRootDeviceIndex()));
998+
999+
if (isAllocationTypeToCapture(drmAllocation->getAllocationType())) {
1000+
drmAllocation->markForCapture();
1001+
}
9981002
}
9991003
}
10001004
} // namespace NEO

0 commit comments

Comments
 (0)