Add Windows image memory export functionality

Adds zeImageGetAllocPropertiesExt function, implementation code shared
shared with zeMemGetAllocProperties moved into common helper function.

Related-To: LOCI-2665

Signed-off-by: Jim Snow <jim.m.snow@intel.com>
This commit is contained in:
Jim Snow
2022-01-25 07:23:34 +00:00
committed by Compute-Runtime-Automation
parent e8a6842b7e
commit 0a926c7d12
10 changed files with 326 additions and 35 deletions

View File

@@ -50,6 +50,8 @@ set(L0_RUNTIME_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/event/event.h
${CMAKE_CURRENT_SOURCE_DIR}/fence/fence.cpp
${CMAKE_CURRENT_SOURCE_DIR}/fence/fence.h
${CMAKE_CURRENT_SOURCE_DIR}/helpers/allocation_extensions.h
${CMAKE_CURRENT_SOURCE_DIR}/helpers/allocation_extensions.cpp
${CMAKE_CURRENT_SOURCE_DIR}/helpers/api_specific_config_l0.cpp
${CMAKE_CURRENT_SOURCE_DIR}/helpers/implicit_scaling_l0.cpp
${CMAKE_CURRENT_SOURCE_DIR}/helpers/l0_populate_factory.h

View File

@@ -17,6 +17,7 @@ struct _ze_context_handle_t {
namespace L0 {
struct DriverHandle;
struct Image;
struct Context : _ze_context_handle_t {
inline static ze_memory_type_t parseUSMType(InternalMemoryType memoryType) {
@@ -77,6 +78,8 @@ struct Context : _ze_context_handle_t {
virtual ze_result_t getMemAllocProperties(const void *ptr,
ze_memory_allocation_properties_t *pMemAllocProperties,
ze_device_handle_t *phDevice) = 0;
virtual ze_result_t getImageAllocProperties(Image *image,
ze_image_allocation_ext_properties_t *pAllocProperties) = 0;
virtual ze_result_t createModule(ze_device_handle_t hDevice,
const ze_module_desc_t *desc,
ze_module_handle_t *phModule,

View File

@@ -13,6 +13,7 @@
#include "level_zero/core/source/device/device_imp.h"
#include "level_zero/core/source/driver/driver_handle_imp.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"
@@ -573,31 +574,22 @@ ze_result_t ContextImp::getMemAllocProperties(const void *ptr,
}
}
if (pMemAllocProperties->pNext) {
ze_base_properties_t *extendedProperties =
reinterpret_cast<ze_base_properties_t *>(pMemAllocProperties->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 (pMemAllocProperties->type != ZE_MEMORY_TYPE_DEVICE) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
uint64_t handle = alloc->gpuAllocations.getDefaultGraphicsAllocation()->peekInternalHandle(this->driverHandle->getMemoryManager());
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 = alloc->gpuAllocations.getDefaultGraphicsAllocation()->peekInternalHandle(this->driverHandle->getMemoryManager());
exportStructure->handle = reinterpret_cast<void *>(reinterpret_cast<uintptr_t *>(handle));
}
return handleAllocationExtensions(alloc->gpuAllocations.getDefaultGraphicsAllocation(),
pMemAllocProperties->type,
pMemAllocProperties->pNext,
driverHandle);
}
ze_result_t ContextImp::getImageAllocProperties(Image *image, ze_image_allocation_ext_properties_t *pAllocProperties) {
NEO::GraphicsAllocation *alloc = image->getAllocation();
if (alloc == nullptr) {
return ZE_RESULT_ERROR_UNKNOWN;
}
return ZE_RESULT_SUCCESS;
pAllocProperties->id = 0;
return handleAllocationExtensions(alloc, ZE_MEMORY_TYPE_DEVICE, pAllocProperties->pNext, driverHandle);
}
ze_result_t ContextImp::createModule(ze_device_handle_t hDevice,

View File

@@ -60,6 +60,8 @@ struct ContextImp : Context {
ze_result_t getMemAllocProperties(const void *ptr,
ze_memory_allocation_properties_t *pMemAllocProperties,
ze_device_handle_t *phDevice) override;
ze_result_t getImageAllocProperties(Image *image,
ze_image_allocation_ext_properties_t *pAllocProperties) override;
ze_result_t createModule(ze_device_handle_t hDevice,
const ze_module_desc_t *desc,
ze_module_handle_t *phModule,

View File

@@ -0,0 +1,47 @@
/*
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "level_zero/core/source/helpers/allocation_extensions.h"
#include "shared/source/helpers/memory_properties_helpers.h"
#include "shared/source/memory_manager/memory_manager.h"
#include "shared/source/memory_manager/unified_memory_manager.h"
#include "level_zero/core/source/driver/driver_handle_imp.h"
namespace L0 {
ze_result_t 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 = alloc->peekInternalHandle(driverHandle->getMemoryManager());
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 = alloc->peekInternalHandle(driverHandle->getMemoryManager());
exportStructure->handle = reinterpret_cast<void *>(handle);
} else {
return ZE_RESULT_ERROR_INVALID_ENUMERATION;
}
}
return ZE_RESULT_SUCCESS;
}
} // namespace L0

View File

@@ -0,0 +1,16 @@
/*
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/memory_manager/memory_manager.h"
#include "level_zero/core/source/driver/driver_handle_imp.h"
namespace L0 {
ze_result_t handleAllocationExtensions(NEO::GraphicsAllocation *alloc, ze_memory_type_t type,
void *pNext, struct DriverHandleImp *driverHandle);
} // namespace L0