mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Simplify platform initialize.
- Remove not required parameters - move the logic to ult directories Change-Id: I913f1048489137a61220d96fa9f2798572cd4f56
This commit is contained in:

committed by
sys_ocldev

parent
6540a9c96b
commit
5c0a562a6b
2
Jenkinsfile
vendored
2
Jenkinsfile
vendored
@ -1,4 +1,4 @@
|
||||
#!groovy
|
||||
neoDependenciesRev='769497-961'
|
||||
strategy='EQUAL'
|
||||
allowedCD=301
|
||||
allowedCD=299
|
||||
|
@ -74,10 +74,9 @@ cl_int CL_API_CALL clGetPlatformIDs(cl_uint numEntries,
|
||||
break;
|
||||
}
|
||||
|
||||
// if the platforms are non-nullptr, we need to fill in the platform IDs
|
||||
while (platforms != nullptr) {
|
||||
auto pPlatform = platform();
|
||||
bool ret = pPlatform->initialize(numPlatformDevices, platformDevices);
|
||||
bool ret = pPlatform->initialize();
|
||||
DEBUG_BREAK_IF(ret != true);
|
||||
if (!ret) {
|
||||
retVal = CL_INVALID_VALUE;
|
||||
@ -158,9 +157,8 @@ cl_int CL_API_CALL clGetDeviceIDs(cl_platform_id platform,
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
/* If platform is nullptr, we choose our default platform. */
|
||||
pPlatform = ::platform();
|
||||
bool ret = pPlatform->initialize(numPlatformDevices, platformDevices);
|
||||
bool ret = pPlatform->initialize();
|
||||
DEBUG_BREAK_IF(ret != true);
|
||||
((void)(ret));
|
||||
}
|
||||
|
@ -106,11 +106,9 @@ const std::string &Platform::peekCompilerExtensions() const {
|
||||
return compilerExtensions;
|
||||
}
|
||||
|
||||
bool Platform::initialize(size_t numDevices,
|
||||
const HardwareInfo **devices) {
|
||||
bool Platform::initialize() {
|
||||
HardwareInfo *hwInfo = nullptr;
|
||||
size_t numDevicesReturned = 0;
|
||||
const HardwareInfo **hwInfoConst = nullptr;
|
||||
|
||||
TakeOwnershipWrapper<Platform> platformOwnership(*this);
|
||||
|
||||
@ -124,15 +122,12 @@ bool Platform::initialize(size_t numDevices,
|
||||
return false;
|
||||
}
|
||||
|
||||
hwInfoConst = (hwInfo != nullptr) ? const_cast<const HardwareInfo **>(&hwInfo) : devices;
|
||||
numDevicesReturned = (hwInfo != nullptr) ? numDevicesReturned : numDevices;
|
||||
|
||||
DEBUG_BREAK_IF(this->platformInfo);
|
||||
this->platformInfo = new PlatformInfo;
|
||||
|
||||
this->devices.resize(numDevicesReturned);
|
||||
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);
|
||||
if (pDevice) {
|
||||
this->devices[deviceOrdinal] = pDevice;
|
||||
|
@ -54,8 +54,7 @@ class Platform : public BaseObject<_cl_platform_id> {
|
||||
|
||||
const std::string &peekCompilerExtensions() const;
|
||||
|
||||
bool initialize(size_t numDevices,
|
||||
const HardwareInfo **devices);
|
||||
bool initialize();
|
||||
bool isInitialized();
|
||||
void shutdown();
|
||||
|
||||
|
@ -32,11 +32,11 @@ using namespace OCLRT;
|
||||
|
||||
struct GetDevicesTest : ::testing::TestWithParam<std::tuple<CommandStreamReceiverType, const char *>> {
|
||||
void SetUp() override {
|
||||
overrideDeviceWithNullHardwareInfo = false;
|
||||
overrideDeviceWithDefaultHardwareInfo = false;
|
||||
gtSystemInfo = *platformDevices[0]->pSysInfo;
|
||||
}
|
||||
void TearDown() override {
|
||||
overrideDeviceWithNullHardwareInfo = true;
|
||||
overrideDeviceWithDefaultHardwareInfo = true;
|
||||
memcpy(const_cast<GT_SYSTEM_INFO *>(platformDevices[0]->pSysInfo), >SystemInfo, sizeof(GT_SYSTEM_INFO));
|
||||
}
|
||||
GT_SYSTEM_INFO gtSystemInfo;
|
||||
|
@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "unit_tests/fixtures/platform_fixture.h"
|
||||
#include "unit_tests/libult/create_command_stream.h"
|
||||
#include "runtime/device/device.h"
|
||||
#include "runtime/platform/platform.h"
|
||||
#include "gtest/gtest.h"
|
||||
@ -28,9 +29,7 @@
|
||||
namespace OCLRT {
|
||||
|
||||
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) {
|
||||
@ -38,7 +37,7 @@ void PlatformFixture::SetUp(size_t numDevices, const HardwareInfo **pDevices) {
|
||||
ASSERT_EQ(0u, pPlatform->getNumDevices());
|
||||
|
||||
// setup platform / context
|
||||
bool isInitialized = pPlatform->initialize(numDevices, pDevices);
|
||||
bool isInitialized = pPlatform->initialize();
|
||||
ASSERT_EQ(true, isInitialized);
|
||||
|
||||
num_devices = static_cast<cl_uint>(pPlatform->getNumDevices());
|
||||
|
@ -134,7 +134,7 @@ class GTPinFixture : public ContextFixture, public MemoryManagementFixture {
|
||||
void SetUp() override {
|
||||
MemoryManagementFixture::SetUp();
|
||||
pPlatform = platform();
|
||||
pPlatform->initialize(numPlatformDevices, platformDevices);
|
||||
pPlatform->initialize();
|
||||
pDevice = pPlatform->getDevice(0);
|
||||
cl_device_id device = (cl_device_id)pDevice;
|
||||
ContextFixture::SetUp(1, &device);
|
||||
|
@ -34,7 +34,7 @@ extern CommandStreamReceiverCreateFunc commandStreamReceiverFactory[2 * IGFX_MAX
|
||||
bool getDevicesResult = true;
|
||||
|
||||
bool overrideCommandStreamReceiverCreation = false;
|
||||
bool overrideDeviceWithNullHardwareInfo = true;
|
||||
bool overrideDeviceWithDefaultHardwareInfo = true;
|
||||
|
||||
CommandStreamReceiver *createCommandStream(const HardwareInfo *pHwInfo) {
|
||||
CommandStreamReceiver *commandStreamReceiver = nullptr;
|
||||
@ -53,11 +53,12 @@ CommandStreamReceiver *createCommandStream(const HardwareInfo *pHwInfo) {
|
||||
}
|
||||
|
||||
bool getDevices(HardwareInfo **hwInfo, size_t &numDevicesReturned) {
|
||||
if (overrideDeviceWithNullHardwareInfo) {
|
||||
*hwInfo = nullptr;
|
||||
numDevicesReturned = 0;
|
||||
if (overrideDeviceWithDefaultHardwareInfo) {
|
||||
*hwInfo = const_cast<HardwareInfo *>(*platformDevices);
|
||||
numDevicesReturned = numPlatformDevices;
|
||||
return getDevicesResult;
|
||||
}
|
||||
|
||||
return getDevicesImpl(hwInfo, numDevicesReturned);
|
||||
}
|
||||
} // namespace OCLRT
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
namespace OCLRT {
|
||||
extern bool overrideCommandStreamReceiverCreation;
|
||||
extern bool overrideDeviceWithNullHardwareInfo;
|
||||
extern bool overrideDeviceWithDefaultHardwareInfo;
|
||||
|
||||
extern CommandStreamReceiver *createCommandStream(const HardwareInfo *pHwInfo);
|
||||
extern bool getDevices(HardwareInfo **hwInfo, size_t &numDevicesReturned);
|
||||
|
@ -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
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
@ -55,6 +55,6 @@ TEST_F(PlatformNegativeTest, GivenPlatformWhenGetDevicesFailedThenFalseIsReturne
|
||||
|
||||
VariableBackup<decltype(getDevicesResult)> bkp(&getDevicesResult, false);
|
||||
|
||||
auto ret = pPlatform->initialize(numPlatformDevices, platformDevices);
|
||||
auto ret = pPlatform->initialize();
|
||||
EXPECT_FALSE(ret);
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ TEST_F(PlatformTest, getDevices) {
|
||||
Device *device = pPlatform->getDevice(0);
|
||||
EXPECT_EQ(nullptr, device);
|
||||
|
||||
bool ret = pPlatform->initialize(numPlatformDevices, platformDevices);
|
||||
bool ret = pPlatform->initialize();
|
||||
EXPECT_TRUE(ret);
|
||||
|
||||
EXPECT_TRUE(pPlatform->isInitialized());
|
||||
@ -80,7 +80,7 @@ TEST_F(PlatformTest, PlatformgetAsCompilerEnabledExtensionsString) {
|
||||
std::string compilerExtensions = pPlatform->peekCompilerExtensions();
|
||||
EXPECT_EQ(std::string(""), compilerExtensions);
|
||||
|
||||
pPlatform->initialize(numPlatformDevices, platformDevices);
|
||||
pPlatform->initialize();
|
||||
compilerExtensions = pPlatform->peekCompilerExtensions();
|
||||
|
||||
EXPECT_THAT(compilerExtensions, ::testing::HasSubstr(std::string(" -cl-ext=-all,+cl")));
|
||||
@ -95,7 +95,7 @@ TEST_F(PlatformTest, PlatformgetAsCompilerEnabledExtensionsString) {
|
||||
TEST_F(PlatformTest, destructorCallsShutdownAndReleasesAllResources) {
|
||||
Platform *platform = new Platform;
|
||||
ASSERT_NE(nullptr, platform);
|
||||
platform->initialize(numPlatformDevices, platformDevices);
|
||||
platform->initialize();
|
||||
delete platform;
|
||||
}
|
||||
|
||||
@ -147,7 +147,7 @@ class PlatformFailingTest : public PlatformTest {
|
||||
|
||||
TEST_F(PlatformFailingTest, givenPlatformInitializationWhenIncorrectHwInfoThenInitializationFails) {
|
||||
Platform *platform = new Platform;
|
||||
bool ret = platform->initialize(numPlatformDevices, platformDevices);
|
||||
bool ret = platform->initialize();
|
||||
EXPECT_FALSE(ret);
|
||||
EXPECT_FALSE(platform->isInitialized());
|
||||
delete platform;
|
||||
|
@ -34,7 +34,7 @@ struct PlatformTestMt : public ::testing::Test {
|
||||
void TearDown() override {}
|
||||
|
||||
static void initThreadFunc(Platform *pP) {
|
||||
pP->initialize(numPlatformDevices, platformDevices);
|
||||
pP->initialize();
|
||||
}
|
||||
|
||||
static void shutdownThreadFunc(Platform *pP) {
|
||||
@ -46,7 +46,7 @@ struct PlatformTestMt : public ::testing::Test {
|
||||
};
|
||||
|
||||
static void callinitPlatform(Platform *plt, bool *ret) {
|
||||
*ret = plt->initialize(numPlatformDevices, platformDevices);
|
||||
*ret = plt->initialize();
|
||||
}
|
||||
|
||||
TEST_F(PlatformTestMt, initialize) {
|
||||
@ -83,7 +83,7 @@ TEST_F(PlatformTestMt, mtSafeTest) {
|
||||
size_t devNum = pPlatform->getNumDevices();
|
||||
EXPECT_EQ(0u, devNum);
|
||||
|
||||
bool ret = pPlatform->initialize(numPlatformDevices, platformDevices);
|
||||
bool ret = pPlatform->initialize();
|
||||
std::thread t1(PlatformTestMt::initThreadFunc, pPlatform);
|
||||
std::thread t2(PlatformTestMt::shutdownThreadFunc, pPlatform);
|
||||
EXPECT_TRUE(ret);
|
||||
|
Reference in New Issue
Block a user