From 91b2758f05633229f3a69e8456d3ebab03b809e9 Mon Sep 17 00:00:00 2001 From: Filip Hazubski Date: Thu, 2 Apr 2020 10:37:59 +0200 Subject: [PATCH] Add UltDeviceFactory Change-Id: Ib35bb6132f69e887fad3db282d7c0206d35515b7 Signed-off-by: Filip Hazubski --- opencl/test/unit_test/mocks/CMakeLists.txt | 2 + .../unit_test/mocks/ult_cl_device_factory.cpp | 33 +++++++++++++ .../unit_test/mocks/ult_cl_device_factory.h | 27 +++++++++++ shared/test/unit_test/mocks/CMakeLists.txt | 2 + .../unit_test/mocks/ult_device_factory.cpp | 47 +++++++++++++++++++ .../test/unit_test/mocks/ult_device_factory.h | 26 ++++++++++ 6 files changed, 137 insertions(+) create mode 100644 opencl/test/unit_test/mocks/ult_cl_device_factory.cpp create mode 100644 opencl/test/unit_test/mocks/ult_cl_device_factory.h create mode 100644 shared/test/unit_test/mocks/ult_device_factory.cpp create mode 100644 shared/test/unit_test/mocks/ult_device_factory.h diff --git a/opencl/test/unit_test/mocks/CMakeLists.txt b/opencl/test/unit_test/mocks/CMakeLists.txt index 630fd0b5c4..d50521967c 100644 --- a/opencl/test/unit_test/mocks/CMakeLists.txt +++ b/opencl/test/unit_test/mocks/CMakeLists.txt @@ -91,6 +91,8 @@ set(IGDRCL_SRCS_tests_mocks ${CMAKE_CURRENT_SOURCE_DIR}/mock_tbx_csr.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_tbx_stream.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 ${IGDRCL_SRCS_tests_compiler_mocks} ) diff --git a/opencl/test/unit_test/mocks/ult_cl_device_factory.cpp b/opencl/test/unit_test/mocks/ult_cl_device_factory.cpp new file mode 100644 index 0000000000..d6c1056bfe --- /dev/null +++ b/opencl/test/unit_test/mocks/ult_cl_device_factory.cpp @@ -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(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(); + } +} diff --git a/opencl/test/unit_test/mocks/ult_cl_device_factory.h b/opencl/test/unit_test/mocks/ult_cl_device_factory.h new file mode 100644 index 0000000000..36dcfddaaf --- /dev/null +++ b/opencl/test/unit_test/mocks/ult_cl_device_factory.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once +#include +#include +#include + +namespace NEO { +class ClDevice; +class MockClDevice; +struct UltDeviceFactory; + +struct UltClDeviceFactory { + UltClDeviceFactory(uint32_t rootDevicesCount, uint32_t subDevicesCount); + ~UltClDeviceFactory(); + + std::unique_ptr pUltDeviceFactory; + std::vector rootDevices; + std::vector subDevices; +}; + +} // namespace NEO diff --git a/shared/test/unit_test/mocks/CMakeLists.txt b/shared/test/unit_test/mocks/CMakeLists.txt index 64ecfbe14a..48aa5e8ad8 100644 --- a/shared/test/unit_test/mocks/CMakeLists.txt +++ b/shared/test/unit_test/mocks/CMakeLists.txt @@ -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) diff --git a/shared/test/unit_test/mocks/ult_device_factory.cpp b/shared/test/unit_test/mocks/ult_device_factory.cpp new file mode 100644 index 0000000000..b864bbd03c --- /dev/null +++ b/shared/test/unit_test/mocks/ult_device_factory.cpp @@ -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 createSingleDeviceBackup{&MockDevice::createSingleDevice, false}; + VariableBackup createRootDeviceFuncBackup{&DeviceFactory::createRootDeviceFunc}; + + DebugManager.flags.CreateMultipleRootDevices.set(rootDevicesCount); + DebugManager.flags.CreateMultipleSubDevices.set(subDevicesCount); + createRootDeviceFuncBackup = [](ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex) -> std::unique_ptr { + return std::unique_ptr(MockDevice::create(&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(pCreatedDevice->getDeviceById(i))); + } + this->rootDevices.push_back(static_cast(pCreatedDevice.release())); + } +} + +UltDeviceFactory::~UltDeviceFactory() { + for (auto &pDevice : rootDevices) { + pDevice->decRefInternal(); + } +} diff --git a/shared/test/unit_test/mocks/ult_device_factory.h b/shared/test/unit_test/mocks/ult_device_factory.h new file mode 100644 index 0000000000..93e556aeaa --- /dev/null +++ b/shared/test/unit_test/mocks/ult_device_factory.h @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once +#include +#include + +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 rootDevices; + std::vector subDevices; +}; + +} // namespace NEO