mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +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
@ -91,6 +91,8 @@ set(IGDRCL_SRCS_tests_mocks
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_tbx_csr.h
|
${CMAKE_CURRENT_SOURCE_DIR}/mock_tbx_csr.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_tbx_stream.h
|
${CMAKE_CURRENT_SOURCE_DIR}/mock_tbx_stream.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_timestamp_container.h
|
${CMAKE_CURRENT_SOURCE_DIR}/mock_timestamp_container.h
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/ult_cl_device_factory.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/ult_cl_device_factory.h
|
||||||
${NEO_SHARED_DIRECTORY}/gmm_helper/page_table_mngr_impl.cpp
|
${NEO_SHARED_DIRECTORY}/gmm_helper/page_table_mngr_impl.cpp
|
||||||
${IGDRCL_SRCS_tests_compiler_mocks}
|
${IGDRCL_SRCS_tests_compiler_mocks}
|
||||||
)
|
)
|
||||||
|
33
opencl/test/unit_test/mocks/ult_cl_device_factory.cpp
Normal file
33
opencl/test/unit_test/mocks/ult_cl_device_factory.cpp
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Intel Corporation
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "opencl/test/unit_test/mocks/ult_cl_device_factory.h"
|
||||||
|
|
||||||
|
#include "shared/test/unit_test/mocks/ult_device_factory.h"
|
||||||
|
|
||||||
|
#include "opencl/test/unit_test/mocks/mock_cl_device.h"
|
||||||
|
|
||||||
|
using namespace NEO;
|
||||||
|
|
||||||
|
UltClDeviceFactory::UltClDeviceFactory(uint32_t rootDevicesCount, uint32_t subDevicesCount) {
|
||||||
|
auto executionEnvironment = new ClExecutionEnvironment();
|
||||||
|
pUltDeviceFactory = std::make_unique<UltDeviceFactory>(rootDevicesCount, subDevicesCount, *executionEnvironment);
|
||||||
|
|
||||||
|
for (auto &pRootDevice : pUltDeviceFactory->rootDevices) {
|
||||||
|
auto pRootClDevice = new MockClDevice{pRootDevice};
|
||||||
|
for (auto &pClSubDevice : pRootClDevice->subDevices) {
|
||||||
|
subDevices.push_back(pClSubDevice.get());
|
||||||
|
}
|
||||||
|
rootDevices.push_back(pRootClDevice);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
UltClDeviceFactory::~UltClDeviceFactory() {
|
||||||
|
for (auto &pClDevice : rootDevices) {
|
||||||
|
pClDevice->decRefInternal();
|
||||||
|
}
|
||||||
|
}
|
27
opencl/test/unit_test/mocks/ult_cl_device_factory.h
Normal file
27
opencl/test/unit_test/mocks/ult_cl_device_factory.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Intel Corporation
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <cstdint>
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace NEO {
|
||||||
|
class ClDevice;
|
||||||
|
class MockClDevice;
|
||||||
|
struct UltDeviceFactory;
|
||||||
|
|
||||||
|
struct UltClDeviceFactory {
|
||||||
|
UltClDeviceFactory(uint32_t rootDevicesCount, uint32_t subDevicesCount);
|
||||||
|
~UltClDeviceFactory();
|
||||||
|
|
||||||
|
std::unique_ptr<UltDeviceFactory> pUltDeviceFactory;
|
||||||
|
std::vector<MockClDevice *> rootDevices;
|
||||||
|
std::vector<ClDevice *> subDevices;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace NEO
|
@ -12,6 +12,8 @@ set(NEO_CORE_tests_mocks
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_device.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/mock_device.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_device.h
|
${CMAKE_CURRENT_SOURCE_DIR}/mock_device.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_os_library.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)
|
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