Skip to content

Commit aed1da7

Browse files
Code cleanup - avoid copy 3/n
Signed-off-by: Kamil Kopryk <[email protected]>
1 parent 88c6c9d commit aed1da7

File tree

7 files changed

+15
-19
lines changed

7 files changed

+15
-19
lines changed

level_zero/core/source/device/device_imp.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,10 @@ ze_result_t DeviceImp::createCommandQueue(const ze_command_queue_desc_t *desc,
139139
ze_result_t DeviceImp::getCommandQueueGroupProperties(uint32_t *pCount,
140140
ze_command_queue_group_properties_t *pCommandQueueGroupProperties) {
141141
NEO::Device *activeDevice = getActiveDevice();
142-
auto engines = activeDevice->getEngineGroups();
143-
144-
uint32_t numEngineGroups = 0;
145-
for (uint32_t i = 0; i < engines.size(); i++) {
146-
if (engines[i].size() > 0) {
147-
numEngineGroups++;
148-
}
149-
}
142+
auto &engineGroups = activeDevice->getEngineGroups();
143+
auto numEngineGroups = static_cast<uint32_t>(std::count_if(std::begin(engineGroups), std::end(engineGroups), [](const auto &engines) {
144+
return !engines.empty();
145+
}));
150146

151147
if (*pCount == 0) {
152148
*pCount = numEngineGroups;
@@ -158,7 +154,7 @@ ze_result_t DeviceImp::getCommandQueueGroupProperties(uint32_t *pCount,
158154
i < static_cast<uint32_t>(NEO::EngineGroupType::MaxEngineGroups) && engineGroupCount < *pCount;
159155
i++) {
160156

161-
if (engines[i].empty()) {
157+
if (engineGroups[i].empty()) {
162158
continue;
163159
}
164160
const auto &hardwareInfo = this->neoDevice->getHardwareInfo();
@@ -182,7 +178,7 @@ ze_result_t DeviceImp::getCommandQueueGroupProperties(uint32_t *pCount,
182178
}
183179
auto &l0HwHelper = L0HwHelper::get(hardwareInfo.platform.eRenderCoreFamily);
184180
l0HwHelper.setAdditionalGroupProperty(pCommandQueueGroupProperties[engineGroupCount], i);
185-
pCommandQueueGroupProperties[engineGroupCount].numQueues = static_cast<uint32_t>(engines[i].size());
181+
pCommandQueueGroupProperties[engineGroupCount].numQueues = static_cast<uint32_t>(engineGroups[i].size());
186182
engineGroupCount++;
187183
}
188184

@@ -916,7 +912,7 @@ ze_result_t DeviceImp::getCsrForLowPriority(NEO::CommandStreamReceiver **csr) {
916912

917913
ze_result_t DeviceImp::mapOrdinalForAvailableEngineGroup(uint32_t *ordinal) {
918914
NEO::Device *activeDevice = getActiveDevice();
919-
auto engines = activeDevice->getEngineGroups();
915+
const auto &engines = activeDevice->getEngineGroups();
920916
uint32_t numNonEmptyGroups = 0;
921917
uint32_t i = 0;
922918
for (; i < engines.size() && numNonEmptyGroups <= *ordinal; i++) {

level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ TEST_F(CommandListCreate, whenInvokingAppendMemoryCopyFromContextForImmediateCom
11871187
}
11881188

11891189
TEST_F(CommandListCreate, givenQueueDescriptionwhenCreatingImmediateCommandListForEveryEnigneThenItHasImmediateCommandQueueCreated) {
1190-
auto engines = neoDevice->getEngineGroups();
1190+
auto &engines = neoDevice->getEngineGroups();
11911191
uint32_t numaAvailableEngineGroups = 0;
11921192
for (uint32_t ordinal = 0; ordinal < static_cast<uint32_t>(NEO::EngineGroupType::MaxEngineGroups); ordinal++) {
11931193
if (engines[ordinal].size()) {

level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ TEST_F(CommandListCreate, whenCreatingImmCmdListWithASyncModeAndAppendEventReset
11441144
}
11451145

11461146
TEST_F(CommandListCreate, givenQueueDescriptionwhenCreatingImmediateCommandListForCopyEnigneThenItHasImmediateCommandQueueCreated) {
1147-
auto engines = neoDevice->getEngineGroups();
1147+
auto &engines = neoDevice->getEngineGroups();
11481148
uint32_t numaAvailableEngineGroups = 0;
11491149
for (uint32_t ordinal = 0; ordinal < static_cast<uint32_t>(NEO::EngineGroupType::MaxEngineGroups); ordinal++) {
11501150
if (engines[ordinal].size()) {

level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ TEST_F(ContextCreateCommandQueueTest, givenCallToContextCreateCommandQueueThenCa
887887

888888
HWTEST_F(ContextCreateCommandQueueTest, givenEveryPossibleGroupIndexWhenCreatingCommandQueueThenCommandQueueIsCreated) {
889889
ze_command_queue_handle_t commandQueue = {};
890-
auto engines = neoDevice->getEngineGroups();
890+
auto &engines = neoDevice->getEngineGroups();
891891
uint32_t numaAvailableEngineGroups = 0;
892892
for (uint32_t ordinal = 0; ordinal < static_cast<uint32_t>(NEO::EngineGroupType::MaxEngineGroups); ordinal++) {
893893
if (engines[ordinal].size()) {
@@ -912,7 +912,7 @@ HWTEST_F(ContextCreateCommandQueueTest, givenEveryPossibleGroupIndexWhenCreating
912912

913913
HWTEST_F(ContextCreateCommandQueueTest, givenOrdinalBigerThanAvailableEnginesWhenCreatingCommandQueueThenInvalidArgReturned) {
914914
ze_command_queue_handle_t commandQueue = {};
915-
auto engines = neoDevice->getEngineGroups();
915+
auto &engines = neoDevice->getEngineGroups();
916916
uint32_t numaAvailableEngineGroups = 0;
917917
for (uint32_t ordinal = 0; ordinal < static_cast<uint32_t>(NEO::EngineGroupType::MaxEngineGroups); ordinal++) {
918918
if (engines[ordinal].size()) {

opencl/source/command_queue/command_queue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ void CommandQueue::processProperties(const cl_queue_properties *properties) {
840840
this->queueFamilySelected = true;
841841
if (getDevice().getNumAvailableDevices() == 1) {
842842
auto queueFamily = getDevice().getNonEmptyEngineGroup(selectedQueueFamilyIndex);
843-
auto engine = queueFamily->at(selectedQueueIndex);
843+
const auto &engine = queueFamily->at(selectedQueueIndex);
844844
auto engineType = engine.getEngineType();
845845
this->overrideEngine(engineType);
846846
this->queueCapabilities = getClDevice().getDeviceInfo().queueFamilyProperties[selectedQueueFamilyIndex].capabilities;

opencl/test/unit_test/api/cl_create_command_queue_with_properties_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ HWTEST_F(LowPriorityCommandQueueTest, GivenDeviceWithSubdevicesWhenCreatingLowPr
562562

563563
auto commandQueueObj = castToObject<CommandQueue>(cmdQ);
564564
auto subDevice = context.getDevice(0)->getDeviceById(0);
565-
auto engine = subDevice->getEngine(getChosenEngineType(subDevice->getHardwareInfo()), EngineUsage::LowPriority);
565+
auto &engine = subDevice->getEngine(getChosenEngineType(subDevice->getHardwareInfo()), EngineUsage::LowPriority);
566566

567567
EXPECT_EQ(engine.commandStreamReceiver, &commandQueueObj->getGpgpuCommandStreamReceiver());
568568
EXPECT_EQ(engine.osContext, &commandQueueObj->getGpgpuCommandStreamReceiver().getOsContext());

shared/source/helpers/engine_control.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2020 Intel Corporation
2+
* Copyright (C) 2018-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -22,6 +22,6 @@ struct EngineControl {
2222
CommandStreamReceiver *commandStreamReceiver = nullptr;
2323
OsContext *osContext = nullptr;
2424

25-
aub_stream::EngineType &getEngineType() { return osContext->getEngineType(); }
25+
aub_stream::EngineType &getEngineType() const { return osContext->getEngineType(); }
2626
};
2727
} // namespace NEO

0 commit comments

Comments
 (0)