Simplify platform initialize.

- Remove not required parameters
- move the logic to ult directories

Change-Id: I913f1048489137a61220d96fa9f2798572cd4f56
This commit is contained in:
Mrozek, Michal
2018-06-20 18:25:40 +02:00
committed by sys_ocldev
parent 6540a9c96b
commit 5c0a562a6b
12 changed files with 27 additions and 35 deletions

2
Jenkinsfile vendored
View File

@@ -1,4 +1,4 @@
#!groovy #!groovy
neoDependenciesRev='769497-961' neoDependenciesRev='769497-961'
strategy='EQUAL' strategy='EQUAL'
allowedCD=301 allowedCD=299

View File

@@ -74,10 +74,9 @@ cl_int CL_API_CALL clGetPlatformIDs(cl_uint numEntries,
break; break;
} }
// if the platforms are non-nullptr, we need to fill in the platform IDs
while (platforms != nullptr) { while (platforms != nullptr) {
auto pPlatform = platform(); auto pPlatform = platform();
bool ret = pPlatform->initialize(numPlatformDevices, platformDevices); bool ret = pPlatform->initialize();
DEBUG_BREAK_IF(ret != true); DEBUG_BREAK_IF(ret != true);
if (!ret) { if (!ret) {
retVal = CL_INVALID_VALUE; retVal = CL_INVALID_VALUE;
@@ -158,9 +157,8 @@ cl_int CL_API_CALL clGetDeviceIDs(cl_platform_id platform,
break; break;
} }
} else { } else {
/* If platform is nullptr, we choose our default platform. */
pPlatform = ::platform(); pPlatform = ::platform();
bool ret = pPlatform->initialize(numPlatformDevices, platformDevices); bool ret = pPlatform->initialize();
DEBUG_BREAK_IF(ret != true); DEBUG_BREAK_IF(ret != true);
((void)(ret)); ((void)(ret));
} }

View File

@@ -106,11 +106,9 @@ const std::string &Platform::peekCompilerExtensions() const {
return compilerExtensions; return compilerExtensions;
} }
bool Platform::initialize(size_t numDevices, bool Platform::initialize() {
const HardwareInfo **devices) {
HardwareInfo *hwInfo = nullptr; HardwareInfo *hwInfo = nullptr;
size_t numDevicesReturned = 0; size_t numDevicesReturned = 0;
const HardwareInfo **hwInfoConst = nullptr;
TakeOwnershipWrapper<Platform> platformOwnership(*this); TakeOwnershipWrapper<Platform> platformOwnership(*this);
@@ -124,15 +122,12 @@ bool Platform::initialize(size_t numDevices,
return false; return false;
} }
hwInfoConst = (hwInfo != nullptr) ? const_cast<const HardwareInfo **>(&hwInfo) : devices;
numDevicesReturned = (hwInfo != nullptr) ? numDevicesReturned : numDevices;
DEBUG_BREAK_IF(this->platformInfo); DEBUG_BREAK_IF(this->platformInfo);
this->platformInfo = new PlatformInfo; this->platformInfo = new PlatformInfo;
this->devices.resize(numDevicesReturned); this->devices.resize(numDevicesReturned);
for (size_t deviceOrdinal = 0; deviceOrdinal < numDevicesReturned; ++deviceOrdinal) { for (size_t deviceOrdinal = 0; deviceOrdinal < numDevicesReturned; ++deviceOrdinal) {
auto pDevice = Device::create<OCLRT::Device>(hwInfoConst[deviceOrdinal]); auto pDevice = Device::create<OCLRT::Device>(&hwInfo[deviceOrdinal]);
DEBUG_BREAK_IF(!pDevice); DEBUG_BREAK_IF(!pDevice);
if (pDevice) { if (pDevice) {
this->devices[deviceOrdinal] = pDevice; this->devices[deviceOrdinal] = pDevice;

View File

@@ -54,8 +54,7 @@ class Platform : public BaseObject<_cl_platform_id> {
const std::string &peekCompilerExtensions() const; const std::string &peekCompilerExtensions() const;
bool initialize(size_t numDevices, bool initialize();
const HardwareInfo **devices);
bool isInitialized(); bool isInitialized();
void shutdown(); void shutdown();

View File

@@ -32,11 +32,11 @@ using namespace OCLRT;
struct GetDevicesTest : ::testing::TestWithParam<std::tuple<CommandStreamReceiverType, const char *>> { struct GetDevicesTest : ::testing::TestWithParam<std::tuple<CommandStreamReceiverType, const char *>> {
void SetUp() override { void SetUp() override {
overrideDeviceWithNullHardwareInfo = false; overrideDeviceWithDefaultHardwareInfo = false;
gtSystemInfo = *platformDevices[0]->pSysInfo; gtSystemInfo = *platformDevices[0]->pSysInfo;
} }
void TearDown() override { void TearDown() override {
overrideDeviceWithNullHardwareInfo = true; overrideDeviceWithDefaultHardwareInfo = true;
memcpy(const_cast<GT_SYSTEM_INFO *>(platformDevices[0]->pSysInfo), &gtSystemInfo, sizeof(GT_SYSTEM_INFO)); memcpy(const_cast<GT_SYSTEM_INFO *>(platformDevices[0]->pSysInfo), &gtSystemInfo, sizeof(GT_SYSTEM_INFO));
} }
GT_SYSTEM_INFO gtSystemInfo; GT_SYSTEM_INFO gtSystemInfo;

View File

@@ -21,6 +21,7 @@
*/ */
#include "unit_tests/fixtures/platform_fixture.h" #include "unit_tests/fixtures/platform_fixture.h"
#include "unit_tests/libult/create_command_stream.h"
#include "runtime/device/device.h" #include "runtime/device/device.h"
#include "runtime/platform/platform.h" #include "runtime/platform/platform.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@@ -28,9 +29,7 @@
namespace OCLRT { namespace OCLRT {
PlatformFixture::PlatformFixture() PlatformFixture::PlatformFixture()
: pPlatform(nullptr), num_devices(0), devices(nullptr) : pPlatform(nullptr), num_devices(0), devices(nullptr) {
{
} }
void PlatformFixture::SetUp(size_t numDevices, const HardwareInfo **pDevices) { void PlatformFixture::SetUp(size_t numDevices, const HardwareInfo **pDevices) {
@@ -38,7 +37,7 @@ void PlatformFixture::SetUp(size_t numDevices, const HardwareInfo **pDevices) {
ASSERT_EQ(0u, pPlatform->getNumDevices()); ASSERT_EQ(0u, pPlatform->getNumDevices());
// setup platform / context // setup platform / context
bool isInitialized = pPlatform->initialize(numDevices, pDevices); bool isInitialized = pPlatform->initialize();
ASSERT_EQ(true, isInitialized); ASSERT_EQ(true, isInitialized);
num_devices = static_cast<cl_uint>(pPlatform->getNumDevices()); num_devices = static_cast<cl_uint>(pPlatform->getNumDevices());

View File

@@ -134,7 +134,7 @@ class GTPinFixture : public ContextFixture, public MemoryManagementFixture {
void SetUp() override { void SetUp() override {
MemoryManagementFixture::SetUp(); MemoryManagementFixture::SetUp();
pPlatform = platform(); pPlatform = platform();
pPlatform->initialize(numPlatformDevices, platformDevices); pPlatform->initialize();
pDevice = pPlatform->getDevice(0); pDevice = pPlatform->getDevice(0);
cl_device_id device = (cl_device_id)pDevice; cl_device_id device = (cl_device_id)pDevice;
ContextFixture::SetUp(1, &device); ContextFixture::SetUp(1, &device);

View File

@@ -34,7 +34,7 @@ extern CommandStreamReceiverCreateFunc commandStreamReceiverFactory[2 * IGFX_MAX
bool getDevicesResult = true; bool getDevicesResult = true;
bool overrideCommandStreamReceiverCreation = false; bool overrideCommandStreamReceiverCreation = false;
bool overrideDeviceWithNullHardwareInfo = true; bool overrideDeviceWithDefaultHardwareInfo = true;
CommandStreamReceiver *createCommandStream(const HardwareInfo *pHwInfo) { CommandStreamReceiver *createCommandStream(const HardwareInfo *pHwInfo) {
CommandStreamReceiver *commandStreamReceiver = nullptr; CommandStreamReceiver *commandStreamReceiver = nullptr;
@@ -53,11 +53,12 @@ CommandStreamReceiver *createCommandStream(const HardwareInfo *pHwInfo) {
} }
bool getDevices(HardwareInfo **hwInfo, size_t &numDevicesReturned) { bool getDevices(HardwareInfo **hwInfo, size_t &numDevicesReturned) {
if (overrideDeviceWithNullHardwareInfo) { if (overrideDeviceWithDefaultHardwareInfo) {
*hwInfo = nullptr; *hwInfo = const_cast<HardwareInfo *>(*platformDevices);
numDevicesReturned = 0; numDevicesReturned = numPlatformDevices;
return getDevicesResult; return getDevicesResult;
} }
return getDevicesImpl(hwInfo, numDevicesReturned); return getDevicesImpl(hwInfo, numDevicesReturned);
} }
} // namespace OCLRT } // namespace OCLRT

View File

@@ -24,7 +24,7 @@
namespace OCLRT { namespace OCLRT {
extern bool overrideCommandStreamReceiverCreation; extern bool overrideCommandStreamReceiverCreation;
extern bool overrideDeviceWithNullHardwareInfo; extern bool overrideDeviceWithDefaultHardwareInfo;
extern CommandStreamReceiver *createCommandStream(const HardwareInfo *pHwInfo); extern CommandStreamReceiver *createCommandStream(const HardwareInfo *pHwInfo);
extern bool getDevices(HardwareInfo **hwInfo, size_t &numDevicesReturned); extern bool getDevices(HardwareInfo **hwInfo, size_t &numDevicesReturned);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2017, Intel Corporation * Copyright (c) 2017 - 2018, Intel Corporation
* *
* Permission is hereby granted, free of charge, to any person obtaining a * Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"), * copy of this software and associated documentation files (the "Software"),
@@ -55,6 +55,6 @@ TEST_F(PlatformNegativeTest, GivenPlatformWhenGetDevicesFailedThenFalseIsReturne
VariableBackup<decltype(getDevicesResult)> bkp(&getDevicesResult, false); VariableBackup<decltype(getDevicesResult)> bkp(&getDevicesResult, false);
auto ret = pPlatform->initialize(numPlatformDevices, platformDevices); auto ret = pPlatform->initialize();
EXPECT_FALSE(ret); EXPECT_FALSE(ret);
} }

View File

@@ -51,7 +51,7 @@ TEST_F(PlatformTest, getDevices) {
Device *device = pPlatform->getDevice(0); Device *device = pPlatform->getDevice(0);
EXPECT_EQ(nullptr, device); EXPECT_EQ(nullptr, device);
bool ret = pPlatform->initialize(numPlatformDevices, platformDevices); bool ret = pPlatform->initialize();
EXPECT_TRUE(ret); EXPECT_TRUE(ret);
EXPECT_TRUE(pPlatform->isInitialized()); EXPECT_TRUE(pPlatform->isInitialized());
@@ -80,7 +80,7 @@ TEST_F(PlatformTest, PlatformgetAsCompilerEnabledExtensionsString) {
std::string compilerExtensions = pPlatform->peekCompilerExtensions(); std::string compilerExtensions = pPlatform->peekCompilerExtensions();
EXPECT_EQ(std::string(""), compilerExtensions); EXPECT_EQ(std::string(""), compilerExtensions);
pPlatform->initialize(numPlatformDevices, platformDevices); pPlatform->initialize();
compilerExtensions = pPlatform->peekCompilerExtensions(); compilerExtensions = pPlatform->peekCompilerExtensions();
EXPECT_THAT(compilerExtensions, ::testing::HasSubstr(std::string(" -cl-ext=-all,+cl"))); EXPECT_THAT(compilerExtensions, ::testing::HasSubstr(std::string(" -cl-ext=-all,+cl")));
@@ -95,7 +95,7 @@ TEST_F(PlatformTest, PlatformgetAsCompilerEnabledExtensionsString) {
TEST_F(PlatformTest, destructorCallsShutdownAndReleasesAllResources) { TEST_F(PlatformTest, destructorCallsShutdownAndReleasesAllResources) {
Platform *platform = new Platform; Platform *platform = new Platform;
ASSERT_NE(nullptr, platform); ASSERT_NE(nullptr, platform);
platform->initialize(numPlatformDevices, platformDevices); platform->initialize();
delete platform; delete platform;
} }
@@ -147,7 +147,7 @@ class PlatformFailingTest : public PlatformTest {
TEST_F(PlatformFailingTest, givenPlatformInitializationWhenIncorrectHwInfoThenInitializationFails) { TEST_F(PlatformFailingTest, givenPlatformInitializationWhenIncorrectHwInfoThenInitializationFails) {
Platform *platform = new Platform; Platform *platform = new Platform;
bool ret = platform->initialize(numPlatformDevices, platformDevices); bool ret = platform->initialize();
EXPECT_FALSE(ret); EXPECT_FALSE(ret);
EXPECT_FALSE(platform->isInitialized()); EXPECT_FALSE(platform->isInitialized());
delete platform; delete platform;

View File

@@ -34,7 +34,7 @@ struct PlatformTestMt : public ::testing::Test {
void TearDown() override {} void TearDown() override {}
static void initThreadFunc(Platform *pP) { static void initThreadFunc(Platform *pP) {
pP->initialize(numPlatformDevices, platformDevices); pP->initialize();
} }
static void shutdownThreadFunc(Platform *pP) { static void shutdownThreadFunc(Platform *pP) {
@@ -46,7 +46,7 @@ struct PlatformTestMt : public ::testing::Test {
}; };
static void callinitPlatform(Platform *plt, bool *ret) { static void callinitPlatform(Platform *plt, bool *ret) {
*ret = plt->initialize(numPlatformDevices, platformDevices); *ret = plt->initialize();
} }
TEST_F(PlatformTestMt, initialize) { TEST_F(PlatformTestMt, initialize) {
@@ -83,7 +83,7 @@ TEST_F(PlatformTestMt, mtSafeTest) {
size_t devNum = pPlatform->getNumDevices(); size_t devNum = pPlatform->getNumDevices();
EXPECT_EQ(0u, devNum); EXPECT_EQ(0u, devNum);
bool ret = pPlatform->initialize(numPlatformDevices, platformDevices); bool ret = pPlatform->initialize();
std::thread t1(PlatformTestMt::initThreadFunc, pPlatform); std::thread t1(PlatformTestMt::initThreadFunc, pPlatform);
std::thread t2(PlatformTestMt::shutdownThreadFunc, pPlatform); std::thread t2(PlatformTestMt::shutdownThreadFunc, pPlatform);
EXPECT_TRUE(ret); EXPECT_TRUE(ret);