Fail when handle cannot be obtain for an allocation

If a handle cannot be obtained, like PRIME_HANDLE_TO_FD, then
properly check for the error and propagate it upwards.

Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
This commit is contained in:
Jaime Arteaga
2022-11-10 02:57:51 +00:00
committed by Compute-Runtime-Automation
parent acb8186744
commit 4391ad21bb
23 changed files with 1007 additions and 115 deletions

View File

@@ -16,7 +16,6 @@
#include "level_zero/core/source/device/device_imp.h"
#include "level_zero/core/source/driver/driver_handle_imp.h"
#include "level_zero/core/source/event/event.h"
#include "level_zero/core/source/helpers/allocation_extensions.h"
#include "level_zero/core/source/helpers/properties_parser.h"
#include "level_zero/core/source/hw_helpers/l0_hw_helper.h"
#include "level_zero/core/source/image/image.h"
@@ -438,7 +437,11 @@ ze_result_t ContextImp::getIpcMemHandle(const void *ptr,
ze_ipc_mem_handle_t *pIpcHandle) {
NEO::SvmAllocationData *allocData = this->driverHandle->svmAllocsManager->getSVMAlloc(ptr);
if (allocData) {
uint64_t handle = allocData->gpuAllocations.getDefaultGraphicsAllocation()->peekInternalHandle(this->driverHandle->getMemoryManager());
uint64_t handle = 0;
int ret = allocData->gpuAllocations.getDefaultGraphicsAllocation()->peekInternalHandle(this->driverHandle->getMemoryManager(), handle);
if (ret < 0) {
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}
memcpy_s(reinterpret_cast<void *>(pIpcHandle->data),
sizeof(ze_ipc_mem_handle_t),
&handle,
@@ -467,11 +470,15 @@ ze_result_t ContextImp::getIpcMemHandles(const void *ptr,
}
for (uint32_t i = 0; i < *numIpcHandles; i++) {
int handle = static_cast<int>(allocData->gpuAllocations.getDefaultGraphicsAllocation()->peekInternalHandle(this->driverHandle->getMemoryManager(), i));
uint64_t handle = 0;
int ret = allocData->gpuAllocations.getDefaultGraphicsAllocation()->peekInternalHandle(this->driverHandle->getMemoryManager(), i, handle);
if (ret < 0) {
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}
memcpy_s(reinterpret_cast<void *>(pIpcHandles[i].data),
sizeof(ze_ipc_mem_handle_t),
&handle,
sizeof(handle));
sizeof(int));
}
return ZE_RESULT_SUCCESS;
@@ -540,7 +547,11 @@ ze_result_t EventPoolImp::getIpcHandle(ze_ipc_event_pool_handle_t *pIpcHandle) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
uint64_t handle = this->eventPoolAllocations->getDefaultGraphicsAllocation()->peekInternalHandle(this->context->getDriverHandle()->getMemoryManager());
uint64_t handle = 0;
int ret = this->eventPoolAllocations->getDefaultGraphicsAllocation()->peekInternalHandle(this->context->getDriverHandle()->getMemoryManager(), handle);
if (ret < 0) {
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}
memcpy_s(pIpcHandle->data, sizeof(int), &handle, sizeof(int));
@@ -630,6 +641,44 @@ ze_result_t ContextImp::openEventPoolIpcHandle(const ze_ipc_event_pool_handle_t
return ZE_RESULT_SUCCESS;
}
ze_result_t ContextImp::handleAllocationExtensions(NEO::GraphicsAllocation *alloc, ze_memory_type_t type, void *pNext, struct DriverHandleImp *driverHandle) {
if (pNext != nullptr) {
ze_base_properties_t *extendedProperties =
reinterpret_cast<ze_base_properties_t *>(pNext);
if (extendedProperties->stype == ZE_STRUCTURE_TYPE_EXTERNAL_MEMORY_EXPORT_FD) {
ze_external_memory_export_fd_t *extendedMemoryExportProperties =
reinterpret_cast<ze_external_memory_export_fd_t *>(extendedProperties);
if (extendedMemoryExportProperties->flags & ZE_EXTERNAL_MEMORY_TYPE_FLAG_OPAQUE_FD) {
return ZE_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
}
if (type != ZE_MEMORY_TYPE_DEVICE) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
uint64_t handle = 0;
int ret = alloc->peekInternalHandle(driverHandle->getMemoryManager(), handle);
if (ret < 0) {
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}
extendedMemoryExportProperties->fd = static_cast<int>(handle);
} else if (extendedProperties->stype == ZE_STRUCTURE_TYPE_EXTERNAL_MEMORY_EXPORT_WIN32) {
ze_external_memory_export_win32_handle_t *exportStructure = reinterpret_cast<ze_external_memory_export_win32_handle_t *>(extendedProperties);
if (exportStructure->flags != ZE_EXTERNAL_MEMORY_TYPE_FLAG_OPAQUE_WIN32) {
return ZE_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
}
uint64_t handle = 0;
int ret = alloc->peekInternalHandle(driverHandle->getMemoryManager(), handle);
if (ret < 0) {
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}
exportStructure->handle = reinterpret_cast<void *>(handle);
} else {
return ZE_RESULT_ERROR_INVALID_ENUMERATION;
}
}
return ZE_RESULT_SUCCESS;
}
ze_result_t ContextImp::getMemAllocProperties(const void *ptr,
ze_memory_allocation_properties_t *pMemAllocProperties,
ze_device_handle_t *phDevice) {

View File

@@ -8,6 +8,7 @@
#pragma once
#include "shared/source/helpers/common_types.h"
#include "shared/source/memory_manager/memory_manager.h"
#include "shared/source/utilities/stackvec.h"
#include "level_zero/core/source/context/context.h"
@@ -142,6 +143,9 @@ struct ContextImp : Context {
void freePeerAllocations(const void *ptr, bool blocking, Device *device);
ze_result_t handleAllocationExtensions(NEO::GraphicsAllocation *alloc, ze_memory_type_t type,
void *pNext, struct DriverHandleImp *driverHandle);
RootDeviceIndicesContainer rootDeviceIndices;
std::map<uint32_t, NEO::DeviceBitfield> deviceBitfields;