Skip to content

Commit 93e3d94

Browse files
Fallback to cpu copy when filling work partition allocation
move some command stream receiver tests to shared Related-To: NEO-6325 Signed-off-by: Mateusz Jablonski <[email protected]>
1 parent 3a2b018 commit 93e3d94

17 files changed

+378
-152
lines changed

opencl/test/unit_test/command_stream/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ set(IGDRCL_SRCS_tests_command_stream
1111
${CMAKE_CURRENT_SOURCE_DIR}/aub_command_stream_receiver_3_tests.cpp
1212
${CMAKE_CURRENT_SOURCE_DIR}/aub_file_stream_tests.cpp
1313
${CMAKE_CURRENT_SOURCE_DIR}/aub_subcapture_tests.cpp
14+
${CMAKE_CURRENT_SOURCE_DIR}/cl_command_stream_receiver_tests.cpp
1415
${CMAKE_CURRENT_SOURCE_DIR}/cmd_parse_tests.cpp
1516
${CMAKE_CURRENT_SOURCE_DIR}/command_stream_fixture.h
1617
${CMAKE_CURRENT_SOURCE_DIR}/command_stream_receiver_hw_1_tests.cpp
1718
${CMAKE_CURRENT_SOURCE_DIR}/command_stream_receiver_hw_2_tests.cpp
1819
${CMAKE_CURRENT_SOURCE_DIR}/command_stream_receiver_hw_fixture.h
1920
${CMAKE_CURRENT_SOURCE_DIR}/command_stream_receiver_hw_tests.inl
2021
${CMAKE_CURRENT_SOURCE_DIR}/command_stream_receiver_mt_tests.cpp
21-
${CMAKE_CURRENT_SOURCE_DIR}/command_stream_receiver_tests.cpp
2222
${CMAKE_CURRENT_SOURCE_DIR}/command_stream_receiver_flush_task_1_tests.cpp
2323
${CMAKE_CURRENT_SOURCE_DIR}/command_stream_receiver_flush_task_2_tests.cpp
2424
${CMAKE_CURRENT_SOURCE_DIR}/command_stream_receiver_flush_task_3_tests.cpp
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
* Copyright (C) 2018-2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "shared/source/memory_manager/surface.h"
9+
#include "shared/test/common/fixtures/device_fixture.h"
10+
#include "shared/test/common/mocks/mock_csr.h"
11+
12+
#include "opencl/source/mem_obj/buffer.h"
13+
#include "opencl/test/unit_test/fixtures/multi_root_device_fixture.h"
14+
#include "opencl/test/unit_test/helpers/raii_hw_helper.h"
15+
#include "opencl/test/unit_test/mocks/mock_context.h"
16+
#include "opencl/test/unit_test/mocks/mock_hw_helper.h"
17+
#include "test.h"
18+
19+
#include "gmock/gmock.h"
20+
21+
using namespace NEO;
22+
23+
TEST(ClCommandStreamReceiverTest, WhenMakingResidentThenBufferResidencyFlagIsSet) {
24+
MockContext context;
25+
auto commandStreamReceiver = context.getDevice(0)->getDefaultEngine().commandStreamReceiver;
26+
float srcMemory[] = {1.0f};
27+
28+
auto retVal = CL_INVALID_VALUE;
29+
auto buffer = Buffer::create(
30+
&context,
31+
CL_MEM_USE_HOST_PTR,
32+
sizeof(srcMemory),
33+
srcMemory,
34+
retVal);
35+
ASSERT_NE(nullptr, buffer);
36+
37+
auto graphicsAllocation = buffer->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex());
38+
EXPECT_FALSE(graphicsAllocation->isResident(commandStreamReceiver->getOsContext().getContextId()));
39+
40+
commandStreamReceiver->makeResident(*graphicsAllocation);
41+
42+
EXPECT_TRUE(graphicsAllocation->isResident(commandStreamReceiver->getOsContext().getContextId()));
43+
44+
delete buffer;
45+
}
46+
47+
using ClCommandStreamReceiverTests = Test<DeviceFixture>;
48+
49+
HWTEST_F(ClCommandStreamReceiverTests, givenCommandStreamReceiverWhenFenceAllocationIsRequiredAndCreateGlobalFenceAllocationIsCalledThenFenceAllocationIsAllocated) {
50+
RAIIHwHelperFactory<MockHwHelperWithFenceAllocation<FamilyType>> hwHelperBackup{pDevice->getHardwareInfo().platform.eRenderCoreFamily};
51+
52+
MockCsrHw<FamilyType> csr(*pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
53+
csr.setupContext(*pDevice->getDefaultEngine().osContext);
54+
EXPECT_EQ(nullptr, csr.globalFenceAllocation);
55+
56+
EXPECT_TRUE(csr.createGlobalFenceAllocation());
57+
58+
ASSERT_NE(nullptr, csr.globalFenceAllocation);
59+
EXPECT_EQ(GraphicsAllocation::AllocationType::GLOBAL_FENCE, csr.globalFenceAllocation->getAllocationType());
60+
}
61+
62+
HWTEST_F(ClCommandStreamReceiverTests, givenCommandStreamReceiverWhenGettingFenceAllocationThenCorrectFenceAllocationIsReturned) {
63+
RAIIHwHelperFactory<MockHwHelperWithFenceAllocation<FamilyType>> hwHelperBackup{pDevice->getHardwareInfo().platform.eRenderCoreFamily};
64+
65+
CommandStreamReceiverHw<FamilyType> csr(*pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
66+
csr.setupContext(*pDevice->getDefaultEngine().osContext);
67+
EXPECT_EQ(nullptr, csr.getGlobalFenceAllocation());
68+
69+
EXPECT_TRUE(csr.createGlobalFenceAllocation());
70+
71+
ASSERT_NE(nullptr, csr.getGlobalFenceAllocation());
72+
EXPECT_EQ(GraphicsAllocation::AllocationType::GLOBAL_FENCE, csr.getGlobalFenceAllocation()->getAllocationType());
73+
}
74+
75+
using CommandStreamReceiverMultiRootDeviceTest = MultiRootDeviceFixture;
76+
77+
TEST_F(CommandStreamReceiverMultiRootDeviceTest, WhenCreatingCommandStreamGraphicsAllocationsThenTheyHaveCorrectRootDeviceIndex) {
78+
auto commandStreamReceiver = &device1->getGpgpuCommandStreamReceiver();
79+
80+
ASSERT_NE(nullptr, commandStreamReceiver);
81+
EXPECT_EQ(expectedRootDeviceIndex, commandStreamReceiver->getRootDeviceIndex());
82+
83+
// Linear stream / Command buffer
84+
GraphicsAllocation *allocation = mockMemoryManager->allocateGraphicsMemoryWithProperties({expectedRootDeviceIndex, 128u, GraphicsAllocation::AllocationType::COMMAND_BUFFER, device1->getDeviceBitfield()});
85+
LinearStream commandStream{allocation};
86+
87+
commandStreamReceiver->ensureCommandBufferAllocation(commandStream, 100u, 0u);
88+
EXPECT_EQ(allocation, commandStream.getGraphicsAllocation());
89+
EXPECT_EQ(128u, commandStream.getMaxAvailableSpace());
90+
EXPECT_EQ(expectedRootDeviceIndex, commandStream.getGraphicsAllocation()->getRootDeviceIndex());
91+
92+
commandStreamReceiver->ensureCommandBufferAllocation(commandStream, 1024u, 0u);
93+
EXPECT_NE(allocation, commandStream.getGraphicsAllocation());
94+
EXPECT_EQ(0u, commandStream.getMaxAvailableSpace() % MemoryConstants::pageSize64k);
95+
EXPECT_EQ(expectedRootDeviceIndex, commandStream.getGraphicsAllocation()->getRootDeviceIndex());
96+
mockMemoryManager->freeGraphicsMemory(commandStream.getGraphicsAllocation());
97+
98+
// Debug surface
99+
auto debugSurface = commandStreamReceiver->allocateDebugSurface(MemoryConstants::pageSize);
100+
ASSERT_NE(nullptr, debugSurface);
101+
EXPECT_EQ(expectedRootDeviceIndex, debugSurface->getRootDeviceIndex());
102+
103+
// Indirect heaps
104+
IndirectHeap::Type heapTypes[]{IndirectHeap::DYNAMIC_STATE, IndirectHeap::INDIRECT_OBJECT, IndirectHeap::SURFACE_STATE};
105+
for (auto heapType : heapTypes) {
106+
IndirectHeap *heap = nullptr;
107+
commandStreamReceiver->allocateHeapMemory(heapType, MemoryConstants::pageSize, heap);
108+
ASSERT_NE(nullptr, heap);
109+
ASSERT_NE(nullptr, heap->getGraphicsAllocation());
110+
EXPECT_EQ(expectedRootDeviceIndex, heap->getGraphicsAllocation()->getRootDeviceIndex());
111+
mockMemoryManager->freeGraphicsMemory(heap->getGraphicsAllocation());
112+
delete heap;
113+
}
114+
115+
// Tag allocation
116+
ASSERT_NE(nullptr, commandStreamReceiver->getTagAllocation());
117+
EXPECT_EQ(expectedRootDeviceIndex, commandStreamReceiver->getTagAllocation()->getRootDeviceIndex());
118+
119+
// Preemption allocation
120+
if (nullptr == commandStreamReceiver->getPreemptionAllocation()) {
121+
commandStreamReceiver->createPreemptionAllocation();
122+
}
123+
EXPECT_EQ(expectedRootDeviceIndex, commandStreamReceiver->getPreemptionAllocation()->getRootDeviceIndex());
124+
125+
// HostPtr surface
126+
char memory[8] = {1, 2, 3, 4, 5, 6, 7, 8};
127+
HostPtrSurface surface(memory, sizeof(memory), true);
128+
EXPECT_TRUE(commandStreamReceiver->createAllocationForHostSurface(surface, false));
129+
ASSERT_NE(nullptr, surface.getAllocation());
130+
EXPECT_EQ(expectedRootDeviceIndex, surface.getAllocation()->getRootDeviceIndex());
131+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,7 @@ TEST_F(DrmMemoryManagerCopyMemoryToAllocationTest, givenDrmMemoryManagerWhenCopy
763763
allocData.flags.allocateMemory = true;
764764
allocData.type = GraphicsAllocation::AllocationType::KERNEL_ISA;
765765
allocData.rootDeviceIndex = rootDeviceIndex;
766+
allocData.storageInfo.memoryBanks.set(0, true);
766767
MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success;
767768
auto allocation = drmMemoryManger.allocateGraphicsMemoryInDevicePool(allocData, status);
768769
ASSERT_NE(nullptr, allocation);
@@ -785,6 +786,7 @@ TEST_F(DrmMemoryManagerCopyMemoryToAllocationTest, givenDrmMemoryManagerWhenCopy
785786
allocData.flags.allocateMemory = true;
786787
allocData.type = GraphicsAllocation::AllocationType::KERNEL_ISA;
787788
allocData.rootDeviceIndex = rootDeviceIndex;
789+
allocData.storageInfo.memoryBanks.set(0, true);
788790
MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success;
789791
auto allocation = drmMemoryManger.allocateGraphicsMemoryInDevicePool(allocData, status);
790792
ASSERT_NE(nullptr, allocation);

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5418,4 +5418,61 @@ TEST_F(DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest, givenOversize
54185418
memoryManager->freeGraphicsMemory(allocation);
54195419
}
54205420

5421+
struct DrmMemoryManagerToTestCopyMemoryToAllocationBanks : public DrmMemoryManager {
5422+
DrmMemoryManagerToTestCopyMemoryToAllocationBanks(ExecutionEnvironment &executionEnvironment, size_t lockableLocalMemorySize)
5423+
: DrmMemoryManager(gemCloseWorkerMode::gemCloseWorkerInactive, false, false, executionEnvironment) {
5424+
lockedLocalMemorySize = lockableLocalMemorySize;
5425+
}
5426+
void *lockResourceInLocalMemoryImpl(BufferObject *bo) override {
5427+
if (lockedLocalMemorySize > 0) {
5428+
if (static_cast<uint32_t>(bo->peekHandle()) < lockedLocalMemory.size()) {
5429+
lockedLocalMemory[bo->peekHandle()].reset(new uint8_t[lockedLocalMemorySize]);
5430+
return lockedLocalMemory[bo->peekHandle()].get();
5431+
}
5432+
}
5433+
return nullptr;
5434+
}
5435+
void unlockResourceInLocalMemoryImpl(BufferObject *bo) override {
5436+
}
5437+
std::array<std::unique_ptr<uint8_t[]>, 4> lockedLocalMemory;
5438+
size_t lockedLocalMemorySize = 0;
5439+
};
5440+
5441+
TEST(DrmMemoryManagerCopyMemoryToAllocationBanksTest, givenDrmMemoryManagerWhenCopyMemoryToAllocationOnSpecificMemoryBanksThenAllocationIsFilledWithCorrectDataOnSpecificBanks) {
5442+
uint8_t sourceData[64]{};
5443+
size_t offset = 3;
5444+
size_t sourceAllocationSize = sizeof(sourceData);
5445+
size_t destinationAllocationSize = sourceAllocationSize + offset;
5446+
MockExecutionEnvironment executionEnvironment;
5447+
auto drm = new DrmMock(mockFd, *executionEnvironment.rootDeviceEnvironments[0]);
5448+
executionEnvironment.rootDeviceEnvironments[0]->osInterface.reset(new OSInterface());
5449+
executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(drm));
5450+
DrmMemoryManagerToTestCopyMemoryToAllocationBanks drmMemoryManger(executionEnvironment, destinationAllocationSize);
5451+
std::vector<uint8_t> dataToCopy(sourceAllocationSize, 1u);
5452+
5453+
MockDrmAllocation mockAllocation(GraphicsAllocation::AllocationType::WORK_PARTITION_SURFACE, MemoryPool::LocalMemory);
5454+
5455+
mockAllocation.storageInfo.memoryBanks = 0b1110;
5456+
DeviceBitfield memoryBanksToCopy = 0b1010;
5457+
mockAllocation.bufferObjects.clear();
5458+
5459+
for (auto index = 0u; index < 4; index++) {
5460+
drmMemoryManger.lockedLocalMemory[index].reset();
5461+
mockAllocation.bufferObjects.push_back(new BufferObject(drm, index, sourceAllocationSize, 3));
5462+
}
5463+
5464+
auto ret = drmMemoryManger.copyMemoryToAllocationBanks(&mockAllocation, offset, dataToCopy.data(), dataToCopy.size(), memoryBanksToCopy);
5465+
EXPECT_TRUE(ret);
5466+
5467+
EXPECT_EQ(nullptr, drmMemoryManger.lockedLocalMemory[0].get());
5468+
ASSERT_NE(nullptr, drmMemoryManger.lockedLocalMemory[1].get());
5469+
EXPECT_EQ(nullptr, drmMemoryManger.lockedLocalMemory[2].get());
5470+
ASSERT_NE(nullptr, drmMemoryManger.lockedLocalMemory[3].get());
5471+
5472+
EXPECT_EQ(0, memcmp(ptrOffset(drmMemoryManger.lockedLocalMemory[1].get(), offset), dataToCopy.data(), dataToCopy.size()));
5473+
EXPECT_EQ(0, memcmp(ptrOffset(drmMemoryManger.lockedLocalMemory[3].get(), offset), dataToCopy.data(), dataToCopy.size()));
5474+
for (auto index = 0u; index < 4; index++) {
5475+
delete mockAllocation.bufferObjects[index];
5476+
}
5477+
}
54215478
} // namespace NEO

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2497,3 +2497,52 @@ TEST_F(WddmMemoryManagerSimpleTest, whenAlignmentRequirementExceedsPageSizeThenA
24972497
EXPECT_EQ(0U, memoryManager.callCount.allocateGraphicsMemoryUsingKmdAndMapItToCpuVA);
24982498
}
24992499
}
2500+
2501+
struct WddmWithMockedLock : public WddmMock {
2502+
using WddmMock::WddmMock;
2503+
2504+
void *lockResource(const D3DKMT_HANDLE &handle, bool applyMakeResidentPriorToLock, size_t size) override {
2505+
if (handle < storageLocked.size()) {
2506+
storageLocked.set(handle);
2507+
}
2508+
return storages[handle];
2509+
}
2510+
std::bitset<4> storageLocked{};
2511+
uint8_t storages[EngineLimits::maxHandleCount][MemoryConstants::pageSize64k] = {0u};
2512+
};
2513+
2514+
TEST(WddmMemoryManagerCopyMemoryToAllocationBanksTest, givenAllocationWithMultiTilePlacementWhenCopyDataSpecificMemoryBanksThenLockOnlySpecificStorages) {
2515+
uint8_t sourceData[32]{};
2516+
size_t offset = 3;
2517+
size_t sourceAllocationSize = sizeof(sourceData);
2518+
auto hwInfo = *defaultHwInfo;
2519+
hwInfo.featureTable.ftrLocalMemory = true;
2520+
2521+
MockExecutionEnvironment executionEnvironment(&hwInfo);
2522+
executionEnvironment.initGmm();
2523+
auto wddm = new WddmWithMockedLock(*executionEnvironment.rootDeviceEnvironments[0]);
2524+
wddm->init();
2525+
MemoryManagerCreate<WddmMemoryManager> memoryManager(true, true, executionEnvironment);
2526+
2527+
MockWddmAllocation mockAllocation(executionEnvironment.rootDeviceEnvironments[0]->getGmmClientContext());
2528+
2529+
mockAllocation.storageInfo.memoryBanks = 0b1110;
2530+
DeviceBitfield memoryBanksToCopy = 0b1010;
2531+
mockAllocation.handles.resize(4);
2532+
for (auto index = 0u; index < 4; index++) {
2533+
wddm->storageLocked.set(index, false);
2534+
if (mockAllocation.storageInfo.memoryBanks.test(index)) {
2535+
mockAllocation.handles[index] = index;
2536+
}
2537+
}
2538+
std::vector<uint8_t> dataToCopy(sourceAllocationSize, 1u);
2539+
auto ret = memoryManager.copyMemoryToAllocationBanks(&mockAllocation, offset, dataToCopy.data(), dataToCopy.size(), memoryBanksToCopy);
2540+
EXPECT_TRUE(ret);
2541+
2542+
EXPECT_FALSE(wddm->storageLocked.test(0));
2543+
ASSERT_TRUE(wddm->storageLocked.test(1));
2544+
EXPECT_FALSE(wddm->storageLocked.test(2));
2545+
ASSERT_TRUE(wddm->storageLocked.test(3));
2546+
EXPECT_EQ(0, memcmp(ptrOffset(wddm->storages[1], offset), dataToCopy.data(), dataToCopy.size()));
2547+
EXPECT_EQ(0, memcmp(ptrOffset(wddm->storages[3], offset), dataToCopy.data(), dataToCopy.size()));
2548+
}

shared/source/command_stream/command_stream_receiver.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -570,12 +570,11 @@ bool CommandStreamReceiver::createWorkPartitionAllocation(const Device &device)
570570
}
571571

572572
const uint32_t copySrc = deviceIndex;
573-
const Vec3<size_t> copySrcSize = {sizeof(copySrc), 1, 1};
574573
DeviceBitfield copyBitfield{};
575574
copyBitfield.set(deviceIndex);
576-
BlitOperationResult blitResult = BlitHelper::blitMemoryToAllocationBanks(device, workPartitionAllocation, 0, &copySrc, copySrcSize, copyBitfield);
575+
auto copySuccess = MemoryTransferHelper::transferMemoryToAllocationBanks(device, workPartitionAllocation, 0, &copySrc, sizeof(copySrc), copyBitfield);
577576

578-
if (blitResult != BlitOperationResult::Success) {
577+
if (!copySuccess) {
579578
return false;
580579
}
581580
}

shared/source/memory_manager/memory_manager.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,11 @@ bool MemoryManager::copyMemoryToAllocation(GraphicsAllocation *graphicsAllocatio
688688
return true;
689689
}
690690

691+
bool MemoryManager::copyMemoryToAllocationBanks(GraphicsAllocation *graphicsAllocation, size_t destinationOffset, const void *memoryToCopy, size_t sizeToCopy, DeviceBitfield dstMemoryBanks) {
692+
memcpy_s(ptrOffset(static_cast<uint8_t *>(graphicsAllocation->getUnderlyingBuffer()), destinationOffset),
693+
(graphicsAllocation->getUnderlyingBufferSize() - destinationOffset), memoryToCopy, sizeToCopy);
694+
return true;
695+
}
691696
void MemoryManager::waitForEnginesCompletion(GraphicsAllocation &graphicsAllocation) {
692697
for (auto &engine : getRegisteredEngines()) {
693698
auto osContextId = engine.osContext->getContextId();
@@ -864,4 +869,13 @@ bool MemoryTransferHelper::transferMemoryToAllocation(bool useBlitter, const Dev
864869
}
865870
return device.getMemoryManager()->copyMemoryToAllocation(dstAllocation, dstOffset, srcMemory, srcSize);
866871
}
872+
bool MemoryTransferHelper::transferMemoryToAllocationBanks(const Device &device, GraphicsAllocation *dstAllocation, size_t dstOffset, const void *srcMemory,
873+
size_t srcSize, DeviceBitfield dstMemoryBanks) {
874+
auto blitSuccess = BlitHelper::blitMemoryToAllocationBanks(device, dstAllocation, dstOffset, srcMemory, {srcSize, 1, 1}, dstMemoryBanks) == BlitOperationResult::Success;
875+
876+
if (!blitSuccess) {
877+
return device.getMemoryManager()->copyMemoryToAllocationBanks(dstAllocation, dstOffset, srcMemory, srcSize, dstMemoryBanks);
878+
}
879+
return true;
880+
}
867881
} // namespace NEO

shared/source/memory_manager/memory_manager.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ constexpr size_t paddingBufferSize = 2 * MemoryConstants::megaByte;
5656

5757
namespace MemoryTransferHelper {
5858
bool transferMemoryToAllocation(bool useBlitter, const Device &device, GraphicsAllocation *dstAllocation, size_t dstOffset, const void *srcMemory, size_t srcSize);
59-
}
59+
bool transferMemoryToAllocationBanks(const Device &device, GraphicsAllocation *dstAllocation, size_t dstOffset, const void *srcMemory,
60+
size_t srcSize, DeviceBitfield dstMemoryBanks);
61+
} // namespace MemoryTransferHelper
6062

6163
class MemoryManager {
6264
public:
@@ -191,6 +193,7 @@ class MemoryManager {
191193
HostPtrManager *getHostPtrManager() const { return hostPtrManager.get(); }
192194
void setDefaultEngineIndex(uint32_t rootDeviceIndex, uint32_t engineIndex) { defaultEngineIndex[rootDeviceIndex] = engineIndex; }
193195
virtual bool copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, size_t destinationOffset, const void *memoryToCopy, size_t sizeToCopy);
196+
virtual bool copyMemoryToAllocationBanks(GraphicsAllocation *graphicsAllocation, size_t destinationOffset, const void *memoryToCopy, size_t sizeToCopy, DeviceBitfield dstMemoryBanks);
194197
HeapIndex selectHeap(const GraphicsAllocation *allocation, bool hasPointer, bool isFullRangeSVM, bool useFrontWindow);
195198
static std::unique_ptr<MemoryManager> createMemoryManager(ExecutionEnvironment &executionEnvironment, DriverModelType driverModel = DriverModelType::UNKNOWN);
196199
virtual void *reserveCpuAddressRange(size_t size, uint32_t rootDeviceIndex) { return nullptr; };

shared/source/os_interface/linux/drm_memory_manager.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1111,8 +1111,17 @@ bool DrmMemoryManager::copyMemoryToAllocation(GraphicsAllocation *graphicsAlloca
11111111
if (graphicsAllocation->getUnderlyingBuffer() || !isLocalMemorySupported(graphicsAllocation->getRootDeviceIndex())) {
11121112
return MemoryManager::copyMemoryToAllocation(graphicsAllocation, destinationOffset, memoryToCopy, sizeToCopy);
11131113
}
1114+
return copyMemoryToAllocationBanks(graphicsAllocation, destinationOffset, memoryToCopy, sizeToCopy, graphicsAllocation->storageInfo.memoryBanks);
1115+
}
1116+
bool DrmMemoryManager::copyMemoryToAllocationBanks(GraphicsAllocation *graphicsAllocation, size_t destinationOffset, const void *memoryToCopy, size_t sizeToCopy, DeviceBitfield dstMemoryBanks) {
1117+
if (MemoryPool::isSystemMemoryPool(graphicsAllocation->getMemoryPool())) {
1118+
return false;
1119+
}
11141120
auto drmAllocation = static_cast<DrmAllocation *>(graphicsAllocation);
1115-
for (auto handleId = 0u; handleId < graphicsAllocation->storageInfo.getNumBanks(); handleId++) {
1121+
for (auto handleId = 0u; handleId < graphicsAllocation->storageInfo.getTotalBanksCnt(); handleId++) {
1122+
if (!dstMemoryBanks.test(handleId)) {
1123+
continue;
1124+
}
11161125
auto ptr = lockResourceInLocalMemoryImpl(drmAllocation->getBOs()[handleId]);
11171126
if (!ptr) {
11181127
return false;

shared/source/os_interface/linux/drm_memory_manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class DrmMemoryManager : public MemoryManager {
5757

5858
DrmGemCloseWorker *peekGemCloseWorker() const { return this->gemCloseWorker.get(); }
5959
bool copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, size_t destinationOffset, const void *memoryToCopy, size_t sizeToCopy) override;
60+
bool copyMemoryToAllocationBanks(GraphicsAllocation *graphicsAllocation, size_t destinationOffset, const void *memoryToCopy, size_t sizeToCopy, DeviceBitfield dstMemoryBanks) override;
6061

6162
MOCKABLE_VIRTUAL int obtainFdFromHandle(int boHandle, uint32_t rootDeviceindex);
6263
AddressRange reserveGpuAddress(size_t size, uint32_t rootDeviceIndex) override;

0 commit comments

Comments
 (0)