From 0a0b1ce1d862548bf6098faba3f7ab100cfd2b1f Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Mon, 27 Jan 2020 10:36:39 +0100 Subject: [PATCH] Pass platform to ClDevice Related-To: NEO-4207 Change-Id: I1c70d209df2b378573a41fa991ab594746691adb Signed-off-by: Mateusz Jablonski --- runtime/device/cl_device.cpp | 6 +++--- runtime/device/cl_device.h | 3 ++- runtime/platform/platform.cpp | 2 +- unit_tests/api/cl_create_pipe_tests.inl | 2 +- unit_tests/api/cl_get_supported_image_formats_tests.inl | 2 +- unit_tests/api/cl_svm_alloc_tests.inl | 2 +- unit_tests/command_queue/sync_buffer_handler_tests.cpp | 2 +- unit_tests/device/get_device_info_size_tests.cpp | 8 ++++---- unit_tests/event/event_tests.cpp | 2 +- unit_tests/fixtures/device_instrumentation_fixture.cpp | 2 +- unit_tests/mocks/mock_device.cpp | 2 +- unit_tests/os_interface/linux/device_os_tests.cpp | 2 +- unit_tests/os_interface/windows/device_os_tests.cpp | 2 +- 13 files changed, 19 insertions(+), 18 deletions(-) diff --git a/runtime/device/cl_device.cpp b/runtime/device/cl_device.cpp index f1e44255c8..0a2340d92b 100644 --- a/runtime/device/cl_device.cpp +++ b/runtime/device/cl_device.cpp @@ -13,15 +13,15 @@ namespace NEO { -ClDevice::ClDevice(Device &device) : device(device), platformId(platform()) { +ClDevice::ClDevice(Device &device, Platform *platform) : device(device), platformId(platform) { device.incRefInternal(); initializeCaps(); auto numAvailableDevices = device.getNumAvailableDevices(); if (numAvailableDevices > 1) { for (uint32_t i = 0; i < numAvailableDevices; i++) { - subDevices.push_back(std::make_unique(*device.getDeviceById(i))); - platform()->clDeviceMap.emplace(device.getDeviceById(i), subDevices[i].get()); + subDevices.push_back(std::make_unique(*device.getDeviceById(i), platform)); + platform->clDeviceMap.emplace(device.getDeviceById(i), subDevices[i].get()); } } } diff --git a/runtime/device/cl_device.h b/runtime/device/cl_device.h index f00f70a398..c9a8568694 100644 --- a/runtime/device/cl_device.h +++ b/runtime/device/cl_device.h @@ -29,6 +29,7 @@ struct EngineControl; struct HardwareCapabilities; struct HardwareInfo; struct RootDeviceEnvironment; +class Platform; template <> struct OpenCLObjectMapper<_cl_device_id> { @@ -42,7 +43,7 @@ class ClDevice : public BaseObject<_cl_device_id> { ClDevice &operator=(const ClDevice &) = delete; ClDevice(const ClDevice &) = delete; - explicit ClDevice(Device &device); + explicit ClDevice(Device &device, Platform *platformId); ~ClDevice() override; unsigned int getEnabledClVersion() const; //CL diff --git a/runtime/platform/platform.cpp b/runtime/platform/platform.cpp index 4ca8fdc6c8..e3ef149439 100644 --- a/runtime/platform/platform.cpp +++ b/runtime/platform/platform.cpp @@ -160,7 +160,7 @@ bool Platform::initialize() { DEBUG_BREAK_IF(!pDevice); ClDevice *pClDevice = nullptr; if (pDevice) { - pClDevice = new ClDevice{*pDevice}; + pClDevice = new ClDevice{*pDevice, this}; } DEBUG_BREAK_IF(!pClDevice); if (pClDevice) { diff --git a/unit_tests/api/cl_create_pipe_tests.inl b/unit_tests/api/cl_create_pipe_tests.inl index 73325fb7e2..3fffd6c277 100644 --- a/unit_tests/api/cl_create_pipe_tests.inl +++ b/unit_tests/api/cl_create_pipe_tests.inl @@ -167,7 +167,7 @@ TEST(clCreatePipeTest, givenPlatformWithoutDevicesWhenClCreatePipeIsCalledThenDe auto executionEnvironment = platform()->peekExecutionEnvironment(); executionEnvironment->initializeMemoryManager(); executionEnvironment->prepareRootDeviceEnvironments(1); - auto device = std::make_unique(*Device::create(executionEnvironment, 0u)); + auto device = std::make_unique(*Device::create(executionEnvironment, 0u), platform()); const DeviceInfo &devInfo = device->getDeviceInfo(); if (devInfo.svmCapabilities == 0) { GTEST_SKIP(); diff --git a/unit_tests/api/cl_get_supported_image_formats_tests.inl b/unit_tests/api/cl_get_supported_image_formats_tests.inl index 828cc64264..3771535b52 100644 --- a/unit_tests/api/cl_get_supported_image_formats_tests.inl +++ b/unit_tests/api/cl_get_supported_image_formats_tests.inl @@ -74,7 +74,7 @@ TEST(clGetSupportedImageFormatsTest, givenPlatformWithoutDevicesWhenClGetSupport auto executionEnvironment = platform()->peekExecutionEnvironment(); executionEnvironment->initializeMemoryManager(); executionEnvironment->prepareRootDeviceEnvironments(1); - auto device = std::make_unique(*Device::create(executionEnvironment, 0u)); + auto device = std::make_unique(*Device::create(executionEnvironment, 0u), platform()); const DeviceInfo &devInfo = device->getDeviceInfo(); if (!devInfo.imageSupport) { GTEST_SKIP(); diff --git a/unit_tests/api/cl_svm_alloc_tests.inl b/unit_tests/api/cl_svm_alloc_tests.inl index 6f2d325e04..3823ae1032 100644 --- a/unit_tests/api/cl_svm_alloc_tests.inl +++ b/unit_tests/api/cl_svm_alloc_tests.inl @@ -41,7 +41,7 @@ TEST(clSVMAllocTest, givenPlatformWithoutDevicesWhenClSVMAllocIsCalledThenDevice executionEnvironment->initializeMemoryManager(); executionEnvironment->prepareRootDeviceEnvironments(1); auto device = Device::create(executionEnvironment, 0u); - auto clDevice = std::make_unique(*device); + auto clDevice = std::make_unique(*device, platform()); const DeviceInfo &devInfo = device->getDeviceInfo(); if (devInfo.svmCapabilities == 0) { GTEST_SKIP(); diff --git a/unit_tests/command_queue/sync_buffer_handler_tests.cpp b/unit_tests/command_queue/sync_buffer_handler_tests.cpp index 091eac2fad..718c9ed5c0 100644 --- a/unit_tests/command_queue/sync_buffer_handler_tests.cpp +++ b/unit_tests/command_queue/sync_buffer_handler_tests.cpp @@ -171,7 +171,7 @@ TEST(SyncBufferHandlerDeviceTest, GivenRootDeviceWhenAllocateSyncBufferIsCalledT TEST(SyncBufferHandlerDeviceTest, GivenSubDeviceWhenAllocateSyncBufferIsCalledTwiceThenTheObjectIsCreatedOnlyOnce) { const size_t testUsedBufferSize = 100; MockClDevice rootDevice{new MockDevice}; - ClDevice subDevice{*rootDevice.createSubDevice(0)}; + ClDevice subDevice{*rootDevice.createSubDevice(0), platform()}; subDevice.allocateSyncBufferHandler(); auto syncBufferHandler = reinterpret_cast(subDevice.syncBufferHandler.get()); diff --git a/unit_tests/device/get_device_info_size_tests.cpp b/unit_tests/device/get_device_info_size_tests.cpp index 6715fbb6c4..c9a37c6bda 100644 --- a/unit_tests/device/get_device_info_size_tests.cpp +++ b/unit_tests/device/get_device_info_size_tests.cpp @@ -129,7 +129,7 @@ INSTANTIATE_TEST_CASE_P( struct GetDeviceInfoForImage : public GetDeviceInfoSize {}; TEST_P(GetDeviceInfoForImage, imageInfoSizeIsValid) { - auto device = std::make_unique(*MockDevice::createWithNewExecutionEnvironment(nullptr)); + auto device = std::make_unique(*MockDevice::createWithNewExecutionEnvironment(nullptr), platform()); if (!device->getDeviceInfo().imageSupport) { GTEST_SKIP(); } @@ -147,7 +147,7 @@ TEST_P(GetDeviceInfoForImage, imageInfoSizeIsValid) { } TEST_P(GetDeviceInfoForImage, whenImageAreNotSupportedThenClInvalidValueIsReturned) { - auto device = std::make_unique(*MockDevice::createWithNewExecutionEnvironment(nullptr)); + auto device = std::make_unique(*MockDevice::createWithNewExecutionEnvironment(nullptr), platform()); if (device->getDeviceInfo().imageSupport) { GTEST_SKIP(); } @@ -161,7 +161,7 @@ TEST_P(GetDeviceInfoForImage, whenImageAreNotSupportedThenClInvalidValueIsReturn } TEST_P(GetDeviceInfoForImage, givenInfoImageParamsWhenCallGetDeviceInfoForImageThenSizeIsValidAndTrueReturned) { - auto device = std::make_unique(*MockDevice::createWithNewExecutionEnvironment(nullptr)); + auto device = std::make_unique(*MockDevice::createWithNewExecutionEnvironment(nullptr), platform()); size_t srcSize = 0; size_t retSize = 0; const void *src = nullptr; @@ -177,7 +177,7 @@ TEST_P(GetDeviceInfoForImage, givenInfoImageParamsWhenCallGetDeviceInfoForImageT } TEST(GetDeviceInfoForImage, givenNotImageParamWhenCallGetDeviceInfoForImageThenSizeIsNotValidAndFalseReturned) { - auto device = std::make_unique(*MockDevice::createWithNewExecutionEnvironment(nullptr)); + auto device = std::make_unique(*MockDevice::createWithNewExecutionEnvironment(nullptr), platform()); size_t srcSize = 0; size_t retSize = 0; const void *src = nullptr; diff --git a/unit_tests/event/event_tests.cpp b/unit_tests/event/event_tests.cpp index b81beabefd..7d4f00a403 100644 --- a/unit_tests/event/event_tests.cpp +++ b/unit_tests/event/event_tests.cpp @@ -395,7 +395,7 @@ struct UpdateEventTest : public ::testing::Test { memoryManager = new MockMemoryManager(*executionEnvironment); hostPtrManager = static_cast(memoryManager->getHostPtrManager()); executionEnvironment->memoryManager.reset(memoryManager); - device.reset(new ClDevice{*Device::create(executionEnvironment, 0u)}); + device.reset(new ClDevice{*Device::create(executionEnvironment, 0u), platform()}); context = std::make_unique(device.get()); cl_int retVal = CL_OUT_OF_RESOURCES; commandQueue.reset(CommandQueue::create(context.get(), device.get(), nullptr, retVal)); diff --git a/unit_tests/fixtures/device_instrumentation_fixture.cpp b/unit_tests/fixtures/device_instrumentation_fixture.cpp index f5778fa9c3..5817423bec 100644 --- a/unit_tests/fixtures/device_instrumentation_fixture.cpp +++ b/unit_tests/fixtures/device_instrumentation_fixture.cpp @@ -14,7 +14,7 @@ namespace NEO { void DeviceInstrumentationFixture::SetUp(bool instrumentation) { ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); hwInfo->capabilityTable.instrumentationEnabled = instrumentation; - device = std::make_unique(*Device::create(executionEnvironment, 0)); + device = std::make_unique(*Device::create(executionEnvironment, 0), platform()); } } // namespace NEO diff --git a/unit_tests/mocks/mock_device.cpp b/unit_tests/mocks/mock_device.cpp index 464c14b5a7..08fc172c49 100644 --- a/unit_tests/mocks/mock_device.cpp +++ b/unit_tests/mocks/mock_device.cpp @@ -24,7 +24,7 @@ decltype(&createCommandStream) MockDevice::createCommandStreamReceiverFunc = cre decltype(&createCommandStream) &MockClDevice::createCommandStreamReceiverFunc = MockDevice::createCommandStreamReceiverFunc; MockClDevice::MockClDevice(MockDevice *pMockDevice) - : ClDevice(*pMockDevice), device(*pMockDevice), deviceInfo(pMockDevice->deviceInfo), + : ClDevice(*pMockDevice, platform()), device(*pMockDevice), deviceInfo(pMockDevice->deviceInfo), executionEnvironment(pMockDevice->executionEnvironment), subdevices(pMockDevice->subdevices), mockMemoryManager(pMockDevice->mockMemoryManager), engines(pMockDevice->engines) { diff --git a/unit_tests/os_interface/linux/device_os_tests.cpp b/unit_tests/os_interface/linux/device_os_tests.cpp index 1842dc7be8..0315119ceb 100644 --- a/unit_tests/os_interface/linux/device_os_tests.cpp +++ b/unit_tests/os_interface/linux/device_os_tests.cpp @@ -41,7 +41,7 @@ TEST(DeviceOsTest, GivenDefaultDeviceWhenCheckingForOsSpecificExtensionsThenCorr TEST(DeviceOsTest, GivenDefaultClDeviceWhenCheckingForOsSpecificExtensionsThenCorrectExtensionsAreSet) { auto hwInfo = *platformDevices; auto pDevice = MockDevice::createWithNewExecutionEnvironment(hwInfo); - auto pClDevice = new ClDevice{*pDevice}; + auto pClDevice = new ClDevice{*pDevice, platform()}; std::string extensionString(pClDevice->getDeviceInfo().deviceExtensions); diff --git a/unit_tests/os_interface/windows/device_os_tests.cpp b/unit_tests/os_interface/windows/device_os_tests.cpp index 48eefc4d40..bde90fbced 100644 --- a/unit_tests/os_interface/windows/device_os_tests.cpp +++ b/unit_tests/os_interface/windows/device_os_tests.cpp @@ -37,7 +37,7 @@ TEST(DeviceOsTest, GivenDefaultDeviceWhenCheckingForOsSpecificExtensionsThenCorr TEST(DeviceOsTest, GivenDefaultClDeviceWhenCheckingForOsSpecificExtensionsThenCorrectExtensionsAreSet) { auto hwInfo = *platformDevices; auto pDevice = MockDevice::createWithNewExecutionEnvironment(hwInfo); - auto pClDevice = new ClDevice{*pDevice}; + auto pClDevice = new ClDevice{*pDevice, platform()}; std::string extensionString(pClDevice->getDeviceInfo().deviceExtensions);