mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-10 12:53:42 +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/device/device_imp.h"
|
||||||
#include "level_zero/core/source/driver/driver_handle_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/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/helpers/properties_parser.h"
|
||||||
#include "level_zero/core/source/hw_helpers/l0_hw_helper.h"
|
#include "level_zero/core/source/hw_helpers/l0_hw_helper.h"
|
||||||
#include "level_zero/core/source/image/image.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) {
|
ze_ipc_mem_handle_t *pIpcHandle) {
|
||||||
NEO::SvmAllocationData *allocData = this->driverHandle->svmAllocsManager->getSVMAlloc(ptr);
|
NEO::SvmAllocationData *allocData = this->driverHandle->svmAllocsManager->getSVMAlloc(ptr);
|
||||||
if (allocData) {
|
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),
|
memcpy_s(reinterpret_cast<void *>(pIpcHandle->data),
|
||||||
sizeof(ze_ipc_mem_handle_t),
|
sizeof(ze_ipc_mem_handle_t),
|
||||||
&handle,
|
&handle,
|
||||||
@ -467,11 +470,15 @@ ze_result_t ContextImp::getIpcMemHandles(const void *ptr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (uint32_t i = 0; i < *numIpcHandles; i++) {
|
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),
|
memcpy_s(reinterpret_cast<void *>(pIpcHandles[i].data),
|
||||||
sizeof(ze_ipc_mem_handle_t),
|
sizeof(ze_ipc_mem_handle_t),
|
||||||
&handle,
|
&handle,
|
||||||
sizeof(handle));
|
sizeof(int));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ZE_RESULT_SUCCESS;
|
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;
|
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));
|
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;
|
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_result_t ContextImp::getMemAllocProperties(const void *ptr,
|
||||||
ze_memory_allocation_properties_t *pMemAllocProperties,
|
ze_memory_allocation_properties_t *pMemAllocProperties,
|
||||||
ze_device_handle_t *phDevice) {
|
ze_device_handle_t *phDevice) {
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "shared/source/helpers/common_types.h"
|
#include "shared/source/helpers/common_types.h"
|
||||||
|
#include "shared/source/memory_manager/memory_manager.h"
|
||||||
#include "shared/source/utilities/stackvec.h"
|
#include "shared/source/utilities/stackvec.h"
|
||||||
|
|
||||||
#include "level_zero/core/source/context/context.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);
|
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;
|
RootDeviceIndicesContainer rootDeviceIndices;
|
||||||
std::map<uint32_t, NEO::DeviceBitfield> deviceBitfields;
|
std::map<uint32_t, NEO::DeviceBitfield> deviceBitfields;
|
||||||
|
|
||||||
|
@ -567,13 +567,21 @@ NEO::GraphicsAllocation *DriverHandleImp::getPeerAllocation(Device *device,
|
|||||||
UNRECOVERABLE_IF(numHandles == 0);
|
UNRECOVERABLE_IF(numHandles == 0);
|
||||||
std::vector<NEO::osHandle> handles;
|
std::vector<NEO::osHandle> handles;
|
||||||
for (uint32_t i = 0; i < numHandles; i++) {
|
for (uint32_t i = 0; i < numHandles; i++) {
|
||||||
int handle = static_cast<int>(alloc->peekInternalHandle(this->getMemoryManager(), i));
|
uint64_t handle = 0;
|
||||||
handles.push_back(handle);
|
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();
|
auto neoDevice = device->getNEODevice()->getRootDevice();
|
||||||
peerPtr = this->importFdHandles(neoDevice, flags, handles, &alloc);
|
peerPtr = this->importFdHandles(neoDevice, flags, handles, &alloc);
|
||||||
} else {
|
} 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);
|
peerPtr = this->importFdHandle(device->getNEODevice(), flags, handle, &alloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,8 +7,6 @@
|
|||||||
target_sources(${L0_STATIC_LIB_NAME}
|
target_sources(${L0_STATIC_LIB_NAME}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
${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}/api_specific_config_l0.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/error_code_helper_l0.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/error_code_helper_l0.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/error_code_helper_l0.h
|
${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.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/test_memory_${DRIVER_MODEL}.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/file_io.h"
|
||||||
#include "shared/source/helpers/string.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/memory_manager/memory_operations_status.h"
|
||||||
#include "shared/source/os_interface/device_factory.h"
|
#include "shared/source/os_interface/device_factory.h"
|
||||||
#include "shared/test/common/helpers/debug_manager_state_restore.h"
|
#include "shared/test/common/helpers/debug_manager_state_restore.h"
|
||||||
@ -1801,6 +1802,53 @@ TEST_F(MemoryExportImportTest,
|
|||||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
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,
|
TEST_F(MemoryExportImportTest,
|
||||||
givenCallToMemAllocPropertiesWithExtendedExportPropertiesForNonDeviceAllocationThenUnsupportedFeatureIsReturned) {
|
givenCallToMemAllocPropertiesWithExtendedExportPropertiesForNonDeviceAllocationThenUnsupportedFeatureIsReturned) {
|
||||||
size_t size = 10;
|
size_t size = 10;
|
||||||
|
@ -193,7 +193,7 @@ cl_int MemObj::getMemObjectInfo(cl_mem_info paramName,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CL_MEM_ALLOCATION_HANDLE_INTEL:
|
case CL_MEM_ALLOCATION_HANDLE_INTEL:
|
||||||
internalHandle = multiGraphicsAllocation.getDefaultGraphicsAllocation()->peekInternalHandle(this->memoryManager);
|
multiGraphicsAllocation.getDefaultGraphicsAllocation()->peekInternalHandle(this->memoryManager, internalHandle);
|
||||||
srcParamSize = sizeof(internalHandle);
|
srcParamSize = sizeof(internalHandle);
|
||||||
srcParam = &internalHandle;
|
srcParam = &internalHandle;
|
||||||
break;
|
break;
|
||||||
|
@ -481,7 +481,9 @@ TEST_F(WddmTestWithMockGdiDll, givenShareableAllocationWhenCreateThenSharedHandl
|
|||||||
allocation.setDefaultGmm(gmm.get());
|
allocation.setDefaultGmm(gmm.get());
|
||||||
auto status = memoryManager.createGpuAllocationsWithRetry(&allocation);
|
auto status = memoryManager.createGpuAllocationsWithRetry(&allocation);
|
||||||
EXPECT_TRUE(status);
|
EXPECT_TRUE(status);
|
||||||
EXPECT_NE(0u, allocation.peekInternalHandle(&memoryManager));
|
uint64_t handle = 0;
|
||||||
|
allocation.peekInternalHandle(&memoryManager, handle);
|
||||||
|
EXPECT_NE(0u, handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(WddmAllocationTest, whenAllocationIsShareableThenSharedHandleToModifyIsSharedHandleOfAllocation) {
|
TEST(WddmAllocationTest, whenAllocationIsShareableThenSharedHandleToModifyIsSharedHandleOfAllocation) {
|
||||||
@ -489,7 +491,10 @@ TEST(WddmAllocationTest, whenAllocationIsShareableThenSharedHandleToModifyIsShar
|
|||||||
auto sharedHandleToModify = allocation.getSharedHandleToModify();
|
auto sharedHandleToModify = allocation.getSharedHandleToModify();
|
||||||
EXPECT_NE(nullptr, sharedHandleToModify);
|
EXPECT_NE(nullptr, sharedHandleToModify);
|
||||||
*sharedHandleToModify = 1234u;
|
*sharedHandleToModify = 1234u;
|
||||||
EXPECT_EQ(*sharedHandleToModify, allocation.peekInternalHandle(nullptr));
|
uint64_t handle = 0;
|
||||||
|
int ret = allocation.peekInternalHandle(nullptr, handle);
|
||||||
|
EXPECT_EQ(ret, 0);
|
||||||
|
EXPECT_EQ(*sharedHandleToModify, handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(WddmAllocationTest, whenAllocationIsNotShareableThenItDoesntReturnSharedHandleToModify) {
|
TEST(WddmAllocationTest, whenAllocationIsNotShareableThenItDoesntReturnSharedHandleToModify) {
|
||||||
|
@ -75,7 +75,9 @@ TEST_F(WddmMemoryManagerSimpleTest, givenShareableAllocationWhenAllocateInDevice
|
|||||||
EXPECT_EQ(MemoryManager::AllocationStatus::Success, status);
|
EXPECT_EQ(MemoryManager::AllocationStatus::Success, status);
|
||||||
EXPECT_EQ(MemoryPool::LocalMemory, allocation->getMemoryPool());
|
EXPECT_EQ(MemoryPool::LocalMemory, allocation->getMemoryPool());
|
||||||
EXPECT_EQ(0u, allocation->getDefaultGmm()->resourceParams.Flags.Info.NonLocalOnly);
|
EXPECT_EQ(0u, allocation->getDefaultGmm()->resourceParams.Flags.Info.NonLocalOnly);
|
||||||
EXPECT_NE(allocation->peekInternalHandle(memoryManager.get()), 0u);
|
uint64_t handle = 0;
|
||||||
|
allocation->peekInternalHandle(memoryManager.get(), handle);
|
||||||
|
EXPECT_NE(handle, 0u);
|
||||||
|
|
||||||
EXPECT_EQ(1u, allocation->getDefaultGmm()->resourceParams.Flags.Info.LocalOnly);
|
EXPECT_EQ(1u, allocation->getDefaultGmm()->resourceParams.Flags.Info.LocalOnly);
|
||||||
EXPECT_EQ(1u, allocation->getDefaultGmm()->resourceParams.Flags.Info.NotLockable);
|
EXPECT_EQ(1u, allocation->getDefaultGmm()->resourceParams.Flags.Info.NotLockable);
|
||||||
@ -102,7 +104,9 @@ TEST_F(WddmMemoryManagerSimpleTest, givenShareableAllocationWhenAllocateGraphics
|
|||||||
EXPECT_NE(nullptr, allocation);
|
EXPECT_NE(nullptr, allocation);
|
||||||
EXPECT_EQ(MemoryPool::LocalMemory, allocation->getMemoryPool());
|
EXPECT_EQ(MemoryPool::LocalMemory, allocation->getMemoryPool());
|
||||||
EXPECT_EQ(0u, allocation->getDefaultGmm()->resourceParams.Flags.Info.NonLocalOnly);
|
EXPECT_EQ(0u, allocation->getDefaultGmm()->resourceParams.Flags.Info.NonLocalOnly);
|
||||||
EXPECT_NE(allocation->peekInternalHandle(memoryManager.get()), 0u);
|
uint64_t handle = 0;
|
||||||
|
allocation->peekInternalHandle(memoryManager.get(), handle);
|
||||||
|
EXPECT_NE(handle, 0u);
|
||||||
|
|
||||||
EXPECT_EQ(1u, allocation->getDefaultGmm()->resourceParams.Flags.Info.LocalOnly);
|
EXPECT_EQ(1u, allocation->getDefaultGmm()->resourceParams.Flags.Info.LocalOnly);
|
||||||
EXPECT_EQ(1u, allocation->getDefaultGmm()->resourceParams.Flags.Info.NotLockable);
|
EXPECT_EQ(1u, allocation->getDefaultGmm()->resourceParams.Flags.Info.NotLockable);
|
||||||
|
@ -169,10 +169,10 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
|
|||||||
bool isResidencyTaskCountBelow(uint32_t taskCount, uint32_t contextId) const { return !isResident(contextId) || getResidencyTaskCount(contextId) < taskCount; }
|
bool isResidencyTaskCountBelow(uint32_t taskCount, uint32_t contextId) const { return !isResident(contextId) || getResidencyTaskCount(contextId) < taskCount; }
|
||||||
|
|
||||||
virtual std::string getAllocationInfoString() const;
|
virtual std::string getAllocationInfoString() const;
|
||||||
virtual uint64_t peekInternalHandle(MemoryManager *memoryManager) { return 0llu; }
|
virtual int peekInternalHandle(MemoryManager *memoryManager, uint64_t &handle) { return 0; }
|
||||||
|
|
||||||
virtual uint64_t peekInternalHandle(MemoryManager *memoryManager, uint32_t handleId) {
|
virtual int peekInternalHandle(MemoryManager *memoryManager, uint32_t handleId, uint64_t &handle) {
|
||||||
return 0u;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual uint32_t getNumHandles() {
|
virtual uint32_t getNumHandles() {
|
||||||
|
@ -37,20 +37,24 @@ std::string DrmAllocation::getAllocationInfoString() const {
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t DrmAllocation::peekInternalHandle(MemoryManager *memoryManager) {
|
int DrmAllocation::peekInternalHandle(MemoryManager *memoryManager, uint64_t &handle) {
|
||||||
if (handles[0] != std::numeric_limits<uint32_t>::max()) {
|
return peekInternalHandle(memoryManager, 0u, handle);
|
||||||
return handles[0];
|
|
||||||
}
|
|
||||||
handles[0] = static_cast<uint64_t>((static_cast<DrmMemoryManager *>(memoryManager))->obtainFdFromHandle(getBO()->peekHandle(), this->rootDeviceIndex));
|
|
||||||
return handles[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t DrmAllocation::peekInternalHandle(MemoryManager *memoryManager, uint32_t handleId) {
|
int DrmAllocation::peekInternalHandle(MemoryManager *memoryManager, uint32_t handleId, uint64_t &handle) {
|
||||||
if (handles[handleId] != std::numeric_limits<uint32_t>::max()) {
|
if (handles[handleId] != std::numeric_limits<uint64_t>::max()) {
|
||||||
return handles[handleId];
|
handle = handles[handleId];
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
handles[handleId] = static_cast<uint64_t>((static_cast<DrmMemoryManager *>(memoryManager))->obtainFdFromHandle(getBufferObjectToModify(handleId)->peekHandle(), this->rootDeviceIndex));
|
|
||||||
return handles[handleId];
|
int64_t ret = static_cast<int64_t>((static_cast<DrmMemoryManager *>(memoryManager))->obtainFdFromHandle(getBufferObjectToModify(handleId)->peekHandle(), this->rootDeviceIndex));
|
||||||
|
if (ret < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
handle = handles[handleId] = ret;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrmAllocation::setCachePolicy(CachePolicy memType) {
|
void DrmAllocation::setCachePolicy(CachePolicy memType) {
|
||||||
|
@ -40,7 +40,7 @@ class DrmAllocation : public GraphicsAllocation {
|
|||||||
DrmAllocation(uint32_t rootDeviceIndex, size_t numGmms, AllocationType allocationType, BufferObject *bo, void *ptrIn, size_t sizeIn, osHandle sharedHandle, MemoryPool pool, uint64_t canonizedGpuAddress)
|
DrmAllocation(uint32_t rootDeviceIndex, size_t numGmms, AllocationType allocationType, BufferObject *bo, void *ptrIn, size_t sizeIn, osHandle sharedHandle, MemoryPool pool, uint64_t canonizedGpuAddress)
|
||||||
: GraphicsAllocation(rootDeviceIndex, numGmms, allocationType, ptrIn, sizeIn, sharedHandle, pool, MemoryManager::maxOsContextCount, canonizedGpuAddress), bufferObjects(EngineLimits::maxHandleCount) {
|
: GraphicsAllocation(rootDeviceIndex, numGmms, allocationType, ptrIn, sizeIn, sharedHandle, pool, MemoryManager::maxOsContextCount, canonizedGpuAddress), bufferObjects(EngineLimits::maxHandleCount) {
|
||||||
bufferObjects[0] = bo;
|
bufferObjects[0] = bo;
|
||||||
handles.resize(EngineLimits::maxHandleCount, std::numeric_limits<uint32_t>::max());
|
handles.resize(EngineLimits::maxHandleCount, std::numeric_limits<uint64_t>::max());
|
||||||
}
|
}
|
||||||
|
|
||||||
DrmAllocation(uint32_t rootDeviceIndex, AllocationType allocationType, BufferObject *bo, void *ptrIn, uint64_t canonizedGpuAddress, size_t sizeIn, MemoryPool pool)
|
DrmAllocation(uint32_t rootDeviceIndex, AllocationType allocationType, BufferObject *bo, void *ptrIn, uint64_t canonizedGpuAddress, size_t sizeIn, MemoryPool pool)
|
||||||
@ -49,7 +49,7 @@ class DrmAllocation : public GraphicsAllocation {
|
|||||||
DrmAllocation(uint32_t rootDeviceIndex, size_t numGmms, AllocationType allocationType, BufferObject *bo, void *ptrIn, uint64_t canonizedGpuAddress, size_t sizeIn, MemoryPool pool)
|
DrmAllocation(uint32_t rootDeviceIndex, size_t numGmms, AllocationType allocationType, BufferObject *bo, void *ptrIn, uint64_t canonizedGpuAddress, size_t sizeIn, MemoryPool pool)
|
||||||
: GraphicsAllocation(rootDeviceIndex, numGmms, allocationType, ptrIn, canonizedGpuAddress, 0, sizeIn, pool, MemoryManager::maxOsContextCount), bufferObjects(EngineLimits::maxHandleCount) {
|
: GraphicsAllocation(rootDeviceIndex, numGmms, allocationType, ptrIn, canonizedGpuAddress, 0, sizeIn, pool, MemoryManager::maxOsContextCount), bufferObjects(EngineLimits::maxHandleCount) {
|
||||||
bufferObjects[0] = bo;
|
bufferObjects[0] = bo;
|
||||||
handles.resize(EngineLimits::maxHandleCount, std::numeric_limits<uint32_t>::max());
|
handles.resize(EngineLimits::maxHandleCount, std::numeric_limits<uint64_t>::max());
|
||||||
}
|
}
|
||||||
|
|
||||||
DrmAllocation(uint32_t rootDeviceIndex, AllocationType allocationType, BufferObjects &bos, void *ptrIn, uint64_t canonizedGpuAddress, size_t sizeIn, MemoryPool pool)
|
DrmAllocation(uint32_t rootDeviceIndex, AllocationType allocationType, BufferObjects &bos, void *ptrIn, uint64_t canonizedGpuAddress, size_t sizeIn, MemoryPool pool)
|
||||||
@ -58,7 +58,7 @@ class DrmAllocation : public GraphicsAllocation {
|
|||||||
DrmAllocation(uint32_t rootDeviceIndex, size_t numGmms, AllocationType allocationType, BufferObjects &bos, void *ptrIn, uint64_t canonizedGpuAddress, size_t sizeIn, MemoryPool pool)
|
DrmAllocation(uint32_t rootDeviceIndex, size_t numGmms, AllocationType allocationType, BufferObjects &bos, void *ptrIn, uint64_t canonizedGpuAddress, size_t sizeIn, MemoryPool pool)
|
||||||
: GraphicsAllocation(rootDeviceIndex, numGmms, allocationType, ptrIn, canonizedGpuAddress, 0, sizeIn, pool, MemoryManager::maxOsContextCount),
|
: GraphicsAllocation(rootDeviceIndex, numGmms, allocationType, ptrIn, canonizedGpuAddress, 0, sizeIn, pool, MemoryManager::maxOsContextCount),
|
||||||
bufferObjects(bos) {
|
bufferObjects(bos) {
|
||||||
handles.resize(EngineLimits::maxHandleCount, std::numeric_limits<uint32_t>::max());
|
handles.resize(EngineLimits::maxHandleCount, std::numeric_limits<uint64_t>::max());
|
||||||
}
|
}
|
||||||
|
|
||||||
~DrmAllocation() override;
|
~DrmAllocation() override;
|
||||||
@ -74,7 +74,7 @@ class DrmAllocation : public GraphicsAllocation {
|
|||||||
const BufferObjects &getBOs() const {
|
const BufferObjects &getBOs() const {
|
||||||
return this->bufferObjects;
|
return this->bufferObjects;
|
||||||
}
|
}
|
||||||
BufferObject *&getBufferObjectToModify(uint32_t handleIndex) {
|
MOCKABLE_VIRTUAL BufferObject *&getBufferObjectToModify(uint32_t handleIndex) {
|
||||||
return bufferObjects[handleIndex];
|
return bufferObjects[handleIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,9 +90,9 @@ class DrmAllocation : public GraphicsAllocation {
|
|||||||
this->numHandles = numHandles;
|
this->numHandles = numHandles;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t peekInternalHandle(MemoryManager *memoryManager) override;
|
int peekInternalHandle(MemoryManager *memoryManager, uint64_t &handle) override;
|
||||||
|
|
||||||
uint64_t peekInternalHandle(MemoryManager *memoryManager, uint32_t handleId) override;
|
int peekInternalHandle(MemoryManager *memoryManager, uint32_t handleId, uint64_t &handle) override;
|
||||||
|
|
||||||
bool setCacheRegion(Drm *drm, CacheRegion regionIndex);
|
bool setCacheRegion(Drm *drm, CacheRegion regionIndex);
|
||||||
bool setCacheAdvice(Drm *drm, size_t regionSize, CacheRegion regionIndex);
|
bool setCacheAdvice(Drm *drm, size_t regionSize, CacheRegion regionIndex);
|
||||||
|
@ -978,7 +978,11 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromExistingStorag
|
|||||||
properties.size = defaultAlloc->getUnderlyingBufferSize();
|
properties.size = defaultAlloc->getUnderlyingBufferSize();
|
||||||
properties.gpuAddress = castToUint64(ptr);
|
properties.gpuAddress = castToUint64(ptr);
|
||||||
|
|
||||||
auto internalHandle = defaultAlloc->peekInternalHandle(this);
|
uint64_t internalHandle = 0;
|
||||||
|
int ret = defaultAlloc->peekInternalHandle(this, internalHandle);
|
||||||
|
if (ret < 0) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
return createUSMHostAllocationFromSharedHandle(static_cast<osHandle>(internalHandle), properties, true);
|
return createUSMHostAllocationFromSharedHandle(static_cast<osHandle>(internalHandle), properties, true);
|
||||||
} else {
|
} else {
|
||||||
return allocateGraphicsMemoryWithProperties(properties, ptr);
|
return allocateGraphicsMemoryWithProperties(properties, ptr);
|
||||||
@ -1114,7 +1118,10 @@ int DrmMemoryManager::obtainFdFromHandle(int boHandle, uint32_t rootDeviceIndex)
|
|||||||
openFd.flags = ioctlHelper->getFlagsForPrimeHandleToFd();
|
openFd.flags = ioctlHelper->getFlagsForPrimeHandleToFd();
|
||||||
openFd.handle = boHandle;
|
openFd.handle = boHandle;
|
||||||
|
|
||||||
ioctlHelper->ioctl(DrmIoctl::PrimeHandleToFd, &openFd);
|
int ret = ioctlHelper->ioctl(DrmIoctl::PrimeHandleToFd, &openFd);
|
||||||
|
if (ret < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return openFd.fileDescriptor;
|
return openFd.fileDescriptor;
|
||||||
}
|
}
|
||||||
|
@ -72,8 +72,9 @@ class WddmAllocation : public GraphicsAllocation {
|
|||||||
handles[handleIndex] = handle;
|
handles[handleIndex] = handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t peekInternalHandle(MemoryManager *memoryManager) override {
|
int peekInternalHandle(MemoryManager *memoryManager, uint64_t &handle) override {
|
||||||
return ntSecureHandle;
|
handle = ntSecureHandle;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t *getSharedHandleToModify() {
|
uint64_t *getSharedHandleToModify() {
|
||||||
|
@ -557,8 +557,10 @@ void WddmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation
|
|||||||
for (auto handleId = 0u; handleId < gfxAllocation->getNumGmms(); handleId++) {
|
for (auto handleId = 0u; handleId < gfxAllocation->getNumGmms(); handleId++) {
|
||||||
delete gfxAllocation->getGmm(handleId);
|
delete gfxAllocation->getGmm(handleId);
|
||||||
}
|
}
|
||||||
if (input->peekInternalHandle(nullptr) != 0u) {
|
uint64_t handle = 0;
|
||||||
[[maybe_unused]] auto status = SysCalls::closeHandle(reinterpret_cast<void *>(reinterpret_cast<uintptr_t *>(input->peekInternalHandle(nullptr))));
|
int ret = input->peekInternalHandle(nullptr, handle);
|
||||||
|
if (ret == 0) {
|
||||||
|
[[maybe_unused]] auto status = SysCalls::closeHandle(reinterpret_cast<void *>(reinterpret_cast<uintptr_t *>(handle)));
|
||||||
DEBUG_BREAK_IF(!status);
|
DEBUG_BREAK_IF(!status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,6 +160,15 @@ class TestedDrmMemoryManager : public MemoryManagerCreate<DrmMemoryManager> {
|
|||||||
|
|
||||||
bool failOnfindAndReferenceSharedBufferObject = false;
|
bool failOnfindAndReferenceSharedBufferObject = false;
|
||||||
|
|
||||||
|
bool failOnObtainFdFromHandle = false;
|
||||||
|
|
||||||
|
int obtainFdFromHandle(int boHandle, uint32_t rootDeviceIndex) override {
|
||||||
|
if (failOnObtainFdFromHandle) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return DrmMemoryManager::obtainFdFromHandle(boHandle, rootDeviceIndex);
|
||||||
|
}
|
||||||
|
|
||||||
ExecutionEnvironment *executionEnvironment = nullptr;
|
ExecutionEnvironment *executionEnvironment = nullptr;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -227,7 +227,9 @@ TEST(GraphicsAllocationTest, givenAlwaysResidentAllocationWhenUpdateTaskCountThe
|
|||||||
|
|
||||||
TEST(GraphicsAllocationTest, givenDefaultGraphicsAllocationWhenInternalHandleIsBeingObtainedThenZeroIsReturned) {
|
TEST(GraphicsAllocationTest, givenDefaultGraphicsAllocationWhenInternalHandleIsBeingObtainedThenZeroIsReturned) {
|
||||||
MockGraphicsAllocation graphicsAllocation;
|
MockGraphicsAllocation graphicsAllocation;
|
||||||
EXPECT_EQ(0llu, graphicsAllocation.peekInternalHandle(nullptr));
|
uint64_t handle = 0;
|
||||||
|
graphicsAllocation.peekInternalHandle(nullptr, handle);
|
||||||
|
EXPECT_EQ(0ull, handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(GraphicsAllocationTest, givenDefaultGraphicsAllocationWhenGettingNumHandlesThenZeroIsReturned) {
|
TEST(GraphicsAllocationTest, givenDefaultGraphicsAllocationWhenGettingNumHandlesThenZeroIsReturned) {
|
||||||
|
@ -131,6 +131,46 @@ TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenMultiRootDeviceEnvironmentAnd
|
|||||||
executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(osInterface);
|
executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(osInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenMultiRootDeviceEnvironmentAndMemoryInfoWhenCreateMultiGraphicsAllocationAndObtainFdFromHandleFailsThenNullptrIsReturned) {
|
||||||
|
uint32_t rootDevicesNumber = 3u;
|
||||||
|
MultiGraphicsAllocation multiGraphics(rootDevicesNumber);
|
||||||
|
RootDeviceIndicesContainer rootDeviceIndices;
|
||||||
|
auto osInterface = executionEnvironment->rootDeviceEnvironments[0]->osInterface.release();
|
||||||
|
|
||||||
|
executionEnvironment->prepareRootDeviceEnvironments(rootDevicesNumber);
|
||||||
|
for (uint32_t i = 0; i < rootDevicesNumber; i++) {
|
||||||
|
executionEnvironment->rootDeviceEnvironments[i]->setHwInfo(defaultHwInfo.get());
|
||||||
|
executionEnvironment->rootDeviceEnvironments[i]->initGmm();
|
||||||
|
auto mock = new DrmQueryMock(*executionEnvironment->rootDeviceEnvironments[i]);
|
||||||
|
|
||||||
|
std::vector<MemoryRegion> regionInfo(2);
|
||||||
|
regionInfo[0].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_SYSTEM, 0};
|
||||||
|
regionInfo[1].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, DrmMockHelper::getEngineOrMemoryInstanceValue(0, 0)};
|
||||||
|
|
||||||
|
mock->memoryInfo.reset(new MemoryInfo(regionInfo, *mock));
|
||||||
|
mock->queryEngineInfo();
|
||||||
|
mock->ioctlCallsCount = 0;
|
||||||
|
executionEnvironment->rootDeviceEnvironments[i]->osInterface = std::make_unique<OSInterface>();
|
||||||
|
executionEnvironment->rootDeviceEnvironments[i]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(mock));
|
||||||
|
executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u);
|
||||||
|
executionEnvironment->rootDeviceEnvironments[i]->initGmm();
|
||||||
|
|
||||||
|
rootDeviceIndices.push_back(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
memoryManager = new TestedDrmMemoryManager(true, false, false, *executionEnvironment);
|
||||||
|
executionEnvironment->memoryManager.reset(memoryManager);
|
||||||
|
|
||||||
|
size_t size = 4096u;
|
||||||
|
AllocationProperties properties(rootDeviceIndex, true, size, AllocationType::BUFFER_HOST_MEMORY, false, {});
|
||||||
|
|
||||||
|
memoryManager->failOnObtainFdFromHandle = true;
|
||||||
|
auto ptr = memoryManager->createMultiGraphicsAllocationInSystemMemoryPool(rootDeviceIndices, properties, multiGraphics);
|
||||||
|
EXPECT_EQ(ptr, nullptr);
|
||||||
|
|
||||||
|
executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(osInterface);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenMultiRootDeviceEnvironmentAndMemoryInfoWhenCreateMultiGraphicsAllocationAndImportFailsThenNullptrIsReturned) {
|
TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenMultiRootDeviceEnvironmentAndMemoryInfoWhenCreateMultiGraphicsAllocationAndImportFailsThenNullptrIsReturned) {
|
||||||
uint32_t rootDevicesNumber = 3u;
|
uint32_t rootDevicesNumber = 3u;
|
||||||
MultiGraphicsAllocation multiGraphics(rootDevicesNumber);
|
MultiGraphicsAllocation multiGraphics(rootDevicesNumber);
|
||||||
|
@ -452,7 +452,25 @@ TEST_F(DrmMemoryManagerTest, whenPeekInternalHandleIsCalledThenBoIsReturned) {
|
|||||||
mock->outputFd = 1337;
|
mock->outputFd = 1337;
|
||||||
auto allocation = static_cast<DrmAllocation *>(this->memoryManager->allocateGraphicsMemoryWithProperties(createAllocationProperties(rootDeviceIndex, 10 * MemoryConstants::pageSize, true)));
|
auto allocation = static_cast<DrmAllocation *>(this->memoryManager->allocateGraphicsMemoryWithProperties(createAllocationProperties(rootDeviceIndex, 10 * MemoryConstants::pageSize, true)));
|
||||||
ASSERT_NE(allocation->getBO(), nullptr);
|
ASSERT_NE(allocation->getBO(), nullptr);
|
||||||
ASSERT_EQ(allocation->peekInternalHandle(this->memoryManager), static_cast<uint64_t>(1337));
|
uint64_t handle = 0;
|
||||||
|
int ret = allocation->peekInternalHandle(this->memoryManager, handle);
|
||||||
|
ASSERT_EQ(ret, 0);
|
||||||
|
ASSERT_EQ(handle, static_cast<uint64_t>(1337));
|
||||||
|
|
||||||
|
memoryManager->freeGraphicsMemory(allocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DrmMemoryManagerTest, whenPeekInternalHandleIsCalledAndObtainFdFromHandleFailsThenErrorIsReturned) {
|
||||||
|
mock->ioctl_expected.gemUserptr = 1;
|
||||||
|
mock->ioctl_expected.gemWait = 1;
|
||||||
|
mock->ioctl_expected.gemClose = 1;
|
||||||
|
mock->outputFd = 1337;
|
||||||
|
auto allocation = static_cast<DrmAllocation *>(this->memoryManager->allocateGraphicsMemoryWithProperties(createAllocationProperties(rootDeviceIndex, 10 * MemoryConstants::pageSize, true)));
|
||||||
|
ASSERT_NE(allocation->getBO(), nullptr);
|
||||||
|
memoryManager->failOnObtainFdFromHandle = true;
|
||||||
|
uint64_t handle = 0;
|
||||||
|
int ret = allocation->peekInternalHandle(this->memoryManager, handle);
|
||||||
|
ASSERT_EQ(ret, -1);
|
||||||
|
|
||||||
memoryManager->freeGraphicsMemory(allocation);
|
memoryManager->freeGraphicsMemory(allocation);
|
||||||
}
|
}
|
||||||
@ -469,11 +487,18 @@ TEST_F(DrmMemoryManagerTest, whenCallingPeekInternalHandleSeveralTimesThenSameHa
|
|||||||
ASSERT_NE(allocation->getBO(), nullptr);
|
ASSERT_NE(allocation->getBO(), nullptr);
|
||||||
|
|
||||||
EXPECT_EQ(mock->outputFd, static_cast<int32_t>(expectedFd));
|
EXPECT_EQ(mock->outputFd, static_cast<int32_t>(expectedFd));
|
||||||
uint64_t handle0 = allocation->peekInternalHandle(this->memoryManager);
|
uint64_t handle0 = 0;
|
||||||
|
int ret = allocation->peekInternalHandle(this->memoryManager, handle0);
|
||||||
|
ASSERT_EQ(ret, 0);
|
||||||
EXPECT_NE(mock->outputFd, static_cast<int32_t>(expectedFd));
|
EXPECT_NE(mock->outputFd, static_cast<int32_t>(expectedFd));
|
||||||
|
|
||||||
uint64_t handle1 = allocation->peekInternalHandle(this->memoryManager);
|
uint64_t handle1 = 0;
|
||||||
uint64_t handle2 = allocation->peekInternalHandle(this->memoryManager);
|
uint64_t handle2 = 0;
|
||||||
|
|
||||||
|
ret = allocation->peekInternalHandle(this->memoryManager, handle1);
|
||||||
|
ASSERT_EQ(ret, 0);
|
||||||
|
ret = allocation->peekInternalHandle(this->memoryManager, handle2);
|
||||||
|
ASSERT_EQ(ret, 0);
|
||||||
|
|
||||||
ASSERT_EQ(handle0, expectedFd);
|
ASSERT_EQ(handle0, expectedFd);
|
||||||
ASSERT_EQ(handle1, expectedFd);
|
ASSERT_EQ(handle1, expectedFd);
|
||||||
@ -491,8 +516,11 @@ TEST_F(DrmMemoryManagerTest, whenPeekInternalHandleWithHandleIdIsCalledThenBoIsR
|
|||||||
auto allocation = static_cast<DrmAllocation *>(this->memoryManager->allocateGraphicsMemoryWithProperties(createAllocationProperties(rootDeviceIndex, 10 * MemoryConstants::pageSize, true)));
|
auto allocation = static_cast<DrmAllocation *>(this->memoryManager->allocateGraphicsMemoryWithProperties(createAllocationProperties(rootDeviceIndex, 10 * MemoryConstants::pageSize, true)));
|
||||||
ASSERT_NE(allocation->getBO(), nullptr);
|
ASSERT_NE(allocation->getBO(), nullptr);
|
||||||
|
|
||||||
|
uint64_t handle = 0;
|
||||||
uint32_t handleId = 0;
|
uint32_t handleId = 0;
|
||||||
ASSERT_EQ(allocation->peekInternalHandle(this->memoryManager, handleId), static_cast<uint64_t>(1337));
|
int ret = allocation->peekInternalHandle(this->memoryManager, handleId, handle);
|
||||||
|
ASSERT_EQ(ret, 0);
|
||||||
|
ASSERT_EQ(handle, static_cast<uint64_t>(1337));
|
||||||
|
|
||||||
memoryManager->freeGraphicsMemory(allocation);
|
memoryManager->freeGraphicsMemory(allocation);
|
||||||
}
|
}
|
||||||
@ -510,11 +538,17 @@ TEST_F(DrmMemoryManagerTest, whenCallingPeekInternalHandleWithIdSeveralTimesThen
|
|||||||
|
|
||||||
EXPECT_EQ(mock->outputFd, static_cast<int32_t>(expectedFd));
|
EXPECT_EQ(mock->outputFd, static_cast<int32_t>(expectedFd));
|
||||||
uint32_t handleId = 0;
|
uint32_t handleId = 0;
|
||||||
uint64_t handle0 = allocation->peekInternalHandle(this->memoryManager, handleId);
|
uint64_t handle0 = 0;
|
||||||
|
int ret = allocation->peekInternalHandle(this->memoryManager, handleId, handle0);
|
||||||
|
ASSERT_EQ(ret, 0);
|
||||||
EXPECT_NE(mock->outputFd, static_cast<int32_t>(expectedFd));
|
EXPECT_NE(mock->outputFd, static_cast<int32_t>(expectedFd));
|
||||||
|
|
||||||
uint64_t handle1 = allocation->peekInternalHandle(this->memoryManager, handleId);
|
uint64_t handle1 = 0;
|
||||||
uint64_t handle2 = allocation->peekInternalHandle(this->memoryManager, handleId);
|
uint64_t handle2 = 0;
|
||||||
|
ret = allocation->peekInternalHandle(this->memoryManager, handleId, handle1);
|
||||||
|
ASSERT_EQ(ret, 0);
|
||||||
|
ret = allocation->peekInternalHandle(this->memoryManager, handleId, handle2);
|
||||||
|
ASSERT_EQ(ret, 0);
|
||||||
|
|
||||||
ASSERT_EQ(handle0, expectedFd);
|
ASSERT_EQ(handle0, expectedFd);
|
||||||
ASSERT_EQ(handle1, expectedFd);
|
ASSERT_EQ(handle1, expectedFd);
|
||||||
@ -3163,6 +3197,29 @@ TEST(DrmMemoryManagerWithExplicitExpectationsTest2, whenObtainFdFromHandleIsCall
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(DrmMemoryManagerWithExplicitExpectationsTest2, whenFailingToObtainFdFromHandleThenErrorIsReturned) {
|
||||||
|
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
|
||||||
|
executionEnvironment->prepareRootDeviceEnvironments(4u);
|
||||||
|
for (auto i = 0u; i < 4u; i++) {
|
||||||
|
executionEnvironment->rootDeviceEnvironments[i]->setHwInfo(defaultHwInfo.get());
|
||||||
|
auto mock = new DrmMockCustom(*executionEnvironment->rootDeviceEnvironments[0]);
|
||||||
|
executionEnvironment->rootDeviceEnvironments[i]->osInterface = std::make_unique<OSInterface>();
|
||||||
|
executionEnvironment->rootDeviceEnvironments[i]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(mock));
|
||||||
|
executionEnvironment->rootDeviceEnvironments[i]->initGmm();
|
||||||
|
}
|
||||||
|
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(false, false, false, *executionEnvironment);
|
||||||
|
for (auto i = 0u; i < 4u; i++) {
|
||||||
|
auto mock = executionEnvironment->rootDeviceEnvironments[i]->osInterface->getDriverModel()->as<DrmMockCustom>();
|
||||||
|
|
||||||
|
int boHandle = 3;
|
||||||
|
mock->outputFd = -1;
|
||||||
|
mock->ioctl_res = -1;
|
||||||
|
mock->ioctl_expected.handleToPrimeFd = 1;
|
||||||
|
auto fdHandle = memoryManager->obtainFdFromHandle(boHandle, i);
|
||||||
|
EXPECT_EQ(-1, fdHandle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(DrmMemoryManagerTest, givenSvmCpuAllocationWhenSizeAndAlignmentProvidedThenAllocateMemoryAndReserveGpuVa) {
|
TEST_F(DrmMemoryManagerTest, givenSvmCpuAllocationWhenSizeAndAlignmentProvidedThenAllocateMemoryAndReserveGpuVa) {
|
||||||
mock->ioctl_expected.gemUserptr = 1;
|
mock->ioctl_expected.gemUserptr = 1;
|
||||||
mock->ioctl_expected.gemWait = 1;
|
mock->ioctl_expected.gemWait = 1;
|
||||||
|
Reference in New Issue
Block a user