-
Notifications
You must be signed in to change notification settings - Fork 93
[SYCLomatic] Emit the verified component version. #2855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ShengchenJ
wants to merge
11
commits into
oneapi-src:SYCLomatic
Choose a base branch
from
ShengchenJ:ver_comp
base: SYCLomatic
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f8f7b8e
[SYCLomatic] Emit the verified component version.
ShengchenJ 11baaf3
up
ShengchenJ 10c83e2
up
ShengchenJ 721ae1b
update
ShengchenJ 293b7c2
up
ShengchenJ 08dc6dc
up
ShengchenJ 71ccd4d
up
ShengchenJ 147cdf6
up
ShengchenJ 75b4d8c
up
ShengchenJ 76b6d87
up
ShengchenJ 89dc114
up
ShengchenJ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
//===--------------- 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 <iostream> | ||
#include <sstream> | ||
|
||
using namespace llvm; | ||
|
||
template <> | ||
struct llvm::yaml::SequenceTraits<std::vector<clang::dpct::CompStatus>> { | ||
static size_t size(IO &io, std::vector<clang::dpct::CompStatus> &seq) { | ||
return seq.size(); | ||
} | ||
|
||
static clang::dpct::CompStatus & | ||
element(IO &io, std::vector<clang::dpct::CompStatus> &seq, size_t index) { | ||
if (index >= seq.size()) | ||
seq.resize(index + 1); | ||
return seq[index]; | ||
} | ||
}; | ||
|
||
template <> | ||
struct llvm::yaml::MappingTraits<std::shared_ptr<clang::dpct::CompStatus>> { | ||
static void mapping(IO &io, | ||
std::shared_ptr<clang::dpct::CompStatus> &Status) { | ||
Status = std::make_shared<clang::dpct::CompStatus>(); | ||
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<ComponentType> { | ||
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<ComponentType, ComponentInfo> | ||
&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<ComponentType, ComponentInfo> | ||
&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<ComponentType, ComponentInfo> 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<clang::dpct::CompStatus> &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<clang::dpct::CompStatus> &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<clang::tooling::UnifiedPath> &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<std::shared_ptr<clang::dpct::CompStatus>> CompsStatus; | ||
yaml::Input yin(file.get()->getBuffer()); | ||
yin >> CompsStatus; | ||
DpctGlobalInfo::setCompatibleCompsStatus(CompsStatus); | ||
} | ||
|
||
} // namespace dpct | ||
} // namespace clang |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//===--------------- 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 <string> | ||
#include <vector> | ||
|
||
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<std::string> ComponentDes; | ||
}; | ||
|
||
void parseSupportComponentStatus( | ||
std::vector<clang::tooling::UnifiedPath> &RuleFiles, | ||
bool IsPrintComponentOpt = false); | ||
void displayComponentDetailsInfo( | ||
const std::unordered_map<ComponentType, ComponentInfo> | ||
&SupportedComponentInfo); | ||
void displaySupportedComponents(bool isPrintOverall = false); | ||
void updateComInfoByCompStatus(ComponentInfo &Info, | ||
const std::shared_ptr<clang::dpct::CompStatus> &Status); | ||
} // namespace dpct | ||
} // namespace clang | ||
|
||
#endif // DPCT_COMPONENT_VERSION |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -911,6 +911,22 @@ void genCodePinHeader(dpct::RawFDOStream &RS, bool IsForCUDADebug) { | |||||
RS << "#endif" << getNL(); | ||||||
} | ||||||
|
||||||
void GenVerifiedCmpVer( | ||||||
const std::vector<clang::tooling::Replacement> &MainSrcFilesRepls) { | ||||||
auto CompStatusList = dpct::DpctGlobalInfo::getCompatibleCompsStatus(); | ||||||
auto CompsInfo = dpct::DpctGlobalInfo::getSupportedComponentInfo(); | ||||||
for (auto CompStatus : CompStatusList) { | ||||||
for (auto Repl : MainSrcFilesRepls) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This loop copies each
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
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. | ||||||
/// | ||||||
|
@@ -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) { | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.