2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2025-02-12 11:25:57 +00:00
|
|
|
* Copyright (C) 2018-2025 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-18 09:11:08 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/device/device.h"
|
2023-03-15 10:35:43 +00:00
|
|
|
#include "shared/source/helpers/compiler_product_helper.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/helpers/hw_info.h"
|
2020-06-16 20:54:15 +02:00
|
|
|
#include "shared/source/helpers/string.h"
|
2020-02-27 15:32:57 +01:00
|
|
|
#include "shared/source/os_interface/device_factory.h"
|
2023-04-13 14:16:49 +00:00
|
|
|
#include "shared/source/release_helper/release_helper.h"
|
2022-08-10 17:00:50 +00:00
|
|
|
#include "shared/test/common/fixtures/mock_aub_center_fixture.h"
|
2021-01-21 13:10:13 +01:00
|
|
|
#include "shared/test/common/helpers/debug_manager_state_restore.h"
|
2022-08-10 11:24:38 +00:00
|
|
|
#include "shared/test/common/helpers/gtest_helpers.h"
|
2021-01-21 13:10:13 +01:00
|
|
|
#include "shared/test/common/helpers/ult_hw_config.h"
|
|
|
|
|
#include "shared/test/common/helpers/variable_backup.h"
|
2021-10-15 12:02:31 +00:00
|
|
|
#include "shared/test/common/mocks/mock_builtins.h"
|
2021-10-12 16:42:24 +00:00
|
|
|
#include "shared/test/common/mocks/mock_csr.h"
|
2021-01-21 13:10:13 +01:00
|
|
|
#include "shared/test/common/mocks/mock_device.h"
|
2021-07-06 15:44:16 +02:00
|
|
|
#include "shared/test/common/mocks/mock_execution_environment.h"
|
2021-04-16 12:52:30 +00:00
|
|
|
#include "shared/test/common/mocks/mock_sip.h"
|
2020-02-24 10:22:30 +01:00
|
|
|
|
2020-03-20 11:15:25 +01:00
|
|
|
#include "opencl/source/cl_device/cl_device.h"
|
2023-09-12 09:23:51 +00:00
|
|
|
#include "opencl/source/platform/platform_info.h"
|
2020-02-22 22:50:57 +01:00
|
|
|
#include "opencl/source/sharings/sharing_factory.h"
|
2020-02-23 15:20:22 +01:00
|
|
|
#include "opencl/test/unit_test/fixtures/platform_fixture.h"
|
2020-06-16 20:54:15 +02:00
|
|
|
#include "opencl/test/unit_test/mocks/mock_cl_device.h"
|
2020-02-23 15:20:22 +01:00
|
|
|
#include "opencl/test/unit_test/mocks/mock_platform.h"
|
2020-06-16 20:54:15 +02:00
|
|
|
#include "opencl/test/unit_test/mocks/ult_cl_device_factory.h"
|
2020-10-07 13:37:34 +02:00
|
|
|
#include "opencl/test/unit_test/test_macros/test_checks_ocl.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
using namespace NEO;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2018-03-29 21:26:25 +02:00
|
|
|
struct PlatformTest : public ::testing::Test {
|
2019-12-03 15:57:45 +01:00
|
|
|
void SetUp() override {
|
2021-04-16 12:52:30 +00:00
|
|
|
MockSipData::clearUseFlags();
|
|
|
|
|
backupSipInitType = std::make_unique<VariableBackup<bool>>(&MockSipData::useMockSip, true);
|
|
|
|
|
|
2020-02-07 12:15:46 +01:00
|
|
|
pPlatform.reset(new MockPlatform());
|
2023-03-15 10:35:43 +00:00
|
|
|
compilerProductHelper = CompilerProductHelper::create(defaultHwInfo->platform.eProductFamily);
|
2023-04-13 14:16:49 +00:00
|
|
|
releaseHelper = ReleaseHelper::create(defaultHwInfo->ipVersion);
|
2019-12-03 15:57:45 +01:00
|
|
|
}
|
|
|
|
|
void TearDown() override {
|
2021-04-16 12:52:30 +00:00
|
|
|
MockSipData::clearUseFlags();
|
2019-12-03 15:57:45 +01:00
|
|
|
}
|
2020-02-14 17:36:30 +01:00
|
|
|
std::unique_ptr<MockPlatform> pPlatform;
|
2021-04-16 12:52:30 +00:00
|
|
|
std::unique_ptr<VariableBackup<bool>> backupSipInitType;
|
2023-03-15 10:35:43 +00:00
|
|
|
std::unique_ptr<CompilerProductHelper> compilerProductHelper;
|
2023-04-13 14:16:49 +00:00
|
|
|
std::unique_ptr<ReleaseHelper> releaseHelper;
|
2021-04-16 12:52:30 +00:00
|
|
|
|
|
|
|
|
cl_int retVal = CL_SUCCESS;
|
2017-12-21 00:45:38 +01:00
|
|
|
};
|
|
|
|
|
|
2020-02-14 17:36:30 +01:00
|
|
|
struct MockPlatformWithMockExecutionEnvironment : public MockPlatform {
|
2020-02-07 12:15:46 +01:00
|
|
|
|
2020-02-14 17:36:30 +01:00
|
|
|
MockPlatformWithMockExecutionEnvironment() : MockPlatform(*(new MockExecutionEnvironment(nullptr, false, 1))) {
|
2020-02-07 12:15:46 +01:00
|
|
|
MockAubCenterFixture::setMockAubCenter(*executionEnvironment.rootDeviceEnvironments[0]);
|
2018-11-10 22:25:48 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-01-14 14:32:11 +01:00
|
|
|
TEST_F(PlatformTest, GivenUninitializedPlatformWhenInitializeIsCalledThenPlatformIsInitialized) {
|
|
|
|
|
EXPECT_FALSE(pPlatform->isInitialized());
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2020-02-14 17:36:30 +01:00
|
|
|
pPlatform->initializeWithNewDevices();
|
2020-02-11 11:39:25 +01:00
|
|
|
|
2020-01-14 14:32:11 +01:00
|
|
|
EXPECT_TRUE(pPlatform->isInitialized());
|
|
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2020-01-14 14:32:11 +01:00
|
|
|
TEST_F(PlatformTest, WhenGetNumDevicesIsCalledThenExpectedValuesAreReturned) {
|
|
|
|
|
EXPECT_EQ(0u, pPlatform->getNumDevices());
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2020-02-14 17:36:30 +01:00
|
|
|
pPlatform->initializeWithNewDevices();
|
2020-01-14 14:32:11 +01:00
|
|
|
|
|
|
|
|
EXPECT_GT(pPlatform->getNumDevices(), 0u);
|
|
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2020-01-14 14:32:11 +01:00
|
|
|
TEST_F(PlatformTest, WhenGetDeviceIsCalledThenExpectedValuesAreReturned) {
|
|
|
|
|
EXPECT_EQ(nullptr, pPlatform->getClDevice(0));
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2020-02-14 17:36:30 +01:00
|
|
|
pPlatform->initializeWithNewDevices();
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2020-01-14 14:32:11 +01:00
|
|
|
EXPECT_NE(nullptr, pPlatform->getClDevice(0));
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2020-01-14 14:32:11 +01:00
|
|
|
auto numDevices = pPlatform->getNumDevices();
|
|
|
|
|
EXPECT_EQ(nullptr, pPlatform->getClDevice(numDevices));
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-27 15:50:33 +00:00
|
|
|
TEST_F(PlatformTest, WhenPlatformIsDestroyedThenDirectSubmissionIsTerminated) {
|
|
|
|
|
VariableBackup<decltype(DeviceFactory::createRootDeviceFunc)> createFuncBackup{&DeviceFactory::createRootDeviceFunc};
|
|
|
|
|
DeviceFactory::createRootDeviceFunc = [](ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex) -> std::unique_ptr<Device> {
|
|
|
|
|
return std::unique_ptr<Device>(MockDevice::create<MockDevice>(&executionEnvironment, rootDeviceIndex));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pPlatform->initializeWithNewDevices();
|
|
|
|
|
|
|
|
|
|
auto clDevice = pPlatform->getClDevice(0);
|
|
|
|
|
EXPECT_NE(nullptr, clDevice);
|
|
|
|
|
|
|
|
|
|
auto mockDevice = static_cast<MockDevice *>(&clDevice->getDevice());
|
|
|
|
|
EXPECT_FALSE(mockDevice->stopDirectSubmissionCalled);
|
|
|
|
|
|
|
|
|
|
clDevice->incRefInternal();
|
|
|
|
|
|
|
|
|
|
pPlatform = nullptr;
|
|
|
|
|
EXPECT_TRUE(mockDevice->stopDirectSubmissionCalled);
|
|
|
|
|
|
|
|
|
|
clDevice->decRefInternal();
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-14 14:32:11 +01:00
|
|
|
TEST_F(PlatformTest, WhenGetClDevicesIsCalledThenExpectedValuesAreReturned) {
|
|
|
|
|
EXPECT_EQ(nullptr, pPlatform->getClDevices());
|
|
|
|
|
|
2020-02-14 17:36:30 +01:00
|
|
|
pPlatform->initializeWithNewDevices();
|
2020-01-14 14:32:11 +01:00
|
|
|
|
|
|
|
|
EXPECT_NE(nullptr, pPlatform->getClDevices());
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
2020-07-06 16:19:32 +02:00
|
|
|
TEST_F(PlatformTest, givenSupportingCl21WhenGettingExtensionsStringThenSubgroupsIsEnabled) {
|
2020-10-07 13:37:34 +02:00
|
|
|
REQUIRE_OCL_21_OR_SKIP(defaultHwInfo);
|
|
|
|
|
|
2020-02-14 17:36:30 +01:00
|
|
|
pPlatform->initializeWithNewDevices();
|
2020-01-30 10:58:03 +01:00
|
|
|
auto compilerExtensions = pPlatform->getClDevice(0)->peekCompilerExtensions();
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2020-06-18 15:07:58 +02:00
|
|
|
auto isIndependentForwardProgressSupported = pPlatform->getClDevice(0)->getDeviceInfo().independentForwardProgress;
|
2020-03-25 13:06:45 +01:00
|
|
|
|
2022-03-14 10:15:57 +00:00
|
|
|
EXPECT_TRUE(hasSubstr(compilerExtensions, std::string(" -cl-ext=-all,+cl")));
|
2020-10-07 13:37:34 +02:00
|
|
|
if (isIndependentForwardProgressSupported) {
|
2022-03-14 10:15:57 +00:00
|
|
|
EXPECT_TRUE(hasSubstr(compilerExtensions, std::string("cl_khr_subgroups")));
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-19 16:18:06 +01:00
|
|
|
TEST_F(PlatformTest, givenMidThreadPreemptionWhenInitializingPlatformThenCallGetSipKernel) {
|
|
|
|
|
DebugManagerStateRestore dbgRestorer;
|
2023-11-30 08:32:25 +00:00
|
|
|
debugManager.flags.ForcePreemptionMode.set(static_cast<int32_t>(PreemptionMode::MidThread));
|
2018-11-19 16:18:06 +01:00
|
|
|
|
|
|
|
|
auto builtIns = new MockBuiltins();
|
2020-02-27 15:32:57 +01:00
|
|
|
auto executionEnvironment = pPlatform->peekExecutionEnvironment();
|
|
|
|
|
executionEnvironment->prepareRootDeviceEnvironments(1);
|
2024-06-19 11:04:27 +00:00
|
|
|
MockRootDeviceEnvironment::resetBuiltins(executionEnvironment->rootDeviceEnvironments[0].get(), builtIns);
|
2018-11-19 16:18:06 +01:00
|
|
|
|
2023-12-11 11:02:15 +00:00
|
|
|
EXPECT_EQ(SipKernelType::count, MockSipData::calledType);
|
2019-12-03 15:57:45 +01:00
|
|
|
EXPECT_FALSE(MockSipData::called);
|
2020-02-14 17:36:30 +01:00
|
|
|
pPlatform->initializeWithNewDevices();
|
2023-12-11 11:02:15 +00:00
|
|
|
EXPECT_EQ(SipKernelType::csr, MockSipData::calledType);
|
2019-12-03 15:57:45 +01:00
|
|
|
EXPECT_TRUE(MockSipData::called);
|
2018-11-19 16:18:06 +01:00
|
|
|
}
|
|
|
|
|
|
2024-07-10 15:03:33 +00:00
|
|
|
TEST_F(PlatformTest, givenDisabledPreemptionAndNoDebuggerWhenInitializingPlatformThenDoNotCallGetSipKernel) {
|
2018-11-19 16:18:06 +01:00
|
|
|
DebugManagerStateRestore dbgRestorer;
|
2023-11-30 08:32:25 +00:00
|
|
|
debugManager.flags.ForcePreemptionMode.set(static_cast<int32_t>(PreemptionMode::Disabled));
|
2018-11-19 16:18:06 +01:00
|
|
|
|
|
|
|
|
auto builtIns = new MockBuiltins();
|
2020-02-27 15:32:57 +01:00
|
|
|
auto executionEnvironment = pPlatform->peekExecutionEnvironment();
|
|
|
|
|
executionEnvironment->prepareRootDeviceEnvironments(1);
|
2024-06-19 11:04:27 +00:00
|
|
|
MockRootDeviceEnvironment::resetBuiltins(executionEnvironment->rootDeviceEnvironments[0].get(), builtIns);
|
2018-11-19 16:18:06 +01:00
|
|
|
|
2023-12-11 11:02:15 +00:00
|
|
|
EXPECT_EQ(SipKernelType::count, MockSipData::calledType);
|
2019-12-03 15:57:45 +01:00
|
|
|
EXPECT_FALSE(MockSipData::called);
|
2020-02-14 17:36:30 +01:00
|
|
|
pPlatform->initializeWithNewDevices();
|
2023-12-11 11:02:15 +00:00
|
|
|
EXPECT_EQ(SipKernelType::count, MockSipData::calledType);
|
2019-12-03 15:57:45 +01:00
|
|
|
EXPECT_FALSE(MockSipData::called);
|
2018-11-19 16:18:06 +01:00
|
|
|
}
|
|
|
|
|
|
2018-11-10 22:25:48 +01:00
|
|
|
TEST(PlatformTestSimple, givenCsrHwTypeWhenPlatformIsInitializedThenInitAubCenterIsNotCalled) {
|
|
|
|
|
DebugManagerStateRestore stateRestore;
|
2023-11-30 08:32:25 +00:00
|
|
|
debugManager.flags.SetCommandStreamReceiver.set(0);
|
2018-11-10 22:25:48 +01:00
|
|
|
MockPlatformWithMockExecutionEnvironment platform;
|
2020-02-11 11:39:25 +01:00
|
|
|
|
2020-02-14 17:36:30 +01:00
|
|
|
bool ret = platform.initializeWithNewDevices();
|
2018-11-10 22:25:48 +01:00
|
|
|
EXPECT_TRUE(ret);
|
2020-02-07 12:15:46 +01:00
|
|
|
auto rootDeviceEnvironment = static_cast<MockRootDeviceEnvironment *>(platform.peekExecutionEnvironment()->rootDeviceEnvironments[0].get());
|
2019-11-15 09:59:48 +01:00
|
|
|
EXPECT_FALSE(rootDeviceEnvironment->initAubCenterCalled);
|
2018-11-10 22:25:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(PlatformTestSimple, givenNotCsrHwTypeWhenPlatformIsInitializedThenInitAubCenterIsCalled) {
|
|
|
|
|
DebugManagerStateRestore stateRestore;
|
2023-11-30 08:32:25 +00:00
|
|
|
debugManager.flags.SetCommandStreamReceiver.set(1);
|
2020-02-03 13:19:12 +01:00
|
|
|
VariableBackup<UltHwConfig> backup(&ultHwConfig);
|
|
|
|
|
ultHwConfig.useHwCsr = true;
|
2018-11-10 22:25:48 +01:00
|
|
|
MockPlatformWithMockExecutionEnvironment platform;
|
2020-02-14 17:36:30 +01:00
|
|
|
bool ret = platform.initializeWithNewDevices();
|
2018-11-10 22:25:48 +01:00
|
|
|
EXPECT_TRUE(ret);
|
2020-02-07 12:15:46 +01:00
|
|
|
auto rootDeviceEnvironment = static_cast<MockRootDeviceEnvironment *>(platform.peekExecutionEnvironment()->rootDeviceEnvironments[0].get());
|
2019-11-15 09:59:48 +01:00
|
|
|
EXPECT_TRUE(rootDeviceEnvironment->initAubCenterCalled);
|
2018-11-10 22:25:48 +01:00
|
|
|
}
|
|
|
|
|
|
2020-06-16 20:54:15 +02:00
|
|
|
TEST(PlatformTestSimple, WhenConvertingCustomOclCFeaturesToCompilerInternalOptionsThenResultIsCorrect) {
|
2020-09-26 15:34:32 +02:00
|
|
|
OpenClCFeaturesContainer customOpenclCFeatures;
|
2020-06-16 20:54:15 +02:00
|
|
|
|
|
|
|
|
cl_name_version feature;
|
|
|
|
|
strcpy_s(feature.name, CL_NAME_VERSION_MAX_NAME_SIZE, "custom_feature");
|
|
|
|
|
customOpenclCFeatures.push_back(feature);
|
2020-11-16 16:56:33 +00:00
|
|
|
auto compilerOption = convertEnabledExtensionsToCompilerInternalOptions("", customOpenclCFeatures);
|
2020-11-25 15:11:11 +01:00
|
|
|
EXPECT_STREQ(" -cl-ext=-all,+custom_feature ", compilerOption.c_str());
|
2020-06-16 20:54:15 +02:00
|
|
|
|
|
|
|
|
strcpy_s(feature.name, CL_NAME_VERSION_MAX_NAME_SIZE, "other_extra_feature");
|
|
|
|
|
customOpenclCFeatures.push_back(feature);
|
2020-09-26 15:34:32 +02:00
|
|
|
compilerOption = convertEnabledExtensionsToCompilerInternalOptions("", customOpenclCFeatures);
|
2020-11-25 15:11:11 +01:00
|
|
|
EXPECT_STREQ(" -cl-ext=-all,+custom_feature,+other_extra_feature ", compilerOption.c_str());
|
2020-06-16 20:54:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(PlatformTestSimple, WhenConvertingOclCFeaturesToCompilerInternalOptionsThenResultIsCorrect) {
|
|
|
|
|
UltClDeviceFactory deviceFactory{1, 0};
|
|
|
|
|
auto pClDevice = deviceFactory.rootDevices[0];
|
|
|
|
|
|
2020-11-25 15:11:11 +01:00
|
|
|
std::string expectedCompilerOption = " -cl-ext=-all,";
|
2020-11-16 16:56:33 +00:00
|
|
|
for (auto &openclCFeature : pClDevice->deviceInfo.openclCFeatures) {
|
|
|
|
|
expectedCompilerOption += "+";
|
|
|
|
|
expectedCompilerOption += openclCFeature.name;
|
|
|
|
|
expectedCompilerOption += ",";
|
2020-09-26 15:34:32 +02:00
|
|
|
}
|
2020-11-16 16:56:33 +00:00
|
|
|
expectedCompilerOption.erase(expectedCompilerOption.size() - 1, 1);
|
|
|
|
|
expectedCompilerOption += " ";
|
|
|
|
|
|
|
|
|
|
auto compilerOption = convertEnabledExtensionsToCompilerInternalOptions("", pClDevice->deviceInfo.openclCFeatures);
|
|
|
|
|
EXPECT_STREQ(expectedCompilerOption.c_str(), compilerOption.c_str());
|
2020-06-16 20:54:15 +02:00
|
|
|
}
|
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2021-05-11 19:23:47 +00:00
|
|
|
extern CommandStreamReceiverCreateFunc commandStreamReceiverFactory[2 * IGFX_MAX_CORE];
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
2020-10-29 15:33:35 +01:00
|
|
|
CommandStreamReceiver *createMockCommandStreamReceiver(bool withAubDump,
|
|
|
|
|
ExecutionEnvironment &executionEnvironment,
|
|
|
|
|
uint32_t rootDeviceIndex,
|
|
|
|
|
const DeviceBitfield deviceBitfield) {
|
2017-12-21 00:45:38 +01:00
|
|
|
return nullptr;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class PlatformFailingTest : public PlatformTest {
|
|
|
|
|
public:
|
2020-02-03 13:19:12 +01:00
|
|
|
PlatformFailingTest() {
|
|
|
|
|
ultHwConfig.useHwCsr = true;
|
|
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
void SetUp() override {
|
|
|
|
|
PlatformTest::SetUp();
|
2020-03-24 17:52:43 +01:00
|
|
|
hwInfo = defaultHwInfo.get();
|
2019-05-08 16:00:24 +02:00
|
|
|
commandStreamReceiverCreateFunc = commandStreamReceiverFactory[hwInfo->platform.eRenderCoreFamily];
|
|
|
|
|
commandStreamReceiverFactory[hwInfo->platform.eRenderCoreFamily] = createMockCommandStreamReceiver;
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TearDown() override {
|
2019-05-08 16:00:24 +02:00
|
|
|
commandStreamReceiverFactory[hwInfo->platform.eRenderCoreFamily] = commandStreamReceiverCreateFunc;
|
2017-12-21 00:45:38 +01:00
|
|
|
PlatformTest::TearDown();
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-03 13:19:12 +01:00
|
|
|
VariableBackup<UltHwConfig> backup{&ultHwConfig};
|
2017-12-21 00:45:38 +01:00
|
|
|
CommandStreamReceiverCreateFunc commandStreamReceiverCreateFunc;
|
2023-04-13 14:16:49 +00:00
|
|
|
const HardwareInfo *hwInfo{};
|
2017-12-21 00:45:38 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST_F(PlatformFailingTest, givenPlatformInitializationWhenIncorrectHwInfoThenInitializationFails) {
|
2020-02-14 17:36:30 +01:00
|
|
|
auto platform = new MockPlatform();
|
|
|
|
|
bool ret = platform->initializeWithNewDevices();
|
2017-12-21 00:45:38 +01:00
|
|
|
EXPECT_FALSE(ret);
|
|
|
|
|
EXPECT_FALSE(platform->isInitialized());
|
|
|
|
|
delete platform;
|
|
|
|
|
}
|
2018-01-15 18:16:50 +01:00
|
|
|
|
2018-06-26 15:56:50 +02:00
|
|
|
TEST_F(PlatformTest, givenSupportingCl21WhenPlatformSupportsFp64ThenFillMatchingSubstringsAndMandatoryTrailingSpace) {
|
2018-01-15 18:16:50 +01:00
|
|
|
const HardwareInfo *hwInfo;
|
2020-03-24 17:52:43 +01:00
|
|
|
hwInfo = defaultHwInfo.get();
|
2023-04-13 14:16:49 +00:00
|
|
|
std::string extensionsList = compilerProductHelper->getDeviceExtensions(*hwInfo, releaseHelper.get());
|
2020-09-26 15:34:32 +02:00
|
|
|
OpenClCFeaturesContainer features;
|
2024-03-28 13:47:16 +00:00
|
|
|
getOpenclCFeaturesList(*hwInfo, features, *compilerProductHelper.get(), releaseHelper.get());
|
2018-01-15 18:16:50 +01:00
|
|
|
|
2020-09-26 15:34:32 +02:00
|
|
|
std::string compilerExtensions = convertEnabledExtensionsToCompilerInternalOptions(extensionsList.c_str(), features);
|
2022-03-14 10:15:57 +00:00
|
|
|
EXPECT_TRUE(hasSubstr(compilerExtensions, std::string(" -cl-ext=-all,+cl")));
|
2018-01-15 18:16:50 +01:00
|
|
|
|
2020-04-30 15:47:43 +02:00
|
|
|
if (hwInfo->capabilityTable.supportsOcl21Features) {
|
2021-05-13 14:58:26 +00:00
|
|
|
if (hwInfo->capabilityTable.supportsMediaBlock) {
|
2022-03-14 10:15:57 +00:00
|
|
|
EXPECT_TRUE(hasSubstr(compilerExtensions, std::string("cl_intel_spirv_media_block_io")));
|
2020-01-08 15:15:01 +01:00
|
|
|
} else {
|
2022-03-14 10:15:57 +00:00
|
|
|
EXPECT_FALSE(hasSubstr(compilerExtensions, std::string("cl_intel_spirv_media_block_io")));
|
2020-01-08 15:15:01 +01:00
|
|
|
}
|
|
|
|
|
|
2022-03-14 10:15:57 +00:00
|
|
|
EXPECT_TRUE(hasSubstr(compilerExtensions, std::string("cl_intel_spirv_subgroups")));
|
2023-07-11 08:29:24 +02:00
|
|
|
EXPECT_TRUE(hasSubstr(compilerExtensions, std::string("cl_khr_spirv_linkonce_odr")));
|
2022-03-14 10:15:57 +00:00
|
|
|
EXPECT_TRUE(hasSubstr(compilerExtensions, std::string("cl_khr_spirv_no_integer_wrap_decoration")));
|
2025-05-30 02:29:39 +00:00
|
|
|
EXPECT_TRUE(hasSubstr(compilerExtensions, std::string("cl_khr_spirv_queries")));
|
2018-01-15 18:16:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hwInfo->capabilityTable.ftrSupportsFP64) {
|
2022-03-14 10:15:57 +00:00
|
|
|
EXPECT_TRUE(hasSubstr(compilerExtensions, std::string("cl_khr_fp64")));
|
2018-01-15 18:16:50 +01:00
|
|
|
}
|
2018-06-26 15:56:50 +02:00
|
|
|
|
2020-02-14 14:07:31 +01:00
|
|
|
if (hwInfo->capabilityTable.supportsImages) {
|
2022-03-14 10:15:57 +00:00
|
|
|
EXPECT_TRUE(hasSubstr(extensionsList, std::string("cl_khr_3d_image_writes")));
|
2020-02-14 14:07:31 +01:00
|
|
|
}
|
2022-03-14 10:15:57 +00:00
|
|
|
EXPECT_TRUE(endsWith(compilerExtensions, std::string(" ")));
|
2018-01-15 18:16:50 +01:00
|
|
|
}
|
|
|
|
|
|
2018-06-26 15:56:50 +02:00
|
|
|
TEST_F(PlatformTest, givenNotSupportingCl21WhenPlatformNotSupportFp64ThenNotFillMatchingSubstringAndFillMandatoryTrailingSpace) {
|
2022-05-12 14:04:41 +00:00
|
|
|
HardwareInfo testHwInfo = *defaultHwInfo;
|
|
|
|
|
testHwInfo.capabilityTable.ftrSupportsFP64 = false;
|
|
|
|
|
testHwInfo.capabilityTable.clVersionSupport = 10;
|
|
|
|
|
testHwInfo.capabilityTable.supportsOcl21Features = false;
|
2018-01-15 18:16:50 +01:00
|
|
|
|
2023-04-13 14:16:49 +00:00
|
|
|
std::string extensionsList = compilerProductHelper->getDeviceExtensions(testHwInfo, releaseHelper.get());
|
2020-09-26 15:34:32 +02:00
|
|
|
OpenClCFeaturesContainer features;
|
2024-03-28 13:47:16 +00:00
|
|
|
getOpenclCFeaturesList(*defaultHwInfo, features, *compilerProductHelper.get(), releaseHelper.get());
|
2022-05-12 14:04:41 +00:00
|
|
|
if (testHwInfo.capabilityTable.supportsImages) {
|
2022-03-14 10:15:57 +00:00
|
|
|
EXPECT_TRUE(hasSubstr(extensionsList, std::string("cl_khr_3d_image_writes")));
|
2020-02-14 14:07:31 +01:00
|
|
|
}
|
2018-01-15 18:16:50 +01:00
|
|
|
|
2020-09-26 15:34:32 +02:00
|
|
|
std::string compilerExtensions = convertEnabledExtensionsToCompilerInternalOptions(extensionsList.c_str(), features);
|
2022-03-14 10:15:57 +00:00
|
|
|
EXPECT_TRUE(hasSubstr(compilerExtensions, std::string("-cl-ext=-all,+cl")));
|
2018-01-15 18:16:50 +01:00
|
|
|
|
2022-03-14 10:15:57 +00:00
|
|
|
EXPECT_FALSE(hasSubstr(compilerExtensions, std::string("cl_khr_fp64")));
|
2018-06-26 15:56:50 +02:00
|
|
|
|
2022-03-14 10:15:57 +00:00
|
|
|
EXPECT_TRUE(endsWith(compilerExtensions, std::string(" ")));
|
2018-01-15 18:16:50 +01:00
|
|
|
}
|
|
|
|
|
|
2019-08-20 15:17:10 +02:00
|
|
|
TEST_F(PlatformTest, givenFtrSupportAtomicsWhenCreateExtentionsListThenGetMatchingSubstrings) {
|
|
|
|
|
const HardwareInfo *hwInfo;
|
2020-03-24 17:52:43 +01:00
|
|
|
hwInfo = defaultHwInfo.get();
|
2023-04-13 14:16:49 +00:00
|
|
|
std::string extensionsList = compilerProductHelper->getDeviceExtensions(*hwInfo, releaseHelper.get());
|
2020-09-26 15:34:32 +02:00
|
|
|
OpenClCFeaturesContainer features;
|
2024-03-28 13:47:16 +00:00
|
|
|
getOpenclCFeaturesList(*hwInfo, features, *compilerProductHelper.get(), releaseHelper.get());
|
2020-09-26 15:34:32 +02:00
|
|
|
std::string compilerExtensions = convertEnabledExtensionsToCompilerInternalOptions(extensionsList.c_str(), features);
|
2019-08-20 15:17:10 +02:00
|
|
|
|
|
|
|
|
if (hwInfo->capabilityTable.ftrSupportsInteger64BitAtomics) {
|
2022-03-14 10:15:57 +00:00
|
|
|
EXPECT_TRUE(hasSubstr(compilerExtensions, std::string("cl_khr_int64_base_atomics")));
|
|
|
|
|
EXPECT_TRUE(hasSubstr(compilerExtensions, std::string("cl_khr_int64_extended_atomics")));
|
2019-08-20 15:17:10 +02:00
|
|
|
} else {
|
2022-03-14 10:15:57 +00:00
|
|
|
EXPECT_FALSE(hasSubstr(compilerExtensions, std::string("cl_khr_int64_base_atomics")));
|
|
|
|
|
EXPECT_FALSE(hasSubstr(compilerExtensions, std::string("cl_khr_int64_extended_atomics")));
|
2019-08-20 15:17:10 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-13 14:58:26 +00:00
|
|
|
TEST_F(PlatformTest, givenSupportedMediaBlockAndClVersion21WhenCreateExtentionsListThenDeviceReportsSpritvMediaBlockIoExtension) {
|
2020-03-24 11:42:54 +01:00
|
|
|
HardwareInfo hwInfo = *defaultHwInfo;
|
2021-05-13 14:58:26 +00:00
|
|
|
hwInfo.capabilityTable.supportsMediaBlock = true;
|
2020-01-08 15:15:01 +01:00
|
|
|
hwInfo.capabilityTable.clVersionSupport = 21;
|
2020-04-30 15:47:43 +02:00
|
|
|
hwInfo.capabilityTable.supportsOcl21Features = true;
|
2023-04-13 14:16:49 +00:00
|
|
|
std::string extensionsList = compilerProductHelper->getDeviceExtensions(hwInfo, releaseHelper.get());
|
2020-09-26 15:34:32 +02:00
|
|
|
OpenClCFeaturesContainer features;
|
2024-03-28 13:47:16 +00:00
|
|
|
getOpenclCFeaturesList(*defaultHwInfo, features, *compilerProductHelper.get(), releaseHelper.get());
|
2020-09-26 15:34:32 +02:00
|
|
|
std::string compilerExtensions = convertEnabledExtensionsToCompilerInternalOptions(extensionsList.c_str(), features);
|
2020-01-08 15:15:01 +01:00
|
|
|
|
2022-03-14 10:15:57 +00:00
|
|
|
EXPECT_TRUE(hasSubstr(compilerExtensions, std::string("cl_intel_spirv_media_block_io")));
|
2020-01-08 15:15:01 +01:00
|
|
|
}
|
|
|
|
|
|
2021-05-13 14:58:26 +00:00
|
|
|
TEST_F(PlatformTest, givenNotSupportedMediaBlockAndClVersion21WhenCreateExtentionsListThenDeviceNotReportsSpritvMediaBlockIoExtension) {
|
2020-03-24 11:42:54 +01:00
|
|
|
HardwareInfo hwInfo = *defaultHwInfo;
|
2021-05-13 14:58:26 +00:00
|
|
|
hwInfo.capabilityTable.supportsMediaBlock = false;
|
2020-01-08 15:15:01 +01:00
|
|
|
hwInfo.capabilityTable.clVersionSupport = 21;
|
2023-04-13 14:16:49 +00:00
|
|
|
std::string extensionsList = compilerProductHelper->getDeviceExtensions(hwInfo, releaseHelper.get());
|
2020-09-26 15:34:32 +02:00
|
|
|
OpenClCFeaturesContainer features;
|
2024-03-28 13:47:16 +00:00
|
|
|
getOpenclCFeaturesList(*defaultHwInfo, features, *compilerProductHelper.get(), releaseHelper.get());
|
2020-09-26 15:34:32 +02:00
|
|
|
std::string compilerExtensions = convertEnabledExtensionsToCompilerInternalOptions(extensionsList.c_str(), features);
|
2020-01-08 15:15:01 +01:00
|
|
|
|
2022-03-14 10:15:57 +00:00
|
|
|
EXPECT_FALSE(hasSubstr(compilerExtensions, std::string("cl_intel_spirv_media_block_io")));
|
2020-01-08 15:15:01 +01:00
|
|
|
}
|
|
|
|
|
|
2021-05-13 14:58:26 +00:00
|
|
|
TEST_F(PlatformTest, givenSupportedImagesWhenCreateExtentionsListThenDeviceNotReportsKhr3DImageWritesExtension) {
|
|
|
|
|
HardwareInfo hwInfo = *defaultHwInfo;
|
|
|
|
|
hwInfo.capabilityTable.supportsImages = true;
|
2023-04-13 14:16:49 +00:00
|
|
|
std::string extensionsList = compilerProductHelper->getDeviceExtensions(hwInfo, releaseHelper.get());
|
2021-05-13 14:58:26 +00:00
|
|
|
OpenClCFeaturesContainer features;
|
2024-03-28 13:47:16 +00:00
|
|
|
getOpenclCFeaturesList(*defaultHwInfo, features, *compilerProductHelper.get(), releaseHelper.get());
|
2021-05-13 14:58:26 +00:00
|
|
|
std::string compilerExtensions = convertEnabledExtensionsToCompilerInternalOptions(extensionsList.c_str(), features);
|
|
|
|
|
|
2022-03-14 10:15:57 +00:00
|
|
|
EXPECT_TRUE(hasSubstr(compilerExtensions, std::string("cl_khr_3d_image_writes")));
|
2021-05-13 14:58:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(PlatformTest, givenNotSupportedImagesWhenCreateExtentionsListThenDeviceNotReportsKhr3DImageWritesExtension) {
|
|
|
|
|
HardwareInfo hwInfo = *defaultHwInfo;
|
|
|
|
|
hwInfo.capabilityTable.supportsImages = false;
|
2023-04-13 14:16:49 +00:00
|
|
|
std::string extensionsList = compilerProductHelper->getDeviceExtensions(hwInfo, releaseHelper.get());
|
2021-05-13 14:58:26 +00:00
|
|
|
OpenClCFeaturesContainer features;
|
2024-03-28 13:47:16 +00:00
|
|
|
getOpenclCFeaturesList(*defaultHwInfo, features, *compilerProductHelper.get(), releaseHelper.get());
|
2021-05-13 14:58:26 +00:00
|
|
|
std::string compilerExtensions = convertEnabledExtensionsToCompilerInternalOptions(extensionsList.c_str(), features);
|
|
|
|
|
|
2022-03-14 10:15:57 +00:00
|
|
|
EXPECT_FALSE(hasSubstr(compilerExtensions, std::string("cl_khr_3d_image_writes")));
|
2021-05-13 14:58:26 +00:00
|
|
|
}
|
|
|
|
|
|
2018-06-26 16:15:48 +02:00
|
|
|
TEST(PlatformConstructionTest, givenPlatformConstructorWhenItIsCalledTwiceThenTheSamePlatformIsReturned) {
|
2020-09-01 12:38:50 +02:00
|
|
|
platformsImpl->clear();
|
2020-02-03 16:18:21 +01:00
|
|
|
auto platform1 = constructPlatform();
|
|
|
|
|
EXPECT_EQ(platform1, platform());
|
2018-06-26 16:15:48 +02:00
|
|
|
auto platform2 = constructPlatform();
|
2020-02-03 16:18:21 +01:00
|
|
|
EXPECT_EQ(platform2, platform1);
|
|
|
|
|
EXPECT_NE(platform1, nullptr);
|
2018-06-26 16:15:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(PlatformConstructionTest, givenPlatformConstructorWhenItIsCalledAfterResetThenNewPlatformIsConstructed) {
|
2020-09-01 12:38:50 +02:00
|
|
|
platformsImpl->clear();
|
2018-06-26 16:15:48 +02:00
|
|
|
auto platform = constructPlatform();
|
2020-09-01 12:38:50 +02:00
|
|
|
std::unique_ptr<Platform> temporaryOwnership(std::move((*platformsImpl)[0]));
|
|
|
|
|
platformsImpl->clear();
|
2018-06-26 16:15:48 +02:00
|
|
|
auto platform2 = constructPlatform();
|
|
|
|
|
EXPECT_NE(platform2, platform);
|
|
|
|
|
EXPECT_NE(platform, nullptr);
|
|
|
|
|
EXPECT_NE(platform2, nullptr);
|
2020-09-01 12:38:50 +02:00
|
|
|
platformsImpl->clear();
|
2018-06-26 16:15:48 +02:00
|
|
|
}
|
2018-06-28 08:51:44 +02:00
|
|
|
|
2020-02-14 17:36:30 +01: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 10:13:46 +01:00
|
|
|
TEST(PlatformInitTest, givenSingleDeviceWithNonZeroRootDeviceIndexInPassedDeviceVectorWhenInitializePlatformThenCreateOnlyOneClDevice) {
|
|
|
|
|
std::vector<std::unique_ptr<Device>> devices;
|
2020-03-24 17:52:43 +01:00
|
|
|
auto executionEnvironment = new MockExecutionEnvironment(defaultHwInfo.get(), false, 3);
|
2025-07-02 12:44:21 +00:00
|
|
|
devices.push_back(std::unique_ptr<Device>(MockDevice::createWithExecutionEnvironment<MockDevice>(defaultHwInfo.get(), executionEnvironment, 2)));
|
2020-03-02 10:13:46 +01:00
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-12 09:23:51 +00:00
|
|
|
TEST(PlatformInitTest, GivenPreferredPlatformNameWhenPlatformIsInitializedThenOverridePlatformName) {
|
|
|
|
|
std::vector<std::unique_ptr<Device>> devices;
|
|
|
|
|
auto executionEnvironment = new MockExecutionEnvironment(defaultHwInfo.get(), false, 1);
|
2025-07-02 12:44:21 +00:00
|
|
|
devices.push_back(std::unique_ptr<Device>(MockDevice::createWithExecutionEnvironment<MockDevice>(defaultHwInfo.get(), executionEnvironment, 0)));
|
2023-09-12 09:23:51 +00:00
|
|
|
executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo()->capabilityTable.preferredPlatformName = "Overridden Platform Name";
|
|
|
|
|
auto status = platform()->initialize(std::move(devices));
|
|
|
|
|
EXPECT_TRUE(status);
|
|
|
|
|
EXPECT_STREQ("Overridden Platform Name", platform()->getPlatformInfo().name.c_str());
|
|
|
|
|
}
|