From e2db05500802a8b861a1a20f850ce2a79b293b13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Semenov=20Herman=20=28=D0=A1=D0=B5=D0=BC=D0=B5=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=20=D0=93=D0=B5=D1=80=D0=BC=D0=B0=D0=BD=29?= Date: Sat, 4 Jan 2025 22:12:04 +0300 Subject: [PATCH] refactor: using optimized funcs with char param, constexpr calc out-of-loop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Semenov Herman (Семенов Герман) --- .../command_queue/command_queue_staging.cpp | 6 +++--- .../source/decoder/binary_decoder.cpp | 6 +++--- shared/offline_compiler/source/multi_command.cpp | 4 ++-- .../offline_compiler/source/ocloc_fatbinary.cpp | 4 ++-- .../offline_compiler/source/offline_compiler.cpp | 10 +++++----- .../device_binary_format/zebin/zeinfo_decoder.cpp | 4 ++-- shared/source/helpers/product_config_helper.cpp | 12 ++++++------ shared/source/os_interface/linux/drm_neo.cpp | 15 +++++++++------ .../os_interface/linux/xe/ioctl_helper_xe.cpp | 4 ---- .../os_interface/linux/ioctl_helper_tests_dg1.cpp | 4 ++++ .../linux/xe/ioctl_helper_xe_tests.cpp | 5 +---- 11 files changed, 37 insertions(+), 37 deletions(-) diff --git a/opencl/source/command_queue/command_queue_staging.cpp b/opencl/source/command_queue/command_queue_staging.cpp index 1cd9fe3d82c07..8a96319ca91b9 100644 --- a/opencl/source/command_queue/command_queue_staging.cpp +++ b/opencl/source/command_queue/command_queue_staging.cpp @@ -25,7 +25,7 @@ cl_int CommandQueue::enqueueStagingBufferMemcpy(cl_bool blockingCopy, void *dstP CsrSelectionArgs csrSelectionArgs{CL_COMMAND_SVM_MEMCPY, &size}; csrSelectionArgs.direction = TransferDirection::hostToLocal; auto csr = &selectCsrForBuiltinOperation(csrSelectionArgs); - cl_event profilingEvent; + cl_event profilingEvent = nullptr; bool isSingleTransfer = false; ChunkCopyFunction chunkCopy = [&](void *chunkSrc, void *chunkDst, size_t chunkSize) -> int32_t { @@ -46,7 +46,7 @@ cl_int CommandQueue::enqueueStagingWriteImage(Image *dstImage, cl_bool blockingC size_t inputRowPitch, size_t inputSlicePitch, const void *ptr, cl_event *event) { CsrSelectionArgs csrSelectionArgs{CL_COMMAND_WRITE_IMAGE, nullptr, dstImage, this->getDevice().getRootDeviceIndex(), globalRegion, nullptr, globalOrigin}; auto &csr = selectCsrForBuiltinOperation(csrSelectionArgs); - cl_event profilingEvent; + cl_event profilingEvent = nullptr; bool isSingleTransfer = false; 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 size_t inputRowPitch, size_t inputSlicePitch, const void *ptr, cl_event *event) { CsrSelectionArgs csrSelectionArgs{CL_COMMAND_READ_IMAGE, srcImage, nullptr, this->getDevice().getRootDeviceIndex(), globalRegion, nullptr, globalOrigin}; auto &csr = selectCsrForBuiltinOperation(csrSelectionArgs); - cl_event profilingEvent; + cl_event profilingEvent = nullptr; bool isSingleTransfer = false; ChunkTransferImageFunc chunkRead = [&](void *stagingBuffer, const size_t *origin, const size_t *region) -> int32_t { diff --git a/shared/offline_compiler/source/decoder/binary_decoder.cpp b/shared/offline_compiler/source/decoder/binary_decoder.cpp index ae74b978a2ad6..59f38cbcd676c 100644 --- a/shared/offline_compiler/source/decoder/binary_decoder.cpp +++ b/shared/offline_compiler/source/decoder/binary_decoder.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2024 Intel Corporation + * Copyright (C) 2018-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -237,7 +237,7 @@ void BinaryDecoder::parseTokens() { break; } else if (patchList[i].find("PATCH_TOKEN") == std::string::npos) { continue; - } else if (patchList[i].find("@") == std::string::npos) { + } else if (patchList[i].find('@') == std::string::npos) { continue; } @@ -254,7 +254,7 @@ void BinaryDecoder::parseTokens() { nameEndPos = patchList[i].find(',', nameStartPos); patchTokenPtr->name = patchList[i].substr(nameStartPos, nameEndPos - nameStartPos); - nameStartPos = patchList[i].find("@"); + nameStartPos = patchList[i].find('@'); nameEndPos = patchList[i].find('@', nameStartPos + 1); if (nameEndPos == std::string::npos) { continue; diff --git a/shared/offline_compiler/source/multi_command.cpp b/shared/offline_compiler/source/multi_command.cpp index c90c9b8919bb4..98deda7480eb9 100644 --- a/shared/offline_compiler/source/multi_command.cpp +++ b/shared/offline_compiler/source/multi_command.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2024 Intel Corporation + * Copyright (C) 2019-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -189,7 +189,7 @@ int MultiCommand::splitLineInSeparateArgs(std::vector &qargs, const continue; } else { start = i; - end = commandsLine.find(" ", start); + end = commandsLine.find(' ', start); end = (end == std::string::npos) ? commandsLine.length() : end; } if (end == std::string::npos) { diff --git a/shared/offline_compiler/source/ocloc_fatbinary.cpp b/shared/offline_compiler/source/ocloc_fatbinary.cpp index 0ce7bdd73b1d4..9352521b03e9b 100644 --- a/shared/offline_compiler/source/ocloc_fatbinary.cpp +++ b/shared/offline_compiler/source/ocloc_fatbinary.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2024 Intel Corporation + * Copyright (C) 2020-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -306,7 +306,7 @@ int buildFatBinaryForTarget(int retVal, const std::vector &argsCopy } std::string entryName(""); - if (product.find(".") != std::string::npos) { + if (product.find('.') != std::string::npos) { entryName = product; } else { auto productConfig = argHelper->productConfigHelper->getProductConfigFromDeviceName(product); diff --git a/shared/offline_compiler/source/offline_compiler.cpp b/shared/offline_compiler/source/offline_compiler.cpp index 870db00f2f082..b67045af66a16 100644 --- a/shared/offline_compiler/source/offline_compiler.cpp +++ b/shared/offline_compiler/source/offline_compiler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2024 Intel Corporation + * Copyright (C) 2018-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -247,7 +247,7 @@ std::string formatNameVersionString(std::vector extensions, boo for (const auto &ext : extensions) { formatedExtensions.push_back({}); auto it = formatedExtensions.rbegin(); - bool needsQuoutes = (nullptr != strstr(ext.name, " ")); + bool needsQuoutes = (nullptr != strchr(ext.name, ' ')); it->reserve(strnlen_s(ext.name, sizeof(ext.name)) + (needsQuoutes ? 2 : 0) + (needVersions ? 16 : 0)); if (needsQuoutes) { it->append("\""); @@ -888,7 +888,7 @@ int OfflineCompiler::initialize(size_t numArgs, const std::vector & if (options.empty()) { // try to read options from file if not provided by commandline - size_t extStart = inputFile.find_last_of("."); + size_t extStart = inputFile.find_last_of('.'); if (extStart != std::string::npos) { std::string oclocOptionsFileName = inputFile.substr(0, extStart); oclocOptionsFileName.append("_ocloc_options.txt"); @@ -1236,7 +1236,7 @@ std::string OfflineCompiler::parseBinAsCharArray(uint8_t *binary, size_t size, s std::string OfflineCompiler::getFileNameTrunk(std::string &filePath) { size_t slashPos = filePath.find_last_of("\\/", filePath.size()) + 1; - size_t extPos = filePath.find_last_of(".", filePath.size()); + size_t extPos = filePath.find_last_of('.', filePath.size()); if (extPos == std::string::npos) { extPos = filePath.size(); } @@ -1576,7 +1576,7 @@ void OfflineCompiler::writeOutAllFiles() { if (outputFile.empty()) { elfOutputFile = generateFilePath(outputDirectory, fileBase, ".bin"); } else { - size_t extPos = fileBase.find_last_of(".", fileBase.size()); + size_t extPos = fileBase.find_last_of('.', fileBase.size()); std::string fileExt = ".bin"; if (extPos != std::string::npos) { auto existingExt = fileBase.substr(extPos, fileBase.size()); diff --git a/shared/source/device_binary_format/zebin/zeinfo_decoder.cpp b/shared/source/device_binary_format/zebin/zeinfo_decoder.cpp index 8dcbfbb85d0f4..9b87f809a9f37 100644 --- a/shared/source/device_binary_format/zebin/zeinfo_decoder.cpp +++ b/shared/source/device_binary_format/zebin/zeinfo_decoder.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023-2024 Intel Corporation + * Copyright (C) 2023-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -354,7 +354,7 @@ void populateKernelMiscInfo(KernelDescriptor &dst, KernelMiscArgInfos &kernelMis dstTypeTraits.typeQualifiers = KernelArgMetadata::parseTypeQualifiers(dstMetadata.typeQualifiers); dst.payloadMappings.explicitArgs.at(srcMetadata.index).getTraits() = std::move(dstTypeTraits); - dstMetadata.type = dstMetadata.type.substr(0U, dstMetadata.type.find(";")); + dstMetadata.type = dstMetadata.type.substr(0U, dstMetadata.type.find(';')); dst.explicitArgsExtendedMetadata.at(srcMetadata.index) = std::move(dstMetadata); } } diff --git a/shared/source/helpers/product_config_helper.cpp b/shared/source/helpers/product_config_helper.cpp index acb27d4a1bc0e..46fcb8eb31d07 100644 --- a/shared/source/helpers/product_config_helper.cpp +++ b/shared/source/helpers/product_config_helper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2024 Intel Corporation + * Copyright (C) 2022-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -47,7 +47,7 @@ void ProductConfigHelper::adjustDeviceName(std::string &device) { device = device.substr(0, findCore); } - auto findUnderscore = device.find("_"); + auto findUnderscore = device.find('_'); if (findUnderscore != std::string::npos) { device.erase(std::remove(device.begin(), device.end(), '_'), device.end()); } @@ -146,7 +146,7 @@ bool ProductConfigHelper::isSupportedProductConfig(uint32_t config) const { AOT::PRODUCT_CONFIG ProductConfigHelper::getProductConfigFromDeviceName(const std::string &device) const { uint32_t config = AOT::UNKNOWN_ISA; - if (device.find(".") != std::string::npos) { + if (device.find('.') != std::string::npos) { config = getProductConfigFromVersionValue(device); } else if (std::all_of(device.begin(), device.end(), (::isdigit))) { config = static_cast(std::stoul(device)); @@ -212,7 +212,7 @@ std::vector ProductConfigHelper::getAllProductAcronyms() { PRODUCT_FAMILY ProductConfigHelper::getProductFamilyFromDeviceName(const std::string &device) const { std::vector::const_iterator it; - if (device.find(".") != std::string::npos) { + if (device.find('.') != std::string::npos) { it = std::find_if(deviceAotInfo.begin(), deviceAotInfo.end(), findProductConfig(getProductConfigFromVersionValue(device))); } else { it = std::find_if(deviceAotInfo.begin(), deviceAotInfo.end(), findAcronym(device)); @@ -271,13 +271,13 @@ int ProductConfigHelper::parseProductConfigFromString(const std::string &device, } uint32_t ProductConfigHelper::getProductConfigFromVersionValue(const std::string &device) { - auto majorPos = device.find("."); + auto majorPos = device.find('.'); auto major = parseProductConfigFromString(device, 0, majorPos); if (major == ConfigStatus::MismatchedValue || majorPos == std::string::npos) { return AOT::UNKNOWN_ISA; } - auto minorPos = device.find(".", ++majorPos); + auto minorPos = device.find('.', ++majorPos); auto minor = parseProductConfigFromString(device, majorPos, minorPos); if (minor == ConfigStatus::MismatchedValue || minorPos == std::string::npos) { diff --git a/shared/source/os_interface/linux/drm_neo.cpp b/shared/source/os_interface/linux/drm_neo.cpp index 7e0dccd5445af..53d3b699c008a 100644 --- a/shared/source/os_interface/linux/drm_neo.cpp +++ b/shared/source/os_interface/linux/drm_neo.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2024 Intel Corporation + * Copyright (C) 2018-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -659,15 +659,17 @@ std::vector> Drm::discoverDevices(ExecutionEnvironme do { const char *renderDeviceSuffix = "-render"; + constexpr size_t renderDevSufSize = std::char_traits::length(renderDeviceSuffix); + constexpr size_t pciDevDirLen = std::char_traits::length(Os::pciDevicesDirectory); for (std::vector::iterator file = files.begin(); file != files.end(); ++file) { std::string_view devicePathView(file->c_str(), file->size()); - devicePathView = devicePathView.substr(strlen(Os::pciDevicesDirectory)); + devicePathView = devicePathView.substr(pciDevDirLen); auto rdsPos = devicePathView.rfind(renderDeviceSuffix); if (rdsPos == std::string::npos) { continue; } - if (rdsPos < devicePathView.size() - strlen(renderDeviceSuffix)) { + if (rdsPos < devicePathView.size() - renderDevSufSize) { continue; } // at least 'pci-0000:00:00.0' -> 16 @@ -1091,9 +1093,12 @@ bool Drm::completionFenceSupport() { void Drm::setupIoctlHelper(const PRODUCT_FAMILY productFamily) { if (!this->ioctlHelper) { + auto drmVersion = Drm::getDrmVersion(getFileDescriptor()); auto productSpecificIoctlHelperCreator = ioctlHelperFactory[productFamily]; if (productSpecificIoctlHelperCreator && !debugManager.flags.IgnoreProductSpecificIoctlHelper.get()) { this->ioctlHelper = productSpecificIoctlHelperCreator.value()(*this); + } else if ("xe" == drmVersion) { + this->ioctlHelper = IoctlHelperXe::create(*this); } else { std::string prelimVersion = ""; getPrelimVersion(prelimVersion); @@ -1726,10 +1731,8 @@ bool Drm::isDrmSupported(int fileDescriptor) { bool Drm::queryDeviceIdAndRevision() { auto drmVersion = Drm::getDrmVersion(getFileDescriptor()); if ("xe" == drmVersion) { - this->ioctlHelper = IoctlHelperXe::create(*this); - auto xeIoctlHelperPtr = static_cast(this->ioctlHelper.get()); this->setPerContextVMRequired(false); - return xeIoctlHelperPtr->initialize(); + return IoctlHelperXe::queryDeviceIdAndRevision(*this); } return IoctlHelperI915::queryDeviceIdAndRevision(*this); } diff --git a/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp b/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp index 95d3453202d35..2841fdc4fc014 100644 --- a/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp +++ b/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp @@ -161,10 +161,6 @@ bool IoctlHelperXe::initialize() { euDebugInterface = EuDebugInterface::create(drm.getSysFsPciPath()); - if (!IoctlHelperXe::queryDeviceIdAndRevision(this->drm)) { - return false; - } - drm_xe_device_query queryConfig = {}; queryConfig.query = DRM_XE_DEVICE_QUERY_CONFIG; diff --git a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_dg1.cpp b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_dg1.cpp index e6738e88a8c12..21a354671a884 100644 --- a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_dg1.cpp +++ b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_dg1.cpp @@ -20,6 +20,10 @@ using namespace NEO; using IoctlHelperTestsDg1 = ::testing::Test; +DG1TEST_F(IoctlHelperTestsDg1, givenDg1WhenSetupIoctlHelperThenDg1SpecificHelperIsAvailable) { + EXPECT_TRUE(ioctlHelperFactory[IGFX_DG1].has_value()); +} + DG1TEST_F(IoctlHelperTestsDg1, givenDg1WhenCreateGemExtThenReturnCorrectValue) { auto executionEnvironment = std::make_unique(); auto drm = std::make_unique(*executionEnvironment->rootDeviceEnvironments[0]); diff --git a/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp index af9f93b04f6cc..69cc8084f2b88 100644 --- a/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp @@ -1959,13 +1959,10 @@ TEST_F(IoctlHelperXeTest, whenInitializeThenProperHwInfoIsSet) { auto hwInfo = executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo(); - hwInfo->platform.usDeviceID = defaultHwInfo->platform.usDeviceID + 1; - hwInfo->platform.usRevId = defaultHwInfo->platform.usRevId + 1; hwInfo->capabilityTable.gpuAddressSpace = 0; ioctlHelper->initialize(); - EXPECT_EQ(defaultHwInfo->platform.usRevId, hwInfo->platform.usRevId); - EXPECT_EQ(defaultHwInfo->platform.usDeviceID, hwInfo->platform.usDeviceID); + EXPECT_EQ((1ull << 48) - 1, hwInfo->capabilityTable.gpuAddressSpace); EXPECT_EQ(static_cast(DrmMockXe::mockDefaultCxlType), hwInfo->capabilityTable.cxlType);