diff --git a/opencl/source/command_queue/command_queue.cpp b/opencl/source/command_queue/command_queue.cpp index 5cf14677f6..2c60231011 100644 --- a/opencl/source/command_queue/command_queue.cpp +++ b/opencl/source/command_queue/command_queue.cpp @@ -778,7 +778,12 @@ void CommandQueue::processProperties(const cl_queue_properties *properties) { } void CommandQueue::overrideEngine(aub_stream::EngineType engineType) { - if (engineType == aub_stream::EngineType::ENGINE_BCS) { + const HardwareInfo &hwInfo = getDevice().getHardwareInfo(); + const HwHelper &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily); + const EngineGroupType engineGroupType = hwHelper.getEngineGroupType(engineType, hwInfo); + const bool isEngineCopyOnly = hwHelper.isCopyOnlyEngineType(engineGroupType); + + if (isEngineCopyOnly) { bcsEngine = &device->getEngine(engineType, false, false); timestampPacketContainer = std::make_unique(); isCopyOnly = true; diff --git a/opencl/test/unit_test/device/device_tests.cpp b/opencl/test/unit_test/device/device_tests.cpp index 4640e08b11..d98d38e81c 100644 --- a/opencl/test/unit_test/device/device_tests.cpp +++ b/opencl/test/unit_test/device/device_tests.cpp @@ -474,6 +474,45 @@ TEST(DeviceGenEngineTest, givenEmptyGroupsWhenGettingNonEmptyGroupsThenReturnCor EXPECT_EQ(nullptr, device->getNonEmptyEngineGroup(2)); } +TEST(DeviceGenEngineTest, givenNoEmptyGroupsWhenGettingNonEmptyGroupIndexThenReturnCorrectResults) { + const auto nonEmptyEngineGroup = std::vector{EngineControl{nullptr, nullptr}}; + + auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); + auto &engineGroups = device->getEngineGroups(); + engineGroups.clear(); + engineGroups.push_back(nonEmptyEngineGroup); + engineGroups.push_back(nonEmptyEngineGroup); + engineGroups.push_back(nonEmptyEngineGroup); + engineGroups.push_back(nonEmptyEngineGroup); + + EXPECT_EQ(0u, device->getIndexOfNonEmptyEngineGroup(static_cast(0u))); + EXPECT_EQ(1u, device->getIndexOfNonEmptyEngineGroup(static_cast(1u))); + EXPECT_EQ(2u, device->getIndexOfNonEmptyEngineGroup(static_cast(2u))); + EXPECT_EQ(3u, device->getIndexOfNonEmptyEngineGroup(static_cast(3u))); + EXPECT_ANY_THROW(device->getIndexOfNonEmptyEngineGroup(static_cast(4u))); + EXPECT_ANY_THROW(device->getIndexOfNonEmptyEngineGroup(static_cast(5u))); +} + +TEST(DeviceGenEngineTest, givenEmptyGroupsWhenGettingNonEmptyGroupIndexThenReturnCorrectResults) { + const auto emptyEngineGroup = std::vector{}; + const auto nonEmptyEngineGroup = std::vector{EngineControl{nullptr, nullptr}}; + + auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); + auto &engineGroups = device->getEngineGroups(); + engineGroups.clear(); + engineGroups.push_back(emptyEngineGroup); + engineGroups.push_back(nonEmptyEngineGroup); + engineGroups.push_back(emptyEngineGroup); + engineGroups.push_back(nonEmptyEngineGroup); + + EXPECT_ANY_THROW(device->getIndexOfNonEmptyEngineGroup(static_cast(0u))); + EXPECT_EQ(0u, device->getIndexOfNonEmptyEngineGroup(static_cast(1u))); + EXPECT_ANY_THROW(device->getIndexOfNonEmptyEngineGroup(static_cast(2u))); + EXPECT_EQ(1u, device->getIndexOfNonEmptyEngineGroup(static_cast(3u))); + EXPECT_ANY_THROW(device->getIndexOfNonEmptyEngineGroup(static_cast(4u))); + EXPECT_ANY_THROW(device->getIndexOfNonEmptyEngineGroup(static_cast(5u))); +} + TEST(DeviceGenEngineTest, whenGettingQueueFamilyCapabilitiesAllThenReturnCorrectValue) { const cl_command_queue_capabilities_intel expectedProperties = CL_QUEUE_CAPABILITY_CREATE_SINGLE_QUEUE_EVENTS_INTEL | CL_QUEUE_CAPABILITY_CREATE_CROSS_QUEUE_EVENTS_INTEL | diff --git a/opencl/test/unit_test/mocks/mock_command_queue.h b/opencl/test/unit_test/mocks/mock_command_queue.h index 452c3a4e36..16f188ae7d 100644 --- a/opencl/test/unit_test/mocks/mock_command_queue.h +++ b/opencl/test/unit_test/mocks/mock_command_queue.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -18,6 +18,7 @@ namespace NEO { class MockCommandQueue : public CommandQueue { public: + using CommandQueue::bcsEngine; using CommandQueue::blitEnqueueAllowed; using CommandQueue::blitEnqueueImageAllowed; using CommandQueue::bufferCpuCopyAllowed; diff --git a/shared/source/device/device.cpp b/shared/source/device/device.cpp index c007d16b6a..6fc964305b 100644 --- a/shared/source/device/device.cpp +++ b/shared/source/device/device.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -243,6 +243,21 @@ const std::vector *Device::getNonEmptyEngineGroup(size_t index) c return nullptr; } +size_t Device::getIndexOfNonEmptyEngineGroup(EngineGroupType engineGroupType) const { + const auto groupIndex = static_cast(engineGroupType); + UNRECOVERABLE_IF(groupIndex >= engineGroups.size()); + UNRECOVERABLE_IF(engineGroups[groupIndex].empty()); + + size_t result = 0u; + for (auto currentGroupIndex = 0u; currentGroupIndex < groupIndex; currentGroupIndex++) { + if (!engineGroups[currentGroupIndex].empty()) { + result++; + } + } + + return result; +} + EngineControl &Device::getEngine(aub_stream::EngineType engineType, bool lowPriority, bool internalUsage) { for (auto &engine : engines) { if (engine.osContext->getEngineType() == engineType && diff --git a/shared/source/device/device.h b/shared/source/device/device.h index 2f0df45225..8ef0e9c897 100644 --- a/shared/source/device/device.h +++ b/shared/source/device/device.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -18,6 +18,8 @@ #include "opencl/source/os_interface/performance_counters.h" +#include "engine_group_types.h" + namespace NEO { class OSTime; class SourceLevelDebugger; @@ -50,6 +52,7 @@ class Device : public ReferenceTrackedObject { return this->engineGroups; } const std::vector *getNonEmptyEngineGroup(size_t index) const; + size_t getIndexOfNonEmptyEngineGroup(EngineGroupType engineGroupType) const; EngineControl &getEngine(uint32_t index); EngineControl &getDefaultEngine(); EngineControl &getInternalEngine();