Move SVM allocs memory manager to L0::Context (1/N)

Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
This commit is contained in:
Jaime Arteaga
2021-05-04 02:58:32 +00:00
committed by Compute-Runtime-Automation
parent 47256642c3
commit 9080e2ee5b
36 changed files with 559 additions and 459 deletions

View File

@@ -128,6 +128,10 @@ struct Context : _ze_context_handle_t {
virtual ze_result_t createImage(ze_device_handle_t hDevice, virtual ze_result_t createImage(ze_device_handle_t hDevice,
const ze_image_desc_t *desc, const ze_image_desc_t *desc,
ze_image_handle_t *phImage) = 0; ze_image_handle_t *phImage) = 0;
virtual NEO::MemoryManager *getMemoryManager() = 0;
virtual void setMemoryManager(NEO::MemoryManager *memoryManager) = 0;
virtual NEO::SVMAllocsManager *getSvmAllocsManager() = 0;
virtual void setSvmAllocsManager(NEO::SVMAllocsManager *) = 0;
static Context *fromHandle(ze_context_handle_t handle) { return static_cast<Context *>(handle); } static Context *fromHandle(ze_context_handle_t handle) { return static_cast<Context *>(handle); }
inline ze_context_handle_t toHandle() { return this; } inline ze_context_handle_t toHandle() { return this; }

View File

@@ -18,6 +18,15 @@
namespace L0 { namespace L0 {
ze_result_t ContextImp::destroy() { ze_result_t ContextImp::destroy() {
if (this->svmAllocsManager) {
delete this->svmAllocsManager;
this->svmAllocsManager = nullptr;
}
if (this->driverHandle->mainContext == this) {
this->driverHandle->mainContext = nullptr;
}
delete this; delete this;
return ZE_RESULT_SUCCESS; return ZE_RESULT_SUCCESS;
@@ -78,8 +87,8 @@ ze_result_t ContextImp::allocHostMem(const ze_host_mem_alloc_desc_t *hostDesc,
this->rootDeviceIndices, this->rootDeviceIndices,
this->deviceBitfields); this->deviceBitfields);
auto usmPtr = this->driverHandle->svmAllocsManager->createHostUnifiedMemoryAllocation(size, auto usmPtr = this->driverHandle->getSvmAllocsManager()->createHostUnifiedMemoryAllocation(size,
unifiedMemoryProperties); unifiedMemoryProperties);
if (usmPtr == nullptr) { if (usmPtr == nullptr) {
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY; return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
} }
@@ -157,7 +166,7 @@ ze_result_t ContextImp::allocDeviceMem(ze_device_handle_t hDevice,
} }
void *usmPtr = void *usmPtr =
this->driverHandle->svmAllocsManager->createUnifiedMemoryAllocation(size, unifiedMemoryProperties); this->driverHandle->getSvmAllocsManager()->createUnifiedMemoryAllocation(size, unifiedMemoryProperties);
if (usmPtr == nullptr) { if (usmPtr == nullptr) {
return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY; return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY;
} }
@@ -216,9 +225,9 @@ ze_result_t ContextImp::allocSharedMem(ze_device_handle_t hDevice,
} }
auto usmPtr = auto usmPtr =
this->driverHandle->svmAllocsManager->createSharedUnifiedMemoryAllocation(size, this->driverHandle->getSvmAllocsManager()->createSharedUnifiedMemoryAllocation(size,
unifiedMemoryProperties, unifiedMemoryProperties,
static_cast<void *>(neoDevice->getSpecializedDevice<L0::Device>())); static_cast<void *>(neoDevice->getSpecializedDevice<L0::Device>()));
if (usmPtr == nullptr) { if (usmPtr == nullptr) {
return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY; return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY;
@@ -229,7 +238,7 @@ ze_result_t ContextImp::allocSharedMem(ze_device_handle_t hDevice,
} }
ze_result_t ContextImp::freeMem(const void *ptr) { ze_result_t ContextImp::freeMem(const void *ptr) {
auto allocation = this->driverHandle->svmAllocsManager->getSVMAlloc(ptr); auto allocation = this->driverHandle->getSvmAllocsManager()->getSVMAlloc(ptr);
if (allocation == nullptr) { if (allocation == nullptr) {
return ZE_RESULT_ERROR_INVALID_ARGUMENT; return ZE_RESULT_ERROR_INVALID_ARGUMENT;
} }
@@ -244,13 +253,13 @@ ze_result_t ContextImp::freeMem(const void *ptr) {
auto peerAllocData = &iter->second; auto peerAllocData = &iter->second;
auto peerAlloc = peerAllocData->gpuAllocations.getDefaultGraphicsAllocation(); auto peerAlloc = peerAllocData->gpuAllocations.getDefaultGraphicsAllocation();
auto peerPtr = reinterpret_cast<void *>(peerAlloc->getGpuAddress()); auto peerPtr = reinterpret_cast<void *>(peerAlloc->getGpuAddress());
this->driverHandle->svmAllocsManager->freeSVMAlloc(peerPtr); this->driverHandle->getSvmAllocsManager()->freeSVMAlloc(peerPtr);
} }
} }
this->driverHandle->svmAllocsManager->freeSVMAlloc(const_cast<void *>(ptr)); this->driverHandle->getSvmAllocsManager()->freeSVMAlloc(const_cast<void *>(ptr));
if (this->driverHandle->svmAllocsManager->getSvmMapOperation(ptr)) { if (this->driverHandle->getSvmAllocsManager()->getSvmMapOperation(ptr)) {
this->driverHandle->svmAllocsManager->removeSvmMapOperation(ptr); this->driverHandle->getSvmAllocsManager()->removeSvmMapOperation(ptr);
} }
return ZE_RESULT_SUCCESS; return ZE_RESULT_SUCCESS;
} }
@@ -326,7 +335,7 @@ ze_result_t ContextImp::evictImage(ze_device_handle_t hDevice, ze_image_handle_t
ze_result_t ContextImp::getMemAddressRange(const void *ptr, ze_result_t ContextImp::getMemAddressRange(const void *ptr,
void **pBase, void **pBase,
size_t *pSize) { size_t *pSize) {
NEO::SvmAllocationData *allocData = this->driverHandle->svmAllocsManager->getSVMAlloc(ptr); NEO::SvmAllocationData *allocData = this->driverHandle->getSvmAllocsManager()->getSVMAlloc(ptr);
if (allocData) { if (allocData) {
NEO::GraphicsAllocation *alloc; NEO::GraphicsAllocation *alloc;
alloc = allocData->gpuAllocations.getDefaultGraphicsAllocation(); alloc = allocData->gpuAllocations.getDefaultGraphicsAllocation();
@@ -351,7 +360,7 @@ ze_result_t ContextImp::closeIpcMemHandle(const void *ptr) {
ze_result_t ContextImp::getIpcMemHandle(const void *ptr, ze_result_t ContextImp::getIpcMemHandle(const void *ptr,
ze_ipc_mem_handle_t *pIpcHandle) { ze_ipc_mem_handle_t *pIpcHandle) {
NEO::SvmAllocationData *allocData = this->driverHandle->svmAllocsManager->getSVMAlloc(ptr); NEO::SvmAllocationData *allocData = this->driverHandle->getSvmAllocsManager()->getSVMAlloc(ptr);
if (allocData) { if (allocData) {
uint64_t handle = allocData->gpuAllocations.getDefaultGraphicsAllocation()->peekInternalHandle(this->driverHandle->getMemoryManager()); uint64_t handle = allocData->gpuAllocations.getDefaultGraphicsAllocation()->peekInternalHandle(this->driverHandle->getMemoryManager());
memcpy_s(reinterpret_cast<void *>(pIpcHandle->data), memcpy_s(reinterpret_cast<void *>(pIpcHandle->data),
@@ -385,7 +394,7 @@ ze_result_t ContextImp::openIpcMemHandle(ze_device_handle_t hDevice,
ze_result_t ContextImp::getMemAllocProperties(const void *ptr, ze_result_t ContextImp::getMemAllocProperties(const void *ptr,
ze_memory_allocation_properties_t *pMemAllocProperties, ze_memory_allocation_properties_t *pMemAllocProperties,
ze_device_handle_t *phDevice) { ze_device_handle_t *phDevice) {
auto alloc = driverHandle->svmAllocsManager->getSVMAlloc(ptr); auto alloc = driverHandle->getSvmAllocsManager()->getSVMAlloc(ptr);
if (nullptr == alloc) { if (nullptr == alloc) {
pMemAllocProperties->type = ZE_MEMORY_TYPE_UNKNOWN; pMemAllocProperties->type = ZE_MEMORY_TYPE_UNKNOWN;
return ZE_RESULT_SUCCESS; return ZE_RESULT_SUCCESS;

View File

@@ -115,11 +115,28 @@ struct ContextImp : Context {
return devices; return devices;
} }
NEO::MemoryManager *getMemoryManager() override {
return this->memoryManager;
}
void setMemoryManager(NEO::MemoryManager *memoryManager) override {
this->memoryManager = memoryManager;
}
NEO::SVMAllocsManager *getSvmAllocsManager() override {
return this->svmAllocsManager;
}
void setSvmAllocsManager(NEO::SVMAllocsManager *svmManager) override {
this->svmAllocsManager = svmManager;
}
std::set<uint32_t> rootDeviceIndices = {}; std::set<uint32_t> rootDeviceIndices = {};
std::map<uint32_t, NEO::DeviceBitfield> deviceBitfields; std::map<uint32_t, NEO::DeviceBitfield> deviceBitfields;
bool isDeviceDefinedForThisContext(Device *inDevice); bool isDeviceDefinedForThisContext(Device *inDevice);
NEO::MemoryManager *memoryManager = nullptr;
NEO::SVMAllocsManager *svmAllocsManager = nullptr;
protected: protected:
std::map<ze_device_handle_t, Device *> devices; std::map<ze_device_handle_t, Device *> devices;
DriverHandleImp *driverHandle = nullptr; DriverHandleImp *driverHandle = nullptr;

View File

@@ -47,6 +47,7 @@ struct DriverHandle : _ze_driver_handle_t {
bool *allocationRangeCovered) = 0; bool *allocationRangeCovered) = 0;
virtual NEO::SVMAllocsManager *getSvmAllocsManager() = 0; virtual NEO::SVMAllocsManager *getSvmAllocsManager() = 0;
virtual void setSvmAllocsManager(NEO::SVMAllocsManager *) = 0;
virtual ze_result_t sysmanEventsListen(uint32_t timeout, uint32_t count, zes_device_handle_t *phDevices, virtual ze_result_t sysmanEventsListen(uint32_t timeout, uint32_t count, zes_device_handle_t *phDevices,
uint32_t *pNumDeviceEvents, zes_event_type_flags_t *pEvents) = 0; uint32_t *pNumDeviceEvents, zes_event_type_flags_t *pEvents) = 0;
virtual ze_result_t sysmanEventsListenEx(uint64_t timeout, uint32_t count, zes_device_handle_t *phDevices, virtual ze_result_t sysmanEventsListenEx(uint64_t timeout, uint32_t count, zes_device_handle_t *phDevices,

View File

@@ -53,13 +53,22 @@ ze_result_t DriverHandleImp::createContext(const ze_context_desc_t *desc,
} }
} }
bool multiOsContextDriver = false;
for (auto devicePair : context->getDevices()) { for (auto devicePair : context->getDevices()) {
auto neoDevice = devicePair.second->getNEODevice(); auto neoDevice = devicePair.second->getNEODevice();
multiOsContextDriver |= devicePair.second->isMultiDeviceCapable();
context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(),
neoDevice->getDeviceBitfield()}); neoDevice->getDeviceBitfield()});
} }
if (this->mainContext == nullptr) {
this->mainContext = context;
context->setMemoryManager(context->getDevices().begin()->second->getNEODevice()->getMemoryManager());
context->setSvmAllocsManager(new NEO::SVMAllocsManager(context->getMemoryManager(), multiOsContextDriver));
}
return ZE_RESULT_SUCCESS; return ZE_RESULT_SUCCESS;
} }
@@ -72,7 +81,11 @@ void DriverHandleImp::setMemoryManager(NEO::MemoryManager *memoryManager) {
} }
NEO::SVMAllocsManager *DriverHandleImp::getSvmAllocsManager() { NEO::SVMAllocsManager *DriverHandleImp::getSvmAllocsManager() {
return this->svmAllocsManager; return this->mainContext->getSvmAllocsManager();
}
void DriverHandleImp::setSvmAllocsManager(NEO::SVMAllocsManager *svmManager) {
this->mainContext->setSvmAllocsManager(svmManager);
} }
ze_result_t DriverHandleImp::getApiVersion(ze_api_version_t *version) { ze_result_t DriverHandleImp::getApiVersion(ze_api_version_t *version) {
@@ -133,10 +146,6 @@ DriverHandleImp::~DriverHandleImp() {
for (auto &device : this->devices) { for (auto &device : this->devices) {
delete device; delete device;
} }
if (this->svmAllocsManager) {
delete this->svmAllocsManager;
this->svmAllocsManager = nullptr;
}
} }
ze_result_t DriverHandleImp::initialize(std::vector<std::unique_ptr<NEO::Device>> neoDevices) { ze_result_t DriverHandleImp::initialize(std::vector<std::unique_ptr<NEO::Device>> neoDevices) {
@@ -153,9 +162,6 @@ ze_result_t DriverHandleImp::initialize(std::vector<std::unique_ptr<NEO::Device>
if (this->memoryManager == nullptr) { if (this->memoryManager == nullptr) {
this->memoryManager = neoDevice->getMemoryManager(); this->memoryManager = neoDevice->getMemoryManager();
if (this->memoryManager == nullptr) {
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}
} }
const auto rootDeviceIndex = neoDevice->getRootDeviceIndex(); const auto rootDeviceIndex = neoDevice->getRootDeviceIndex();
@@ -189,11 +195,6 @@ ze_result_t DriverHandleImp::initialize(std::vector<std::unique_ptr<NEO::Device>
return ZE_RESULT_ERROR_UNINITIALIZED; return ZE_RESULT_ERROR_UNINITIALIZED;
} }
this->svmAllocsManager = new NEO::SVMAllocsManager(memoryManager, multiOsContextDriver);
if (this->svmAllocsManager == nullptr) {
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}
this->numDevices = static_cast<uint32_t>(this->devices.size()); this->numDevices = static_cast<uint32_t>(this->devices.size());
extensionFunctionsLookupMap = getExtensionFunctionsLookupMap(); extensionFunctionsLookupMap = getExtensionFunctionsLookupMap();
@@ -250,8 +251,8 @@ bool DriverHandleImp::findAllocationDataForRange(const void *buffer,
NEO::SvmAllocationData **allocData) { NEO::SvmAllocationData **allocData) {
// Make sure the host buffer does not overlap any existing allocation // Make sure the host buffer does not overlap any existing allocation
const char *baseAddress = reinterpret_cast<const char *>(buffer); const char *baseAddress = reinterpret_cast<const char *>(buffer);
NEO::SvmAllocationData *beginAllocData = svmAllocsManager->getSVMAlloc(baseAddress); NEO::SvmAllocationData *beginAllocData = this->getSvmAllocsManager()->getSVMAlloc(baseAddress);
NEO::SvmAllocationData *endAllocData = svmAllocsManager->getSVMAlloc(baseAddress + size - 1); NEO::SvmAllocationData *endAllocData = this->getSvmAllocsManager()->getSVMAlloc(baseAddress + size - 1);
if (allocData) { if (allocData) {
if (beginAllocData) { if (beginAllocData) {
@@ -275,8 +276,8 @@ std::vector<NEO::SvmAllocationData *> DriverHandleImp::findAllocationsWithinRang
std::vector<NEO::SvmAllocationData *> allocDataArray; std::vector<NEO::SvmAllocationData *> allocDataArray;
const char *baseAddress = reinterpret_cast<const char *>(buffer); const char *baseAddress = reinterpret_cast<const char *>(buffer);
// Check if the host buffer overlaps any existing allocation // Check if the host buffer overlaps any existing allocation
NEO::SvmAllocationData *beginAllocData = svmAllocsManager->getSVMAlloc(baseAddress); NEO::SvmAllocationData *beginAllocData = this->getSvmAllocsManager()->getSVMAlloc(baseAddress);
NEO::SvmAllocationData *endAllocData = svmAllocsManager->getSVMAlloc(baseAddress + size - 1); NEO::SvmAllocationData *endAllocData = this->getSvmAllocsManager()->getSVMAlloc(baseAddress + size - 1);
// Add the allocation that matches the beginning address // Add the allocation that matches the beginning address
if (beginAllocData) { if (beginAllocData) {

View File

@@ -10,11 +10,13 @@
#include "shared/source/os_interface/os_library.h" #include "shared/source/os_interface/os_library.h"
#include "level_zero/api/extensions/public/ze_exp_ext.h" #include "level_zero/api/extensions/public/ze_exp_ext.h"
#include "level_zero/core/source/context/context.h"
#include "level_zero/core/source/driver/driver_handle.h" #include "level_zero/core/source/driver/driver_handle.h"
#include "level_zero/core/source/get_extension_function_lookup_map.h" #include "level_zero/core/source/get_extension_function_lookup_map.h"
namespace L0 { namespace L0 {
class HostPointerManager; class HostPointerManager;
struct Context;
struct DriverHandleImp : public DriverHandle { struct DriverHandleImp : public DriverHandle {
~DriverHandleImp() override; ~DriverHandleImp() override;
@@ -38,6 +40,7 @@ struct DriverHandleImp : public DriverHandle {
ze_result_t openEventPoolIpcHandle(ze_ipc_event_pool_handle_t hIpc, ze_event_pool_handle_t *phEventPool) override; ze_result_t openEventPoolIpcHandle(ze_ipc_event_pool_handle_t hIpc, ze_event_pool_handle_t *phEventPool) override;
ze_result_t checkMemoryAccessFromDevice(Device *device, const void *ptr) override; ze_result_t checkMemoryAccessFromDevice(Device *device, const void *ptr) override;
NEO::SVMAllocsManager *getSvmAllocsManager() override; NEO::SVMAllocsManager *getSvmAllocsManager() override;
void setSvmAllocsManager(NEO::SVMAllocsManager *) override;
ze_result_t initialize(std::vector<std::unique_ptr<NEO::Device>> neoDevices); ze_result_t initialize(std::vector<std::unique_ptr<NEO::Device>> neoDevices);
bool findAllocationDataForRange(const void *buffer, bool findAllocationDataForRange(const void *buffer,
size_t size, size_t size,
@@ -91,10 +94,11 @@ struct DriverHandleImp : public DriverHandle {
uint64_t uuidTimestamp = 0u; uint64_t uuidTimestamp = 0u;
NEO::MemoryManager *memoryManager = nullptr; NEO::MemoryManager *memoryManager = nullptr;
NEO::SVMAllocsManager *svmAllocsManager = nullptr;
uint32_t numDevices = 0; uint32_t numDevices = 0;
Context *mainContext = nullptr;
std::set<uint32_t> rootDeviceIndices = {}; std::set<uint32_t> rootDeviceIndices = {};
std::map<uint32_t, NEO::DeviceBitfield> deviceBitfields; std::map<uint32_t, NEO::DeviceBitfield> deviceBitfields;

View File

@@ -96,7 +96,7 @@ ze_result_t EventPoolImp::initialize(DriverHandle *driver, Context *context, uin
alignedSize, alignedSize,
allocationType, allocationType,
false, false,
(deviceBitfield.count() > 1) && driverHandleImp->svmAllocsManager->getMultiOsContextSupport(), (deviceBitfield.count() > 1) && driverHandleImp->getSvmAllocsManager()->getMultiOsContextSupport(),
deviceBitfield}; deviceBitfield};
unifiedMemoryProperties.flags.isUSMHostAllocation = true; unifiedMemoryProperties.flags.isUSMHostAllocation = true;
unifiedMemoryProperties.flags.isUSMDeviceAllocation = false; unifiedMemoryProperties.flags.isUSMDeviceAllocation = false;

View File

@@ -51,7 +51,7 @@ void *DriverHandleImp::importFdHandle(ze_device_handle_t hDevice, ze_ipc_memory_
} }
ze_result_t DriverHandleImp::checkMemoryAccessFromDevice(Device *device, const void *ptr) { ze_result_t DriverHandleImp::checkMemoryAccessFromDevice(Device *device, const void *ptr) {
auto allocation = svmAllocsManager->getSVMAlloc(ptr); auto allocation = this->getSvmAllocsManager()->getSVMAlloc(ptr);
if (allocation == nullptr) { if (allocation == nullptr) {
return ZE_RESULT_ERROR_INVALID_ARGUMENT; return ZE_RESULT_ERROR_INVALID_ARGUMENT;
} }

View File

@@ -31,17 +31,23 @@ class CommandListFixture : public DeviceFixture {
eventDesc.wait = 0; eventDesc.wait = 0;
eventDesc.signal = 0; eventDesc.signal = 0;
eventPool = std::unique_ptr<EventPool>(EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc)); eventPool = EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc);
event = std::unique_ptr<Event>(Event::create(eventPool.get(), &eventDesc, device)); event = Event::create(eventPool, &eventDesc, device);
} }
void TearDown() override { void TearDown() override {
if (event) {
event->destroy();
}
if (eventPool) {
eventPool->destroy();
}
DeviceFixture::TearDown(); DeviceFixture::TearDown();
} }
std::unique_ptr<L0::ult::CommandList> commandList; std::unique_ptr<L0::ult::CommandList> commandList;
std::unique_ptr<EventPool> eventPool; EventPool *eventPool = nullptr;
std::unique_ptr<Event> event; Event *event = nullptr;
}; };
} // namespace ult } // namespace ult

View File

@@ -15,7 +15,10 @@
#include "opencl/test/unit_test/mocks/mock_compilers.h" #include "opencl/test/unit_test/mocks/mock_compilers.h"
#include "level_zero/core/source/context/context_imp.h" #include "level_zero/core/source/context/context_imp.h"
#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h" #include "level_zero/core/test/unit_tests/mock.h"
#include "level_zero/core/test/unit_tests/mocks/mock_device.h"
#include "level_zero/core/test/unit_tests/mocks/mock_memory_manager.h"
#include "level_zero/core/test/unit_tests/white_box.h"
namespace L0 { namespace L0 {
struct Context; struct Context;

View File

@@ -19,7 +19,6 @@
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.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_built_ins.h"
#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h"
#include "level_zero/core/test/unit_tests/mocks/mock_host_pointer_manager.h" #include "level_zero/core/test/unit_tests/mocks/mock_host_pointer_manager.h"
namespace L0 { namespace L0 {
@@ -39,29 +38,29 @@ struct HostPointerManagerFixure {
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice)); devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
DebugManager.flags.EnableHostPointerImport.set(1); DebugManager.flags.EnableHostPointerImport.set(1);
hostDriverHandle = std::make_unique<L0::ult::DriverHandle>(); hostDriverHandle = std::make_unique<L0::DriverHandleImp>();
hostDriverHandle->initialize(std::move(devices)); hostDriverHandle->initialize(std::move(devices));
ze_context_desc_t desc;
ze_result_t ret = hostDriverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
context = L0::Context::fromHandle(hContext);
device = hostDriverHandle->devices[0]; device = hostDriverHandle->devices[0];
EXPECT_NE(nullptr, hostDriverHandle->hostPointerManager.get()); EXPECT_NE(nullptr, hostDriverHandle->hostPointerManager.get());
openHostPointerManager = static_cast<L0::ult::HostPointerManager *>(hostDriverHandle->hostPointerManager.get()); openHostPointerManager = static_cast<L0::ult::HostPointerManager *>(hostDriverHandle->hostPointerManager.get());
heapPointer = hostDriverHandle->getMemoryManager()->allocateSystemMemory(heapSize, MemoryConstants::pageSize); heapPointer = hostDriverHandle->getMemoryManager()->allocateSystemMemory(heapSize, MemoryConstants::pageSize);
ASSERT_NE(nullptr, heapPointer); ASSERT_NE(nullptr, heapPointer);
ze_context_desc_t desc;
ze_result_t ret = hostDriverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
context = L0::Context::fromHandle(hContext);
} }
void TearDown() { void TearDown() {
context->destroy();
hostDriverHandle->getMemoryManager()->freeSystemMemory(heapPointer); hostDriverHandle->getMemoryManager()->freeSystemMemory(heapPointer);
context->destroy();
} }
DebugManagerStateRestore debugRestore; DebugManagerStateRestore debugRestore;
std::unique_ptr<L0::ult::DriverHandle> hostDriverHandle; std::unique_ptr<L0::DriverHandleImp> hostDriverHandle;
L0::ult::HostPointerManager *openHostPointerManager = nullptr; L0::ult::HostPointerManager *openHostPointerManager = nullptr;
NEO::MockDevice *neoDevice = nullptr; NEO::MockDevice *neoDevice = nullptr;

View File

@@ -147,11 +147,11 @@ struct ModuleImmutableDataFixture : public DeviceFixture {
ModuleBuildLog *moduleBuildLog = nullptr; ModuleBuildLog *moduleBuildLog = nullptr;
module = std::make_unique<MockModule>(device, module = new MockModule(device,
moduleBuildLog, moduleBuildLog,
ModuleType::User, ModuleType::User,
perHwThreadPrivateMemorySize, perHwThreadPrivateMemorySize,
mockKernelImmData); mockKernelImmData);
module->type = isInternal ? ModuleType::Builtin : ModuleType::User; module->type = isInternal ? ModuleType::Builtin : ModuleType::User;
bool result = module->initialize(&moduleDesc, device->getNEODevice()); bool result = module->initialize(&moduleDesc, device->getNEODevice());
@@ -165,13 +165,16 @@ struct ModuleImmutableDataFixture : public DeviceFixture {
} }
void TearDown() override { void TearDown() override {
if (module) {
module->destroy();
}
DeviceFixture::TearDown(); DeviceFixture::TearDown();
} }
const std::string binaryFilename = "test_kernel"; const std::string binaryFilename = "test_kernel";
const std::string kernelName = "test"; const std::string kernelName = "test";
const uint32_t numKernelArguments = 6; const uint32_t numKernelArguments = 6;
std::unique_ptr<MockModule> module; MockModule *module = nullptr;
MockImmutableMemoryManager *memoryManager; MockImmutableMemoryManager *memoryManager;
}; };
@@ -201,27 +204,36 @@ struct ModuleFixture : public DeviceFixture {
ModuleBuildLog *moduleBuildLog = nullptr; ModuleBuildLog *moduleBuildLog = nullptr;
module.reset(Module::create(device, &moduleDesc, moduleBuildLog, type)); if (module) {
module->destroy();
}
module = Module::create(device, &moduleDesc, moduleBuildLog, type);
} }
void createKernel() { void createKernel() {
ze_kernel_desc_t desc = {}; ze_kernel_desc_t desc = {};
desc.pKernelName = kernelName.c_str(); desc.pKernelName = kernelName.c_str();
kernel = std::make_unique<WhiteBox<::L0::Kernel>>(); kernel = new WhiteBox<::L0::Kernel>();
kernel->module = module.get(); kernel->module = module;
kernel->initialize(&desc); kernel->initialize(&desc);
} }
void TearDown() override { void TearDown() override {
if (kernel) {
kernel->destroy();
}
if (module) {
module->destroy();
}
DeviceFixture::TearDown(); DeviceFixture::TearDown();
} }
const std::string binaryFilename = "test_kernel"; const std::string binaryFilename = "test_kernel";
const std::string kernelName = "test"; const std::string kernelName = "test";
const uint32_t numKernelArguments = 6; const uint32_t numKernelArguments = 6;
std::unique_ptr<L0::Module> module; L0::Module *module = nullptr;
std::unique_ptr<WhiteBox<::L0::Kernel>> kernel; WhiteBox<::L0::Kernel> *kernel = nullptr;
}; };
struct MultiDeviceModuleFixture : public MultiDeviceFixture { struct MultiDeviceModuleFixture : public MultiDeviceFixture {
@@ -248,29 +260,35 @@ struct MultiDeviceModuleFixture : public MultiDeviceFixture {
ModuleBuildLog *moduleBuildLog = nullptr; ModuleBuildLog *moduleBuildLog = nullptr;
auto device = driverHandle->devices[rootDeviceIndex]; auto device = driverHandle->devices[rootDeviceIndex];
modules[rootDeviceIndex].reset(Module::create(device, modules[rootDeviceIndex] = Module::create(device,
&moduleDesc, &moduleDesc,
moduleBuildLog, ModuleType::User)); moduleBuildLog, ModuleType::User);
} }
void createKernel(uint32_t rootDeviceIndex) { void createKernel(uint32_t rootDeviceIndex) {
ze_kernel_desc_t desc = {}; ze_kernel_desc_t desc = {};
desc.pKernelName = kernelName.c_str(); desc.pKernelName = kernelName.c_str();
kernel = std::make_unique<WhiteBox<::L0::Kernel>>(); kernel = new WhiteBox<::L0::Kernel>();
kernel->module = modules[rootDeviceIndex].get(); kernel->module = modules[rootDeviceIndex];
kernel->initialize(&desc); kernel->initialize(&desc);
} }
void TearDown() override { void TearDown() override {
if (kernel) {
kernel->destroy();
}
for (auto &module : modules) {
module->destroy();
}
MultiDeviceFixture::TearDown(); MultiDeviceFixture::TearDown();
} }
const std::string binaryFilename = "test_kernel"; const std::string binaryFilename = "test_kernel";
const std::string kernelName = "test"; const std::string kernelName = "test";
const uint32_t numKernelArguments = 6; const uint32_t numKernelArguments = 6;
std::vector<std::unique_ptr<L0::Module>> modules; std::vector<L0::Module *> modules;
std::unique_ptr<WhiteBox<::L0::Kernel>> kernel; WhiteBox<::L0::Kernel> *kernel = nullptr;
}; };
struct ImportHostPointerModuleFixture : public ModuleFixture { struct ImportHostPointerModuleFixture : public ModuleFixture {

View File

@@ -13,6 +13,7 @@
#include "opencl/test/unit_test/mocks/mock_compilers.h" #include "opencl/test/unit_test/mocks/mock_compilers.h"
#include "test.h" #include "test.h"
#include "level_zero/core/source/context/context_imp.h"
#include "level_zero/core/source/driver/driver_imp.h" #include "level_zero/core/source/driver/driver_imp.h"
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.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_built_ins.h"
@@ -38,9 +39,14 @@ struct CommandQueueThreadArbitrationPolicyTests : public ::testing::Test {
auto driverHandleUlt = whitebox_cast(DriverHandle::create(std::move(devices), L0EnvVariables{}, &returnValue)); auto driverHandleUlt = whitebox_cast(DriverHandle::create(std::move(devices), L0EnvVariables{}, &returnValue));
driverHandle.reset(driverHandleUlt); driverHandle.reset(driverHandleUlt);
ASSERT_NE(nullptr, driverHandle); ASSERT_NE(nullptr, driverHandle);
ze_context_handle_t hContext;
ze_context_desc_t desc = {};
returnValue = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, returnValue);
context = static_cast<ContextImp *>(Context::fromHandle(hContext));
ze_device_handle_t hDevice; ze_device_handle_t hDevice;
uint32_t count = 1; uint32_t count = 1;
ze_result_t result = driverHandle->getDevice(&count, &hDevice); ze_result_t result = driverHandle->getDevice(&count, &hDevice);
@@ -63,6 +69,7 @@ struct CommandQueueThreadArbitrationPolicyTests : public ::testing::Test {
void TearDown() override { void TearDown() override {
commandList->destroy(); commandList->destroy();
commandQueue->destroy(); commandQueue->destroy();
context->destroy();
L0::GlobalDriver = nullptr; L0::GlobalDriver = nullptr;
} }
@@ -72,6 +79,7 @@ struct CommandQueueThreadArbitrationPolicyTests : public ::testing::Test {
std::unique_ptr<L0::ult::WhiteBox<L0::DriverHandle>> driverHandle; std::unique_ptr<L0::ult::WhiteBox<L0::DriverHandle>> driverHandle;
NEO::MockDevice *neoDevice = nullptr; NEO::MockDevice *neoDevice = nullptr;
L0::Device *device; L0::Device *device;
L0::ContextImp *context = nullptr;
}; };
HWTEST2_F(CommandQueueThreadArbitrationPolicyTests, HWTEST2_F(CommandQueueThreadArbitrationPolicyTests,

View File

@@ -32,18 +32,20 @@ struct TimestampEvent : public Test<DeviceFixture> {
eventDesc.signal = 0; eventDesc.signal = 0;
eventDesc.wait = 0; eventDesc.wait = 0;
eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc)); eventPool = L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc);
ASSERT_NE(nullptr, eventPool); ASSERT_NE(nullptr, eventPool);
event = std::unique_ptr<L0::Event>(L0::Event::create(eventPool.get(), &eventDesc, device)); event = L0::Event::create(eventPool, &eventDesc, device);
ASSERT_NE(nullptr, event); ASSERT_NE(nullptr, event);
} }
void TearDown() override { void TearDown() override {
event->destroy();
eventPool->destroy();
DeviceFixture::TearDown(); DeviceFixture::TearDown();
} }
std::unique_ptr<L0::EventPool> eventPool; L0::EventPool *eventPool = nullptr;
std::unique_ptr<L0::Event> event; L0::Event *event = nullptr;
}; };
GEN12LPTEST_F(TimestampEvent, givenEventTimestampsWhenQueryKernelTimestampThenCorrectDataAreSet) { GEN12LPTEST_F(TimestampEvent, givenEventTimestampsWhenQueryKernelTimestampThenCorrectDataAreSet) {

View File

@@ -14,6 +14,7 @@
#include "test.h" #include "test.h"
#include "level_zero/core/source/cmdqueue/cmdqueue_imp.h" #include "level_zero/core/source/cmdqueue/cmdqueue_imp.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/driver/driver_handle_imp.h"
#include "level_zero/core/source/driver/driver_imp.h" #include "level_zero/core/source/driver/driver_imp.h"
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h" #include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
@@ -40,9 +41,14 @@ struct CommandQueueThreadArbitrationPolicyTests : public ::testing::Test {
auto driverHandleUlt = whitebox_cast(DriverHandle::create(std::move(devices), L0EnvVariables{}, &returnValue)); auto driverHandleUlt = whitebox_cast(DriverHandle::create(std::move(devices), L0EnvVariables{}, &returnValue));
driverHandle.reset(driverHandleUlt); driverHandle.reset(driverHandleUlt);
ASSERT_NE(nullptr, driverHandle); ASSERT_NE(nullptr, driverHandle);
ze_context_handle_t hContext;
ze_context_desc_t desc = {};
returnValue = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, returnValue);
context = static_cast<ContextImp *>(Context::fromHandle(hContext));
ze_device_handle_t hDevice; ze_device_handle_t hDevice;
uint32_t count = 1; uint32_t count = 1;
ze_result_t result = driverHandle->getDevice(&count, &hDevice); ze_result_t result = driverHandle->getDevice(&count, &hDevice);
@@ -65,6 +71,7 @@ struct CommandQueueThreadArbitrationPolicyTests : public ::testing::Test {
void TearDown() override { void TearDown() override {
commandList->destroy(); commandList->destroy();
commandQueue->destroy(); commandQueue->destroy();
context->destroy();
L0::GlobalDriver = nullptr; L0::GlobalDriver = nullptr;
} }
@@ -74,6 +81,7 @@ struct CommandQueueThreadArbitrationPolicyTests : public ::testing::Test {
std::unique_ptr<L0::ult::WhiteBox<L0::DriverHandle>> driverHandle; std::unique_ptr<L0::ult::WhiteBox<L0::DriverHandle>> driverHandle;
NEO::MockDevice *neoDevice = nullptr; NEO::MockDevice *neoDevice = nullptr;
L0::Device *device; L0::Device *device;
L0::ContextImp *context = nullptr;
}; };
HWTEST2_F(CommandQueueThreadArbitrationPolicyTests, HWTEST2_F(CommandQueueThreadArbitrationPolicyTests,

View File

@@ -25,8 +25,6 @@ set(L0_MOCKS_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/mock_device_recompile_built_ins.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_device_recompile_built_ins.h
${CMAKE_CURRENT_SOURCE_DIR}/mock_driver.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_driver.h
${CMAKE_CURRENT_SOURCE_DIR}/mock_driver.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_driver.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mock_driver_handle.h
${CMAKE_CURRENT_SOURCE_DIR}/mock_driver_handle.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mock_event.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_event.h
${CMAKE_CURRENT_SOURCE_DIR}/mock_event.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_event.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_resource_info_l0.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_resource_info_l0.cpp

View File

@@ -1,87 +0,0 @@
/*
* Copyright (C) 2019-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h"
#include "shared/test/common/mocks/mock_graphics_allocation.h"
#include "level_zero/core/source/driver/host_pointer_manager.h"
namespace L0 {
namespace ult {
using MockDriverHandle = Mock<L0::ult::DriverHandle>;
using namespace testing;
using ::testing::Invoke;
using ::testing::Return;
Mock<DriverHandle>::Mock() = default;
NEO::MemoryManager *Mock<DriverHandle>::getMemoryManager() {
return memoryManager;
}
NEO::SVMAllocsManager *Mock<DriverHandle>::getSvmAllocManager() {
return svmAllocsManager;
}
ze_result_t Mock<DriverHandle>::getDevice(uint32_t *pCount, ze_device_handle_t *phDevices) {
if (*pCount == 0) { // User wants to know number of devices
*pCount = this->num_devices;
return ZE_RESULT_SUCCESS;
}
if (phDevices == nullptr) // User is expected to allocate space
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
phDevices[0] = &this->device;
return ZE_RESULT_SUCCESS;
}
ze_result_t Mock<DriverHandle>::allocDeviceMem(ze_device_handle_t hDevice, const ze_device_mem_alloc_desc_t *deviceDesc,
size_t size, size_t alignment, void **ptr) {
NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::DEVICE_UNIFIED_MEMORY, rootDeviceIndices, deviceBitfields);
auto allocation = svmAllocsManager->createUnifiedMemoryAllocation(size, unifiedMemoryProperties);
if (allocation == nullptr) {
return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY;
}
*ptr = allocation;
return ZE_RESULT_SUCCESS;
}
ze_result_t Mock<DriverHandle>::freeMem(const void *ptr) {
auto allocation = svmAllocsManager->getSVMAlloc(ptr);
if (allocation == nullptr) {
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
}
svmAllocsManager->freeSVMAlloc(const_cast<void *>(ptr));
if (svmAllocsManager->getSvmMapOperation(ptr)) {
svmAllocsManager->removeSvmMapOperation(ptr);
}
return ZE_RESULT_SUCCESS;
}
void Mock<DriverHandle>::setupDevices(std::vector<std::unique_ptr<NEO::Device>> neoDevices) {
this->numDevices = static_cast<uint32_t>(neoDevices.size());
for (auto &neoDevice : neoDevices) {
ze_result_t returnValue = ZE_RESULT_SUCCESS;
this->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
this->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
auto device = Device::create(this, neoDevice.release(), std::numeric_limits<uint32_t>::max(), false, &returnValue);
this->devices.push_back(device);
}
}
Mock<DriverHandle>::~Mock(){};
} // namespace ult
} // namespace L0

View File

@@ -1,88 +0,0 @@
/*
* Copyright (C) 2019-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "level_zero/core/source/driver/driver_handle_imp.h"
#include "level_zero/core/test/unit_tests/mock.h"
#include "level_zero/core/test/unit_tests/mocks/mock_device.h"
#include "level_zero/core/test/unit_tests/mocks/mock_memory_manager.h"
#include "level_zero/core/test/unit_tests/white_box.h"
namespace L0 {
namespace ult {
template <>
struct WhiteBox<::L0::DriverHandle> : public ::L0::DriverHandleImp {
using ::L0::DriverHandleImp::enableProgramDebugging;
};
using DriverHandle = WhiteBox<::L0::DriverHandle>;
#define ADDMETHOD_NOBASE(funcName, retType, defaultReturn, funcParams) \
retType funcName##Result = defaultReturn; \
uint32_t funcName##Called = 0u; \
retType funcName funcParams override { \
funcName##Called++; \
return funcName##Result; \
}
template <>
struct Mock<DriverHandle> : public DriverHandleImp {
Mock();
~Mock() override;
ADDMETHOD_NOBASE(getProperties, ze_result_t, ZE_RESULT_SUCCESS, (ze_driver_properties_t * properties))
ADDMETHOD_NOBASE(getApiVersion, ze_result_t, ZE_RESULT_SUCCESS, (ze_api_version_t * version))
ADDMETHOD_NOBASE(getIPCProperties, ze_result_t, ZE_RESULT_SUCCESS, (ze_driver_ipc_properties_t * pIPCProperties))
uint32_t num_devices = 1;
Mock<Device> device;
void setupDevices(std::vector<std::unique_ptr<NEO::Device>> devices);
ze_result_t freeMem(const void *ptr);
ze_result_t getDevice(uint32_t *pCount,
ze_device_handle_t *phDevices) override;
NEO::MemoryManager *getMemoryManager() override;
NEO::SVMAllocsManager *getSvmAllocManager();
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);
ze_result_t importExternalPointer(void *ptr, size_t size) override {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
ze_result_t releaseImportedPointer(void *ptr) override {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
ze_result_t getHostPointerBaseAddress(void *ptr, void **baseAddress) override {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
NEO::GraphicsAllocation *findHostPointerAllocation(void *ptr, size_t size, uint32_t rootDeviceIndex) override {
return nullptr;
}
NEO::GraphicsAllocation *getDriverSystemMemoryAllocation(void *ptr,
size_t size,
uint32_t rootDeviceIndex,
uintptr_t *gpuAddress) override {
auto svmData = svmAllocsManager->getSVMAlloc(ptr);
if (svmData != nullptr) {
if (gpuAddress != nullptr) {
*gpuAddress = reinterpret_cast<uintptr_t>(ptr);
}
return svmData->gpuAllocations.getGraphicsAllocation(rootDeviceIndex);
}
return nullptr;
}
};
#undef ADDMETHOD_NOBASE
} // namespace ult
} // namespace L0

View File

@@ -200,7 +200,7 @@ HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithPrintfUsedWhenAppendedToC
EXPECT_EQ(ZE_RESULT_SUCCESS, result); EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(1u, commandList->getPrintfFunctionContainer().size()); EXPECT_EQ(1u, commandList->getPrintfFunctionContainer().size());
EXPECT_EQ(kernel.get(), commandList->getPrintfFunctionContainer()[0]); EXPECT_EQ(kernel, commandList->getPrintfFunctionContainer()[0]);
} }
HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithPrintfUsedWhenAppendedToCommandListMultipleTimesThenKernelIsStoredOnce) { HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithPrintfUsedWhenAppendedToCommandListMultipleTimesThenKernelIsStoredOnce) {
@@ -215,7 +215,7 @@ HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithPrintfUsedWhenAppendedToC
EXPECT_EQ(ZE_RESULT_SUCCESS, result); EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(1u, commandList->getPrintfFunctionContainer().size()); EXPECT_EQ(1u, commandList->getPrintfFunctionContainer().size());
EXPECT_EQ(kernel.get(), commandList->getPrintfFunctionContainer()[0]); EXPECT_EQ(kernel, commandList->getPrintfFunctionContainer()[0]);
result = commandList->appendLaunchKernel(kernel->toHandle(), &groupCount, nullptr, 0, nullptr); result = commandList->appendLaunchKernel(kernel->toHandle(), &groupCount, nullptr, 0, nullptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result); EXPECT_EQ(ZE_RESULT_SUCCESS, result);
@@ -595,9 +595,9 @@ HWTEST_F(CommandListAppendLaunchKernel, givenIndirectDispatchWhenAppendingThenWo
using MI_LOAD_REGISTER_REG = typename FamilyType::MI_LOAD_REGISTER_REG; using MI_LOAD_REGISTER_REG = typename FamilyType::MI_LOAD_REGISTER_REG;
using MI_LOAD_REGISTER_IMM = typename FamilyType::MI_LOAD_REGISTER_IMM; using MI_LOAD_REGISTER_IMM = typename FamilyType::MI_LOAD_REGISTER_IMM;
Mock<::L0::Kernel> kernel; Mock<::L0::Kernel> mockKernel;
kernel.descriptor.payloadMappings.dispatchTraits.numWorkGroups[0] = 2; mockKernel.descriptor.payloadMappings.dispatchTraits.numWorkGroups[0] = 2;
kernel.descriptor.payloadMappings.dispatchTraits.globalWorkSize[0] = 2; mockKernel.descriptor.payloadMappings.dispatchTraits.globalWorkSize[0] = 2;
ze_result_t returnValue; ze_result_t returnValue;
std::unique_ptr<L0::CommandList> commandList(L0::CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, returnValue)); std::unique_ptr<L0::CommandList> commandList(L0::CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, returnValue));
@@ -606,7 +606,7 @@ HWTEST_F(CommandListAppendLaunchKernel, givenIndirectDispatchWhenAppendingThenWo
auto result = context->allocDeviceMem(device->toHandle(), &deviceDesc, 16384u, 4096u, &alloc); auto result = context->allocDeviceMem(device->toHandle(), &deviceDesc, 16384u, 4096u, &alloc);
ASSERT_EQ(ZE_RESULT_SUCCESS, result); ASSERT_EQ(ZE_RESULT_SUCCESS, result);
result = commandList->appendLaunchKernelIndirect(kernel.toHandle(), result = commandList->appendLaunchKernelIndirect(mockKernel.toHandle(),
static_cast<ze_group_count_t *>(alloc), static_cast<ze_group_count_t *>(alloc),
nullptr, 0, nullptr); nullptr, 0, nullptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result); EXPECT_EQ(ZE_RESULT_SUCCESS, result);

View File

@@ -112,7 +112,7 @@ HWTEST_F(CommandListAppendWaitOnEvent, givenEventWithWaitScopeFlagDeviceWhenAppe
0, 0,
ZE_EVENT_SCOPE_FLAG_DEVICE}; ZE_EVENT_SCOPE_FLAG_DEVICE};
auto event = std::unique_ptr<Event>(Event::create(eventPool.get(), &eventDesc, device)); auto event = std::unique_ptr<Event>(Event::create(eventPool, &eventDesc, device));
ze_event_handle_t hEventHandle = event->toHandle(); ze_event_handle_t hEventHandle = event->toHandle();
auto result = commandList->appendWaitOnEvents(1, &hEventHandle); auto result = commandList->appendWaitOnEvents(1, &hEventHandle);

View File

@@ -85,11 +85,19 @@ HWTEST2_F(AppendMemoryCopy, givenCopyOnlyCommandListWhenAppenBlitFillThenCopyBlt
using GfxFamily = typename NEO::GfxFamilyMapper<gfxCoreFamily>::GfxFamily; using GfxFamily = typename NEO::GfxFamilyMapper<gfxCoreFamily>::GfxFamily;
using XY_COLOR_BLT = typename GfxFamily::XY_COLOR_BLT; using XY_COLOR_BLT = typename GfxFamily::XY_COLOR_BLT;
MockCommandListForMemFill<gfxCoreFamily> commandList; MockCommandListForMemFill<gfxCoreFamily> commandList;
MockDriverHandle driverHandleMock; MockDriverHandle driverHandleMock;
NEO::DeviceVector neoDevices; NEO::DeviceVector neoDevices;
neoDevices.push_back(std::unique_ptr<NEO::Device>(neoDevice)); neoDevices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
driverHandleMock.initialize(std::move(neoDevices)); driverHandleMock.initialize(std::move(neoDevices));
device->setDriverHandle(&driverHandleMock); device->setDriverHandle(&driverHandleMock);
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_result_t res = driverHandleMock.createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
L0::ContextImp *contextDriverMock = static_cast<ContextImp *>(Context::fromHandle(hContext));
commandList.initialize(device, NEO::EngineGroupType::Copy); commandList.initialize(device, NEO::EngineGroupType::Copy);
uint16_t pattern = 1; uint16_t pattern = 1;
void *ptr = reinterpret_cast<void *>(0x1234); void *ptr = reinterpret_cast<void *>(0x1234);
@@ -99,6 +107,7 @@ HWTEST2_F(AppendMemoryCopy, givenCopyOnlyCommandListWhenAppenBlitFillThenCopyBlt
cmdList, ptrOffset(commandList.commandContainer.getCommandStream()->getCpuBase(), 0), commandList.commandContainer.getCommandStream()->getUsed())); cmdList, ptrOffset(commandList.commandContainer.getCommandStream()->getCpuBase(), 0), commandList.commandContainer.getCommandStream()->getUsed()));
auto itor = find<XY_COLOR_BLT *>(cmdList.begin(), cmdList.end()); auto itor = find<XY_COLOR_BLT *>(cmdList.begin(), cmdList.end());
EXPECT_NE(cmdList.end(), itor); EXPECT_NE(cmdList.end(), itor);
contextDriverMock->destroy();
device->setDriverHandle(driverHandle.get()); device->setDriverHandle(driverHandle.get());
} }

View File

@@ -80,11 +80,18 @@ class AppendFillFixture : public DeviceFixture, public ::testing::Test {
driverHandle = std::make_unique<Mock<MockDriverFillHandle>>(); driverHandle = std::make_unique<Mock<MockDriverFillHandle>>();
driverHandle->initialize(std::move(devices)); driverHandle->initialize(std::move(devices));
device = driverHandle->devices[0]; device = driverHandle->devices[0];
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
context = static_cast<ContextImp *>(Context::fromHandle(hContext));
} }
void TearDown() override { void TearDown() override {
delete[] immediateDstPtr; delete[] immediateDstPtr;
delete[] dstPtr; delete[] dstPtr;
context->destroy();
} }
std::unique_ptr<Mock<MockDriverFillHandle>> driverHandle; std::unique_ptr<Mock<MockDriverFillHandle>> driverHandle;
@@ -94,6 +101,7 @@ class AppendFillFixture : public DeviceFixture, public ::testing::Test {
static constexpr size_t patternSize = 8; static constexpr size_t patternSize = 8;
uint8_t *dstPtr = nullptr; uint8_t *dstPtr = nullptr;
uint8_t pattern[patternSize] = {1, 2, 3, 4}; uint8_t pattern[patternSize] = {1, 2, 3, 4};
L0::ContextImp *context = nullptr;
static constexpr size_t immediateAllocSize = 106; static constexpr size_t immediateAllocSize = 106;
uint8_t immediatePattern = 4; uint8_t immediatePattern = 4;

View File

@@ -17,7 +17,6 @@
#include "level_zero/core/source/image/image.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/device_fixture.h"
#include "level_zero/core/test/unit_tests/fixtures/host_pointer_manager_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" #include "gtest/gtest.h"
@@ -159,23 +158,9 @@ struct ContextHostAllocTests : public ::testing::Test {
driverHandle = std::make_unique<DriverHandleImp>(); driverHandle = std::make_unique<DriverHandleImp>();
ze_result_t res = driverHandle->initialize(std::move(devices)); ze_result_t res = driverHandle->initialize(std::move(devices));
EXPECT_EQ(ZE_RESULT_SUCCESS, res); EXPECT_EQ(ZE_RESULT_SUCCESS, res);
prevSvmAllocsManager = driverHandle->svmAllocsManager;
currSvmAllocsManager = new SVMAllocsManagerContextMock(driverHandle->memoryManager);
driverHandle->svmAllocsManager = currSvmAllocsManager;
zeDevices.resize(numberOfDevicesInContext);
driverHandle->getDevice(&numberOfDevicesInContext, zeDevices.data());
for (uint32_t i = 0; i < numberOfDevicesInContext; i++) {
L0::DeviceImp *deviceImp = static_cast<L0::DeviceImp *>(L0::Device::fromHandle(zeDevices[i]));
currSvmAllocsManager->expectedRootDeviceIndexes.push_back(deviceImp->getRootDeviceIndex());
}
} }
void TearDown() override { void TearDown() override {
driverHandle->svmAllocsManager = prevSvmAllocsManager;
delete currSvmAllocsManager;
} }
DebugManagerStateRestore restorer; DebugManagerStateRestore restorer;
@@ -189,6 +174,9 @@ struct ContextHostAllocTests : public ::testing::Test {
TEST_F(ContextHostAllocTests, TEST_F(ContextHostAllocTests,
whenAllocatingHostMemoryOnlyIndexesOfDevicesWithinTheContextAreUsed) { whenAllocatingHostMemoryOnlyIndexesOfDevicesWithinTheContextAreUsed) {
zeDevices.resize(numberOfDevicesInContext);
driverHandle->getDevice(&numberOfDevicesInContext, zeDevices.data());
L0::ContextImp *context = nullptr; L0::ContextImp *context = nullptr;
ze_context_handle_t hContext; ze_context_handle_t hContext;
ze_context_desc_t desc; ze_context_desc_t desc;
@@ -199,6 +187,15 @@ TEST_F(ContextHostAllocTests,
EXPECT_EQ(ZE_RESULT_SUCCESS, res); EXPECT_EQ(ZE_RESULT_SUCCESS, res);
context = static_cast<ContextImp *>(Context::fromHandle(hContext)); context = static_cast<ContextImp *>(Context::fromHandle(hContext));
prevSvmAllocsManager = context->getSvmAllocsManager();
currSvmAllocsManager = new SVMAllocsManagerContextMock(context->getMemoryManager());
context->setSvmAllocsManager(currSvmAllocsManager);
for (uint32_t i = 0; i < numberOfDevicesInContext; i++) {
L0::DeviceImp *deviceImp = static_cast<L0::DeviceImp *>(L0::Device::fromHandle(zeDevices[i]));
currSvmAllocsManager->expectedRootDeviceIndexes.push_back(deviceImp->getRootDeviceIndex());
}
void *hostPtr = nullptr; void *hostPtr = nullptr;
ze_host_mem_alloc_desc_t hostDesc = {}; ze_host_mem_alloc_desc_t hostDesc = {};
size_t size = 1024; size_t size = 1024;
@@ -209,6 +206,9 @@ TEST_F(ContextHostAllocTests,
res = context->freeMem(hostPtr); res = context->freeMem(hostPtr);
EXPECT_EQ(ZE_RESULT_SUCCESS, res); EXPECT_EQ(ZE_RESULT_SUCCESS, res);
context->setSvmAllocsManager(prevSvmAllocsManager);
delete currSvmAllocsManager;
context->destroy(); context->destroy();
} }

View File

@@ -14,13 +14,13 @@
#include "opencl/test/unit_test/mocks/mock_source_level_debugger.h" #include "opencl/test/unit_test/mocks/mock_source_level_debugger.h"
#include "level_zero/core/source/cmdqueue/cmdqueue_hw.h" #include "level_zero/core/source/cmdqueue/cmdqueue_hw.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/driver/driver_handle_imp.h"
#include "level_zero/core/source/fence/fence.h" #include "level_zero/core/source/fence/fence.h"
#include "level_zero/core/source/module/module.h" #include "level_zero/core/source/module/module.h"
#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h" #include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h"
#include "level_zero/core/test/unit_tests/mocks/mock_device.h" #include "level_zero/core/test/unit_tests/mocks/mock_device.h"
#include "level_zero/core/test/unit_tests/mocks/mock_driver.h" #include "level_zero/core/test/unit_tests/mocks/mock_driver.h"
#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h"
#include "level_zero/core/test/unit_tests/mocks/mock_memory_manager.h" #include "level_zero/core/test/unit_tests/mocks/mock_memory_manager.h"
namespace L0 { namespace L0 {
@@ -54,6 +54,12 @@ struct ActiveDebuggerFixture {
ASSERT_NE(nullptr, driverHandle); ASSERT_NE(nullptr, driverHandle);
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
context = static_cast<ContextImp *>(Context::fromHandle(hContext));
ze_device_handle_t hDevice; ze_device_handle_t hDevice;
uint32_t count = 1; uint32_t count = 1;
ze_result_t result = driverHandle->getDevice(&count, &hDevice); ze_result_t result = driverHandle->getDevice(&count, &hDevice);
@@ -62,6 +68,7 @@ struct ActiveDebuggerFixture {
ASSERT_NE(nullptr, deviceL0); ASSERT_NE(nullptr, deviceL0);
} }
void TearDown() { // NOLINT(readability-identifier-naming) void TearDown() { // NOLINT(readability-identifier-naming)
context->destroy();
L0::GlobalDriver = nullptr; L0::GlobalDriver = nullptr;
} }
@@ -70,6 +77,7 @@ struct ActiveDebuggerFixture {
L0::Device *deviceL0; L0::Device *deviceL0;
MockActiveSourceLevelDebugger *debugger = nullptr; MockActiveSourceLevelDebugger *debugger = nullptr;
HardwareInfo hwInfo; HardwareInfo hwInfo;
L0::ContextImp *context = nullptr;
}; };
} // namespace ult } // namespace ult
} // namespace L0 } // namespace L0

View File

@@ -38,15 +38,23 @@ struct L0DebuggerFixture {
driverHandle->initialize(std::move(devices)); driverHandle->initialize(std::move(devices));
device = driverHandle->devices[0]; device = driverHandle->devices[0];
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
context = static_cast<ContextImp *>(Context::fromHandle(hContext));
} }
void TearDown() { void TearDown() {
context->destroy();
} }
std::unique_ptr<Mock<L0::DriverHandleImp>> driverHandle; std::unique_ptr<Mock<L0::DriverHandleImp>> driverHandle;
NEO::MockDevice *neoDevice = nullptr; NEO::MockDevice *neoDevice = nullptr;
L0::Device *device = nullptr; L0::Device *device = nullptr;
NEO::HardwareInfo hwInfo; NEO::HardwareInfo hwInfo;
L0::ContextImp *context = nullptr;
}; };
struct L0DebuggerHwFixture : public L0DebuggerFixture { struct L0DebuggerHwFixture : public L0DebuggerFixture {

View File

@@ -23,8 +23,11 @@
#include "level_zero/core/source/context/context_imp.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/driver/driver_handle_imp.h"
#include "level_zero/core/source/driver/host_pointer_manager.h" #include "level_zero/core/source/driver/host_pointer_manager.h"
#include "level_zero/core/test/unit_tests/mock.h"
#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.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" #include "level_zero/core/test/unit_tests/mocks/mock_device.h"
#include "level_zero/core/test/unit_tests/mocks/mock_memory_manager.h"
#include "level_zero/core/test/unit_tests/white_box.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@@ -192,6 +195,16 @@ struct DeviceTest : public ::testing::Test {
driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>(); driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
driverHandle->initialize(std::move(devices)); driverHandle->initialize(std::move(devices));
device = driverHandle->devices[0]; device = driverHandle->devices[0];
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
context = static_cast<ContextImp *>(Context::fromHandle(hContext));
}
void TearDown() override {
context->destroy();
} }
DebugManagerStateRestore restorer; DebugManagerStateRestore restorer;
@@ -200,6 +213,7 @@ struct DeviceTest : public ::testing::Test {
L0::Device *device = nullptr; L0::Device *device = nullptr;
const uint32_t rootDeviceIndex = 1u; const uint32_t rootDeviceIndex = 1u;
const uint32_t numRootDevices = 2u; const uint32_t numRootDevices = 2u;
L0::ContextImp *context = nullptr;
}; };
TEST_F(DeviceTest, givenEmptySVmAllocStorageWhenAllocateManagedMemoryFromHostPtrThenBufferHostAllocationIsCreated) { TEST_F(DeviceTest, givenEmptySVmAllocStorageWhenAllocateManagedMemoryFromHostPtrThenBufferHostAllocationIsCreated) {
@@ -248,12 +262,19 @@ struct DeviceHostPointerTest : public ::testing::Test {
driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>(); driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
driverHandle->initialize(std::move(devices)); driverHandle->initialize(std::move(devices));
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
context = static_cast<ContextImp *>(Context::fromHandle(hContext));
static_cast<MockMemoryManager *>(driverHandle.get()->getMemoryManager())->isMockHostMemoryManager = true; static_cast<MockMemoryManager *>(driverHandle.get()->getMemoryManager())->isMockHostMemoryManager = true;
static_cast<MockMemoryManager *>(driverHandle.get()->getMemoryManager())->forceFailureInAllocationWithHostPointer = true; static_cast<MockMemoryManager *>(driverHandle.get()->getMemoryManager())->forceFailureInAllocationWithHostPointer = true;
device = driverHandle->devices[0]; device = driverHandle->devices[0];
} }
void TearDown() override { void TearDown() override {
context->destroy();
} }
NEO::ExecutionEnvironment *executionEnvironment = nullptr; NEO::ExecutionEnvironment *executionEnvironment = nullptr;
@@ -262,6 +283,7 @@ struct DeviceHostPointerTest : public ::testing::Test {
L0::Device *device = nullptr; L0::Device *device = nullptr;
const uint32_t rootDeviceIndex = 1u; const uint32_t rootDeviceIndex = 1u;
const uint32_t numRootDevices = 2u; const uint32_t numRootDevices = 2u;
L0::ContextImp *context = nullptr;
}; };
TEST_F(DeviceHostPointerTest, givenHostPointerNotAcceptedByKernelThenNewAllocationIsCreatedAndHostPointerCopied) { TEST_F(DeviceHostPointerTest, givenHostPointerNotAcceptedByKernelThenNewAllocationIsCreatedAndHostPointerCopied) {

View File

@@ -165,10 +165,11 @@ TEST(DriverTest, givenNullEnvVariableWhenCreatingDriverThenEnableProgramDebuggin
L0EnvVariables envVariables = {}; L0EnvVariables envVariables = {};
envVariables.programDebugging = false; envVariables.programDebugging = false;
auto driverHandle = whitebox_cast(DriverHandle::create(std::move(devices), envVariables, &returnValue)); auto driverHandle = DriverHandle::create(std::move(devices), envVariables, &returnValue);
EXPECT_NE(nullptr, driverHandle); EXPECT_NE(nullptr, driverHandle);
EXPECT_FALSE(driverHandle->enableProgramDebugging); DriverHandleImp *driverHandleImp = static_cast<DriverHandleImp *>(driverHandle);
EXPECT_FALSE(driverHandleImp->enableProgramDebugging);
delete driverHandle; delete driverHandle;
L0::GlobalDriver = nullptr; L0::GlobalDriver = nullptr;
@@ -262,10 +263,11 @@ TEST(DriverTest, givenProgramDebuggingEnvVarNonZeroWhenCreatingDriverThenEnableP
L0EnvVariables envVariables = {}; L0EnvVariables envVariables = {};
envVariables.programDebugging = true; envVariables.programDebugging = true;
auto driverHandle = whitebox_cast(DriverHandle::create(std::move(devices), envVariables, &returnValue)); auto driverHandle = DriverHandle::create(std::move(devices), envVariables, &returnValue);
EXPECT_NE(nullptr, driverHandle); EXPECT_NE(nullptr, driverHandle);
EXPECT_TRUE(driverHandle->enableProgramDebugging); DriverHandleImp *driverHandleImp = static_cast<DriverHandleImp *>(driverHandle);
EXPECT_TRUE(driverHandleImp->enableProgramDebugging);
delete driverHandle; delete driverHandle;
L0::GlobalDriver = nullptr; L0::GlobalDriver = nullptr;
@@ -381,13 +383,21 @@ struct DriverHandleTest : public ::testing::Test {
driverHandle = whitebox_cast(DriverHandle::create(std::move(devices), envVariables, &returnValue)); driverHandle = whitebox_cast(DriverHandle::create(std::move(devices), envVariables, &returnValue));
L0::GlobalDriverHandle = driverHandle; L0::GlobalDriverHandle = driverHandle;
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
context = static_cast<ContextImp *>(Context::fromHandle(hContext));
} }
void TearDown() override { void TearDown() override {
context->destroy();
delete driverHandle; delete driverHandle;
L0::GlobalDriver = nullptr; L0::GlobalDriver = nullptr;
L0::GlobalDriverHandle = nullptr; L0::GlobalDriverHandle = nullptr;
} }
L0::DriverHandle *driverHandle; L0::DriverHandle *driverHandle = nullptr;
L0::ContextImp *context = nullptr;
}; };
TEST_F(DriverHandleTest, givenInitializedDriverWhenZeDriverGetIsCalledThenDriverHandleCountIsObtained) { TEST_F(DriverHandleTest, givenInitializedDriverWhenZeDriverGetIsCalledThenDriverHandleCountIsObtained) {
@@ -451,11 +461,9 @@ TEST_F(DriverHandleTest, givenInitializedDriverWhenZeDriverGetIsCalledThenGlobal
} }
TEST_F(DriverHandleTest, givenInitializedDriverWhenGetDeviceIsCalledThenOneDeviceIsObtained) { TEST_F(DriverHandleTest, givenInitializedDriverWhenGetDeviceIsCalledThenOneDeviceIsObtained) {
ze_result_t result;
uint32_t count = 1; uint32_t count = 1;
ze_device_handle_t device; ze_device_handle_t device;
result = driverHandle->getDevice(&count, &device); ze_result_t result = driverHandle->getDevice(&count, &device);
EXPECT_EQ(ZE_RESULT_SUCCESS, result); EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_NE(nullptr, &device); EXPECT_NE(nullptr, &device);
} }
@@ -465,40 +473,37 @@ TEST_F(DriverHandleTest, givenValidDriverHandleWhenGetSvmAllocManagerIsCalledThe
EXPECT_NE(nullptr, svmAllocsManager); EXPECT_NE(nullptr, svmAllocsManager);
} }
TEST(zeDriverHandleGetProperties, whenZeDriverGetPropertiesIsCalledThenGetPropertiesIsCalled) { TEST_F(DriverHandleTest, whenZeDriverGetPropertiesIsCalledThenSuccessIsReturned) {
ze_result_t result; ze_driver_properties_t properties = {};
Mock<DriverHandle> driverHandle; ze_result_t result = zeDriverGetProperties(driverHandle->toHandle(), &properties);
ze_driver_properties_t properties; EXPECT_EQ(ZE_RESULT_SUCCESS, result);
ze_result_t expectedResult = ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS;
driverHandle.getPropertiesResult = expectedResult;
result = zeDriverGetProperties(driverHandle.toHandle(), &properties);
EXPECT_EQ(expectedResult, result);
EXPECT_EQ(1u, driverHandle.getPropertiesCalled);
} }
TEST(zeDriverHandleGetApiVersion, whenZeDriverGetApiIsCalledThenGetApiVersionIsCalled) { TEST_F(DriverHandleTest, whenZeDriverGetApiIsCalledThenSuccessIsReturned) {
ze_result_t result; ze_api_version_t version = {};
Mock<DriverHandle> driverHandle; ze_result_t result = zeDriverGetApiVersion(driverHandle->toHandle(), &version);
ze_api_version_t version; EXPECT_EQ(ZE_RESULT_SUCCESS, result);
ze_result_t expectedResult = ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS;
driverHandle.getApiVersionResult = expectedResult;
result = zeDriverGetApiVersion(driverHandle.toHandle(), &version);
EXPECT_EQ(expectedResult, result);
EXPECT_EQ(1u, driverHandle.getApiVersionCalled);
} }
TEST(zeDriverGetIpcProperties, whenZeDriverGetIpcPropertiesIsCalledThenGetIPCPropertiesIsCalled) { TEST_F(DriverHandleTest, whenGettingApiVersionThenCorrectApiVersionIsReturned) {
ze_result_t result; ze_api_version_t version = {};
Mock<DriverHandle> driverHandle; ze_result_t result = driverHandle->getApiVersion(&version);
ze_driver_ipc_properties_t ipcProperties; EXPECT_EQ(ZE_RESULT_SUCCESS, result);
ze_result_t expectedResult = ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS; EXPECT_EQ(ZE_API_VERSION_1_1, version);
driverHandle.getIPCPropertiesResult = expectedResult;
result = zeDriverGetIpcProperties(driverHandle.toHandle(), &ipcProperties);
EXPECT_EQ(expectedResult, result);
EXPECT_EQ(1u, driverHandle.getIPCPropertiesCalled);
} }
TEST_F(DriverHandleTest, whenZeDriverGetIpcPropertiesIsCalledThenSuccessIsReturned) {
ze_driver_ipc_properties_t ipcProperties = {};
ze_result_t result = zeDriverGetIpcProperties(driverHandle->toHandle(), &ipcProperties);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
}
TEST_F(DriverHandleTest, whenGettingIpcPropertiesThenCorrectPropertiesAreReturned) {
ze_driver_ipc_properties_t ipcProperties = {};
ze_result_t result = driverHandle->getIPCProperties(&ipcProperties);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(ZE_IPC_PROPERTY_FLAG_MEMORY, ipcProperties.flags);
}
} // namespace ult } // namespace ult
} // namespace L0 } // namespace L0

View File

@@ -70,21 +70,32 @@ struct EventPoolFailTests : public ::testing::Test {
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice)); devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
driverHandle = std::make_unique<DriverHandleImp>(); driverHandle = std::make_unique<DriverHandleImp>();
driverHandle->initialize(std::move(devices)); driverHandle->initialize(std::move(devices));
prevMemoryManager = driverHandle->getMemoryManager();
currMemoryManager = new MemoryManagerEventPoolFailMock(*neoDevice->executionEnvironment);
driverHandle->setMemoryManager(currMemoryManager);
device = driverHandle->devices[0]; device = driverHandle->devices[0];
context = std::make_unique<ContextImp>(driverHandle.get()); context = std::make_unique<ContextImp>(driverHandle.get());
EXPECT_NE(context, nullptr); EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->toHandle(), device));
auto neoDevice = device->getNEODevice(); {
context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); context->getDevices().insert(std::make_pair(device->toHandle(), device));
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}
context->setMemoryManager(context->getDevices().begin()->second->getNEODevice()->getMemoryManager());
prevMemoryManager = context->getMemoryManager();
currMemoryManager = new MemoryManagerEventPoolFailMock(*neoDevice->executionEnvironment);
context->setMemoryManager(currMemoryManager);
driverHandle->mainContext = context.get();
driverHandle->setMemoryManager(context->getMemoryManager());
driverHandle->setSvmAllocsManager(context->getSvmAllocsManager());
} }
void TearDown() override { void TearDown() override {
driverHandle->setMemoryManager(prevMemoryManager); context->setMemoryManager(prevMemoryManager);
delete currMemoryManager; delete currMemoryManager;
} }
NEO::MemoryManager *prevMemoryManager = nullptr; NEO::MemoryManager *prevMemoryManager = nullptr;
@@ -315,18 +326,20 @@ class EventSynchronizeTest : public Test<DeviceFixture> {
eventDesc.signal = 0; eventDesc.signal = 0;
eventDesc.wait = 0; eventDesc.wait = 0;
eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc)); eventPool = L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc);
ASSERT_NE(nullptr, eventPool); ASSERT_NE(nullptr, eventPool);
event = std::unique_ptr<L0::Event>(L0::Event::create(eventPool.get(), &eventDesc, device)); event = L0::Event::create(eventPool, &eventDesc, device);
ASSERT_NE(nullptr, event); ASSERT_NE(nullptr, event);
} }
void TearDown() override { void TearDown() override {
event->destroy();
eventPool->destroy();
DeviceFixture::TearDown(); DeviceFixture::TearDown();
} }
std::unique_ptr<L0::EventPool> eventPool = nullptr; L0::EventPool *eventPool = nullptr;
std::unique_ptr<L0::Event> event; L0::Event *event = nullptr;
}; };
TEST_F(EventSynchronizeTest, givenCallToEventHostSynchronizeWithTimeoutZeroAndStateInitialHostSynchronizeReturnsNotReady) { TEST_F(EventSynchronizeTest, givenCallToEventHostSynchronizeWithTimeoutZeroAndStateInitialHostSynchronizeReturnsNotReady) {
@@ -368,13 +381,17 @@ HWTEST_F(EventAubCsrTest, givenCallToEventHostSynchronizeWithAubModeCsrReturnsSu
driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>(); driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
driverHandle->initialize(std::move(devices)); driverHandle->initialize(std::move(devices));
device = driverHandle->devices[0]; device = driverHandle->devices[0];
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
L0::ContextImp *context = static_cast<ContextImp *>(Context::fromHandle(hContext));
int32_t tag; int32_t tag;
auto aubCsr = new MockCsrAub<FamilyType>(tag, *neoDevice->executionEnvironment, neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()); auto aubCsr = new MockCsrAub<FamilyType>(tag, *neoDevice->executionEnvironment, neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield());
neoDevice->resetCommandStreamReceiver(aubCsr); neoDevice->resetCommandStreamReceiver(aubCsr);
std::unique_ptr<L0::EventPool> eventPool = nullptr;
std::unique_ptr<L0::Event> event;
ze_event_pool_desc_t eventPoolDesc = {}; ze_event_pool_desc_t eventPoolDesc = {};
eventPoolDesc.count = 1; eventPoolDesc.count = 1;
eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE; eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE;
@@ -384,13 +401,17 @@ HWTEST_F(EventAubCsrTest, givenCallToEventHostSynchronizeWithAubModeCsrReturnsSu
eventDesc.signal = 0; eventDesc.signal = 0;
eventDesc.wait = 0; eventDesc.wait = 0;
eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc)); L0::EventPool *eventPool = L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc);
ASSERT_NE(nullptr, eventPool); ASSERT_NE(nullptr, eventPool);
event = std::unique_ptr<L0::Event>(L0::Event::create(eventPool.get(), &eventDesc, device)); L0::Event *event = L0::Event::create(eventPool, &eventDesc, device);
ASSERT_NE(nullptr, event); ASSERT_NE(nullptr, event);
ze_result_t result = event->hostSynchronize(10); ze_result_t result = event->hostSynchronize(10);
EXPECT_EQ(ZE_RESULT_SUCCESS, result); EXPECT_EQ(ZE_RESULT_SUCCESS, result);
event->destroy();
eventPool->destroy();
context->destroy();
} }
struct EventCreateAllocationResidencyTest : public ::testing::Test { struct EventCreateAllocationResidencyTest : public ::testing::Test {
@@ -428,18 +449,20 @@ class TimestampEventCreate : public Test<DeviceFixture> {
eventDesc.signal = 0; eventDesc.signal = 0;
eventDesc.wait = 0; eventDesc.wait = 0;
eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc)); eventPool = L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc);
ASSERT_NE(nullptr, eventPool); ASSERT_NE(nullptr, eventPool);
event = std::unique_ptr<L0::Event>(L0::Event::create(eventPool.get(), &eventDesc, device)); event = L0::Event::create(eventPool, &eventDesc, device);
ASSERT_NE(nullptr, event); ASSERT_NE(nullptr, event);
} }
void TearDown() override { void TearDown() override {
event->destroy();
eventPool->destroy();
DeviceFixture::TearDown(); DeviceFixture::TearDown();
} }
std::unique_ptr<L0::EventPool> eventPool; L0::EventPool *eventPool = nullptr;
std::unique_ptr<L0::Event> event; L0::Event *event = nullptr;
}; };
TEST_F(TimestampEventCreate, givenEventCreatedWithTimestampThenIsTimestampEventFlagSet) { TEST_F(TimestampEventCreate, givenEventCreatedWithTimestampThenIsTimestampEventFlagSet) {
@@ -553,7 +576,7 @@ TEST_F(TimestampEventCreate, givenEventWhenQueryKernelTimestampThenNotReadyRetur
} }
}; };
auto mockEvent = std::make_unique<MockEventQuery>(eventPool.get(), 1u, device); auto mockEvent = std::make_unique<MockEventQuery>(eventPool, 1u, device);
ze_kernel_timestamp_result_t resultTimestamp = {}; ze_kernel_timestamp_result_t resultTimestamp = {};
@@ -583,11 +606,11 @@ TEST_F(EventPoolCreateMultiDevice, whenCreatingEventPoolWithMultipleDevicesThenE
result = zeDeviceGet(driverHandle.get(), &deviceCount, devices); result = zeDeviceGet(driverHandle.get(), &deviceCount, devices);
EXPECT_EQ(ZE_RESULT_SUCCESS, result); EXPECT_EQ(ZE_RESULT_SUCCESS, result);
std::unique_ptr<L0::EventPool> eventPool(EventPool::create(driverHandle.get(), L0::EventPool *eventPool = EventPool::create(driverHandle.get(),
context, context,
deviceCount, deviceCount,
devices, devices,
&eventPoolDesc)); &eventPoolDesc);
EXPECT_NE(nullptr, eventPool); EXPECT_NE(nullptr, eventPool);
auto allocation = &eventPool->getAllocation(); auto allocation = &eventPool->getAllocation();
@@ -596,6 +619,8 @@ TEST_F(EventPoolCreateMultiDevice, whenCreatingEventPoolWithMultipleDevicesThenE
EXPECT_EQ(allocation->getGraphicsAllocations().size(), numRootDevices); EXPECT_EQ(allocation->getGraphicsAllocations().size(), numRootDevices);
delete[] devices; delete[] devices;
eventPool->destroy();
} }
TEST_F(EventPoolCreateMultiDevice, whenCreatingEventPoolWithNoDevicesThenEventPoolCreateSucceedsAndAllDeviceAreUsed) { TEST_F(EventPoolCreateMultiDevice, whenCreatingEventPoolWithNoDevicesThenEventPoolCreateSucceedsAndAllDeviceAreUsed) {
@@ -655,15 +680,16 @@ struct EventPoolCreateNegativeTest : public ::testing::Test {
driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>(); driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
driverHandle->initialize(std::move(devices)); driverHandle->initialize(std::move(devices));
static_cast<MockMemoryManager *>(driverHandle.get()->getMemoryManager())->isMockEventPoolCreateMemoryManager = true;
device = driverHandle->devices[0];
ze_context_handle_t hContext; ze_context_handle_t hContext;
ze_context_desc_t desc; ze_context_desc_t desc;
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext); ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res); EXPECT_EQ(ZE_RESULT_SUCCESS, res);
context = static_cast<ContextImp *>(Context::fromHandle(hContext)); context = static_cast<ContextImp *>(Context::fromHandle(hContext));
static_cast<MockMemoryManager *>(driverHandle.get()->getMemoryManager())->isMockEventPoolCreateMemoryManager = true;
device = driverHandle->devices[0];
} }
void TearDown() override { void TearDown() override {
context->destroy(); context->destroy();

View File

@@ -136,6 +136,13 @@ HWTEST_F(FenceAubCsrTest, givenCallToFenceHostSynchronizeWithAubModeCsrReturnsSu
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice)); devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>(); driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
driverHandle->initialize(std::move(devices)); driverHandle->initialize(std::move(devices));
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
L0::ContextImp *context = static_cast<ContextImp *>(Context::fromHandle(hContext));
device = driverHandle->devices[0]; device = driverHandle->devices[0];
int32_t tag; int32_t tag;
auto aubCsr = new MockCsrAub<FamilyType>(tag, *neoDevice->executionEnvironment, neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()); auto aubCsr = new MockCsrAub<FamilyType>(tag, *neoDevice->executionEnvironment, neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield());
@@ -147,6 +154,8 @@ HWTEST_F(FenceAubCsrTest, givenCallToFenceHostSynchronizeWithAubModeCsrReturnsSu
ze_result_t result = fence->hostSynchronize(10); ze_result_t result = fence->hostSynchronize(10);
EXPECT_EQ(ZE_RESULT_SUCCESS, result); EXPECT_EQ(ZE_RESULT_SUCCESS, result);
fence->destroy(); fence->destroy();
context->destroy();
} }
} // namespace ult } // namespace ult

View File

@@ -44,14 +44,15 @@ TEST_F(KernelInitTest, givenKernelToInitWhenItHasUnknownArgThenUnknowKernelArgHa
std::make_unique<MockImmutableData>(perHwThreadPrivateMemorySizeRequested); std::make_unique<MockImmutableData>(perHwThreadPrivateMemorySizeRequested);
createModuleFromBinary(perHwThreadPrivateMemorySizeRequested, false, mockKernelImmData.get()); createModuleFromBinary(perHwThreadPrivateMemorySizeRequested, false, mockKernelImmData.get());
std::unique_ptr<ModuleImmutableDataFixture::MockKernel> kernel; ModuleImmutableDataFixture::MockKernel *kernel = new ModuleImmutableDataFixture::MockKernel(module);
kernel = std::make_unique<ModuleImmutableDataFixture::MockKernel>(module.get());
ze_kernel_desc_t desc = {}; ze_kernel_desc_t desc = {};
desc.pKernelName = kernelName.c_str(); desc.pKernelName = kernelName.c_str();
mockKernelImmData->resizeExplicitArgs(1); mockKernelImmData->resizeExplicitArgs(1);
kernel->initialize(&desc); kernel->initialize(&desc);
EXPECT_EQ(kernel->kernelArgHandlers[0], &KernelImp::setArgUnknown); EXPECT_EQ(kernel->kernelArgHandlers[0], &KernelImp::setArgUnknown);
EXPECT_EQ(mockKernelImmData->getDescriptor().payloadMappings.explicitArgs[0].type, NEO::ArgDescriptor::ArgTUnknown); EXPECT_EQ(mockKernelImmData->getDescriptor().payloadMappings.explicitArgs[0].type, NEO::ArgDescriptor::ArgTUnknown);
delete kernel;
} }
TEST(KernelArgTest, givenKernelWhenSetArgUnknownCalledThenSuccessRteurned) { TEST(KernelArgTest, givenKernelWhenSetArgUnknownCalledThenSuccessRteurned) {
@@ -258,7 +259,7 @@ HWTEST_F(KernelImmutableDataTests, givenKernelInitializedWithNoPrivateMemoryThen
createModuleFromBinary(perHwThreadPrivateMemorySizeRequested, isInternal, mockKernelImmData.get()); createModuleFromBinary(perHwThreadPrivateMemorySizeRequested, isInternal, mockKernelImmData.get());
std::unique_ptr<ModuleImmutableDataFixture::MockKernel> kernel; std::unique_ptr<ModuleImmutableDataFixture::MockKernel> kernel;
kernel = std::make_unique<ModuleImmutableDataFixture::MockKernel>(module.get()); kernel = std::make_unique<ModuleImmutableDataFixture::MockKernel>(module);
createKernel(kernel.get()); createKernel(kernel.get());
@@ -274,7 +275,7 @@ HWTEST_F(KernelImmutableDataTests, givenKernelInitializedWithPrivateMemoryThenPr
createModuleFromBinary(perHwThreadPrivateMemorySizeRequested, isInternal, mockKernelImmData.get()); createModuleFromBinary(perHwThreadPrivateMemorySizeRequested, isInternal, mockKernelImmData.get());
std::unique_ptr<ModuleImmutableDataFixture::MockKernel> kernel; std::unique_ptr<ModuleImmutableDataFixture::MockKernel> kernel;
kernel = std::make_unique<ModuleImmutableDataFixture::MockKernel>(module.get()); kernel = std::make_unique<ModuleImmutableDataFixture::MockKernel>(module);
createKernel(kernel.get()); createKernel(kernel.get());
@@ -309,7 +310,7 @@ HWTEST_F(KernelImmutableDataIsaCopyTests, whenUserKernelIsCreatedThenIsaIsaCopie
mockMemoryManager->copyMemoryToAllocationCalledTimes); mockMemoryManager->copyMemoryToAllocationCalledTimes);
std::unique_ptr<ModuleImmutableDataFixture::MockKernel> kernel; std::unique_ptr<ModuleImmutableDataFixture::MockKernel> kernel;
kernel = std::make_unique<ModuleImmutableDataFixture::MockKernel>(module.get()); kernel = std::make_unique<ModuleImmutableDataFixture::MockKernel>(module);
createKernel(kernel.get()); createKernel(kernel.get());
@@ -339,7 +340,7 @@ HWTEST_F(KernelImmutableDataIsaCopyTests, whenInternalKernelIsCreatedThenIsaIsCo
mockMemoryManager->copyMemoryToAllocationCalledTimes); mockMemoryManager->copyMemoryToAllocationCalledTimes);
std::unique_ptr<ModuleImmutableDataFixture::MockKernel> kernel; std::unique_ptr<ModuleImmutableDataFixture::MockKernel> kernel;
kernel = std::make_unique<ModuleImmutableDataFixture::MockKernel>(module.get()); kernel = std::make_unique<ModuleImmutableDataFixture::MockKernel>(module);
createKernel(kernel.get()); createKernel(kernel.get());
@@ -364,8 +365,8 @@ HWTEST_F(KernelImmutableDataIsaCopyTests, whenImmutableDataIsInitializedForUserK
mockKernelImmData->initialize(mockKernelImmData->mockKernelInfo, device, mockKernelImmData->initialize(mockKernelImmData->mockKernelInfo, device,
device->getNEODevice()->getDeviceInfo().computeUnitsUsedForScratch, device->getNEODevice()->getDeviceInfo().computeUnitsUsedForScratch,
module.get()->translationUnit->globalConstBuffer, module->translationUnit->globalConstBuffer,
module.get()->translationUnit->globalVarBuffer, module->translationUnit->globalVarBuffer,
isInternal); isInternal);
EXPECT_EQ(previouscopyMemoryToAllocationCalledTimes + 1u, EXPECT_EQ(previouscopyMemoryToAllocationCalledTimes + 1u,
@@ -387,8 +388,8 @@ HWTEST_F(KernelImmutableDataIsaCopyTests, whenImmutableDataIsInitializedForInter
mockKernelImmData->initialize(mockKernelImmData->mockKernelInfo, device, mockKernelImmData->initialize(mockKernelImmData->mockKernelInfo, device,
device->getNEODevice()->getDeviceInfo().computeUnitsUsedForScratch, device->getNEODevice()->getDeviceInfo().computeUnitsUsedForScratch,
module.get()->translationUnit->globalConstBuffer, module->translationUnit->globalConstBuffer,
module.get()->translationUnit->globalVarBuffer, module->translationUnit->globalVarBuffer,
isInternal); isInternal);
EXPECT_EQ(previouscopyMemoryToAllocationCalledTimes, EXPECT_EQ(previouscopyMemoryToAllocationCalledTimes,
@@ -415,8 +416,8 @@ HWTEST_F(KernelImmutableDataWithNullHeapTests, whenImmutableDataIsInitializedFor
mockKernelImmData->initialize(mockKernelImmData->mockKernelInfo, device, mockKernelImmData->initialize(mockKernelImmData->mockKernelInfo, device,
device->getNEODevice()->getDeviceInfo().computeUnitsUsedForScratch, device->getNEODevice()->getDeviceInfo().computeUnitsUsedForScratch,
module.get()->translationUnit->globalConstBuffer, module->translationUnit->globalConstBuffer,
module.get()->translationUnit->globalVarBuffer, module->translationUnit->globalVarBuffer,
isInternal); isInternal);
EXPECT_EQ(previouscopyMemoryToAllocationCalledTimes, EXPECT_EQ(previouscopyMemoryToAllocationCalledTimes,
@@ -443,8 +444,8 @@ HWTEST_F(KernelImmutableDataWithNullHeapTests, whenImmutableDataIsInitializedFor
mockKernelImmData->initialize(mockKernelImmData->mockKernelInfo, device, mockKernelImmData->initialize(mockKernelImmData->mockKernelInfo, device,
device->getNEODevice()->getDeviceInfo().computeUnitsUsedForScratch, device->getNEODevice()->getDeviceInfo().computeUnitsUsedForScratch,
module.get()->translationUnit->globalConstBuffer, module->translationUnit->globalConstBuffer,
module.get()->translationUnit->globalVarBuffer, module->translationUnit->globalVarBuffer,
isInternal); isInternal);
EXPECT_EQ(previouscopyMemoryToAllocationCalledTimes, EXPECT_EQ(previouscopyMemoryToAllocationCalledTimes,
@@ -475,7 +476,7 @@ HWTEST_F(KernelImmutableDataWithNullHeapTests, whenInternalKernelIsCreatedWithNu
mockMemoryManager->copyMemoryToAllocationCalledTimes); mockMemoryManager->copyMemoryToAllocationCalledTimes);
std::unique_ptr<ModuleImmutableDataFixture::MockKernel> kernel; std::unique_ptr<ModuleImmutableDataFixture::MockKernel> kernel;
kernel = std::make_unique<ModuleImmutableDataFixture::MockKernel>(module.get()); kernel = std::make_unique<ModuleImmutableDataFixture::MockKernel>(module);
auto previousKernelHeap = mockKernelImmData->kernelInfo->heapInfo.pKernelHeap; auto previousKernelHeap = mockKernelImmData->kernelInfo->heapInfo.pKernelHeap;
mockKernelImmData->kernelInfo->heapInfo.pKernelHeap = nullptr; mockKernelImmData->kernelInfo->heapInfo.pKernelHeap = nullptr;
@@ -559,7 +560,7 @@ HWTEST_F(KernelIndirectPropertiesFromIGCTests, whenInitializingKernelWithNoKerne
createModuleFromBinary(perHwThreadPrivateMemorySizeRequested, isInternal, mockKernelImmData.get()); createModuleFromBinary(perHwThreadPrivateMemorySizeRequested, isInternal, mockKernelImmData.get());
std::unique_ptr<ModuleImmutableDataFixture::MockKernel> kernel; std::unique_ptr<ModuleImmutableDataFixture::MockKernel> kernel;
kernel = std::make_unique<ModuleImmutableDataFixture::MockKernel>(module.get()); kernel = std::make_unique<ModuleImmutableDataFixture::MockKernel>(module);
ze_kernel_desc_t desc = {}; ze_kernel_desc_t desc = {};
desc.pKernelName = kernelName.c_str(); desc.pKernelName = kernelName.c_str();
@@ -587,7 +588,7 @@ HWTEST_F(KernelIndirectPropertiesFromIGCTests, whenInitializingKernelWithKernelL
{ {
std::unique_ptr<ModuleImmutableDataFixture::MockKernel> kernel; std::unique_ptr<ModuleImmutableDataFixture::MockKernel> kernel;
kernel = std::make_unique<ModuleImmutableDataFixture::MockKernel>(module.get()); kernel = std::make_unique<ModuleImmutableDataFixture::MockKernel>(module);
ze_kernel_desc_t desc = {}; ze_kernel_desc_t desc = {};
desc.pKernelName = kernelName.c_str(); desc.pKernelName = kernelName.c_str();
@@ -603,7 +604,7 @@ HWTEST_F(KernelIndirectPropertiesFromIGCTests, whenInitializingKernelWithKernelL
{ {
std::unique_ptr<ModuleImmutableDataFixture::MockKernel> kernel; std::unique_ptr<ModuleImmutableDataFixture::MockKernel> kernel;
kernel = std::make_unique<ModuleImmutableDataFixture::MockKernel>(module.get()); kernel = std::make_unique<ModuleImmutableDataFixture::MockKernel>(module);
ze_kernel_desc_t desc = {}; ze_kernel_desc_t desc = {};
desc.pKernelName = kernelName.c_str(); desc.pKernelName = kernelName.c_str();
@@ -619,7 +620,7 @@ HWTEST_F(KernelIndirectPropertiesFromIGCTests, whenInitializingKernelWithKernelL
{ {
std::unique_ptr<ModuleImmutableDataFixture::MockKernel> kernel; std::unique_ptr<ModuleImmutableDataFixture::MockKernel> kernel;
kernel = std::make_unique<ModuleImmutableDataFixture::MockKernel>(module.get()); kernel = std::make_unique<ModuleImmutableDataFixture::MockKernel>(module);
ze_kernel_desc_t desc = {}; ze_kernel_desc_t desc = {};
desc.pKernelName = kernelName.c_str(); desc.pKernelName = kernelName.c_str();
@@ -932,7 +933,7 @@ HWTEST_F(KernelPropertiesTests, givenValidKernelAndNoMediavfestateThenSpillMemSi
ze_result_t res = kernel->getProperties(&kernelProperties); ze_result_t res = kernel->getProperties(&kernelProperties);
EXPECT_EQ(ZE_RESULT_SUCCESS, res); EXPECT_EQ(ZE_RESULT_SUCCESS, res);
L0::ModuleImp *moduleImp = reinterpret_cast<L0::ModuleImp *>(module.get()); L0::ModuleImp *moduleImp = reinterpret_cast<L0::ModuleImp *>(module);
NEO::KernelInfo *ki = nullptr; NEO::KernelInfo *ki = nullptr;
for (uint32_t i = 0; i < moduleImp->getTranslationUnit()->programInfo.kernelInfos.size(); i++) { for (uint32_t i = 0; i < moduleImp->getTranslationUnit()->programInfo.kernelInfos.size(); i++) {
ki = moduleImp->getTranslationUnit()->programInfo.kernelInfos[i]; ki = moduleImp->getTranslationUnit()->programInfo.kernelInfos[i];
@@ -955,7 +956,7 @@ HWTEST_F(KernelPropertiesTests, givenValidKernelAndNollocateStatelessPrivateSurf
ze_result_t res = kernel->getProperties(&kernelProperties); ze_result_t res = kernel->getProperties(&kernelProperties);
EXPECT_EQ(ZE_RESULT_SUCCESS, res); EXPECT_EQ(ZE_RESULT_SUCCESS, res);
L0::ModuleImp *moduleImp = reinterpret_cast<L0::ModuleImp *>(module.get()); L0::ModuleImp *moduleImp = reinterpret_cast<L0::ModuleImp *>(module);
NEO::KernelInfo *ki = nullptr; NEO::KernelInfo *ki = nullptr;
for (uint32_t i = 0; i < moduleImp->getTranslationUnit()->programInfo.kernelInfos.size(); i++) { for (uint32_t i = 0; i < moduleImp->getTranslationUnit()->programInfo.kernelInfos.size(); i++) {
ki = moduleImp->getTranslationUnit()->programInfo.kernelInfos[i]; ki = moduleImp->getTranslationUnit()->programInfo.kernelInfos[i];
@@ -1222,7 +1223,7 @@ HWTEST2_F(KernelImpPatchBindlessTest, GivenKernelImpWhenSetSurfaceStateBindlessT
desc.pKernelName = kernelName.c_str(); desc.pKernelName = kernelName.c_str();
WhiteBoxKernelHw<gfxCoreFamily> mockKernel; WhiteBoxKernelHw<gfxCoreFamily> mockKernel;
mockKernel.module = module.get(); mockKernel.module = module;
mockKernel.initialize(&desc); mockKernel.initialize(&desc);
auto &arg = const_cast<NEO::ArgDescPointer &>(mockKernel.kernelImmData->getDescriptor().payloadMappings.explicitArgs[0].template as<NEO::ArgDescPointer>()); auto &arg = const_cast<NEO::ArgDescPointer &>(mockKernel.kernelImmData->getDescriptor().payloadMappings.explicitArgs[0].template as<NEO::ArgDescPointer>());
arg.bindless = 0x40; arg.bindless = 0x40;
@@ -1253,7 +1254,7 @@ HWTEST2_F(KernelImpPatchBindlessTest, GivenKernelImpWhenSetSurfaceStateBindfulTh
desc.pKernelName = kernelName.c_str(); desc.pKernelName = kernelName.c_str();
WhiteBoxKernelHw<gfxCoreFamily> mockKernel; WhiteBoxKernelHw<gfxCoreFamily> mockKernel;
mockKernel.module = module.get(); mockKernel.module = module;
mockKernel.initialize(&desc); mockKernel.initialize(&desc);
auto &arg = const_cast<NEO::ArgDescPointer &>(mockKernel.kernelImmData->getDescriptor().payloadMappings.explicitArgs[0].template as<NEO::ArgDescPointer>()); auto &arg = const_cast<NEO::ArgDescPointer &>(mockKernel.kernelImmData->getDescriptor().payloadMappings.explicitArgs[0].template as<NEO::ArgDescPointer>());
@@ -1293,7 +1294,7 @@ TEST_F(KernelImpPatchBindlessTest, GivenValidBindlessOffsetWhenSetArgBufferWithA
desc.pKernelName = kernelName.c_str(); desc.pKernelName = kernelName.c_str();
MyMockKernel mockKernel; MyMockKernel mockKernel;
mockKernel.module = module.get(); mockKernel.module = module;
mockKernel.initialize(&desc); mockKernel.initialize(&desc);
auto &arg = const_cast<NEO::ArgDescPointer &>(mockKernel.kernelImmData->getDescriptor().payloadMappings.explicitArgs[0].as<NEO::ArgDescPointer>()); auto &arg = const_cast<NEO::ArgDescPointer &>(mockKernel.kernelImmData->getDescriptor().payloadMappings.explicitArgs[0].as<NEO::ArgDescPointer>());
@@ -1312,7 +1313,7 @@ TEST_F(KernelImpPatchBindlessTest, GivenValidBindfulOffsetWhenSetArgBufferWithAl
desc.pKernelName = kernelName.c_str(); desc.pKernelName = kernelName.c_str();
MyMockKernel mockKernel; MyMockKernel mockKernel;
mockKernel.module = module.get(); mockKernel.module = module;
mockKernel.initialize(&desc); mockKernel.initialize(&desc);
auto &arg = const_cast<NEO::ArgDescPointer &>(mockKernel.kernelImmData->getDescriptor().payloadMappings.explicitArgs[0].as<NEO::ArgDescPointer>()); auto &arg = const_cast<NEO::ArgDescPointer &>(mockKernel.kernelImmData->getDescriptor().payloadMappings.explicitArgs[0].as<NEO::ArgDescPointer>());
@@ -1331,7 +1332,7 @@ TEST_F(KernelImpPatchBindlessTest, GivenUndefiedBidfulAndBindlesstOffsetWhenSetA
desc.pKernelName = kernelName.c_str(); desc.pKernelName = kernelName.c_str();
MyMockKernel mockKernel; MyMockKernel mockKernel;
mockKernel.module = module.get(); mockKernel.module = module;
mockKernel.initialize(&desc); mockKernel.initialize(&desc);
auto &arg = const_cast<NEO::ArgDescPointer &>(mockKernel.kernelImmData->getDescriptor().payloadMappings.explicitArgs[0].as<NEO::ArgDescPointer>()); auto &arg = const_cast<NEO::ArgDescPointer &>(mockKernel.kernelImmData->getDescriptor().payloadMappings.explicitArgs[0].as<NEO::ArgDescPointer>());
@@ -1352,7 +1353,7 @@ TEST_F(KernelBindlessUncachedMemoryTests, givenBindlessKernelAndAllocDataNoTfoun
desc.pKernelName = kernelName.c_str(); desc.pKernelName = kernelName.c_str();
MyMockKernel mockKernel; MyMockKernel mockKernel;
mockKernel.module = module.get(); mockKernel.module = module;
mockKernel.initialize(&desc); mockKernel.initialize(&desc);
auto &arg = const_cast<NEO::ArgDescPointer &>(mockKernel.kernelImmData->getDescriptor().payloadMappings.explicitArgs[0].as<NEO::ArgDescPointer>()); auto &arg = const_cast<NEO::ArgDescPointer &>(mockKernel.kernelImmData->getDescriptor().payloadMappings.explicitArgs[0].as<NEO::ArgDescPointer>());
@@ -1371,7 +1372,7 @@ TEST_F(KernelBindlessUncachedMemoryTests,
desc.pKernelName = kernelName.c_str(); desc.pKernelName = kernelName.c_str();
MyMockKernel mockKernel; MyMockKernel mockKernel;
mockKernel.module = module.get(); mockKernel.module = module;
mockKernel.initialize(&desc); mockKernel.initialize(&desc);
auto &arg = const_cast<NEO::ArgDescPointer &>(mockKernel.kernelImmData->getDescriptor().payloadMappings.explicitArgs[0].as<NEO::ArgDescPointer>()); auto &arg = const_cast<NEO::ArgDescPointer &>(mockKernel.kernelImmData->getDescriptor().payloadMappings.explicitArgs[0].as<NEO::ArgDescPointer>());
@@ -1421,7 +1422,7 @@ TEST_F(KernelBindlessUncachedMemoryTests,
desc.pKernelName = kernelName.c_str(); desc.pKernelName = kernelName.c_str();
MyMockKernel mockKernel; MyMockKernel mockKernel;
mockKernel.module = module.get(); mockKernel.module = module;
mockKernel.initialize(&desc); mockKernel.initialize(&desc);
auto &arg = const_cast<NEO::ArgDescPointer &>(mockKernel.kernelImmData->getDescriptor().payloadMappings.explicitArgs[0].as<NEO::ArgDescPointer>()); auto &arg = const_cast<NEO::ArgDescPointer &>(mockKernel.kernelImmData->getDescriptor().payloadMappings.explicitArgs[0].as<NEO::ArgDescPointer>());
@@ -1473,7 +1474,7 @@ TEST_F(KernelBindlessUncachedMemoryTests,
desc.pKernelName = kernelName.c_str(); desc.pKernelName = kernelName.c_str();
MyMockKernel mockKernel; MyMockKernel mockKernel;
mockKernel.module = module.get(); mockKernel.module = module;
mockKernel.initialize(&desc); mockKernel.initialize(&desc);
auto &arg = const_cast<NEO::ArgDescPointer &>(mockKernel.kernelImmData->getDescriptor().payloadMappings.explicitArgs[0].as<NEO::ArgDescPointer>()); auto &arg = const_cast<NEO::ArgDescPointer &>(mockKernel.kernelImmData->getDescriptor().payloadMappings.explicitArgs[0].as<NEO::ArgDescPointer>());
@@ -1657,8 +1658,8 @@ TEST_F(KernelPrintHandlerTest, whenPrintPrintfOutputIsCalledThenPrintfBufferIsUs
ze_kernel_desc_t desc = {}; ze_kernel_desc_t desc = {};
desc.pKernelName = kernelName.c_str(); desc.pKernelName = kernelName.c_str();
kernel = std::make_unique<WhiteBox<::L0::Kernel>>(); kernel = new WhiteBox<::L0::Kernel>();
kernel->module = module.get(); kernel->module = module;
kernel->initialize(&desc); kernel->initialize(&desc);
EXPECT_FALSE(kernel->printfBuffer == nullptr); EXPECT_FALSE(kernel->printfBuffer == nullptr);

View File

@@ -122,21 +122,26 @@ struct OutOfMemoryTests : public ::testing::Test {
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice)); devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
driverHandle = std::make_unique<DriverHandleOutOfMemoryMock>(); driverHandle = std::make_unique<DriverHandleOutOfMemoryMock>();
driverHandle->initialize(std::move(devices)); driverHandle->initialize(std::move(devices));
prevSvmAllocsManager = driverHandle->svmAllocsManager;
currSvmAllocsManager = new SVMAllocsManagerOutOFMemoryMock(driverHandle->memoryManager);
driverHandle->svmAllocsManager = currSvmAllocsManager;
device = driverHandle->devices[0]; device = driverHandle->devices[0];
context = std::make_unique<ContextImp>(driverHandle.get()); context = new ContextImp(driverHandle.get());
EXPECT_NE(context, nullptr); EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->toHandle(), device)); context->getDevices().insert(std::make_pair(device->toHandle(), device));
auto neoDevice = device->getNEODevice(); auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
context->setMemoryManager(context->getDevices().begin()->second->getNEODevice()->getMemoryManager());
context->setSvmAllocsManager(new NEO::SVMAllocsManager(context->getMemoryManager(), false));
driverHandle->mainContext = context;
prevSvmAllocsManager = context->getSvmAllocsManager();
currSvmAllocsManager = new SVMAllocsManagerOutOFMemoryMock(context->getMemoryManager());
context->setSvmAllocsManager(currSvmAllocsManager);
} }
void TearDown() override { void TearDown() override {
driverHandle->svmAllocsManager = prevSvmAllocsManager; context->setSvmAllocsManager(prevSvmAllocsManager);
context->destroy();
delete currSvmAllocsManager; delete currSvmAllocsManager;
} }
NEO::SVMAllocsManager *prevSvmAllocsManager; NEO::SVMAllocsManager *prevSvmAllocsManager;
@@ -144,7 +149,7 @@ struct OutOfMemoryTests : public ::testing::Test {
std::unique_ptr<DriverHandleOutOfMemoryMock> driverHandle; std::unique_ptr<DriverHandleOutOfMemoryMock> driverHandle;
NEO::MockDevice *neoDevice = nullptr; NEO::MockDevice *neoDevice = nullptr;
L0::Device *device = nullptr; L0::Device *device = nullptr;
std::unique_ptr<ContextImp> context; L0::ContextImp *context = nullptr;
}; };
TEST_F(OutOfMemoryTests, TEST_F(OutOfMemoryTests,
@@ -198,21 +203,26 @@ struct MemoryRelaxedSizeTests : public ::testing::Test {
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice)); devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
driverHandle = std::make_unique<DriverHandleImp>(); driverHandle = std::make_unique<DriverHandleImp>();
driverHandle->initialize(std::move(devices)); driverHandle->initialize(std::move(devices));
prevSvmAllocsManager = driverHandle->svmAllocsManager;
currSvmAllocsManager = new SVMAllocsManagerRelaxedSizeMock(driverHandle->memoryManager);
driverHandle->svmAllocsManager = currSvmAllocsManager;
device = driverHandle->devices[0]; device = driverHandle->devices[0];
context = std::make_unique<ContextRelaxedSizeMock>(driverHandle.get()); context = new ContextRelaxedSizeMock(driverHandle.get());
EXPECT_NE(context, nullptr); EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->toHandle(), device)); context->getDevices().insert(std::make_pair(device->toHandle(), device));
auto neoDevice = device->getNEODevice(); auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
context->setMemoryManager(context->getDevices().begin()->second->getNEODevice()->getMemoryManager());
context->setSvmAllocsManager(new NEO::SVMAllocsManager(context->getMemoryManager(), false));
driverHandle->mainContext = context;
prevSvmAllocsManager = context->getSvmAllocsManager();
currSvmAllocsManager = new SVMAllocsManagerRelaxedSizeMock(context->getMemoryManager());
context->setSvmAllocsManager(currSvmAllocsManager);
} }
void TearDown() override { void TearDown() override {
driverHandle->svmAllocsManager = prevSvmAllocsManager; context->setSvmAllocsManager(prevSvmAllocsManager);
context->destroy();
delete currSvmAllocsManager; delete currSvmAllocsManager;
} }
NEO::SVMAllocsManager *prevSvmAllocsManager; NEO::SVMAllocsManager *prevSvmAllocsManager;
@@ -220,7 +230,7 @@ struct MemoryRelaxedSizeTests : public ::testing::Test {
std::unique_ptr<DriverHandleImp> driverHandle; std::unique_ptr<DriverHandleImp> driverHandle;
NEO::MockDevice *neoDevice = nullptr; NEO::MockDevice *neoDevice = nullptr;
L0::Device *device = nullptr; L0::Device *device = nullptr;
std::unique_ptr<ContextRelaxedSizeMock> context; L0::ContextImp *context = nullptr;
}; };
TEST_F(MemoryRelaxedSizeTests, TEST_F(MemoryRelaxedSizeTests,
@@ -549,21 +559,29 @@ struct MemoryExportImportFailTest : public ::testing::Test {
driverHandle->initialize(std::move(devices)); driverHandle->initialize(std::move(devices));
device = driverHandle->devices[0]; device = driverHandle->devices[0];
context = std::make_unique<ContextFailFdMock>(driverHandle.get()); context = new ContextFailFdMock(driverHandle.get());
EXPECT_NE(context, nullptr); EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->toHandle(), device)); context->getDevices().insert(std::make_pair(device->toHandle(), device));
auto neoDevice = device->getNEODevice(); auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
context->setMemoryManager(context->getDevices().begin()->second->getNEODevice()->getMemoryManager());
context->setSvmAllocsManager(new NEO::SVMAllocsManager(context->getMemoryManager(), false));
driverHandle->mainContext = context;
driverHandle->setMemoryManager(context->getMemoryManager());
driverHandle->setSvmAllocsManager(context->getSvmAllocsManager());
driverHandle->mainContext = context;
} }
void TearDown() override { void TearDown() override {
context->destroy();
} }
std::unique_ptr<DriverHandleFailGetFdMock> driverHandle; std::unique_ptr<DriverHandleFailGetFdMock> driverHandle;
NEO::MockDevice *neoDevice = nullptr; NEO::MockDevice *neoDevice = nullptr;
L0::Device *device = nullptr; L0::Device *device = nullptr;
ze_context_handle_t hContext; ze_context_handle_t hContext;
std::unique_ptr<ContextFailFdMock> context; ContextFailFdMock *context = nullptr;
}; };
TEST_F(MemoryExportImportFailTest, TEST_F(MemoryExportImportFailTest,
@@ -667,21 +685,27 @@ struct MemoryExportImportTest : public ::testing::Test {
driverHandle->initialize(std::move(devices)); driverHandle->initialize(std::move(devices));
device = driverHandle->devices[0]; device = driverHandle->devices[0];
context = std::make_unique<ContextFdMock>(driverHandle.get()); context = new ContextFdMock(driverHandle.get());
EXPECT_NE(context, nullptr); EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->toHandle(), device)); context->getDevices().insert(std::make_pair(device->toHandle(), device));
auto neoDevice = device->getNEODevice(); auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
context->setMemoryManager(context->getDevices().begin()->second->getNEODevice()->getMemoryManager());
context->setSvmAllocsManager(new NEO::SVMAllocsManager(context->getMemoryManager(), false));
driverHandle->mainContext = context;
driverHandle->setMemoryManager(context->getMemoryManager());
driverHandle->setSvmAllocsManager(context->getSvmAllocsManager());
} }
void TearDown() override { void TearDown() override {
context->destroy();
} }
std::unique_ptr<DriverHandleGetFdMock> driverHandle; std::unique_ptr<DriverHandleGetFdMock> driverHandle;
NEO::MockDevice *neoDevice = nullptr; NEO::MockDevice *neoDevice = nullptr;
L0::Device *device = nullptr; L0::Device *device = nullptr;
ze_context_handle_t hContext; ze_context_handle_t hContext;
std::unique_ptr<ContextFdMock> context; ContextFdMock *context = nullptr;
}; };
TEST_F(MemoryExportImportTest, TEST_F(MemoryExportImportTest,
@@ -1087,21 +1111,27 @@ struct MemoryGetIpcHandleTest : public ::testing::Test {
driverHandle->initialize(std::move(devices)); driverHandle->initialize(std::move(devices));
device = driverHandle->devices[0]; device = driverHandle->devices[0];
context = std::make_unique<ContextGetIpcHandleMock>(driverHandle.get()); context = new ContextGetIpcHandleMock(driverHandle.get());
EXPECT_NE(context, nullptr); EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->toHandle(), device)); context->getDevices().insert(std::make_pair(device->toHandle(), device));
auto neoDevice = device->getNEODevice(); auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
context->setMemoryManager(context->getDevices().begin()->second->getNEODevice()->getMemoryManager());
context->setSvmAllocsManager(new NEO::SVMAllocsManager(context->getMemoryManager(), false));
driverHandle->mainContext = context;
driverHandle->setMemoryManager(context->getMemoryManager());
driverHandle->setSvmAllocsManager(context->getSvmAllocsManager());
} }
void TearDown() override { void TearDown() override {
context->destroy();
} }
std::unique_ptr<DriverHandleGetIpcHandleMock> driverHandle; std::unique_ptr<DriverHandleGetIpcHandleMock> driverHandle;
NEO::MockDevice *neoDevice = nullptr; NEO::MockDevice *neoDevice = nullptr;
L0::Device *device = nullptr; L0::Device *device = nullptr;
std::unique_ptr<ContextGetIpcHandleMock> context; ContextGetIpcHandleMock *context = nullptr;
}; };
TEST_F(MemoryGetIpcHandleTest, TEST_F(MemoryGetIpcHandleTest,
@@ -1209,21 +1239,31 @@ struct MemoryOpenIpcHandleTest : public ::testing::Test {
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice)); devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
driverHandle = std::make_unique<DriverHandleImp>(); driverHandle = std::make_unique<DriverHandleImp>();
driverHandle->initialize(std::move(devices)); driverHandle->initialize(std::move(devices));
prevMemoryManager = driverHandle->getMemoryManager();
currMemoryManager = new MemoryManagerOpenIpcMock(*neoDevice->executionEnvironment);
driverHandle->setMemoryManager(currMemoryManager);
device = driverHandle->devices[0]; device = driverHandle->devices[0];
context = std::make_unique<ContextIpcMock>(driverHandle.get()); context = new ContextIpcMock(driverHandle.get());
EXPECT_NE(context, nullptr); EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->toHandle(), device)); context->getDevices().insert(std::make_pair(device->toHandle(), device));
auto neoDevice = device->getNEODevice(); {
context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); auto neoDevice = device->getNEODevice();
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}
context->setMemoryManager(context->getDevices().begin()->second->getNEODevice()->getMemoryManager());
context->setSvmAllocsManager(new NEO::SVMAllocsManager(context->getMemoryManager(), false));
driverHandle->mainContext = context;
prevMemoryManager = context->getMemoryManager();
currMemoryManager = new MemoryManagerOpenIpcMock(*neoDevice->executionEnvironment);
context->setMemoryManager(currMemoryManager);
driverHandle->setMemoryManager(context->getMemoryManager());
driverHandle->setSvmAllocsManager(context->getSvmAllocsManager());
} }
void TearDown() override { void TearDown() override {
driverHandle->setMemoryManager(prevMemoryManager); context->setMemoryManager(prevMemoryManager);
context->destroy();
delete currMemoryManager; delete currMemoryManager;
} }
NEO::MemoryManager *prevMemoryManager = nullptr; NEO::MemoryManager *prevMemoryManager = nullptr;
@@ -1231,7 +1271,7 @@ struct MemoryOpenIpcHandleTest : public ::testing::Test {
std::unique_ptr<DriverHandleImp> driverHandle; std::unique_ptr<DriverHandleImp> driverHandle;
NEO::MockDevice *neoDevice = nullptr; NEO::MockDevice *neoDevice = nullptr;
L0::Device *device = nullptr; L0::Device *device = nullptr;
std::unique_ptr<ContextIpcMock> context; ContextIpcMock *context = nullptr;
}; };
struct MultipleDevicePeerAllocationTest : public ::testing::Test { struct MultipleDevicePeerAllocationTest : public ::testing::Test {
@@ -1254,7 +1294,7 @@ struct MultipleDevicePeerAllocationTest : public ::testing::Test {
ModuleBuildLog *moduleBuildLog = nullptr; ModuleBuildLog *moduleBuildLog = nullptr;
module.reset(Module::create(device, &moduleDesc, moduleBuildLog, type)); module = Module::create(device, &moduleDesc, moduleBuildLog, type);
} }
void SetUp() override { void SetUp() override {
@@ -1276,11 +1316,9 @@ struct MultipleDevicePeerAllocationTest : public ::testing::Test {
} }
driverHandle = std::make_unique<DriverHandleImp>(); driverHandle = std::make_unique<DriverHandleImp>();
driverHandle->initialize(std::move(devices)); driverHandle->initialize(std::move(devices));
prevMemoryManager = driverHandle->getMemoryManager();
currMemoryManager = new MemoryManagerOpenIpcMock(*executionEnvironment);
driverHandle->setMemoryManager(currMemoryManager);
context = std::make_unique<ContextImp>(driverHandle.get()); context = new ContextImp(driverHandle.get());
bool multiOsContextDriver = false;
EXPECT_NE(context, nullptr); EXPECT_NE(context, nullptr);
for (auto i = 0u; i < numRootDevices; i++) { for (auto i = 0u; i < numRootDevices; i++) {
auto device = driverHandle->devices[i]; auto device = driverHandle->devices[i];
@@ -1288,20 +1326,39 @@ struct MultipleDevicePeerAllocationTest : public ::testing::Test {
auto neoDevice = device->getNEODevice(); auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
multiOsContextDriver |= device->isMultiDeviceCapable();
} }
context->setMemoryManager(context->getDevices().begin()->second->getNEODevice()->getMemoryManager());
context->setSvmAllocsManager(new NEO::SVMAllocsManager(context->getMemoryManager(), multiOsContextDriver));
driverHandle->mainContext = context;
prevMemoryManager = context->getMemoryManager();
currMemoryManager = new MemoryManagerOpenIpcMock(*executionEnvironment);
context->setMemoryManager(currMemoryManager);
driverHandle->setMemoryManager(context->getMemoryManager());
driverHandle->setSvmAllocsManager(context->getSvmAllocsManager());
} }
void createKernel() { void createKernel() {
ze_kernel_desc_t desc = {}; ze_kernel_desc_t desc = {};
desc.pKernelName = kernelName.c_str(); desc.pKernelName = kernelName.c_str();
kernel = std::make_unique<WhiteBox<::L0::Kernel>>(); kernel = new WhiteBox<::L0::Kernel>();
kernel->module = module.get(); kernel->module = module;
kernel->initialize(&desc); kernel->initialize(&desc);
} }
void TearDown() override { void TearDown() override {
driverHandle->setMemoryManager(prevMemoryManager); if (kernel) {
kernel->destroy();
}
if (module) {
module->destroy();
}
context->setMemoryManager(prevMemoryManager);
context->destroy();
delete currMemoryManager; delete currMemoryManager;
} }
@@ -1311,13 +1368,13 @@ struct MultipleDevicePeerAllocationTest : public ::testing::Test {
std::unique_ptr<DriverHandleImp> driverHandle; std::unique_ptr<DriverHandleImp> driverHandle;
std::unique_ptr<UltDeviceFactory> deviceFactory; std::unique_ptr<UltDeviceFactory> deviceFactory;
std::unique_ptr<ContextImp> context; L0::ContextImp *context = nullptr;
const std::string binaryFilename = "test_kernel"; const std::string binaryFilename = "test_kernel";
const std::string kernelName = "test"; const std::string kernelName = "test";
const uint32_t numKernelArguments = 6; const uint32_t numKernelArguments = 6;
std::unique_ptr<L0::Module> module; L0::Module *module = nullptr;
std::unique_ptr<WhiteBox<::L0::Kernel>> kernel; WhiteBox<::L0::Kernel> *kernel = nullptr;
const uint32_t numRootDevices = 2u; const uint32_t numRootDevices = 2u;
const uint32_t numSubDevices = 2u; const uint32_t numSubDevices = 2u;
@@ -1738,21 +1795,31 @@ struct MemoryFailedOpenIpcHandleTest : public ::testing::Test {
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice)); devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
driverHandle = std::make_unique<DriverHandleImp>(); driverHandle = std::make_unique<DriverHandleImp>();
driverHandle->initialize(std::move(devices)); driverHandle->initialize(std::move(devices));
prevMemoryManager = driverHandle->getMemoryManager();
currMemoryManager = new MemoryManagerIpcMock(*neoDevice->executionEnvironment);
driverHandle->setMemoryManager(currMemoryManager);
device = driverHandle->devices[0]; device = driverHandle->devices[0];
context = std::make_unique<ContextImp>(driverHandle.get()); context = new ContextImp(driverHandle.get());
EXPECT_NE(context, nullptr); EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->toHandle(), device)); context->getDevices().insert(std::make_pair(device->toHandle(), device));
auto neoDevice = device->getNEODevice(); {
context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); auto neoDevice = device->getNEODevice();
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}
context->setMemoryManager(context->getDevices().begin()->second->getNEODevice()->getMemoryManager());
context->setSvmAllocsManager(new NEO::SVMAllocsManager(context->getMemoryManager(), false));
driverHandle->mainContext = context;
prevMemoryManager = context->getMemoryManager();
currMemoryManager = new MemoryManagerIpcMock(*neoDevice->executionEnvironment);
context->setMemoryManager(currMemoryManager);
driverHandle->setMemoryManager(context->getMemoryManager());
driverHandle->setSvmAllocsManager(context->getSvmAllocsManager());
} }
void TearDown() override { void TearDown() override {
driverHandle->setMemoryManager(prevMemoryManager); context->setMemoryManager(prevMemoryManager);
context->destroy();
delete currMemoryManager; delete currMemoryManager;
} }
NEO::MemoryManager *prevMemoryManager = nullptr; NEO::MemoryManager *prevMemoryManager = nullptr;
@@ -1760,7 +1827,7 @@ struct MemoryFailedOpenIpcHandleTest : public ::testing::Test {
std::unique_ptr<DriverHandleImp> driverHandle; std::unique_ptr<DriverHandleImp> driverHandle;
NEO::MockDevice *neoDevice = nullptr; NEO::MockDevice *neoDevice = nullptr;
L0::Device *device = nullptr; L0::Device *device = nullptr;
std::unique_ptr<ContextImp> context; L0::ContextImp *context;
}; };
TEST_F(MemoryFailedOpenIpcHandleTest, TEST_F(MemoryFailedOpenIpcHandleTest,
@@ -1900,7 +1967,7 @@ TEST_F(MemoryTest, givenNoDeviceWhenAllocatingSharedMemoryThenDeviceInAllocation
&deviceDesc, &deviceDesc,
&hostDesc, &hostDesc,
size, alignment, &ptr); size, alignment, &ptr);
auto alloc = driverHandle->svmAllocsManager->getSVMAlloc(ptr); auto alloc = driverHandle->getSvmAllocsManager()->getSVMAlloc(ptr);
EXPECT_EQ(alloc->device, nullptr); EXPECT_EQ(alloc->device, nullptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result); EXPECT_EQ(ZE_RESULT_SUCCESS, result);
@@ -1993,17 +2060,22 @@ struct MemoryBitfieldTest : testing::Test {
ASSERT_NE(nullptr, driverHandle->devices[0]->toHandle()); ASSERT_NE(nullptr, driverHandle->devices[0]->toHandle());
EXPECT_NE(neoDevice->getDeviceBitfield(), memoryManager->recentlyPassedDeviceBitfield); EXPECT_NE(neoDevice->getDeviceBitfield(), memoryManager->recentlyPassedDeviceBitfield);
context = std::make_unique<ContextImp>(driverHandle.get()); context = new ContextImp(driverHandle.get());
EXPECT_NE(context, nullptr); EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->toHandle(), device)); context->getDevices().insert(std::make_pair(device->toHandle(), device));
auto neoDevice = device->getNEODevice(); auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
context->setMemoryManager(context->getDevices().begin()->second->getNEODevice()->getMemoryManager());
context->setSvmAllocsManager(new NEO::SVMAllocsManager(context->getMemoryManager(), false));
driverHandle->mainContext = context;
} }
void TearDown() override { void TearDown() override {
auto result = context->freeMem(ptr); auto result = context->freeMem(ptr);
ASSERT_EQ(result, ZE_RESULT_SUCCESS); ASSERT_EQ(result, ZE_RESULT_SUCCESS);
context->destroy();
} }
std::unique_ptr<Mock<L0::DriverHandleImp>> driverHandle; std::unique_ptr<Mock<L0::DriverHandleImp>> driverHandle;
@@ -2013,7 +2085,7 @@ struct MemoryBitfieldTest : testing::Test {
size_t size = 10; size_t size = 10;
size_t alignment = 1u; size_t alignment = 1u;
void *ptr = nullptr; void *ptr = nullptr;
std::unique_ptr<ContextImp> context; L0::ContextImp *context = nullptr;
}; };
TEST_F(MemoryBitfieldTest, givenDeviceWithValidBitfieldWhenAllocatingDeviceMemoryThenPassProperBitfield) { TEST_F(MemoryBitfieldTest, givenDeviceWithValidBitfieldWhenAllocatingDeviceMemoryThenPassProperBitfield) {
@@ -2051,13 +2123,15 @@ TEST(MemoryBitfieldTests, givenDeviceWithValidBitfieldWhenAllocatingSharedMemory
driverHandle->initialize(std::move(devices)); driverHandle->initialize(std::move(devices));
auto device = driverHandle->devices[0]; auto device = driverHandle->devices[0];
std::unique_ptr<ContextImp> context; ContextImp *context = new ContextImp(driverHandle.get());
context = std::make_unique<ContextImp>(driverHandle.get());
EXPECT_NE(context, nullptr); EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->toHandle(), device)); context->getDevices().insert(std::make_pair(device->toHandle(), device));
auto neoDevice = device->getNEODevice(); auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
context->setMemoryManager(context->getDevices().begin()->second->getNEODevice()->getMemoryManager());
context->setSvmAllocsManager(new NEO::SVMAllocsManager(context->getMemoryManager(), false));
driverHandle->mainContext = context;
memoryManager->recentlyPassedDeviceBitfield = {}; memoryManager->recentlyPassedDeviceBitfield = {};
ASSERT_NE(nullptr, driverHandle->devices[1]->toHandle()); ASSERT_NE(nullptr, driverHandle->devices[1]->toHandle());
@@ -2088,6 +2162,7 @@ TEST(MemoryBitfieldTests, givenDeviceWithValidBitfieldWhenAllocatingSharedMemory
EXPECT_NE(nullptr, ptr); EXPECT_NE(nullptr, ptr);
result = context->freeMem(ptr); result = context->freeMem(ptr);
ASSERT_EQ(result, ZE_RESULT_SUCCESS); ASSERT_EQ(result, ZE_RESULT_SUCCESS);
context->destroy();
} }
struct AllocHostMemoryTest : public ::testing::Test { struct AllocHostMemoryTest : public ::testing::Test {
@@ -2358,7 +2433,7 @@ TEST_F(ImportFdUncachedTests,
void *ptr = driverHandle->importFdHandle(device->toHandle(), flags, handle, nullptr); void *ptr = driverHandle->importFdHandle(device->toHandle(), flags, handle, nullptr);
EXPECT_NE(nullptr, ptr); EXPECT_NE(nullptr, ptr);
auto allocData = driverHandle->svmAllocsManager->getSVMAlloc(ptr); auto allocData = driverHandle->getSvmAllocsManager()->getSVMAlloc(ptr);
EXPECT_EQ(allocData->allocationFlagsProperty.flags.locallyUncachedResource, 1u); EXPECT_EQ(allocData->allocationFlagsProperty.flags.locallyUncachedResource, 1u);
context->freeMem(ptr); context->freeMem(ptr);
@@ -2371,7 +2446,7 @@ TEST_F(ImportFdUncachedTests,
void *ptr = driverHandle->importFdHandle(device->toHandle(), flags, handle, nullptr); void *ptr = driverHandle->importFdHandle(device->toHandle(), flags, handle, nullptr);
EXPECT_NE(nullptr, ptr); EXPECT_NE(nullptr, ptr);
auto allocData = driverHandle->svmAllocsManager->getSVMAlloc(ptr); auto allocData = driverHandle->getSvmAllocsManager()->getSVMAlloc(ptr);
EXPECT_EQ(allocData->allocationFlagsProperty.flags.locallyUncachedResource, 0u); EXPECT_EQ(allocData->allocationFlagsProperty.flags.locallyUncachedResource, 0u);
context->freeMem(ptr); context->freeMem(ptr);
@@ -2397,21 +2472,31 @@ struct SharedAllocFailTests : public ::testing::Test {
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice)); devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
driverHandle = std::make_unique<DriverHandleImp>(); driverHandle = std::make_unique<DriverHandleImp>();
driverHandle->initialize(std::move(devices)); driverHandle->initialize(std::move(devices));
prevSvmAllocsManager = driverHandle->svmAllocsManager;
currSvmAllocsManager = new SVMAllocsManagerSharedAllocFailMock(driverHandle->memoryManager);
driverHandle->svmAllocsManager = currSvmAllocsManager;
device = driverHandle->devices[0]; device = driverHandle->devices[0];
context = std::make_unique<ContextImp>(driverHandle.get()); context = new ContextImp(driverHandle.get());
EXPECT_NE(context, nullptr); EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->toHandle(), device)); context->getDevices().insert(std::make_pair(device->toHandle(), device));
auto neoDevice = device->getNEODevice(); {
context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); auto neoDevice = device->getNEODevice();
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}
context->setMemoryManager(context->getDevices().begin()->second->getNEODevice()->getMemoryManager());
context->setSvmAllocsManager(new NEO::SVMAllocsManager(context->getMemoryManager(), false));
driverHandle->mainContext = context;
prevSvmAllocsManager = context->getSvmAllocsManager();
currSvmAllocsManager = new SVMAllocsManagerSharedAllocFailMock(context->getMemoryManager());
context->setSvmAllocsManager(currSvmAllocsManager);
driverHandle->setMemoryManager(context->getMemoryManager());
driverHandle->setSvmAllocsManager(context->getSvmAllocsManager());
} }
void TearDown() override { void TearDown() override {
driverHandle->svmAllocsManager = prevSvmAllocsManager; context->setSvmAllocsManager(prevSvmAllocsManager);
context->destroy();
delete currSvmAllocsManager; delete currSvmAllocsManager;
} }
NEO::SVMAllocsManager *prevSvmAllocsManager; NEO::SVMAllocsManager *prevSvmAllocsManager;
@@ -2419,7 +2504,7 @@ struct SharedAllocFailTests : public ::testing::Test {
std::unique_ptr<DriverHandleImp> driverHandle; std::unique_ptr<DriverHandleImp> driverHandle;
NEO::MockDevice *neoDevice = nullptr; NEO::MockDevice *neoDevice = nullptr;
L0::Device *device = nullptr; L0::Device *device = nullptr;
std::unique_ptr<ContextImp> context; ContextImp *context;
}; };
TEST_F(SharedAllocFailTests, whenAllocatinSharedMemoryAndAllocationFailsThenOutOfDeviceMemoryIsReturned) { TEST_F(SharedAllocFailTests, whenAllocatinSharedMemoryAndAllocationFailsThenOutOfDeviceMemoryIsReturned) {
@@ -2446,7 +2531,7 @@ struct ContextMultiDeviceMock : public L0::ContextImp {
ContextMultiDeviceMock(L0::DriverHandleImp *driverHandle) : L0::ContextImp(driverHandle) {} ContextMultiDeviceMock(L0::DriverHandleImp *driverHandle) : L0::ContextImp(driverHandle) {}
ze_result_t freeMem(const void *ptr) override { ze_result_t freeMem(const void *ptr) override {
SVMAllocsManagerSharedAllocMultiDeviceMock *currSvmAllocsManager = SVMAllocsManagerSharedAllocMultiDeviceMock *currSvmAllocsManager =
static_cast<SVMAllocsManagerSharedAllocMultiDeviceMock *>(this->driverHandle->svmAllocsManager); static_cast<SVMAllocsManagerSharedAllocMultiDeviceMock *>(this->driverHandle->getSvmAllocsManager());
if (currSvmAllocsManager->createHostUnifiedMemoryAllocationTimes == 0) { if (currSvmAllocsManager->createHostUnifiedMemoryAllocationTimes == 0) {
return ContextImp::freeMem(ptr); return ContextImp::freeMem(ptr);
} }
@@ -2464,32 +2549,43 @@ struct SharedAllocMultiDeviceTests : public ::testing::Test {
driverHandle = std::make_unique<DriverHandleImp>(); driverHandle = std::make_unique<DriverHandleImp>();
ze_result_t res = driverHandle->initialize(std::move(devices)); ze_result_t res = driverHandle->initialize(std::move(devices));
EXPECT_EQ(ZE_RESULT_SUCCESS, res); EXPECT_EQ(ZE_RESULT_SUCCESS, res);
prevSvmAllocsManager = driverHandle->svmAllocsManager;
currSvmAllocsManager = new SVMAllocsManagerSharedAllocMultiDeviceMock(driverHandle->memoryManager);
driverHandle->svmAllocsManager = currSvmAllocsManager;
context = std::make_unique<ContextMultiDeviceMock>(driverHandle.get()); context = new ContextMultiDeviceMock(driverHandle.get());
EXPECT_NE(context, nullptr); EXPECT_NE(context, nullptr);
bool multiOsContextDriver = false;
for (uint32_t i = 0; i < numRootDevices; i++) { for (uint32_t i = 0; i < numRootDevices; i++) {
auto device = driverHandle->devices[i]; auto device = driverHandle->devices[i];
context->getDevices().insert(std::make_pair(device->toHandle(), device)); context->getDevices().insert(std::make_pair(device->toHandle(), device));
auto neoDevice = device->getNEODevice(); auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
multiOsContextDriver |= device->isMultiDeviceCapable();
} }
context->setMemoryManager(context->getDevices().begin()->second->getNEODevice()->getMemoryManager());
context->setSvmAllocsManager(new NEO::SVMAllocsManager(context->getMemoryManager(), multiOsContextDriver));
driverHandle->mainContext = context;
prevSvmAllocsManager = context->getSvmAllocsManager();
currSvmAllocsManager = new SVMAllocsManagerSharedAllocMultiDeviceMock(context->getMemoryManager());
context->setSvmAllocsManager(currSvmAllocsManager);
driverHandle->setMemoryManager(context->getMemoryManager());
driverHandle->setSvmAllocsManager(context->getSvmAllocsManager());
} }
void TearDown() override { void TearDown() override {
driverHandle->svmAllocsManager = prevSvmAllocsManager; context->setSvmAllocsManager(prevSvmAllocsManager);
context->destroy();
delete currSvmAllocsManager; delete currSvmAllocsManager;
} }
DebugManagerStateRestore restorer; DebugManagerStateRestore restorer;
NEO::SVMAllocsManager *prevSvmAllocsManager; NEO::SVMAllocsManager *prevSvmAllocsManager = nullptr;
SVMAllocsManagerSharedAllocMultiDeviceMock *currSvmAllocsManager; SVMAllocsManagerSharedAllocMultiDeviceMock *currSvmAllocsManager = nullptr;
std::unique_ptr<DriverHandleImp> driverHandle; std::unique_ptr<DriverHandleImp> driverHandle;
std::unique_ptr<ContextMultiDeviceMock> context; ContextMultiDeviceMock *context = nullptr;
const uint32_t numRootDevices = 4u; const uint32_t numRootDevices = 4u;
}; };

View File

@@ -60,7 +60,7 @@ HWTEST_F(ModuleTest, givenZeroCountWhenGettingKernelNamesThenCountIsFilled) {
uint32_t count = 0; uint32_t count = 0;
auto result = module->getKernelNames(&count, nullptr); auto result = module->getKernelNames(&count, nullptr);
auto whiteboxModule = whitebox_cast(module.get()); auto whiteboxModule = whitebox_cast(module);
EXPECT_EQ(whiteboxModule->kernelImmDatas.size(), count); EXPECT_EQ(whiteboxModule->kernelImmDatas.size(), count);
EXPECT_EQ(ZE_RESULT_SUCCESS, result); EXPECT_EQ(ZE_RESULT_SUCCESS, result);
@@ -576,7 +576,7 @@ TEST_F(ModulePropertyTest, givenCallToGetPropertiesWithUnresolvedSymbolsThenFlag
NEO::Linker::RelocationInfo unresolvedRelocation; NEO::Linker::RelocationInfo unresolvedRelocation;
unresolvedRelocation.symbolName = "unresolved"; unresolvedRelocation.symbolName = "unresolved";
whitebox_cast(module.get())->unresolvedExternalsInfo.push_back({unresolvedRelocation}); whitebox_cast(module)->unresolvedExternalsInfo.push_back({unresolvedRelocation});
ze_module_property_flags_t expectedFlags = 0; ze_module_property_flags_t expectedFlags = 0;
expectedFlags |= ZE_MODULE_PROPERTY_FLAG_IMPORTS; expectedFlags |= ZE_MODULE_PROPERTY_FLAG_IMPORTS;
@@ -690,7 +690,7 @@ class DeviceModuleSetArgBufferTest : public ModuleFixture, public ::testing::Tes
void createKernelAndAllocMemory(uint32_t rootDeviceIndex, void **ptr, ze_kernel_handle_t *kernelHandle) { void createKernelAndAllocMemory(uint32_t rootDeviceIndex, void **ptr, ze_kernel_handle_t *kernelHandle) {
ze_kernel_desc_t kernelDesc = {}; ze_kernel_desc_t kernelDesc = {};
kernelDesc.pKernelName = kernelName.c_str(); kernelDesc.pKernelName = kernelName.c_str();
ze_result_t res = module.get()->createKernel(&kernelDesc, kernelHandle); ze_result_t res = module->createKernel(&kernelDesc, kernelHandle);
EXPECT_EQ(ZE_RESULT_SUCCESS, res); EXPECT_EQ(ZE_RESULT_SUCCESS, res);
ze_host_mem_alloc_desc_t hostDesc = {}; ze_host_mem_alloc_desc_t hostDesc = {};
@@ -702,7 +702,6 @@ class DeviceModuleSetArgBufferTest : public ModuleFixture, public ::testing::Tes
HWTEST_F(DeviceModuleSetArgBufferTest, HWTEST_F(DeviceModuleSetArgBufferTest,
givenValidMemoryUsedinFirstCallToSetArgBufferThenNullptrSetOnTheSecondCallThenArgBufferisUpdatedInEachCallAndSuccessIsReturned) { givenValidMemoryUsedinFirstCallToSetArgBufferThenNullptrSetOnTheSecondCallThenArgBufferisUpdatedInEachCallAndSuccessIsReturned) {
uint32_t rootDeviceIndex = 0; uint32_t rootDeviceIndex = 0;
createModuleFromBinary();
ze_kernel_handle_t kernelHandle; ze_kernel_handle_t kernelHandle;
void *validBufferPtr = nullptr; void *validBufferPtr = nullptr;
@@ -752,7 +751,7 @@ class MultiDeviceModuleSetArgBufferTest : public MultiDeviceModuleFixture, publi
void createKernelAndAllocMemory(uint32_t rootDeviceIndex, void **ptr, ze_kernel_handle_t *kernelHandle) { void createKernelAndAllocMemory(uint32_t rootDeviceIndex, void **ptr, ze_kernel_handle_t *kernelHandle) {
ze_kernel_desc_t kernelDesc = {}; ze_kernel_desc_t kernelDesc = {};
kernelDesc.pKernelName = kernelName.c_str(); kernelDesc.pKernelName = kernelName.c_str();
ze_result_t res = modules[rootDeviceIndex].get()->createKernel(&kernelDesc, kernelHandle); ze_result_t res = modules[rootDeviceIndex]->createKernel(&kernelDesc, kernelHandle);
EXPECT_EQ(ZE_RESULT_SUCCESS, res); EXPECT_EQ(ZE_RESULT_SUCCESS, res);
ze_host_mem_alloc_desc_t hostDesc = {}; ze_host_mem_alloc_desc_t hostDesc = {};
@@ -771,10 +770,10 @@ HWTEST_F(MultiDeviceModuleSetArgBufferTest,
void *ptr = nullptr; void *ptr = nullptr;
createKernelAndAllocMemory(rootDeviceIndex, &ptr, &kernelHandle); createKernelAndAllocMemory(rootDeviceIndex, &ptr, &kernelHandle);
L0::KernelImp *kernel = reinterpret_cast<L0::KernelImp *>(Kernel::fromHandle(kernelHandle)); L0::KernelImp *pKernel = reinterpret_cast<L0::KernelImp *>(Kernel::fromHandle(kernelHandle));
kernel->setArgBuffer(0, sizeof(ptr), &ptr); pKernel->setArgBuffer(0, sizeof(ptr), &ptr);
for (auto alloc : kernel->getResidencyContainer()) { for (auto alloc : pKernel->getResidencyContainer()) {
if (alloc && alloc->getGpuAddress() == reinterpret_cast<uint64_t>(ptr)) { if (alloc && alloc->getGpuAddress() == reinterpret_cast<uint64_t>(ptr)) {
EXPECT_EQ(rootDeviceIndex, alloc->getRootDeviceIndex()); EXPECT_EQ(rootDeviceIndex, alloc->getRootDeviceIndex());
} }

View File

@@ -12,7 +12,6 @@
#include "level_zero/core/source/driver/driver_imp.h" #include "level_zero/core/source/driver/driver_imp.h"
#include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h" #include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h"
#include "level_zero/core/test/unit_tests/mocks/mock_device.h" #include "level_zero/core/test/unit_tests/mocks/mock_device.h"
#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h"
#include "level_zero/tools/test/unit_tests/sources/metrics/mock_metric.h" #include "level_zero/tools/test/unit_tests/sources/metrics/mock_metric.h"
#include "gmock/gmock.h" #include "gmock/gmock.h"

View File

@@ -13,7 +13,6 @@
#include "level_zero/core/source/driver/driver_imp.h" #include "level_zero/core/source/driver/driver_imp.h"
#include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h" #include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h"
#include "level_zero/core/test/unit_tests/mocks/mock_device.h" #include "level_zero/core/test/unit_tests/mocks/mock_device.h"
#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h"
#include "level_zero/tools/test/unit_tests/sources/metrics/mock_metric.h" #include "level_zero/tools/test/unit_tests/sources/metrics/mock_metric.h"
#include "gmock/gmock.h" #include "gmock/gmock.h"

View File

@@ -30,10 +30,10 @@ class ZesEngineFixture : public SysmanDeviceFixture {
void SetUp() override { void SetUp() override {
SysmanDeviceFixture::SetUp(); SysmanDeviceFixture::SetUp();
pMemoryManagerOriginal = device->getDriverHandle()->getMemoryManager(); pMemoryManagerOriginal = driverHandle->getMemoryManager();
pMemoryManager = std::make_unique<::testing::NiceMock<MockMemoryManagerInEngineSysman>>(*neoDevice->getExecutionEnvironment()); pMemoryManager = std::make_unique<::testing::NiceMock<MockMemoryManagerInEngineSysman>>(*neoDevice->getExecutionEnvironment());
pMemoryManager->localMemorySupported[0] = false; pMemoryManager->localMemorySupported[0] = false;
device->getDriverHandle()->setMemoryManager(pMemoryManager.get()); driverHandle->setMemoryManager(pMemoryManager.get());
pSysfsAccessOriginal = pLinuxSysmanImp->pSysfsAccess; pSysfsAccessOriginal = pLinuxSysmanImp->pSysfsAccess;
pSysfsAccess = std::make_unique<NiceMock<Mock<EngineSysfsAccess>>>(); pSysfsAccess = std::make_unique<NiceMock<Mock<EngineSysfsAccess>>>();
@@ -67,8 +67,8 @@ class ZesEngineFixture : public SysmanDeviceFixture {
} }
void TearDown() override { void TearDown() override {
context->setMemoryManager(pMemoryManagerOriginal);
SysmanDeviceFixture::TearDown(); SysmanDeviceFixture::TearDown();
device->getDriverHandle()->setMemoryManager(pMemoryManagerOriginal);
pLinuxSysmanImp->pDrm = pOriginalDrm; pLinuxSysmanImp->pDrm = pOriginalDrm;
pLinuxSysmanImp->pPmuInterface = pOriginalPmuInterface; pLinuxSysmanImp->pPmuInterface = pOriginalPmuInterface;
pLinuxSysmanImp->pSysfsAccess = pSysfsAccessOriginal; pLinuxSysmanImp->pSysfsAccess = pSysfsAccessOriginal;

View File

@@ -50,6 +50,7 @@ class ZesPciFixture : public ::testing::Test {
std::unique_ptr<Mock<L0::DriverHandleImp>> driverHandle; std::unique_ptr<Mock<L0::DriverHandleImp>> driverHandle;
NEO::MockDevice *neoDevice = nullptr; NEO::MockDevice *neoDevice = nullptr;
L0::Device *device = nullptr; L0::Device *device = nullptr;
L0::Context *context = nullptr;
void SetUp() override { void SetUp() override {
neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get()); neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get());
@@ -61,6 +62,12 @@ class ZesPciFixture : public ::testing::Test {
driverHandle->initialize(std::move(devices)); driverHandle->initialize(std::move(devices));
device = driverHandle->devices[0]; device = driverHandle->devices[0];
ze_context_handle_t hContext;
ze_context_desc_t desc;
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
context = static_cast<ContextImp *>(Context::fromHandle(hContext));
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[device->getRootDeviceIndex()]->osInterface = std::make_unique<NEO::OSInterface>(); neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[device->getRootDeviceIndex()]->osInterface = std::make_unique<NEO::OSInterface>();
auto osInterface = device->getOsInterface().get(); auto osInterface = device->getOsInterface().get();
osInterface->setDrm(new SysmanMockDrm(const_cast<NEO::RootDeviceEnvironment &>(neoDevice->getRootDeviceEnvironment()))); osInterface->setDrm(new SysmanMockDrm(const_cast<NEO::RootDeviceEnvironment &>(neoDevice->getRootDeviceEnvironment())));
@@ -110,6 +117,7 @@ class ZesPciFixture : public ::testing::Test {
unsetenv("ZES_ENABLE_SYSMAN"); unsetenv("ZES_ENABLE_SYSMAN");
pLinuxSysmanImp->pSysfsAccess = pOriginalSysfsAccess; pLinuxSysmanImp->pSysfsAccess = pOriginalSysfsAccess;
pLinuxSysmanImp->pFsAccess = pOriginalFsAccess; pLinuxSysmanImp->pFsAccess = pOriginalFsAccess;
context->destroy();
} }
SysmanDevice *pSysmanDevice = nullptr; SysmanDevice *pSysmanDevice = nullptr;
SysmanDeviceImp *pSysmanDeviceImp = nullptr; SysmanDeviceImp *pSysmanDeviceImp = nullptr;