From 2ead0e6910785dc6005c8de2adb1a5edbf40e40f Mon Sep 17 00:00:00 2001 From: Filip Hazubski Date: Tue, 3 Dec 2019 10:15:46 +0100 Subject: [PATCH] Update Device::getDeviceBitfield() Related-To: NEO-2712 Change-Id: I609f55c9a0ee637dcef7cb176728f2ae65499a58 Signed-off-by: Filip Hazubski --- runtime/device/device.cpp | 2 +- runtime/device/device.h | 2 +- runtime/device/root_device.cpp | 5 ++--- runtime/device/root_device.h | 2 +- runtime/device/sub_device.cpp | 2 +- runtime/device/sub_device.h | 2 +- runtime/memory_manager/memory_manager.h | 4 ---- .../aub_command_stream_receiver_1_tests.cpp | 12 ++++++------ unit_tests/device/sub_device_tests.cpp | 11 +++++++++++ unit_tests/memory_manager/memory_manager_tests.cpp | 2 +- 10 files changed, 25 insertions(+), 19 deletions(-) diff --git a/runtime/device/device.cpp b/runtime/device/device.cpp index a9605173c5..9de794bfd3 100644 --- a/runtime/device/device.cpp +++ b/runtime/device/device.cpp @@ -151,7 +151,7 @@ bool Device::createEngine(uint32_t deviceCsrIndex, aub_stream::EngineType engine bool lowPriority = (deviceCsrIndex == HwHelper::lowPriorityGpgpuEngineIndex); auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(commandStreamReceiver.get(), engineType, - getDeviceBitfieldForOsContext(), preemptionMode, lowPriority); + getDeviceBitfield(), preemptionMode, lowPriority); commandStreamReceiver->setupContext(*osContext); if (!commandStreamReceiver->initializeTagAllocation()) { diff --git a/runtime/device/device.h b/runtime/device/device.h index d42df0e440..505c5bcfa4 100644 --- a/runtime/device/device.h +++ b/runtime/device/device.h @@ -113,7 +113,7 @@ class Device : public BaseObject<_cl_device_id> { bool createEngine(uint32_t deviceCsrIndex, aub_stream::EngineType engineType); MOCKABLE_VIRTUAL std::unique_ptr createCommandStreamReceiver() const; - virtual DeviceBitfield getDeviceBitfieldForOsContext() const = 0; + virtual DeviceBitfield getDeviceBitfield() const = 0; std::vector simultaneousInterops; unsigned int enabledClVersion = 0u; diff --git a/runtime/device/root_device.cpp b/runtime/device/root_device.cpp index 1cd4914e1d..c6380a16bd 100644 --- a/runtime/device/root_device.cpp +++ b/runtime/device/root_device.cpp @@ -73,9 +73,8 @@ unique_ptr_if_unused RootDevice::release() { DEBUG_BREAK_IF(!isValid()); return unique_ptr_if_unused(this, false); } -DeviceBitfield RootDevice::getDeviceBitfieldForOsContext() const { - DeviceBitfield deviceBitfield; - deviceBitfield.set(0); +DeviceBitfield RootDevice::getDeviceBitfield() const { + DeviceBitfield deviceBitfield{static_cast(maxNBitValue(getNumAvailableDevices()))}; return deviceBitfield; } diff --git a/runtime/device/root_device.h b/runtime/device/root_device.h index 78cb26fab6..f796e321e8 100644 --- a/runtime/device/root_device.h +++ b/runtime/device/root_device.h @@ -27,7 +27,7 @@ class RootDevice : public Device { uint32_t getNumSubDevices() const; protected: - DeviceBitfield getDeviceBitfieldForOsContext() const override; + DeviceBitfield getDeviceBitfield() const override; bool createEngines() override; MOCKABLE_VIRTUAL bool initializeRootCommandStreamReceiver(); diff --git a/runtime/device/sub_device.cpp b/runtime/device/sub_device.cpp index 04785ce4d7..e156e70252 100644 --- a/runtime/device/sub_device.cpp +++ b/runtime/device/sub_device.cpp @@ -27,7 +27,7 @@ void SubDevice::releaseInternal() { rootDevice.decRefInternal(); } -DeviceBitfield SubDevice::getDeviceBitfieldForOsContext() const { +DeviceBitfield SubDevice::getDeviceBitfield() const { DeviceBitfield deviceBitfield; deviceBitfield.set(subDeviceIndex); return deviceBitfield; diff --git a/runtime/device/sub_device.h b/runtime/device/sub_device.h index 78b1b2d0fe..b47672a474 100644 --- a/runtime/device/sub_device.h +++ b/runtime/device/sub_device.h @@ -26,7 +26,7 @@ class SubDevice : public Device { uint32_t getSubDeviceIndex() const; protected: - DeviceBitfield getDeviceBitfieldForOsContext() const override; + DeviceBitfield getDeviceBitfield() const override; const uint32_t subDeviceIndex; RootDevice &rootDevice; }; diff --git a/runtime/memory_manager/memory_manager.h b/runtime/memory_manager/memory_manager.h index 8ce1734e2e..b3030145fd 100644 --- a/runtime/memory_manager/memory_manager.h +++ b/runtime/memory_manager/memory_manager.h @@ -33,10 +33,6 @@ class Gmm; class HostPtrManager; class OsContext; -inline DeviceBitfield getDeviceBitfieldForNDevices(uint32_t numDevices) { - return DeviceBitfield(maxNBitValue(numDevices)); -} - enum AllocationUsage { TEMPORARY_ALLOCATION, REUSABLE_ALLOCATION diff --git a/unit_tests/command_stream/aub_command_stream_receiver_1_tests.cpp b/unit_tests/command_stream/aub_command_stream_receiver_1_tests.cpp index e46bac8a9b..1d374ed288 100644 --- a/unit_tests/command_stream/aub_command_stream_receiver_1_tests.cpp +++ b/unit_tests/command_stream/aub_command_stream_receiver_1_tests.cpp @@ -819,7 +819,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenProcess } HWTEST_F(AubCommandStreamReceiverTests, givenOsContextWithMultipleDevicesSupportedWhenSetupIsCalledThenCreateMultipleHardwareContexts) { - MockOsContext osContext(1, getDeviceBitfieldForNDevices(2), aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false); + MockOsContext osContext(1, 0b11, aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false); auto aubCsr = std::make_unique>("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex()); aubCsr->setupContext(osContext); @@ -1171,7 +1171,7 @@ using HardwareContextContainerTests = ::testing::Test; TEST_F(HardwareContextContainerTests, givenOsContextWithMultipleDevicesSupportedThenInitialzeHwContextsWithValidIndexes) { MockAubManager aubManager; - MockOsContext osContext(1, getDeviceBitfieldForNDevices(2), aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false); + MockOsContext osContext(1, 0b11, aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false); HardwareContextController hwContextControler(aubManager, osContext, 0); EXPECT_EQ(2u, hwContextControler.hardwareContexts.size()); @@ -1184,7 +1184,7 @@ TEST_F(HardwareContextContainerTests, givenOsContextWithMultipleDevicesSupported TEST_F(HardwareContextContainerTests, givenSingleHwContextWhenSubmitMethodIsCalledOnHwContextControllerThenSubmitIsCalled) { MockAubManager aubManager; - MockOsContext osContext(1, getDeviceBitfieldForNDevices(1), aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false); + MockOsContext osContext(1, 0b1, aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false); HardwareContextController hwContextContainer(aubManager, osContext, 0); EXPECT_EQ(1u, hwContextContainer.hardwareContexts.size()); @@ -1202,7 +1202,7 @@ TEST_F(HardwareContextContainerTests, givenSingleHwContextWhenSubmitMethodIsCall TEST_F(HardwareContextContainerTests, givenSingleHwContextWhenWriteMemoryIsCalledThenWholeMemoryBanksArePassed) { MockAubManager aubManager; - MockOsContext osContext(1, getDeviceBitfieldForNDevices(1), aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false); + MockOsContext osContext(1, 0b1, aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false); HardwareContextController hwContextContainer(aubManager, osContext, 0); EXPECT_EQ(1u, hwContextContainer.hardwareContexts.size()); @@ -1216,7 +1216,7 @@ TEST_F(HardwareContextContainerTests, givenSingleHwContextWhenWriteMemoryIsCalle TEST_F(HardwareContextContainerTests, givenMultipleHwContextWhenSingleMethodIsCalledThenUseAllContexts) { MockAubManager aubManager; - MockOsContext osContext(1, getDeviceBitfieldForNDevices(2), aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false); + MockOsContext osContext(1, 0b11, aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false); HardwareContextController hwContextContainer(aubManager, osContext, 0); EXPECT_EQ(2u, hwContextContainer.hardwareContexts.size()); @@ -1256,7 +1256,7 @@ TEST_F(HardwareContextContainerTests, givenMultipleHwContextWhenSingleMethodIsCa TEST_F(HardwareContextContainerTests, givenMultipleHwContextWhenSingleMethodIsCalledThenUseFirstContext) { MockAubManager aubManager; - MockOsContext osContext(1, getDeviceBitfieldForNDevices(2), aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false); + MockOsContext osContext(1, 0b11, aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false); HardwareContextController hwContextContainer(aubManager, osContext, 0); EXPECT_EQ(2u, hwContextContainer.hardwareContexts.size()); diff --git a/unit_tests/device/sub_device_tests.cpp b/unit_tests/device/sub_device_tests.cpp index e4ce427ec2..e0325a84c7 100644 --- a/unit_tests/device/sub_device_tests.cpp +++ b/unit_tests/device/sub_device_tests.cpp @@ -100,6 +100,17 @@ TEST(SubDevicesTest, givenCreateMultipleRootDevicesFlagsEnabledWhenDevicesAreCre EXPECT_EQ(1u, platform()->getDevice(1)->getRootDeviceIndex()); } +TEST(SubDevicesTest, givenRootDeviceWithSubDevicesWhenOsContextIsCreatedThenItsBitfieldBasesOnSubDevicesCount) { + DebugManagerStateRestore restorer; + DebugManager.flags.CreateMultipleSubDevices.set(2); + VariableBackup mockDeviceFlagBackup(&MockDevice::createSingleDevice, false); + auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(*platformDevices)); + EXPECT_EQ(2u, device->getNumSubDevices()); + + uint32_t rootDeviceBitfield = 0b11; + EXPECT_EQ(rootDeviceBitfield, static_cast(device->getDefaultEngine().osContext->getDeviceBitfield().to_ulong())); +} + TEST(SubDevicesTest, givenSubDeviceWhenOsContextIsCreatedThenItsBitfieldBasesOnSubDeviceId) { DebugManagerStateRestore restorer; DebugManager.flags.CreateMultipleSubDevices.set(2); diff --git a/unit_tests/memory_manager/memory_manager_tests.cpp b/unit_tests/memory_manager/memory_manager_tests.cpp index 41704decfb..61b92c9b96 100644 --- a/unit_tests/memory_manager/memory_manager_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_tests.cpp @@ -1658,7 +1658,7 @@ TEST(MemoryManagerRegisteredEnginesTest, givenOsContextWhenItIsUnregisteredFromM TEST(ResidencyDataTest, givenDeviceBitfieldWhenCreatingOsContextThenSetValidValue) { MockExecutionEnvironment executionEnvironment(*platformDevices); MockMemoryManager memoryManager(false, false, executionEnvironment); - DeviceBitfield deviceBitfield = getDeviceBitfieldForNDevices(2); + DeviceBitfield deviceBitfield = 0b11; PreemptionMode preemptionMode = PreemptionMode::MidThread; memoryManager.createAndRegisterOsContext(nullptr, HwHelper::get(platformDevices[0]->platform.eRenderCoreFamily).getGpgpuEngineInstances()[0], deviceBitfield, preemptionMode, false);