mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 14:55:24 +08:00
Add UltDeviceFactory
Change-Id: Ib35bb6132f69e887fad3db282d7c0206d35515b7 Signed-off-by: Filip Hazubski <filip.hazubski@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
bb5df7afb9
commit
91b2758f05
@@ -12,6 +12,8 @@ set(NEO_CORE_tests_mocks
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_device.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_device.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_os_library.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ult_device_factory.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ult_device_factory.h
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
|
||||
47
shared/test/unit_test/mocks/ult_device_factory.cpp
Normal file
47
shared/test/unit_test/mocks/ult_device_factory.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/test/unit_test/mocks/ult_device_factory.h"
|
||||
|
||||
#include "shared/source/os_interface/device_factory.h"
|
||||
#include "shared/test/unit_test/helpers/debug_manager_state_restore.h"
|
||||
#include "shared/test/unit_test/helpers/variable_backup.h"
|
||||
#include "shared/test/unit_test/mocks/mock_device.h"
|
||||
|
||||
using namespace NEO;
|
||||
|
||||
UltDeviceFactory::UltDeviceFactory(uint32_t rootDevicesCount, uint32_t subDevicesCount)
|
||||
: UltDeviceFactory(rootDevicesCount, subDevicesCount, *(new ExecutionEnvironment)) {
|
||||
}
|
||||
|
||||
UltDeviceFactory::UltDeviceFactory(uint32_t rootDevicesCount, uint32_t subDevicesCount, ExecutionEnvironment &executionEnvironment) {
|
||||
DebugManagerStateRestore restorer;
|
||||
VariableBackup<bool> createSingleDeviceBackup{&MockDevice::createSingleDevice, false};
|
||||
VariableBackup<decltype(DeviceFactory::createRootDeviceFunc)> createRootDeviceFuncBackup{&DeviceFactory::createRootDeviceFunc};
|
||||
|
||||
DebugManager.flags.CreateMultipleRootDevices.set(rootDevicesCount);
|
||||
DebugManager.flags.CreateMultipleSubDevices.set(subDevicesCount);
|
||||
createRootDeviceFuncBackup = [](ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex) -> std::unique_ptr<Device> {
|
||||
return std::unique_ptr<Device>(MockDevice::create<MockDevice>(&executionEnvironment, rootDeviceIndex));
|
||||
};
|
||||
|
||||
auto createdDevices = DeviceFactory::createDevices(executionEnvironment);
|
||||
|
||||
for (auto &pCreatedDevice : createdDevices) {
|
||||
pCreatedDevice->incRefInternal();
|
||||
for (uint32_t i = 0; i < pCreatedDevice->getNumAvailableDevices(); i++) {
|
||||
this->subDevices.push_back(static_cast<SubDevice *>(pCreatedDevice->getDeviceById(i)));
|
||||
}
|
||||
this->rootDevices.push_back(static_cast<MockDevice *>(pCreatedDevice.release()));
|
||||
}
|
||||
}
|
||||
|
||||
UltDeviceFactory::~UltDeviceFactory() {
|
||||
for (auto &pDevice : rootDevices) {
|
||||
pDevice->decRefInternal();
|
||||
}
|
||||
}
|
||||
26
shared/test/unit_test/mocks/ult_device_factory.h
Normal file
26
shared/test/unit_test/mocks/ult_device_factory.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
namespace NEO {
|
||||
class ExecutionEnvironment;
|
||||
class MockDevice;
|
||||
class SubDevice;
|
||||
|
||||
struct UltDeviceFactory {
|
||||
UltDeviceFactory(uint32_t rootDevicesCount, uint32_t subDevicesCount);
|
||||
UltDeviceFactory(uint32_t rootDevicesCount, uint32_t subDevicesCount, ExecutionEnvironment &executionEnvironment);
|
||||
~UltDeviceFactory();
|
||||
|
||||
std::vector<MockDevice *> rootDevices;
|
||||
std::vector<SubDevice *> subDevices;
|
||||
};
|
||||
|
||||
} // namespace NEO
|
||||
Reference in New Issue
Block a user