mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-04 15:53:45 +08:00
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:
committed by
Compute-Runtime-Automation
parent
acb8186744
commit
4391ad21bb
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -567,13 +567,21 @@ NEO::GraphicsAllocation *DriverHandleImp::getPeerAllocation(Device *device,
|
||||
UNRECOVERABLE_IF(numHandles == 0);
|
||||
std::vector<NEO::osHandle> handles;
|
||||
for (uint32_t i = 0; i < numHandles; i++) {
|
||||
int handle = static_cast<int>(alloc->peekInternalHandle(this->getMemoryManager(), i));
|
||||
handles.push_back(handle);
|
||||
uint64_t handle = 0;
|
||||
int ret = alloc->peekInternalHandle(this->getMemoryManager(), i, handle);
|
||||
if (ret < 0) {
|
||||
return nullptr;
|
||||
}
|
||||
handles.push_back(static_cast<NEO::osHandle>(handle));
|
||||
}
|
||||
auto neoDevice = device->getNEODevice()->getRootDevice();
|
||||
peerPtr = this->importFdHandles(neoDevice, flags, handles, &alloc);
|
||||
} else {
|
||||
uint64_t handle = alloc->peekInternalHandle(this->getMemoryManager());
|
||||
uint64_t handle = 0;
|
||||
int ret = alloc->peekInternalHandle(this->getMemoryManager(), handle);
|
||||
if (ret < 0) {
|
||||
return nullptr;
|
||||
}
|
||||
peerPtr = this->importFdHandle(device->getNEODevice(), flags, handle, &alloc);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
target_sources(${L0_STATIC_LIB_NAME}
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/allocation_extensions.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/allocation_extensions.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/api_specific_config_l0.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/error_code_helper_l0.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/error_code_helper_l0.h
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
@@ -1,18 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#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
|
||||
@@ -9,3 +9,4 @@ target_sources(${TARGET_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_memory.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_memory_${DRIVER_MODEL}.cpp
|
||||
)
|
||||
add_subdirectories()
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#
|
||||
# Copyright (C) 2022 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
if(UNIX)
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_memory_linux.cpp
|
||||
)
|
||||
endif()
|
||||
@@ -0,0 +1,706 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/os_interface/linux/drm_allocation.h"
|
||||
#include "shared/source/os_interface/linux/drm_buffer_object.h"
|
||||
#include "shared/source/os_interface/linux/drm_gem_close_worker.h"
|
||||
#include "shared/source/os_interface/linux/drm_memory_manager.h"
|
||||
#include "shared/test/common/libult/linux/drm_mock.h"
|
||||
#include "shared/test/common/mocks/linux/mock_drm_allocation.h"
|
||||
#include "shared/test/common/mocks/mock_driver_model.h"
|
||||
|
||||
#include "level_zero/core/source/context/context_imp.h"
|
||||
#include "level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
class IpcImplicitScalingObtainFdMockGraphicsAllocation : public NEO::DrmAllocation {
|
||||
public:
|
||||
using NEO::DrmAllocation::bufferObjects;
|
||||
|
||||
IpcImplicitScalingObtainFdMockGraphicsAllocation(uint32_t rootDeviceIndex,
|
||||
AllocationType allocationType,
|
||||
BufferObject *bo,
|
||||
void *ptrIn,
|
||||
size_t sizeIn,
|
||||
NEO::osHandle sharedHandle,
|
||||
MemoryPool pool,
|
||||
uint64_t canonizedGpuAddress) : NEO::DrmAllocation(rootDeviceIndex,
|
||||
allocationType,
|
||||
bo,
|
||||
ptrIn,
|
||||
sizeIn,
|
||||
sharedHandle,
|
||||
pool,
|
||||
canonizedGpuAddress) {
|
||||
bufferObjects.resize(2u);
|
||||
}
|
||||
|
||||
uint32_t getNumHandles() override {
|
||||
return 2u;
|
||||
}
|
||||
|
||||
bool isResident(uint32_t contextId) const override {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
class MemoryManagerIpcImplicitScalingObtainFdMock : public NEO::DrmMemoryManager {
|
||||
public:
|
||||
MemoryManagerIpcImplicitScalingObtainFdMock(NEO::ExecutionEnvironment &executionEnvironment) : NEO::DrmMemoryManager(gemCloseWorkerMode::gemCloseWorkerInactive, false, false, executionEnvironment) {}
|
||||
|
||||
NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { return nullptr; }
|
||||
void addAllocationToHostPtrManager(NEO::GraphicsAllocation *memory) override{};
|
||||
void removeAllocationFromHostPtrManager(NEO::GraphicsAllocation *memory) override{};
|
||||
NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; };
|
||||
AllocationStatus populateOsHandles(NEO::OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override { return AllocationStatus::Success; };
|
||||
void cleanOsHandles(NEO::OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override{};
|
||||
void freeGraphicsMemoryImpl(NEO::GraphicsAllocation *gfxAllocation) override{};
|
||||
void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation, bool isImportedAllocation) override{};
|
||||
uint64_t getSystemSharedMemory(uint32_t rootDeviceIndex) override { return 0; };
|
||||
uint64_t getLocalMemorySize(uint32_t rootDeviceIndex, uint32_t deviceBitfield) override { return 0; };
|
||||
double getPercentOfGlobalMemoryAvailable(uint32_t rootDeviceIndex) override { return 0; }
|
||||
AddressRange reserveGpuAddress(size_t size, uint32_t rootDeviceIndex) override {
|
||||
return {};
|
||||
}
|
||||
void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override{};
|
||||
NEO::GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const NEO::AllocationData &allocationData) override { return nullptr; };
|
||||
NEO::GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const NEO::AllocationData &allocationData) override { return nullptr; };
|
||||
NEO::GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const NEO::AllocationData &allocationData) override { return nullptr; };
|
||||
NEO::GraphicsAllocation *allocateUSMHostGraphicsMemory(const NEO::AllocationData &allocationData) override { return nullptr; };
|
||||
NEO::GraphicsAllocation *allocateGraphicsMemory64kb(const NEO::AllocationData &allocationData) override { return nullptr; };
|
||||
NEO::GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const NEO::AllocationData &allocationData, bool useLocalMemory) override { return nullptr; };
|
||||
NEO::GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const NEO::AllocationData &allocationData, AllocationStatus &status) override { return nullptr; };
|
||||
NEO::GraphicsAllocation *allocateGraphicsMemoryWithGpuVa(const NEO::AllocationData &allocationData) override { return nullptr; };
|
||||
|
||||
NEO::GraphicsAllocation *allocateGraphicsMemoryForImageImpl(const NEO::AllocationData &allocationData, std::unique_ptr<Gmm> gmm) override { return nullptr; };
|
||||
NEO::GraphicsAllocation *allocateMemoryByKMD(const NEO::AllocationData &allocationData) override { return nullptr; };
|
||||
void *lockResourceImpl(NEO::GraphicsAllocation &graphicsAllocation) override { return nullptr; };
|
||||
void unlockResourceImpl(NEO::GraphicsAllocation &graphicsAllocation) override{};
|
||||
|
||||
NEO::GraphicsAllocation *allocateGraphicsMemoryInPreferredPool(const AllocationProperties &properties, const void *hostPtr) override {
|
||||
auto ptr = reinterpret_cast<void *>(sharedHandleAddress++);
|
||||
auto gmmHelper = getGmmHelper(0);
|
||||
auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr));
|
||||
size_t size = 0x1000;
|
||||
auto alloc = new IpcImplicitScalingObtainFdMockGraphicsAllocation(0u,
|
||||
NEO::AllocationType::BUFFER,
|
||||
nullptr,
|
||||
ptr,
|
||||
size,
|
||||
0u,
|
||||
MemoryPool::System4KBPages,
|
||||
canonizedGpuAddress);
|
||||
auto &drm = this->getDrm(0u);
|
||||
MockBufferObject bo0(&drm);
|
||||
MockBufferObject bo1(&drm);
|
||||
alloc->bufferObjects[0] = &bo0;
|
||||
alloc->bufferObjects[1] = &bo1;
|
||||
alloc->setGpuBaseAddress(0xabcd);
|
||||
return alloc;
|
||||
}
|
||||
|
||||
NEO::GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) override {
|
||||
auto ptr = reinterpret_cast<void *>(sharedHandleAddress++);
|
||||
auto gmmHelper = getGmmHelper(0);
|
||||
auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr));
|
||||
size_t size = 0x1000;
|
||||
auto alloc = new IpcImplicitScalingObtainFdMockGraphicsAllocation(0u,
|
||||
NEO::AllocationType::BUFFER,
|
||||
nullptr,
|
||||
ptr,
|
||||
size,
|
||||
0u,
|
||||
MemoryPool::System4KBPages,
|
||||
canonizedGpuAddress);
|
||||
auto &drm = this->getDrm(0u);
|
||||
MockBufferObject bo0(&drm);
|
||||
MockBufferObject bo1(&drm);
|
||||
alloc->bufferObjects[0] = &bo0;
|
||||
alloc->bufferObjects[1] = &bo1;
|
||||
alloc->setGpuBaseAddress(0xabcd);
|
||||
return alloc;
|
||||
}
|
||||
|
||||
NEO::GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector<osHandle> &handles,
|
||||
AllocationProperties &properties,
|
||||
bool requireSpecificBitness,
|
||||
bool isHostIpcAllocation) override {
|
||||
if (failOnCreateGraphicsAllocationFromSharedHandle) {
|
||||
return nullptr;
|
||||
}
|
||||
auto ptr = reinterpret_cast<void *>(sharedHandleAddress++);
|
||||
auto gmmHelper = getGmmHelper(0);
|
||||
auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr));
|
||||
size_t size = 0x1000;
|
||||
auto alloc = new IpcImplicitScalingObtainFdMockGraphicsAllocation(0u,
|
||||
NEO::AllocationType::BUFFER,
|
||||
nullptr,
|
||||
ptr,
|
||||
size,
|
||||
0u,
|
||||
MemoryPool::System4KBPages,
|
||||
canonizedGpuAddress);
|
||||
auto &drm = this->getDrm(0u);
|
||||
MockBufferObject bo0(&drm);
|
||||
MockBufferObject bo1(&drm);
|
||||
alloc->bufferObjects[0] = &bo0;
|
||||
alloc->bufferObjects[1] = &bo1;
|
||||
alloc->setGpuBaseAddress(0xabcd);
|
||||
return alloc;
|
||||
}
|
||||
|
||||
void freeGraphicsMemory(NEO::GraphicsAllocation *alloc, bool isImportedAllocation) override {
|
||||
delete alloc;
|
||||
}
|
||||
|
||||
int obtainFdFromHandle(int boHandle, uint32_t rootDeviceIndex) override {
|
||||
if (failOnObtainFdFromHandle) {
|
||||
return -1;
|
||||
}
|
||||
return NEO::DrmMemoryManager::obtainFdFromHandle(boHandle, rootDeviceIndex);
|
||||
}
|
||||
bool failOnObtainFdFromHandle = false;
|
||||
|
||||
uint64_t sharedHandleAddress = 0x1234;
|
||||
|
||||
bool failOnCreateGraphicsAllocationFromSharedHandle = false;
|
||||
};
|
||||
|
||||
struct MemoryExportImportObtainFdTest : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
DebugManagerStateRestore restorer;
|
||||
DebugManager.flags.EnableImplicitScaling.set(1);
|
||||
|
||||
executionEnvironment = new NEO::ExecutionEnvironment();
|
||||
executionEnvironment->prepareRootDeviceEnvironments(numRootDevices);
|
||||
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
|
||||
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
|
||||
executionEnvironment->rootDeviceEnvironments[i]->setHwInfo(&hwInfo);
|
||||
}
|
||||
deviceFactory = std::make_unique<UltDeviceFactory>(numRootDevices, numSubDevices, *executionEnvironment);
|
||||
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
|
||||
devices.push_back(std::unique_ptr<NEO::Device>(deviceFactory->rootDevices[i]));
|
||||
executionEnvironment->rootDeviceEnvironments[i]->osInterface.reset(new NEO::OSInterface());
|
||||
auto drmMock = new DrmMockResources(*executionEnvironment->rootDeviceEnvironments[i]);
|
||||
executionEnvironment->rootDeviceEnvironments[i]->osInterface->setDriverModel(std::unique_ptr<Drm>(drmMock));
|
||||
}
|
||||
|
||||
driverHandle = std::make_unique<DriverHandleImp>();
|
||||
driverHandle->initialize(std::move(devices));
|
||||
|
||||
prevMemoryManager = driverHandle->getMemoryManager();
|
||||
currMemoryManager = new MemoryManagerIpcImplicitScalingObtainFdMock(*executionEnvironment);
|
||||
driverHandle->setMemoryManager(currMemoryManager);
|
||||
|
||||
prevSvmAllocsManager = driverHandle->svmAllocsManager;
|
||||
currSvmAllocsManager = new NEO::SVMAllocsManager(currMemoryManager, false);
|
||||
driverHandle->svmAllocsManager = currSvmAllocsManager;
|
||||
|
||||
context = std::make_unique<L0::ContextImp>(driverHandle.get());
|
||||
EXPECT_NE(context, nullptr);
|
||||
for (auto i = 0u; i < numRootDevices; i++) {
|
||||
auto dev = driverHandle->devices[i];
|
||||
context->getDevices().insert(std::make_pair(dev->getRootDeviceIndex(), dev->toHandle()));
|
||||
}
|
||||
device = driverHandle->devices[0];
|
||||
auto neoDevice = device->getNEODevice();
|
||||
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
|
||||
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
driverHandle->svmAllocsManager = prevSvmAllocsManager;
|
||||
delete currSvmAllocsManager;
|
||||
driverHandle->setMemoryManager(prevMemoryManager);
|
||||
delete currMemoryManager;
|
||||
}
|
||||
|
||||
static constexpr uint32_t numRootDevices = 2u;
|
||||
static constexpr uint32_t numSubDevices = 2u;
|
||||
|
||||
std::vector<std::unique_ptr<NEO::Device>> devices;
|
||||
std::unique_ptr<UltDeviceFactory> deviceFactory;
|
||||
|
||||
SVMAllocsManager *prevSvmAllocsManager;
|
||||
NEO::SVMAllocsManager *currSvmAllocsManager;
|
||||
|
||||
NEO::ExecutionEnvironment *executionEnvironment = nullptr;
|
||||
NEO::MemoryManager *prevMemoryManager = nullptr;
|
||||
MemoryManagerIpcImplicitScalingObtainFdMock *currMemoryManager = nullptr;
|
||||
std::unique_ptr<L0::DriverHandleImp> driverHandle;
|
||||
NEO::MockDevice *neoDevice = nullptr;
|
||||
L0::Device *device = nullptr;
|
||||
std::unique_ptr<L0::ContextImp> context;
|
||||
};
|
||||
|
||||
TEST_F(MemoryExportImportObtainFdTest,
|
||||
givenCallToGetIpcHandlesWithFailureToGetFdHandleThenOutOfHostMemoryIsReturned) {
|
||||
size_t size = 10;
|
||||
size_t alignment = 1u;
|
||||
void *ptr = nullptr;
|
||||
|
||||
ze_device_mem_alloc_desc_t deviceDesc = {};
|
||||
ze_result_t result = context->allocDeviceMem(device->toHandle(),
|
||||
&deviceDesc,
|
||||
size, alignment, &ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_NE(nullptr, ptr);
|
||||
|
||||
uint32_t numIpcHandles = 0;
|
||||
result = context->getIpcMemHandles(ptr, &numIpcHandles, nullptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_EQ(numIpcHandles, 2u);
|
||||
|
||||
currMemoryManager->failOnObtainFdFromHandle = true;
|
||||
|
||||
std::vector<ze_ipc_mem_handle_t> ipcHandles(numIpcHandles);
|
||||
result = context->getIpcMemHandles(ptr, &numIpcHandles, ipcHandles.data());
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY, result);
|
||||
|
||||
result = context->freeMem(ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
TEST_F(MemoryExportImportObtainFdTest,
|
||||
givenCallToGetIpcHandlesWithFdHandleThenSuccessIsReturned) {
|
||||
size_t size = 10;
|
||||
size_t alignment = 1u;
|
||||
void *ptr = nullptr;
|
||||
|
||||
ze_device_mem_alloc_desc_t deviceDesc = {};
|
||||
ze_result_t result = context->allocDeviceMem(device->toHandle(),
|
||||
&deviceDesc,
|
||||
size, alignment, &ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_NE(nullptr, ptr);
|
||||
|
||||
uint32_t numIpcHandles = 0;
|
||||
result = context->getIpcMemHandles(ptr, &numIpcHandles, nullptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_EQ(numIpcHandles, 2u);
|
||||
|
||||
currMemoryManager->failOnObtainFdFromHandle = false;
|
||||
|
||||
std::vector<ze_ipc_mem_handle_t> ipcHandles(numIpcHandles);
|
||||
result = context->getIpcMemHandles(ptr, &numIpcHandles, ipcHandles.data());
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
result = context->freeMem(ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
TEST_F(MemoryExportImportObtainFdTest,
|
||||
givenCallToGetIpcHandleWithFailureToGetFdHandleThenOutOfHostMemoryIsReturned) {
|
||||
size_t size = 10;
|
||||
size_t alignment = 1u;
|
||||
void *ptr = nullptr;
|
||||
|
||||
ze_device_mem_alloc_desc_t deviceDesc = {};
|
||||
ze_result_t result = context->allocDeviceMem(device->toHandle(),
|
||||
&deviceDesc,
|
||||
size, alignment, &ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_NE(nullptr, ptr);
|
||||
|
||||
currMemoryManager->failOnObtainFdFromHandle = true;
|
||||
ze_ipc_mem_handle_t ipcHandle{};
|
||||
result = context->getIpcMemHandle(ptr, &ipcHandle);
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY, result);
|
||||
|
||||
result = context->freeMem(ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
TEST_F(MemoryExportImportObtainFdTest,
|
||||
givenCallToGetIpcHandleWithFdHandleThenSuccessIsReturned) {
|
||||
size_t size = 10;
|
||||
size_t alignment = 1u;
|
||||
void *ptr = nullptr;
|
||||
|
||||
ze_device_mem_alloc_desc_t deviceDesc = {};
|
||||
ze_result_t result = context->allocDeviceMem(device->toHandle(),
|
||||
&deviceDesc,
|
||||
size, alignment, &ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_NE(nullptr, ptr);
|
||||
|
||||
currMemoryManager->failOnObtainFdFromHandle = false;
|
||||
ze_ipc_mem_handle_t ipcHandle{};
|
||||
result = context->getIpcMemHandle(ptr, &ipcHandle);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
result = context->freeMem(ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
TEST_F(MemoryExportImportObtainFdTest,
|
||||
givenCallToEventPoolGetIpcHandleWithFailureToGetFdHandleThenOutOfHostMemoryIsReturned) {
|
||||
|
||||
uint32_t numEvents = 4;
|
||||
ze_event_pool_desc_t eventPoolDesc = {
|
||||
ZE_STRUCTURE_TYPE_EVENT_POOL_DESC,
|
||||
nullptr,
|
||||
ZE_EVENT_POOL_FLAG_HOST_VISIBLE | ZE_EVENT_POOL_FLAG_IPC,
|
||||
numEvents};
|
||||
|
||||
auto deviceHandle = device->toHandle();
|
||||
ze_result_t result = ZE_RESULT_SUCCESS;
|
||||
auto eventPool = static_cast<EventPoolImp *>(EventPool::create(driverHandle.get(),
|
||||
context.get(),
|
||||
1,
|
||||
&deviceHandle,
|
||||
&eventPoolDesc,
|
||||
result));
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_NE(nullptr, eventPool);
|
||||
eventPool->isShareableEventMemory = true;
|
||||
|
||||
currMemoryManager->failOnObtainFdFromHandle = true;
|
||||
ze_ipc_event_pool_handle_t ipcHandle = {};
|
||||
result = eventPool->getIpcHandle(&ipcHandle);
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY, result);
|
||||
|
||||
result = eventPool->destroy();
|
||||
EXPECT_EQ(result, ZE_RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
TEST_F(MemoryExportImportObtainFdTest,
|
||||
givenCallToEventPoolGetIpcHandleWithFdHandleThenSuccessIsReturned) {
|
||||
uint32_t numEvents = 4;
|
||||
ze_event_pool_desc_t eventPoolDesc = {
|
||||
ZE_STRUCTURE_TYPE_EVENT_POOL_DESC,
|
||||
nullptr,
|
||||
ZE_EVENT_POOL_FLAG_HOST_VISIBLE | ZE_EVENT_POOL_FLAG_IPC,
|
||||
numEvents};
|
||||
|
||||
auto deviceHandle = device->toHandle();
|
||||
ze_result_t result = ZE_RESULT_SUCCESS;
|
||||
auto eventPool = static_cast<EventPoolImp *>(EventPool::create(driverHandle.get(),
|
||||
context.get(),
|
||||
1,
|
||||
&deviceHandle,
|
||||
&eventPoolDesc,
|
||||
result));
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_NE(nullptr, eventPool);
|
||||
eventPool->isShareableEventMemory = true;
|
||||
|
||||
currMemoryManager->failOnObtainFdFromHandle = false;
|
||||
ze_ipc_event_pool_handle_t ipcHandle = {};
|
||||
result = eventPool->getIpcHandle(&ipcHandle);
|
||||
EXPECT_EQ(result, ZE_RESULT_SUCCESS);
|
||||
|
||||
result = eventPool->destroy();
|
||||
EXPECT_EQ(result, ZE_RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
TEST_F(MemoryExportImportObtainFdTest,
|
||||
whenPeerAllocationForDeviceAllocationIsRequestedThenPeerAllocationIsReturned) {
|
||||
L0::Device *device0 = driverHandle->devices[0];
|
||||
L0::Device *device1 = driverHandle->devices[1];
|
||||
|
||||
size_t size = 1024;
|
||||
size_t alignment = 1u;
|
||||
void *ptr = nullptr;
|
||||
ze_device_mem_alloc_desc_t deviceDesc = {};
|
||||
ze_result_t result = context->allocDeviceMem(device0->toHandle(),
|
||||
&deviceDesc,
|
||||
size, alignment, &ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_NE(nullptr, ptr);
|
||||
|
||||
uintptr_t peerGpuAddress = 0u;
|
||||
auto allocData = context->getDriverHandle()->getSvmAllocsManager()->getSVMAlloc(ptr);
|
||||
EXPECT_NE(allocData, nullptr);
|
||||
currMemoryManager->failOnObtainFdFromHandle = false;
|
||||
auto peerAlloc = driverHandle->getPeerAllocation(device1, allocData, ptr, &peerGpuAddress);
|
||||
EXPECT_NE(peerAlloc, nullptr);
|
||||
|
||||
result = context->freeMem(ptr);
|
||||
ASSERT_EQ(result, ZE_RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
TEST_F(MemoryExportImportObtainFdTest,
|
||||
whenPeerAllocationForDeviceAllocationIsRequestedThenNullptrIsReturned) {
|
||||
L0::Device *device0 = driverHandle->devices[0];
|
||||
L0::Device *device1 = driverHandle->devices[1];
|
||||
|
||||
size_t size = 1024;
|
||||
size_t alignment = 1u;
|
||||
void *ptr = nullptr;
|
||||
ze_device_mem_alloc_desc_t deviceDesc = {};
|
||||
ze_result_t result = context->allocDeviceMem(device0->toHandle(),
|
||||
&deviceDesc,
|
||||
size, alignment, &ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_NE(nullptr, ptr);
|
||||
|
||||
uintptr_t peerGpuAddress = 0u;
|
||||
auto allocData = context->getDriverHandle()->getSvmAllocsManager()->getSVMAlloc(ptr);
|
||||
EXPECT_NE(allocData, nullptr);
|
||||
currMemoryManager->failOnObtainFdFromHandle = true;
|
||||
auto peerAlloc = driverHandle->getPeerAllocation(device1, allocData, ptr, &peerGpuAddress);
|
||||
EXPECT_EQ(peerAlloc, nullptr);
|
||||
|
||||
result = context->freeMem(ptr);
|
||||
ASSERT_EQ(result, ZE_RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
class IpcObtainFdMockGraphicsAllocation : public NEO::DrmAllocation {
|
||||
public:
|
||||
using NEO::DrmAllocation::bufferObjects;
|
||||
|
||||
IpcObtainFdMockGraphicsAllocation(uint32_t rootDeviceIndex,
|
||||
AllocationType allocationType,
|
||||
BufferObject *bo,
|
||||
void *ptrIn,
|
||||
size_t sizeIn,
|
||||
NEO::osHandle sharedHandle,
|
||||
MemoryPool pool,
|
||||
uint64_t canonizedGpuAddress) : NEO::DrmAllocation(rootDeviceIndex,
|
||||
allocationType,
|
||||
bo,
|
||||
ptrIn,
|
||||
sizeIn,
|
||||
sharedHandle,
|
||||
pool,
|
||||
canonizedGpuAddress) {
|
||||
bufferObjects.resize(1u);
|
||||
}
|
||||
|
||||
uint32_t getNumHandles() override {
|
||||
return 1u;
|
||||
}
|
||||
|
||||
bool isResident(uint32_t contextId) const override {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
class MemoryManagerIpcObtainFdMock : public NEO::DrmMemoryManager {
|
||||
public:
|
||||
MemoryManagerIpcObtainFdMock(NEO::ExecutionEnvironment &executionEnvironment) : NEO::DrmMemoryManager(gemCloseWorkerMode::gemCloseWorkerInactive, false, false, executionEnvironment) {}
|
||||
|
||||
NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { return nullptr; }
|
||||
void addAllocationToHostPtrManager(NEO::GraphicsAllocation *memory) override{};
|
||||
void removeAllocationFromHostPtrManager(NEO::GraphicsAllocation *memory) override{};
|
||||
NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; };
|
||||
AllocationStatus populateOsHandles(NEO::OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override { return AllocationStatus::Success; };
|
||||
void cleanOsHandles(NEO::OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override{};
|
||||
void freeGraphicsMemoryImpl(NEO::GraphicsAllocation *gfxAllocation) override{};
|
||||
void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation, bool isImportedAllocation) override{};
|
||||
uint64_t getSystemSharedMemory(uint32_t rootDeviceIndex) override { return 0; };
|
||||
uint64_t getLocalMemorySize(uint32_t rootDeviceIndex, uint32_t deviceBitfield) override { return 0; };
|
||||
double getPercentOfGlobalMemoryAvailable(uint32_t rootDeviceIndex) override { return 0; }
|
||||
AddressRange reserveGpuAddress(size_t size, uint32_t rootDeviceIndex) override {
|
||||
return {};
|
||||
}
|
||||
void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override{};
|
||||
NEO::GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const NEO::AllocationData &allocationData) override { return nullptr; };
|
||||
NEO::GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const NEO::AllocationData &allocationData) override { return nullptr; };
|
||||
NEO::GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const NEO::AllocationData &allocationData) override { return nullptr; };
|
||||
NEO::GraphicsAllocation *allocateUSMHostGraphicsMemory(const NEO::AllocationData &allocationData) override { return nullptr; };
|
||||
NEO::GraphicsAllocation *allocateGraphicsMemory64kb(const NEO::AllocationData &allocationData) override { return nullptr; };
|
||||
NEO::GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const NEO::AllocationData &allocationData, bool useLocalMemory) override { return nullptr; };
|
||||
NEO::GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const NEO::AllocationData &allocationData, AllocationStatus &status) override { return nullptr; };
|
||||
NEO::GraphicsAllocation *allocateGraphicsMemoryWithGpuVa(const NEO::AllocationData &allocationData) override { return nullptr; };
|
||||
|
||||
NEO::GraphicsAllocation *allocateGraphicsMemoryForImageImpl(const NEO::AllocationData &allocationData, std::unique_ptr<Gmm> gmm) override { return nullptr; };
|
||||
NEO::GraphicsAllocation *allocateMemoryByKMD(const NEO::AllocationData &allocationData) override { return nullptr; };
|
||||
void *lockResourceImpl(NEO::GraphicsAllocation &graphicsAllocation) override { return nullptr; };
|
||||
void unlockResourceImpl(NEO::GraphicsAllocation &graphicsAllocation) override{};
|
||||
|
||||
NEO::GraphicsAllocation *allocateGraphicsMemoryInPreferredPool(const AllocationProperties &properties, const void *hostPtr) override {
|
||||
auto ptr = reinterpret_cast<void *>(sharedHandleAddress++);
|
||||
auto gmmHelper = getGmmHelper(0);
|
||||
auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr));
|
||||
size_t size = 0x1000;
|
||||
auto alloc = new IpcObtainFdMockGraphicsAllocation(0u,
|
||||
NEO::AllocationType::BUFFER,
|
||||
nullptr,
|
||||
ptr,
|
||||
size,
|
||||
0u,
|
||||
MemoryPool::System4KBPages,
|
||||
canonizedGpuAddress);
|
||||
auto &drm = this->getDrm(0u);
|
||||
MockBufferObject bo0(&drm);
|
||||
alloc->bufferObjects[0] = &bo0;
|
||||
alloc->setGpuBaseAddress(0xabcd);
|
||||
return alloc;
|
||||
}
|
||||
|
||||
NEO::GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) override {
|
||||
auto ptr = reinterpret_cast<void *>(sharedHandleAddress++);
|
||||
auto gmmHelper = getGmmHelper(0);
|
||||
auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr));
|
||||
size_t size = 0x1000;
|
||||
auto alloc = new IpcObtainFdMockGraphicsAllocation(0u,
|
||||
NEO::AllocationType::BUFFER,
|
||||
nullptr,
|
||||
ptr,
|
||||
size,
|
||||
0u,
|
||||
MemoryPool::System4KBPages,
|
||||
canonizedGpuAddress);
|
||||
auto &drm = this->getDrm(0u);
|
||||
MockBufferObject bo0(&drm);
|
||||
alloc->bufferObjects[0] = &bo0;
|
||||
alloc->setGpuBaseAddress(0xabcd);
|
||||
return alloc;
|
||||
}
|
||||
|
||||
NEO::GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector<osHandle> &handles,
|
||||
AllocationProperties &properties,
|
||||
bool requireSpecificBitness,
|
||||
bool isHostIpcAllocation) override {
|
||||
if (failOnCreateGraphicsAllocationFromSharedHandle) {
|
||||
return nullptr;
|
||||
}
|
||||
auto ptr = reinterpret_cast<void *>(sharedHandleAddress++);
|
||||
auto gmmHelper = getGmmHelper(0);
|
||||
auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr));
|
||||
size_t size = 0x1000;
|
||||
auto alloc = new IpcObtainFdMockGraphicsAllocation(0u,
|
||||
NEO::AllocationType::BUFFER,
|
||||
nullptr,
|
||||
ptr,
|
||||
size,
|
||||
0u,
|
||||
MemoryPool::System4KBPages,
|
||||
canonizedGpuAddress);
|
||||
auto &drm = this->getDrm(0u);
|
||||
MockBufferObject bo0(&drm);
|
||||
alloc->bufferObjects[0] = &bo0;
|
||||
alloc->setGpuBaseAddress(0xabcd);
|
||||
return alloc;
|
||||
}
|
||||
|
||||
void freeGraphicsMemory(NEO::GraphicsAllocation *alloc, bool isImportedAllocation) override {
|
||||
delete alloc;
|
||||
}
|
||||
|
||||
int obtainFdFromHandle(int boHandle, uint32_t rootDeviceIndex) override {
|
||||
if (failOnObtainFdFromHandle) {
|
||||
return -1;
|
||||
}
|
||||
return NEO::DrmMemoryManager::obtainFdFromHandle(boHandle, rootDeviceIndex);
|
||||
}
|
||||
bool failOnObtainFdFromHandle = false;
|
||||
|
||||
uint64_t sharedHandleAddress = 0x1234;
|
||||
|
||||
bool failOnCreateGraphicsAllocationFromSharedHandle = false;
|
||||
};
|
||||
|
||||
struct DriverHandleObtaindFdMock : public L0::DriverHandleImp {
|
||||
void *importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::GraphicsAllocation **pAloc) override {
|
||||
DeviceBitfield deviceBitfield{0x0};
|
||||
AllocationProperties properties(0, MemoryConstants::pageSize,
|
||||
AllocationType::BUFFER,
|
||||
deviceBitfield);
|
||||
auto alloc = getMemoryManager()->allocateGraphicsMemoryWithProperties(properties);
|
||||
return reinterpret_cast<void *>(alloc->getGpuAddress());
|
||||
}
|
||||
};
|
||||
|
||||
struct MemoryObtainFdTest : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
DebugManagerStateRestore restorer;
|
||||
|
||||
executionEnvironment = new NEO::ExecutionEnvironment();
|
||||
executionEnvironment->prepareRootDeviceEnvironments(numRootDevices);
|
||||
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
|
||||
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
|
||||
executionEnvironment->rootDeviceEnvironments[i]->setHwInfo(&hwInfo);
|
||||
}
|
||||
deviceFactory = std::make_unique<UltDeviceFactory>(numRootDevices, numSubDevices, *executionEnvironment);
|
||||
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
|
||||
devices.push_back(std::unique_ptr<NEO::Device>(deviceFactory->rootDevices[i]));
|
||||
executionEnvironment->rootDeviceEnvironments[i]->osInterface.reset(new NEO::OSInterface());
|
||||
auto drmMock = new DrmMockResources(*executionEnvironment->rootDeviceEnvironments[i]);
|
||||
executionEnvironment->rootDeviceEnvironments[i]->osInterface->setDriverModel(std::unique_ptr<Drm>(drmMock));
|
||||
}
|
||||
|
||||
driverHandle = std::make_unique<DriverHandleObtaindFdMock>();
|
||||
driverHandle->initialize(std::move(devices));
|
||||
|
||||
prevMemoryManager = driverHandle->getMemoryManager();
|
||||
currMemoryManager = new MemoryManagerIpcObtainFdMock(*executionEnvironment);
|
||||
driverHandle->setMemoryManager(currMemoryManager);
|
||||
|
||||
prevSvmAllocsManager = driverHandle->svmAllocsManager;
|
||||
currSvmAllocsManager = new NEO::SVMAllocsManager(currMemoryManager, false);
|
||||
driverHandle->svmAllocsManager = currSvmAllocsManager;
|
||||
|
||||
context = std::make_unique<L0::ContextImp>(driverHandle.get());
|
||||
EXPECT_NE(context, nullptr);
|
||||
for (auto i = 0u; i < numRootDevices; i++) {
|
||||
auto dev = driverHandle->devices[i];
|
||||
context->getDevices().insert(std::make_pair(dev->getRootDeviceIndex(), dev->toHandle()));
|
||||
}
|
||||
device = driverHandle->devices[0];
|
||||
auto neoDevice = device->getNEODevice();
|
||||
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
|
||||
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
driverHandle->svmAllocsManager = prevSvmAllocsManager;
|
||||
delete currSvmAllocsManager;
|
||||
driverHandle->setMemoryManager(prevMemoryManager);
|
||||
delete currMemoryManager;
|
||||
}
|
||||
|
||||
static constexpr uint32_t numRootDevices = 2u;
|
||||
static constexpr uint32_t numSubDevices = 2u;
|
||||
|
||||
std::vector<std::unique_ptr<NEO::Device>> devices;
|
||||
std::unique_ptr<UltDeviceFactory> deviceFactory;
|
||||
|
||||
SVMAllocsManager *prevSvmAllocsManager;
|
||||
NEO::SVMAllocsManager *currSvmAllocsManager;
|
||||
|
||||
NEO::ExecutionEnvironment *executionEnvironment = nullptr;
|
||||
NEO::MemoryManager *prevMemoryManager = nullptr;
|
||||
MemoryManagerIpcObtainFdMock *currMemoryManager = nullptr;
|
||||
std::unique_ptr<DriverHandleObtaindFdMock> driverHandle;
|
||||
NEO::MockDevice *neoDevice = nullptr;
|
||||
L0::Device *device = nullptr;
|
||||
std::unique_ptr<L0::ContextImp> context;
|
||||
};
|
||||
|
||||
TEST_F(MemoryObtainFdTest,
|
||||
whenPeerAllocationForDeviceAllocationIsRequestedThenNullptrIsReturned) {
|
||||
L0::Device *device0 = driverHandle->devices[0];
|
||||
L0::Device *device1 = driverHandle->devices[1];
|
||||
|
||||
size_t size = 1024;
|
||||
size_t alignment = 1u;
|
||||
void *ptr = nullptr;
|
||||
ze_device_mem_alloc_desc_t deviceDesc = {};
|
||||
ze_result_t result = context->allocDeviceMem(device0->toHandle(),
|
||||
&deviceDesc,
|
||||
size, alignment, &ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_NE(nullptr, ptr);
|
||||
|
||||
uintptr_t peerGpuAddress = 0u;
|
||||
auto allocData = context->getDriverHandle()->getSvmAllocsManager()->getSVMAlloc(ptr);
|
||||
EXPECT_NE(allocData, nullptr);
|
||||
currMemoryManager->failOnObtainFdFromHandle = true;
|
||||
auto peerAlloc = driverHandle->getPeerAllocation(device1, allocData, ptr, &peerGpuAddress);
|
||||
EXPECT_EQ(peerAlloc, nullptr);
|
||||
|
||||
result = context->freeMem(ptr);
|
||||
ASSERT_EQ(result, ZE_RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "shared/source/helpers/file_io.h"
|
||||
#include "shared/source/helpers/string.h"
|
||||
#include "shared/source/memory_manager/graphics_allocation.h"
|
||||
#include "shared/source/memory_manager/memory_operations_status.h"
|
||||
#include "shared/source/os_interface/device_factory.h"
|
||||
#include "shared/test/common/helpers/debug_manager_state_restore.h"
|
||||
@@ -1801,6 +1802,53 @@ TEST_F(MemoryExportImportTest,
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
TEST_F(MemoryExportImportTest,
|
||||
givenCallToMemAllocPropertiesWithExtendedExportPropertiesAndNoFdHandleThenErrorIsReturned) {
|
||||
class ExportImportMockGraphicsAllocation : public NEO::MemoryAllocation {
|
||||
public:
|
||||
ExportImportMockGraphicsAllocation() : NEO::MemoryAllocation(0, AllocationType::BUFFER, nullptr, 0u, 0, MemoryPool::MemoryNull, MemoryManager::maxOsContextCount, 0llu) {}
|
||||
|
||||
int peekInternalHandle(NEO::MemoryManager *memoryManager, uint64_t &handle) override {
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
|
||||
ze_memory_allocation_properties_t memoryProperties = {};
|
||||
ze_external_memory_export_fd_t extendedProperties = {};
|
||||
extendedProperties.stype = ZE_STRUCTURE_TYPE_EXTERNAL_MEMORY_EXPORT_FD;
|
||||
extendedProperties.fd = std::numeric_limits<int>::max();
|
||||
memoryProperties.pNext = &extendedProperties;
|
||||
|
||||
ze_memory_type_t type = ZE_MEMORY_TYPE_DEVICE;
|
||||
ExportImportMockGraphicsAllocation alloc;
|
||||
ze_result_t result = context->handleAllocationExtensions(&alloc, type, &extendedProperties, driverHandle.get());
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY, result);
|
||||
}
|
||||
|
||||
TEST_F(MemoryExportImportTest,
|
||||
givenCallToMemAllocPropertiesWithExtendedExportPropertiesAndNoFdHandleForWin32FormatThenErrorIsReturned) {
|
||||
class ExportImportMockGraphicsAllocation : public NEO::MemoryAllocation {
|
||||
public:
|
||||
ExportImportMockGraphicsAllocation() : NEO::MemoryAllocation(0, AllocationType::BUFFER, nullptr, 0u, 0, MemoryPool::MemoryNull, MemoryManager::maxOsContextCount, 0llu) {}
|
||||
|
||||
int peekInternalHandle(NEO::MemoryManager *memoryManager, uint64_t &handle) override {
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
|
||||
ze_memory_allocation_properties_t memoryProperties = {};
|
||||
ze_external_memory_export_fd_t extendedProperties = {};
|
||||
extendedProperties.stype = ZE_STRUCTURE_TYPE_EXTERNAL_MEMORY_EXPORT_WIN32;
|
||||
extendedProperties.flags = ZE_EXTERNAL_MEMORY_TYPE_FLAG_OPAQUE_WIN32;
|
||||
extendedProperties.fd = std::numeric_limits<int>::max();
|
||||
memoryProperties.pNext = &extendedProperties;
|
||||
|
||||
ze_memory_type_t type = ZE_MEMORY_TYPE_DEVICE;
|
||||
ExportImportMockGraphicsAllocation alloc;
|
||||
ze_result_t result = context->handleAllocationExtensions(&alloc, type, &extendedProperties, driverHandle.get());
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY, result);
|
||||
}
|
||||
|
||||
TEST_F(MemoryExportImportTest,
|
||||
givenCallToMemAllocPropertiesWithExtendedExportPropertiesForNonDeviceAllocationThenUnsupportedFeatureIsReturned) {
|
||||
size_t size = 10;
|
||||
|
||||
Reference in New Issue
Block a user