2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2020-01-08 22:15:01 +08:00
|
|
|
* Copyright (C) 2017-2020 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/device/device.h"
|
|
|
|
#include "shared/source/helpers/hw_info.h"
|
2020-02-27 22:32:57 +08:00
|
|
|
#include "shared/source/os_interface/device_factory.h"
|
2020-02-24 08:01:38 +08:00
|
|
|
#include "shared/test/unit_test/helpers/debug_manager_state_restore.h"
|
|
|
|
#include "shared/test/unit_test/helpers/ult_hw_config.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-03-20 18:15:25 +08:00
|
|
|
#include "opencl/source/cl_device/cl_device.h"
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/platform/extensions.h"
|
|
|
|
#include "opencl/source/sharings/sharing_factory.h"
|
2020-02-23 22:20:22 +08:00
|
|
|
#include "opencl/test/unit_test/fixtures/mock_aub_center_fixture.h"
|
|
|
|
#include "opencl/test/unit_test/fixtures/platform_fixture.h"
|
|
|
|
#include "opencl/test/unit_test/helpers/variable_backup.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_async_event_handler.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_builtins.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_csr.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_device.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_execution_environment.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_platform.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_source_level_debugger.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "gmock/gmock.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
#include "gtest/gtest.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-12-03 22:57:45 +08:00
|
|
|
namespace NEO {
|
|
|
|
namespace MockSipData {
|
|
|
|
extern SipKernelType calledType;
|
|
|
|
extern bool called;
|
|
|
|
} // namespace MockSipData
|
|
|
|
} // namespace NEO
|
|
|
|
|
2018-03-30 03:26:25 +08:00
|
|
|
struct PlatformTest : public ::testing::Test {
|
2019-12-03 22:57:45 +08:00
|
|
|
void SetUp() override {
|
|
|
|
MockSipData::calledType = SipKernelType::COUNT;
|
|
|
|
MockSipData::called = false;
|
2020-02-07 19:15:46 +08:00
|
|
|
pPlatform.reset(new MockPlatform());
|
2019-12-03 22:57:45 +08:00
|
|
|
}
|
|
|
|
void TearDown() override {
|
|
|
|
MockSipData::calledType = SipKernelType::COUNT;
|
|
|
|
MockSipData::called = false;
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_int retVal = CL_SUCCESS;
|
2020-02-15 00:36:30 +08:00
|
|
|
std::unique_ptr<MockPlatform> pPlatform;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
2020-02-15 00:36:30 +08:00
|
|
|
struct MockPlatformWithMockExecutionEnvironment : public MockPlatform {
|
2020-02-07 19:15:46 +08:00
|
|
|
|
2020-02-15 00:36:30 +08:00
|
|
|
MockPlatformWithMockExecutionEnvironment() : MockPlatform(*(new MockExecutionEnvironment(nullptr, false, 1))) {
|
2020-02-07 19:15:46 +08:00
|
|
|
MockAubCenterFixture::setMockAubCenter(*executionEnvironment.rootDeviceEnvironments[0]);
|
2018-11-11 05:25:48 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-01-14 21:32:11 +08:00
|
|
|
TEST_F(PlatformTest, GivenUninitializedPlatformWhenInitializeIsCalledThenPlatformIsInitialized) {
|
|
|
|
EXPECT_FALSE(pPlatform->isInitialized());
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-02-15 00:36:30 +08:00
|
|
|
pPlatform->initializeWithNewDevices();
|
2020-02-11 18:39:25 +08:00
|
|
|
|
2020-01-14 21:32:11 +08:00
|
|
|
EXPECT_TRUE(pPlatform->isInitialized());
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-01-14 21:32:11 +08:00
|
|
|
TEST_F(PlatformTest, WhenGetNumDevicesIsCalledThenExpectedValuesAreReturned) {
|
|
|
|
EXPECT_EQ(0u, pPlatform->getNumDevices());
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-02-15 00:36:30 +08:00
|
|
|
pPlatform->initializeWithNewDevices();
|
2020-01-14 21:32:11 +08:00
|
|
|
|
|
|
|
EXPECT_GT(pPlatform->getNumDevices(), 0u);
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-01-14 21:32:11 +08:00
|
|
|
TEST_F(PlatformTest, WhenGetDeviceIsCalledThenExpectedValuesAreReturned) {
|
|
|
|
EXPECT_EQ(nullptr, pPlatform->getClDevice(0));
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-02-15 00:36:30 +08:00
|
|
|
pPlatform->initializeWithNewDevices();
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-01-14 21:32:11 +08:00
|
|
|
EXPECT_NE(nullptr, pPlatform->getClDevice(0));
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-01-14 21:32:11 +08:00
|
|
|
auto numDevices = pPlatform->getNumDevices();
|
|
|
|
EXPECT_EQ(nullptr, pPlatform->getClDevice(numDevices));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(PlatformTest, WhenGetClDevicesIsCalledThenExpectedValuesAreReturned) {
|
|
|
|
EXPECT_EQ(nullptr, pPlatform->getClDevices());
|
|
|
|
|
2020-02-15 00:36:30 +08:00
|
|
|
pPlatform->initializeWithNewDevices();
|
2020-01-14 21:32:11 +08:00
|
|
|
|
|
|
|
EXPECT_NE(nullptr, pPlatform->getClDevices());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-01-16 01:16:50 +08:00
|
|
|
TEST_F(PlatformTest, PlatformgetAsCompilerEnabledExtensionsString) {
|
2020-02-15 00:36:30 +08:00
|
|
|
pPlatform->initializeWithNewDevices();
|
2020-01-30 17:58:03 +08:00
|
|
|
auto compilerExtensions = pPlatform->getClDevice(0)->peekCompilerExtensions();
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-03-25 20:06:45 +08:00
|
|
|
auto &hwHelper = HwHelper::get(pPlatform->getClDevice(0)->getHardwareInfo().platform.eRenderCoreFamily);
|
|
|
|
|
2018-05-02 20:27:55 +08:00
|
|
|
EXPECT_THAT(compilerExtensions, ::testing::HasSubstr(std::string(" -cl-ext=-all,+cl")));
|
2020-03-25 20:06:45 +08:00
|
|
|
if (std::string(pPlatform->getClDevice(0)->getDeviceInfo().clVersion).find("OpenCL 2.1") != std::string::npos && hwHelper.isIndependentForwardProgressSupported()) {
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_THAT(compilerExtensions, ::testing::HasSubstr(std::string("cl_khr_subgroups")));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(PlatformTest, hasAsyncEventsHandler) {
|
|
|
|
EXPECT_NE(nullptr, pPlatform->getAsyncEventsHandler());
|
|
|
|
}
|
|
|
|
|
2018-11-19 23:18:06 +08:00
|
|
|
TEST_F(PlatformTest, givenMidThreadPreemptionWhenInitializingPlatformThenCallGetSipKernel) {
|
|
|
|
DebugManagerStateRestore dbgRestorer;
|
|
|
|
DebugManager.flags.ForcePreemptionMode.set(static_cast<int32_t>(PreemptionMode::MidThread));
|
|
|
|
|
|
|
|
auto builtIns = new MockBuiltins();
|
2020-02-27 22:32:57 +08:00
|
|
|
auto executionEnvironment = pPlatform->peekExecutionEnvironment();
|
|
|
|
executionEnvironment->prepareRootDeviceEnvironments(1);
|
|
|
|
executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(builtIns);
|
2018-11-19 23:18:06 +08:00
|
|
|
|
2019-12-03 22:57:45 +08:00
|
|
|
EXPECT_EQ(SipKernelType::COUNT, MockSipData::calledType);
|
|
|
|
EXPECT_FALSE(MockSipData::called);
|
2020-02-15 00:36:30 +08:00
|
|
|
pPlatform->initializeWithNewDevices();
|
2019-12-03 22:57:45 +08:00
|
|
|
EXPECT_EQ(SipKernelType::Csr, MockSipData::calledType);
|
|
|
|
EXPECT_TRUE(MockSipData::called);
|
2018-11-19 23:18:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(PlatformTest, givenDisabledPreemptionAndNoSourceLevelDebuggerWhenInitializingPlatformThenDoNotCallGetSipKernel) {
|
|
|
|
DebugManagerStateRestore dbgRestorer;
|
|
|
|
DebugManager.flags.ForcePreemptionMode.set(static_cast<int32_t>(PreemptionMode::Disabled));
|
|
|
|
|
|
|
|
auto builtIns = new MockBuiltins();
|
2020-02-27 22:32:57 +08:00
|
|
|
auto executionEnvironment = pPlatform->peekExecutionEnvironment();
|
|
|
|
executionEnvironment->prepareRootDeviceEnvironments(1);
|
|
|
|
executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(builtIns);
|
2018-11-19 23:18:06 +08:00
|
|
|
|
2019-12-03 22:57:45 +08:00
|
|
|
EXPECT_EQ(SipKernelType::COUNT, MockSipData::calledType);
|
|
|
|
EXPECT_FALSE(MockSipData::called);
|
2020-02-15 00:36:30 +08:00
|
|
|
pPlatform->initializeWithNewDevices();
|
2019-12-03 22:57:45 +08:00
|
|
|
EXPECT_EQ(SipKernelType::COUNT, MockSipData::calledType);
|
|
|
|
EXPECT_FALSE(MockSipData::called);
|
2018-11-19 23:18:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(PlatformTest, givenDisabledPreemptionInactiveSourceLevelDebuggerWhenInitializingPlatformThenDoNotCallGetSipKernel) {
|
|
|
|
DebugManagerStateRestore dbgRestorer;
|
|
|
|
DebugManager.flags.ForcePreemptionMode.set(static_cast<int32_t>(PreemptionMode::Disabled));
|
|
|
|
|
|
|
|
auto builtIns = new MockBuiltins();
|
2020-02-27 22:32:57 +08:00
|
|
|
auto executionEnvironment = pPlatform->peekExecutionEnvironment();
|
|
|
|
executionEnvironment->prepareRootDeviceEnvironments(1);
|
|
|
|
executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(builtIns);
|
2018-11-19 23:18:06 +08:00
|
|
|
auto sourceLevelDebugger = new MockSourceLevelDebugger();
|
|
|
|
sourceLevelDebugger->setActive(false);
|
2020-03-11 15:56:55 +08:00
|
|
|
executionEnvironment->rootDeviceEnvironments[0]->debugger.reset(sourceLevelDebugger);
|
2018-11-19 23:18:06 +08:00
|
|
|
|
2019-12-03 22:57:45 +08:00
|
|
|
EXPECT_EQ(SipKernelType::COUNT, MockSipData::calledType);
|
|
|
|
EXPECT_FALSE(MockSipData::called);
|
2020-02-15 00:36:30 +08:00
|
|
|
pPlatform->initializeWithNewDevices();
|
2019-12-03 22:57:45 +08:00
|
|
|
EXPECT_EQ(SipKernelType::COUNT, MockSipData::calledType);
|
|
|
|
EXPECT_FALSE(MockSipData::called);
|
2018-11-19 23:18:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(PlatformTest, givenDisabledPreemptionActiveSourceLevelDebuggerWhenInitializingPlatformThenCallGetSipKernel) {
|
|
|
|
DebugManagerStateRestore dbgRestorer;
|
|
|
|
DebugManager.flags.ForcePreemptionMode.set(static_cast<int32_t>(PreemptionMode::Disabled));
|
|
|
|
|
|
|
|
auto builtIns = new MockBuiltins();
|
2020-02-27 22:32:57 +08:00
|
|
|
auto executionEnvironment = pPlatform->peekExecutionEnvironment();
|
|
|
|
executionEnvironment->prepareRootDeviceEnvironments(1);
|
|
|
|
executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(builtIns);
|
2020-03-11 15:56:55 +08:00
|
|
|
executionEnvironment->rootDeviceEnvironments[0]->debugger.reset(new MockActiveSourceLevelDebugger());
|
2018-11-19 23:18:06 +08:00
|
|
|
|
2019-12-03 22:57:45 +08:00
|
|
|
EXPECT_EQ(SipKernelType::COUNT, MockSipData::calledType);
|
|
|
|
EXPECT_FALSE(MockSipData::called);
|
2020-02-15 00:36:30 +08:00
|
|
|
pPlatform->initializeWithNewDevices();
|
2019-12-03 22:57:45 +08:00
|
|
|
EXPECT_TRUE(MockSipData::called);
|
|
|
|
EXPECT_LE(SipKernelType::DbgCsr, MockSipData::calledType);
|
|
|
|
EXPECT_GE(SipKernelType::DbgCsrLocal, MockSipData::calledType);
|
2018-11-19 23:18:06 +08:00
|
|
|
}
|
|
|
|
|
2018-11-11 05:25:48 +08:00
|
|
|
TEST(PlatformTestSimple, givenCsrHwTypeWhenPlatformIsInitializedThenInitAubCenterIsNotCalled) {
|
|
|
|
DebugManagerStateRestore stateRestore;
|
|
|
|
DebugManager.flags.SetCommandStreamReceiver.set(0);
|
|
|
|
MockPlatformWithMockExecutionEnvironment platform;
|
2020-02-11 18:39:25 +08:00
|
|
|
|
2020-02-15 00:36:30 +08:00
|
|
|
bool ret = platform.initializeWithNewDevices();
|
2018-11-11 05:25:48 +08:00
|
|
|
EXPECT_TRUE(ret);
|
2020-02-07 19:15:46 +08:00
|
|
|
auto rootDeviceEnvironment = static_cast<MockRootDeviceEnvironment *>(platform.peekExecutionEnvironment()->rootDeviceEnvironments[0].get());
|
2019-11-15 16:59:48 +08:00
|
|
|
EXPECT_FALSE(rootDeviceEnvironment->initAubCenterCalled);
|
2018-11-11 05:25:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(PlatformTestSimple, givenNotCsrHwTypeWhenPlatformIsInitializedThenInitAubCenterIsCalled) {
|
|
|
|
DebugManagerStateRestore stateRestore;
|
|
|
|
DebugManager.flags.SetCommandStreamReceiver.set(1);
|
2020-02-03 20:19:12 +08:00
|
|
|
VariableBackup<UltHwConfig> backup(&ultHwConfig);
|
|
|
|
ultHwConfig.useHwCsr = true;
|
2018-11-11 05:25:48 +08:00
|
|
|
MockPlatformWithMockExecutionEnvironment platform;
|
2020-02-15 00:36:30 +08:00
|
|
|
bool ret = platform.initializeWithNewDevices();
|
2018-11-11 05:25:48 +08:00
|
|
|
EXPECT_TRUE(ret);
|
2020-02-07 19:15:46 +08:00
|
|
|
auto rootDeviceEnvironment = static_cast<MockRootDeviceEnvironment *>(platform.peekExecutionEnvironment()->rootDeviceEnvironments[0].get());
|
2019-11-15 16:59:48 +08:00
|
|
|
EXPECT_TRUE(rootDeviceEnvironment->initAubCenterCalled);
|
2018-11-11 05:25:48 +08:00
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
TEST(PlatformTestSimple, shutdownClosesAsyncEventHandlerThread) {
|
2020-02-07 19:15:46 +08:00
|
|
|
Platform *platform = new MockPlatform();
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-02-07 19:15:46 +08:00
|
|
|
MockHandler *mockAsyncHandler = new MockHandler();
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-02-21 23:31:53 +08:00
|
|
|
auto oldHandler = platform->setAsyncEventsHandler(std::unique_ptr<AsyncEventsHandler>(mockAsyncHandler));
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_EQ(mockAsyncHandler, platform->getAsyncEventsHandler());
|
|
|
|
|
|
|
|
mockAsyncHandler->openThread();
|
|
|
|
delete platform;
|
2018-06-28 14:51:44 +08:00
|
|
|
EXPECT_TRUE(MockAsyncEventHandlerGlobals::destructorCalled);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2019-08-07 00:01:26 +08:00
|
|
|
extern CommandStreamReceiverCreateFunc commandStreamReceiverFactory[IGFX_MAX_CORE];
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2019-10-29 15:01:53 +08:00
|
|
|
CommandStreamReceiver *createMockCommandStreamReceiver(bool withAubDump, ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex) {
|
2017-12-21 07:45:38 +08:00
|
|
|
return nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PlatformFailingTest : public PlatformTest {
|
|
|
|
public:
|
2020-02-03 20:19:12 +08:00
|
|
|
PlatformFailingTest() {
|
|
|
|
ultHwConfig.useHwCsr = true;
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
void SetUp() override {
|
|
|
|
PlatformTest::SetUp();
|
2020-03-25 00:52:43 +08:00
|
|
|
hwInfo = defaultHwInfo.get();
|
2019-05-08 22:00:24 +08:00
|
|
|
commandStreamReceiverCreateFunc = commandStreamReceiverFactory[hwInfo->platform.eRenderCoreFamily];
|
|
|
|
commandStreamReceiverFactory[hwInfo->platform.eRenderCoreFamily] = createMockCommandStreamReceiver;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override {
|
2019-05-08 22:00:24 +08:00
|
|
|
commandStreamReceiverFactory[hwInfo->platform.eRenderCoreFamily] = commandStreamReceiverCreateFunc;
|
2017-12-21 07:45:38 +08:00
|
|
|
PlatformTest::TearDown();
|
|
|
|
}
|
|
|
|
|
2020-02-03 20:19:12 +08:00
|
|
|
VariableBackup<UltHwConfig> backup{&ultHwConfig};
|
2017-12-21 07:45:38 +08:00
|
|
|
CommandStreamReceiverCreateFunc commandStreamReceiverCreateFunc;
|
|
|
|
const HardwareInfo *hwInfo;
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(PlatformFailingTest, givenPlatformInitializationWhenIncorrectHwInfoThenInitializationFails) {
|
2020-02-15 00:36:30 +08:00
|
|
|
auto platform = new MockPlatform();
|
|
|
|
bool ret = platform->initializeWithNewDevices();
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_FALSE(ret);
|
|
|
|
EXPECT_FALSE(platform->isInitialized());
|
|
|
|
delete platform;
|
|
|
|
}
|
2018-01-16 01:16:50 +08:00
|
|
|
|
2018-06-26 21:56:50 +08:00
|
|
|
TEST_F(PlatformTest, givenSupportingCl21WhenPlatformSupportsFp64ThenFillMatchingSubstringsAndMandatoryTrailingSpace) {
|
2018-01-16 01:16:50 +08:00
|
|
|
const HardwareInfo *hwInfo;
|
2020-03-25 00:52:43 +08:00
|
|
|
hwInfo = defaultHwInfo.get();
|
2018-01-16 01:16:50 +08:00
|
|
|
std::string extensionsList = getExtensionsList(*hwInfo);
|
|
|
|
|
|
|
|
std::string compilerExtensions = convertEnabledExtensionsToCompilerInternalOptions(extensionsList.c_str());
|
2018-05-02 20:27:55 +08:00
|
|
|
EXPECT_THAT(compilerExtensions, ::testing::HasSubstr(std::string(" -cl-ext=-all,+cl")));
|
2018-01-16 01:16:50 +08:00
|
|
|
|
|
|
|
if (hwInfo->capabilityTable.clVersionSupport > 20) {
|
|
|
|
EXPECT_THAT(compilerExtensions, ::testing::HasSubstr(std::string("cl_khr_subgroups")));
|
|
|
|
EXPECT_THAT(compilerExtensions, ::testing::HasSubstr(std::string("cl_khr_il_program")));
|
2019-12-12 23:48:58 +08:00
|
|
|
if (hwInfo->capabilityTable.supportsVme) {
|
|
|
|
EXPECT_THAT(compilerExtensions, ::testing::HasSubstr(std::string("cl_intel_spirv_device_side_avc_motion_estimation")));
|
|
|
|
} else {
|
|
|
|
EXPECT_THAT(compilerExtensions, testing::Not(::testing::HasSubstr(std::string("cl_intel_spirv_device_side_avc_motion_estimation"))));
|
|
|
|
}
|
2020-01-08 22:15:01 +08:00
|
|
|
if (hwInfo->capabilityTable.supportsImages) {
|
|
|
|
EXPECT_THAT(compilerExtensions, ::testing::HasSubstr(std::string("cl_intel_spirv_media_block_io")));
|
|
|
|
} else {
|
|
|
|
EXPECT_THAT(compilerExtensions, testing::Not(::testing::HasSubstr(std::string("cl_intel_spirv_media_block_io"))));
|
|
|
|
}
|
|
|
|
|
2018-12-17 17:03:08 +08:00
|
|
|
EXPECT_THAT(compilerExtensions, ::testing::HasSubstr(std::string("cl_intel_spirv_subgroups")));
|
2019-03-18 21:12:57 +08:00
|
|
|
EXPECT_THAT(compilerExtensions, ::testing::HasSubstr(std::string("cl_khr_spirv_no_integer_wrap_decoration")));
|
2018-01-16 01:16:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hwInfo->capabilityTable.ftrSupportsFP64) {
|
|
|
|
EXPECT_THAT(compilerExtensions, ::testing::HasSubstr(std::string("cl_khr_fp64")));
|
|
|
|
}
|
2018-06-26 21:56:50 +08:00
|
|
|
|
2020-02-14 21:07:31 +08:00
|
|
|
if (hwInfo->capabilityTable.supportsImages) {
|
|
|
|
EXPECT_THAT(extensionsList, ::testing::HasSubstr(std::string("cl_khr_3d_image_writes")));
|
|
|
|
}
|
2018-06-26 21:56:50 +08:00
|
|
|
EXPECT_THAT(compilerExtensions, ::testing::EndsWith(std::string(" ")));
|
2018-01-16 01:16:50 +08:00
|
|
|
}
|
|
|
|
|
2018-06-26 21:56:50 +08:00
|
|
|
TEST_F(PlatformTest, givenNotSupportingCl21WhenPlatformNotSupportFp64ThenNotFillMatchingSubstringAndFillMandatoryTrailingSpace) {
|
2020-03-24 18:42:54 +08:00
|
|
|
HardwareInfo TesthwInfo = *defaultHwInfo;
|
2018-01-16 01:16:50 +08:00
|
|
|
TesthwInfo.capabilityTable.ftrSupportsFP64 = false;
|
|
|
|
TesthwInfo.capabilityTable.clVersionSupport = 10;
|
|
|
|
|
|
|
|
std::string extensionsList = getExtensionsList(TesthwInfo);
|
2020-02-14 21:07:31 +08:00
|
|
|
if (TesthwInfo.capabilityTable.supportsImages) {
|
|
|
|
EXPECT_THAT(extensionsList, ::testing::HasSubstr(std::string("cl_khr_3d_image_writes")));
|
|
|
|
}
|
2018-01-16 01:16:50 +08:00
|
|
|
|
|
|
|
std::string compilerExtensions = convertEnabledExtensionsToCompilerInternalOptions(extensionsList.c_str());
|
|
|
|
EXPECT_THAT(compilerExtensions, ::testing::HasSubstr(std::string("-cl-ext=-all,+cl")));
|
|
|
|
|
|
|
|
EXPECT_THAT(compilerExtensions, ::testing::Not(::testing::HasSubstr(std::string("cl_khr_fp64"))));
|
|
|
|
EXPECT_THAT(compilerExtensions, ::testing::Not(::testing::HasSubstr(std::string("cl_khr_subgroups"))));
|
2018-06-26 21:56:50 +08:00
|
|
|
|
|
|
|
EXPECT_THAT(compilerExtensions, ::testing::EndsWith(std::string(" ")));
|
2018-01-16 01:16:50 +08:00
|
|
|
}
|
|
|
|
|
2019-08-20 21:17:10 +08:00
|
|
|
TEST_F(PlatformTest, givenFtrSupportAtomicsWhenCreateExtentionsListThenGetMatchingSubstrings) {
|
|
|
|
const HardwareInfo *hwInfo;
|
2020-03-25 00:52:43 +08:00
|
|
|
hwInfo = defaultHwInfo.get();
|
2019-08-20 21:17:10 +08:00
|
|
|
std::string extensionsList = getExtensionsList(*hwInfo);
|
|
|
|
std::string compilerExtensions = convertEnabledExtensionsToCompilerInternalOptions(extensionsList.c_str());
|
|
|
|
|
|
|
|
if (hwInfo->capabilityTable.ftrSupportsInteger64BitAtomics) {
|
|
|
|
EXPECT_THAT(compilerExtensions, ::testing::HasSubstr(std::string("cl_khr_int64_base_atomics")));
|
|
|
|
EXPECT_THAT(compilerExtensions, ::testing::HasSubstr(std::string("cl_khr_int64_extended_atomics")));
|
|
|
|
} else {
|
|
|
|
EXPECT_THAT(compilerExtensions, ::testing::Not(::testing::HasSubstr(std::string("cl_khr_int64_base_atomics"))));
|
|
|
|
EXPECT_THAT(compilerExtensions, ::testing::Not(::testing::HasSubstr(std::string("cl_khr_int64_extended_atomics"))));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-08 22:15:01 +08:00
|
|
|
TEST_F(PlatformTest, givenSupporteImagesAndClVersion21WhenCreateExtentionsListThenDeviceReportsSpritvMediaBlockIoExtension) {
|
2020-03-24 18:42:54 +08:00
|
|
|
HardwareInfo hwInfo = *defaultHwInfo;
|
2020-01-08 22:15:01 +08:00
|
|
|
hwInfo.capabilityTable.supportsImages = true;
|
|
|
|
hwInfo.capabilityTable.clVersionSupport = 21;
|
|
|
|
std::string extensionsList = getExtensionsList(hwInfo);
|
|
|
|
std::string compilerExtensions = convertEnabledExtensionsToCompilerInternalOptions(extensionsList.c_str());
|
|
|
|
|
|
|
|
EXPECT_THAT(compilerExtensions, testing::HasSubstr(std::string("cl_intel_spirv_media_block_io")));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(PlatformTest, givenNotSupporteImagesAndClVersion21WhenCreateExtentionsListThenDeviceNotReportsSpritvMediaBlockIoExtension) {
|
2020-03-24 18:42:54 +08:00
|
|
|
HardwareInfo hwInfo = *defaultHwInfo;
|
2020-01-08 22:15:01 +08:00
|
|
|
hwInfo.capabilityTable.supportsImages = false;
|
|
|
|
hwInfo.capabilityTable.clVersionSupport = 21;
|
|
|
|
std::string extensionsList = getExtensionsList(hwInfo);
|
|
|
|
std::string compilerExtensions = convertEnabledExtensionsToCompilerInternalOptions(extensionsList.c_str());
|
|
|
|
|
|
|
|
EXPECT_THAT(compilerExtensions, testing::Not(testing::HasSubstr(std::string("cl_intel_spirv_media_block_io"))));
|
|
|
|
}
|
|
|
|
|
2018-01-16 01:16:50 +08:00
|
|
|
TEST_F(PlatformTest, testRemoveLastSpace) {
|
|
|
|
std::string emptyString = "";
|
|
|
|
removeLastSpace(emptyString);
|
|
|
|
EXPECT_EQ(std::string(""), emptyString);
|
|
|
|
|
|
|
|
std::string xString = "x";
|
|
|
|
removeLastSpace(xString);
|
|
|
|
EXPECT_EQ(std::string("x"), xString);
|
|
|
|
|
|
|
|
std::string xSpaceString = "x ";
|
|
|
|
removeLastSpace(xSpaceString);
|
|
|
|
EXPECT_EQ(std::string("x"), xSpaceString);
|
2018-03-30 03:26:25 +08:00
|
|
|
}
|
2018-06-26 22:15:48 +08:00
|
|
|
TEST(PlatformConstructionTest, givenPlatformConstructorWhenItIsCalledTwiceThenTheSamePlatformIsReturned) {
|
2020-02-03 23:18:21 +08:00
|
|
|
platformsImpl.clear();
|
|
|
|
auto platform1 = constructPlatform();
|
|
|
|
EXPECT_EQ(platform1, platform());
|
2018-06-26 22:15:48 +08:00
|
|
|
auto platform2 = constructPlatform();
|
2020-02-03 23:18:21 +08:00
|
|
|
EXPECT_EQ(platform2, platform1);
|
|
|
|
EXPECT_NE(platform1, nullptr);
|
2018-06-26 22:15:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(PlatformConstructionTest, givenPlatformConstructorWhenItIsCalledAfterResetThenNewPlatformIsConstructed) {
|
2020-02-03 23:18:21 +08:00
|
|
|
platformsImpl.clear();
|
2018-06-26 22:15:48 +08:00
|
|
|
auto platform = constructPlatform();
|
2020-02-03 23:18:21 +08:00
|
|
|
std::unique_ptr<Platform> temporaryOwnership(std::move(platformsImpl[0]));
|
|
|
|
platformsImpl.clear();
|
2018-06-26 22:15:48 +08:00
|
|
|
auto platform2 = constructPlatform();
|
|
|
|
EXPECT_NE(platform2, platform);
|
|
|
|
EXPECT_NE(platform, nullptr);
|
|
|
|
EXPECT_NE(platform2, nullptr);
|
2020-02-03 23:18:21 +08:00
|
|
|
platformsImpl.clear();
|
2018-06-26 22:15:48 +08:00
|
|
|
}
|
2018-06-28 14:51:44 +08:00
|
|
|
|
2018-08-14 19:54:33 +08:00
|
|
|
TEST(PlatformInitLoopTests, givenPlatformWhenInitLoopHelperIsCalledThenItDoesNothing) {
|
2020-02-07 19:15:46 +08:00
|
|
|
MockPlatform platform;
|
2018-08-14 19:54:33 +08:00
|
|
|
platform.initializationLoopHelper();
|
|
|
|
}
|
|
|
|
|
2020-02-15 00:36:30 +08:00
|
|
|
TEST(PlatformInitTest, givenNullptrDeviceInPassedDeviceVectorWhenInitializePlatformThenExceptionIsThrown) {
|
|
|
|
std::vector<std::unique_ptr<Device>> devices;
|
|
|
|
devices.push_back(nullptr);
|
|
|
|
EXPECT_THROW(platform()->initialize(std::move(devices)), std::exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(PlatformInitTest, givenInitializedPlatformWhenInitializeIsCalledOneMoreTimeWithNullptrDeviceThenSuccessIsEarlyReturned) {
|
|
|
|
initPlatform();
|
|
|
|
EXPECT_TRUE(platform()->isInitialized());
|
|
|
|
std::vector<std::unique_ptr<Device>> devices;
|
|
|
|
devices.push_back(nullptr);
|
|
|
|
EXPECT_TRUE(platform()->initialize(std::move(devices)));
|
|
|
|
}
|
|
|
|
|
2020-03-02 17:13:46 +08:00
|
|
|
TEST(PlatformInitTest, givenSingleDeviceWithNonZeroRootDeviceIndexInPassedDeviceVectorWhenInitializePlatformThenCreateOnlyOneClDevice) {
|
|
|
|
std::vector<std::unique_ptr<Device>> devices;
|
2020-03-25 00:52:43 +08:00
|
|
|
auto executionEnvironment = new MockExecutionEnvironment(defaultHwInfo.get(), false, 3);
|
2020-03-02 17:13:46 +08:00
|
|
|
devices.push_back(std::make_unique<MockDevice>(executionEnvironment, 2));
|
|
|
|
auto status = platform()->initialize(std::move(devices));
|
|
|
|
EXPECT_TRUE(status);
|
|
|
|
size_t expectedNumDevices = 1u;
|
|
|
|
EXPECT_EQ(expectedNumDevices, platform()->getNumDevices());
|
|
|
|
EXPECT_EQ(2u, platform()->getClDevice(0)->getRootDeviceIndex());
|
|
|
|
}
|
|
|
|
|
2018-08-14 19:54:33 +08:00
|
|
|
TEST(PlatformInitLoopTests, givenPlatformWithDebugSettingWhenInitIsCalledThenItEntersEndlessLoop) {
|
|
|
|
DebugManagerStateRestore stateRestore;
|
|
|
|
DebugManager.flags.LoopAtPlatformInitialize.set(true);
|
|
|
|
bool called = false;
|
2020-02-07 19:15:46 +08:00
|
|
|
struct mockPlatform : public MockPlatform {
|
2018-08-14 19:54:33 +08:00
|
|
|
mockPlatform(bool &called) : called(called){};
|
|
|
|
void initializationLoopHelper() override {
|
|
|
|
DebugManager.flags.LoopAtPlatformInitialize.set(false);
|
|
|
|
called = true;
|
|
|
|
}
|
|
|
|
bool &called;
|
|
|
|
};
|
|
|
|
mockPlatform platform(called);
|
2020-02-15 00:36:30 +08:00
|
|
|
platform.initializeWithNewDevices();
|
2018-08-14 19:54:33 +08:00
|
|
|
EXPECT_TRUE(called);
|
|
|
|
}
|
2020-02-18 23:02:26 +08:00
|
|
|
|
|
|
|
TEST(PlatformGroupDevicesTest, whenMultipleDevicesAreCreatedThenGroupDevicesCreatesVectorPerEachProductFamily) {
|
|
|
|
DebugManagerStateRestore restorer;
|
|
|
|
const size_t numRootDevices = 5u;
|
|
|
|
|
|
|
|
DebugManager.flags.CreateMultipleRootDevices.set(numRootDevices);
|
|
|
|
auto executionEnvironment = new ExecutionEnvironment();
|
|
|
|
|
|
|
|
for (auto i = 0u; i < numRootDevices; i++) {
|
|
|
|
executionEnvironment->rootDeviceEnvironments.push_back(std::make_unique<MockRootDeviceEnvironment>(*executionEnvironment));
|
|
|
|
}
|
|
|
|
auto inputDevices = DeviceFactory::createDevices(*executionEnvironment);
|
|
|
|
EXPECT_EQ(numRootDevices, inputDevices.size());
|
|
|
|
|
|
|
|
auto skl0Device = inputDevices[0].get();
|
2020-03-10 19:58:35 +08:00
|
|
|
auto kbl0Device = inputDevices[1].get();
|
|
|
|
auto skl1Device = inputDevices[2].get();
|
|
|
|
auto skl2Device = inputDevices[3].get();
|
2020-02-18 23:02:26 +08:00
|
|
|
auto cfl0Device = inputDevices[4].get();
|
|
|
|
|
2020-03-10 19:58:35 +08:00
|
|
|
executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo()->platform.eProductFamily = IGFX_SKYLAKE;
|
|
|
|
executionEnvironment->rootDeviceEnvironments[1]->getMutableHardwareInfo()->platform.eProductFamily = IGFX_KABYLAKE;
|
|
|
|
executionEnvironment->rootDeviceEnvironments[2]->getMutableHardwareInfo()->platform.eProductFamily = IGFX_SKYLAKE;
|
|
|
|
executionEnvironment->rootDeviceEnvironments[3]->getMutableHardwareInfo()->platform.eProductFamily = IGFX_SKYLAKE;
|
|
|
|
executionEnvironment->rootDeviceEnvironments[4]->getMutableHardwareInfo()->platform.eProductFamily = IGFX_COFFEELAKE;
|
2020-02-18 23:02:26 +08:00
|
|
|
|
|
|
|
auto groupedDevices = Platform::groupDevices(std::move(inputDevices));
|
|
|
|
|
|
|
|
EXPECT_EQ(3u, groupedDevices.size());
|
2020-02-21 18:48:02 +08:00
|
|
|
EXPECT_EQ(1u, groupedDevices[0].size());
|
2020-02-18 23:02:26 +08:00
|
|
|
EXPECT_EQ(1u, groupedDevices[1].size());
|
2020-02-21 18:48:02 +08:00
|
|
|
EXPECT_EQ(3u, groupedDevices[2].size());
|
2020-02-18 23:02:26 +08:00
|
|
|
|
2020-02-21 18:48:02 +08:00
|
|
|
EXPECT_EQ(skl0Device, groupedDevices[2][0].get());
|
|
|
|
EXPECT_EQ(skl1Device, groupedDevices[2][1].get());
|
|
|
|
EXPECT_EQ(skl2Device, groupedDevices[2][2].get());
|
2020-02-18 23:02:26 +08:00
|
|
|
EXPECT_EQ(kbl0Device, groupedDevices[1][0].get());
|
2020-02-21 18:48:02 +08:00
|
|
|
EXPECT_EQ(cfl0Device, groupedDevices[0][0].get());
|
2020-02-18 23:02:26 +08:00
|
|
|
}
|