mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-04 23:56:39 +08:00
Refactor gem creation with extensions
Related-To: NEO-6149 Signed-off-by: Szymon Morek <szymon.morek@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
d4a4c35759
commit
5c1c96fa94
@@ -1290,4 +1290,31 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryInDevicePool(const A
|
||||
return allocation.release();
|
||||
}
|
||||
|
||||
BufferObject *DrmMemoryManager::createBufferObjectInMemoryRegion(Drm *drm,
|
||||
uint64_t gpuAddress,
|
||||
size_t size,
|
||||
uint32_t memoryBanks,
|
||||
size_t maxOsContextCount) {
|
||||
auto memoryInfo = drm->getMemoryInfo();
|
||||
if (!memoryInfo) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint32_t handle = 0;
|
||||
auto ret = memoryInfo->createGemExtWithSingleRegion(drm, memoryBanks, size, handle);
|
||||
|
||||
if (ret != 0) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto bo = new (std::nothrow) BufferObject(drm, handle, size, maxOsContextCount);
|
||||
if (!bo) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bo->setAddress(gpuAddress);
|
||||
|
||||
return bo;
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
@@ -13,10 +13,6 @@ bool DrmMemoryManager::createDrmAllocation(Drm *drm, DrmAllocation *allocation,
|
||||
return false;
|
||||
}
|
||||
|
||||
BufferObject *DrmMemoryManager::createBufferObjectInMemoryRegion(Drm *drm, uint64_t gpuAddress, size_t size, uint32_t memoryBanks, size_t maxOsContextCount) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
DrmAllocation *DrmMemoryManager::createUSMHostAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool hasMappedPtr) {
|
||||
drm_prime_handle openFd = {0, 0, 0};
|
||||
openFd.fd = handle;
|
||||
|
||||
@@ -17,50 +17,6 @@
|
||||
#include "shared/source/os_interface/linux/memory_info_impl.h"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
BufferObject *DrmMemoryManager::createBufferObjectInMemoryRegion(Drm *drm,
|
||||
uint64_t gpuAddress,
|
||||
size_t size,
|
||||
uint32_t memoryBanks,
|
||||
size_t maxOsContextCount) {
|
||||
auto memoryInfo = static_cast<MemoryInfoImpl *>(drm->getMemoryInfo());
|
||||
if (!memoryInfo) {
|
||||
return nullptr;
|
||||
}
|
||||
auto pHwInfo = drm->getRootDeviceEnvironment().getHardwareInfo();
|
||||
auto regionClassAndInstance = memoryInfo->getMemoryRegionClassAndInstance(memoryBanks, *pHwInfo);
|
||||
|
||||
drm_i915_gem_memory_class_instance memRegions{};
|
||||
memRegions.memory_class = regionClassAndInstance.memory_class;
|
||||
memRegions.memory_instance = regionClassAndInstance.memory_instance;
|
||||
|
||||
drm_i915_gem_object_param regionParam{};
|
||||
regionParam.size = 1;
|
||||
regionParam.data = reinterpret_cast<uintptr_t>(&memRegions);
|
||||
regionParam.param = I915_OBJECT_PARAM | I915_PARAM_MEMORY_REGIONS;
|
||||
|
||||
drm_i915_gem_create_ext_setparam setparamRegion{};
|
||||
setparamRegion.base.name = I915_GEM_CREATE_EXT_SETPARAM;
|
||||
setparamRegion.param = regionParam;
|
||||
|
||||
drm_i915_gem_create_ext createExt{};
|
||||
createExt.size = size;
|
||||
createExt.extensions = reinterpret_cast<uintptr_t>(&setparamRegion);
|
||||
auto ret = drm->ioctl(DRM_IOCTL_I915_GEM_CREATE_EXT, &createExt);
|
||||
if (ret != 0) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto bo = new (std::nothrow) BufferObject(drm, createExt.handle, size, maxOsContextCount);
|
||||
if (!bo) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bo->setAddress(gpuAddress);
|
||||
|
||||
return bo;
|
||||
}
|
||||
|
||||
GraphicsAllocation *DrmMemoryManager::createSharedUnifiedMemoryAllocation(const AllocationData &allocationData) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -10,12 +10,15 @@
|
||||
#include <cstdint>
|
||||
|
||||
namespace NEO {
|
||||
class Drm;
|
||||
|
||||
class MemoryInfo {
|
||||
public:
|
||||
MemoryInfo() = default;
|
||||
virtual ~MemoryInfo() = 0;
|
||||
virtual size_t getMemoryRegionSize(uint32_t memoryBank) = 0;
|
||||
virtual uint32_t createGemExt(Drm *drm, void *data, uint32_t dataSize, size_t allocSize, uint32_t &handle) = 0;
|
||||
virtual uint32_t createGemExtWithSingleRegion(Drm *drm, uint32_t memoryBanks, size_t allocSize, uint32_t &handle) = 0;
|
||||
};
|
||||
|
||||
inline MemoryInfo::~MemoryInfo(){};
|
||||
|
||||
@@ -27,6 +27,39 @@ MemoryInfoImpl::MemoryInfoImpl(const drm_i915_memory_region_info *regionInfo, si
|
||||
});
|
||||
}
|
||||
|
||||
uint32_t MemoryInfoImpl::createGemExt(Drm *drm, void *data, uint32_t dataSize, size_t allocSize, uint32_t &handle) {
|
||||
drm_i915_gem_object_param regionParam{};
|
||||
regionParam.size = dataSize;
|
||||
regionParam.data = reinterpret_cast<uintptr_t>(data);
|
||||
regionParam.param = I915_OBJECT_PARAM | I915_PARAM_MEMORY_REGIONS;
|
||||
|
||||
drm_i915_gem_create_ext_setparam setparamRegion{};
|
||||
setparamRegion.base.name = I915_GEM_CREATE_EXT_SETPARAM;
|
||||
setparamRegion.param = regionParam;
|
||||
|
||||
drm_i915_gem_create_ext createExt{};
|
||||
createExt.size = allocSize;
|
||||
createExt.extensions = reinterpret_cast<uintptr_t>(&setparamRegion);
|
||||
|
||||
printDebugString(DebugManager.flags.PrintBOCreateDestroyResult.get(), stdout, "Performing GEM_CREATE_EXT with { size: %lu, param: 0x%llX",
|
||||
allocSize, regionParam.param);
|
||||
|
||||
if (DebugManager.flags.PrintBOCreateDestroyResult.get()) {
|
||||
for (uint32_t i = 0; i < dataSize; i++) {
|
||||
auto region = reinterpret_cast<drm_i915_gem_memory_class_instance *>(data)[i];
|
||||
printDebugString(DebugManager.flags.PrintBOCreateDestroyResult.get(), stdout, ", memory class: %d, memory instance: %d",
|
||||
region.memory_class, region.memory_instance);
|
||||
}
|
||||
printDebugString(DebugManager.flags.PrintBOCreateDestroyResult.get(), stdout, "%s", " }\n");
|
||||
}
|
||||
|
||||
auto ret = drm->ioctl(DRM_IOCTL_I915_GEM_CREATE_EXT, &createExt);
|
||||
|
||||
printDebugString(DebugManager.flags.PrintBOCreateDestroyResult.get(), stdout, "GEM_CREATE_EXT has returned: %d BO-%u with size: %lu\n", ret, createExt.handle, createExt.size);
|
||||
handle = createExt.handle;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void MemoryInfoImpl::assignRegionsFromDistances(const void *distanceInfosPtr, size_t size) {
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/execution_environment/root_device_environment.h"
|
||||
#include "shared/source/helpers/basic_math.h"
|
||||
#include "shared/source/helpers/debug_helpers.h"
|
||||
#include "shared/source/helpers/hw_helper.h"
|
||||
@@ -29,6 +30,8 @@ class MemoryInfoImpl : public MemoryInfo {
|
||||
|
||||
void assignRegionsFromDistances(const void *distanceInfosPtr, size_t size);
|
||||
|
||||
uint32_t createGemExt(Drm *drm, void *data, uint32_t dataSize, size_t allocSize, uint32_t &handle) override;
|
||||
|
||||
drm_i915_gem_memory_class_instance getMemoryRegionClassAndInstance(uint32_t memoryBank, const HardwareInfo &hwInfo) {
|
||||
auto &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily);
|
||||
if (!hwHelper.getEnableLocalMemory(hwInfo) || memoryBank == 0) {
|
||||
@@ -73,6 +76,13 @@ class MemoryInfoImpl : public MemoryInfo {
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t createGemExtWithSingleRegion(Drm *drm, uint32_t memoryBanks, size_t allocSize, uint32_t &handle) override {
|
||||
auto pHwInfo = drm->getRootDeviceEnvironment().getHardwareInfo();
|
||||
auto regionClassAndInstance = getMemoryRegionClassAndInstance(memoryBanks, *pHwInfo);
|
||||
auto ret = createGemExt(drm, ®ionClassAndInstance, 1, allocSize, handle);
|
||||
return ret;
|
||||
}
|
||||
|
||||
const RegionContainer &getDrmRegionInfos() const { return drmQueryRegions; }
|
||||
|
||||
protected:
|
||||
|
||||
Reference in New Issue
Block a user