Skip to content

Commit 739c1c6

Browse files
Pass maxOsContextCount to BufferObject
Change-Id: I9e64718a5a64096c8fdc50f3b84d3843701ff602 Signed-off-by: Mateusz Jablonski <[email protected]>
1 parent 53cb6a1 commit 739c1c6

10 files changed

+39
-38
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ namespace NEO {
1414
class MockBufferObject : public BufferObject {
1515
public:
1616
using BufferObject::bindInfo;
17+
using BufferObject::BufferObject;
1718
using BufferObject::handle;
1819

19-
MockBufferObject(Drm *drm) : BufferObject(drm, 0, 0) {
20+
MockBufferObject(Drm *drm) : BufferObject(drm, 0, 0, 1) {
2021
}
2122
};
2223

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ using namespace NEO;
2525

2626
class TestedBufferObject : public BufferObject {
2727
public:
28-
TestedBufferObject(Drm *drm) : BufferObject(drm, 1, 0) {
28+
TestedBufferObject(Drm *drm) : BufferObject(drm, 1, 0, 1) {
2929
}
3030

3131
void tileBy(uint32_t mode) {
@@ -188,7 +188,7 @@ TEST(DrmBufferObjectSimpleTest, givenInvalidBoWhenPinIsCalledThenErrorIsReturned
188188

189189
TEST(DrmBufferObjectSimpleTest, givenBufferObjectWhenConstructedWithASizeThenTheSizeIsInitialized) {
190190
std::unique_ptr<DrmMockCustom> drmMock(new DrmMockCustom);
191-
std::unique_ptr<BufferObject> bo(new BufferObject(drmMock.get(), 1, 0x1000));
191+
std::unique_ptr<BufferObject> bo(new BufferObject(drmMock.get(), 1, 0x1000, 1));
192192

193193
EXPECT_EQ(0x1000u, bo->peekSize());
194194
}
@@ -231,7 +231,7 @@ TEST_F(DrmBufferObjectTest, givenDeleterWhenBufferObjectIsCreatedAndDeletedThenC
231231
mock->ioctl_expected.reset();
232232

233233
{
234-
std::unique_ptr<BufferObject, BufferObject::Deleter> bo(new BufferObject(mock.get(), 1, 0x1000));
234+
std::unique_ptr<BufferObject, BufferObject::Deleter> bo(new BufferObject(mock.get(), 1, 0x1000, 1));
235235
}
236236

237237
EXPECT_EQ(1, mock->ioctl_cnt.gemClose);
@@ -245,9 +245,9 @@ TEST(DrmBufferObject, givenPerContextVmRequiredWhenBoCreatedThenBindInfoIsInitia
245245
device->getExecutionEnvironment()->calculateMaxOsContextCount();
246246
DrmMock drm(*(device->getExecutionEnvironment()->rootDeviceEnvironments[0].get()));
247247
EXPECT_TRUE(drm.isPerContextVMRequired());
248-
MockBufferObject bo(&drm);
249-
250248
auto osContextCount = device->getExecutionEnvironment()->memoryManager->getRegisteredEnginesCount();
249+
MockBufferObject bo(&drm, 0, 0, osContextCount);
250+
251251
EXPECT_EQ(osContextCount, bo.bindInfo.size());
252252

253253
for (auto &iter : bo.bindInfo) {
@@ -273,9 +273,9 @@ TEST(DrmBufferObject, givenPerContextVmRequiredWhenBoBoundAndUnboundThenCorrectB
273273

274274
std::unique_ptr<Device> device(MockDevice::createWithExecutionEnvironment<MockDevice>(defaultHwInfo.get(), executionEnvironment, 0));
275275

276-
MockBufferObject bo(drm);
277-
278276
auto osContextCount = device->getExecutionEnvironment()->memoryManager->getRegisteredEnginesCount();
277+
MockBufferObject bo(drm, 0, 0, osContextCount);
278+
279279
EXPECT_EQ(osContextCount, bo.bindInfo.size());
280280

281281
auto contextId = device->getExecutionEnvironment()->memoryManager->getRegisteredEnginesCount() / 2;

opencl/test/unit_test/os_interface/linux/drm_command_stream_fixture.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class DrmCommandStreamEnhancedTemplate : public ::testing::Test {
147147
friend DrmCommandStreamEnhancedTemplate<T>;
148148

149149
protected:
150-
MockBufferObject(Drm *drm, size_t size) : BufferObject(drm, 1, 0) {
150+
MockBufferObject(Drm *drm, size_t size) : BufferObject(drm, 1, 0, 16u) {
151151
this->size = alignUp(size, 4096);
152152
}
153153
};

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ TEST_F(DrmGemCloseWorkerTests, gemClose) {
104104
this->drmMock->gem_close_expected = 1;
105105

106106
auto worker = new DrmGemCloseWorker(*mm);
107-
auto bo = new BufferObject(this->drmMock, 1, 0);
107+
auto bo = new BufferObject(this->drmMock, 1, 0, 1);
108108

109109
worker->push(bo);
110110

@@ -115,7 +115,7 @@ TEST_F(DrmGemCloseWorkerTests, gemCloseExit) {
115115
this->drmMock->gem_close_expected = -1;
116116

117117
auto worker = new DrmGemCloseWorker(*mm);
118-
auto bo = new BufferObject(this->drmMock, 1, 0);
118+
auto bo = new BufferObject(this->drmMock, 1, 0, 1);
119119

120120
worker->push(bo);
121121

@@ -135,7 +135,7 @@ TEST_F(DrmGemCloseWorkerTests, close) {
135135
this->drmMock->gem_close_expected = -1;
136136

137137
auto worker = new DrmGemCloseWorker(*mm);
138-
auto bo = new BufferObject(this->drmMock, 1, 0);
138+
auto bo = new BufferObject(this->drmMock, 1, 0, 1);
139139

140140
worker->push(bo);
141141
worker->close(false);
@@ -153,7 +153,7 @@ TEST_F(DrmGemCloseWorkerTests, givenAllocationWhenAskedForUnreferenceWithForceFl
153153
this->drmMock->gem_close_expected = 1;
154154

155155
auto worker = new DrmGemCloseWorker(*mm);
156-
auto bo = new BufferObject(this->drmMock, 1, 0);
156+
auto bo = new BufferObject(this->drmMock, 1, 0, 1);
157157

158158
bo->reference();
159159
worker->push(bo);

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenGetLocalMemoryIsCalledThen
104104

105105
namespace NEO {
106106

107-
BufferObject *createBufferObjectInMemoryRegion(Drm *drm, uint64_t gpuAddress, size_t size, uint32_t memoryBanks);
107+
BufferObject *createBufferObjectInMemoryRegion(Drm *drm, uint64_t gpuAddress, size_t size, uint32_t memoryBanks, size_t maxOsContextCount);
108108

109109
class DrmMemoryManagerLocalMemoryTest : public ::testing::Test {
110110
public:
@@ -166,7 +166,7 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, givenDrmMemoryManagerWhenCreateBufferObj
166166
auto gpuAddress = 0x1234u;
167167
auto size = MemoryConstants::pageSize64k;
168168

169-
auto bo = std::unique_ptr<BufferObject>(createBufferObjectInMemoryRegion(&memoryManager->getDrm(0), gpuAddress, size, (1 << (MemoryBanks::Bank0 - 1))));
169+
auto bo = std::unique_ptr<BufferObject>(createBufferObjectInMemoryRegion(&memoryManager->getDrm(0), gpuAddress, size, (1 << (MemoryBanks::Bank0 - 1)), 1));
170170
ASSERT_NE(nullptr, bo);
171171

172172
EXPECT_EQ(1u, mock->ioctlCallsCount);
@@ -195,7 +195,7 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, givenDrmMemoryManagerWhenCreateBufferObj
195195
auto gpuAddress = 0x1234u;
196196
auto size = MemoryConstants::pageSize;
197197

198-
auto bo = std::unique_ptr<BufferObject>(createBufferObjectInMemoryRegion(&memoryManager->getDrm(0), gpuAddress, size, MemoryBanks::MainBank));
198+
auto bo = std::unique_ptr<BufferObject>(createBufferObjectInMemoryRegion(&memoryManager->getDrm(0), gpuAddress, size, MemoryBanks::MainBank, 1));
199199
EXPECT_EQ(nullptr, bo);
200200
}
201201

@@ -207,7 +207,7 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, givenDrmMemoryManagerWhenCreateBufferObj
207207
auto gpuAddress = 0x1234u;
208208
auto size = MemoryConstants::pageSize;
209209

210-
auto bo = std::unique_ptr<BufferObject>(createBufferObjectInMemoryRegion(&memoryManager->getDrm(0), gpuAddress, size, MemoryBanks::MainBank));
210+
auto bo = std::unique_ptr<BufferObject>(createBufferObjectInMemoryRegion(&memoryManager->getDrm(0), gpuAddress, size, MemoryBanks::MainBank, 1));
211211
EXPECT_EQ(nullptr, bo);
212212
}
213213

@@ -217,7 +217,7 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, givenDrmMemoryManagerWhenCreateBufferObj
217217
auto gpuAddress = 0x1234u;
218218
auto size = 0u;
219219

220-
auto bo = std::unique_ptr<BufferObject>(createBufferObjectInMemoryRegion(&memoryManager->getDrm(0), gpuAddress, size, MemoryBanks::MainBank));
220+
auto bo = std::unique_ptr<BufferObject>(createBufferObjectInMemoryRegion(&memoryManager->getDrm(0), gpuAddress, size, MemoryBanks::MainBank, 1));
221221
EXPECT_EQ(nullptr, bo);
222222
}
223223

@@ -643,7 +643,7 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, givenDrmMemoryManagerWithLocalMemoryWhen
643643
}
644644

645645
TEST_F(DrmMemoryManagerLocalMemoryWithCustomMockTest, givenDrmMemoryManagerWithLocalMemoryWhenLockResourceIsCalledOnBufferObjectThenReturnPtr) {
646-
BufferObject bo(mock, 1, 1024);
646+
BufferObject bo(mock, 1, 1024, 0);
647647

648648
DrmAllocation drmAllocation(0, GraphicsAllocation::AllocationType::UNKNOWN, &bo, nullptr, 0u, 0u, MemoryPool::LocalMemory);
649649
EXPECT_EQ(&bo, drmAllocation.getBO());
@@ -657,7 +657,7 @@ TEST_F(DrmMemoryManagerLocalMemoryWithCustomMockTest, givenDrmMemoryManagerWithL
657657
}
658658

659659
TEST_F(DrmMemoryManagerLocalMemoryWithCustomMockTest, givenDrmMemoryManagerWithLocalMemoryWhenLockResourceIsCalledOnWriteCombinedAllocationThenReturnPtrAlignedTo64Kb) {
660-
BufferObject bo(mock, 1, 1024);
660+
BufferObject bo(mock, 1, 1024, 0);
661661

662662
DrmAllocation drmAllocation(0, GraphicsAllocation::AllocationType::WRITE_COMBINED, &bo, nullptr, 0u, 0u, MemoryPool::LocalMemory);
663663
EXPECT_EQ(&bo, drmAllocation.getBO());
@@ -851,7 +851,7 @@ TEST_F(DrmMemoryManagerTestDg1, givenDrmMemoryManagerWhenLockUnlockIsCalledOnAll
851851
this->ioctlResExt = {mockDg1->ioctl_cnt.total, -1};
852852
mockDg1->ioctl_res_ext = &ioctlResExt;
853853

854-
BufferObject bo(mockDg1, 1, 0);
854+
BufferObject bo(mockDg1, 1, 0, 0);
855855
DrmAllocation drmAllocation(0, GraphicsAllocation::AllocationType::UNKNOWN, &bo, nullptr, 0u, 0u, MemoryPool::LocalMemory);
856856
EXPECT_NE(nullptr, drmAllocation.getBO());
857857

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,7 +2383,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenLockUnlockIsCalledButFails
23832383

23842384
DrmMockCustom drmMock;
23852385
struct BufferObjectMock : public BufferObject {
2386-
BufferObjectMock(Drm *drm) : BufferObject(drm, 1, 0) {}
2386+
BufferObjectMock(Drm *drm) : BufferObject(drm, 1, 0, 1) {}
23872387
};
23882388
BufferObjectMock bo(&drmMock);
23892389
DrmAllocation drmAllocation(rootDeviceIndex, GraphicsAllocation::AllocationType::UNKNOWN, &bo, nullptr, 0u, (osHandle)0u, MemoryPool::MemoryNull);
@@ -2416,7 +2416,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenUnlockResourceIsCalledOnAl
24162416

24172417
DrmMockCustom drmMock;
24182418
struct BufferObjectMock : public BufferObject {
2419-
BufferObjectMock(Drm *drm) : BufferObject(drm, 1, 0) {}
2419+
BufferObjectMock(Drm *drm) : BufferObject(drm, 1, 0, 1) {}
24202420
};
24212421
auto bo = new BufferObjectMock(&drmMock);
24222422
auto drmAllocation = new DrmAllocation(rootDeviceIndex, GraphicsAllocation::AllocationType::UNKNOWN, bo, nullptr, 0u, (osHandle)0u, MemoryPool::LocalMemory);
@@ -2443,7 +2443,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSetDomainCpuIsCalledButFai
24432443

24442444
DrmMockCustom drmMock;
24452445
struct BufferObjectMock : public BufferObject {
2446-
BufferObjectMock(Drm *drm) : BufferObject(drm, 1, 0) {}
2446+
BufferObjectMock(Drm *drm) : BufferObject(drm, 1, 0, 1) {}
24472447
};
24482448
BufferObjectMock bo(&drmMock);
24492449
DrmAllocation drmAllocation(rootDeviceIndex, GraphicsAllocation::AllocationType::UNKNOWN, &bo, nullptr, 0u, (osHandle)0u, MemoryPool::MemoryNull);
@@ -2459,7 +2459,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSetDomainCpuIsCalledOnAllo
24592459

24602460
DrmMockCustom drmMock;
24612461
struct BufferObjectMock : public BufferObject {
2462-
BufferObjectMock(Drm *drm) : BufferObject(drm, 1, 0) {}
2462+
BufferObjectMock(Drm *drm) : BufferObject(drm, 1, 0, 1) {}
24632463
};
24642464
BufferObjectMock bo(&drmMock);
24652465
DrmAllocation drmAllocation(rootDeviceIndex, GraphicsAllocation::AllocationType::UNKNOWN, &bo, nullptr, 0u, (osHandle)0u, MemoryPool::MemoryNull);
@@ -2981,7 +2981,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDisabledForcePinAndEna
29812981

29822982
class PinBufferObject : public BufferObject {
29832983
public:
2984-
PinBufferObject(Drm *drm) : BufferObject(drm, 1, 0) {
2984+
PinBufferObject(Drm *drm) : BufferObject(drm, 1, 0, 1) {
29852985
}
29862986

29872987
int pin(BufferObject *const boToPin[], size_t numberOfBos, OsContext *osContext, uint32_t vmHandleId, uint32_t drmContextId) override {

shared/source/os_interface/linux/drm_buffer_object.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@
3030

3131
namespace NEO {
3232

33-
BufferObject::BufferObject(Drm *drm, int handle, size_t size) : drm(drm), refCount(1), handle(handle), size(size), isReused(false) {
33+
BufferObject::BufferObject(Drm *drm, int handle, size_t size, size_t maxOsContextCount) : drm(drm), refCount(1), handle(handle), size(size), isReused(false) {
3434
this->tiling_mode = I915_TILING_NONE;
3535
this->lockedAddress = nullptr;
3636

3737
perContextVmsUsed = drm->isPerContextVMRequired();
3838

3939
if (perContextVmsUsed) {
40-
bindInfo.resize(MemoryManager::maxOsContextCount);
40+
bindInfo.resize(maxOsContextCount);
4141
for (auto &iter : bindInfo) {
4242
iter.fill(false);
4343
}

shared/source/os_interface/linux/drm_buffer_object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class BufferObject {
2929
friend DrmMemoryManager;
3030

3131
public:
32-
BufferObject(Drm *drm, int handle, size_t size);
32+
BufferObject(Drm *drm, int handle, size_t size, size_t maxOsContextCount);
3333
MOCKABLE_VIRTUAL ~BufferObject(){};
3434

3535
struct Deleter {

shared/source/os_interface/linux/drm_memory_manager.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ NEO::BufferObject *DrmMemoryManager::allocUserptr(uintptr_t address, size_t size
175175
return nullptr;
176176
}
177177

178-
auto res = new (std::nothrow) BufferObject(&getDrm(rootDeviceIndex), userptr.handle, size);
178+
auto res = new (std::nothrow) BufferObject(&getDrm(rootDeviceIndex), userptr.handle, size, maxOsContextCount);
179179
if (!res) {
180180
DEBUG_BREAK_IF(true);
181181
return nullptr;
@@ -349,7 +349,7 @@ GraphicsAllocation *DrmMemoryManager::allocateShareableMemory(const AllocationDa
349349
DEBUG_BREAK_IF(ret != 0);
350350
((void)(ret));
351351

352-
std::unique_ptr<BufferObject, BufferObject::Deleter> bo(new BufferObject(&getDrm(allocationData.rootDeviceIndex), create.handle, bufferSize));
352+
std::unique_ptr<BufferObject, BufferObject::Deleter> bo(new BufferObject(&getDrm(allocationData.rootDeviceIndex), create.handle, bufferSize, maxOsContextCount));
353353
bo->gpuAddress = gpuRange;
354354

355355
auto allocation = new DrmAllocation(allocationData.rootDeviceIndex, allocationData.type, bo.get(), nullptr, gpuRange, bufferSize, MemoryPool::SystemCpuInaccessible);
@@ -378,7 +378,7 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryForImageImpl(const A
378378
DEBUG_BREAK_IF(ret != 0);
379379
UNUSED_VARIABLE(ret);
380380

381-
std::unique_ptr<BufferObject, BufferObject::Deleter> bo(new (std::nothrow) BufferObject(&getDrm(allocationData.rootDeviceIndex), create.handle, allocationData.imgInfo->size));
381+
std::unique_ptr<BufferObject, BufferObject::Deleter> bo(new (std::nothrow) BufferObject(&getDrm(allocationData.rootDeviceIndex), create.handle, allocationData.imgInfo->size, maxOsContextCount));
382382
if (!bo) {
383383
return nullptr;
384384
}
@@ -484,7 +484,7 @@ BufferObject *DrmMemoryManager::createSharedBufferObject(int boHandle, size_t si
484484

485485
gpuRange = acquireGpuRange(size, requireSpecificBitness, rootDeviceIndex, isLocalMemorySupported(rootDeviceIndex));
486486

487-
auto bo = new (std::nothrow) BufferObject(&getDrm(rootDeviceIndex), boHandle, size);
487+
auto bo = new (std::nothrow) BufferObject(&getDrm(rootDeviceIndex), boHandle, size, maxOsContextCount);
488488
if (!bo) {
489489
return nullptr;
490490
}

shared/source/os_interface/linux/drm_memory_manager_allocate_in_device_pool_dg1.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
namespace NEO {
2020

21-
BufferObject *createBufferObjectInMemoryRegion(Drm *drm, uint64_t gpuAddress, size_t size, uint32_t memoryBanks) {
21+
BufferObject *createBufferObjectInMemoryRegion(Drm *drm, uint64_t gpuAddress, size_t size, uint32_t memoryBanks, size_t maxOsContextCount) {
2222
auto memoryInfo = static_cast<MemoryInfoImpl *>(drm->getMemoryInfo());
2323
if (!memoryInfo) {
2424
return nullptr;
@@ -50,7 +50,7 @@ BufferObject *createBufferObjectInMemoryRegion(Drm *drm, uint64_t gpuAddress, si
5050
return nullptr;
5151
}
5252

53-
auto bo = new (std::nothrow) BufferObject(drm, createExt.handle, size);
53+
auto bo = new (std::nothrow) BufferObject(drm, createExt.handle, size, maxOsContextCount);
5454
if (!bo) {
5555
return nullptr;
5656
}
@@ -85,7 +85,7 @@ uint64_t getGpuAddress(GraphicsAllocation::AllocationType allocType, GfxPartitio
8585
return gpuAddress;
8686
}
8787

88-
bool createDrmAllocation(Drm *drm, DrmAllocation *allocation, uint64_t gpuAddress) {
88+
bool createDrmAllocation(Drm *drm, DrmAllocation *allocation, uint64_t gpuAddress, size_t maxOsContextCount) {
8989
std::array<std::unique_ptr<BufferObject>, EngineLimits::maxHandleCount> bos{};
9090
auto &storageInfo = allocation->storageInfo;
9191
auto boAddress = gpuAddress;
@@ -95,7 +95,7 @@ bool createDrmAllocation(Drm *drm, DrmAllocation *allocation, uint64_t gpuAddres
9595
memoryBanks &= 1u << handleId;
9696
}
9797
auto boSize = alignUp(allocation->getGmm(handleId)->gmmResourceInfo->getSizeAllocation(), MemoryConstants::pageSize64k);
98-
bos[handleId] = std::unique_ptr<BufferObject>(createBufferObjectInMemoryRegion(drm, boAddress, boSize, memoryBanks));
98+
bos[handleId] = std::unique_ptr<BufferObject>(createBufferObjectInMemoryRegion(drm, boAddress, boSize, memoryBanks, maxOsContextCount));
9999
if (nullptr == bos[handleId]) {
100100
return false;
101101
}
@@ -148,7 +148,7 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryInDevicePool(const A
148148
allocation->setFlushL3Required(allocationData.flags.flushL3);
149149
allocation->setReservedAddressRange(reinterpret_cast<void *>(gpuAddress), sizeAllocated);
150150

151-
if (!createDrmAllocation(&getDrm(allocationData.rootDeviceIndex), allocation.get(), gpuAddress)) {
151+
if (!createDrmAllocation(&getDrm(allocationData.rootDeviceIndex), allocation.get(), gpuAddress, maxOsContextCount)) {
152152
for (auto handleId = 0u; handleId < allocationData.storageInfo.getNumBanks(); handleId++) {
153153
delete allocation->getGmm(handleId);
154154
}

0 commit comments

Comments
 (0)