Skip to content

Commit e2db055

Browse files
committed
refactor: using optimized funcs with char param, constexpr calc out-of-loop
Signed-off-by: Semenov Herman (Семенов Герман) <[email protected]>
1 parent 47ed553 commit e2db055

File tree

11 files changed

+37
-37
lines changed

11 files changed

+37
-37
lines changed

opencl/source/command_queue/command_queue_staging.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ cl_int CommandQueue::enqueueStagingBufferMemcpy(cl_bool blockingCopy, void *dstP
2525
CsrSelectionArgs csrSelectionArgs{CL_COMMAND_SVM_MEMCPY, &size};
2626
csrSelectionArgs.direction = TransferDirection::hostToLocal;
2727
auto csr = &selectCsrForBuiltinOperation(csrSelectionArgs);
28-
cl_event profilingEvent;
28+
cl_event profilingEvent = nullptr;
2929

3030
bool isSingleTransfer = false;
3131
ChunkCopyFunction chunkCopy = [&](void *chunkSrc, void *chunkDst, size_t chunkSize) -> int32_t {
@@ -46,7 +46,7 @@ cl_int CommandQueue::enqueueStagingWriteImage(Image *dstImage, cl_bool blockingC
4646
size_t inputRowPitch, size_t inputSlicePitch, const void *ptr, cl_event *event) {
4747
CsrSelectionArgs csrSelectionArgs{CL_COMMAND_WRITE_IMAGE, nullptr, dstImage, this->getDevice().getRootDeviceIndex(), globalRegion, nullptr, globalOrigin};
4848
auto &csr = selectCsrForBuiltinOperation(csrSelectionArgs);
49-
cl_event profilingEvent;
49+
cl_event profilingEvent = nullptr;
5050

5151
bool isSingleTransfer = false;
5252
ChunkTransferImageFunc chunkWrite = [&](void *stagingBuffer, const size_t *origin, const size_t *region) -> int32_t {
@@ -69,7 +69,7 @@ cl_int CommandQueue::enqueueStagingReadImage(Image *srcImage, cl_bool blockingCo
6969
size_t inputRowPitch, size_t inputSlicePitch, const void *ptr, cl_event *event) {
7070
CsrSelectionArgs csrSelectionArgs{CL_COMMAND_READ_IMAGE, srcImage, nullptr, this->getDevice().getRootDeviceIndex(), globalRegion, nullptr, globalOrigin};
7171
auto &csr = selectCsrForBuiltinOperation(csrSelectionArgs);
72-
cl_event profilingEvent;
72+
cl_event profilingEvent = nullptr;
7373

7474
bool isSingleTransfer = false;
7575
ChunkTransferImageFunc chunkRead = [&](void *stagingBuffer, const size_t *origin, const size_t *region) -> int32_t {

shared/offline_compiler/source/decoder/binary_decoder.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2024 Intel Corporation
2+
* Copyright (C) 2018-2025 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -237,7 +237,7 @@ void BinaryDecoder::parseTokens() {
237237
break;
238238
} else if (patchList[i].find("PATCH_TOKEN") == std::string::npos) {
239239
continue;
240-
} else if (patchList[i].find("@") == std::string::npos) {
240+
} else if (patchList[i].find('@') == std::string::npos) {
241241
continue;
242242
}
243243

@@ -254,7 +254,7 @@ void BinaryDecoder::parseTokens() {
254254
nameEndPos = patchList[i].find(',', nameStartPos);
255255
patchTokenPtr->name = patchList[i].substr(nameStartPos, nameEndPos - nameStartPos);
256256

257-
nameStartPos = patchList[i].find("@");
257+
nameStartPos = patchList[i].find('@');
258258
nameEndPos = patchList[i].find('@', nameStartPos + 1);
259259
if (nameEndPos == std::string::npos) {
260260
continue;

shared/offline_compiler/source/multi_command.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2024 Intel Corporation
2+
* Copyright (C) 2019-2025 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -189,7 +189,7 @@ int MultiCommand::splitLineInSeparateArgs(std::vector<std::string> &qargs, const
189189
continue;
190190
} else {
191191
start = i;
192-
end = commandsLine.find(" ", start);
192+
end = commandsLine.find(' ', start);
193193
end = (end == std::string::npos) ? commandsLine.length() : end;
194194
}
195195
if (end == std::string::npos) {

shared/offline_compiler/source/ocloc_fatbinary.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2024 Intel Corporation
2+
* Copyright (C) 2020-2025 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -306,7 +306,7 @@ int buildFatBinaryForTarget(int retVal, const std::vector<std::string> &argsCopy
306306
}
307307

308308
std::string entryName("");
309-
if (product.find(".") != std::string::npos) {
309+
if (product.find('.') != std::string::npos) {
310310
entryName = product;
311311
} else {
312312
auto productConfig = argHelper->productConfigHelper->getProductConfigFromDeviceName(product);

shared/offline_compiler/source/offline_compiler.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2024 Intel Corporation
2+
* Copyright (C) 2018-2025 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -247,7 +247,7 @@ std::string formatNameVersionString(std::vector<NameVersionPair> extensions, boo
247247
for (const auto &ext : extensions) {
248248
formatedExtensions.push_back({});
249249
auto it = formatedExtensions.rbegin();
250-
bool needsQuoutes = (nullptr != strstr(ext.name, " "));
250+
bool needsQuoutes = (nullptr != strchr(ext.name, ' '));
251251
it->reserve(strnlen_s(ext.name, sizeof(ext.name)) + (needsQuoutes ? 2 : 0) + (needVersions ? 16 : 0));
252252
if (needsQuoutes) {
253253
it->append("\"");
@@ -888,7 +888,7 @@ int OfflineCompiler::initialize(size_t numArgs, const std::vector<std::string> &
888888

889889
if (options.empty()) {
890890
// try to read options from file if not provided by commandline
891-
size_t extStart = inputFile.find_last_of(".");
891+
size_t extStart = inputFile.find_last_of('.');
892892
if (extStart != std::string::npos) {
893893
std::string oclocOptionsFileName = inputFile.substr(0, extStart);
894894
oclocOptionsFileName.append("_ocloc_options.txt");
@@ -1236,7 +1236,7 @@ std::string OfflineCompiler::parseBinAsCharArray(uint8_t *binary, size_t size, s
12361236

12371237
std::string OfflineCompiler::getFileNameTrunk(std::string &filePath) {
12381238
size_t slashPos = filePath.find_last_of("\\/", filePath.size()) + 1;
1239-
size_t extPos = filePath.find_last_of(".", filePath.size());
1239+
size_t extPos = filePath.find_last_of('.', filePath.size());
12401240
if (extPos == std::string::npos) {
12411241
extPos = filePath.size();
12421242
}
@@ -1576,7 +1576,7 @@ void OfflineCompiler::writeOutAllFiles() {
15761576
if (outputFile.empty()) {
15771577
elfOutputFile = generateFilePath(outputDirectory, fileBase, ".bin");
15781578
} else {
1579-
size_t extPos = fileBase.find_last_of(".", fileBase.size());
1579+
size_t extPos = fileBase.find_last_of('.', fileBase.size());
15801580
std::string fileExt = ".bin";
15811581
if (extPos != std::string::npos) {
15821582
auto existingExt = fileBase.substr(extPos, fileBase.size());

shared/source/device_binary_format/zebin/zeinfo_decoder.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2023-2024 Intel Corporation
2+
* Copyright (C) 2023-2025 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -354,7 +354,7 @@ void populateKernelMiscInfo(KernelDescriptor &dst, KernelMiscArgInfos &kernelMis
354354
dstTypeTraits.typeQualifiers = KernelArgMetadata::parseTypeQualifiers(dstMetadata.typeQualifiers);
355355
dst.payloadMappings.explicitArgs.at(srcMetadata.index).getTraits() = std::move(dstTypeTraits);
356356

357-
dstMetadata.type = dstMetadata.type.substr(0U, dstMetadata.type.find(";"));
357+
dstMetadata.type = dstMetadata.type.substr(0U, dstMetadata.type.find(';'));
358358
dst.explicitArgsExtendedMetadata.at(srcMetadata.index) = std::move(dstMetadata);
359359
}
360360
}

shared/source/helpers/product_config_helper.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2022-2024 Intel Corporation
2+
* Copyright (C) 2022-2025 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -47,7 +47,7 @@ void ProductConfigHelper::adjustDeviceName(std::string &device) {
4747
device = device.substr(0, findCore);
4848
}
4949

50-
auto findUnderscore = device.find("_");
50+
auto findUnderscore = device.find('_');
5151
if (findUnderscore != std::string::npos) {
5252
device.erase(std::remove(device.begin(), device.end(), '_'), device.end());
5353
}
@@ -146,7 +146,7 @@ bool ProductConfigHelper::isSupportedProductConfig(uint32_t config) const {
146146

147147
AOT::PRODUCT_CONFIG ProductConfigHelper::getProductConfigFromDeviceName(const std::string &device) const {
148148
uint32_t config = AOT::UNKNOWN_ISA;
149-
if (device.find(".") != std::string::npos) {
149+
if (device.find('.') != std::string::npos) {
150150
config = getProductConfigFromVersionValue(device);
151151
} else if (std::all_of(device.begin(), device.end(), (::isdigit))) {
152152
config = static_cast<uint32_t>(std::stoul(device));
@@ -212,7 +212,7 @@ std::vector<NEO::ConstStringRef> ProductConfigHelper::getAllProductAcronyms() {
212212

213213
PRODUCT_FAMILY ProductConfigHelper::getProductFamilyFromDeviceName(const std::string &device) const {
214214
std::vector<DeviceAotInfo>::const_iterator it;
215-
if (device.find(".") != std::string::npos) {
215+
if (device.find('.') != std::string::npos) {
216216
it = std::find_if(deviceAotInfo.begin(), deviceAotInfo.end(), findProductConfig(getProductConfigFromVersionValue(device)));
217217
} else {
218218
it = std::find_if(deviceAotInfo.begin(), deviceAotInfo.end(), findAcronym(device));
@@ -271,13 +271,13 @@ int ProductConfigHelper::parseProductConfigFromString(const std::string &device,
271271
}
272272

273273
uint32_t ProductConfigHelper::getProductConfigFromVersionValue(const std::string &device) {
274-
auto majorPos = device.find(".");
274+
auto majorPos = device.find('.');
275275
auto major = parseProductConfigFromString(device, 0, majorPos);
276276
if (major == ConfigStatus::MismatchedValue || majorPos == std::string::npos) {
277277
return AOT::UNKNOWN_ISA;
278278
}
279279

280-
auto minorPos = device.find(".", ++majorPos);
280+
auto minorPos = device.find('.', ++majorPos);
281281
auto minor = parseProductConfigFromString(device, majorPos, minorPos);
282282

283283
if (minor == ConfigStatus::MismatchedValue || minorPos == std::string::npos) {

shared/source/os_interface/linux/drm_neo.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2024 Intel Corporation
2+
* Copyright (C) 2018-2025 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -659,15 +659,17 @@ std::vector<std::unique_ptr<HwDeviceId>> Drm::discoverDevices(ExecutionEnvironme
659659

660660
do {
661661
const char *renderDeviceSuffix = "-render";
662+
constexpr size_t renderDevSufSize = std::char_traits<char>::length(renderDeviceSuffix);
663+
constexpr size_t pciDevDirLen = std::char_traits<char>::length(Os::pciDevicesDirectory);
662664
for (std::vector<std::string>::iterator file = files.begin(); file != files.end(); ++file) {
663665
std::string_view devicePathView(file->c_str(), file->size());
664-
devicePathView = devicePathView.substr(strlen(Os::pciDevicesDirectory));
666+
devicePathView = devicePathView.substr(pciDevDirLen);
665667

666668
auto rdsPos = devicePathView.rfind(renderDeviceSuffix);
667669
if (rdsPos == std::string::npos) {
668670
continue;
669671
}
670-
if (rdsPos < devicePathView.size() - strlen(renderDeviceSuffix)) {
672+
if (rdsPos < devicePathView.size() - renderDevSufSize) {
671673
continue;
672674
}
673675
// at least 'pci-0000:00:00.0' -> 16
@@ -1091,9 +1093,12 @@ bool Drm::completionFenceSupport() {
10911093

10921094
void Drm::setupIoctlHelper(const PRODUCT_FAMILY productFamily) {
10931095
if (!this->ioctlHelper) {
1096+
auto drmVersion = Drm::getDrmVersion(getFileDescriptor());
10941097
auto productSpecificIoctlHelperCreator = ioctlHelperFactory[productFamily];
10951098
if (productSpecificIoctlHelperCreator && !debugManager.flags.IgnoreProductSpecificIoctlHelper.get()) {
10961099
this->ioctlHelper = productSpecificIoctlHelperCreator.value()(*this);
1100+
} else if ("xe" == drmVersion) {
1101+
this->ioctlHelper = IoctlHelperXe::create(*this);
10971102
} else {
10981103
std::string prelimVersion = "";
10991104
getPrelimVersion(prelimVersion);
@@ -1726,10 +1731,8 @@ bool Drm::isDrmSupported(int fileDescriptor) {
17261731
bool Drm::queryDeviceIdAndRevision() {
17271732
auto drmVersion = Drm::getDrmVersion(getFileDescriptor());
17281733
if ("xe" == drmVersion) {
1729-
this->ioctlHelper = IoctlHelperXe::create(*this);
1730-
auto xeIoctlHelperPtr = static_cast<IoctlHelperXe *>(this->ioctlHelper.get());
17311734
this->setPerContextVMRequired(false);
1732-
return xeIoctlHelperPtr->initialize();
1735+
return IoctlHelperXe::queryDeviceIdAndRevision(*this);
17331736
}
17341737
return IoctlHelperI915::queryDeviceIdAndRevision(*this);
17351738
}

shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,6 @@ bool IoctlHelperXe::initialize() {
161161

162162
euDebugInterface = EuDebugInterface::create(drm.getSysFsPciPath());
163163

164-
if (!IoctlHelperXe::queryDeviceIdAndRevision(this->drm)) {
165-
return false;
166-
}
167-
168164
drm_xe_device_query queryConfig = {};
169165
queryConfig.query = DRM_XE_DEVICE_QUERY_CONFIG;
170166

shared/test/unit_test/os_interface/linux/ioctl_helper_tests_dg1.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ using namespace NEO;
2020

2121
using IoctlHelperTestsDg1 = ::testing::Test;
2222

23+
DG1TEST_F(IoctlHelperTestsDg1, givenDg1WhenSetupIoctlHelperThenDg1SpecificHelperIsAvailable) {
24+
EXPECT_TRUE(ioctlHelperFactory[IGFX_DG1].has_value());
25+
}
26+
2327
DG1TEST_F(IoctlHelperTestsDg1, givenDg1WhenCreateGemExtThenReturnCorrectValue) {
2428
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
2529
auto drm = std::make_unique<DrmTipMock>(*executionEnvironment->rootDeviceEnvironments[0]);

shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -1959,13 +1959,10 @@ TEST_F(IoctlHelperXeTest, whenInitializeThenProperHwInfoIsSet) {
19591959

19601960
auto hwInfo = executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo();
19611961

1962-
hwInfo->platform.usDeviceID = defaultHwInfo->platform.usDeviceID + 1;
1963-
hwInfo->platform.usRevId = defaultHwInfo->platform.usRevId + 1;
19641962
hwInfo->capabilityTable.gpuAddressSpace = 0;
19651963

19661964
ioctlHelper->initialize();
1967-
EXPECT_EQ(defaultHwInfo->platform.usRevId, hwInfo->platform.usRevId);
1968-
EXPECT_EQ(defaultHwInfo->platform.usDeviceID, hwInfo->platform.usDeviceID);
1965+
19691966
EXPECT_EQ((1ull << 48) - 1, hwInfo->capabilityTable.gpuAddressSpace);
19701967
EXPECT_EQ(static_cast<uint32_t>(DrmMockXe::mockDefaultCxlType), hwInfo->capabilityTable.cxlType);
19711968

0 commit comments

Comments
 (0)