Add control on platform life cycle.

Change-Id: I5c24b41747d822b71dd57e9a949cf25fcc78a453
This commit is contained in:
Mrozek, Michal
2018-06-26 16:15:48 +02:00
committed by sys_ocldev
parent 0f91c3bc47
commit a21c0a0074
27 changed files with 90 additions and 31 deletions

View File

@@ -75,7 +75,7 @@ cl_int CL_API_CALL clGetPlatformIDs(cl_uint numEntries,
}
while (platforms != nullptr) {
auto pPlatform = platform();
auto pPlatform = constructPlatform();
bool ret = pPlatform->initialize();
DEBUG_BREAK_IF(ret != true);
if (!ret) {
@@ -157,7 +157,7 @@ cl_int CL_API_CALL clGetDeviceIDs(cl_platform_id platform,
break;
}
} else {
pPlatform = ::platform();
pPlatform = constructPlatform();
bool ret = pPlatform->initialize();
DEBUG_BREAK_IF(ret != true);
((void)(ret));

View File

@@ -39,10 +39,20 @@
namespace OCLRT {
Platform platformImpl;
std::unique_ptr<Platform> platformImpl;
bool getDevices(HardwareInfo **hwInfo, size_t &numDevicesReturned);
Platform *platform() { return &platformImpl; }
Platform *platform() { return platformImpl.get(); }
Platform *constructPlatform() {
static std::mutex mutex;
std::unique_lock<std::mutex> lock(mutex);
if (!platformImpl) {
platformImpl.reset(new Platform());
}
return platformImpl.get();
}
Platform::Platform() {
devices.reserve(64);

View File

@@ -84,5 +84,7 @@ class Platform : public BaseObject<_cl_platform_id> {
ExecutionEnvironment *executionEnvironment = nullptr;
};
extern std::unique_ptr<Platform> platformImpl;
Platform *platform();
Platform *constructPlatform();
} // namespace OCLRT

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
* copy of this software and associated documentation files (the "Software"),
@@ -76,6 +76,6 @@ TEST(clGetPlatformIDsNegativeTests, WhenInitFailedThenErrorIsReturned) {
EXPECT_EQ(0u, numPlatforms);
EXPECT_EQ(nullptr, platformRet);
platform()->shutdown();
platformImpl.reset(nullptr);
}
} // namespace ULT

View File

@@ -21,6 +21,7 @@
*/
#pragma once
#include "runtime/platform/platform.h"
#include "unit_tests/aub_tests/command_stream/aub_command_stream_fixture.h"
#include "unit_tests/fixtures/device_fixture.h"
#include "unit_tests/fixtures/built_in_fixture.h"
@@ -36,6 +37,7 @@ struct CommandEnqueueAUBFixture : public CommandEnqueueBaseFixture,
public AUBCommandStreamFixture {
using AUBCommandStreamFixture::SetUp;
void SetUp() {
constructPlatform();
CommandEnqueueBaseFixture::SetUp(cl_command_queue_properties(0));
AUBCommandStreamFixture::SetUp(pCmdQ);
}
@@ -43,6 +45,7 @@ struct CommandEnqueueAUBFixture : public CommandEnqueueBaseFixture,
void TearDown() {
AUBCommandStreamFixture::TearDown();
CommandEnqueueBaseFixture::TearDown();
platformImpl.reset(nullptr);
}
};
} // namespace OCLRT

View File

@@ -40,10 +40,8 @@ struct AUBCopyImage
typedef AUBCommandStreamFixture CommandStreamFixture;
AUBCopyImage() {
}
void SetUp() override {
constructPlatform();
CommandDeviceFixture::SetUp(cl_command_queue_properties(0));
CommandStreamFixture::SetUp(pCmdQ);
context = new MockContext(pDevice);
@@ -55,6 +53,7 @@ struct AUBCopyImage
delete context;
CommandStreamFixture::TearDown();
CommandDeviceFixture::TearDown();
platformImpl.reset(nullptr);
}
MockContext *context;

View File

@@ -102,10 +102,8 @@ struct AubFillImage
typedef AUBCommandStreamFixture CommandStreamFixture;
AubFillImage() {
}
void SetUp() override {
constructPlatform();
CommandDeviceFixture::SetUp(cl_command_queue_properties(0));
CommandStreamFixture::SetUp(pCmdQ);
context = new MockContext(pDevice);
@@ -116,6 +114,7 @@ struct AubFillImage
delete context;
CommandStreamFixture::TearDown();
CommandDeviceFixture::TearDown();
platformImpl.reset(nullptr);
}
MockContext *context;

View File

@@ -52,10 +52,8 @@ struct AUBMapImage
using AUBCommandStreamFixture::SetUp;
AUBMapImage() {
}
void SetUp() override {
constructPlatform();
CommandDeviceFixture::SetUp(cl_command_queue_properties(0));
CommandStreamFixture::SetUp(pCmdQ);
context = new MockContext(pDevice);
@@ -66,6 +64,7 @@ struct AUBMapImage
delete context;
CommandStreamFixture::TearDown();
CommandDeviceFixture::TearDown();
platformImpl.reset(nullptr);
}
MockContext *context;

View File

@@ -55,6 +55,7 @@ struct AUBReadImage
using AUBCommandStreamFixture::SetUp;
void SetUp() override {
constructPlatform();
CommandDeviceFixture::SetUp(cl_command_queue_properties(0));
CommandStreamFixture::SetUp(pCmdQ);
context = new MockContext(pDevice);
@@ -65,6 +66,7 @@ struct AUBReadImage
delete context;
CommandStreamFixture::TearDown();
CommandDeviceFixture::TearDown();
platformImpl.reset(nullptr);
}
MockContext *context;

View File

@@ -53,6 +53,7 @@ struct AUBWriteImage
using AUBCommandStreamFixture::SetUp;
void SetUp() override {
constructPlatform();
CommandDeviceFixture::SetUp(cl_command_queue_properties(0));
CommandStreamFixture::SetUp(pCmdQ);
context = new MockContext(pDevice);
@@ -63,6 +64,7 @@ struct AUBWriteImage
delete context;
CommandStreamFixture::TearDown();
CommandDeviceFixture::TearDown();
platformImpl.reset(nullptr);
}
MockContext *context;

View File

@@ -23,6 +23,7 @@
#include "runtime/mem_obj/image.h"
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
#include "runtime/helpers/aligned_memory.h"
#include "runtime/platform/platform.h"
#include "unit_tests/aub_tests/command_stream/aub_command_stream_fixture.h"
#include "unit_tests/command_queue/command_enqueue_fixture.h"
#include "test.h"
@@ -46,10 +47,8 @@ struct AUBCreateImage
using AUBCommandStreamFixture::SetUp;
AUBCreateImage() {
}
void SetUp() override {
constructPlatform();
CommandDeviceFixture::SetUp(cl_command_queue_properties(0));
CommandStreamFixture::SetUp(pCmdQ);
@@ -73,6 +72,7 @@ struct AUBCreateImage
//delete context;
CommandStreamFixture::TearDown();
CommandDeviceFixture::TearDown();
platformImpl.reset(nullptr);
}
//MockContext *context;

View File

@@ -65,6 +65,7 @@ class BuiltInTests
}
void SetUp() override {
constructPlatform();
DeviceFixture::SetUp();
cl_device_id device = pDevice;
ContextFixture::SetUp(1, &device);
@@ -76,6 +77,7 @@ class BuiltInTests
BuiltInFixture::TearDown();
ContextFixture::TearDown();
DeviceFixture::TearDown();
platformImpl.reset(nullptr);
}
void AppendBuiltInStringFromFile(std::string builtInFile, size_t &size) {

View File

@@ -24,14 +24,12 @@
#include "buffer_operations_fixture.h"
#include "runtime/helpers/options.h"
#include "runtime/platform/platform.h"
namespace OCLRT {
struct AsyncGPUoperations : public EnqueueWriteBufferTypeTest {
AsyncGPUoperations(void) {
}
void SetUp() override {
constructPlatform();
storeInitHWTag = initialHardwareTag;
initialHardwareTag = 0;
EnqueueWriteBufferTypeTest::SetUp();
@@ -40,6 +38,7 @@ struct AsyncGPUoperations : public EnqueueWriteBufferTypeTest {
void TearDown() override {
initialHardwareTag = storeInitHWTag;
EnqueueWriteBufferTypeTest::TearDown();
platformImpl.reset(nullptr);
}
protected:

View File

@@ -22,6 +22,7 @@
#include "runtime/compiler_interface/compiler_options.h"
#include "runtime/command_queue/command_queue.h"
#include "runtime/platform/platform.h"
#include "runtime/program/program.h"
#include "runtime/source_level_debugger/source_level_debugger.h"
#include "unit_tests/fixtures/enqueue_handler_fixture.h"
@@ -43,6 +44,7 @@ class EnqueueDebugKernelTest : public ProgramSimpleFixture,
public ::testing::Test {
public:
void SetUp() override {
constructPlatform();
ProgramSimpleFixture::SetUp();
device = pDevice;
pDevice->sourceLevelDebugger.reset(new SourceLevelDebugger(nullptr));
@@ -90,6 +92,7 @@ class EnqueueDebugKernelTest : public ProgramSimpleFixture,
debugKernel->release();
}
ProgramSimpleFixture::TearDown();
platformImpl.reset(nullptr);
}
cl_device_id device;
Kernel *debugKernel = nullptr;

View File

@@ -26,6 +26,7 @@
#include "unit_tests/fixtures/buffer_fixture.h"
#include "unit_tests/helpers/debug_manager_state_restore.h"
#include "runtime/memory_manager/svm_memory_manager.h"
#include "runtime/platform/platform.h"
#include "unit_tests/mocks/mock_context.h"
#include "unit_tests/mocks/mock_kernel.h"
#include "runtime/memory_manager/surface.h"
@@ -45,6 +46,7 @@ struct EnqueueSvmTest : public DeviceFixture,
}
void SetUp() override {
constructPlatform();
DeviceFixture::SetUp();
CommandQueueFixture::SetUp(pDevice, 0);
ptrSVM = context->getSVMAllocsManager()->createSVMAlloc(256);
@@ -54,6 +56,7 @@ struct EnqueueSvmTest : public DeviceFixture,
context->getSVMAllocsManager()->freeSVMAlloc(ptrSVM);
CommandQueueFixture::TearDown();
DeviceFixture::TearDown();
platformImpl.reset(nullptr);
}
cl_int retVal = CL_SUCCESS;

View File

@@ -32,6 +32,7 @@
#include "runtime/event/perf_counter.h"
#include "runtime/kernel/kernel.h"
#include "runtime/helpers/kernel_commands.h"
#include "runtime/platform/platform.h"
#include "unit_tests/command_queue/command_enqueue_fixture.h"
#include "unit_tests/command_queue/enqueue_fixture.h"
#include "unit_tests/command_queue/enqueue_write_image_fixture.h"
@@ -49,6 +50,7 @@ struct GetSizeRequiredImageTest : public CommandEnqueueFixture,
}
void SetUp() override {
constructPlatform();
CommandEnqueueFixture::SetUp();
srcImage = Image2dHelper<>::create(context);
@@ -62,6 +64,7 @@ struct GetSizeRequiredImageTest : public CommandEnqueueFixture,
delete srcImage;
CommandEnqueueFixture::TearDown();
platformImpl.reset(nullptr);
}
Image *srcImage = nullptr;

View File

@@ -52,11 +52,8 @@ const char *gCBadDompilerDllName = "libbad_compiler.so";
class CompilerInterfaceTest : public DeviceFixture,
public ::testing::Test {
public:
CompilerInterfaceTest() {
//
}
void SetUp() override {
constructPlatform();
DeviceFixture::SetUp();
retVal = CL_SUCCESS;
@@ -102,6 +99,7 @@ class CompilerInterfaceTest : public DeviceFixture,
pCompilerInterface.reset();
DeviceFixture::TearDown();
platformImpl.reset(nullptr);
}
std::unique_ptr<MockCompilerInterface> pCompilerInterface = nullptr;

View File

@@ -55,6 +55,7 @@ class AsyncEventsHandlerTests : public ::testing::Test {
}
void SetUp() override {
constructPlatform();
dbgRestore.reset(new DebugManagerStateRestore());
DebugManager.flags.EnableAsyncEventsHandler.set(false);
handler.reset(new MockHandler());
@@ -68,6 +69,7 @@ class AsyncEventsHandlerTests : public ::testing::Test {
event1->release();
event2->release();
event3->release();
platformImpl.reset(nullptr);
}
std::unique_ptr<DebugManagerStateRestore> dbgRestore;

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
* copy of this software and associated documentation files (the "Software"),
@@ -56,6 +56,7 @@ TEST(EventCallbackTest, NestedCallbacksAreCalledForUserEvent) {
}
TEST(EventCallbackTest, NestedCallbacksAreCalledForEvent) {
constructPlatform();
std::unique_ptr<Device> device(DeviceHelper<>::create());
MockContext context;
MockCommandQueue queue(&context, device.get(), nullptr);
@@ -68,4 +69,5 @@ TEST(EventCallbackTest, NestedCallbacksAreCalledForEvent) {
platform()->getAsyncEventsHandler()->closeThread();
EXPECT_EQ(4u, nestLevel);
platformImpl.reset(nullptr);
}

View File

@@ -73,6 +73,7 @@ struct HelloWorldFixture : public FixtureFactory::IndirectHeapFixture,
public:
virtual void SetUp() {
constructPlatform();
DeviceFixture::SetUp();
ASSERT_NE(nullptr, pDevice);
CommandQueueFixture::SetUp(pDevice, 0);
@@ -106,6 +107,7 @@ struct HelloWorldFixture : public FixtureFactory::IndirectHeapFixture,
CommandQueueFixture::TearDown();
delete BufferDefaults::context;
DeviceFixture::TearDown();
platformImpl.reset(nullptr);
}
void *pSrcMemory;

View File

@@ -33,7 +33,7 @@ PlatformFixture::PlatformFixture()
}
void PlatformFixture::SetUp() {
pPlatform = platform();
pPlatform = constructPlatform();
ASSERT_EQ(0u, pPlatform->getNumDevices());
// setup platform / context
@@ -55,7 +55,7 @@ void PlatformFixture::SetUp() {
}
void PlatformFixture::TearDown() {
pPlatform->shutdown();
platformImpl.reset(nullptr);
delete[] devices;
}
} // namespace OCLRT

View File

@@ -133,6 +133,7 @@ class GTPinFixture : public ContextFixture, public MemoryManagementFixture {
public:
void SetUp() override {
MemoryManagementFixture::SetUp();
constructPlatform();
pPlatform = platform();
pPlatform->initialize();
pDevice = pPlatform->getDevice(0);
@@ -157,7 +158,7 @@ class GTPinFixture : public ContextFixture, public MemoryManagementFixture {
void TearDown() override {
ContextFixture::TearDown();
pPlatform->shutdown();
platformImpl.reset(nullptr);
MemoryManagementFixture::TearDown();
OCLRT::isGTPinInitialized = false;
}

View File

@@ -21,6 +21,7 @@
*/
#include "gtest/gtest.h"
#include "runtime/platform/platform.h"
#include "unit_tests/mocks/mock_context.h"
#include "unit_tests/mocks/mock_device.h"
#include "unit_tests/mocks/mock_kernel.h"
@@ -30,6 +31,7 @@ using namespace OCLRT;
class PatchedKernelTest : public ::testing::Test {
public:
void SetUp() override {
constructPlatform();
device.reset(MockDevice::create<MockDevice>(nullptr));
context.reset(new MockContext(device.get()));
program.reset(Program::create("FillBufferBytes", context.get(), *device.get(), true, &retVal));
@@ -41,6 +43,7 @@ class PatchedKernelTest : public ::testing::Test {
}
void TearDown() override {
context.reset();
platformImpl.reset(nullptr);
}
std::unique_ptr<MockContext> context;

View File

@@ -195,3 +195,24 @@ TEST_F(PlatformTest, testRemoveLastSpace) {
removeLastSpace(xSpaceString);
EXPECT_EQ(std::string("x"), xSpaceString);
}
TEST(PlatformConstructionTest, givenPlatformConstructorWhenItIsCalledTwiceThenTheSamePlatformIsReturned) {
ASSERT_EQ(nullptr, platformImpl);
auto platform = constructPlatform();
EXPECT_EQ(platform, platformImpl.get());
auto platform2 = constructPlatform();
EXPECT_EQ(platform2, platform);
EXPECT_NE(platform, nullptr);
platformImpl.reset(nullptr);
}
TEST(PlatformConstructionTest, givenPlatformConstructorWhenItIsCalledAfterResetThenNewPlatformIsConstructed) {
ASSERT_EQ(nullptr, platformImpl);
auto platform = constructPlatform();
std::unique_ptr<Platform> temporaryOwnership(std::move(platformImpl));
EXPECT_EQ(nullptr, platformImpl.get());
auto platform2 = constructPlatform();
EXPECT_NE(platform2, platform);
EXPECT_NE(platform, nullptr);
EXPECT_NE(platform2, nullptr);
platformImpl.reset(nullptr);
}

View File

@@ -95,7 +95,6 @@ TEST_F(PlatformTestMt, mtSafeTest) {
devNum = pPlatform->getNumDevices();
EXPECT_EQ(numPlatformDevices, devNum);
pPlatform->shutdown();
devNum = pPlatform->getNumDevices();
EXPECT_EQ(0u, devNum);

View File

@@ -55,6 +55,7 @@
using namespace OCLRT;
void ProgramTests::SetUp() {
constructPlatform();
DeviceFixture::SetUp();
cl_device_id device = pDevice;
ContextFixture::SetUp(1, &device);
@@ -62,6 +63,7 @@ void ProgramTests::SetUp() {
void ProgramTests::TearDown() {
ContextFixture::TearDown();
DeviceFixture::TearDown();
platformImpl.reset(nullptr);
}
void CL_CALLBACK notifyFunc(

View File

@@ -21,6 +21,7 @@
*/
#include "runtime/compiler_interface/compiler_options.h"
#include "runtime/platform/platform.h"
#include "unit_tests/fixtures/program_fixture.h"
#include "unit_tests/global_environment.h"
#include "unit_tests/helpers/kernel_binary_helper.h"
@@ -52,6 +53,7 @@ class ProgramWithKernelDebuggingTest : public ProgramSimpleFixture,
public ::testing::Test {
public:
void SetUp() override {
constructPlatform();
ProgramSimpleFixture::SetUp();
device = pDevice;
@@ -71,6 +73,7 @@ class ProgramWithKernelDebuggingTest : public ProgramSimpleFixture,
void TearDown() override {
delete kbHelper;
ProgramSimpleFixture::TearDown();
platformImpl.reset(nullptr);
}
cl_device_id device;
KernelBinaryHelper *kbHelper = nullptr;