Skip to content

[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

Closed
wants to merge 18 commits into from
Closed
1 change: 1 addition & 0 deletions clang/lib/DPCT/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ add_clang_library(DPCT
Diagnostics/Diagnostics.cpp
ErrorHandle/Error.cpp
MigrationReport/Statics.cpp
MigrationReport/RecommendLibraries.cpp
RuleInfra/ExprAnalysis.cpp
ExtReplacements.cpp
RuleInfra/MapNames.cpp
Expand Down
5 changes: 4 additions & 1 deletion clang/lib/DPCT/DPCT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//

#include "clang/DPCT/DPCT.h"
#include "MigrationReport/RecommendLibraries.h"
#include "ASTTraversal.h"
#include "AnalysisInfo.h"
#include "CommandOption/ValidateArguments.h"
Expand Down Expand Up @@ -1481,7 +1482,9 @@ int runDPCT(int argc, const char **argv) {
return showAPIMapping(QueryAPIMappingSrc, QueryAPIMappingOpt, Tool,
ReplSYCL);
}

if (!ReplSYCL.empty()) {
CollectDepLib(ReplSYCL);
}
// OC_Action: Analysis mode
if (DpctGlobalInfo::isAnalysisModeEnabled()) {
if (AnalysisModeOutputFile.getValue().empty()) {
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/DPCT/FileGenerator/GenFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_os_ostream.h"

#include "MigrationReport/RecommendLibraries.h"

#include <algorithm>
#include <cassert>
#include <fstream>
Expand Down Expand Up @@ -996,6 +998,7 @@ int saveNewFiles(clang::tooling::RefactoringTool &Tool,
clang::dpct::RT_CUDAWithCodePin))
return RewriteStatus;
}
PrintRecommendLibs(llvm::outs());
// Print the in-root path and the number of processed files
size_t ProcessedFileNumber;
if (ProcessAll) {
Expand Down
98 changes: 98 additions & 0 deletions clang/lib/DPCT/MigrationReport/RecommendLibraries.cpp
Original file line number Diff line number Diff line change
@@ -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 "RecommendLibraries.h"
#include "FileGenerator/GenFiles.h"
#include "Statics.h"
#include <string>
#include <unordered_map>

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<LibType, RecommendLib> &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<clang::dpct::LibType, clang::dpct::RecommendLib>
RecommendLibs;
std::vector<clang::dpct::RecommendLib> RecommendLibList;

#define RECOMMENDLIBRARY(NAME, Feature, VERSION, COMPTYPE, REPLACEMENT, MSG) \
RecommendLib DepRecommend_##NAME(RecommendLibs, Feature, VERSION, COMPTYPE, \
REPLACEMENT, MSG);
#include "RecommendLibrariesVersion.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 << "Recommend 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
25 changes: 25 additions & 0 deletions clang/lib/DPCT/MigrationReport/RecommendLibraries.h
Original file line number Diff line number Diff line change
@@ -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 <string>
#include <unordered_map>

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
19 changes: 19 additions & 0 deletions clang/lib/DPCT/MigrationReport/RecommendLibrariesVersion.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===--------------- 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.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// - Name: Obj name
// Feature: Feature name
// SupportedVersion: Time stamp of component
// LibType: Component type.
// ReplacementText: The migrated Replacement Text
// Description: Details of the feature.

#ifndef RECOMMENDLIBRARY
#define RECOMMENDLIBRARY
#endif
// Example:
// 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.")
3 changes: 3 additions & 0 deletions clang/lib/DPCT/MigrationReport/Statics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "MigrationReport/Statics.h"
#include "ASTTraversal.h"
#include "RulesInclude/InclusionHeaders.h"
#include "MigrationReport/RecommendLibraries.h"

#include <numeric>
#include <unordered_set>
Expand Down Expand Up @@ -363,6 +364,8 @@ class AnalysisModeStats {
}
}
LineStream(OS, Indent) << LastMsg;

PrintRecommendLibs(OS);
}

static void recordApisOrTypes(SourceLocation SL, StringRef Name,
Expand Down
Loading