From ffed348f3bdca2cd0ed261825e25791eb1b5e4f5 Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Mon, 2 Mar 2020 10:13:46 +0100 Subject: [PATCH] Correct accessing cl device from Platform don't use root device index to store cl device in Platform::initialize Related-To: NEO-3691 Change-Id: I1fc5435e0246e241c4a38060de26f5c0369a1873 Signed-off-by: Mateusz Jablonski --- opencl/source/api/api.cpp | 4 ++-- opencl/source/platform/platform.cpp | 9 +++------ opencl/test/unit_test/platform/platform_tests.cpp | 11 +++++++++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/opencl/source/api/api.cpp b/opencl/source/api/api.cpp index 42a3017cca..5ba7e8e369 100644 --- a/opencl/source/api/api.cpp +++ b/opencl/source/api/api.cpp @@ -225,9 +225,9 @@ cl_int CL_API_CALL clGetDeviceIDs(cl_platform_id platform, } cl_uint retNum = 0; - for (auto rootDeviceIndex = 0u; rootDeviceIndex < numDev; rootDeviceIndex++) { + for (auto platformDeviceIndex = 0u; platformDeviceIndex < numDev; platformDeviceIndex++) { - ClDevice *device = pPlatform->getClDevice(rootDeviceIndex); + ClDevice *device = pPlatform->getClDevice(platformDeviceIndex); UNRECOVERABLE_IF(device == nullptr); if (deviceType & device->getDeviceInfo().deviceType) { diff --git a/opencl/source/platform/platform.cpp b/opencl/source/platform/platform.cpp index 40eaad82d5..80c91c4e21 100644 --- a/opencl/source/platform/platform.cpp +++ b/opencl/source/platform/platform.cpp @@ -65,9 +65,7 @@ Platform::Platform(ExecutionEnvironment &executionEnvironmentIn) : executionEnvi Platform::~Platform() { asyncEventsHandler->closeThread(); for (auto clDevice : this->clDevices) { - if (clDevice) { - clDevice->decRefInternal(); - } + clDevice->decRefInternal(); } gtpinNotifyPlatformShutdown(); @@ -144,13 +142,12 @@ bool Platform::initialize(std::vector> devices) { DEBUG_BREAK_IF(this->platformInfo); this->platformInfo.reset(new PlatformInfo); - this->clDevices.resize(devices.size()); for (auto &inputDevice : devices) { ClDevice *pClDevice = nullptr; auto pDevice = inputDevice.release(); UNRECOVERABLE_IF(!pDevice); pClDevice = new ClDevice{*pDevice, this}; - this->clDevices[pDevice->getRootDeviceIndex()] = pClDevice; + this->clDevices.push_back(pClDevice); this->platformInfo->extensions = pClDevice->getDeviceInfo().deviceExtensions; @@ -176,7 +173,7 @@ bool Platform::initialize(std::vector> devices) { } this->fillGlobalDispatchTable(); - DEBUG_BREAK_IF(DebugManager.flags.CreateMultipleRootDevices.get() > 1 && !this->clDevices[0]->getDefaultEngine().commandStreamReceiver->peekTimestampPacketWriteEnabled()); + DEBUG_BREAK_IF(DebugManager.flags.CreateMultipleSubDevices.get() > 1 && !this->clDevices[0]->getDefaultEngine().commandStreamReceiver->peekTimestampPacketWriteEnabled()); state = StateInited; return true; } diff --git a/opencl/test/unit_test/platform/platform_tests.cpp b/opencl/test/unit_test/platform/platform_tests.cpp index cc9977f13b..63342a1c0e 100644 --- a/opencl/test/unit_test/platform/platform_tests.cpp +++ b/opencl/test/unit_test/platform/platform_tests.cpp @@ -386,6 +386,17 @@ TEST(PlatformInitTest, givenInitializedPlatformWhenInitializeIsCalledOneMoreTime EXPECT_TRUE(platform()->initialize(std::move(devices))); } +TEST(PlatformInitTest, givenSingleDeviceWithNonZeroRootDeviceIndexInPassedDeviceVectorWhenInitializePlatformThenCreateOnlyOneClDevice) { + std::vector> devices; + auto executionEnvironment = new MockExecutionEnvironment(*platformDevices, false, 3); + devices.push_back(std::make_unique(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()); +} + TEST(PlatformInitLoopTests, givenPlatformWithDebugSettingWhenInitIsCalledThenItEntersEndlessLoop) { DebugManagerStateRestore stateRestore; DebugManager.flags.LoopAtPlatformInitialize.set(true);