fix: set mmapPtr in every allocation in multiGraphicAllocation

Related-To: GSD-7360
Signed-off-by: Warchulski, Jaroslaw <jaroslaw.warchulski@intel.com>
This commit is contained in:
Warchulski, Jaroslaw 2024-01-16 14:15:07 +00:00 committed by Compute-Runtime-Automation
parent dad44f48ed
commit f7dc17e6a2
5 changed files with 21 additions and 12 deletions

View File

@ -113,8 +113,14 @@ class DrmAllocation : public GraphicsAllocation {
bool setAtomicAccess(Drm *drm, size_t size, AtomicAccessMode mode); bool setAtomicAccess(Drm *drm, size_t size, AtomicAccessMode mode);
bool setMemPrefetch(Drm *drm, SubDeviceIdsVec &subDeviceIds); bool setMemPrefetch(Drm *drm, SubDeviceIdsVec &subDeviceIds);
void *getMmapPtr() { return this->mmapPtr; } void *getMmapPtr() {
if (this->importedMmapPtr)
return this->importedMmapPtr;
else
return this->mmapPtr;
}
void setMmapPtr(void *ptr) { this->mmapPtr = ptr; } void setMmapPtr(void *ptr) { this->mmapPtr = ptr; }
void setImportedMmapPtr(void *ptr) { this->importedMmapPtr = ptr; }
size_t getMmapSize() { return this->mmapSize; } size_t getMmapSize() { return this->mmapSize; }
void setMmapSize(size_t size) { this->mmapSize = size; } void setMmapSize(size_t size) { this->mmapSize = size; }
@ -151,6 +157,7 @@ class DrmAllocation : public GraphicsAllocation {
std::vector<uint64_t> handles; std::vector<uint64_t> handles;
void *mmapPtr = nullptr; void *mmapPtr = nullptr;
void *importedMmapPtr = nullptr;
size_t mmapSize = 0u; size_t mmapSize = 0u;
bool usmHostAllocation = false; bool usmHostAllocation = false;

View File

@ -951,7 +951,7 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o
bool reuseSharedAllocation, bool reuseSharedAllocation,
void *mapPointer) { void *mapPointer) {
if (isHostIpcAllocation) { if (isHostIpcAllocation) {
return createUSMHostAllocationFromSharedHandle(handle, properties, false, reuseSharedAllocation); return createUSMHostAllocationFromSharedHandle(handle, properties, nullptr, reuseSharedAllocation);
} }
std::unique_lock<std::mutex> lock(mtx); std::unique_lock<std::mutex> lock(mtx);
@ -1190,7 +1190,7 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromExistingStorag
if (ret < 0) { if (ret < 0) {
return nullptr; return nullptr;
} }
return createUSMHostAllocationFromSharedHandle(static_cast<osHandle>(internalHandle), properties, true, true); return createUSMHostAllocationFromSharedHandle(static_cast<osHandle>(internalHandle), properties, ptr, true);
} else { } else {
return allocateGraphicsMemoryWithProperties(properties, ptr); return allocateGraphicsMemoryWithProperties(properties, ptr);
} }
@ -2439,7 +2439,7 @@ GraphicsAllocation *DrmMemoryManager::createSharedUnifiedMemoryAllocation(const
DrmAllocation *DrmMemoryManager::createUSMHostAllocationFromSharedHandle(osHandle handle, DrmAllocation *DrmMemoryManager::createUSMHostAllocationFromSharedHandle(osHandle handle,
const AllocationProperties &properties, const AllocationProperties &properties,
bool hasMappedPtr, void *mappedPtr,
bool reuseSharedAllocation) { bool reuseSharedAllocation) {
PrimeHandle openFd{}; PrimeHandle openFd{};
openFd.fileDescriptor = handle; openFd.fileDescriptor = handle;
@ -2458,14 +2458,16 @@ DrmAllocation *DrmMemoryManager::createUSMHostAllocationFromSharedHandle(osHandl
return nullptr; return nullptr;
} }
if (hasMappedPtr) { if (mappedPtr) {
auto bo = new BufferObject(properties.rootDeviceIndex, &drm, patIndex, openFd.handle, properties.size, maxOsContextCount); auto bo = new BufferObject(properties.rootDeviceIndex, &drm, patIndex, openFd.handle, properties.size, maxOsContextCount);
bo->setAddress(properties.gpuAddress); bo->setAddress(properties.gpuAddress);
auto gmmHelper = getGmmHelper(properties.rootDeviceIndex); auto gmmHelper = getGmmHelper(properties.rootDeviceIndex);
auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(reinterpret_cast<void *>(bo->peekAddress()))); auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(reinterpret_cast<void *>(bo->peekAddress())));
return new DrmAllocation(properties.rootDeviceIndex, properties.allocationType, bo, reinterpret_cast<void *>(bo->peekAddress()), bo->peekSize(), auto allocation = new DrmAllocation(properties.rootDeviceIndex, properties.allocationType, bo, reinterpret_cast<void *>(bo->peekAddress()), bo->peekSize(),
handle, memoryPool, canonizedGpuAddress); handle, memoryPool, canonizedGpuAddress);
allocation->setImportedMmapPtr(mappedPtr);
return allocation;
} }
const bool useBooMmap = drm.getMemoryInfo() && properties.useMmapObject; const bool useBooMmap = drm.getMemoryInfo() && properties.useMmapObject;

View File

@ -90,7 +90,7 @@ class DrmMemoryManager : public MemoryManager {
static std::unique_ptr<MemoryManager> create(ExecutionEnvironment &executionEnvironment); static std::unique_ptr<MemoryManager> create(ExecutionEnvironment &executionEnvironment);
DrmAllocation *createUSMHostAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool hasMappedPtr, bool reuseSharedAllocation); DrmAllocation *createUSMHostAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, void *mappedPtr, bool reuseSharedAllocation);
void releaseDeviceSpecificMemResources(uint32_t rootDeviceIndex) override; void releaseDeviceSpecificMemResources(uint32_t rootDeviceIndex) override;
void createDeviceSpecificMemResources(uint32_t rootDeviceIndex) override; void createDeviceSpecificMemResources(uint32_t rootDeviceIndex) override;
bool allowIndirectAllocationsAsPack(uint32_t rootDeviceIndex) override; bool allowIndirectAllocationsAsPack(uint32_t rootDeviceIndex) override;

View File

@ -123,11 +123,11 @@ TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenMultiRootDeviceEnvironmentAnd
auto ptr = memoryManager->createMultiGraphicsAllocationInSystemMemoryPool(rootDeviceIndices, properties, multiGraphics); auto ptr = memoryManager->createMultiGraphicsAllocationInSystemMemoryPool(rootDeviceIndices, properties, multiGraphics);
EXPECT_NE(ptr, nullptr); EXPECT_NE(ptr, nullptr);
EXPECT_NE(static_cast<DrmAllocation *>(multiGraphics.getDefaultGraphicsAllocation())->getMmapPtr(), nullptr);
for (uint32_t i = 0; i < rootDevicesNumber; i++) { for (uint32_t i = 0; i < rootDevicesNumber; i++) {
if (i != 0) { if (i != 0) {
EXPECT_EQ(static_cast<DrmQueryMock *>(executionEnvironment->rootDeviceEnvironments[i]->osInterface->getDriverModel()->as<Drm>())->inputFd, 7); EXPECT_EQ(static_cast<DrmQueryMock *>(executionEnvironment->rootDeviceEnvironments[i]->osInterface->getDriverModel()->as<Drm>())->inputFd, 7);
} }
EXPECT_NE(static_cast<DrmAllocation *>(multiGraphics.getGraphicsAllocation(i))->getMmapPtr(), nullptr);
EXPECT_NE(multiGraphics.getGraphicsAllocation(i), nullptr); EXPECT_NE(multiGraphics.getGraphicsAllocation(i), nullptr);
memoryManager->freeGraphicsMemory(multiGraphics.getGraphicsAllocation(i)); memoryManager->freeGraphicsMemory(multiGraphics.getGraphicsAllocation(i));
} }
@ -244,7 +244,7 @@ TEST_F(DrmMemoryManagerUsmSharedHandlePrelimTest, givenMultiRootDeviceEnvironmen
size_t size = 4096u; size_t size = 4096u;
AllocationProperties properties(rootDeviceIndex, true, size, AllocationType::bufferHostMemory, false, {}); AllocationProperties properties(rootDeviceIndex, true, size, AllocationType::bufferHostMemory, false, {});
auto ptr = memoryManager->createUSMHostAllocationFromSharedHandle(1, properties, false, true); auto ptr = memoryManager->createUSMHostAllocationFromSharedHandle(1, properties, nullptr, true);
EXPECT_EQ(ptr, nullptr); EXPECT_EQ(ptr, nullptr);
executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(osInterface); executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(osInterface);
@ -282,8 +282,8 @@ TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenMultiRootDeviceEnvironmentAnd
EXPECT_NE(ptr, nullptr); EXPECT_NE(ptr, nullptr);
EXPECT_EQ(static_cast<DrmAllocation *>(multiGraphics.getDefaultGraphicsAllocation())->getMmapPtr(), nullptr);
for (uint32_t i = 0; i < rootDevicesNumber; i++) { for (uint32_t i = 0; i < rootDevicesNumber; i++) {
EXPECT_EQ(static_cast<DrmAllocation *>(multiGraphics.getGraphicsAllocation(i))->getMmapPtr(), nullptr);
EXPECT_NE(multiGraphics.getGraphicsAllocation(i), nullptr); EXPECT_NE(multiGraphics.getGraphicsAllocation(i), nullptr);
memoryManager->freeGraphicsMemory(multiGraphics.getGraphicsAllocation(i)); memoryManager->freeGraphicsMemory(multiGraphics.getGraphicsAllocation(i));
} }

View File

@ -278,7 +278,7 @@ TEST_F(DrmMemoryManagerUsmSharedHandleTest, givenMultiRootDeviceEnvironmentAndMe
size_t size = 4096u; size_t size = 4096u;
AllocationProperties properties(rootDeviceIndex, true, size, AllocationType::bufferHostMemory, false, {}); AllocationProperties properties(rootDeviceIndex, true, size, AllocationType::bufferHostMemory, false, {});
auto ptr = memoryManager->createUSMHostAllocationFromSharedHandle(1, properties, false, true); auto ptr = memoryManager->createUSMHostAllocationFromSharedHandle(1, properties, nullptr, true);
EXPECT_EQ(ptr, nullptr); EXPECT_EQ(ptr, nullptr);