From f8f7b8eccafcbf02cb5e16b55b4df43e275e4813 Mon Sep 17 00:00:00 2001 From: "Chen, Sheng S" Date: Mon, 26 May 2025 01:47:17 -0700 Subject: [PATCH 01/16] [SYCLomatic] Emit the verified component version. Signed-off-by: Chen, Sheng S --- clang/include/clang/DPCT/DPCTOptions.inc | 8 ++ clang/lib/DPCT/AnalysisInfo.cpp | 1 + clang/lib/DPCT/AnalysisInfo.h | 1 + clang/lib/DPCT/CMakeLists.txt | 1 + .../ComponentVersion/ComponentVersion.cpp | 86 +++++++++++++++++++ .../DPCT/ComponentVersion/ComponentVersion.h | 36 ++++++++ clang/lib/DPCT/DPCT.cpp | 15 ++++ clang/tools/dpct/extensions/CMakeLists.txt | 10 +++ .../verified_component/component_version.yaml | 16 ++++ 9 files changed, 174 insertions(+) create mode 100644 clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp create mode 100644 clang/lib/DPCT/ComponentVersion/ComponentVersion.h create mode 100644 clang/tools/dpct/extensions/verified_component/component_version.yaml diff --git a/clang/include/clang/DPCT/DPCTOptions.inc b/clang/include/clang/DPCT/DPCTOptions.inc index afa05039ad58..e0d93ab0ad71 100644 --- a/clang/include/clang/DPCT/DPCTOptions.inc +++ b/clang/include/clang/DPCT/DPCTOptions.inc @@ -554,6 +554,14 @@ DPCT_FLAG_OPTION( "_codepin_sycl, where is specified by --out-root option."), llvm::cl::cat(CtHelpCatAll)) +DPCT_FLAG_OPTION( + VerifiedComp, clang::dpct::DpctOptionClass::OC_Attribute, + DPCT_OPTION_ACTIONS(clang::dpct::DpctActionKind::DAK_Migration), + "verified-component", + llvm::cl::desc( + "Print the dependency for building and runnning the migrated code.\n"), + llvm::cl::cat(CtHelpCatAll)) + DPCT_FLAG_OPTION( EnableCTAD, clang::dpct::DpctOptionClass::OC_Attribute, DPCT_OPTION_ACTIONS(clang::dpct::DpctActionKind::DAK_Migration, diff --git a/clang/lib/DPCT/AnalysisInfo.cpp b/clang/lib/DPCT/AnalysisInfo.cpp index 065f2117e28c..8ca58cdae99e 100644 --- a/clang/lib/DPCT/AnalysisInfo.cpp +++ b/clang/lib/DPCT/AnalysisInfo.cpp @@ -2428,6 +2428,7 @@ format::FormatRange DpctGlobalInfo::FmtRng = format::FormatRange::none; DPCTFormatStyle DpctGlobalInfo::FmtST = DPCTFormatStyle::FS_LLVM; bool DpctGlobalInfo::EnableCtad = false; bool DpctGlobalInfo::EnableCodePin = false; +bool DpctGlobalInfo::VerifiedComp = false; bool DpctGlobalInfo::IsMLKHeaderUsed = false; bool DpctGlobalInfo::GenBuildScript = false; bool DpctGlobalInfo::MigrateBuildScriptOnly = false; diff --git a/clang/lib/DPCT/AnalysisInfo.h b/clang/lib/DPCT/AnalysisInfo.h index 4eedfb910a25..f21872f28f9b 100644 --- a/clang/lib/DPCT/AnalysisInfo.h +++ b/clang/lib/DPCT/AnalysisInfo.h @@ -1594,6 +1594,7 @@ class DpctGlobalInfo { static DPCTFormatStyle FmtST; static bool EnableCtad; static bool EnableCodePin; + static bool VerifiedComp; static bool IsMLKHeaderUsed; static bool GenBuildScript; static bool MigrateBuildScriptOnly; diff --git a/clang/lib/DPCT/CMakeLists.txt b/clang/lib/DPCT/CMakeLists.txt index 7576567119d2..75da92d73386 100644 --- a/clang/lib/DPCT/CMakeLists.txt +++ b/clang/lib/DPCT/CMakeLists.txt @@ -233,6 +233,7 @@ add_clang_library(DPCT MigrateScript/GenMakefile.cpp RulesInclude/InclusionHeaders.cpp IncMigration/IncrementalMigrationUtility.cpp + ComponentVersion/ComponentVersion.cpp UserDefinedRules/UserDefinedRules.cpp UserDefinedRules/PatternRewriter.cpp MigrateScript/MigrateBuildScript.cpp diff --git a/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp b/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp new file mode 100644 index 000000000000..4a7150ddc561 --- /dev/null +++ b/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp @@ -0,0 +1,86 @@ + +#include "ComponentVersion.h" +#include +#include + +using namespace llvm; + + +template <> +struct llvm::yaml::SequenceTraits> { + static size_t size(IO &io, std::vector &seq) { + return seq.size(); + } + + static clang::dpct::CmpStats & + element(IO &io, std::vector &seq, size_t index) { + if (index >= seq.size()) + seq.resize(index + 1); + return seq[index]; + } +}; + +template <> +struct llvm::yaml::MappingTraits> { + static void mapping(IO &io, std::shared_ptr &Stats) { + Stats = std::make_shared(); + io.mapRequired("Feature", Stats->Feature); + io.mapRequired("TestComponent", Stats->TestComponent); + io.mapRequired("SupportedVersion", Stats->SupportedVersion); + io.mapOptional("IsOpenSource", Stats->IsOpenSource); + io.mapRequired("IsInNextOneAPIVersion", Stats->IsInNextOneAPIVersion); + io.mapOptional("Link", Stats->Link); + io.mapOptional("Description", Stats->Description); + } +}; + +template +struct llvm::yaml::SequenceTraits>> { + static size_t size(llvm::yaml::IO &Io, std::vector> &Seq) { + return Seq.size(); + } + static std::shared_ptr &element(IO &, std::vector> &Seq, + size_t Index) { + if (Index >= Seq.size()) + Seq.resize(Index + 1); + return Seq[Index]; + } +}; +namespace clang { +namespace dpct { +void importStatus(std::vector &RuleFiles) { + auto file = llvm::MemoryBuffer::getFile(RuleFiles[0].getCanonicalPath()); + if (!file) { + llvm::errs() << "Error: failed to read " << RuleFiles[0].getCanonicalPath() + << ": " << file.getError().message() << "\n"; + return; + } + + std::vector> features; + yaml::Input yin(file.get()->getBuffer()); + yin >> features; + std::stringstream ss; + + for (auto &feature : features) { + ss << "The feature " << feature->Feature << " is supported in the " + << feature->SupportedVersion << " daily build. "; + if (feature->IsOpenSource) { + ss << "This feature is open-source. "; + } + if (!feature->Link.empty()) { + ss << "For more details, please refer to the provided link: " + << feature->Link << ". "; + } + if (feature->IsInNextOneAPIVersion) { + ss << "This feature will be included in the next oneAPI version. "; + } + if (!feature->Description.empty()) { + + ss << "Description: " << feature->Description << ".\n"; + } + } + std::cout << ss.str() << "\n"; +} + +} // namespace dpct +} // namespace clang \ No newline at end of file diff --git a/clang/lib/DPCT/ComponentVersion/ComponentVersion.h b/clang/lib/DPCT/ComponentVersion/ComponentVersion.h new file mode 100644 index 000000000000..ce437ad5a5c7 --- /dev/null +++ b/clang/lib/DPCT/ComponentVersion/ComponentVersion.h @@ -0,0 +1,36 @@ +//===--------------- ComponentVersion.h ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef DPCT_COMPONENT_VERSION +#define DPCT_COMPONENT_VERSION +#include "clang/Tooling/Tooling.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/YAMLTraits.h" +#include +#include + +namespace clang { +namespace dpct { + +class CmpStats { +public: + std::string Feature; + std::string SupportedVersion; + std::string TestComponent; + bool IsOpenSource; + bool IsInNextOneAPIVersion; + std::string Link; + std::string Description; +}; + +void importStatus(std::vector &RuleFiles); + +} // namespace dpct +} // namespace clang + +#endif // DPCT_COMPONENT_VERSION \ No newline at end of file diff --git a/clang/lib/DPCT/DPCT.cpp b/clang/lib/DPCT/DPCT.cpp index 85ce5abc7f91..3bfdc7155b2b 100644 --- a/clang/lib/DPCT/DPCT.cpp +++ b/clang/lib/DPCT/DPCT.cpp @@ -11,6 +11,7 @@ #include "AnalysisInfo.h" #include "CommandOption/ValidateArguments.h" #include "Config.h" +#include "ComponentVersion/ComponentVersion.h" #include "ErrorHandle/CrashRecovery.h" #include "ErrorHandle/Error.h" #include "FileGenerator/GenFiles.h" @@ -975,7 +976,21 @@ int runDPCT(int argc, const char **argv) { showReportHeader(); ExtraIncPaths = OptParser->getExtraIncPathList(); + if (VerifiedComp) { + SmallString<128> FilePath1(DpctInstallPath.getCanonicalPath()); + llvm::sys::path::append(FilePath1, + Twine("extensions/verified_component/component_version.yaml")); + SmallString<128> FilePath2(DpctInstallPath.getCanonicalPath()); + llvm::sys::path::append(FilePath2, + Twine("opt/dpct/extensions/verified_component/component_version.yaml")); + std::vector SupportedComponents{ + llvm::sys::fs::exists(FilePath1) ? FilePath1.c_str() + : FilePath2.c_str()}; + std::cout << SupportedComponents[0].getPath().str() << "\n"; + importStatus(SupportedComponents); + return 0; + } if (isCUDAHeaderRequired()) { // TODO: implement one of this for each source language. CudaPath = getCudaInstallPath(OriginalArgc, argv); diff --git a/clang/tools/dpct/extensions/CMakeLists.txt b/clang/tools/dpct/extensions/CMakeLists.txt index c8570c5043be..174176ba8d0a 100644 --- a/clang/tools/dpct/extensions/CMakeLists.txt +++ b/clang/tools/dpct/extensions/CMakeLists.txt @@ -19,6 +19,10 @@ set(dpct_pytorch_api_rule_files ${CMAKE_SOURCE_DIR}/../clang/tools/dpct/extensions/pytorch_api_rules/pytorch_api.yaml ) +set(dpct_verified_component_files + ${CMAKE_SOURCE_DIR}/../clang/tools/dpct/extensions/verified_component/component_version.yaml +) + set(dpct_rule_template_files ${CMAKE_SOURCE_DIR}/../clang/tools/dpct/extensions/rule_templates/api_rule.yaml ${CMAKE_SOURCE_DIR}/../clang/tools/dpct/extensions/rule_templates/class_rule.yaml @@ -55,6 +59,12 @@ install( PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ DESTINATION ./extensions/pytorch_api_rules) +install( + FILES ${dpct_verified_component_files} + COMPONENT dpct-rules + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + DESTINATION ./extensions/verified_component) + install( FILES ${dpct_rule_template_files} COMPONENT dpct-rules diff --git a/clang/tools/dpct/extensions/verified_component/component_version.yaml b/clang/tools/dpct/extensions/verified_component/component_version.yaml new file mode 100644 index 000000000000..af8cbadfa8da --- /dev/null +++ b/clang/tools/dpct/extensions/verified_component/component_version.yaml @@ -0,0 +1,16 @@ +--- +- Feature: Free Function query for SYCL + SupportedVersion: 20250526 + Link: https:github.com/oneapi-src/oneAPI-sycl/issues/444sss + TestComponent: Compiler + IsOpenSource: true + IsInNextOneAPIVersion: true + Description: Free Function query for SYCL is supported. and user can use it to query the kernel info in the kernel function directly + +- Feature: Free Function query for SYCL222 + SupportedVersion: 2025052x + TestComponent: MKL Library + Link: https:github.com/oneapi-src/oneAPI-sycl/issues/444sss + IsOpenSource: false + IsInNextOneAPIVersion: true + Description: Free Function query for SYCL is supported. and user can use it to query the kernel info in the kernel function directly \ No newline at end of file From 11baaf39d788e9046e55305368da42f2a6bb2043 Mon Sep 17 00:00:00 2001 From: "Chen, Sheng S" Date: Tue, 27 May 2025 01:50:32 -0700 Subject: [PATCH 02/16] up Signed-off-by: Chen, Sheng S --- clang/lib/DPCT/AnalysisInfo.cpp | 1 + clang/lib/DPCT/AnalysisInfo.h | 10 ++++ .../ComponentVersion/ComponentVersion.cpp | 57 +++++++++---------- .../DPCT/ComponentVersion/ComponentVersion.h | 6 +- clang/lib/DPCT/FileGenerator/GenFiles.cpp | 17 ++++++ 5 files changed, 58 insertions(+), 33 deletions(-) diff --git a/clang/lib/DPCT/AnalysisInfo.cpp b/clang/lib/DPCT/AnalysisInfo.cpp index 8ca58cdae99e..3729c4827330 100644 --- a/clang/lib/DPCT/AnalysisInfo.cpp +++ b/clang/lib/DPCT/AnalysisInfo.cpp @@ -2410,6 +2410,7 @@ std::shared_ptr clang::tooling::UnifiedPath DpctGlobalInfo::InRoot; clang::tooling::UnifiedPath DpctGlobalInfo::OutRoot; std::vector DpctGlobalInfo::AnalysisScope; +std::vector> DpctGlobalInfo::VerifiedCmpStats; std::unordered_set DpctGlobalInfo::ChangeExtensions = {}; std::string DpctGlobalInfo::SYCLSourceExtension = std::string(); std::string DpctGlobalInfo::SYCLHeaderExtension = std::string(); diff --git a/clang/lib/DPCT/AnalysisInfo.h b/clang/lib/DPCT/AnalysisInfo.h index f21872f28f9b..0cd3fcd69190 100644 --- a/clang/lib/DPCT/AnalysisInfo.h +++ b/clang/lib/DPCT/AnalysisInfo.h @@ -19,6 +19,7 @@ #include "TextModification.h" #include "Utility.h" #include "CommandOption/ValidateArguments.h" +#include "ComponentVersion/ComponentVersion.h" #include #include #include @@ -736,6 +737,14 @@ class DpctGlobalInfo { static const std::vector &getAnalysisScope() { return AnalysisScope; } + + static void + setVerifiedCmpStats(const std::vector> &CmpStats) { + VerifiedCmpStats = CmpStats; + } + static const std::vector> &getVerifiedCmpStats() { + return VerifiedCmpStats; + } static void addChangeExtensions(const std::string &Extension) { assert(!Extension.empty()); ChangeExtensions.insert(Extension); @@ -1576,6 +1585,7 @@ class DpctGlobalInfo { static clang::tooling::UnifiedPath InRoot; static clang::tooling::UnifiedPath OutRoot; static std::vector AnalysisScope; + static std::vector> VerifiedCmpStats; static std::unordered_set ChangeExtensions; static std::string SYCLSourceExtension; static std::string SYCLHeaderExtension; diff --git a/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp b/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp index 4a7150ddc561..4caef521a94d 100644 --- a/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp +++ b/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp @@ -1,11 +1,11 @@ #include "ComponentVersion.h" +#include "AnalysisInfo.h" #include #include using namespace llvm; - template <> struct llvm::yaml::SequenceTraits> { static size_t size(IO &io, std::vector &seq) { @@ -25,6 +25,7 @@ struct llvm::yaml::MappingTraits> { static void mapping(IO &io, std::shared_ptr &Stats) { Stats = std::make_shared(); io.mapRequired("Feature", Stats->Feature); + io.mapRequired("ReplacementText", Stats->ReplacementText); io.mapRequired("TestComponent", Stats->TestComponent); io.mapRequired("SupportedVersion", Stats->SupportedVersion); io.mapOptional("IsOpenSource", Stats->IsOpenSource); @@ -34,20 +35,30 @@ struct llvm::yaml::MappingTraits> { } }; -template -struct llvm::yaml::SequenceTraits>> { - static size_t size(llvm::yaml::IO &Io, std::vector> &Seq) { - return Seq.size(); - } - static std::shared_ptr &element(IO &, std::vector> &Seq, - size_t Index) { - if (Index >= Seq.size()) - Seq.resize(Index + 1); - return Seq[Index]; - } -}; + namespace clang { namespace dpct { + +void emitCmpStatsWarning(std::shared_ptr Stats, + std::stringstream &ss) { + ss << "The feature " << Stats->Feature << " is supported in the " + << Stats->SupportedVersion << " daily build. "; + if (Stats->IsOpenSource) { + ss << "This feature is open-source. "; + } + if (!Stats->Link.empty()) { + ss << "For more details, please refer to the provided link: " << Stats->Link + << ". "; + } + if (Stats->IsInNextOneAPIVersion) { + ss << "This feature will be included in the next oneAPI version. "; + } + if (!Stats->Description.empty()) { + ss << "Description: " << Stats->Description << "."; + } + ss << "\n"; +} + void importStatus(std::vector &RuleFiles) { auto file = llvm::MemoryBuffer::getFile(RuleFiles[0].getCanonicalPath()); if (!file) { @@ -60,26 +71,10 @@ void importStatus(std::vector &RuleFiles) { yaml::Input yin(file.get()->getBuffer()); yin >> features; std::stringstream ss; - + DpctGlobalInfo::setVerifiedCmpStats(features); for (auto &feature : features) { - ss << "The feature " << feature->Feature << " is supported in the " - << feature->SupportedVersion << " daily build. "; - if (feature->IsOpenSource) { - ss << "This feature is open-source. "; - } - if (!feature->Link.empty()) { - ss << "For more details, please refer to the provided link: " - << feature->Link << ". "; - } - if (feature->IsInNextOneAPIVersion) { - ss << "This feature will be included in the next oneAPI version. "; - } - if (!feature->Description.empty()) { - - ss << "Description: " << feature->Description << ".\n"; - } + emitCmpStatsWarning(feature, ss); } - std::cout << ss.str() << "\n"; } } // namespace dpct diff --git a/clang/lib/DPCT/ComponentVersion/ComponentVersion.h b/clang/lib/DPCT/ComponentVersion/ComponentVersion.h index ce437ad5a5c7..610336d67820 100644 --- a/clang/lib/DPCT/ComponentVersion/ComponentVersion.h +++ b/clang/lib/DPCT/ComponentVersion/ComponentVersion.h @@ -17,10 +17,10 @@ namespace clang { namespace dpct { -class CmpStats { -public: +struct CmpStats { std::string Feature; std::string SupportedVersion; + std::string ReplacementText; std::string TestComponent; bool IsOpenSource; bool IsInNextOneAPIVersion; @@ -30,6 +30,8 @@ class CmpStats { void importStatus(std::vector &RuleFiles); +void emitCmpStatsWarning(std::shared_ptr Stats, + std::stringstream &StrStream); } // namespace dpct } // namespace clang diff --git a/clang/lib/DPCT/FileGenerator/GenFiles.cpp b/clang/lib/DPCT/FileGenerator/GenFiles.cpp index a2d95abc735b..caca9866cdd4 100644 --- a/clang/lib/DPCT/FileGenerator/GenFiles.cpp +++ b/clang/lib/DPCT/FileGenerator/GenFiles.cpp @@ -607,6 +607,7 @@ int writeReplacementsToFiles( MainSrcFileMap[Entry.first] = true; for (const auto &Repl : Entry.second) { + Repl.getReplacementText(); MainSrcFilesRepls.push_back(Repl); } } @@ -911,6 +912,21 @@ void genCodePinHeader(dpct::RawFDOStream &RS, bool IsForCUDADebug) { RS << "#endif" << getNL(); } +void genVerifiedCmpVer(const std::vector &CmpVerRepls) { + auto CmpStatsList = dpct::DpctGlobalInfo::getVerifiedCmpStats(); + for (auto CmpStats : CmpStatsList) { + for (auto Repl : CmpVerRepls) { + if (Repl.getReplacementText().str().find(CmpStats->ReplacementText) != + std::string::npos) { + // If the replacement text is already in the list, skip it. + std::stringstream ss; + emitCmpStatsWarning(CmpStats, ss); + PrintMsg(ss.str()); + return; + } + } + } +} /// Apply all generated replacements, and immediately save the results to files /// in output directory. /// @@ -996,6 +1012,7 @@ int saveNewFiles(clang::tooling::RefactoringTool &Tool, clang::dpct::RT_CUDAWithCodePin)) return RewriteStatus; } + genVerifiedCmpVer(MainSrcFilesRepls); // Print the in-root path and the number of processed files size_t ProcessedFileNumber; if (ProcessAll) { From 10c83e2c901cc870b14bd484111e08e7024dae73 Mon Sep 17 00:00:00 2001 From: "Chen, Sheng S" Date: Wed, 28 May 2025 00:49:44 -0700 Subject: [PATCH 03/16] up --- clang/include/clang/DPCT/DPCTOptions.inc | 8 +- clang/lib/DPCT/AnalysisInfo.cpp | 4 +- clang/lib/DPCT/AnalysisInfo.h | 12 +- .../ComponentVersion/ComponentVersion.cpp | 128 +++++++++++++----- .../DPCT/ComponentVersion/ComponentVersion.h | 14 +- clang/lib/DPCT/DPCT.cpp | 6 +- clang/lib/DPCT/FileGenerator/GenFiles.cpp | 8 +- clang/tools/dpct/extensions/CMakeLists.txt | 8 +- .../component_version.yaml | 2 + 9 files changed, 131 insertions(+), 59 deletions(-) rename clang/tools/dpct/extensions/{verified_component => supported_components}/component_version.yaml (79%) diff --git a/clang/include/clang/DPCT/DPCTOptions.inc b/clang/include/clang/DPCT/DPCTOptions.inc index e0d93ab0ad71..34dc19c3ab76 100644 --- a/clang/include/clang/DPCT/DPCTOptions.inc +++ b/clang/include/clang/DPCT/DPCTOptions.inc @@ -555,11 +555,11 @@ DPCT_FLAG_OPTION( llvm::cl::cat(CtHelpCatAll)) DPCT_FLAG_OPTION( - VerifiedComp, clang::dpct::DpctOptionClass::OC_Attribute, + SupportedComps, clang::dpct::DpctOptionClass::OC_Attribute, DPCT_OPTION_ACTIONS(clang::dpct::DpctActionKind::DAK_Migration), - "verified-component", - llvm::cl::desc( - "Print the dependency for building and runnning the migrated code.\n"), + "supported-components", + llvm::cl::desc("Show the supported components and their compatibility " + "version information.\n"), llvm::cl::cat(CtHelpCatAll)) DPCT_FLAG_OPTION( diff --git a/clang/lib/DPCT/AnalysisInfo.cpp b/clang/lib/DPCT/AnalysisInfo.cpp index 3729c4827330..2a60e59efae8 100644 --- a/clang/lib/DPCT/AnalysisInfo.cpp +++ b/clang/lib/DPCT/AnalysisInfo.cpp @@ -2410,7 +2410,7 @@ std::shared_ptr clang::tooling::UnifiedPath DpctGlobalInfo::InRoot; clang::tooling::UnifiedPath DpctGlobalInfo::OutRoot; std::vector DpctGlobalInfo::AnalysisScope; -std::vector> DpctGlobalInfo::VerifiedCmpStats; +std::vector> DpctGlobalInfo::SupportedCompsStatus; std::unordered_set DpctGlobalInfo::ChangeExtensions = {}; std::string DpctGlobalInfo::SYCLSourceExtension = std::string(); std::string DpctGlobalInfo::SYCLHeaderExtension = std::string(); @@ -2429,7 +2429,7 @@ format::FormatRange DpctGlobalInfo::FmtRng = format::FormatRange::none; DPCTFormatStyle DpctGlobalInfo::FmtST = DPCTFormatStyle::FS_LLVM; bool DpctGlobalInfo::EnableCtad = false; bool DpctGlobalInfo::EnableCodePin = false; -bool DpctGlobalInfo::VerifiedComp = false; +bool DpctGlobalInfo::SupportedComps = false; bool DpctGlobalInfo::IsMLKHeaderUsed = false; bool DpctGlobalInfo::GenBuildScript = false; bool DpctGlobalInfo::MigrateBuildScriptOnly = false; diff --git a/clang/lib/DPCT/AnalysisInfo.h b/clang/lib/DPCT/AnalysisInfo.h index 0cd3fcd69190..5a58bfb3daa0 100644 --- a/clang/lib/DPCT/AnalysisInfo.h +++ b/clang/lib/DPCT/AnalysisInfo.h @@ -739,11 +739,11 @@ class DpctGlobalInfo { } static void - setVerifiedCmpStats(const std::vector> &CmpStats) { - VerifiedCmpStats = CmpStats; + setSupportedCompsStatus(const std::vector> &CompStatus) { + SupportedCompsStatus = CompStatus; } - static const std::vector> &getVerifiedCmpStats() { - return VerifiedCmpStats; + static const std::vector> &getSupportedCompsStatus() { + return SupportedCompsStatus; } static void addChangeExtensions(const std::string &Extension) { assert(!Extension.empty()); @@ -1585,7 +1585,7 @@ class DpctGlobalInfo { static clang::tooling::UnifiedPath InRoot; static clang::tooling::UnifiedPath OutRoot; static std::vector AnalysisScope; - static std::vector> VerifiedCmpStats; + static std::vector> SupportedCompsStatus; static std::unordered_set ChangeExtensions; static std::string SYCLSourceExtension; static std::string SYCLHeaderExtension; @@ -1604,7 +1604,7 @@ class DpctGlobalInfo { static DPCTFormatStyle FmtST; static bool EnableCtad; static bool EnableCodePin; - static bool VerifiedComp; + static bool SupportedComps; static bool IsMLKHeaderUsed; static bool GenBuildScript; static bool MigrateBuildScriptOnly; diff --git a/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp b/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp index 4caef521a94d..466354509fa9 100644 --- a/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp +++ b/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp @@ -6,14 +6,15 @@ using namespace llvm; + template <> -struct llvm::yaml::SequenceTraits> { - static size_t size(IO &io, std::vector &seq) { +struct llvm::yaml::SequenceTraits> { + static size_t size(IO &io, std::vector &seq) { return seq.size(); } - static clang::dpct::CmpStats & - element(IO &io, std::vector &seq, size_t index) { + static clang::dpct::CompStatus & + element(IO &io, std::vector &seq, size_t index) { if (index >= seq.size()) seq.resize(index + 1); return seq[index]; @@ -21,40 +22,79 @@ struct llvm::yaml::SequenceTraits> { }; template <> -struct llvm::yaml::MappingTraits> { - static void mapping(IO &io, std::shared_ptr &Stats) { - Stats = std::make_shared(); - io.mapRequired("Feature", Stats->Feature); - io.mapRequired("ReplacementText", Stats->ReplacementText); - io.mapRequired("TestComponent", Stats->TestComponent); - io.mapRequired("SupportedVersion", Stats->SupportedVersion); - io.mapOptional("IsOpenSource", Stats->IsOpenSource); - io.mapRequired("IsInNextOneAPIVersion", Stats->IsInNextOneAPIVersion); - io.mapOptional("Link", Stats->Link); - io.mapOptional("Description", Stats->Description); +struct llvm::yaml::MappingTraits> { + static void mapping(IO &io, std::shared_ptr &Status) { + Status = std::make_shared(); + io.mapRequired("Feature", Status->Feature); + io.mapRequired("ReplacementText", Status->ReplacementText); + io.mapRequired("ComponentType", Status->CompType); + io.mapRequired("SupportedVersion", Status->SupportedVersion); + io.mapOptional("IsOpenSource", Status->IsOpenSource); + io.mapRequired("IsInNextOneAPIVersion", Status->IsInNextOneAPIVersion); + io.mapOptional("Link", Status->Link); + io.mapOptional("Description", Status->Description); + } +}; +template <> struct llvm::yaml::ScalarEnumerationTraits { + static void enumeration(llvm::yaml::IO &Io, ComponentType &Value) { + Io.enumCase(Value, "Compiler", ComponentType::DPCPP); + Io.enumCase(Value, "DPC++", ComponentType::DPCPP); + Io.enumCase(Value, "DPCPP", ComponentType::DPCPP); + Io.enumCase(Value, "oneDPL", ComponentType::oneDPL); + Io.enumCase(Value, "oneMKL", ComponentType::oneMKL); + Io.enumCase(Value, "oneCCL", ComponentType::oneCCL); + Io.enumCase(Value, "oneDNNL", ComponentType::oneDNNL); + Io.enumCase(Value, "ISHMEM", ComponentType::ISHMEM); } }; - - namespace clang { namespace dpct { -void emitCmpStatsWarning(std::shared_ptr Stats, - std::stringstream &ss) { - ss << "The feature " << Stats->Feature << " is supported in the " - << Stats->SupportedVersion << " daily build. "; - if (Stats->IsOpenSource) { +const std::string oneAPIVersion = "2025.1"; +class ComponentInfo { +public: + ComponentInfo(const std::string &Name, + const std::string &Version = "oneAPI " + oneAPIVersion) + : ComponentName(Name), ComponentVersion(Version) {} + + std::string ComponentName; + std::string ComponentVersion; +}; + +void DisplayComponentInfo(const ComponentInfo &Info) { + std::cout << " - " << Info.ComponentName << ": " << Info.ComponentVersion << ".\n"; +} +void SupportedComponents() { + std::vector Components = { + {"DPC++/C++"}, + {"oneDPL"}, + {"oneMKL"}, + {"oneDNNL"}, + {"oneCCL"}, + {"ISHMEM"}}; + + std::cout << "Supported components:\n"; + for (const auto &Component : Components) { + DisplayComponentInfo(Component); + } +} + + void emitCompStatusWarning(std::shared_ptr Status, + std::stringstream &ss) { + ss << "The feature " << Status->Feature << " is supported in the " + << Status->SupportedVersion << " daily build. "; + if (Status->IsOpenSource) { ss << "This feature is open-source. "; } - if (!Stats->Link.empty()) { - ss << "For more details, please refer to the provided link: " << Stats->Link + if (!Status->Link.empty()) { + ss << "For more details, please refer to the provided link: " << Status->Link << ". "; } - if (Stats->IsInNextOneAPIVersion) { + if (Status->IsInNextOneAPIVersion) { ss << "This feature will be included in the next oneAPI version. "; } - if (!Stats->Description.empty()) { - ss << "Description: " << Stats->Description << "."; + if (!Status->Description.empty()) { + ss << "Description: " << Status->Description << "."; } ss << "\n"; } @@ -66,14 +106,36 @@ void importStatus(std::vector &RuleFiles) { << ": " << file.getError().message() << "\n"; return; } - - std::vector> features; + std::vector> NewCompsStatus; yaml::Input yin(file.get()->getBuffer()); - yin >> features; + yin >> NewCompsStatus; std::stringstream ss; - DpctGlobalInfo::setVerifiedCmpStats(features); - for (auto &feature : features) { - emitCmpStatsWarning(feature, ss); + DpctGlobalInfo::setSupportedCompsStatus(NewCompsStatus); + SupportedComponents(); + if (NewCompsStatus.empty()) { + return; + } + for (auto &CompStatus : NewCompsStatus) { + // if () + switch (CompStatus->CompType) { + case ComponentType::DPCPP: + ss << "DPC++/C++: "; + break; + case ComponentType::oneDPL: + ss << "oneDPL: "; + break; + case ComponentType::oneMKL: + ss << "oneMKL: "; + break; + case ComponentType::oneCCL: + ss << "oneCCL: "; + break; + case ComponentType::oneDNNL: + ss << "oneDNNL: "; + break; + case ComponentType::ISHMEM: + ss << "ISHMEM: "; + break; } } diff --git a/clang/lib/DPCT/ComponentVersion/ComponentVersion.h b/clang/lib/DPCT/ComponentVersion/ComponentVersion.h index 610336d67820..7ecda5fc30c1 100644 --- a/clang/lib/DPCT/ComponentVersion/ComponentVersion.h +++ b/clang/lib/DPCT/ComponentVersion/ComponentVersion.h @@ -16,12 +16,20 @@ namespace clang { namespace dpct { +enum ComponentType { + DPCPP, + oneDPL, + oneMKL, + oneCCL, + oneDNNL, + ISHMEM +}; -struct CmpStats { +struct CompStatus { std::string Feature; std::string SupportedVersion; std::string ReplacementText; - std::string TestComponent; + ComponentType CompType; bool IsOpenSource; bool IsInNextOneAPIVersion; std::string Link; @@ -30,7 +38,7 @@ struct CmpStats { void importStatus(std::vector &RuleFiles); -void emitCmpStatsWarning(std::shared_ptr Stats, +void emitCompStatusWarning(std::shared_ptr Stats, std::stringstream &StrStream); } // namespace dpct } // namespace clang diff --git a/clang/lib/DPCT/DPCT.cpp b/clang/lib/DPCT/DPCT.cpp index 3bfdc7155b2b..b5dfb8ecb6e7 100644 --- a/clang/lib/DPCT/DPCT.cpp +++ b/clang/lib/DPCT/DPCT.cpp @@ -976,13 +976,13 @@ int runDPCT(int argc, const char **argv) { showReportHeader(); ExtraIncPaths = OptParser->getExtraIncPathList(); - if (VerifiedComp) { + if (SupportedComps) { SmallString<128> FilePath1(DpctInstallPath.getCanonicalPath()); llvm::sys::path::append(FilePath1, - Twine("extensions/verified_component/component_version.yaml")); + Twine("extensions/supported_components/component_version.yaml")); SmallString<128> FilePath2(DpctInstallPath.getCanonicalPath()); llvm::sys::path::append(FilePath2, - Twine("opt/dpct/extensions/verified_component/component_version.yaml")); + Twine("opt/dpct/extensions/supported_components/component_version.yaml")); std::vector SupportedComponents{ llvm::sys::fs::exists(FilePath1) ? FilePath1.c_str() diff --git a/clang/lib/DPCT/FileGenerator/GenFiles.cpp b/clang/lib/DPCT/FileGenerator/GenFiles.cpp index caca9866cdd4..e15607850fd7 100644 --- a/clang/lib/DPCT/FileGenerator/GenFiles.cpp +++ b/clang/lib/DPCT/FileGenerator/GenFiles.cpp @@ -913,14 +913,14 @@ void genCodePinHeader(dpct::RawFDOStream &RS, bool IsForCUDADebug) { } void genVerifiedCmpVer(const std::vector &CmpVerRepls) { - auto CmpStatsList = dpct::DpctGlobalInfo::getVerifiedCmpStats(); - for (auto CmpStats : CmpStatsList) { + auto CompStatusList = dpct::DpctGlobalInfo::getSupportedCompsStatus(); + for (auto CompStatus : CompStatusList) { for (auto Repl : CmpVerRepls) { - if (Repl.getReplacementText().str().find(CmpStats->ReplacementText) != + if (Repl.getReplacementText().str().find(CompStatus->ReplacementText) != std::string::npos) { // If the replacement text is already in the list, skip it. std::stringstream ss; - emitCmpStatsWarning(CmpStats, ss); + emitCompStatusWarning(CompStatus, ss); PrintMsg(ss.str()); return; } diff --git a/clang/tools/dpct/extensions/CMakeLists.txt b/clang/tools/dpct/extensions/CMakeLists.txt index 174176ba8d0a..581a793d9315 100644 --- a/clang/tools/dpct/extensions/CMakeLists.txt +++ b/clang/tools/dpct/extensions/CMakeLists.txt @@ -19,8 +19,8 @@ set(dpct_pytorch_api_rule_files ${CMAKE_SOURCE_DIR}/../clang/tools/dpct/extensions/pytorch_api_rules/pytorch_api.yaml ) -set(dpct_verified_component_files - ${CMAKE_SOURCE_DIR}/../clang/tools/dpct/extensions/verified_component/component_version.yaml +set(dpct_supported_components_files + ${CMAKE_SOURCE_DIR}/../clang/tools/dpct/extensions/supported_components/component_version.yaml ) set(dpct_rule_template_files @@ -60,10 +60,10 @@ install( DESTINATION ./extensions/pytorch_api_rules) install( - FILES ${dpct_verified_component_files} + FILES ${dpct_supported_components_files} COMPONENT dpct-rules PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ - DESTINATION ./extensions/verified_component) + DESTINATION ./extensions/supported_components) install( FILES ${dpct_rule_template_files} diff --git a/clang/tools/dpct/extensions/verified_component/component_version.yaml b/clang/tools/dpct/extensions/supported_components/component_version.yaml similarity index 79% rename from clang/tools/dpct/extensions/verified_component/component_version.yaml rename to clang/tools/dpct/extensions/supported_components/component_version.yaml index af8cbadfa8da..f4dd77fdbec2 100644 --- a/clang/tools/dpct/extensions/verified_component/component_version.yaml +++ b/clang/tools/dpct/extensions/supported_components/component_version.yaml @@ -3,6 +3,7 @@ SupportedVersion: 20250526 Link: https:github.com/oneapi-src/oneAPI-sycl/issues/444sss TestComponent: Compiler + ReplacementText: "sycl::get_kernel_info(kernel)" IsOpenSource: true IsInNextOneAPIVersion: true Description: Free Function query for SYCL is supported. and user can use it to query the kernel info in the kernel function directly @@ -11,6 +12,7 @@ SupportedVersion: 2025052x TestComponent: MKL Library Link: https:github.com/oneapi-src/oneAPI-sycl/issues/444sss + ReplacementText: "sycl::get_kernel_info(kernel)" IsOpenSource: false IsInNextOneAPIVersion: true Description: Free Function query for SYCL is supported. and user can use it to query the kernel info in the kernel function directly \ No newline at end of file From 721ae1bdf09cea1ff8de0c1a34a74484f7813c75 Mon Sep 17 00:00:00 2001 From: "Chen, Sheng S" Date: Thu, 29 May 2025 00:02:09 -0700 Subject: [PATCH 04/16] update Signed-off-by: Chen, Sheng S --- clang/lib/DPCT/AnalysisInfo.cpp | 1 + clang/lib/DPCT/AnalysisInfo.h | 9 +- .../ComponentVersion/ComponentVersion.cpp | 105 +++++++++--------- .../DPCT/ComponentVersion/ComponentVersion.h | 28 +++-- clang/lib/DPCT/FileGenerator/GenFiles.cpp | 4 + .../component_version.yaml | 4 +- 6 files changed, 86 insertions(+), 65 deletions(-) diff --git a/clang/lib/DPCT/AnalysisInfo.cpp b/clang/lib/DPCT/AnalysisInfo.cpp index 2a60e59efae8..8f8123eb866b 100644 --- a/clang/lib/DPCT/AnalysisInfo.cpp +++ b/clang/lib/DPCT/AnalysisInfo.cpp @@ -2411,6 +2411,7 @@ clang::tooling::UnifiedPath DpctGlobalInfo::InRoot; clang::tooling::UnifiedPath DpctGlobalInfo::OutRoot; std::vector DpctGlobalInfo::AnalysisScope; std::vector> DpctGlobalInfo::SupportedCompsStatus; +std::unordered_map DpctGlobalInfo::SupportedCompsInfo; std::unordered_set DpctGlobalInfo::ChangeExtensions = {}; std::string DpctGlobalInfo::SYCLSourceExtension = std::string(); std::string DpctGlobalInfo::SYCLHeaderExtension = std::string(); diff --git a/clang/lib/DPCT/AnalysisInfo.h b/clang/lib/DPCT/AnalysisInfo.h index 5a58bfb3daa0..e46de9fb64ef 100644 --- a/clang/lib/DPCT/AnalysisInfo.h +++ b/clang/lib/DPCT/AnalysisInfo.h @@ -737,7 +737,6 @@ class DpctGlobalInfo { static const std::vector &getAnalysisScope() { return AnalysisScope; } - static void setSupportedCompsStatus(const std::vector> &CompStatus) { SupportedCompsStatus = CompStatus; @@ -745,6 +744,13 @@ class DpctGlobalInfo { static const std::vector> &getSupportedCompsStatus() { return SupportedCompsStatus; } + static void + setSupportedComponentInfo(std::unordered_map &CompsInfo) { + SupportedCompsInfo = CompsInfo; + } + static const std::unordered_map &getSupportedComponentInfo() { + return SupportedCompsInfo; + } static void addChangeExtensions(const std::string &Extension) { assert(!Extension.empty()); ChangeExtensions.insert(Extension); @@ -1586,6 +1592,7 @@ class DpctGlobalInfo { static clang::tooling::UnifiedPath OutRoot; static std::vector AnalysisScope; static std::vector> SupportedCompsStatus; + static std::unordered_map SupportedCompsInfo; static std::unordered_set ChangeExtensions; static std::string SYCLSourceExtension; static std::string SYCLHeaderExtension; diff --git a/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp b/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp index 466354509fa9..01ccad5b502f 100644 --- a/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp +++ b/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp @@ -6,7 +6,6 @@ using namespace llvm; - template <> struct llvm::yaml::SequenceTraits> { static size_t size(IO &io, std::vector &seq) { @@ -23,7 +22,8 @@ struct llvm::yaml::SequenceTraits> { template <> struct llvm::yaml::MappingTraits> { - static void mapping(IO &io, std::shared_ptr &Status) { + static void mapping(IO &io, + std::shared_ptr &Status) { Status = std::make_shared(); io.mapRequired("Feature", Status->Feature); io.mapRequired("ReplacementText", Status->ReplacementText); @@ -32,7 +32,7 @@ struct llvm::yaml::MappingTraits> { io.mapOptional("IsOpenSource", Status->IsOpenSource); io.mapRequired("IsInNextOneAPIVersion", Status->IsInNextOneAPIVersion); io.mapOptional("Link", Status->Link); - io.mapOptional("Description", Status->Description); + io.mapOptional("Description", Status->Link); } }; template <> struct llvm::yaml::ScalarEnumerationTraits { @@ -47,31 +47,16 @@ template <> struct llvm::yaml::ScalarEnumerationTraits { Io.enumCase(Value, "ISHMEM", ComponentType::ISHMEM); } }; + namespace clang { namespace dpct { - -const std::string oneAPIVersion = "2025.1"; -class ComponentInfo { -public: - ComponentInfo(const std::string &Name, - const std::string &Version = "oneAPI " + oneAPIVersion) - : ComponentName(Name), ComponentVersion(Version) {} - - std::string ComponentName; - std::string ComponentVersion; -}; - void DisplayComponentInfo(const ComponentInfo &Info) { - std::cout << " - " << Info.ComponentName << ": " << Info.ComponentVersion << ".\n"; + std::cout << " - " << Info.ComponentName << ": " << Info.ComponentVersion + << ".\n"; } void SupportedComponents() { - std::vector Components = { - {"DPC++/C++"}, - {"oneDPL"}, - {"oneMKL"}, - {"oneDNNL"}, - {"oneCCL"}, - {"ISHMEM"}}; + std::vector Components = {{"DPCPP"}, {"oneDPL"}, {"oneMKL"}, + {"oneDNNL"}, {"oneCCL"}, {"ISHMEM"}}; std::cout << "Supported components:\n"; for (const auto &Component : Components) { @@ -79,24 +64,49 @@ void SupportedComponents() { } } - void emitCompStatusWarning(std::shared_ptr Status, - std::stringstream &ss) { +void emitCompStatusWarning(std::shared_ptr Status, + std::stringstream &ss) { ss << "The feature " << Status->Feature << " is supported in the " << Status->SupportedVersion << " daily build. "; if (Status->IsOpenSource) { ss << "This feature is open-source. "; } if (!Status->Link.empty()) { - ss << "For more details, please refer to the provided link: " << Status->Link - << ". "; + ss << "For more details, please refer to the provided link: " + << Status->Link << ". "; } - if (Status->IsInNextOneAPIVersion) { - ss << "This feature will be included in the next oneAPI version. "; + + ss << "\n"; +} + +void printWarning(std::stringstream &ss, + const std::shared_ptr &Status, + std::string &ComponentType) { + ss << ComponentType; + if (Status->IsOpenSource) { + ss << Status->SupportedVersion << "\n"; + } else { } - if (!Status->Description.empty()) { - ss << "Description: " << Status->Description << "."; +} + +void collectNewVerInfo(ComponentInfo &Info, + const std::shared_ptr &Status) { + std::string Description = ""; + Description += "The feature " + Status->Feature; + if (Status->IsOpenSource) { + Description += " is supported in the " + Status->SupportedVersion + ". "; + Info.ComponentVersion = Status->SupportedVersion; + } else { + if (Status->IsInNextOneAPIVersion) { + Description += " is supported in the next oneAPI version. "; + } } - ss << "\n"; + if (!Status->Link.empty()) { + Description += + "For more details, please refer to the provided link: " + Status->Link + + ". \n"; + } + Info.ComponentDes.push_back(Description); } void importStatus(std::vector &RuleFiles) { @@ -115,27 +125,18 @@ void importStatus(std::vector &RuleFiles) { if (NewCompsStatus.empty()) { return; } + + std::unordered_map Components = { + {ComponentType::DPCPP, ComponentInfo("DPCPP")}, + {ComponentType::oneDPL, ComponentInfo("oneDPL")}, + {ComponentType::oneMKL, ComponentInfo("oneMKL")}, + {ComponentType::oneDNNL, ComponentInfo("oneDNNL")}, + {ComponentType::oneCCL, ComponentInfo("oneCCL")}, + {ComponentType::ISHMEM, ComponentInfo("ISHMEM")}}; + DpctGlobalInfo::setSupportedComponentInfo(Components); + for (auto &CompStatus : NewCompsStatus) { - // if () - switch (CompStatus->CompType) { - case ComponentType::DPCPP: - ss << "DPC++/C++: "; - break; - case ComponentType::oneDPL: - ss << "oneDPL: "; - break; - case ComponentType::oneMKL: - ss << "oneMKL: "; - break; - case ComponentType::oneCCL: - ss << "oneCCL: "; - break; - case ComponentType::oneDNNL: - ss << "oneDNNL: "; - break; - case ComponentType::ISHMEM: - ss << "ISHMEM: "; - break; + collectNewVerInfo(Components[CompStatus->CompType], CompStatus); } } diff --git a/clang/lib/DPCT/ComponentVersion/ComponentVersion.h b/clang/lib/DPCT/ComponentVersion/ComponentVersion.h index 7ecda5fc30c1..ca4c90624366 100644 --- a/clang/lib/DPCT/ComponentVersion/ComponentVersion.h +++ b/clang/lib/DPCT/ComponentVersion/ComponentVersion.h @@ -1,4 +1,5 @@ -//===--------------- ComponentVersion.h ----------------------------------------------===// +//===--------------- ComponentVersion.h +//----------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -16,14 +17,7 @@ namespace clang { namespace dpct { -enum ComponentType { - DPCPP, - oneDPL, - oneMKL, - oneCCL, - oneDNNL, - ISHMEM -}; +enum ComponentType { DPCPP, oneDPL, oneMKL, oneCCL, oneDNNL, ISHMEM }; struct CompStatus { std::string Feature; @@ -36,10 +30,24 @@ struct CompStatus { std::string Description; }; +const std::string CuroneAPIVersion = "2025.1"; +class ComponentInfo { +public: + ComponentInfo(const std::string &Name, + const std::string &Version = "oneAPI " + CuroneAPIVersion) + : ComponentName(Name), ComponentVersion(Version) {} + ComponentInfo() : ComponentName(""), ComponentVersion("oneAPI " + CuroneAPIVersion) {} + std::string ComponentName; + std::string ComponentVersion; + std::vector ComponentDes; +}; + void importStatus(std::vector &RuleFiles); void emitCompStatusWarning(std::shared_ptr Stats, - std::stringstream &StrStream); + std::stringstream &StrStream); +void collectNewVerInfo(ComponentInfo &Info, + const std::shared_ptr &Status); } // namespace dpct } // namespace clang diff --git a/clang/lib/DPCT/FileGenerator/GenFiles.cpp b/clang/lib/DPCT/FileGenerator/GenFiles.cpp index e15607850fd7..0e71b2b2d45a 100644 --- a/clang/lib/DPCT/FileGenerator/GenFiles.cpp +++ b/clang/lib/DPCT/FileGenerator/GenFiles.cpp @@ -914,6 +914,7 @@ void genCodePinHeader(dpct::RawFDOStream &RS, bool IsForCUDADebug) { void genVerifiedCmpVer(const std::vector &CmpVerRepls) { auto CompStatusList = dpct::DpctGlobalInfo::getSupportedCompsStatus(); + auto CompsInfo = dpct::DpctGlobalInfo::getSupportedComponentInfo(); for (auto CompStatus : CompStatusList) { for (auto Repl : CmpVerRepls) { if (Repl.getReplacementText().str().find(CompStatus->ReplacementText) != @@ -921,6 +922,9 @@ void genVerifiedCmpVer(const std::vector &CmpVerRep // If the replacement text is already in the list, skip it. std::stringstream ss; emitCompStatusWarning(CompStatus, ss); + + collectNewVerInfo( + CompsInfo[CompStatus->CompType], CompStatus); PrintMsg(ss.str()); return; } diff --git a/clang/tools/dpct/extensions/supported_components/component_version.yaml b/clang/tools/dpct/extensions/supported_components/component_version.yaml index f4dd77fdbec2..9f741906542d 100644 --- a/clang/tools/dpct/extensions/supported_components/component_version.yaml +++ b/clang/tools/dpct/extensions/supported_components/component_version.yaml @@ -1,8 +1,8 @@ --- - Feature: Free Function query for SYCL SupportedVersion: 20250526 + ComponentType: Compiler Link: https:github.com/oneapi-src/oneAPI-sycl/issues/444sss - TestComponent: Compiler ReplacementText: "sycl::get_kernel_info(kernel)" IsOpenSource: true IsInNextOneAPIVersion: true @@ -10,7 +10,7 @@ - Feature: Free Function query for SYCL222 SupportedVersion: 2025052x - TestComponent: MKL Library + ComponentType: Compiler Link: https:github.com/oneapi-src/oneAPI-sycl/issues/444sss ReplacementText: "sycl::get_kernel_info(kernel)" IsOpenSource: false From 293b7c29378e8aab8ce9d51e48fe2f6193930a9a Mon Sep 17 00:00:00 2001 From: Shengchenj Date: Fri, 30 May 2025 00:11:41 -0700 Subject: [PATCH 05/16] up Signed-off-by: Shengchenj --- .../ComponentVersion/ComponentVersion.cpp | 37 ++++++++----------- .../DPCT/ComponentVersion/ComponentVersion.h | 3 +- clang/lib/DPCT/FileGenerator/GenFiles.cpp | 1 - 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp b/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp index 01ccad5b502f..2b6fea9837ce 100644 --- a/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp +++ b/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp @@ -32,7 +32,7 @@ struct llvm::yaml::MappingTraits> { io.mapOptional("IsOpenSource", Status->IsOpenSource); io.mapRequired("IsInNextOneAPIVersion", Status->IsInNextOneAPIVersion); io.mapOptional("Link", Status->Link); - io.mapOptional("Description", Status->Link); + io.mapOptional("Description", Status->Description); } }; template <> struct llvm::yaml::ScalarEnumerationTraits { @@ -54,31 +54,24 @@ void DisplayComponentInfo(const ComponentInfo &Info) { std::cout << " - " << Info.ComponentName << ": " << Info.ComponentVersion << ".\n"; } -void SupportedComponents() { - std::vector Components = {{"DPCPP"}, {"oneDPL"}, {"oneMKL"}, - {"oneDNNL"}, {"oneCCL"}, {"ISHMEM"}}; +void SupportedComponents(const std::unordered_map &Components) { std::cout << "Supported components:\n"; + std::stringstream ss; for (const auto &Component : Components) { - DisplayComponentInfo(Component); - } -} - -void emitCompStatusWarning(std::shared_ptr Status, - std::stringstream &ss) { - ss << "The feature " << Status->Feature << " is supported in the " - << Status->SupportedVersion << " daily build. "; - if (Status->IsOpenSource) { - ss << "This feature is open-source. "; + DisplayComponentInfo(Component.second); + for (const auto& Des : Component.second.ComponentDes) { + ss << " - " << Des << "\n"; + } } - if (!Status->Link.empty()) { - ss << "For more details, please refer to the provided link: " - << Status->Link << ". "; + if (!ss.str().empty()) { + std::cout << "\nDetails:\n"; + std::cout << ss.str(); } - ss << "\n"; } + void printWarning(std::stringstream &ss, const std::shared_ptr &Status, std::string &ComponentType) { @@ -94,8 +87,8 @@ void collectNewVerInfo(ComponentInfo &Info, std::string Description = ""; Description += "The feature " + Status->Feature; if (Status->IsOpenSource) { - Description += " is supported in the " + Status->SupportedVersion + ". "; - Info.ComponentVersion = Status->SupportedVersion; + Description += " is supported in " + Info.ComponentName + " " + Status->SupportedVersion + ". "; + Info.ComponentVersion = Status->SupportedVersion + " (open source). "; } else { if (Status->IsInNextOneAPIVersion) { Description += " is supported in the next oneAPI version. "; @@ -106,6 +99,7 @@ void collectNewVerInfo(ComponentInfo &Info, "For more details, please refer to the provided link: " + Status->Link + ". \n"; } + // std::cout < &RuleFiles) { yin >> NewCompsStatus; std::stringstream ss; DpctGlobalInfo::setSupportedCompsStatus(NewCompsStatus); - SupportedComponents(); if (NewCompsStatus.empty()) { return; } @@ -138,6 +131,8 @@ void importStatus(std::vector &RuleFiles) { for (auto &CompStatus : NewCompsStatus) { collectNewVerInfo(Components[CompStatus->CompType], CompStatus); } + SupportedComponents(Components); + } } // namespace dpct diff --git a/clang/lib/DPCT/ComponentVersion/ComponentVersion.h b/clang/lib/DPCT/ComponentVersion/ComponentVersion.h index ca4c90624366..774c3680b05a 100644 --- a/clang/lib/DPCT/ComponentVersion/ComponentVersion.h +++ b/clang/lib/DPCT/ComponentVersion/ComponentVersion.h @@ -44,8 +44,7 @@ class ComponentInfo { void importStatus(std::vector &RuleFiles); -void emitCompStatusWarning(std::shared_ptr Stats, - std::stringstream &StrStream); + void collectNewVerInfo(ComponentInfo &Info, const std::shared_ptr &Status); } // namespace dpct diff --git a/clang/lib/DPCT/FileGenerator/GenFiles.cpp b/clang/lib/DPCT/FileGenerator/GenFiles.cpp index 0e71b2b2d45a..563ffaee5037 100644 --- a/clang/lib/DPCT/FileGenerator/GenFiles.cpp +++ b/clang/lib/DPCT/FileGenerator/GenFiles.cpp @@ -921,7 +921,6 @@ void genVerifiedCmpVer(const std::vector &CmpVerRep std::string::npos) { // If the replacement text is already in the list, skip it. std::stringstream ss; - emitCompStatusWarning(CompStatus, ss); collectNewVerInfo( CompsInfo[CompStatus->CompType], CompStatus); From 08dc6dc480e03e2f9bd0da2556d662bfde8d7c93 Mon Sep 17 00:00:00 2001 From: Shengchenj Date: Tue, 3 Jun 2025 01:59:36 -0700 Subject: [PATCH 06/16] up Signed-off-by: Shengchenj --- .../ComponentVersion/ComponentVersion.cpp | 68 +++++++++++-------- .../DPCT/ComponentVersion/ComponentVersion.h | 2 +- clang/lib/DPCT/DPCT.cpp | 7 +- clang/lib/DPCT/FileGenerator/GenFiles.cpp | 11 ++- .../component_version.yaml | 2 +- 5 files changed, 49 insertions(+), 41 deletions(-) diff --git a/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp b/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp index 2b6fea9837ce..12f65f1a0185 100644 --- a/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp +++ b/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp @@ -50,36 +50,37 @@ template <> struct llvm::yaml::ScalarEnumerationTraits { namespace clang { namespace dpct { -void DisplayComponentInfo(const ComponentInfo &Info) { - std::cout << " - " << Info.ComponentName << ": " << Info.ComponentVersion - << ".\n"; + +void DisplayOverallComponentInfo( + const std::unordered_map + &SupportedComponentInfo) { + std::stringstream ComponentOverallLog; + ComponentOverallLog << "Supported components:\n"; + for (const auto &Component : SupportedComponentInfo) { + ComponentOverallLog << " - " << Component.second.ComponentName << ": " + << Component.second.ComponentVersion << ".\n"; + } + std::cout << ComponentOverallLog.str(); } -void SupportedComponents(const std::unordered_map &Components) { - std::cout << "Supported components:\n"; - std::stringstream ss; - for (const auto &Component : Components) { - DisplayComponentInfo(Component.second); - for (const auto& Des : Component.second.ComponentDes) { - ss << " - " << Des << "\n"; +void DisplayComponentDetailsInfo( + const std::unordered_map + &SupportedComponentInfo) { + std::stringstream ComponentDetailLog; + ComponentDetailLog << "\nSupport Component details:\n"; + for (const auto &Component : SupportedComponentInfo) { + for (const auto &Des : Component.second.ComponentDes) { + ComponentDetailLog << " - " << Des << "\n"; } } - if (!ss.str().empty()) { - std::cout << "\nDetails:\n"; - std::cout << ss.str(); - } - + std::cout << ComponentDetailLog.str() << "\n"; } - -void printWarning(std::stringstream &ss, - const std::shared_ptr &Status, - std::string &ComponentType) { - ss << ComponentType; - if (Status->IsOpenSource) { - ss << Status->SupportedVersion << "\n"; - } else { - } +void showSupportedComponents(bool isPrintOverall) { + auto SupportedComponentInfo = DpctGlobalInfo::getSupportedComponentInfo(); + if (isPrintOverall) + DisplayOverallComponentInfo(SupportedComponentInfo); + DisplayComponentDetailsInfo(SupportedComponentInfo); } void collectNewVerInfo(ComponentInfo &Info, @@ -87,8 +88,18 @@ void collectNewVerInfo(ComponentInfo &Info, std::string Description = ""; Description += "The feature " + Status->Feature; if (Status->IsOpenSource) { - Description += " is supported in " + Info.ComponentName + " " + Status->SupportedVersion + ". "; - Info.ComponentVersion = Status->SupportedVersion + " (open source). "; + Description += " is supported in " + Info.ComponentName + " open source " + + Status->SupportedVersion + ". "; + if (!Info.ComponentVersion.empty()) { + if (Info.ComponentVersion.find("oneAPI") == std::string::npos) { + long orgDate = stoi(Info.ComponentVersion); + long newDate = stoi(Status->SupportedVersion); + if (orgDate < newDate) + Info.ComponentVersion = Status->SupportedVersion; + } else { + Info.ComponentVersion = Status->SupportedVersion; + } + } } else { if (Status->IsInNextOneAPIVersion) { Description += " is supported in the next oneAPI version. "; @@ -99,7 +110,6 @@ void collectNewVerInfo(ComponentInfo &Info, "For more details, please refer to the provided link: " + Status->Link + ". \n"; } - // std::cout < &RuleFiles) { {ComponentType::oneDNNL, ComponentInfo("oneDNNL")}, {ComponentType::oneCCL, ComponentInfo("oneCCL")}, {ComponentType::ISHMEM, ComponentInfo("ISHMEM")}}; - DpctGlobalInfo::setSupportedComponentInfo(Components); for (auto &CompStatus : NewCompsStatus) { collectNewVerInfo(Components[CompStatus->CompType], CompStatus); } - SupportedComponents(Components); - + DpctGlobalInfo::setSupportedComponentInfo(Components); } } // namespace dpct diff --git a/clang/lib/DPCT/ComponentVersion/ComponentVersion.h b/clang/lib/DPCT/ComponentVersion/ComponentVersion.h index 774c3680b05a..d2a2808ff230 100644 --- a/clang/lib/DPCT/ComponentVersion/ComponentVersion.h +++ b/clang/lib/DPCT/ComponentVersion/ComponentVersion.h @@ -44,7 +44,7 @@ class ComponentInfo { void importStatus(std::vector &RuleFiles); - +void showSupportedComponents(bool isPrintOverall = false); void collectNewVerInfo(ComponentInfo &Info, const std::shared_ptr &Status); } // namespace dpct diff --git a/clang/lib/DPCT/DPCT.cpp b/clang/lib/DPCT/DPCT.cpp index b5dfb8ecb6e7..ff6e2c8e34f0 100644 --- a/clang/lib/DPCT/DPCT.cpp +++ b/clang/lib/DPCT/DPCT.cpp @@ -976,7 +976,8 @@ int runDPCT(int argc, const char **argv) { showReportHeader(); ExtraIncPaths = OptParser->getExtraIncPathList(); - if (SupportedComps) { + + { SmallString<128> FilePath1(DpctInstallPath.getCanonicalPath()); llvm::sys::path::append(FilePath1, Twine("extensions/supported_components/component_version.yaml")); @@ -987,8 +988,10 @@ int runDPCT(int argc, const char **argv) { std::vector SupportedComponents{ llvm::sys::fs::exists(FilePath1) ? FilePath1.c_str() : FilePath2.c_str()}; - std::cout << SupportedComponents[0].getPath().str() << "\n"; importStatus(SupportedComponents); + } + if (SupportedComps) { + showSupportedComponents(SupportedComps); return 0; } if (isCUDAHeaderRequired()) { diff --git a/clang/lib/DPCT/FileGenerator/GenFiles.cpp b/clang/lib/DPCT/FileGenerator/GenFiles.cpp index 563ffaee5037..e13a2127bebb 100644 --- a/clang/lib/DPCT/FileGenerator/GenFiles.cpp +++ b/clang/lib/DPCT/FileGenerator/GenFiles.cpp @@ -912,7 +912,8 @@ void genCodePinHeader(dpct::RawFDOStream &RS, bool IsForCUDADebug) { RS << "#endif" << getNL(); } -void genVerifiedCmpVer(const std::vector &CmpVerRepls) { +void genVerifiedCmpVer( + const std::vector &CmpVerRepls) { auto CompStatusList = dpct::DpctGlobalInfo::getSupportedCompsStatus(); auto CompsInfo = dpct::DpctGlobalInfo::getSupportedComponentInfo(); for (auto CompStatus : CompStatusList) { @@ -920,15 +921,11 @@ void genVerifiedCmpVer(const std::vector &CmpVerRep if (Repl.getReplacementText().str().find(CompStatus->ReplacementText) != std::string::npos) { // If the replacement text is already in the list, skip it. - std::stringstream ss; - - collectNewVerInfo( - CompsInfo[CompStatus->CompType], CompStatus); - PrintMsg(ss.str()); - return; + collectNewVerInfo(CompsInfo[CompStatus->CompType], CompStatus); } } } + showSupportedComponents(); } /// Apply all generated replacements, and immediately save the results to files /// in output directory. diff --git a/clang/tools/dpct/extensions/supported_components/component_version.yaml b/clang/tools/dpct/extensions/supported_components/component_version.yaml index 9f741906542d..cbfb8cf98424 100644 --- a/clang/tools/dpct/extensions/supported_components/component_version.yaml +++ b/clang/tools/dpct/extensions/supported_components/component_version.yaml @@ -3,7 +3,7 @@ SupportedVersion: 20250526 ComponentType: Compiler Link: https:github.com/oneapi-src/oneAPI-sycl/issues/444sss - ReplacementText: "sycl::get_kernel_info(kernel)" + ReplacementText: "this_work_item" IsOpenSource: true IsInNextOneAPIVersion: true Description: Free Function query for SYCL is supported. and user can use it to query the kernel info in the kernel function directly From 71ccd4de417378b113a12b636069b2be28e7023d Mon Sep 17 00:00:00 2001 From: Shengchenj Date: Wed, 4 Jun 2025 18:42:30 -0700 Subject: [PATCH 07/16] up Signed-off-by: Shengchenj --- clang/lib/DPCT/AnalysisInfo.cpp | 1 - clang/lib/DPCT/AnalysisInfo.h | 17 ++++--- .../ComponentVersion/ComponentVersion.cpp | 46 ++++++++----------- .../DPCT/ComponentVersion/ComponentVersion.h | 19 +++++--- clang/lib/DPCT/DPCT.cpp | 2 +- clang/lib/DPCT/FileGenerator/GenFiles.cpp | 9 ++-- 6 files changed, 48 insertions(+), 46 deletions(-) diff --git a/clang/lib/DPCT/AnalysisInfo.cpp b/clang/lib/DPCT/AnalysisInfo.cpp index 8f8123eb866b..2a60e59efae8 100644 --- a/clang/lib/DPCT/AnalysisInfo.cpp +++ b/clang/lib/DPCT/AnalysisInfo.cpp @@ -2411,7 +2411,6 @@ clang::tooling::UnifiedPath DpctGlobalInfo::InRoot; clang::tooling::UnifiedPath DpctGlobalInfo::OutRoot; std::vector DpctGlobalInfo::AnalysisScope; std::vector> DpctGlobalInfo::SupportedCompsStatus; -std::unordered_map DpctGlobalInfo::SupportedCompsInfo; std::unordered_set DpctGlobalInfo::ChangeExtensions = {}; std::string DpctGlobalInfo::SYCLSourceExtension = std::string(); std::string DpctGlobalInfo::SYCLHeaderExtension = std::string(); diff --git a/clang/lib/DPCT/AnalysisInfo.h b/clang/lib/DPCT/AnalysisInfo.h index e46de9fb64ef..f75506e14e39 100644 --- a/clang/lib/DPCT/AnalysisInfo.h +++ b/clang/lib/DPCT/AnalysisInfo.h @@ -744,12 +744,16 @@ class DpctGlobalInfo { static const std::vector> &getSupportedCompsStatus() { return SupportedCompsStatus; } - static void - setSupportedComponentInfo(std::unordered_map &CompsInfo) { - SupportedCompsInfo = CompsInfo; - } - static const std::unordered_map &getSupportedComponentInfo() { - return SupportedCompsInfo; +static const std::unordered_map & + getSupportedComponentInfo() { + static std::unordered_map Components = { + {ComponentType::DPCPP, ComponentInfo("DPCPP")}, + {ComponentType::oneDPL, ComponentInfo("oneDPL")}, + {ComponentType::oneMKL, ComponentInfo("oneMKL")}, + {ComponentType::oneDNNL, ComponentInfo("oneDNNL")}, + {ComponentType::oneCCL, ComponentInfo("oneCCL")}, + {ComponentType::ISHMEM, ComponentInfo("ISHMEM")}}; + return Components; } static void addChangeExtensions(const std::string &Extension) { assert(!Extension.empty()); @@ -1592,7 +1596,6 @@ class DpctGlobalInfo { static clang::tooling::UnifiedPath OutRoot; static std::vector AnalysisScope; static std::vector> SupportedCompsStatus; - static std::unordered_map SupportedCompsInfo; static std::unordered_set ChangeExtensions; static std::string SYCLSourceExtension; static std::string SYCLHeaderExtension; diff --git a/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp b/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp index 12f65f1a0185..a605bdf17439 100644 --- a/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp +++ b/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp @@ -68,6 +68,7 @@ void DisplayComponentDetailsInfo( &SupportedComponentInfo) { std::stringstream ComponentDetailLog; ComponentDetailLog << "\nSupport Component details:\n"; + std::cout << "Size " << SupportedComponentInfo.size() << "\n"; for (const auto &Component : SupportedComponentInfo) { for (const auto &Des : Component.second.ComponentDes) { ComponentDetailLog << " - " << Des << "\n"; @@ -77,14 +78,21 @@ void DisplayComponentDetailsInfo( } void showSupportedComponents(bool isPrintOverall) { - auto SupportedComponentInfo = DpctGlobalInfo::getSupportedComponentInfo(); - if (isPrintOverall) - DisplayOverallComponentInfo(SupportedComponentInfo); - DisplayComponentDetailsInfo(SupportedComponentInfo); + auto CompsStatus = DpctGlobalInfo::getSupportedCompsStatus(); + std::unordered_map Components = + dpct::DpctGlobalInfo::getSupportedComponentInfo(); + if (isPrintOverall) { + for (auto &CompStatus : CompsStatus) { + CollectNewVerInfo(Components[CompStatus->CompType], CompStatus); + } + DisplayOverallComponentInfo(Components); + } + DisplayComponentDetailsInfo(Components); } -void collectNewVerInfo(ComponentInfo &Info, +void CollectNewVerInfo(ComponentInfo &Info, const std::shared_ptr &Status) { + std::cout << "HHHHHH \n"; std::string Description = ""; Description += "The feature " + Status->Feature; if (Status->IsOpenSource) { @@ -110,37 +118,23 @@ void collectNewVerInfo(ComponentInfo &Info, "For more details, please refer to the provided link: " + Status->Link + ". \n"; } + std::cout << "Info name " << Info.ComponentName << "\n"; Info.ComponentDes.push_back(Description); } -void importStatus(std::vector &RuleFiles) { +void ParseSupportComponentStatus( + std::vector &RuleFiles, + bool IsPrintComponentOpt) { auto file = llvm::MemoryBuffer::getFile(RuleFiles[0].getCanonicalPath()); if (!file) { llvm::errs() << "Error: failed to read " << RuleFiles[0].getCanonicalPath() << ": " << file.getError().message() << "\n"; return; } - std::vector> NewCompsStatus; + std::vector> CompsStatus; yaml::Input yin(file.get()->getBuffer()); - yin >> NewCompsStatus; - std::stringstream ss; - DpctGlobalInfo::setSupportedCompsStatus(NewCompsStatus); - if (NewCompsStatus.empty()) { - return; - } - - std::unordered_map Components = { - {ComponentType::DPCPP, ComponentInfo("DPCPP")}, - {ComponentType::oneDPL, ComponentInfo("oneDPL")}, - {ComponentType::oneMKL, ComponentInfo("oneMKL")}, - {ComponentType::oneDNNL, ComponentInfo("oneDNNL")}, - {ComponentType::oneCCL, ComponentInfo("oneCCL")}, - {ComponentType::ISHMEM, ComponentInfo("ISHMEM")}}; - - for (auto &CompStatus : NewCompsStatus) { - collectNewVerInfo(Components[CompStatus->CompType], CompStatus); - } - DpctGlobalInfo::setSupportedComponentInfo(Components); + yin >> CompsStatus; + DpctGlobalInfo::setSupportedCompsStatus(CompsStatus); } } // namespace dpct diff --git a/clang/lib/DPCT/ComponentVersion/ComponentVersion.h b/clang/lib/DPCT/ComponentVersion/ComponentVersion.h index d2a2808ff230..52378d722427 100644 --- a/clang/lib/DPCT/ComponentVersion/ComponentVersion.h +++ b/clang/lib/DPCT/ComponentVersion/ComponentVersion.h @@ -30,24 +30,29 @@ struct CompStatus { std::string Description; }; -const std::string CuroneAPIVersion = "2025.1"; +const std::string OneAPIVersion = "2025.1"; class ComponentInfo { public: ComponentInfo(const std::string &Name, - const std::string &Version = "oneAPI " + CuroneAPIVersion) + const std::string &Version = "oneAPI " + OneAPIVersion) : ComponentName(Name), ComponentVersion(Version) {} - ComponentInfo() : ComponentName(""), ComponentVersion("oneAPI " + CuroneAPIVersion) {} + ComponentInfo() + : ComponentName(""), ComponentVersion("oneAPI " + OneAPIVersion) {} std::string ComponentName; std::string ComponentVersion; std::vector ComponentDes; }; -void importStatus(std::vector &RuleFiles); - +void ParseSupportComponentStatus( + std::vector &RuleFiles, + bool IsPrintComponentOpt = false); +void DisplayComponentDetailsInfo( + const std::unordered_map + &SupportedComponentInfo); void showSupportedComponents(bool isPrintOverall = false); -void collectNewVerInfo(ComponentInfo &Info, +void CollectNewVerInfo(ComponentInfo &Info, const std::shared_ptr &Status); } // namespace dpct } // namespace clang -#endif // DPCT_COMPONENT_VERSION \ No newline at end of file +#endif // DPCT_COMPONENT_VERSION diff --git a/clang/lib/DPCT/DPCT.cpp b/clang/lib/DPCT/DPCT.cpp index ff6e2c8e34f0..cce54644b6af 100644 --- a/clang/lib/DPCT/DPCT.cpp +++ b/clang/lib/DPCT/DPCT.cpp @@ -988,7 +988,7 @@ int runDPCT(int argc, const char **argv) { std::vector SupportedComponents{ llvm::sys::fs::exists(FilePath1) ? FilePath1.c_str() : FilePath2.c_str()}; - importStatus(SupportedComponents); + ParseSupportComponentStatus(SupportedComponents, SupportedComps); } if (SupportedComps) { showSupportedComponents(SupportedComps); diff --git a/clang/lib/DPCT/FileGenerator/GenFiles.cpp b/clang/lib/DPCT/FileGenerator/GenFiles.cpp index e13a2127bebb..5b7d414e3578 100644 --- a/clang/lib/DPCT/FileGenerator/GenFiles.cpp +++ b/clang/lib/DPCT/FileGenerator/GenFiles.cpp @@ -912,7 +912,7 @@ void genCodePinHeader(dpct::RawFDOStream &RS, bool IsForCUDADebug) { RS << "#endif" << getNL(); } -void genVerifiedCmpVer( +void GenVerifiedCmpVer( const std::vector &CmpVerRepls) { auto CompStatusList = dpct::DpctGlobalInfo::getSupportedCompsStatus(); auto CompsInfo = dpct::DpctGlobalInfo::getSupportedComponentInfo(); @@ -921,11 +921,12 @@ void genVerifiedCmpVer( if (Repl.getReplacementText().str().find(CompStatus->ReplacementText) != std::string::npos) { // If the replacement text is already in the list, skip it. - collectNewVerInfo(CompsInfo[CompStatus->CompType], CompStatus); + CollectNewVerInfo(CompsInfo[CompStatus->CompType], CompStatus); + break; } } } - showSupportedComponents(); + DisplayComponentDetailsInfo(CompsInfo); } /// Apply all generated replacements, and immediately save the results to files /// in output directory. @@ -1012,7 +1013,7 @@ int saveNewFiles(clang::tooling::RefactoringTool &Tool, clang::dpct::RT_CUDAWithCodePin)) return RewriteStatus; } - genVerifiedCmpVer(MainSrcFilesRepls); + GenVerifiedCmpVer(MainSrcFilesRepls); // Print the in-root path and the number of processed files size_t ProcessedFileNumber; if (ProcessAll) { From 147cdf667ae5efe0ee45448542e476a06c4b9359 Mon Sep 17 00:00:00 2001 From: Shengchenj Date: Wed, 4 Jun 2025 19:55:26 -0700 Subject: [PATCH 08/16] up Signed-off-by: Shengchenj --- clang/lib/DPCT/AnalysisInfo.cpp | 4 +- clang/lib/DPCT/AnalysisInfo.h | 12 ++--- .../ComponentVersion/ComponentVersion.cpp | 44 +++++++++---------- .../DPCT/ComponentVersion/ComponentVersion.h | 8 ++-- clang/lib/DPCT/DPCT.cpp | 6 +-- clang/lib/DPCT/FileGenerator/GenFiles.cpp | 6 +-- 6 files changed, 40 insertions(+), 40 deletions(-) diff --git a/clang/lib/DPCT/AnalysisInfo.cpp b/clang/lib/DPCT/AnalysisInfo.cpp index 2a60e59efae8..9bf400e26df6 100644 --- a/clang/lib/DPCT/AnalysisInfo.cpp +++ b/clang/lib/DPCT/AnalysisInfo.cpp @@ -2410,7 +2410,7 @@ std::shared_ptr clang::tooling::UnifiedPath DpctGlobalInfo::InRoot; clang::tooling::UnifiedPath DpctGlobalInfo::OutRoot; std::vector DpctGlobalInfo::AnalysisScope; -std::vector> DpctGlobalInfo::SupportedCompsStatus; +std::vector> DpctGlobalInfo::CompatibleCompsStatus; std::unordered_set DpctGlobalInfo::ChangeExtensions = {}; std::string DpctGlobalInfo::SYCLSourceExtension = std::string(); std::string DpctGlobalInfo::SYCLHeaderExtension = std::string(); @@ -2429,7 +2429,7 @@ format::FormatRange DpctGlobalInfo::FmtRng = format::FormatRange::none; DPCTFormatStyle DpctGlobalInfo::FmtST = DPCTFormatStyle::FS_LLVM; bool DpctGlobalInfo::EnableCtad = false; bool DpctGlobalInfo::EnableCodePin = false; -bool DpctGlobalInfo::SupportedComps = false; +bool DpctGlobalInfo::CompatibleComps = false; bool DpctGlobalInfo::IsMLKHeaderUsed = false; bool DpctGlobalInfo::GenBuildScript = false; bool DpctGlobalInfo::MigrateBuildScriptOnly = false; diff --git a/clang/lib/DPCT/AnalysisInfo.h b/clang/lib/DPCT/AnalysisInfo.h index f75506e14e39..c1b9fc79d24d 100644 --- a/clang/lib/DPCT/AnalysisInfo.h +++ b/clang/lib/DPCT/AnalysisInfo.h @@ -738,11 +738,11 @@ class DpctGlobalInfo { return AnalysisScope; } static void - setSupportedCompsStatus(const std::vector> &CompStatus) { - SupportedCompsStatus = CompStatus; + setCompatibleCompsStatus(const std::vector> &CompStatus) { + CompatibleCompsStatus = CompStatus; } - static const std::vector> &getSupportedCompsStatus() { - return SupportedCompsStatus; + static const std::vector> &getCompatibleCompsStatus() { + return CompatibleCompsStatus; } static const std::unordered_map & getSupportedComponentInfo() { @@ -1595,7 +1595,7 @@ static const std::unordered_map & static clang::tooling::UnifiedPath InRoot; static clang::tooling::UnifiedPath OutRoot; static std::vector AnalysisScope; - static std::vector> SupportedCompsStatus; + static std::vector> CompatibleCompsStatus; static std::unordered_set ChangeExtensions; static std::string SYCLSourceExtension; static std::string SYCLHeaderExtension; @@ -1614,7 +1614,7 @@ static const std::unordered_map & static DPCTFormatStyle FmtST; static bool EnableCtad; static bool EnableCodePin; - static bool SupportedComps; + static bool CompatibleComps; static bool IsMLKHeaderUsed; static bool GenBuildScript; static bool MigrateBuildScriptOnly; diff --git a/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp b/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp index a605bdf17439..71fcbc3c3ef2 100644 --- a/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp +++ b/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp @@ -51,11 +51,11 @@ template <> struct llvm::yaml::ScalarEnumerationTraits { namespace clang { namespace dpct { -void DisplayOverallComponentInfo( +void displayOverallComponentInfo( const std::unordered_map &SupportedComponentInfo) { std::stringstream ComponentOverallLog; - ComponentOverallLog << "Supported components:\n"; + ComponentOverallLog << "Comptatible components:\n"; for (const auto &Component : SupportedComponentInfo) { ComponentOverallLog << " - " << Component.second.ComponentName << ": " << Component.second.ComponentVersion << ".\n"; @@ -63,12 +63,11 @@ void DisplayOverallComponentInfo( std::cout << ComponentOverallLog.str(); } -void DisplayComponentDetailsInfo( +void displayComponentDetailsInfo( const std::unordered_map &SupportedComponentInfo) { std::stringstream ComponentDetailLog; - ComponentDetailLog << "\nSupport Component details:\n"; - std::cout << "Size " << SupportedComponentInfo.size() << "\n"; + ComponentDetailLog << "\nComptatible Component details:\n"; for (const auto &Component : SupportedComponentInfo) { for (const auto &Des : Component.second.ComponentDes) { ComponentDetailLog << " - " << Des << "\n"; @@ -77,22 +76,23 @@ void DisplayComponentDetailsInfo( std::cout << ComponentDetailLog.str() << "\n"; } -void showSupportedComponents(bool isPrintOverall) { - auto CompsStatus = DpctGlobalInfo::getSupportedCompsStatus(); +void displaySupportedComponents(bool isPrintOverall) { + auto CompsStatus = DpctGlobalInfo::getCompatibleCompsStatus(); std::unordered_map Components = dpct::DpctGlobalInfo::getSupportedComponentInfo(); if (isPrintOverall) { for (auto &CompStatus : CompsStatus) { - CollectNewVerInfo(Components[CompStatus->CompType], CompStatus); + updateComInfoBasedOnCompStatus(Components[CompStatus->CompType], + CompStatus); } - DisplayOverallComponentInfo(Components); + displayOverallComponentInfo(Components); } - DisplayComponentDetailsInfo(Components); + displayComponentDetailsInfo(Components); } -void CollectNewVerInfo(ComponentInfo &Info, - const std::shared_ptr &Status) { - std::cout << "HHHHHH \n"; +void updateComInfoBasedOnCompStatus( + ComponentInfo &Info, + const std::shared_ptr &Status) { std::string Description = ""; Description += "The feature " + Status->Feature; if (Status->IsOpenSource) { @@ -100,12 +100,13 @@ void CollectNewVerInfo(ComponentInfo &Info, Status->SupportedVersion + ". "; if (!Info.ComponentVersion.empty()) { if (Info.ComponentVersion.find("oneAPI") == std::string::npos) { - long orgDate = stoi(Info.ComponentVersion); - long newDate = stoi(Status->SupportedVersion); - if (orgDate < newDate) - Info.ComponentVersion = Status->SupportedVersion; + long OrgDate = + stoi(Info.ComponentVersion); // Version should be datestamp. + long NewDate = stoi(Status->SupportedVersion); + if (OrgDate < NewDate) + Info.ComponentVersion = ">=" + Status->SupportedVersion; } else { - Info.ComponentVersion = Status->SupportedVersion; + Info.ComponentVersion = ">=" + Status->SupportedVersion; } } } else { @@ -118,11 +119,10 @@ void CollectNewVerInfo(ComponentInfo &Info, "For more details, please refer to the provided link: " + Status->Link + ". \n"; } - std::cout << "Info name " << Info.ComponentName << "\n"; Info.ComponentDes.push_back(Description); } -void ParseSupportComponentStatus( +void parseSupportComponentStatus( std::vector &RuleFiles, bool IsPrintComponentOpt) { auto file = llvm::MemoryBuffer::getFile(RuleFiles[0].getCanonicalPath()); @@ -134,8 +134,8 @@ void ParseSupportComponentStatus( std::vector> CompsStatus; yaml::Input yin(file.get()->getBuffer()); yin >> CompsStatus; - DpctGlobalInfo::setSupportedCompsStatus(CompsStatus); + DpctGlobalInfo::setCompatibleCompsStatus(CompsStatus); } } // namespace dpct -} // namespace clang \ No newline at end of file +} // namespace clang diff --git a/clang/lib/DPCT/ComponentVersion/ComponentVersion.h b/clang/lib/DPCT/ComponentVersion/ComponentVersion.h index 52378d722427..e369c4fe88f8 100644 --- a/clang/lib/DPCT/ComponentVersion/ComponentVersion.h +++ b/clang/lib/DPCT/ComponentVersion/ComponentVersion.h @@ -43,14 +43,14 @@ class ComponentInfo { std::vector ComponentDes; }; -void ParseSupportComponentStatus( +void parseSupportComponentStatus( std::vector &RuleFiles, bool IsPrintComponentOpt = false); -void DisplayComponentDetailsInfo( +void displayComponentDetailsInfo( const std::unordered_map &SupportedComponentInfo); -void showSupportedComponents(bool isPrintOverall = false); -void CollectNewVerInfo(ComponentInfo &Info, +void displaySupportedComponents(bool isPrintOverall = false); +void updateComInfoBasedOnCompStatus(ComponentInfo &Info, const std::shared_ptr &Status); } // namespace dpct } // namespace clang diff --git a/clang/lib/DPCT/DPCT.cpp b/clang/lib/DPCT/DPCT.cpp index cce54644b6af..7003d0fcc2fa 100644 --- a/clang/lib/DPCT/DPCT.cpp +++ b/clang/lib/DPCT/DPCT.cpp @@ -988,10 +988,10 @@ int runDPCT(int argc, const char **argv) { std::vector SupportedComponents{ llvm::sys::fs::exists(FilePath1) ? FilePath1.c_str() : FilePath2.c_str()}; - ParseSupportComponentStatus(SupportedComponents, SupportedComps); + parseSupportComponentStatus(SupportedComponents, CompatibleComps); } - if (SupportedComps) { - showSupportedComponents(SupportedComps); + if (CompatibleComps) { + displaySupportedComponents(CompatibleComps); return 0; } if (isCUDAHeaderRequired()) { diff --git a/clang/lib/DPCT/FileGenerator/GenFiles.cpp b/clang/lib/DPCT/FileGenerator/GenFiles.cpp index 5b7d414e3578..ff9666203235 100644 --- a/clang/lib/DPCT/FileGenerator/GenFiles.cpp +++ b/clang/lib/DPCT/FileGenerator/GenFiles.cpp @@ -914,19 +914,19 @@ void genCodePinHeader(dpct::RawFDOStream &RS, bool IsForCUDADebug) { void GenVerifiedCmpVer( const std::vector &CmpVerRepls) { - auto CompStatusList = dpct::DpctGlobalInfo::getSupportedCompsStatus(); + auto CompStatusList = dpct::DpctGlobalInfo::getCompatibleCompsStatus(); auto CompsInfo = dpct::DpctGlobalInfo::getSupportedComponentInfo(); for (auto CompStatus : CompStatusList) { for (auto Repl : CmpVerRepls) { if (Repl.getReplacementText().str().find(CompStatus->ReplacementText) != std::string::npos) { // If the replacement text is already in the list, skip it. - CollectNewVerInfo(CompsInfo[CompStatus->CompType], CompStatus); + updateComInfoBasedOnCompStatus(CompsInfo[CompStatus->CompType], CompStatus); break; } } } - DisplayComponentDetailsInfo(CompsInfo); + displayComponentDetailsInfo(CompsInfo); } /// Apply all generated replacements, and immediately save the results to files /// in output directory. From 75b4d8c2090fbaa8bdbb1628284d79902ee5339e Mon Sep 17 00:00:00 2001 From: Shengchenj Date: Wed, 4 Jun 2025 22:28:52 -0700 Subject: [PATCH 09/16] up Signed-off-by: Shengchenj --- clang/include/clang/DPCT/DPCTOptions.inc | 2 +- .../ComponentVersion/ComponentVersion.cpp | 75 +++++++++++-------- clang/lib/DPCT/FileGenerator/GenFiles.cpp | 1 - .../component_version.yaml | 28 +++---- 4 files changed, 56 insertions(+), 50 deletions(-) diff --git a/clang/include/clang/DPCT/DPCTOptions.inc b/clang/include/clang/DPCT/DPCTOptions.inc index 34dc19c3ab76..93acb0315774 100644 --- a/clang/include/clang/DPCT/DPCTOptions.inc +++ b/clang/include/clang/DPCT/DPCTOptions.inc @@ -555,7 +555,7 @@ DPCT_FLAG_OPTION( llvm::cl::cat(CtHelpCatAll)) DPCT_FLAG_OPTION( - SupportedComps, clang::dpct::DpctOptionClass::OC_Attribute, + CompatibleComps, clang::dpct::DpctOptionClass::OC_Attribute, DPCT_OPTION_ACTIONS(clang::dpct::DpctActionKind::DAK_Migration), "supported-components", llvm::cl::desc("Show the supported components and their compatibility " diff --git a/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp b/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp index 71fcbc3c3ef2..03017cdb2c25 100644 --- a/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp +++ b/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp @@ -26,12 +26,12 @@ struct llvm::yaml::MappingTraits> { std::shared_ptr &Status) { Status = std::make_shared(); io.mapRequired("Feature", Status->Feature); - io.mapRequired("ReplacementText", Status->ReplacementText); - io.mapRequired("ComponentType", Status->CompType); io.mapRequired("SupportedVersion", Status->SupportedVersion); + io.mapRequired("ComponentType", Status->CompType); + io.mapOptional("Link", Status->Link); + io.mapRequired("ReplacementText", Status->ReplacementText); io.mapOptional("IsOpenSource", Status->IsOpenSource); io.mapRequired("IsInNextOneAPIVersion", Status->IsInNextOneAPIVersion); - io.mapOptional("Link", Status->Link); io.mapOptional("Description", Status->Description); } }; @@ -55,7 +55,7 @@ void displayOverallComponentInfo( const std::unordered_map &SupportedComponentInfo) { std::stringstream ComponentOverallLog; - ComponentOverallLog << "Comptatible components:\n"; + ComponentOverallLog << "Compatible components:\n"; for (const auto &Component : SupportedComponentInfo) { ComponentOverallLog << " - " << Component.second.ComponentName << ": " << Component.second.ComponentVersion << ".\n"; @@ -67,13 +67,13 @@ void displayComponentDetailsInfo( const std::unordered_map &SupportedComponentInfo) { std::stringstream ComponentDetailLog; - ComponentDetailLog << "\nComptatible Component details:\n"; + ComponentDetailLog << "\nCompatible Component details:\n"; for (const auto &Component : SupportedComponentInfo) { for (const auto &Des : Component.second.ComponentDes) { ComponentDetailLog << " - " << Des << "\n"; } } - std::cout << ComponentDetailLog.str() << "\n"; + std::cout << ComponentDetailLog.str(); } void displaySupportedComponents(bool isPrintOverall) { @@ -89,37 +89,52 @@ void displaySupportedComponents(bool isPrintOverall) { } displayComponentDetailsInfo(Components); } +std::string +generateDescription(const ComponentInfo &Info, + const std::shared_ptr &Status) { + std::ostringstream oss; + oss << "The feature " << Status->Feature; + if (Status->IsOpenSource) { + oss << " is supported in " << Info.ComponentName << " open source " + << Status->SupportedVersion << ". "; + } else if (Status->IsInNextOneAPIVersion) { + oss << " is supported in the next oneAPI version. "; + } + if (!Status->Link.empty()) { + oss << "For more details, please refer to the provided link: " + << Status->Link << ". \n"; + } + return oss.str(); +} +std::string getContentAfterSpace(const std::string &str) { + size_t pos = str.find(' '); + if (pos != std::string::npos) { + return str.substr(pos + 1); + } + return str; +} void updateComInfoBasedOnCompStatus( ComponentInfo &Info, const std::shared_ptr &Status) { - std::string Description = ""; - Description += "The feature " + Status->Feature; - if (Status->IsOpenSource) { - Description += " is supported in " + Info.ComponentName + " open source " + - Status->SupportedVersion + ". "; - if (!Info.ComponentVersion.empty()) { - if (Info.ComponentVersion.find("oneAPI") == std::string::npos) { - long OrgDate = - stoi(Info.ComponentVersion); // Version should be datestamp. - long NewDate = stoi(Status->SupportedVersion); - if (OrgDate < NewDate) - Info.ComponentVersion = ">=" + Status->SupportedVersion; - } else { - Info.ComponentVersion = ">=" + Status->SupportedVersion; + std::string Description = generateDescription(Info, Status); + Info.ComponentDes.push_back(Description); + if (Status->IsOpenSource && !Info.ComponentVersion.empty() && + !Status->SupportedVersion.empty()) { + try { + float OrgDate = std::stof(getContentAfterSpace(Info.ComponentVersion)); + float NewDate = std::stof(getContentAfterSpace(Status->SupportedVersion)); + if (OrgDate < NewDate || + Info.ComponentVersion.find("oneAPI") != std::string::npos) { + Info.ComponentVersion = ">= " + Status->SupportedVersion; } + } catch (...) { + std::cerr << "DPCT Exit: Error in component_version.yaml. The " + "'SupportedVersion' field must be a valid number. Please " + "check and correct it.\n"; + dpctExit(MigrationError); } - } else { - if (Status->IsInNextOneAPIVersion) { - Description += " is supported in the next oneAPI version. "; - } - } - if (!Status->Link.empty()) { - Description += - "For more details, please refer to the provided link: " + Status->Link + - ". \n"; } - Info.ComponentDes.push_back(Description); } void parseSupportComponentStatus( diff --git a/clang/lib/DPCT/FileGenerator/GenFiles.cpp b/clang/lib/DPCT/FileGenerator/GenFiles.cpp index ff9666203235..eebcabdf2fe0 100644 --- a/clang/lib/DPCT/FileGenerator/GenFiles.cpp +++ b/clang/lib/DPCT/FileGenerator/GenFiles.cpp @@ -607,7 +607,6 @@ int writeReplacementsToFiles( MainSrcFileMap[Entry.first] = true; for (const auto &Repl : Entry.second) { - Repl.getReplacementText(); MainSrcFilesRepls.push_back(Repl); } } diff --git a/clang/tools/dpct/extensions/supported_components/component_version.yaml b/clang/tools/dpct/extensions/supported_components/component_version.yaml index cbfb8cf98424..e7178cb3b4fa 100644 --- a/clang/tools/dpct/extensions/supported_components/component_version.yaml +++ b/clang/tools/dpct/extensions/supported_components/component_version.yaml @@ -1,18 +1,10 @@ ---- -- Feature: Free Function query for SYCL - SupportedVersion: 20250526 - ComponentType: Compiler - Link: https:github.com/oneapi-src/oneAPI-sycl/issues/444sss - ReplacementText: "this_work_item" - IsOpenSource: true - IsInNextOneAPIVersion: true - Description: Free Function query for SYCL is supported. and user can use it to query the kernel info in the kernel function directly - -- Feature: Free Function query for SYCL222 - SupportedVersion: 2025052x - ComponentType: Compiler - Link: https:github.com/oneapi-src/oneAPI-sycl/issues/444sss - ReplacementText: "sycl::get_kernel_info(kernel)" - IsOpenSource: false - IsInNextOneAPIVersion: true - Description: Free Function query for SYCL is supported. and user can use it to query the kernel info in the kernel function directly \ No newline at end of file +# This is a example +# --- +# - Feature: Feature name +# SupportedVersion: Time Stamp of component +# ComponentType: Details Component type. +# Link: Link of the PR to enable this feature. [Optional] +# ReplacementText: The migrated Replacement Text +# IsOpenSource: true +# IsInNextOneAPIVersion: true +# Description: Details. From 76b6d87528691ced238f4d68db5987e6ff651913 Mon Sep 17 00:00:00 2001 From: Shengchenj Date: Wed, 4 Jun 2025 22:35:09 -0700 Subject: [PATCH 10/16] up Signed-off-by: Shengchenj --- clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp | 4 ++-- clang/lib/DPCT/ComponentVersion/ComponentVersion.h | 2 +- clang/lib/DPCT/FileGenerator/GenFiles.cpp | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp b/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp index 03017cdb2c25..71b9def553d4 100644 --- a/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp +++ b/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp @@ -82,7 +82,7 @@ void displaySupportedComponents(bool isPrintOverall) { dpct::DpctGlobalInfo::getSupportedComponentInfo(); if (isPrintOverall) { for (auto &CompStatus : CompsStatus) { - updateComInfoBasedOnCompStatus(Components[CompStatus->CompType], + updateComInfoByCompStatus(Components[CompStatus->CompType], CompStatus); } displayOverallComponentInfo(Components); @@ -114,7 +114,7 @@ std::string getContentAfterSpace(const std::string &str) { } return str; } -void updateComInfoBasedOnCompStatus( +void updateComInfoByCompStatus( ComponentInfo &Info, const std::shared_ptr &Status) { std::string Description = generateDescription(Info, Status); diff --git a/clang/lib/DPCT/ComponentVersion/ComponentVersion.h b/clang/lib/DPCT/ComponentVersion/ComponentVersion.h index e369c4fe88f8..3dcac8e4fe8b 100644 --- a/clang/lib/DPCT/ComponentVersion/ComponentVersion.h +++ b/clang/lib/DPCT/ComponentVersion/ComponentVersion.h @@ -50,7 +50,7 @@ void displayComponentDetailsInfo( const std::unordered_map &SupportedComponentInfo); void displaySupportedComponents(bool isPrintOverall = false); -void updateComInfoBasedOnCompStatus(ComponentInfo &Info, +void updateComInfoByCompStatus(ComponentInfo &Info, const std::shared_ptr &Status); } // namespace dpct } // namespace clang diff --git a/clang/lib/DPCT/FileGenerator/GenFiles.cpp b/clang/lib/DPCT/FileGenerator/GenFiles.cpp index eebcabdf2fe0..0245251281c1 100644 --- a/clang/lib/DPCT/FileGenerator/GenFiles.cpp +++ b/clang/lib/DPCT/FileGenerator/GenFiles.cpp @@ -912,15 +912,15 @@ void genCodePinHeader(dpct::RawFDOStream &RS, bool IsForCUDADebug) { } void GenVerifiedCmpVer( - const std::vector &CmpVerRepls) { + const std::vector &MainSrcFilesRepls) { auto CompStatusList = dpct::DpctGlobalInfo::getCompatibleCompsStatus(); auto CompsInfo = dpct::DpctGlobalInfo::getSupportedComponentInfo(); for (auto CompStatus : CompStatusList) { - for (auto Repl : CmpVerRepls) { + for (auto Repl : MainSrcFilesRepls) { if (Repl.getReplacementText().str().find(CompStatus->ReplacementText) != std::string::npos) { // If the replacement text is already in the list, skip it. - updateComInfoBasedOnCompStatus(CompsInfo[CompStatus->CompType], CompStatus); + updateComInfoByCompStatus(CompsInfo[CompStatus->CompType], CompStatus); break; } } From 89dc1143cf3ff16f20c8e4f20eb5ed13a64a867a Mon Sep 17 00:00:00 2001 From: Shengchenj Date: Wed, 4 Jun 2025 22:37:17 -0700 Subject: [PATCH 11/16] up --- clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp | 7 +++++++ .../extensions/supported_components/component_version.yaml | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp b/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp index 71b9def553d4..e70a80e211c7 100644 --- a/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp +++ b/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp @@ -1,3 +1,10 @@ +//===--------------- ComponentVersion.cpp --------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// #include "ComponentVersion.h" #include "AnalysisInfo.h" diff --git a/clang/tools/dpct/extensions/supported_components/component_version.yaml b/clang/tools/dpct/extensions/supported_components/component_version.yaml index e7178cb3b4fa..26fc902bffe2 100644 --- a/clang/tools/dpct/extensions/supported_components/component_version.yaml +++ b/clang/tools/dpct/extensions/supported_components/component_version.yaml @@ -1,4 +1,6 @@ -# This is a example +# Copyright (C) Intel Corporation +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# See https://llvm.org/LICENSE.txt for license information. # --- # - Feature: Feature name # SupportedVersion: Time Stamp of component From b669d9a6dbc214c02f99d24795797d9956e2f233 Mon Sep 17 00:00:00 2001 From: "Chen, Sheng S" Date: Thu, 26 Jun 2025 14:29:32 +0800 Subject: [PATCH 12/16] update Signed-off-by: Chen, Sheng S --- clang/include/clang/DPCT/DPCTOptions.inc | 8 - clang/lib/DPCT/AnalysisInfo.cpp | 2 - clang/lib/DPCT/AnalysisInfo.h | 21 --- clang/lib/DPCT/CMakeLists.txt | 2 +- .../ComponentVersion/ComponentVersion.cpp | 163 ------------------ .../DPCT/ComponentVersion/ComponentVersion.h | 58 ------- clang/lib/DPCT/DPCT.cpp | 23 +-- clang/lib/DPCT/FileGenerator/GenFiles.cpp | 22 +-- clang/lib/DPCT/MigrationReport/Statics.cpp | 5 + clang/tools/dpct/extensions/CMakeLists.txt | 10 -- .../component_version.yaml | 12 -- 11 files changed, 14 insertions(+), 312 deletions(-) delete mode 100644 clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp delete mode 100644 clang/lib/DPCT/ComponentVersion/ComponentVersion.h delete mode 100644 clang/tools/dpct/extensions/supported_components/component_version.yaml diff --git a/clang/include/clang/DPCT/DPCTOptions.inc b/clang/include/clang/DPCT/DPCTOptions.inc index 93acb0315774..afa05039ad58 100644 --- a/clang/include/clang/DPCT/DPCTOptions.inc +++ b/clang/include/clang/DPCT/DPCTOptions.inc @@ -554,14 +554,6 @@ DPCT_FLAG_OPTION( "_codepin_sycl, where is specified by --out-root option."), llvm::cl::cat(CtHelpCatAll)) -DPCT_FLAG_OPTION( - CompatibleComps, clang::dpct::DpctOptionClass::OC_Attribute, - DPCT_OPTION_ACTIONS(clang::dpct::DpctActionKind::DAK_Migration), - "supported-components", - llvm::cl::desc("Show the supported components and their compatibility " - "version information.\n"), - llvm::cl::cat(CtHelpCatAll)) - DPCT_FLAG_OPTION( EnableCTAD, clang::dpct::DpctOptionClass::OC_Attribute, DPCT_OPTION_ACTIONS(clang::dpct::DpctActionKind::DAK_Migration, diff --git a/clang/lib/DPCT/AnalysisInfo.cpp b/clang/lib/DPCT/AnalysisInfo.cpp index 88f0f42d05c2..36cd3cfe5405 100644 --- a/clang/lib/DPCT/AnalysisInfo.cpp +++ b/clang/lib/DPCT/AnalysisInfo.cpp @@ -2416,7 +2416,6 @@ std::shared_ptr clang::tooling::UnifiedPath DpctGlobalInfo::InRoot; clang::tooling::UnifiedPath DpctGlobalInfo::OutRoot; std::vector DpctGlobalInfo::AnalysisScope; -std::vector> DpctGlobalInfo::CompatibleCompsStatus; std::unordered_set DpctGlobalInfo::ChangeExtensions = {}; std::string DpctGlobalInfo::SYCLSourceExtension = std::string(); std::string DpctGlobalInfo::SYCLHeaderExtension = std::string(); @@ -2435,7 +2434,6 @@ format::FormatRange DpctGlobalInfo::FmtRng = format::FormatRange::none; DPCTFormatStyle DpctGlobalInfo::FmtST = DPCTFormatStyle::FS_LLVM; bool DpctGlobalInfo::EnableCtad = false; bool DpctGlobalInfo::EnableCodePin = false; -bool DpctGlobalInfo::CompatibleComps = false; bool DpctGlobalInfo::IsMLKHeaderUsed = false; bool DpctGlobalInfo::GenBuildScript = false; bool DpctGlobalInfo::MigrateBuildScriptOnly = false; diff --git a/clang/lib/DPCT/AnalysisInfo.h b/clang/lib/DPCT/AnalysisInfo.h index 31e07e8be42d..06958a3785ec 100644 --- a/clang/lib/DPCT/AnalysisInfo.h +++ b/clang/lib/DPCT/AnalysisInfo.h @@ -19,7 +19,6 @@ #include "TextModification.h" #include "Utility.h" #include "CommandOption/ValidateArguments.h" -#include "ComponentVersion/ComponentVersion.h" #include #include #include @@ -737,24 +736,6 @@ class DpctGlobalInfo { static const std::vector &getAnalysisScope() { return AnalysisScope; } - static void - setCompatibleCompsStatus(const std::vector> &CompStatus) { - CompatibleCompsStatus = CompStatus; - } - static const std::vector> &getCompatibleCompsStatus() { - return CompatibleCompsStatus; - } -static const std::unordered_map & - getSupportedComponentInfo() { - static std::unordered_map Components = { - {ComponentType::DPCPP, ComponentInfo("DPCPP")}, - {ComponentType::oneDPL, ComponentInfo("oneDPL")}, - {ComponentType::oneMKL, ComponentInfo("oneMKL")}, - {ComponentType::oneDNNL, ComponentInfo("oneDNNL")}, - {ComponentType::oneCCL, ComponentInfo("oneCCL")}, - {ComponentType::ISHMEM, ComponentInfo("ISHMEM")}}; - return Components; - } static void addChangeExtensions(const std::string &Extension) { assert(!Extension.empty()); ChangeExtensions.insert(Extension); @@ -1604,7 +1585,6 @@ static const std::unordered_map & static clang::tooling::UnifiedPath InRoot; static clang::tooling::UnifiedPath OutRoot; static std::vector AnalysisScope; - static std::vector> CompatibleCompsStatus; static std::unordered_set ChangeExtensions; static std::string SYCLSourceExtension; static std::string SYCLHeaderExtension; @@ -1623,7 +1603,6 @@ static const std::unordered_map & static DPCTFormatStyle FmtST; static bool EnableCtad; static bool EnableCodePin; - static bool CompatibleComps; static bool IsMLKHeaderUsed; static bool GenBuildScript; static bool MigrateBuildScriptOnly; diff --git a/clang/lib/DPCT/CMakeLists.txt b/clang/lib/DPCT/CMakeLists.txt index 75da92d73386..fa46bd25332f 100644 --- a/clang/lib/DPCT/CMakeLists.txt +++ b/clang/lib/DPCT/CMakeLists.txt @@ -212,6 +212,7 @@ add_clang_library(DPCT Diagnostics/Diagnostics.cpp ErrorHandle/Error.cpp MigrationReport/Statics.cpp + MigrationReport/Run.cpp RuleInfra/ExprAnalysis.cpp ExtReplacements.cpp RuleInfra/MapNames.cpp @@ -233,7 +234,6 @@ add_clang_library(DPCT MigrateScript/GenMakefile.cpp RulesInclude/InclusionHeaders.cpp IncMigration/IncrementalMigrationUtility.cpp - ComponentVersion/ComponentVersion.cpp UserDefinedRules/UserDefinedRules.cpp UserDefinedRules/PatternRewriter.cpp MigrateScript/MigrateBuildScript.cpp diff --git a/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp b/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp deleted file mode 100644 index e70a80e211c7..000000000000 --- a/clang/lib/DPCT/ComponentVersion/ComponentVersion.cpp +++ /dev/null @@ -1,163 +0,0 @@ -//===--------------- ComponentVersion.cpp --------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "ComponentVersion.h" -#include "AnalysisInfo.h" -#include -#include - -using namespace llvm; - -template <> -struct llvm::yaml::SequenceTraits> { - static size_t size(IO &io, std::vector &seq) { - return seq.size(); - } - - static clang::dpct::CompStatus & - element(IO &io, std::vector &seq, size_t index) { - if (index >= seq.size()) - seq.resize(index + 1); - return seq[index]; - } -}; - -template <> -struct llvm::yaml::MappingTraits> { - static void mapping(IO &io, - std::shared_ptr &Status) { - Status = std::make_shared(); - io.mapRequired("Feature", Status->Feature); - io.mapRequired("SupportedVersion", Status->SupportedVersion); - io.mapRequired("ComponentType", Status->CompType); - io.mapOptional("Link", Status->Link); - io.mapRequired("ReplacementText", Status->ReplacementText); - io.mapOptional("IsOpenSource", Status->IsOpenSource); - io.mapRequired("IsInNextOneAPIVersion", Status->IsInNextOneAPIVersion); - io.mapOptional("Description", Status->Description); - } -}; -template <> struct llvm::yaml::ScalarEnumerationTraits { - static void enumeration(llvm::yaml::IO &Io, ComponentType &Value) { - Io.enumCase(Value, "Compiler", ComponentType::DPCPP); - Io.enumCase(Value, "DPC++", ComponentType::DPCPP); - Io.enumCase(Value, "DPCPP", ComponentType::DPCPP); - Io.enumCase(Value, "oneDPL", ComponentType::oneDPL); - Io.enumCase(Value, "oneMKL", ComponentType::oneMKL); - Io.enumCase(Value, "oneCCL", ComponentType::oneCCL); - Io.enumCase(Value, "oneDNNL", ComponentType::oneDNNL); - Io.enumCase(Value, "ISHMEM", ComponentType::ISHMEM); - } -}; - -namespace clang { -namespace dpct { - -void displayOverallComponentInfo( - const std::unordered_map - &SupportedComponentInfo) { - std::stringstream ComponentOverallLog; - ComponentOverallLog << "Compatible components:\n"; - for (const auto &Component : SupportedComponentInfo) { - ComponentOverallLog << " - " << Component.second.ComponentName << ": " - << Component.second.ComponentVersion << ".\n"; - } - std::cout << ComponentOverallLog.str(); -} - -void displayComponentDetailsInfo( - const std::unordered_map - &SupportedComponentInfo) { - std::stringstream ComponentDetailLog; - ComponentDetailLog << "\nCompatible Component details:\n"; - for (const auto &Component : SupportedComponentInfo) { - for (const auto &Des : Component.second.ComponentDes) { - ComponentDetailLog << " - " << Des << "\n"; - } - } - std::cout << ComponentDetailLog.str(); -} - -void displaySupportedComponents(bool isPrintOverall) { - auto CompsStatus = DpctGlobalInfo::getCompatibleCompsStatus(); - std::unordered_map Components = - dpct::DpctGlobalInfo::getSupportedComponentInfo(); - if (isPrintOverall) { - for (auto &CompStatus : CompsStatus) { - updateComInfoByCompStatus(Components[CompStatus->CompType], - CompStatus); - } - displayOverallComponentInfo(Components); - } - displayComponentDetailsInfo(Components); -} -std::string -generateDescription(const ComponentInfo &Info, - const std::shared_ptr &Status) { - std::ostringstream oss; - oss << "The feature " << Status->Feature; - if (Status->IsOpenSource) { - oss << " is supported in " << Info.ComponentName << " open source " - << Status->SupportedVersion << ". "; - } else if (Status->IsInNextOneAPIVersion) { - oss << " is supported in the next oneAPI version. "; - } - if (!Status->Link.empty()) { - oss << "For more details, please refer to the provided link: " - << Status->Link << ". \n"; - } - return oss.str(); -} - -std::string getContentAfterSpace(const std::string &str) { - size_t pos = str.find(' '); - if (pos != std::string::npos) { - return str.substr(pos + 1); - } - return str; -} -void updateComInfoByCompStatus( - ComponentInfo &Info, - const std::shared_ptr &Status) { - std::string Description = generateDescription(Info, Status); - Info.ComponentDes.push_back(Description); - if (Status->IsOpenSource && !Info.ComponentVersion.empty() && - !Status->SupportedVersion.empty()) { - try { - float OrgDate = std::stof(getContentAfterSpace(Info.ComponentVersion)); - float NewDate = std::stof(getContentAfterSpace(Status->SupportedVersion)); - if (OrgDate < NewDate || - Info.ComponentVersion.find("oneAPI") != std::string::npos) { - Info.ComponentVersion = ">= " + Status->SupportedVersion; - } - } catch (...) { - std::cerr << "DPCT Exit: Error in component_version.yaml. The " - "'SupportedVersion' field must be a valid number. Please " - "check and correct it.\n"; - dpctExit(MigrationError); - } - } -} - -void parseSupportComponentStatus( - std::vector &RuleFiles, - bool IsPrintComponentOpt) { - auto file = llvm::MemoryBuffer::getFile(RuleFiles[0].getCanonicalPath()); - if (!file) { - llvm::errs() << "Error: failed to read " << RuleFiles[0].getCanonicalPath() - << ": " << file.getError().message() << "\n"; - return; - } - std::vector> CompsStatus; - yaml::Input yin(file.get()->getBuffer()); - yin >> CompsStatus; - DpctGlobalInfo::setCompatibleCompsStatus(CompsStatus); -} - -} // namespace dpct -} // namespace clang diff --git a/clang/lib/DPCT/ComponentVersion/ComponentVersion.h b/clang/lib/DPCT/ComponentVersion/ComponentVersion.h deleted file mode 100644 index 3dcac8e4fe8b..000000000000 --- a/clang/lib/DPCT/ComponentVersion/ComponentVersion.h +++ /dev/null @@ -1,58 +0,0 @@ -//===--------------- ComponentVersion.h -//----------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef DPCT_COMPONENT_VERSION -#define DPCT_COMPONENT_VERSION -#include "clang/Tooling/Tooling.h" -#include "llvm/Support/CommandLine.h" -#include "llvm/Support/YAMLTraits.h" -#include -#include - -namespace clang { -namespace dpct { -enum ComponentType { DPCPP, oneDPL, oneMKL, oneCCL, oneDNNL, ISHMEM }; - -struct CompStatus { - std::string Feature; - std::string SupportedVersion; - std::string ReplacementText; - ComponentType CompType; - bool IsOpenSource; - bool IsInNextOneAPIVersion; - std::string Link; - std::string Description; -}; - -const std::string OneAPIVersion = "2025.1"; -class ComponentInfo { -public: - ComponentInfo(const std::string &Name, - const std::string &Version = "oneAPI " + OneAPIVersion) - : ComponentName(Name), ComponentVersion(Version) {} - ComponentInfo() - : ComponentName(""), ComponentVersion("oneAPI " + OneAPIVersion) {} - std::string ComponentName; - std::string ComponentVersion; - std::vector ComponentDes; -}; - -void parseSupportComponentStatus( - std::vector &RuleFiles, - bool IsPrintComponentOpt = false); -void displayComponentDetailsInfo( - const std::unordered_map - &SupportedComponentInfo); -void displaySupportedComponents(bool isPrintOverall = false); -void updateComInfoByCompStatus(ComponentInfo &Info, - const std::shared_ptr &Status); -} // namespace dpct -} // namespace clang - -#endif // DPCT_COMPONENT_VERSION diff --git a/clang/lib/DPCT/DPCT.cpp b/clang/lib/DPCT/DPCT.cpp index 7003d0fcc2fa..150f02b28b2d 100644 --- a/clang/lib/DPCT/DPCT.cpp +++ b/clang/lib/DPCT/DPCT.cpp @@ -7,11 +7,11 @@ //===----------------------------------------------------------------------===// #include "clang/DPCT/DPCT.h" +#include "MigrationReport/Run.h" #include "ASTTraversal.h" #include "AnalysisInfo.h" #include "CommandOption/ValidateArguments.h" #include "Config.h" -#include "ComponentVersion/ComponentVersion.h" #include "ErrorHandle/CrashRecovery.h" #include "ErrorHandle/Error.h" #include "FileGenerator/GenFiles.h" @@ -977,23 +977,6 @@ int runDPCT(int argc, const char **argv) { ExtraIncPaths = OptParser->getExtraIncPathList(); - { - SmallString<128> FilePath1(DpctInstallPath.getCanonicalPath()); - llvm::sys::path::append(FilePath1, - Twine("extensions/supported_components/component_version.yaml")); - SmallString<128> FilePath2(DpctInstallPath.getCanonicalPath()); - llvm::sys::path::append(FilePath2, - Twine("opt/dpct/extensions/supported_components/component_version.yaml")); - - std::vector SupportedComponents{ - llvm::sys::fs::exists(FilePath1) ? FilePath1.c_str() - : FilePath2.c_str()}; - parseSupportComponentStatus(SupportedComponents, CompatibleComps); - } - if (CompatibleComps) { - displaySupportedComponents(CompatibleComps); - return 0; - } if (isCUDAHeaderRequired()) { // TODO: implement one of this for each source language. CudaPath = getCudaInstallPath(OriginalArgc, argv); @@ -1497,7 +1480,9 @@ int runDPCT(int argc, const char **argv) { return showAPIMapping(QueryAPIMappingSrc, QueryAPIMappingOpt, Tool, ReplSYCL); } - + if (!ReplSYCL.empty()) { + CollectDepsResult(ReplSYCL); + } // OC_Action: Analysis mode if (DpctGlobalInfo::isAnalysisModeEnabled()) { if (AnalysisModeOutputFile.getValue().empty()) { diff --git a/clang/lib/DPCT/FileGenerator/GenFiles.cpp b/clang/lib/DPCT/FileGenerator/GenFiles.cpp index 0245251281c1..3d4ecec9f48a 100644 --- a/clang/lib/DPCT/FileGenerator/GenFiles.cpp +++ b/clang/lib/DPCT/FileGenerator/GenFiles.cpp @@ -34,6 +34,8 @@ #include "llvm/Support/Path.h" #include "llvm/Support/raw_os_ostream.h" +#include "MigrationReport/Run.h" + #include #include #include @@ -911,22 +913,6 @@ void genCodePinHeader(dpct::RawFDOStream &RS, bool IsForCUDADebug) { RS << "#endif" << getNL(); } -void GenVerifiedCmpVer( - const std::vector &MainSrcFilesRepls) { - auto CompStatusList = dpct::DpctGlobalInfo::getCompatibleCompsStatus(); - auto CompsInfo = dpct::DpctGlobalInfo::getSupportedComponentInfo(); - for (auto CompStatus : CompStatusList) { - for (auto Repl : MainSrcFilesRepls) { - if (Repl.getReplacementText().str().find(CompStatus->ReplacementText) != - std::string::npos) { - // If the replacement text is already in the list, skip it. - updateComInfoByCompStatus(CompsInfo[CompStatus->CompType], CompStatus); - break; - } - } - } - displayComponentDetailsInfo(CompsInfo); -} /// Apply all generated replacements, and immediately save the results to files /// in output directory. /// @@ -1012,7 +998,7 @@ int saveNewFiles(clang::tooling::RefactoringTool &Tool, clang::dpct::RT_CUDAWithCodePin)) return RewriteStatus; } - GenVerifiedCmpVer(MainSrcFilesRepls); + ShowDepsResult(llvm::outs()); // Print the in-root path and the number of processed files size_t ProcessedFileNumber; if (ProcessAll) { @@ -1048,7 +1034,7 @@ int saveNewFiles(clang::tooling::RefactoringTool &Tool, } else { ReportMsg += "\n"; } - + ReportMsg += "\n"; ReportMsg += DiagRef; diff --git a/clang/lib/DPCT/MigrationReport/Statics.cpp b/clang/lib/DPCT/MigrationReport/Statics.cpp index 321571a8810d..83555a7a72dd 100644 --- a/clang/lib/DPCT/MigrationReport/Statics.cpp +++ b/clang/lib/DPCT/MigrationReport/Statics.cpp @@ -8,6 +8,7 @@ #include "MigrationReport/Statics.h" #include "ASTTraversal.h" #include "RulesInclude/InclusionHeaders.h" +#include "MigrationReport/Run.h" #include #include @@ -28,6 +29,8 @@ std::unordered_map> LOCStaticsMap; // unsigned int -> Times met std::map SrcAPIStaticsMap; +extern std::vector DepStatusVec; + int VerboseLevel = VL_NonVerbose; void StaticsInfo::printMigrationRules( @@ -363,6 +366,8 @@ class AnalysisModeStats { } } LineStream(OS, Indent) << LastMsg; + + ShowDepsResult(OS); } static void recordApisOrTypes(SourceLocation SL, StringRef Name, diff --git a/clang/tools/dpct/extensions/CMakeLists.txt b/clang/tools/dpct/extensions/CMakeLists.txt index 581a793d9315..c8570c5043be 100644 --- a/clang/tools/dpct/extensions/CMakeLists.txt +++ b/clang/tools/dpct/extensions/CMakeLists.txt @@ -19,10 +19,6 @@ set(dpct_pytorch_api_rule_files ${CMAKE_SOURCE_DIR}/../clang/tools/dpct/extensions/pytorch_api_rules/pytorch_api.yaml ) -set(dpct_supported_components_files - ${CMAKE_SOURCE_DIR}/../clang/tools/dpct/extensions/supported_components/component_version.yaml -) - set(dpct_rule_template_files ${CMAKE_SOURCE_DIR}/../clang/tools/dpct/extensions/rule_templates/api_rule.yaml ${CMAKE_SOURCE_DIR}/../clang/tools/dpct/extensions/rule_templates/class_rule.yaml @@ -59,12 +55,6 @@ install( PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ DESTINATION ./extensions/pytorch_api_rules) -install( - FILES ${dpct_supported_components_files} - COMPONENT dpct-rules - PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ - DESTINATION ./extensions/supported_components) - install( FILES ${dpct_rule_template_files} COMPONENT dpct-rules diff --git a/clang/tools/dpct/extensions/supported_components/component_version.yaml b/clang/tools/dpct/extensions/supported_components/component_version.yaml deleted file mode 100644 index 26fc902bffe2..000000000000 --- a/clang/tools/dpct/extensions/supported_components/component_version.yaml +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright (C) Intel Corporation -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# See https://llvm.org/LICENSE.txt for license information. -# --- -# - Feature: Feature name -# SupportedVersion: Time Stamp of component -# ComponentType: Details Component type. -# Link: Link of the PR to enable this feature. [Optional] -# ReplacementText: The migrated Replacement Text -# IsOpenSource: true -# IsInNextOneAPIVersion: true -# Description: Details. From 3b42ebab68338142d83cccebd37a56bbfd0d1a33 Mon Sep 17 00:00:00 2001 From: "Chen, Sheng S" Date: Thu, 26 Jun 2025 14:30:13 +0800 Subject: [PATCH 13/16] update Signed-off-by: Chen, Sheng S --- .../RecommandLibrariesVersion.inc | 19 ++++++ clang/lib/DPCT/MigrationReport/Run.cpp | 61 +++++++++++++++++++ clang/lib/DPCT/MigrationReport/Run.h | 54 ++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 clang/lib/DPCT/MigrationReport/RecommandLibrariesVersion.inc create mode 100644 clang/lib/DPCT/MigrationReport/Run.cpp create mode 100644 clang/lib/DPCT/MigrationReport/Run.h diff --git a/clang/lib/DPCT/MigrationReport/RecommandLibrariesVersion.inc b/clang/lib/DPCT/MigrationReport/RecommandLibrariesVersion.inc new file mode 100644 index 000000000000..f50fa07a7f7a --- /dev/null +++ b/clang/lib/DPCT/MigrationReport/RecommandLibrariesVersion.inc @@ -0,0 +1,19 @@ +//===--------------- Diagnostics.inc --------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// - Name: Obj name +// Feature: Feature name +// SupportedVersion: Time stamp of component +// ComponentType: Component type. +// ReplacementText: The migrated Replacement Text +// Description: Details of the feature. + +#ifndef RECOMMENDLIBRARY +#define RECOMMENDLIBRARY +#endif + +RECOMMENDLIBRARY(FreeQuery, "SYCL free function query", "20250623", ComponentType::DPCPP, "this_work_item", "See https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/proposed/sycl_ext_oneapi_free_function_kernels.asciidoc for more details.") \ No newline at end of file diff --git a/clang/lib/DPCT/MigrationReport/Run.cpp b/clang/lib/DPCT/MigrationReport/Run.cpp new file mode 100644 index 000000000000..9b0dd81ef394 --- /dev/null +++ b/clang/lib/DPCT/MigrationReport/Run.cpp @@ -0,0 +1,61 @@ + + +#include +#include +#include "FileGenerator/GenFiles.h" +#include "Statics.h" +#include "Run.h" + +namespace clang { +namespace dpct { + +std::unordered_map + DepStatus; +std::vector DepStatusVec; + +#define RECOMMENDLIBRARY(NAME, Feature, VERSION, COMPTYPE, REPLACEMENT, \ + MSG) \ + DependencyStatus DepStatus_##NAME(DepStatus, Feature, VERSION, COMPTYPE, \ + REPLACEMENT, MSG); +#include "RecommandLibrariesVersion.inc" + +void CollectDepsResult(ReplTy &MainSrcFilesRepls) { + for (auto Entry : DepStatus) { + auto &Status = Entry.second; + [&]() { + for (auto Repl : MainSrcFilesRepls) { + for (auto Item : Repl.second) { + llvm::outs() << "XXXXXXXXXX " << Item.getReplacementText().str() <<"\n"; + llvm::outs() << "XXXXXXXXXX2222 " << Status.ReplacementText <<"\n"; + if (Item.getReplacementText().str().find(Status.ReplacementText) != + std::string::npos) { + DepStatusVec.push_back(Status); + return; + } + } + } + }(); + } +} +std::string ComponentTypeToString(ComponentType version) { + switch (version) { + case ComponentType::DPCPP: + return "oneAPI DPC++ compiler Open Source Version"; + case ComponentType::oneDPL: + return "oneAPI DPC++ Library Open Source Version"; + case ComponentType::oneMath: + return "oneAPI Math Library Open Source Version"; + case ComponentType::oneCCL: + return "oneAPI Collective Communications Library Open Source Version"; + case ComponentType::oneDNNL: + return "oneAPI Deep Neural Network Library Open Source Version"; + case ComponentType::ISHMEM: + return "oneAPI SHMEM Library Open Source Version"; + default: + return "Unknown Component Type "; + } +} + + +} // namespace dpct +} // namespace clang \ No newline at end of file diff --git a/clang/lib/DPCT/MigrationReport/Run.h b/clang/lib/DPCT/MigrationReport/Run.h new file mode 100644 index 000000000000..2fac72af9660 --- /dev/null +++ b/clang/lib/DPCT/MigrationReport/Run.h @@ -0,0 +1,54 @@ +#ifndef MIGRATIONREPORT_RUN_H +#define MIGRATIONREPORT_RUN_H + +#include +#include +#include "FileGenerator/GenFiles.h" +#include "llvm/Support/raw_ostream.h" +#include "AnalysisInfo.h" + +namespace clang { +namespace dpct { + +enum class ComponentType { DPCPP, oneDPL, oneMath, oneCCL, oneDNNL, ISHMEM }; + +struct DependencyStatus { + std::string Feature; + std::string SupportedVersion; + std::string ReplacementText; + ComponentType CompType; + std::string Description; + + DependencyStatus() = default; + DependencyStatus(std::unordered_map &Table, + std::string Feature, std::string SupportedVersion, + ComponentType CT, std::string ReplacementText, + std::string Description) + : Feature(Feature), SupportedVersion(SupportedVersion), + ReplacementText(ReplacementText), CompType(CT), Description(Description) { + Table[CT] = *this; + } +}; +extern std::unordered_map + DepStatus; +extern std::vector DepStatusVec; +void CollectDepsResult(ReplTy &MainSrcFilesRepls); +std::string ComponentTypeToString(ComponentType version); + +inline void ShowDepsResult(llvm::raw_ostream &OStream) { + if (DepStatusVec.empty()) + return; + if (DpctGlobalInfo::isAnalysisModeEnabled()) + OStream << llvm::raw_ostream::Colors::BLUE; + OStream << "Recommand Library Dependencies of SYCL Project:\n"; + if (DpctGlobalInfo::isAnalysisModeEnabled()) + OStream << llvm::raw_ostream::Colors::RESET; + for (auto &Status : DepStatusVec) { + OStream << " - The " + Status.Feature + " is supported in " + + ComponentTypeToString(Status.CompType) + " and fter " + + Status.SupportedVersion + ". " + Status.Description + "\n"; + } +} +} // namespace dpct +} // namespace clang +#endif // MIGRATIONREPORT_RUN_H \ No newline at end of file From 5c1bc989ce01f24f93cc096114ce9fbbf025cb00 Mon Sep 17 00:00:00 2001 From: "Chen, Sheng S" Date: Thu, 26 Jun 2025 14:45:40 +0800 Subject: [PATCH 14/16] update Signed-off-by: Chen, Sheng S --- clang/lib/DPCT/CMakeLists.txt | 2 +- clang/lib/DPCT/DPCT.cpp | 4 +-- clang/lib/DPCT/FileGenerator/GenFiles.cpp | 2 +- .../{Run.cpp => RecommandLibraries.cpp} | 5 ++-- .../{Run.h => RecommandLibraries.h} | 30 +++++++++++-------- .../RecommandLibrariesVersion.inc | 4 +-- clang/lib/DPCT/MigrationReport/Statics.cpp | 2 +- 7 files changed, 27 insertions(+), 22 deletions(-) rename clang/lib/DPCT/MigrationReport/{Run.cpp => RecommandLibraries.cpp} (90%) rename clang/lib/DPCT/MigrationReport/{Run.h => RecommandLibraries.h} (73%) diff --git a/clang/lib/DPCT/CMakeLists.txt b/clang/lib/DPCT/CMakeLists.txt index fa46bd25332f..7aec2f6fb5c1 100644 --- a/clang/lib/DPCT/CMakeLists.txt +++ b/clang/lib/DPCT/CMakeLists.txt @@ -212,7 +212,7 @@ add_clang_library(DPCT Diagnostics/Diagnostics.cpp ErrorHandle/Error.cpp MigrationReport/Statics.cpp - MigrationReport/Run.cpp + MigrationReport/RecommandLibraries.cpp RuleInfra/ExprAnalysis.cpp ExtReplacements.cpp RuleInfra/MapNames.cpp diff --git a/clang/lib/DPCT/DPCT.cpp b/clang/lib/DPCT/DPCT.cpp index 150f02b28b2d..8743eae819a7 100644 --- a/clang/lib/DPCT/DPCT.cpp +++ b/clang/lib/DPCT/DPCT.cpp @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// #include "clang/DPCT/DPCT.h" -#include "MigrationReport/Run.h" +#include "MigrationReport/RecommandLibraries.h" #include "ASTTraversal.h" #include "AnalysisInfo.h" #include "CommandOption/ValidateArguments.h" @@ -976,7 +976,7 @@ int runDPCT(int argc, const char **argv) { showReportHeader(); ExtraIncPaths = OptParser->getExtraIncPathList(); - + if (isCUDAHeaderRequired()) { // TODO: implement one of this for each source language. CudaPath = getCudaInstallPath(OriginalArgc, argv); diff --git a/clang/lib/DPCT/FileGenerator/GenFiles.cpp b/clang/lib/DPCT/FileGenerator/GenFiles.cpp index 3d4ecec9f48a..abfe9994de14 100644 --- a/clang/lib/DPCT/FileGenerator/GenFiles.cpp +++ b/clang/lib/DPCT/FileGenerator/GenFiles.cpp @@ -34,7 +34,7 @@ #include "llvm/Support/Path.h" #include "llvm/Support/raw_os_ostream.h" -#include "MigrationReport/Run.h" +#include "MigrationReport/RecommandLibraries.h" #include #include diff --git a/clang/lib/DPCT/MigrationReport/Run.cpp b/clang/lib/DPCT/MigrationReport/RecommandLibraries.cpp similarity index 90% rename from clang/lib/DPCT/MigrationReport/Run.cpp rename to clang/lib/DPCT/MigrationReport/RecommandLibraries.cpp index 9b0dd81ef394..16420181c718 100644 --- a/clang/lib/DPCT/MigrationReport/Run.cpp +++ b/clang/lib/DPCT/MigrationReport/RecommandLibraries.cpp @@ -4,7 +4,7 @@ #include #include "FileGenerator/GenFiles.h" #include "Statics.h" -#include "Run.h" +#include "RecommandLibraries.h" namespace clang { namespace dpct { @@ -25,8 +25,6 @@ void CollectDepsResult(ReplTy &MainSrcFilesRepls) { [&]() { for (auto Repl : MainSrcFilesRepls) { for (auto Item : Repl.second) { - llvm::outs() << "XXXXXXXXXX " << Item.getReplacementText().str() <<"\n"; - llvm::outs() << "XXXXXXXXXX2222 " << Status.ReplacementText <<"\n"; if (Item.getReplacementText().str().find(Status.ReplacementText) != std::string::npos) { DepStatusVec.push_back(Status); @@ -37,6 +35,7 @@ void CollectDepsResult(ReplTy &MainSrcFilesRepls) { }(); } } + std::string ComponentTypeToString(ComponentType version) { switch (version) { case ComponentType::DPCPP: diff --git a/clang/lib/DPCT/MigrationReport/Run.h b/clang/lib/DPCT/MigrationReport/RecommandLibraries.h similarity index 73% rename from clang/lib/DPCT/MigrationReport/Run.h rename to clang/lib/DPCT/MigrationReport/RecommandLibraries.h index 2fac72af9660..ca6349a67741 100644 --- a/clang/lib/DPCT/MigrationReport/Run.h +++ b/clang/lib/DPCT/MigrationReport/RecommandLibraries.h @@ -1,11 +1,11 @@ -#ifndef MIGRATIONREPORT_RUN_H -#define MIGRATIONREPORT_RUN_H +#ifndef RECOMMEND_LIBRARIES_H +#define RECOMMEND_LIBRARIES_H -#include -#include +#include "AnalysisInfo.h" #include "FileGenerator/GenFiles.h" #include "llvm/Support/raw_ostream.h" -#include "AnalysisInfo.h" +#include +#include namespace clang { namespace dpct { @@ -25,30 +25,36 @@ struct DependencyStatus { ComponentType CT, std::string ReplacementText, std::string Description) : Feature(Feature), SupportedVersion(SupportedVersion), - ReplacementText(ReplacementText), CompType(CT), Description(Description) { + ReplacementText(ReplacementText), CompType(CT), + Description(Description) { Table[CT] = *this; } }; -extern std::unordered_map - DepStatus; +extern std::unordered_map + DepStatus; extern std::vector DepStatusVec; + void CollectDepsResult(ReplTy &MainSrcFilesRepls); -std::string ComponentTypeToString(ComponentType version); + +std::string ComponentTypeToString(ComponentType Type); inline void ShowDepsResult(llvm::raw_ostream &OStream) { if (DepStatusVec.empty()) return; if (DpctGlobalInfo::isAnalysisModeEnabled()) OStream << llvm::raw_ostream::Colors::BLUE; + OStream << "Recommand Library Dependencies of SYCL Project:\n"; + if (DpctGlobalInfo::isAnalysisModeEnabled()) OStream << llvm::raw_ostream::Colors::RESET; for (auto &Status : DepStatusVec) { OStream << " - The " + Status.Feature + " is supported in " + - ComponentTypeToString(Status.CompType) + " and fter " + - Status.SupportedVersion + ". " + Status.Description + "\n"; + ComponentTypeToString(Status.CompType) + " and after " + + Status.SupportedVersion + ". " + Status.Description + "\n"; } } } // namespace dpct } // namespace clang -#endif // MIGRATIONREPORT_RUN_H \ No newline at end of file +#endif // RECOMMEND_LIBRARIES_H diff --git a/clang/lib/DPCT/MigrationReport/RecommandLibrariesVersion.inc b/clang/lib/DPCT/MigrationReport/RecommandLibrariesVersion.inc index f50fa07a7f7a..a45ba02d014d 100644 --- a/clang/lib/DPCT/MigrationReport/RecommandLibrariesVersion.inc +++ b/clang/lib/DPCT/MigrationReport/RecommandLibrariesVersion.inc @@ -15,5 +15,5 @@ #ifndef RECOMMENDLIBRARY #define RECOMMENDLIBRARY #endif - -RECOMMENDLIBRARY(FreeQuery, "SYCL free function query", "20250623", ComponentType::DPCPP, "this_work_item", "See https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/proposed/sycl_ext_oneapi_free_function_kernels.asciidoc for more details.") \ No newline at end of file +// Example: +// RECOMMENDLIBRARY(FreeQuery, "SYCL free function query", "Time", ComponentType::DPCPP, "this_work_item", "See https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/proposed/sycl_ext_oneapi_free_function_kernels.asciidoc for more details.") \ No newline at end of file diff --git a/clang/lib/DPCT/MigrationReport/Statics.cpp b/clang/lib/DPCT/MigrationReport/Statics.cpp index 83555a7a72dd..de3afc2f21c5 100644 --- a/clang/lib/DPCT/MigrationReport/Statics.cpp +++ b/clang/lib/DPCT/MigrationReport/Statics.cpp @@ -8,7 +8,7 @@ #include "MigrationReport/Statics.h" #include "ASTTraversal.h" #include "RulesInclude/InclusionHeaders.h" -#include "MigrationReport/Run.h" +#include "MigrationReport/RecommandLibraries.h" #include #include From 57ffbf7b9fef366b566d2d2b7a120784e8adc7f3 Mon Sep 17 00:00:00 2001 From: "Chen, Sheng S" Date: Thu, 26 Jun 2025 15:40:38 +0800 Subject: [PATCH 15/16] up Signed-off-by: Chen, Sheng S --- clang/lib/DPCT/DPCT.cpp | 2 +- clang/lib/DPCT/FileGenerator/GenFiles.cpp | 4 +- .../MigrationReport/RecommandLibraries.cpp | 60 ------------ .../DPCT/MigrationReport/RecommandLibraries.h | 60 ------------ .../RecommandLibrariesVersion.inc | 6 +- .../MigrationReport/RecommendLibraries.cpp | 98 +++++++++++++++++++ .../DPCT/MigrationReport/RecommendLibraries.h | 25 +++++ clang/lib/DPCT/MigrationReport/Statics.cpp | 4 +- 8 files changed, 130 insertions(+), 129 deletions(-) delete mode 100644 clang/lib/DPCT/MigrationReport/RecommandLibraries.cpp delete mode 100644 clang/lib/DPCT/MigrationReport/RecommandLibraries.h create mode 100644 clang/lib/DPCT/MigrationReport/RecommendLibraries.cpp create mode 100644 clang/lib/DPCT/MigrationReport/RecommendLibraries.h diff --git a/clang/lib/DPCT/DPCT.cpp b/clang/lib/DPCT/DPCT.cpp index 8743eae819a7..5fc0712b3645 100644 --- a/clang/lib/DPCT/DPCT.cpp +++ b/clang/lib/DPCT/DPCT.cpp @@ -1481,7 +1481,7 @@ int runDPCT(int argc, const char **argv) { ReplSYCL); } if (!ReplSYCL.empty()) { - CollectDepsResult(ReplSYCL); + CollectDepLib(ReplSYCL); } // OC_Action: Analysis mode if (DpctGlobalInfo::isAnalysisModeEnabled()) { diff --git a/clang/lib/DPCT/FileGenerator/GenFiles.cpp b/clang/lib/DPCT/FileGenerator/GenFiles.cpp index abfe9994de14..61515d916fbd 100644 --- a/clang/lib/DPCT/FileGenerator/GenFiles.cpp +++ b/clang/lib/DPCT/FileGenerator/GenFiles.cpp @@ -998,7 +998,7 @@ int saveNewFiles(clang::tooling::RefactoringTool &Tool, clang::dpct::RT_CUDAWithCodePin)) return RewriteStatus; } - ShowDepsResult(llvm::outs()); + PrintRecommendLibs(llvm::outs()); // Print the in-root path and the number of processed files size_t ProcessedFileNumber; if (ProcessAll) { @@ -1034,7 +1034,7 @@ int saveNewFiles(clang::tooling::RefactoringTool &Tool, } else { ReportMsg += "\n"; } - + ReportMsg += "\n"; ReportMsg += DiagRef; diff --git a/clang/lib/DPCT/MigrationReport/RecommandLibraries.cpp b/clang/lib/DPCT/MigrationReport/RecommandLibraries.cpp deleted file mode 100644 index 16420181c718..000000000000 --- a/clang/lib/DPCT/MigrationReport/RecommandLibraries.cpp +++ /dev/null @@ -1,60 +0,0 @@ - - -#include -#include -#include "FileGenerator/GenFiles.h" -#include "Statics.h" -#include "RecommandLibraries.h" - -namespace clang { -namespace dpct { - -std::unordered_map - DepStatus; -std::vector DepStatusVec; - -#define RECOMMENDLIBRARY(NAME, Feature, VERSION, COMPTYPE, REPLACEMENT, \ - MSG) \ - DependencyStatus DepStatus_##NAME(DepStatus, Feature, VERSION, COMPTYPE, \ - REPLACEMENT, MSG); -#include "RecommandLibrariesVersion.inc" - -void CollectDepsResult(ReplTy &MainSrcFilesRepls) { - for (auto Entry : DepStatus) { - auto &Status = Entry.second; - [&]() { - for (auto Repl : MainSrcFilesRepls) { - for (auto Item : Repl.second) { - if (Item.getReplacementText().str().find(Status.ReplacementText) != - std::string::npos) { - DepStatusVec.push_back(Status); - return; - } - } - } - }(); - } -} - -std::string ComponentTypeToString(ComponentType version) { - switch (version) { - case ComponentType::DPCPP: - return "oneAPI DPC++ compiler Open Source Version"; - case ComponentType::oneDPL: - return "oneAPI DPC++ Library Open Source Version"; - case ComponentType::oneMath: - return "oneAPI Math Library Open Source Version"; - case ComponentType::oneCCL: - return "oneAPI Collective Communications Library Open Source Version"; - case ComponentType::oneDNNL: - return "oneAPI Deep Neural Network Library Open Source Version"; - case ComponentType::ISHMEM: - return "oneAPI SHMEM Library Open Source Version"; - default: - return "Unknown Component Type "; - } -} - - -} // namespace dpct -} // namespace clang \ No newline at end of file diff --git a/clang/lib/DPCT/MigrationReport/RecommandLibraries.h b/clang/lib/DPCT/MigrationReport/RecommandLibraries.h deleted file mode 100644 index ca6349a67741..000000000000 --- a/clang/lib/DPCT/MigrationReport/RecommandLibraries.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef RECOMMEND_LIBRARIES_H -#define RECOMMEND_LIBRARIES_H - -#include "AnalysisInfo.h" -#include "FileGenerator/GenFiles.h" -#include "llvm/Support/raw_ostream.h" -#include -#include - -namespace clang { -namespace dpct { - -enum class ComponentType { DPCPP, oneDPL, oneMath, oneCCL, oneDNNL, ISHMEM }; - -struct DependencyStatus { - std::string Feature; - std::string SupportedVersion; - std::string ReplacementText; - ComponentType CompType; - std::string Description; - - DependencyStatus() = default; - DependencyStatus(std::unordered_map &Table, - std::string Feature, std::string SupportedVersion, - ComponentType CT, std::string ReplacementText, - std::string Description) - : Feature(Feature), SupportedVersion(SupportedVersion), - ReplacementText(ReplacementText), CompType(CT), - Description(Description) { - Table[CT] = *this; - } -}; -extern std::unordered_map - DepStatus; -extern std::vector DepStatusVec; - -void CollectDepsResult(ReplTy &MainSrcFilesRepls); - -std::string ComponentTypeToString(ComponentType Type); - -inline void ShowDepsResult(llvm::raw_ostream &OStream) { - if (DepStatusVec.empty()) - return; - if (DpctGlobalInfo::isAnalysisModeEnabled()) - OStream << llvm::raw_ostream::Colors::BLUE; - - OStream << "Recommand Library Dependencies of SYCL Project:\n"; - - if (DpctGlobalInfo::isAnalysisModeEnabled()) - OStream << llvm::raw_ostream::Colors::RESET; - for (auto &Status : DepStatusVec) { - OStream << " - The " + Status.Feature + " is supported in " + - ComponentTypeToString(Status.CompType) + " and after " + - Status.SupportedVersion + ". " + Status.Description + "\n"; - } -} -} // namespace dpct -} // namespace clang -#endif // RECOMMEND_LIBRARIES_H diff --git a/clang/lib/DPCT/MigrationReport/RecommandLibrariesVersion.inc b/clang/lib/DPCT/MigrationReport/RecommandLibrariesVersion.inc index a45ba02d014d..a67f4cabc83e 100644 --- a/clang/lib/DPCT/MigrationReport/RecommandLibrariesVersion.inc +++ b/clang/lib/DPCT/MigrationReport/RecommandLibrariesVersion.inc @@ -1,4 +1,4 @@ -//===--------------- Diagnostics.inc --------------------------------------===// +//===--------------- RecommandLibrariesVersion.inc --------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -8,7 +8,7 @@ // - Name: Obj name // Feature: Feature name // SupportedVersion: Time stamp of component -// ComponentType: Component type. +// LibType: Component type. // ReplacementText: The migrated Replacement Text // Description: Details of the feature. @@ -16,4 +16,4 @@ #define RECOMMENDLIBRARY #endif // Example: -// RECOMMENDLIBRARY(FreeQuery, "SYCL free function query", "Time", ComponentType::DPCPP, "this_work_item", "See https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/proposed/sycl_ext_oneapi_free_function_kernels.asciidoc for more details.") \ No newline at end of file +// RECOMMENDLIBRARY(FreeQuery, "SYCL free function query", "2025", LibType::DPCPP, "this_work_item", "See https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/proposed/sycl_ext_oneapi_free_function_kernels.asciidoc for more details.") \ No newline at end of file diff --git a/clang/lib/DPCT/MigrationReport/RecommendLibraries.cpp b/clang/lib/DPCT/MigrationReport/RecommendLibraries.cpp new file mode 100644 index 000000000000..8a0d73a5bb6b --- /dev/null +++ b/clang/lib/DPCT/MigrationReport/RecommendLibraries.cpp @@ -0,0 +1,98 @@ +//===--------------- RecommendLibraries.cpp ------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "RecommandLibraries.h" +#include "FileGenerator/GenFiles.h" +#include "Statics.h" +#include +#include + +namespace clang { +namespace dpct { +struct RecommendLib { + std::string Feature; + std::string SupportedVersion; + std::string ReplacementText; + LibType CompType; + std::string Description; + + RecommendLib() = default; + RecommendLib(std::unordered_map &Table, + std::string Feature, std::string SupportedVersion, LibType CT, + std::string ReplacementText, std::string Description) + : Feature(Feature), SupportedVersion(SupportedVersion), + ReplacementText(ReplacementText), CompType(CT), + Description(Description) { + Table[CT] = *this; + } +}; +static std::unordered_map + RecommendLibs; +std::vector RecommendLibList; + +#define RECOMMENDLIBRARY(NAME, Feature, VERSION, COMPTYPE, REPLACEMENT, MSG) \ + RecommendLib DepRecommend_##NAME(RecommendLibs, Feature, VERSION, COMPTYPE, \ + REPLACEMENT, MSG); +#include "RecommandLibrariesVersion.inc" + +void CollectDepLib(ReplTy &Repls) { + for (auto Entry : RecommendLibs) { + auto &Lib = Entry.second; + [&]() { + for (auto Repl : Repls) { + for (auto Item : Repl.second) { + if (Item.getReplacementText().str().find(Lib.ReplacementText) != + std::string::npos) { + RecommendLibList.push_back(Lib); + return; + } + } + } + }(); + } +} + +std::string LibTypeToString(LibType version) { + switch (version) { + case LibType::DPCPP: + return "oneAPI DPC++ compiler Open Source Version"; + case LibType::oneDPL: + return "oneAPI DPC++ Library Open Source Version"; + case LibType::oneMath: + return "oneAPI Math Library Open Source Version"; + case LibType::oneCCL: + return "oneAPI Collective Communications Library Open Source Version"; + case LibType::oneDNNL: + return "oneAPI Deep Neural Network Library Open Source Version"; + case LibType::ISHMEM: + return "oneAPI SHMEM Library Open Source Version"; + default: + return "Unknown Component Type "; + } +} + +void PrintRecommendLibs(llvm::raw_ostream &OStream) { + if (RecommendLibList.empty()) + return; + if (DpctGlobalInfo::isAnalysisModeEnabled()) + OStream << llvm::raw_ostream::Colors::BLUE; + + OStream << "Recommand Library Dependencies of SYCL Project:\n"; + + if (DpctGlobalInfo::isAnalysisModeEnabled()) + OStream << llvm::raw_ostream::Colors::RESET; + for (auto &Status : RecommendLibList) { + OStream << " - The " + Status.Feature + " is supported in " + + LibTypeToString(Status.CompType) + " and after " + + Status.SupportedVersion + ". " + Status.Description + "\n"; + } +} + + +} // namespace dpct +} // namespace clang \ No newline at end of file diff --git a/clang/lib/DPCT/MigrationReport/RecommendLibraries.h b/clang/lib/DPCT/MigrationReport/RecommendLibraries.h new file mode 100644 index 000000000000..b0bf5bec0ff5 --- /dev/null +++ b/clang/lib/DPCT/MigrationReport/RecommendLibraries.h @@ -0,0 +1,25 @@ +//===--------------- RecommendLibraries.h --------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#ifndef RECOMMEND_LIBRARIES_H +#define RECOMMEND_LIBRARIES_H + +#include "AnalysisInfo.h" +#include "FileGenerator/GenFiles.h" +#include "llvm/Support/raw_ostream.h" +#include +#include + +namespace clang { +namespace dpct { +enum class LibType { DPCPP, oneDPL, oneMath, oneCCL, oneDNNL, ISHMEM }; + +void CollectDepLib(ReplTy &MainSrcFilesRepls); +void PrintRecommendLibs(llvm::raw_ostream &OStream); +} // namespace dpct +} // namespace clang +#endif // RECOMMEND_LIBRARIES_H diff --git a/clang/lib/DPCT/MigrationReport/Statics.cpp b/clang/lib/DPCT/MigrationReport/Statics.cpp index de3afc2f21c5..196374d285e5 100644 --- a/clang/lib/DPCT/MigrationReport/Statics.cpp +++ b/clang/lib/DPCT/MigrationReport/Statics.cpp @@ -29,8 +29,6 @@ std::unordered_map> LOCStaticsMap; // unsigned int -> Times met std::map SrcAPIStaticsMap; -extern std::vector DepStatusVec; - int VerboseLevel = VL_NonVerbose; void StaticsInfo::printMigrationRules( @@ -367,7 +365,7 @@ class AnalysisModeStats { } LineStream(OS, Indent) << LastMsg; - ShowDepsResult(OS); + PrintRecommendLibs(OS); } static void recordApisOrTypes(SourceLocation SL, StringRef Name, From ca8bcadc8904fecd90a20f2680ec88af2d8e95d0 Mon Sep 17 00:00:00 2001 From: "Chen, Sheng S" Date: Thu, 26 Jun 2025 16:40:16 +0800 Subject: [PATCH 16/16] fix build. Signed-off-by: Chen, Sheng S --- clang/lib/DPCT/CMakeLists.txt | 2 +- clang/lib/DPCT/DPCT.cpp | 2 +- clang/lib/DPCT/FileGenerator/GenFiles.cpp | 2 +- clang/lib/DPCT/MigrationReport/RecommendLibraries.cpp | 6 +++--- ...ndLibrariesVersion.inc => RecommendLibrariesVersion.inc} | 2 +- clang/lib/DPCT/MigrationReport/Statics.cpp | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) rename clang/lib/DPCT/MigrationReport/{RecommandLibrariesVersion.inc => RecommendLibrariesVersion.inc} (92%) diff --git a/clang/lib/DPCT/CMakeLists.txt b/clang/lib/DPCT/CMakeLists.txt index 7aec2f6fb5c1..2d2c1c67352c 100644 --- a/clang/lib/DPCT/CMakeLists.txt +++ b/clang/lib/DPCT/CMakeLists.txt @@ -212,7 +212,7 @@ add_clang_library(DPCT Diagnostics/Diagnostics.cpp ErrorHandle/Error.cpp MigrationReport/Statics.cpp - MigrationReport/RecommandLibraries.cpp + MigrationReport/RecommendLibraries.cpp RuleInfra/ExprAnalysis.cpp ExtReplacements.cpp RuleInfra/MapNames.cpp diff --git a/clang/lib/DPCT/DPCT.cpp b/clang/lib/DPCT/DPCT.cpp index 5fc0712b3645..970c700e0eaa 100644 --- a/clang/lib/DPCT/DPCT.cpp +++ b/clang/lib/DPCT/DPCT.cpp @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// #include "clang/DPCT/DPCT.h" -#include "MigrationReport/RecommandLibraries.h" +#include "MigrationReport/RecommendLibraries.h" #include "ASTTraversal.h" #include "AnalysisInfo.h" #include "CommandOption/ValidateArguments.h" diff --git a/clang/lib/DPCT/FileGenerator/GenFiles.cpp b/clang/lib/DPCT/FileGenerator/GenFiles.cpp index 61515d916fbd..6055d806b7c6 100644 --- a/clang/lib/DPCT/FileGenerator/GenFiles.cpp +++ b/clang/lib/DPCT/FileGenerator/GenFiles.cpp @@ -34,7 +34,7 @@ #include "llvm/Support/Path.h" #include "llvm/Support/raw_os_ostream.h" -#include "MigrationReport/RecommandLibraries.h" +#include "MigrationReport/RecommendLibraries.h" #include #include diff --git a/clang/lib/DPCT/MigrationReport/RecommendLibraries.cpp b/clang/lib/DPCT/MigrationReport/RecommendLibraries.cpp index 8a0d73a5bb6b..c9223271c40b 100644 --- a/clang/lib/DPCT/MigrationReport/RecommendLibraries.cpp +++ b/clang/lib/DPCT/MigrationReport/RecommendLibraries.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "RecommandLibraries.h" +#include "RecommendLibraries.h" #include "FileGenerator/GenFiles.h" #include "Statics.h" #include @@ -38,7 +38,7 @@ std::vector RecommendLibList; #define RECOMMENDLIBRARY(NAME, Feature, VERSION, COMPTYPE, REPLACEMENT, MSG) \ RecommendLib DepRecommend_##NAME(RecommendLibs, Feature, VERSION, COMPTYPE, \ REPLACEMENT, MSG); -#include "RecommandLibrariesVersion.inc" +#include "RecommendLibrariesVersion.inc" void CollectDepLib(ReplTy &Repls) { for (auto Entry : RecommendLibs) { @@ -82,7 +82,7 @@ void PrintRecommendLibs(llvm::raw_ostream &OStream) { if (DpctGlobalInfo::isAnalysisModeEnabled()) OStream << llvm::raw_ostream::Colors::BLUE; - OStream << "Recommand Library Dependencies of SYCL Project:\n"; + OStream << "Recommend Library Dependencies of SYCL Project:\n"; if (DpctGlobalInfo::isAnalysisModeEnabled()) OStream << llvm::raw_ostream::Colors::RESET; diff --git a/clang/lib/DPCT/MigrationReport/RecommandLibrariesVersion.inc b/clang/lib/DPCT/MigrationReport/RecommendLibrariesVersion.inc similarity index 92% rename from clang/lib/DPCT/MigrationReport/RecommandLibrariesVersion.inc rename to clang/lib/DPCT/MigrationReport/RecommendLibrariesVersion.inc index a67f4cabc83e..115fe99fd7fb 100644 --- a/clang/lib/DPCT/MigrationReport/RecommandLibrariesVersion.inc +++ b/clang/lib/DPCT/MigrationReport/RecommendLibrariesVersion.inc @@ -1,4 +1,4 @@ -//===--------------- RecommandLibrariesVersion.inc --------------------------------------===// +//===--------------- RecommendLibrariesVersion.inc --------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/clang/lib/DPCT/MigrationReport/Statics.cpp b/clang/lib/DPCT/MigrationReport/Statics.cpp index 196374d285e5..5a1b00a57313 100644 --- a/clang/lib/DPCT/MigrationReport/Statics.cpp +++ b/clang/lib/DPCT/MigrationReport/Statics.cpp @@ -8,7 +8,7 @@ #include "MigrationReport/Statics.h" #include "ASTTraversal.h" #include "RulesInclude/InclusionHeaders.h" -#include "MigrationReport/RecommandLibraries.h" +#include "MigrationReport/RecommendLibraries.h" #include #include