mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-21 09:14:47 +08:00
Enable Device Memory to be shared in WSL-2 with L0
- Add getMemoryManagerType to check which memory manager has been init to determine if Linux + WDDM memory manager is in use. - Add isNTHandle to test and verify if a handle is an NT handle during L0 Open IPC Handle. Signed-off-by: Spruit, Neil R <neil.r.spruit@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
90d85bee55
commit
ae77bd1bd2
@@ -28,6 +28,7 @@ set(L0_RUNTIME_SOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cmdqueue/cmdqueue_hw_base.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cmdqueue/cmdqueue_imp.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cmdqueue/cmdqueue_extended${BRANCH_DIR_SUFFIX}cmdqueue_extended.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/context/context_imp_${DRIVER_MODEL}/context_imp.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/context/context_imp.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/context/context_imp.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/context/context.h
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
* Copyright (C) 2020-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -131,6 +131,8 @@ struct Context : _ze_context_handle_t {
|
||||
virtual ze_result_t createImage(ze_device_handle_t hDevice,
|
||||
const ze_image_desc_t *desc,
|
||||
ze_image_handle_t *phImage) = 0;
|
||||
virtual bool isShareableMemory(const void *exportDesc, bool exportableMemory, NEO::Device *neoDevice) = 0;
|
||||
virtual void *getMemHandlePtr(ze_device_handle_t hDevice, uint64_t handle, ze_ipc_memory_flags_t flags) = 0;
|
||||
|
||||
static Context *fromHandle(ze_context_handle_t handle) { return static_cast<Context *>(handle); }
|
||||
inline ze_context_handle_t toHandle() { return this; }
|
||||
|
||||
@@ -160,9 +160,8 @@ ze_result_t ContextImp::allocDeviceMem(ze_device_handle_t hDevice,
|
||||
}
|
||||
|
||||
deviceBitfields[rootDeviceIndex] = neoDevice->getDeviceBitfield();
|
||||
|
||||
NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::DEVICE_UNIFIED_MEMORY, this->driverHandle->rootDeviceIndices, deviceBitfields);
|
||||
unifiedMemoryProperties.allocationFlags.flags.shareable = static_cast<uint32_t>(lookupTable.exportMemory);
|
||||
unifiedMemoryProperties.allocationFlags.flags.shareable = isShareableMemory(deviceDesc->pNext, static_cast<uint32_t>(lookupTable.exportMemory), neoDevice);
|
||||
unifiedMemoryProperties.device = neoDevice;
|
||||
unifiedMemoryProperties.allocationFlags.flags.compressedHint = isAllocationSuitableForCompression(lookupTable, *device, size);
|
||||
|
||||
@@ -430,7 +429,7 @@ ze_result_t ContextImp::openIpcMemHandle(ze_device_handle_t hDevice,
|
||||
reinterpret_cast<void *>(pIpcHandle.data),
|
||||
sizeof(handle));
|
||||
|
||||
*ptr = this->driverHandle->importFdHandle(hDevice, flags, handle, nullptr);
|
||||
*ptr = getMemHandlePtr(hDevice, handle, flags);
|
||||
if (nullptr == *ptr) {
|
||||
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
* Copyright (C) 2020-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "shared/source/os_interface/os_interface.h"
|
||||
|
||||
#include "level_zero/core/source/context/context.h"
|
||||
#include "level_zero/core/source/driver/driver_handle_imp.h"
|
||||
|
||||
@@ -123,6 +125,8 @@ struct ContextImp : Context {
|
||||
std::map<uint32_t, NEO::DeviceBitfield> deviceBitfields;
|
||||
|
||||
bool isDeviceDefinedForThisContext(Device *inDevice);
|
||||
bool isShareableMemory(const void *exportDesc, bool exportableMemory, NEO::Device *neoDevice) override;
|
||||
void *getMemHandlePtr(ze_device_handle_t hDevice, uint64_t handle, ze_ipc_memory_flags_t flags) override;
|
||||
|
||||
protected:
|
||||
bool isAllocationSuitableForCompression(const StructuresLookupTable &structuresLookupTable, Device &device, size_t allocSize);
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/core/source/context/context_imp.h"
|
||||
|
||||
namespace L0 {
|
||||
|
||||
bool ContextImp::isShareableMemory(const void *exportDesc, bool exportableMemory, NEO::Device *neoDevice) {
|
||||
if (exportableMemory) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void *ContextImp::getMemHandlePtr(ze_device_handle_t hDevice, uint64_t handle, ze_ipc_memory_flags_t flags) {
|
||||
return this->driverHandle->importFdHandle(hDevice, flags, handle, nullptr);
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/core/source/context/context_imp.h"
|
||||
|
||||
namespace L0 {
|
||||
|
||||
bool ContextImp::isShareableMemory(const void *exportDesc, bool exportableMemory, NEO::Device *neoDevice) {
|
||||
if (exportableMemory) {
|
||||
return true;
|
||||
}
|
||||
if (neoDevice->getRootDeviceEnvironment().osInterface) {
|
||||
NEO::DriverModelType driverType = neoDevice->getRootDeviceEnvironment().osInterface->getDriverModel()->getDriverModelType();
|
||||
if (!exportDesc && driverType == NEO::DriverModelType::WDDM) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void *ContextImp::getMemHandlePtr(ze_device_handle_t hDevice, uint64_t handle, ze_ipc_memory_flags_t flags) {
|
||||
L0::Device *device = L0::Device::fromHandle(hDevice);
|
||||
bool isNTHandle = this->getDriverHandle()->getMemoryManager()->isNTHandle(NEO::toOsHandle(reinterpret_cast<void *>(handle)), device->getNEODevice()->getRootDeviceIndex());
|
||||
if (isNTHandle) {
|
||||
return this->driverHandle->importNTHandle(hDevice, reinterpret_cast<void *>(handle));
|
||||
} else {
|
||||
return this->driverHandle->importFdHandle(hDevice, flags, handle, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/core/source/context/context_imp.h"
|
||||
|
||||
namespace L0 {
|
||||
|
||||
bool ContextImp::isShareableMemory(const void *exportDesc, bool exportableMemory, NEO::Device *neoDevice) {
|
||||
if (exportableMemory) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void *ContextImp::getMemHandlePtr(ze_device_handle_t hDevice, uint64_t handle, ze_ipc_memory_flags_t flags) {
|
||||
return this->driverHandle->importNTHandle(hDevice, reinterpret_cast<void *>(handle));
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
* Copyright (C) 2020-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (C) 2020-2021 Intel Corporation
|
||||
# Copyright (C) 2020-2022 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
@@ -14,6 +14,7 @@ set(L0_FIXTURES_SOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/device_fixture.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/host_pointer_manager_fixture.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/module_fixture.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/memory_ipc_fixture.h
|
||||
)
|
||||
|
||||
add_library(${TARGET_NAME} OBJECT ${L0_FIXTURES_SOURCES} ${NEO_CORE_tests_compiler_mocks})
|
||||
|
||||
@@ -148,5 +148,33 @@ void SingleRootMultiSubDeviceFixture::SetUp() {
|
||||
neoDevice = device->getNEODevice();
|
||||
}
|
||||
|
||||
void GetMemHandlePtrTestFixture::SetUp() {
|
||||
NEO::MockCompilerEnableGuard mock(true);
|
||||
neoDevice =
|
||||
NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get());
|
||||
auto mockBuiltIns = new MockBuiltins();
|
||||
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns);
|
||||
NEO::DeviceVector devices;
|
||||
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
|
||||
driverHandle = std::make_unique<DriverHandleGetMemHandlePtrMock>();
|
||||
driverHandle->initialize(std::move(devices));
|
||||
prevMemoryManager = driverHandle->getMemoryManager();
|
||||
currMemoryManager = new MemoryManagerMemHandleMock();
|
||||
driverHandle->setMemoryManager(currMemoryManager);
|
||||
device = driverHandle->devices[0];
|
||||
|
||||
context = std::make_unique<L0::ContextImp>(driverHandle.get());
|
||||
EXPECT_NE(context, nullptr);
|
||||
context->getDevices().insert(std::make_pair(device->toHandle(), device));
|
||||
auto neoDevice = device->getNEODevice();
|
||||
context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
|
||||
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
|
||||
}
|
||||
|
||||
void GetMemHandlePtrTestFixture::TearDown() {
|
||||
driverHandle->setMemoryManager(prevMemoryManager);
|
||||
delete currMemoryManager;
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
* Copyright (C) 2020-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "shared/test/common/mocks/mock_device.h"
|
||||
#include "shared/test/common/mocks/mock_memory_manager.h"
|
||||
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h"
|
||||
|
||||
class MockPageFaultManager;
|
||||
@@ -25,7 +26,39 @@ struct Device;
|
||||
struct ContextImp;
|
||||
|
||||
namespace ult {
|
||||
class MockBuiltins;
|
||||
|
||||
struct MockDriverModel : NEO::DriverModel {
|
||||
size_t maxAllocSize;
|
||||
|
||||
MockDriverModel(size_t maxAllocSize) : NEO::DriverModel(NEO::DriverModelType::UNKNOWN), maxAllocSize(maxAllocSize) {}
|
||||
|
||||
void setGmmInputArgs(void *args) override {}
|
||||
uint32_t getDeviceHandle() const override { return {}; }
|
||||
PhysicalDevicePciBusInfo getPciBusInfo() const override { return {}; }
|
||||
size_t getMaxMemAllocSize() const override {
|
||||
return maxAllocSize;
|
||||
}
|
||||
};
|
||||
|
||||
struct MockDriverModelWDDM : NEO::DriverModel {
|
||||
size_t maxAllocSize;
|
||||
|
||||
MockDriverModelWDDM(size_t maxAllocSize) : NEO::DriverModel(NEO::DriverModelType::WDDM), maxAllocSize(maxAllocSize) {}
|
||||
|
||||
void setGmmInputArgs(void *args) override {}
|
||||
uint32_t getDeviceHandle() const override { return {}; }
|
||||
PhysicalDevicePciBusInfo getPciBusInfo() const override { return {}; }
|
||||
size_t getMaxMemAllocSize() const override {
|
||||
return maxAllocSize;
|
||||
}
|
||||
};
|
||||
|
||||
struct ContextShareableMock : public L0::ContextImp {
|
||||
ContextShareableMock(L0::DriverHandleImp *driverHandle) : L0::ContextImp(driverHandle) {}
|
||||
bool isShareableMemory(const void *pNext, bool exportableMemory, NEO::Device *neoDevice) override {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
struct DeviceFixture {
|
||||
NEO::MockCompilerEnableGuard compilerMock = NEO::MockCompilerEnableGuard(true);
|
||||
@@ -40,6 +73,47 @@ struct DeviceFixture {
|
||||
MockBuiltins *mockBuiltIns = nullptr;
|
||||
};
|
||||
|
||||
struct DriverHandleGetMemHandlePtrMock : public L0::DriverHandleImp {
|
||||
void *importFdHandle(ze_device_handle_t hDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::GraphicsAllocation **pAloc) override {
|
||||
if (failHandleLookup) {
|
||||
return nullptr;
|
||||
}
|
||||
return &mockFd;
|
||||
}
|
||||
|
||||
void *importNTHandle(ze_device_handle_t hDevice, void *handle) override {
|
||||
if (failHandleLookup) {
|
||||
return nullptr;
|
||||
}
|
||||
return &mockHandle;
|
||||
}
|
||||
|
||||
uint64_t mockHandle = 57;
|
||||
int mockFd = 57;
|
||||
bool failHandleLookup = false;
|
||||
};
|
||||
|
||||
class MemoryManagerMemHandleMock : public MockMemoryManager {
|
||||
public:
|
||||
bool isNTHandle(osHandle handle, uint32_t rootDeviceIndex) override {
|
||||
return NTHandle;
|
||||
};
|
||||
|
||||
bool NTHandle = false;
|
||||
};
|
||||
|
||||
struct GetMemHandlePtrTestFixture {
|
||||
NEO::MockCompilerEnableGuard compilerMock = NEO::MockCompilerEnableGuard(true);
|
||||
void SetUp(); // NOLINT(readability-identifier-naming)
|
||||
void TearDown(); // NOLINT(readability-identifier-naming)
|
||||
NEO::MemoryManager *prevMemoryManager = nullptr;
|
||||
MemoryManagerMemHandleMock *currMemoryManager = nullptr;
|
||||
std::unique_ptr<DriverHandleGetMemHandlePtrMock> driverHandle;
|
||||
NEO::MockDevice *neoDevice = nullptr;
|
||||
L0::Device *device = nullptr;
|
||||
std::unique_ptr<L0::ContextImp> context;
|
||||
};
|
||||
|
||||
struct PageFaultDeviceFixture {
|
||||
NEO::MockCompilerEnableGuard compilerMock = NEO::MockCompilerEnableGuard(true);
|
||||
void SetUp(); // NOLINT(readability-identifier-naming)
|
||||
|
||||
354
level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h
Normal file
354
level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h
Normal file
@@ -0,0 +1,354 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/helpers/file_io.h"
|
||||
#include "shared/source/helpers/string.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"
|
||||
#include "shared/test/common/helpers/test_files.h"
|
||||
#include "shared/test/common/mocks/mock_compilers.h"
|
||||
#include "shared/test/common/mocks/mock_memory_manager.h"
|
||||
#include "shared/test/common/mocks/ult_device_factory.h"
|
||||
#include "shared/test/common/test_macros/test.h"
|
||||
|
||||
#include "level_zero/core/source/cmdlist/cmdlist_hw.h"
|
||||
#include "level_zero/core/source/context/context_imp.h"
|
||||
#include "level_zero/core/source/device/device_imp.h"
|
||||
#include "level_zero/core/source/driver/host_pointer_manager.h"
|
||||
#include "level_zero/core/source/hw_helpers/l0_hw_helper.h"
|
||||
#include "level_zero/core/source/module/module.h"
|
||||
#include "level_zero/core/source/module/module_imp.h"
|
||||
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_kernel.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
struct DriverHandleGetFdMock : public L0::DriverHandleImp {
|
||||
void *importFdHandle(ze_device_handle_t hDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::GraphicsAllocation **pAloc) override {
|
||||
if (mockFd == allocationMap.second) {
|
||||
return allocationMap.first;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const int mockFd = 57;
|
||||
std::pair<void *, int> allocationMap;
|
||||
};
|
||||
|
||||
struct ContextFdMock : public L0::ContextImp {
|
||||
ContextFdMock(DriverHandleGetFdMock *inDriverHandle) : L0::ContextImp(static_cast<L0::DriverHandle *>(inDriverHandle)) {
|
||||
driverHandle = inDriverHandle;
|
||||
}
|
||||
ze_result_t allocDeviceMem(ze_device_handle_t hDevice,
|
||||
const ze_device_mem_alloc_desc_t *deviceDesc,
|
||||
size_t size,
|
||||
size_t alignment, void **ptr) override {
|
||||
ze_result_t res = L0::ContextImp::allocDeviceMem(hDevice, deviceDesc, size, alignment, ptr);
|
||||
if (ZE_RESULT_SUCCESS == res) {
|
||||
driverHandle->allocationMap.first = *ptr;
|
||||
driverHandle->allocationMap.second = driverHandle->mockFd;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
ze_result_t getMemAllocProperties(const void *ptr,
|
||||
ze_memory_allocation_properties_t *pMemAllocProperties,
|
||||
ze_device_handle_t *phDevice) override {
|
||||
ze_result_t res = ContextImp::getMemAllocProperties(ptr, pMemAllocProperties, phDevice);
|
||||
if (ZE_RESULT_SUCCESS == res && pMemAllocProperties->pNext) {
|
||||
ze_external_memory_export_fd_t *extendedMemoryExportProperties =
|
||||
reinterpret_cast<ze_external_memory_export_fd_t *>(pMemAllocProperties->pNext);
|
||||
extendedMemoryExportProperties->fd = driverHandle->mockFd;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
ze_result_t closeIpcMemHandle(const void *ptr) override {
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
DriverHandleGetFdMock *driverHandle = nullptr;
|
||||
};
|
||||
|
||||
struct MemoryExportImportTest : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
NEO::MockCompilerEnableGuard mock(true);
|
||||
neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get());
|
||||
auto mockBuiltIns = new MockBuiltins();
|
||||
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns);
|
||||
NEO::DeviceVector devices;
|
||||
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
|
||||
driverHandle = std::make_unique<DriverHandleGetFdMock>();
|
||||
driverHandle->initialize(std::move(devices));
|
||||
device = driverHandle->devices[0];
|
||||
|
||||
context = std::make_unique<ContextFdMock>(driverHandle.get());
|
||||
EXPECT_NE(context, nullptr);
|
||||
context->getDevices().insert(std::make_pair(device->toHandle(), device));
|
||||
auto neoDevice = device->getNEODevice();
|
||||
context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
|
||||
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
}
|
||||
std::unique_ptr<DriverHandleGetFdMock> driverHandle;
|
||||
NEO::MockDevice *neoDevice = nullptr;
|
||||
L0::Device *device = nullptr;
|
||||
ze_context_handle_t hContext;
|
||||
std::unique_ptr<ContextFdMock> context;
|
||||
};
|
||||
|
||||
struct DriverHandleGetWinHandleMock : public L0::DriverHandleImp {
|
||||
void *importNTHandle(ze_device_handle_t hDevice, void *handle) override {
|
||||
if (mockHandle == allocationMap.second) {
|
||||
return allocationMap.first;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint64_t mockHandle = 57;
|
||||
std::pair<void *, uint64_t> allocationMap;
|
||||
};
|
||||
|
||||
struct ContextHandleMock : public L0::ContextImp {
|
||||
ContextHandleMock(DriverHandleGetWinHandleMock *inDriverHandle) : L0::ContextImp(static_cast<L0::DriverHandle *>(inDriverHandle)) {
|
||||
driverHandle = inDriverHandle;
|
||||
}
|
||||
ze_result_t allocDeviceMem(ze_device_handle_t hDevice,
|
||||
const ze_device_mem_alloc_desc_t *deviceDesc,
|
||||
size_t size,
|
||||
size_t alignment, void **ptr) override {
|
||||
ze_result_t res = L0::ContextImp::allocDeviceMem(hDevice, deviceDesc, size, alignment, ptr);
|
||||
if (ZE_RESULT_SUCCESS == res) {
|
||||
driverHandle->allocationMap.first = *ptr;
|
||||
driverHandle->allocationMap.second = driverHandle->mockHandle;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
ze_result_t getMemAllocProperties(const void *ptr,
|
||||
ze_memory_allocation_properties_t *pMemAllocProperties,
|
||||
ze_device_handle_t *phDevice) override {
|
||||
ze_result_t res = ContextImp::getMemAllocProperties(ptr, pMemAllocProperties, phDevice);
|
||||
if (ZE_RESULT_SUCCESS == res && pMemAllocProperties->pNext) {
|
||||
_ze_external_memory_export_win32_handle_t *extendedMemoryExportProperties =
|
||||
reinterpret_cast<_ze_external_memory_export_win32_handle_t *>(pMemAllocProperties->pNext);
|
||||
extendedMemoryExportProperties->handle = reinterpret_cast<void *>(reinterpret_cast<uintptr_t *>(driverHandle->mockHandle));
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
ze_result_t freeMem(const void *ptr) override {
|
||||
L0::ContextImp::freeMem(ptr);
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
DriverHandleGetWinHandleMock *driverHandle = nullptr;
|
||||
};
|
||||
|
||||
struct MemoryExportImportWinHandleTest : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
NEO::MockCompilerEnableGuard mock(true);
|
||||
neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get());
|
||||
auto mockBuiltIns = new MockBuiltins();
|
||||
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns);
|
||||
NEO::DeviceVector devices;
|
||||
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
|
||||
driverHandle = std::make_unique<DriverHandleGetWinHandleMock>();
|
||||
driverHandle->initialize(std::move(devices));
|
||||
device = driverHandle->devices[0];
|
||||
|
||||
context = std::make_unique<ContextHandleMock>(driverHandle.get());
|
||||
EXPECT_NE(context, nullptr);
|
||||
context->getDevices().insert(std::make_pair(device->toHandle(), device));
|
||||
auto neoDevice = device->getNEODevice();
|
||||
context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
|
||||
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
}
|
||||
std::unique_ptr<DriverHandleGetWinHandleMock> driverHandle;
|
||||
NEO::MockDevice *neoDevice = nullptr;
|
||||
L0::Device *device = nullptr;
|
||||
ze_context_handle_t hContext;
|
||||
std::unique_ptr<ContextHandleMock> context;
|
||||
};
|
||||
|
||||
struct DriverHandleGetIpcHandleMock : public DriverHandleImp {
|
||||
void *importFdHandle(ze_device_handle_t hDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::GraphicsAllocation **pAlloc) override {
|
||||
EXPECT_EQ(handle, static_cast<uint64_t>(mockFd));
|
||||
if (mockFd == allocationMap.second) {
|
||||
return allocationMap.first;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const int mockFd = 999;
|
||||
std::pair<void *, int> allocationMap;
|
||||
};
|
||||
|
||||
struct ContextGetIpcHandleMock : public L0::ContextImp {
|
||||
ContextGetIpcHandleMock(DriverHandleGetIpcHandleMock *inDriverHandle) : L0::ContextImp(static_cast<L0::DriverHandle *>(inDriverHandle)) {
|
||||
driverHandle = inDriverHandle;
|
||||
}
|
||||
ze_result_t allocDeviceMem(ze_device_handle_t hDevice,
|
||||
const ze_device_mem_alloc_desc_t *deviceDesc,
|
||||
size_t size,
|
||||
size_t alignment, void **ptr) override {
|
||||
ze_result_t res = L0::ContextImp::allocDeviceMem(hDevice, deviceDesc, size, alignment, ptr);
|
||||
if (ZE_RESULT_SUCCESS == res) {
|
||||
driverHandle->allocationMap.first = *ptr;
|
||||
driverHandle->allocationMap.second = driverHandle->mockFd;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
ze_result_t getIpcMemHandle(const void *ptr, ze_ipc_mem_handle_t *pIpcHandle) override {
|
||||
uint64_t handle = driverHandle->mockFd;
|
||||
memcpy_s(reinterpret_cast<void *>(pIpcHandle->data),
|
||||
sizeof(ze_ipc_mem_handle_t),
|
||||
&handle,
|
||||
sizeof(handle));
|
||||
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
DriverHandleGetIpcHandleMock *driverHandle = nullptr;
|
||||
};
|
||||
|
||||
class MemoryManagerIpcMock : public NEO::MemoryManager {
|
||||
public:
|
||||
MemoryManagerIpcMock(NEO::ExecutionEnvironment &executionEnvironment) : NEO::MemoryManager(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, GraphicsAllocation::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{};
|
||||
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{};
|
||||
};
|
||||
|
||||
class MemoryManagerOpenIpcMock : public MemoryManagerIpcMock {
|
||||
public:
|
||||
MemoryManagerOpenIpcMock(NEO::ExecutionEnvironment &executionEnvironment) : MemoryManagerIpcMock(executionEnvironment) {}
|
||||
NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override {
|
||||
if (failOnCreateGraphicsAllocationFromSharedHandle) {
|
||||
return nullptr;
|
||||
}
|
||||
auto alloc = new NEO::MockGraphicsAllocation(0,
|
||||
NEO::GraphicsAllocation::AllocationType::BUFFER,
|
||||
reinterpret_cast<void *>(sharedHandleAddress++),
|
||||
0x1000,
|
||||
0,
|
||||
sizeof(uint32_t),
|
||||
MemoryPool::System4KBPages);
|
||||
alloc->setGpuBaseAddress(0xabcd);
|
||||
return alloc;
|
||||
}
|
||||
NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, GraphicsAllocation::AllocationType allocType) override {
|
||||
auto alloc = new NEO::MockGraphicsAllocation(0,
|
||||
NEO::GraphicsAllocation::AllocationType::BUFFER,
|
||||
reinterpret_cast<void *>(sharedHandleAddress++),
|
||||
0x1000,
|
||||
0,
|
||||
sizeof(uint32_t),
|
||||
MemoryPool::System4KBPages);
|
||||
alloc->setGpuBaseAddress(0xabcd);
|
||||
return alloc;
|
||||
};
|
||||
|
||||
uint64_t sharedHandleAddress = 0x1234;
|
||||
|
||||
bool failOnCreateGraphicsAllocationFromSharedHandle = false;
|
||||
};
|
||||
|
||||
struct ContextIpcMock : public L0::ContextImp {
|
||||
ContextIpcMock(DriverHandleImp *inDriverHandle) : L0::ContextImp(static_cast<L0::DriverHandle *>(inDriverHandle)) {
|
||||
driverHandle = inDriverHandle;
|
||||
}
|
||||
|
||||
ze_result_t getIpcMemHandle(const void *ptr, ze_ipc_mem_handle_t *pIpcHandle) override {
|
||||
uint64_t handle = mockFd;
|
||||
memcpy_s(reinterpret_cast<void *>(pIpcHandle->data),
|
||||
sizeof(ze_ipc_mem_handle_t),
|
||||
&handle,
|
||||
sizeof(handle));
|
||||
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
const int mockFd = 999;
|
||||
};
|
||||
|
||||
struct MemoryOpenIpcHandleTest : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
NEO::MockCompilerEnableGuard mock(true);
|
||||
neoDevice =
|
||||
NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get());
|
||||
auto mockBuiltIns = new MockBuiltins();
|
||||
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns);
|
||||
NEO::DeviceVector devices;
|
||||
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
|
||||
driverHandle = std::make_unique<DriverHandleImp>();
|
||||
driverHandle->initialize(std::move(devices));
|
||||
prevMemoryManager = driverHandle->getMemoryManager();
|
||||
currMemoryManager = new MemoryManagerOpenIpcMock(*neoDevice->executionEnvironment);
|
||||
driverHandle->setMemoryManager(currMemoryManager);
|
||||
device = driverHandle->devices[0];
|
||||
|
||||
context = std::make_unique<ContextIpcMock>(driverHandle.get());
|
||||
EXPECT_NE(context, nullptr);
|
||||
context->getDevices().insert(std::make_pair(device->toHandle(), device));
|
||||
auto neoDevice = device->getNEODevice();
|
||||
context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
|
||||
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
driverHandle->setMemoryManager(prevMemoryManager);
|
||||
delete currMemoryManager;
|
||||
}
|
||||
NEO::MemoryManager *prevMemoryManager = nullptr;
|
||||
NEO::MemoryManager *currMemoryManager = nullptr;
|
||||
std::unique_ptr<DriverHandleImp> driverHandle;
|
||||
NEO::MockDevice *neoDevice = nullptr;
|
||||
L0::Device *device = nullptr;
|
||||
std::unique_ptr<ContextIpcMock> context;
|
||||
};
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Intel Corporation
|
||||
* Copyright (C) 2021-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (C) 2020 Intel Corporation
|
||||
# Copyright (C) 2020-2022 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
@@ -7,4 +7,5 @@
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_context.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/context_${DRIVER_MODEL}/test_context.cpp
|
||||
)
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/test/common/mocks/mock_command_stream_receiver.h"
|
||||
#include "shared/test/common/mocks/mock_compilers.h"
|
||||
#include "shared/test/common/mocks/mock_graphics_allocation.h"
|
||||
#include "shared/test/common/mocks/mock_memory_manager.h"
|
||||
#include "shared/test/common/mocks/mock_svm_manager.h"
|
||||
#include "shared/test/common/test_macros/test.h"
|
||||
#include "shared/test/unit_test/page_fault_manager/mock_cpu_page_fault_manager.h"
|
||||
|
||||
#include "level_zero/core/source/context/context_imp.h"
|
||||
#include "level_zero/core/source/driver/driver_handle_imp.h"
|
||||
#include "level_zero/core/source/image/image.h"
|
||||
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
|
||||
#include "level_zero/core/test/unit_tests/fixtures/host_pointer_manager_fixture.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
using ContextIsShareable = Test<DeviceFixture>;
|
||||
TEST_F(ContextIsShareable, whenCallingisSharedMemoryThenCorrectResultIsReturned) {
|
||||
ze_context_handle_t hContext;
|
||||
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
|
||||
|
||||
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
|
||||
ContextImp *contextImp = static_cast<ContextImp *>(L0::Context::fromHandle(hContext));
|
||||
|
||||
bool exportableMemoryFalse = false;
|
||||
bool exportableMemoryTrue = true;
|
||||
EXPECT_EQ(exportableMemoryFalse, contextImp->isShareableMemory(nullptr, exportableMemoryFalse, neoDevice));
|
||||
EXPECT_EQ(exportableMemoryTrue, contextImp->isShareableMemory(nullptr, exportableMemoryTrue, neoDevice));
|
||||
|
||||
res = contextImp->destroy();
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
}
|
||||
|
||||
using GetMemHandlePtrTest = Test<GetMemHandlePtrTestFixture>;
|
||||
TEST_F(GetMemHandlePtrTest, whenCallingGetMemHandlePtrWithValidHandleThenSuccessIsReturned) {
|
||||
MemoryManagerMemHandleMock *fixtureMemoryManager = static_cast<MemoryManagerMemHandleMock *>(currMemoryManager);
|
||||
|
||||
uint64_t handle = 57;
|
||||
|
||||
// Test Successfully returning fd Handle
|
||||
fixtureMemoryManager->NTHandle = false;
|
||||
EXPECT_NE(nullptr, context->getMemHandlePtr(device, handle, 0));
|
||||
}
|
||||
|
||||
TEST_F(GetMemHandlePtrTest, whenCallingGetMemHandlePtrWithInvalidHandleThenNullptrIsReturned) {
|
||||
MemoryManagerMemHandleMock *fixtureMemoryManager = static_cast<MemoryManagerMemHandleMock *>(currMemoryManager);
|
||||
|
||||
uint64_t handle = 57;
|
||||
|
||||
driverHandle->failHandleLookup = true;
|
||||
|
||||
// Test Failing returning fd Handle
|
||||
fixtureMemoryManager->NTHandle = false;
|
||||
EXPECT_EQ(nullptr, context->getMemHandlePtr(device, handle, 0));
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/test/common/mocks/mock_command_stream_receiver.h"
|
||||
#include "shared/test/common/mocks/mock_compilers.h"
|
||||
#include "shared/test/common/mocks/mock_graphics_allocation.h"
|
||||
#include "shared/test/common/mocks/mock_memory_manager.h"
|
||||
#include "shared/test/common/mocks/mock_svm_manager.h"
|
||||
#include "shared/test/common/test_macros/test.h"
|
||||
#include "shared/test/unit_test/page_fault_manager/mock_cpu_page_fault_manager.h"
|
||||
|
||||
#include "level_zero/core/source/context/context_imp.h"
|
||||
#include "level_zero/core/source/driver/driver_handle_imp.h"
|
||||
#include "level_zero/core/source/image/image.h"
|
||||
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
|
||||
#include "level_zero/core/test/unit_tests/fixtures/host_pointer_manager_fixture.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
using ContextIsShareable = Test<DeviceFixture>;
|
||||
TEST_F(ContextIsShareable, whenCallingisSharedMemoryThenCorrectResultIsReturned) {
|
||||
ze_context_handle_t hContext;
|
||||
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
|
||||
|
||||
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
|
||||
ContextImp *contextImp = static_cast<ContextImp *>(L0::Context::fromHandle(hContext));
|
||||
|
||||
bool exportableMemoryFalse = false;
|
||||
bool exportableMemoryTrue = true;
|
||||
|
||||
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(new NEO::OSInterface());
|
||||
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::make_unique<MockDriverModel>(512));
|
||||
EXPECT_EQ(exportableMemoryFalse, contextImp->isShareableMemory(nullptr, exportableMemoryFalse, neoDevice));
|
||||
EXPECT_EQ(exportableMemoryTrue, contextImp->isShareableMemory(nullptr, exportableMemoryTrue, neoDevice));
|
||||
// exportDesc set && neoDevice is NOT WDDM
|
||||
EXPECT_EQ(exportableMemoryFalse, contextImp->isShareableMemory(&desc, exportableMemoryFalse, neoDevice));
|
||||
// exportDesc unset && neoDevice is NOT WDDM
|
||||
EXPECT_EQ(exportableMemoryFalse, contextImp->isShareableMemory(nullptr, exportableMemoryFalse, neoDevice));
|
||||
// exportDesc unset && neoDevice is WDDM
|
||||
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::make_unique<MockDriverModelWDDM>(512));
|
||||
EXPECT_EQ(exportableMemoryTrue, contextImp->isShareableMemory(nullptr, exportableMemoryFalse, neoDevice));
|
||||
// exportDesc is set && Exportable Memory is False && neoDevice is WDDM
|
||||
EXPECT_EQ(exportableMemoryFalse, contextImp->isShareableMemory(&desc, exportableMemoryFalse, neoDevice));
|
||||
|
||||
res = contextImp->destroy();
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
}
|
||||
|
||||
using GetMemHandlePtrTest = Test<GetMemHandlePtrTestFixture>;
|
||||
TEST_F(GetMemHandlePtrTest, whenCallingGetMemHandlePtrWithValidHandleThenSuccessIsReturned) {
|
||||
MemoryManagerMemHandleMock *fixtureMemoryManager = static_cast<MemoryManagerMemHandleMock *>(currMemoryManager);
|
||||
|
||||
uint64_t handle = 57;
|
||||
|
||||
// Test Successfully returning NT Handle
|
||||
fixtureMemoryManager->NTHandle = true;
|
||||
EXPECT_NE(nullptr, context->getMemHandlePtr(device, handle, 0));
|
||||
|
||||
// Test Successfully returning fd Handle
|
||||
fixtureMemoryManager->NTHandle = false;
|
||||
EXPECT_NE(nullptr, context->getMemHandlePtr(device, handle, 0));
|
||||
}
|
||||
|
||||
TEST_F(GetMemHandlePtrTest, whenCallingGetMemHandlePtrWithInvalidHandleThenNullptrIsReturned) {
|
||||
MemoryManagerMemHandleMock *fixtureMemoryManager = static_cast<MemoryManagerMemHandleMock *>(currMemoryManager);
|
||||
|
||||
uint64_t handle = 57;
|
||||
|
||||
driverHandle->failHandleLookup = true;
|
||||
|
||||
// Test Failing returning NT Handle
|
||||
fixtureMemoryManager->NTHandle = true;
|
||||
EXPECT_EQ(nullptr, context->getMemHandlePtr(device, handle, 0));
|
||||
|
||||
// Test Failing returning fd Handle
|
||||
fixtureMemoryManager->NTHandle = false;
|
||||
EXPECT_EQ(nullptr, context->getMemHandlePtr(device, handle, 0));
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/test/common/mocks/mock_command_stream_receiver.h"
|
||||
#include "shared/test/common/mocks/mock_compilers.h"
|
||||
#include "shared/test/common/mocks/mock_graphics_allocation.h"
|
||||
#include "shared/test/common/mocks/mock_memory_manager.h"
|
||||
#include "shared/test/common/mocks/mock_svm_manager.h"
|
||||
#include "shared/test/common/test_macros/test.h"
|
||||
#include "shared/test/unit_test/page_fault_manager/mock_cpu_page_fault_manager.h"
|
||||
|
||||
#include "level_zero/core/source/context/context_imp.h"
|
||||
#include "level_zero/core/source/driver/driver_handle_imp.h"
|
||||
#include "level_zero/core/source/image/image.h"
|
||||
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
|
||||
#include "level_zero/core/test/unit_tests/fixtures/host_pointer_manager_fixture.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
using ContextIsShareable = Test<DeviceFixture>;
|
||||
TEST_F(ContextIsShareable, whenCallingisSharedMemoryThenCorrectResultIsReturned) {
|
||||
ze_context_handle_t hContext;
|
||||
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
|
||||
|
||||
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
|
||||
ContextImp *contextImp = static_cast<ContextImp *>(L0::Context::fromHandle(hContext));
|
||||
|
||||
bool exportableMemoryFalse = false;
|
||||
bool exportableMemoryTrue = true;
|
||||
EXPECT_EQ(exportableMemoryFalse, contextImp->isShareableMemory(nullptr, exportableMemoryFalse, neoDevice));
|
||||
EXPECT_EQ(exportableMemoryTrue, contextImp->isShareableMemory(nullptr, exportableMemoryTrue, neoDevice));
|
||||
|
||||
res = contextImp->destroy();
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
}
|
||||
|
||||
using GetMemHandlePtrTest = Test<GetMemHandlePtrTestFixture>;
|
||||
TEST_F(GetMemHandlePtrTest, whenCallingGetMemHandlePtrWithValidHandleThenSuccessIsReturned) {
|
||||
MemoryManagerMemHandleMock *fixtureMemoryManager = static_cast<MemoryManagerMemHandleMock *>(currMemoryManager);
|
||||
|
||||
uint64_t handle = 57;
|
||||
|
||||
// Test Successfully returning NT Handle
|
||||
fixtureMemoryManager->NTHandle = true;
|
||||
EXPECT_NE(nullptr, context->getMemHandlePtr(device, handle, 0));
|
||||
}
|
||||
|
||||
TEST_F(GetMemHandlePtrTest, whenCallingGetMemHandlePtrWithInvalidHandleThenNullptrIsReturned) {
|
||||
MemoryManagerMemHandleMock *fixtureMemoryManager = static_cast<MemoryManagerMemHandleMock *>(currMemoryManager);
|
||||
|
||||
uint64_t handle = 57;
|
||||
|
||||
driverHandle->failHandleLookup = true;
|
||||
|
||||
// Test Failing returning NT Handle
|
||||
fixtureMemoryManager->NTHandle = true;
|
||||
EXPECT_EQ(nullptr, context->getMemHandlePtr(device, handle, 0));
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
@@ -577,6 +577,7 @@ HWTEST_F(NotifyModuleLoadTest, givenDebuggingEnabledWhenModuleIsCreatedAndFullyL
|
||||
|
||||
memoryOperationsHandler->makeResidentCalledCount = 0;
|
||||
|
||||
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(nullptr);
|
||||
module->initialize(&moduleDesc, neoDevice);
|
||||
|
||||
EXPECT_EQ(4, memoryOperationsHandler->makeResidentCalledCount);
|
||||
@@ -628,6 +629,7 @@ HWTEST_F(NotifyModuleLoadTest, givenDebuggingEnabledWhenModuleWithUnresolvedSymb
|
||||
|
||||
memoryOperationsHandler->makeResidentCalledCount = 0;
|
||||
|
||||
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(nullptr);
|
||||
module->initialize(&moduleDesc, neoDevice);
|
||||
|
||||
EXPECT_EQ(0, memoryOperationsHandler->makeResidentCalledCount);
|
||||
|
||||
@@ -1463,7 +1463,7 @@ struct MultipleDevicesFixture : public ::testing::Test {
|
||||
driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
|
||||
driverHandle->initialize(std::move(devices));
|
||||
|
||||
context = std::make_unique<ContextImp>(driverHandle.get());
|
||||
context = std::make_unique<ContextShareableMock>(driverHandle.get());
|
||||
EXPECT_NE(context, nullptr);
|
||||
for (auto i = 0u; i < numRootDevices; i++) {
|
||||
auto device = driverHandle->devices[i];
|
||||
@@ -1478,7 +1478,7 @@ struct MultipleDevicesFixture : public ::testing::Test {
|
||||
std::unique_ptr<Mock<L0::DriverHandleImp>> driverHandle;
|
||||
MockMemoryManagerMultiDevice *memoryManager = nullptr;
|
||||
std::unique_ptr<UltDeviceFactory> deviceFactory;
|
||||
std::unique_ptr<ContextImp> context;
|
||||
std::unique_ptr<ContextShareableMock> context;
|
||||
|
||||
const uint32_t numRootDevices = 2u;
|
||||
const uint32_t numSubDevices = 2u;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
* Copyright (C) 2020-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (C) 2020 Intel Corporation
|
||||
# Copyright (C) 2020-2022 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
@@ -7,4 +7,5 @@
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_memory.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_memory_${DRIVER_MODEL}/test_memory_ipc.cpp
|
||||
)
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "level_zero/core/source/module/module.h"
|
||||
#include "level_zero/core/source/module/module_imp.h"
|
||||
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
|
||||
#include "level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_kernel.h"
|
||||
@@ -1211,84 +1212,6 @@ TEST_F(MemoryExportImportFailTest,
|
||||
EXPECT_EQ(usmType, ZE_MEMORY_TYPE_UNKNOWN);
|
||||
}
|
||||
|
||||
struct DriverHandleGetFdMock : public L0::DriverHandleImp {
|
||||
void *importFdHandle(ze_device_handle_t hDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::GraphicsAllocation **pAloc) override {
|
||||
if (mockFd == allocationMap.second) {
|
||||
return allocationMap.first;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const int mockFd = 57;
|
||||
std::pair<void *, int> allocationMap;
|
||||
};
|
||||
|
||||
struct ContextFdMock : public L0::ContextImp {
|
||||
ContextFdMock(DriverHandleGetFdMock *inDriverHandle) : L0::ContextImp(static_cast<L0::DriverHandle *>(inDriverHandle)) {
|
||||
driverHandle = inDriverHandle;
|
||||
}
|
||||
ze_result_t allocDeviceMem(ze_device_handle_t hDevice,
|
||||
const ze_device_mem_alloc_desc_t *deviceDesc,
|
||||
size_t size,
|
||||
size_t alignment, void **ptr) override {
|
||||
ze_result_t res = L0::ContextImp::allocDeviceMem(hDevice, deviceDesc, size, alignment, ptr);
|
||||
if (ZE_RESULT_SUCCESS == res) {
|
||||
driverHandle->allocationMap.first = *ptr;
|
||||
driverHandle->allocationMap.second = driverHandle->mockFd;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
ze_result_t getMemAllocProperties(const void *ptr,
|
||||
ze_memory_allocation_properties_t *pMemAllocProperties,
|
||||
ze_device_handle_t *phDevice) override {
|
||||
ze_result_t res = ContextImp::getMemAllocProperties(ptr, pMemAllocProperties, phDevice);
|
||||
if (ZE_RESULT_SUCCESS == res && pMemAllocProperties->pNext) {
|
||||
ze_external_memory_export_fd_t *extendedMemoryExportProperties =
|
||||
reinterpret_cast<ze_external_memory_export_fd_t *>(pMemAllocProperties->pNext);
|
||||
extendedMemoryExportProperties->fd = driverHandle->mockFd;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
ze_result_t closeIpcMemHandle(const void *ptr) override {
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
DriverHandleGetFdMock *driverHandle = nullptr;
|
||||
};
|
||||
|
||||
struct MemoryExportImportTest : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
NEO::MockCompilerEnableGuard mock(true);
|
||||
neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get());
|
||||
auto mockBuiltIns = new MockBuiltins();
|
||||
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns);
|
||||
NEO::DeviceVector devices;
|
||||
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
|
||||
driverHandle = std::make_unique<DriverHandleGetFdMock>();
|
||||
driverHandle->initialize(std::move(devices));
|
||||
device = driverHandle->devices[0];
|
||||
|
||||
context = std::make_unique<ContextFdMock>(driverHandle.get());
|
||||
EXPECT_NE(context, nullptr);
|
||||
context->getDevices().insert(std::make_pair(device->toHandle(), device));
|
||||
auto neoDevice = device->getNEODevice();
|
||||
context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
|
||||
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
}
|
||||
std::unique_ptr<DriverHandleGetFdMock> driverHandle;
|
||||
NEO::MockDevice *neoDevice = nullptr;
|
||||
L0::Device *device = nullptr;
|
||||
ze_context_handle_t hContext;
|
||||
std::unique_ptr<ContextFdMock> context;
|
||||
};
|
||||
|
||||
TEST_F(MemoryExportImportTest,
|
||||
givenCallToDeviceAllocWithExtendedExportDescriptorAndNonSupportedFlagThenUnsuportedEnumerationIsReturned) {
|
||||
size_t size = 10;
|
||||
@@ -1514,80 +1437,6 @@ TEST_F(MemoryExportImportTest,
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
struct DriverHandleGetWinHandleMock : public L0::DriverHandleImp {
|
||||
void *importNTHandle(ze_device_handle_t hDevice, void *handle) override {
|
||||
if (mockHandle == allocationMap.second) {
|
||||
return allocationMap.first;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint64_t mockHandle = 57;
|
||||
std::pair<void *, uint64_t> allocationMap;
|
||||
};
|
||||
|
||||
struct ContextHandleMock : public L0::ContextImp {
|
||||
ContextHandleMock(DriverHandleGetWinHandleMock *inDriverHandle) : L0::ContextImp(static_cast<L0::DriverHandle *>(inDriverHandle)) {
|
||||
driverHandle = inDriverHandle;
|
||||
}
|
||||
ze_result_t allocDeviceMem(ze_device_handle_t hDevice,
|
||||
const ze_device_mem_alloc_desc_t *deviceDesc,
|
||||
size_t size,
|
||||
size_t alignment, void **ptr) override {
|
||||
ze_result_t res = L0::ContextImp::allocDeviceMem(hDevice, deviceDesc, size, alignment, ptr);
|
||||
if (ZE_RESULT_SUCCESS == res) {
|
||||
driverHandle->allocationMap.first = *ptr;
|
||||
driverHandle->allocationMap.second = driverHandle->mockHandle;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
ze_result_t getMemAllocProperties(const void *ptr,
|
||||
ze_memory_allocation_properties_t *pMemAllocProperties,
|
||||
ze_device_handle_t *phDevice) override {
|
||||
ze_result_t res = ContextImp::getMemAllocProperties(ptr, pMemAllocProperties, phDevice);
|
||||
if (ZE_RESULT_SUCCESS == res && pMemAllocProperties->pNext) {
|
||||
_ze_external_memory_export_win32_handle_t *extendedMemoryExportProperties =
|
||||
reinterpret_cast<_ze_external_memory_export_win32_handle_t *>(pMemAllocProperties->pNext);
|
||||
extendedMemoryExportProperties->handle = reinterpret_cast<void *>(reinterpret_cast<uintptr_t *>(driverHandle->mockHandle));
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
DriverHandleGetWinHandleMock *driverHandle = nullptr;
|
||||
};
|
||||
|
||||
struct MemoryExportImportWinHandleTest : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
NEO::MockCompilerEnableGuard mock(true);
|
||||
neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get());
|
||||
auto mockBuiltIns = new MockBuiltins();
|
||||
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns);
|
||||
NEO::DeviceVector devices;
|
||||
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
|
||||
driverHandle = std::make_unique<DriverHandleGetWinHandleMock>();
|
||||
driverHandle->initialize(std::move(devices));
|
||||
device = driverHandle->devices[0];
|
||||
|
||||
context = std::make_unique<ContextHandleMock>(driverHandle.get());
|
||||
EXPECT_NE(context, nullptr);
|
||||
context->getDevices().insert(std::make_pair(device->toHandle(), device));
|
||||
auto neoDevice = device->getNEODevice();
|
||||
context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
|
||||
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
}
|
||||
std::unique_ptr<DriverHandleGetWinHandleMock> driverHandle;
|
||||
NEO::MockDevice *neoDevice = nullptr;
|
||||
L0::Device *device = nullptr;
|
||||
ze_context_handle_t hContext;
|
||||
std::unique_ptr<ContextHandleMock> context;
|
||||
};
|
||||
|
||||
TEST_F(MemoryExportImportWinHandleTest,
|
||||
givenCallToDeviceAllocWithExtendedExportDescriptorAndNTHandleFlagThenAllocationIsMade) {
|
||||
size_t size = 10;
|
||||
@@ -1666,337 +1515,6 @@ TEST_F(MemoryExportImportWinHandleTest,
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
using MemoryIPCTests = MemoryExportImportTest;
|
||||
|
||||
TEST_F(MemoryIPCTests,
|
||||
givenCallToGetIpcHandleWithNotKnownPointerThenInvalidArgumentIsReturned) {
|
||||
|
||||
uint32_t value = 0;
|
||||
|
||||
ze_ipc_mem_handle_t ipcHandle;
|
||||
ze_result_t result = context->getIpcMemHandle(&value, &ipcHandle);
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result);
|
||||
}
|
||||
|
||||
TEST_F(MemoryIPCTests,
|
||||
givenCallToGetIpcHandleWithDeviceAllocationThenIpcHandleIsReturned) {
|
||||
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);
|
||||
|
||||
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(MemoryIPCTests,
|
||||
whenCallingOpenIpcHandleWithIpcHandleThenDeviceAllocationIsReturned) {
|
||||
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);
|
||||
|
||||
ze_ipc_mem_handle_t ipcHandle = {};
|
||||
result = context->getIpcMemHandle(ptr, &ipcHandle);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
ze_ipc_memory_flags_t flags = {};
|
||||
void *ipcPtr;
|
||||
result = context->openIpcMemHandle(device->toHandle(), ipcHandle, flags, &ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_EQ(ipcPtr, ptr);
|
||||
|
||||
result = context->closeIpcMemHandle(ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
result = context->freeMem(ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
TEST_F(MemoryIPCTests,
|
||||
whenCallingOpenIpcHandleWithIpcHandleAndUsingContextThenDeviceAllocationIsReturned) {
|
||||
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);
|
||||
|
||||
ze_ipc_mem_handle_t ipcHandle = {};
|
||||
result = context->getIpcMemHandle(ptr, &ipcHandle);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
ze_ipc_memory_flags_t flags = {};
|
||||
void *ipcPtr;
|
||||
result = context->openIpcMemHandle(device->toHandle(), ipcHandle, flags, &ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_EQ(ipcPtr, ptr);
|
||||
|
||||
result = context->closeIpcMemHandle(ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
result = context->freeMem(ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
TEST_F(MemoryIPCTests,
|
||||
givenCallingGetIpcHandleWithDeviceAllocationAndUsingContextThenIpcHandleIsReturned) {
|
||||
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);
|
||||
|
||||
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(MemoryIPCTests,
|
||||
whenCallingOpenIpcHandleWithIncorrectHandleThenInvalidArgumentIsReturned) {
|
||||
ze_ipc_mem_handle_t ipcHandle = {};
|
||||
ze_ipc_memory_flags_t flags = {};
|
||||
void *ipcPtr;
|
||||
ze_result_t res = context->openIpcMemHandle(device->toHandle(), ipcHandle, flags, &ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, res);
|
||||
}
|
||||
|
||||
struct DriverHandleGetIpcHandleMock : public DriverHandleImp {
|
||||
void *importFdHandle(ze_device_handle_t hDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::GraphicsAllocation **pAlloc) override {
|
||||
EXPECT_EQ(handle, static_cast<uint64_t>(mockFd));
|
||||
if (mockFd == allocationMap.second) {
|
||||
return allocationMap.first;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const int mockFd = 999;
|
||||
std::pair<void *, int> allocationMap;
|
||||
};
|
||||
|
||||
struct ContextGetIpcHandleMock : public L0::ContextImp {
|
||||
ContextGetIpcHandleMock(DriverHandleGetIpcHandleMock *inDriverHandle) : L0::ContextImp(static_cast<L0::DriverHandle *>(inDriverHandle)) {
|
||||
driverHandle = inDriverHandle;
|
||||
}
|
||||
ze_result_t allocDeviceMem(ze_device_handle_t hDevice,
|
||||
const ze_device_mem_alloc_desc_t *deviceDesc,
|
||||
size_t size,
|
||||
size_t alignment, void **ptr) override {
|
||||
ze_result_t res = L0::ContextImp::allocDeviceMem(hDevice, deviceDesc, size, alignment, ptr);
|
||||
if (ZE_RESULT_SUCCESS == res) {
|
||||
driverHandle->allocationMap.first = *ptr;
|
||||
driverHandle->allocationMap.second = driverHandle->mockFd;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
ze_result_t getIpcMemHandle(const void *ptr, ze_ipc_mem_handle_t *pIpcHandle) override {
|
||||
uint64_t handle = driverHandle->mockFd;
|
||||
memcpy_s(reinterpret_cast<void *>(pIpcHandle->data),
|
||||
sizeof(ze_ipc_mem_handle_t),
|
||||
&handle,
|
||||
sizeof(handle));
|
||||
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
DriverHandleGetIpcHandleMock *driverHandle = nullptr;
|
||||
};
|
||||
|
||||
struct MemoryGetIpcHandleTest : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
NEO::MockCompilerEnableGuard mock(true);
|
||||
neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get());
|
||||
auto mockBuiltIns = new MockBuiltins();
|
||||
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns);
|
||||
NEO::DeviceVector devices;
|
||||
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
|
||||
driverHandle = std::make_unique<DriverHandleGetIpcHandleMock>();
|
||||
driverHandle->initialize(std::move(devices));
|
||||
device = driverHandle->devices[0];
|
||||
|
||||
context = std::make_unique<ContextGetIpcHandleMock>(driverHandle.get());
|
||||
EXPECT_NE(context, nullptr);
|
||||
context->getDevices().insert(std::make_pair(device->toHandle(), device));
|
||||
auto neoDevice = device->getNEODevice();
|
||||
context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
|
||||
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
}
|
||||
|
||||
std::unique_ptr<DriverHandleGetIpcHandleMock> driverHandle;
|
||||
NEO::MockDevice *neoDevice = nullptr;
|
||||
L0::Device *device = nullptr;
|
||||
std::unique_ptr<ContextGetIpcHandleMock> context;
|
||||
};
|
||||
|
||||
TEST_F(MemoryGetIpcHandleTest,
|
||||
whenCallingOpenIpcHandleWithIpcHandleThenFdHandleIsCorrectlyRead) {
|
||||
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);
|
||||
|
||||
ze_ipc_mem_handle_t ipcHandle = {};
|
||||
result = context->getIpcMemHandle(ptr, &ipcHandle);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
ze_ipc_memory_flags_t flags = {};
|
||||
void *ipcPtr;
|
||||
result = context->openIpcMemHandle(device->toHandle(), ipcHandle, flags, &ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_EQ(ipcPtr, ptr);
|
||||
|
||||
result = context->freeMem(ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
class MemoryManagerIpcMock : public NEO::MemoryManager {
|
||||
public:
|
||||
MemoryManagerIpcMock(NEO::ExecutionEnvironment &executionEnvironment) : NEO::MemoryManager(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, GraphicsAllocation::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{};
|
||||
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{};
|
||||
};
|
||||
|
||||
class MemoryManagerOpenIpcMock : public MemoryManagerIpcMock {
|
||||
public:
|
||||
MemoryManagerOpenIpcMock(NEO::ExecutionEnvironment &executionEnvironment) : MemoryManagerIpcMock(executionEnvironment) {}
|
||||
NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override {
|
||||
if (failOnCreateGraphicsAllocationFromSharedHandle) {
|
||||
return nullptr;
|
||||
}
|
||||
auto alloc = new NEO::MockGraphicsAllocation(0,
|
||||
NEO::GraphicsAllocation::AllocationType::BUFFER,
|
||||
reinterpret_cast<void *>(sharedHandleAddress++),
|
||||
0x1000,
|
||||
0,
|
||||
sizeof(uint32_t),
|
||||
MemoryPool::System4KBPages);
|
||||
alloc->setGpuBaseAddress(0xabcd);
|
||||
return alloc;
|
||||
}
|
||||
|
||||
uint64_t sharedHandleAddress = 0x1234;
|
||||
|
||||
bool failOnCreateGraphicsAllocationFromSharedHandle = false;
|
||||
};
|
||||
|
||||
struct ContextIpcMock : public L0::ContextImp {
|
||||
ContextIpcMock(DriverHandleImp *inDriverHandle) : L0::ContextImp(static_cast<L0::DriverHandle *>(inDriverHandle)) {
|
||||
driverHandle = inDriverHandle;
|
||||
}
|
||||
|
||||
ze_result_t getIpcMemHandle(const void *ptr, ze_ipc_mem_handle_t *pIpcHandle) override {
|
||||
uint64_t handle = mockFd;
|
||||
memcpy_s(reinterpret_cast<void *>(pIpcHandle->data),
|
||||
sizeof(ze_ipc_mem_handle_t),
|
||||
&handle,
|
||||
sizeof(handle));
|
||||
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
const int mockFd = 999;
|
||||
};
|
||||
|
||||
struct MemoryOpenIpcHandleTest : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
NEO::MockCompilerEnableGuard mock(true);
|
||||
neoDevice =
|
||||
NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get());
|
||||
auto mockBuiltIns = new MockBuiltins();
|
||||
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns);
|
||||
NEO::DeviceVector devices;
|
||||
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
|
||||
driverHandle = std::make_unique<DriverHandleImp>();
|
||||
driverHandle->initialize(std::move(devices));
|
||||
prevMemoryManager = driverHandle->getMemoryManager();
|
||||
currMemoryManager = new MemoryManagerOpenIpcMock(*neoDevice->executionEnvironment);
|
||||
driverHandle->setMemoryManager(currMemoryManager);
|
||||
device = driverHandle->devices[0];
|
||||
|
||||
context = std::make_unique<ContextIpcMock>(driverHandle.get());
|
||||
EXPECT_NE(context, nullptr);
|
||||
context->getDevices().insert(std::make_pair(device->toHandle(), device));
|
||||
auto neoDevice = device->getNEODevice();
|
||||
context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
|
||||
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
driverHandle->setMemoryManager(prevMemoryManager);
|
||||
delete currMemoryManager;
|
||||
}
|
||||
NEO::MemoryManager *prevMemoryManager = nullptr;
|
||||
NEO::MemoryManager *currMemoryManager = nullptr;
|
||||
std::unique_ptr<DriverHandleImp> driverHandle;
|
||||
NEO::MockDevice *neoDevice = nullptr;
|
||||
L0::Device *device = nullptr;
|
||||
std::unique_ptr<ContextIpcMock> context;
|
||||
};
|
||||
|
||||
struct MultipleDevicePeerAllocationFailTest : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
NEO::MockCompilerEnableGuard mock(true);
|
||||
@@ -2017,7 +1535,7 @@ struct MultipleDevicePeerAllocationFailTest : public ::testing::Test {
|
||||
driverHandle->initialize(std::move(devices));
|
||||
driverHandle->setMemoryManager(driverHandle->getMemoryManager());
|
||||
|
||||
context = std::make_unique<ContextImp>(driverHandle.get());
|
||||
context = std::make_unique<ContextShareableMock>(driverHandle.get());
|
||||
EXPECT_NE(context, nullptr);
|
||||
for (auto i = 0u; i < numRootDevices; i++) {
|
||||
auto device = driverHandle->devices[i];
|
||||
@@ -2031,7 +1549,7 @@ struct MultipleDevicePeerAllocationFailTest : public ::testing::Test {
|
||||
DebugManagerStateRestore restorer;
|
||||
std::unique_ptr<DriverHandleFailGetFdMock> driverHandle;
|
||||
std::unique_ptr<UltDeviceFactory> deviceFactory;
|
||||
std::unique_ptr<ContextImp> context;
|
||||
std::unique_ptr<ContextShareableMock> context;
|
||||
|
||||
const uint32_t numRootDevices = 2u;
|
||||
};
|
||||
@@ -2110,7 +1628,7 @@ struct MultipleDevicePeerAllocationTest : public ::testing::Test {
|
||||
currMemoryManager = new MemoryManagerOpenIpcMock(*executionEnvironment);
|
||||
driverHandle->setMemoryManager(currMemoryManager);
|
||||
|
||||
context = std::make_unique<ContextImp>(driverHandle.get());
|
||||
context = std::make_unique<ContextShareableMock>(driverHandle.get());
|
||||
EXPECT_NE(context, nullptr);
|
||||
for (auto i = 0u; i < numRootDevices; i++) {
|
||||
auto device = driverHandle->devices[i];
|
||||
@@ -2141,7 +1659,7 @@ struct MultipleDevicePeerAllocationTest : public ::testing::Test {
|
||||
std::unique_ptr<DriverHandleImp> driverHandle;
|
||||
|
||||
std::unique_ptr<UltDeviceFactory> deviceFactory;
|
||||
std::unique_ptr<ContextImp> context;
|
||||
std::unique_ptr<ContextShareableMock> context;
|
||||
|
||||
const std::string binaryFilename = "test_kernel";
|
||||
const std::string kernelName = "test";
|
||||
@@ -2624,36 +2142,6 @@ TEST_F(MultipleDevicePeerAllocationTest,
|
||||
ASSERT_EQ(result, ZE_RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
TEST_F(MemoryOpenIpcHandleTest,
|
||||
givenCallToOpenIpcMemHandleItIsSuccessfullyOpenedAndClosed) {
|
||||
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);
|
||||
|
||||
ze_ipc_mem_handle_t ipcHandle = {};
|
||||
result = context->getIpcMemHandle(ptr, &ipcHandle);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
ze_ipc_memory_flags_t flags = {};
|
||||
void *ipcPtr;
|
||||
result = context->openIpcMemHandle(device->toHandle(), ipcHandle, flags, &ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_NE(ipcPtr, nullptr);
|
||||
|
||||
result = context->closeIpcMemHandle(ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
result = context->freeMem(ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
struct MemoryFailedOpenIpcHandleTest : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
NEO::MockCompilerEnableGuard mock(true);
|
||||
@@ -2904,7 +2392,7 @@ TEST_F(MemoryTest, givenCallToCheckMemoryAccessFromDeviceWithValidHostAllocation
|
||||
struct MemoryBitfieldTest : testing::Test {
|
||||
void SetUp() override {
|
||||
NEO::MockCompilerEnableGuard mock(true);
|
||||
auto executionEnvironment = new NEO::ExecutionEnvironment();
|
||||
executionEnvironment = new NEO::ExecutionEnvironment();
|
||||
executionEnvironment->prepareRootDeviceEnvironments(1);
|
||||
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
|
||||
memoryManager = new NEO::MockMemoryManager(*executionEnvironment);
|
||||
@@ -2941,6 +2429,7 @@ struct MemoryBitfieldTest : testing::Test {
|
||||
size_t alignment = 1u;
|
||||
void *ptr = nullptr;
|
||||
std::unique_ptr<ContextImp> context;
|
||||
NEO::ExecutionEnvironment *executionEnvironment;
|
||||
};
|
||||
|
||||
TEST_F(MemoryBitfieldTest, givenDeviceWithValidBitfieldWhenAllocatingDeviceMemoryThenPassProperBitfield) {
|
||||
@@ -3430,6 +2919,9 @@ struct ContextMultiDeviceMock : public L0::ContextImp {
|
||||
alignedFree(const_cast<void *>(ptr));
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
bool isShareableMemory(const void *pNext, bool exportableMemory, NEO::Device *neoDevice) override {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
struct SharedAllocMultiDeviceTests : public ::testing::Test {
|
||||
|
||||
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
using MemoryIPCTests = MemoryExportImportTest;
|
||||
|
||||
TEST_F(MemoryIPCTests,
|
||||
givenCallToGetIpcHandleWithNotKnownPointerThenInvalidArgumentIsReturned) {
|
||||
|
||||
uint32_t value = 0;
|
||||
|
||||
ze_ipc_mem_handle_t ipcHandle;
|
||||
ze_result_t result = context->getIpcMemHandle(&value, &ipcHandle);
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result);
|
||||
}
|
||||
|
||||
TEST_F(MemoryIPCTests,
|
||||
givenCallToGetIpcHandleWithDeviceAllocationThenIpcHandleIsReturned) {
|
||||
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);
|
||||
|
||||
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(MemoryIPCTests,
|
||||
whenCallingOpenIpcHandleWithIpcHandleThenDeviceAllocationIsReturned) {
|
||||
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);
|
||||
|
||||
ze_ipc_mem_handle_t ipcHandle = {};
|
||||
result = context->getIpcMemHandle(ptr, &ipcHandle);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
ze_ipc_memory_flags_t flags = {};
|
||||
void *ipcPtr;
|
||||
result = context->openIpcMemHandle(device->toHandle(), ipcHandle, flags, &ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_EQ(ipcPtr, ptr);
|
||||
|
||||
result = context->closeIpcMemHandle(ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
result = context->freeMem(ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
TEST_F(MemoryIPCTests,
|
||||
whenCallingOpenIpcHandleWithIpcHandleAndUsingContextThenDeviceAllocationIsReturned) {
|
||||
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);
|
||||
|
||||
ze_ipc_mem_handle_t ipcHandle = {};
|
||||
result = context->getIpcMemHandle(ptr, &ipcHandle);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
ze_ipc_memory_flags_t flags = {};
|
||||
void *ipcPtr;
|
||||
result = context->openIpcMemHandle(device->toHandle(), ipcHandle, flags, &ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_EQ(ipcPtr, ptr);
|
||||
|
||||
result = context->closeIpcMemHandle(ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
result = context->freeMem(ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
TEST_F(MemoryIPCTests,
|
||||
givenCallingGetIpcHandleWithDeviceAllocationAndUsingContextThenIpcHandleIsReturned) {
|
||||
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);
|
||||
|
||||
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(MemoryIPCTests,
|
||||
whenCallingOpenIpcHandleWithIncorrectHandleThenInvalidArgumentIsReturned) {
|
||||
ze_ipc_mem_handle_t ipcHandle = {};
|
||||
ze_ipc_memory_flags_t flags = {};
|
||||
void *ipcPtr;
|
||||
ze_result_t res = context->openIpcMemHandle(device->toHandle(), ipcHandle, flags, &ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, res);
|
||||
}
|
||||
|
||||
struct MemoryGetIpcHandleTest : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
NEO::MockCompilerEnableGuard mock(true);
|
||||
neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get());
|
||||
auto mockBuiltIns = new MockBuiltins();
|
||||
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns);
|
||||
NEO::DeviceVector devices;
|
||||
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
|
||||
driverHandle = std::make_unique<DriverHandleGetIpcHandleMock>();
|
||||
driverHandle->initialize(std::move(devices));
|
||||
device = driverHandle->devices[0];
|
||||
|
||||
context = std::make_unique<ContextGetIpcHandleMock>(driverHandle.get());
|
||||
EXPECT_NE(context, nullptr);
|
||||
context->getDevices().insert(std::make_pair(device->toHandle(), device));
|
||||
auto neoDevice = device->getNEODevice();
|
||||
context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
|
||||
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
}
|
||||
|
||||
std::unique_ptr<DriverHandleGetIpcHandleMock> driverHandle;
|
||||
NEO::MockDevice *neoDevice = nullptr;
|
||||
L0::Device *device = nullptr;
|
||||
std::unique_ptr<ContextGetIpcHandleMock> context;
|
||||
};
|
||||
|
||||
TEST_F(MemoryGetIpcHandleTest,
|
||||
whenCallingOpenIpcHandleWithIpcHandleThenFdHandleIsCorrectlyRead) {
|
||||
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);
|
||||
|
||||
ze_ipc_mem_handle_t ipcHandle = {};
|
||||
result = context->getIpcMemHandle(ptr, &ipcHandle);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
ze_ipc_memory_flags_t flags = {};
|
||||
void *ipcPtr;
|
||||
result = context->openIpcMemHandle(device->toHandle(), ipcHandle, flags, &ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_EQ(ipcPtr, ptr);
|
||||
|
||||
result = context->freeMem(ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
TEST_F(MemoryOpenIpcHandleTest,
|
||||
givenCallToOpenIpcMemHandleItIsSuccessfullyOpenedAndClosed) {
|
||||
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);
|
||||
|
||||
ze_ipc_mem_handle_t ipcHandle = {};
|
||||
result = context->getIpcMemHandle(ptr, &ipcHandle);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
ze_ipc_memory_flags_t flags = {};
|
||||
void *ipcPtr;
|
||||
result = context->openIpcMemHandle(device->toHandle(), ipcHandle, flags, &ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_NE(ipcPtr, nullptr);
|
||||
|
||||
result = context->closeIpcMemHandle(ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
result = context->freeMem(ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
using MemoryIPCTests = MemoryExportImportTest;
|
||||
|
||||
TEST_F(MemoryIPCTests,
|
||||
givenCallToGetIpcHandleWithNotKnownPointerThenInvalidArgumentIsReturned) {
|
||||
|
||||
uint32_t value = 0;
|
||||
|
||||
ze_ipc_mem_handle_t ipcHandle;
|
||||
ze_result_t result = context->getIpcMemHandle(&value, &ipcHandle);
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result);
|
||||
}
|
||||
|
||||
TEST_F(MemoryIPCTests,
|
||||
givenCallToGetIpcHandleWithDeviceAllocationThenIpcHandleIsReturned) {
|
||||
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);
|
||||
|
||||
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(MemoryIPCTests,
|
||||
whenCallingOpenIpcHandleWithIpcHandleThenDeviceAllocationIsReturned) {
|
||||
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);
|
||||
|
||||
ze_ipc_mem_handle_t ipcHandle = {};
|
||||
result = context->getIpcMemHandle(ptr, &ipcHandle);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
ze_ipc_memory_flags_t flags = {};
|
||||
void *ipcPtr;
|
||||
result = context->openIpcMemHandle(device->toHandle(), ipcHandle, flags, &ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_EQ(ipcPtr, ptr);
|
||||
|
||||
result = context->closeIpcMemHandle(ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
result = context->freeMem(ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
TEST_F(MemoryIPCTests,
|
||||
whenCallingOpenIpcHandleWithIpcHandleAndUsingContextThenDeviceAllocationIsReturned) {
|
||||
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);
|
||||
|
||||
ze_ipc_mem_handle_t ipcHandle = {};
|
||||
result = context->getIpcMemHandle(ptr, &ipcHandle);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
ze_ipc_memory_flags_t flags = {};
|
||||
void *ipcPtr;
|
||||
result = context->openIpcMemHandle(device->toHandle(), ipcHandle, flags, &ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_EQ(ipcPtr, ptr);
|
||||
|
||||
result = context->closeIpcMemHandle(ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
result = context->freeMem(ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
TEST_F(MemoryIPCTests,
|
||||
givenCallingGetIpcHandleWithDeviceAllocationAndUsingContextThenIpcHandleIsReturned) {
|
||||
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);
|
||||
|
||||
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(MemoryIPCTests,
|
||||
whenCallingOpenIpcHandleWithIncorrectHandleThenInvalidArgumentIsReturned) {
|
||||
ze_ipc_mem_handle_t ipcHandle = {};
|
||||
ze_ipc_memory_flags_t flags = {};
|
||||
void *ipcPtr;
|
||||
ze_result_t res = context->openIpcMemHandle(device->toHandle(), ipcHandle, flags, &ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, res);
|
||||
}
|
||||
|
||||
struct MemoryGetIpcHandleTest : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
NEO::MockCompilerEnableGuard mock(true);
|
||||
neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get());
|
||||
auto mockBuiltIns = new MockBuiltins();
|
||||
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns);
|
||||
NEO::DeviceVector devices;
|
||||
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
|
||||
driverHandle = std::make_unique<DriverHandleGetIpcHandleMock>();
|
||||
driverHandle->initialize(std::move(devices));
|
||||
device = driverHandle->devices[0];
|
||||
|
||||
context = std::make_unique<ContextGetIpcHandleMock>(driverHandle.get());
|
||||
EXPECT_NE(context, nullptr);
|
||||
context->getDevices().insert(std::make_pair(device->toHandle(), device));
|
||||
auto neoDevice = device->getNEODevice();
|
||||
context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
|
||||
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
}
|
||||
|
||||
std::unique_ptr<DriverHandleGetIpcHandleMock> driverHandle;
|
||||
NEO::MockDevice *neoDevice = nullptr;
|
||||
L0::Device *device = nullptr;
|
||||
std::unique_ptr<ContextGetIpcHandleMock> context;
|
||||
};
|
||||
|
||||
TEST_F(MemoryGetIpcHandleTest,
|
||||
whenCallingOpenIpcHandleWithIpcHandleThenFdHandleIsCorrectlyRead) {
|
||||
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);
|
||||
|
||||
ze_ipc_mem_handle_t ipcHandle = {};
|
||||
result = context->getIpcMemHandle(ptr, &ipcHandle);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
ze_ipc_memory_flags_t flags = {};
|
||||
void *ipcPtr;
|
||||
result = context->openIpcMemHandle(device->toHandle(), ipcHandle, flags, &ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_EQ(ipcPtr, ptr);
|
||||
|
||||
result = context->freeMem(ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
TEST_F(MemoryOpenIpcHandleTest,
|
||||
givenCallToOpenIpcMemHandleItIsSuccessfullyOpenedAndClosed) {
|
||||
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);
|
||||
|
||||
ze_ipc_mem_handle_t ipcHandle = {};
|
||||
result = context->getIpcMemHandle(ptr, &ipcHandle);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
ze_ipc_memory_flags_t flags = {};
|
||||
void *ipcPtr;
|
||||
result = context->openIpcMemHandle(device->toHandle(), ipcHandle, flags, &ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_NE(ipcPtr, nullptr);
|
||||
|
||||
result = context->closeIpcMemHandle(ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
result = context->freeMem(ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
using MemoryIPCTests = MemoryExportImportWinHandleTest;
|
||||
|
||||
TEST_F(MemoryIPCTests,
|
||||
givenCallToGetIpcHandleWithNotKnownPointerThenInvalidArgumentIsReturned) {
|
||||
|
||||
uint32_t value = 0;
|
||||
|
||||
ze_ipc_mem_handle_t ipcHandle;
|
||||
ze_result_t result = context->getIpcMemHandle(&value, &ipcHandle);
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result);
|
||||
}
|
||||
|
||||
TEST_F(MemoryIPCTests,
|
||||
givenCallToGetIpcHandleWithDeviceAllocationThenIpcHandleIsReturned) {
|
||||
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);
|
||||
|
||||
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(MemoryIPCTests,
|
||||
whenCallingOpenIpcHandleWithIpcHandleThenDeviceAllocationIsReturned) {
|
||||
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);
|
||||
|
||||
ze_ipc_mem_handle_t ipcHandle = {};
|
||||
result = context->getIpcMemHandle(ptr, &ipcHandle);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
ze_ipc_memory_flags_t flags = {};
|
||||
void *ipcPtr;
|
||||
result = context->openIpcMemHandle(device->toHandle(), ipcHandle, flags, &ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_EQ(ipcPtr, ptr);
|
||||
|
||||
result = context->closeIpcMemHandle(ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
result = context->freeMem(ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
TEST_F(MemoryIPCTests,
|
||||
whenCallingOpenIpcHandleWithIpcHandleAndUsingContextThenDeviceAllocationIsReturned) {
|
||||
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);
|
||||
|
||||
ze_ipc_mem_handle_t ipcHandle = {};
|
||||
result = context->getIpcMemHandle(ptr, &ipcHandle);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
ze_ipc_memory_flags_t flags = {};
|
||||
void *ipcPtr;
|
||||
result = context->openIpcMemHandle(device->toHandle(), ipcHandle, flags, &ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_EQ(ipcPtr, ptr);
|
||||
|
||||
result = context->closeIpcMemHandle(ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
result = context->freeMem(ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
TEST_F(MemoryIPCTests,
|
||||
givenCallingGetIpcHandleWithDeviceAllocationAndUsingContextThenIpcHandleIsReturned) {
|
||||
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);
|
||||
|
||||
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(MemoryIPCTests,
|
||||
whenCallingOpenIpcHandleWithIncorrectHandleThenInvalidArgumentIsReturned) {
|
||||
ze_ipc_mem_handle_t ipcHandle = {};
|
||||
ze_ipc_memory_flags_t flags = {};
|
||||
void *ipcPtr;
|
||||
ze_result_t res = context->openIpcMemHandle(device->toHandle(), ipcHandle, flags, &ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, res);
|
||||
}
|
||||
|
||||
struct MemoryGetIpcHandleTest : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
NEO::MockCompilerEnableGuard mock(true);
|
||||
neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get());
|
||||
auto mockBuiltIns = new MockBuiltins();
|
||||
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns);
|
||||
NEO::DeviceVector devices;
|
||||
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
|
||||
driverHandle = std::make_unique<DriverHandleGetWinHandleMock>();
|
||||
driverHandle->initialize(std::move(devices));
|
||||
device = driverHandle->devices[0];
|
||||
|
||||
context = std::make_unique<ContextHandleMock>(driverHandle.get());
|
||||
EXPECT_NE(context, nullptr);
|
||||
context->getDevices().insert(std::make_pair(device->toHandle(), device));
|
||||
auto neoDevice = device->getNEODevice();
|
||||
context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
|
||||
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
}
|
||||
|
||||
std::unique_ptr<DriverHandleGetWinHandleMock> driverHandle;
|
||||
NEO::MockDevice *neoDevice = nullptr;
|
||||
L0::Device *device = nullptr;
|
||||
std::unique_ptr<ContextHandleMock> context;
|
||||
};
|
||||
|
||||
TEST_F(MemoryGetIpcHandleTest,
|
||||
whenCallingOpenIpcHandleWithIpcHandleThenFdHandleIsCorrectlyRead) {
|
||||
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);
|
||||
|
||||
ze_ipc_mem_handle_t ipcHandle = {};
|
||||
result = context->getIpcMemHandle(ptr, &ipcHandle);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
ze_ipc_memory_flags_t flags = {};
|
||||
void *ipcPtr;
|
||||
result = context->openIpcMemHandle(device->toHandle(), ipcHandle, flags, &ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_EQ(ipcPtr, ptr);
|
||||
|
||||
result = context->freeMem(ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
TEST_F(MemoryOpenIpcHandleTest,
|
||||
givenCallToOpenIpcMemHandleItIsSuccessfullyOpenedAndClosed) {
|
||||
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);
|
||||
|
||||
ze_ipc_mem_handle_t ipcHandle = {};
|
||||
result = context->getIpcMemHandle(ptr, &ipcHandle);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
ze_ipc_memory_flags_t flags = {};
|
||||
void *ipcPtr;
|
||||
result = context->openIpcMemHandle(device->toHandle(), ipcHandle, flags, &ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_NE(ipcPtr, nullptr);
|
||||
|
||||
result = context->closeIpcMemHandle(ipcPtr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
result = context->freeMem(ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
@@ -1659,6 +1659,13 @@ TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWhenVerifyHandleThenRe
|
||||
EXPECT_TRUE(memoryManager.verifyHandle(testOSHandle, 0, 0));
|
||||
}
|
||||
|
||||
TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWhenisNTHandleThenReturnFalse) {
|
||||
MockExecutionEnvironment executionEnvironment;
|
||||
OsAgnosticMemoryManager memoryManager(executionEnvironment);
|
||||
osHandle testOSHandle = 1;
|
||||
EXPECT_FALSE(memoryManager.isNTHandle(testOSHandle, 0));
|
||||
}
|
||||
|
||||
TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenGpuAddressIsSetThenAllocationWithSpecifiedGpuAddressInSystemMemoryIsCreated) {
|
||||
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
|
||||
auto memoryManager = new OsAgnosticMemoryManager(executionEnvironment);
|
||||
|
||||
@@ -1618,6 +1618,15 @@ TEST_F(MockWddmMemoryManagerTest, givenWddmMemoryManagerWhenVerifyNTHandleThenVe
|
||||
EXPECT_EQ(0, wddm->counterVerifySharedHandle);
|
||||
}
|
||||
|
||||
TEST_F(MockWddmMemoryManagerTest, givenWddmMemoryManagerWhenIsNTHandleisCalledThenVerifyNTHandleisCalled) {
|
||||
wddm->init();
|
||||
MockWddmMemoryManager memoryManager(*executionEnvironment);
|
||||
osHandle handle = 1;
|
||||
memoryManager.isNTHandle(handle, 0);
|
||||
EXPECT_EQ(1, wddm->counterVerifyNTHandle);
|
||||
EXPECT_EQ(0, wddm->counterVerifySharedHandle);
|
||||
}
|
||||
|
||||
TEST_F(MockWddmMemoryManagerTest, givenEnabled64kbpagesWhenCreatingGraphicsMemoryForBufferWithoutHostPtrThen64kbAdressIsAllocated) {
|
||||
DebugManagerStateRestore dbgRestore;
|
||||
wddm->init();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2021 Intel Corporation
|
||||
* Copyright (C) 2018-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
||||
@@ -91,6 +91,7 @@ class MemoryManager {
|
||||
MOCKABLE_VIRTUAL GraphicsAllocation *allocateGraphicsMemoryInPreferredPool(const AllocationProperties &properties, const void *hostPtr);
|
||||
|
||||
virtual bool verifyHandle(osHandle handle, uint32_t rootDeviceIndex, bool) { return true; }
|
||||
virtual bool isNTHandle(osHandle handle, uint32_t rootDeviceIndex) { return false; }
|
||||
virtual GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) = 0;
|
||||
virtual void closeSharedHandle(GraphicsAllocation *graphicsAllocation){};
|
||||
virtual GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, GraphicsAllocation::AllocationType allocType) = 0;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2021 Intel Corporation
|
||||
* Copyright (C) 2018-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Intel Corporation
|
||||
* Copyright (C) 2021-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2021 Intel Corporation
|
||||
* Copyright (C) 2018-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
||||
@@ -390,6 +390,11 @@ bool WddmMemoryManager::verifyHandle(osHandle handle, uint32_t rootDeviceIndex,
|
||||
return status;
|
||||
}
|
||||
|
||||
bool WddmMemoryManager::isNTHandle(osHandle handle, uint32_t rootDeviceIndex) {
|
||||
bool status = getWddm(rootDeviceIndex).verifyNTHandle(reinterpret_cast<HANDLE>(static_cast<uintptr_t>(handle)));
|
||||
return status;
|
||||
}
|
||||
|
||||
GraphicsAllocation *WddmMemoryManager::createAllocationFromHandle(osHandle handle, bool requireSpecificBitness, bool ntHandle, GraphicsAllocation::AllocationType allocationType, uint32_t rootDeviceIndex) {
|
||||
auto allocation = std::make_unique<WddmAllocation>(rootDeviceIndex, allocationType, nullptr, 0, handle, MemoryPool::SystemCpuInaccessible, maxOsContextCount);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2021 Intel Corporation
|
||||
* Copyright (C) 2018-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -73,6 +73,7 @@ class WddmMemoryManager : public MemoryManager {
|
||||
AddressRange reserveGpuAddress(size_t size, uint32_t rootDeviceIndex) override { return AddressRange{0, 0}; };
|
||||
void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override{};
|
||||
bool verifyHandle(osHandle handle, uint32_t rootDeviceIndex, bool ntHandle) override;
|
||||
bool isNTHandle(osHandle handle, uint32_t rootDeviceIndex) override;
|
||||
void releaseDeviceSpecificMemResources(uint32_t rootDeviceIndex) override{};
|
||||
void createDeviceSpecificMemResources(uint32_t rootDeviceIndex) override{};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user