Fix shared buffer object size

Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
This commit is contained in:
Lukasz Jobczyk 2021-03-02 11:53:34 +00:00 committed by Compute-Runtime-Automation
parent 049166688c
commit 8fa97ed4a8
5 changed files with 18 additions and 21 deletions

View File

@ -13,7 +13,7 @@ using namespace NEO;
void MemoryAllocatorMultiDeviceSystemSpecificFixture::SetUp(ExecutionEnvironment &executionEnvironment) {
auto memoryManager = static_cast<TestedDrmMemoryManager *>(executionEnvironment.memoryManager.get());
auto bufferObject = memoryManager->createSharedBufferObject(0u, 10, true, 0u);
auto bufferObject = new (std::nothrow) BufferObject(&memoryManager->getDrm(0u), 0, 10, MemoryManager::maxOsContextCount);
memoryManager->pushSharedBufferObject(bufferObject);
}

View File

@ -2003,7 +2003,8 @@ TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmMemoryManagerWithLocalMemory
ASSERT_NE(nullptr, graphicsAllocation);
EXPECT_NE(nullptr, graphicsAllocation->getUnderlyingBuffer());
EXPECT_EQ(alignUp(size, 2 * MemoryConstants::megaByte), graphicsAllocation->getUnderlyingBufferSize());
EXPECT_EQ(size, graphicsAllocation->getUnderlyingBufferSize());
EXPECT_EQ(alignUp(size, 2 * MemoryConstants::megaByte), graphicsAllocation->getReservedAddressSize());
EXPECT_EQ(MemoryPool::SystemCpuInaccessible, graphicsAllocation->getMemoryPool());
EXPECT_EQ(this->mock->inputFd, static_cast<int32_t>(handle));
@ -2015,7 +2016,7 @@ TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmMemoryManagerWithLocalMemory
auto bo = drmAllocation->getBO();
EXPECT_EQ(this->mock->outputHandle, static_cast<uint32_t>(bo->peekHandle()));
EXPECT_EQ(gpuAddress, bo->peekAddress());
EXPECT_EQ(alignUp(size, 2 * MemoryConstants::megaByte), bo->peekSize());
EXPECT_EQ(size, bo->peekSize());
EXPECT_EQ(handle, graphicsAllocation->peekSharedHandle());

View File

@ -567,21 +567,6 @@ BufferObject *DrmMemoryManager::findAndReferenceSharedBufferObject(int boHandle)
return bo;
}
BufferObject *DrmMemoryManager::createSharedBufferObject(int boHandle, size_t size, bool requireSpecificBitness, uint32_t rootDeviceIndex) {
uint64_t gpuRange = 0llu;
gpuRange = acquireGpuRange(size, requireSpecificBitness, rootDeviceIndex, isLocalMemorySupported(rootDeviceIndex));
auto bo = new (std::nothrow) BufferObject(&getDrm(rootDeviceIndex), boHandle, size, maxOsContextCount);
if (!bo) {
return nullptr;
}
bo->gpuAddress = gpuRange;
bo->setUnmapSize(size);
return bo;
}
GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) {
std::unique_lock<std::mutex> lock(mtx);
@ -601,14 +586,24 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o
auto boHandle = openFd.handle;
auto bo = findAndReferenceSharedBufferObject(boHandle);
uint64_t gpuRange = 0llu;
size_t reservedRange = 0u;
if (bo == nullptr) {
size_t size = lseekFunction(handle, 0, SEEK_END);
bo = createSharedBufferObject(boHandle, size, requireSpecificBitness, properties.rootDeviceIndex);
bo = new (std::nothrow) BufferObject(&getDrm(properties.rootDeviceIndex), boHandle, size, maxOsContextCount);
if (!bo) {
return nullptr;
}
gpuRange = acquireGpuRange(size, requireSpecificBitness, properties.rootDeviceIndex, isLocalMemorySupported(properties.rootDeviceIndex));
bo->setAddress(gpuRange);
bo->setUnmapSize(size);
reservedRange = size;
pushSharedBufferObject(bo);
}
@ -616,6 +611,9 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o
auto drmAllocation = new DrmAllocation(properties.rootDeviceIndex, properties.allocationType, bo, reinterpret_cast<void *>(bo->gpuAddress), bo->size,
handle, MemoryPool::SystemCpuInaccessible);
if (reservedRange) {
drmAllocation->setReservedAddressRange(reinterpret_cast<void *>(gpuRange), reservedRange);
}
if (requireSpecificBitness && this->force32bitAllocations) {
drmAllocation->set32BitAllocation(true);

View File

@ -73,7 +73,6 @@ class DrmMemoryManager : public MemoryManager {
protected:
BufferObject *findAndReferenceSharedBufferObject(int boHandle);
BufferObject *createSharedBufferObject(int boHandle, size_t size, bool requireSpecificBitness, uint32_t rootDeviceIndex);
void eraseSharedBufferObject(BufferObject *bo);
void pushSharedBufferObject(BufferObject *bo);
BufferObject *allocUserptr(uintptr_t address, size_t size, uint64_t flags, uint32_t rootDeviceIndex);

View File

@ -72,7 +72,6 @@ class TestedDrmMemoryManager : public MemoryManagerCreate<DrmMemoryManager> {
using DrmMemoryManager::createAllocWithAlignment;
using DrmMemoryManager::createAllocWithAlignmentFromUserptr;
using DrmMemoryManager::createGraphicsAllocation;
using DrmMemoryManager::createSharedBufferObject;
using DrmMemoryManager::eraseSharedBufferObject;
using DrmMemoryManager::getDefaultDrmContextId;
using DrmMemoryManager::getDrm;