mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-24 21:18:24 +08:00
Add support for IPC handles with implicit scaling
When using implicit scaling, device allocations may have more than one internal allocation created internally. In that case, a separate dma-buf handle per internal allocation needs to be exported. So introduced two driver experimental extensions to export and import more than one IPC handle: - zexMemGetIpcHandles - zexMemOpenIpcHandles Related-To: LOCI-2919 Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
c0de4fd243
commit
3f26f45c10
@@ -40,6 +40,10 @@ uint64_t DrmAllocation::peekInternalHandle(MemoryManager *memoryManager) {
|
||||
return static_cast<uint64_t>((static_cast<DrmMemoryManager *>(memoryManager))->obtainFdFromHandle(getBO()->peekHandle(), this->rootDeviceIndex));
|
||||
}
|
||||
|
||||
uint64_t DrmAllocation::peekInternalHandle(MemoryManager *memoryManager, uint32_t handleId) {
|
||||
return static_cast<uint64_t>((static_cast<DrmMemoryManager *>(memoryManager))->obtainFdFromHandle(getBufferObjectToModify(handleId)->peekHandle(), this->rootDeviceIndex));
|
||||
}
|
||||
|
||||
void DrmAllocation::setCachePolicy(CachePolicy memType) {
|
||||
for (auto bo : bufferObjects) {
|
||||
if (bo != nullptr) {
|
||||
|
||||
@@ -78,8 +78,18 @@ class DrmAllocation : public GraphicsAllocation {
|
||||
this->bufferObjects.resize(size);
|
||||
}
|
||||
|
||||
uint32_t getNumHandles() override {
|
||||
return this->numHandles;
|
||||
}
|
||||
|
||||
void setNumHandles(uint32_t numHandles) override {
|
||||
this->numHandles = numHandles;
|
||||
}
|
||||
|
||||
uint64_t peekInternalHandle(MemoryManager *memoryManager) override;
|
||||
|
||||
uint64_t peekInternalHandle(MemoryManager *memoryManager, uint32_t handleId) override;
|
||||
|
||||
bool setCacheRegion(Drm *drm, CacheRegion regionIndex);
|
||||
bool setCacheAdvice(Drm *drm, size_t regionSize, CacheRegion regionIndex);
|
||||
void setCachePolicy(CachePolicy memType);
|
||||
@@ -107,6 +117,7 @@ class DrmAllocation : public GraphicsAllocation {
|
||||
StackVec<uint32_t, 1> registeredBoBindHandles;
|
||||
MemAdviseFlags enabledMemAdviseFlags{};
|
||||
StackVec<MemoryToUnmap, 1> memoryToUnmap;
|
||||
uint32_t numHandles = 0u;
|
||||
|
||||
void *mmapPtr = nullptr;
|
||||
size_t mmapSize = 0u;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "shared/source/helpers/ptr_math.h"
|
||||
#include "shared/source/helpers/string.h"
|
||||
#include "shared/source/helpers/surface_format_info.h"
|
||||
#include "shared/source/memory_manager/allocation_properties.h"
|
||||
#include "shared/source/memory_manager/host_ptr_manager.h"
|
||||
#include "shared/source/memory_manager/memory_banks.h"
|
||||
#include "shared/source/memory_manager/memory_pool.h"
|
||||
@@ -654,6 +655,101 @@ BufferObject *DrmMemoryManager::findAndReferenceSharedBufferObject(int boHandle,
|
||||
return bo;
|
||||
}
|
||||
|
||||
GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromMultipleSharedHandles(std::vector<osHandle> handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) {
|
||||
BufferObjects bos;
|
||||
std::vector<size_t> sizes;
|
||||
size_t totalSize = 0;
|
||||
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
|
||||
uint32_t i = 0;
|
||||
|
||||
if (handles.size() != 1) {
|
||||
properties.multiStorageResource = true;
|
||||
}
|
||||
|
||||
auto &drm = this->getDrm(properties.rootDeviceIndex);
|
||||
|
||||
bool areBosSharedObjects = true;
|
||||
|
||||
for (auto handle : handles) {
|
||||
drm_prime_handle openFd = {0, 0, 0};
|
||||
openFd.fd = handle;
|
||||
|
||||
auto ret = this->getDrm(properties.rootDeviceIndex).ioctl(DRM_IOCTL_PRIME_FD_TO_HANDLE, &openFd);
|
||||
|
||||
if (ret != 0) {
|
||||
[[maybe_unused]] int err = errno;
|
||||
PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stderr, "ioctl(PRIME_FD_TO_HANDLE) failed with %d. errno=%d(%s)\n", ret, err, strerror(err));
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto boHandle = openFd.handle;
|
||||
auto bo = findAndReferenceSharedBufferObject(boHandle, properties.rootDeviceIndex);
|
||||
|
||||
if (bo == nullptr) {
|
||||
areBosSharedObjects = false;
|
||||
|
||||
size_t size = lseekFunction(handle, 0, SEEK_END);
|
||||
totalSize += size;
|
||||
|
||||
auto patIndex = drm.getPatIndex(nullptr, properties.allocationType, CacheRegion::Default, CachePolicy::WriteBack, false);
|
||||
|
||||
bo = new (std::nothrow) BufferObject(&drm, patIndex, boHandle, size, maxOsContextCount);
|
||||
bo->setRootDeviceIndex(properties.rootDeviceIndex);
|
||||
i++;
|
||||
}
|
||||
bos.push_back(bo);
|
||||
sizes.push_back(bo->peekSize());
|
||||
}
|
||||
|
||||
auto heapIndex = HeapIndex::HEAP_STANDARD2MB;
|
||||
auto gpuRange = acquireGpuRange(totalSize, properties.rootDeviceIndex, heapIndex);
|
||||
|
||||
lock.unlock();
|
||||
|
||||
AllocationData allocationData;
|
||||
properties.size = totalSize;
|
||||
getAllocationData(allocationData, properties, nullptr, createStorageInfoFromProperties(properties));
|
||||
|
||||
auto drmAllocation = new DrmAllocation(properties.rootDeviceIndex,
|
||||
handles.size(),
|
||||
properties.allocationType,
|
||||
bos,
|
||||
nullptr,
|
||||
gpuRange,
|
||||
totalSize,
|
||||
MemoryPool::LocalMemory);
|
||||
drmAllocation->storageInfo = allocationData.storageInfo;
|
||||
|
||||
auto gmmHelper = executionEnvironment.rootDeviceEnvironments[properties.rootDeviceIndex]->getGmmHelper();
|
||||
for (i = 0u; i < handles.size(); i++) {
|
||||
auto bo = bos[i];
|
||||
StorageInfo limitedStorageInfo = allocationData.storageInfo;
|
||||
limitedStorageInfo.memoryBanks &= (1u << (i % handles.size()));
|
||||
auto gmm = new Gmm(gmmHelper,
|
||||
nullptr,
|
||||
bo->peekSize(),
|
||||
0u,
|
||||
CacheSettingsHelper::getGmmUsageType(drmAllocation->getAllocationType(), false, *gmmHelper->getHardwareInfo()),
|
||||
false,
|
||||
allocationData.storageInfo,
|
||||
true);
|
||||
drmAllocation->setGmm(gmm, i);
|
||||
|
||||
if (areBosSharedObjects == false) {
|
||||
bo->setAddress(gpuRange);
|
||||
gpuRange += bo->peekSize();
|
||||
bo->setUnmapSize(sizes[i]);
|
||||
pushSharedBufferObject(bo);
|
||||
}
|
||||
drmAllocation->getBufferObjectToModify(i) = bo;
|
||||
}
|
||||
|
||||
return drmAllocation;
|
||||
}
|
||||
|
||||
GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) {
|
||||
if (isHostIpcAllocation) {
|
||||
return createUSMHostAllocationFromSharedHandle(handle, properties, false);
|
||||
@@ -1468,6 +1564,7 @@ bool DrmMemoryManager::createDrmAllocation(Drm *drm, DrmAllocation *allocation,
|
||||
allocation->resizeBufferObjects(handles);
|
||||
bos.resize(handles);
|
||||
}
|
||||
allocation->setNumHandles(handles);
|
||||
|
||||
for (auto handleId = 0u; handleId < handles; handleId++, currentBank++) {
|
||||
if (currentBank == banksCnt) {
|
||||
|
||||
@@ -36,6 +36,7 @@ class DrmMemoryManager : public MemoryManager {
|
||||
void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation, bool isImportedAllocation) override;
|
||||
void handleFenceCompletion(GraphicsAllocation *allocation) override;
|
||||
GraphicsAllocation *createGraphicsAllocationFromExistingStorage(AllocationProperties &properties, void *ptr, MultiGraphicsAllocation &multiGraphicsAllocation) override;
|
||||
GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(std::vector<osHandle> handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override;
|
||||
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override;
|
||||
void closeSharedHandle(GraphicsAllocation *gfxAllocation) override;
|
||||
GraphicsAllocation *createPaddedAllocation(GraphicsAllocation *inputGraphicsAllocation, size_t sizeWithPadding) override;
|
||||
@@ -88,7 +89,7 @@ class DrmMemoryManager : public MemoryManager {
|
||||
}
|
||||
|
||||
protected:
|
||||
BufferObject *findAndReferenceSharedBufferObject(int boHandle, uint32_t rootDeviceIndex);
|
||||
MOCKABLE_VIRTUAL BufferObject *findAndReferenceSharedBufferObject(int boHandle, 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);
|
||||
|
||||
Reference in New Issue
Block a user