Skip to content

Commit a3ae9fc

Browse files
committed
Merge remote-tracking branch 'origin/SYCLomatic' into remove_ipc
2 parents dc8dc57 + b6ca5ce commit a3ae9fc

49 files changed

Lines changed: 1262 additions & 203 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

clang/include/clang/Tooling/Core/Replacement.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,8 @@ struct TranslationUnitReplacements {
436436
#ifdef SYCLomatic_CUSTOMIZATION
437437
std::vector<MainSourceFileInfo> MainSourceFilesDigest;
438438
std::string DpctVersion = "";
439+
std::string SDKVersionMajor = "";
440+
std::string SDKVersionMinor = "";
439441
std::string MainHelperFileName = "";
440442
std::string USMLevel = ""; // deprecated
441443

clang/include/clang/Tooling/ReplacementsYaml.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ template <> struct MappingTraits<clang::tooling::TranslationUnitReplacements> {
269269
#ifdef SYCLomatic_CUSTOMIZATION
270270
Io.mapOptional("MainSourceFilesDigest", Doc.MainSourceFilesDigest);
271271
Io.mapOptional("DpctVersion", Doc.DpctVersion);
272+
Io.mapOptional("SDKVersionMajor", Doc.SDKVersionMajor);
273+
Io.mapOptional("SDKVersionMinor", Doc.SDKVersionMinor);
272274
Io.mapOptional("MainHelperFileName", Doc.MainHelperFileName);
273275
Io.mapOptional("USMLevel", Doc.USMLevel);
274276
// Keep here only for backward compatibility - begin

clang/lib/DPCT/ASTTraversal.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "RulesSHMEM/NVSHMEMAPIMigration.h"
2828
#include "RulesSecurity/Homoglyph.h"
2929
#include "RulesSecurity/MisleadingBidirectional.h"
30+
#include "RulesTensor/CUTensorAPIMigration.h"
3031
#include "TextModification.h"
3132
#include "Utility.h"
3233

@@ -197,5 +198,7 @@ REGISTER_RULE(CuDNNAPIRule, PassKind::PK_Migration, RuleGroupKind::RK_DNN)
197198

198199
REGISTER_RULE(NVSHMEMRule, PassKind::PK_Migration, RuleGroupKind::RK_NVSHMEM)
199200

201+
REGISTER_RULE(CUTensorRule, PassKind::PK_Migration, RuleGroupKind::RK_CUTensor)
202+
200203
} // namespace dpct
201204
} // namespace clang

clang/lib/DPCT/AnalysisInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2950,7 +2950,7 @@ void MemVarInfo::migrateToDeviceGlobal(const VarDecl *MemVar) {
29502950
auto &Ctx = DpctGlobalInfo::getContext();
29512951
auto &MacroArgMap = DpctGlobalInfo::getMacroArgRecordMap();
29522952
auto TSI = MemVar->getTypeSourceInfo();
2953-
auto OriginTL = TSI->getTypeLoc();
2953+
auto OriginTL = TSI->getTypeLoc().getUnqualifiedLoc().getAs<TypeLoc>();
29542954
auto TL = OriginTL;
29552955
auto BegLoc = MemVar->getBeginLoc();
29562956
if (BegLoc.isMacroID()) {

clang/lib/DPCT/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ add_clang_library(DPCT
205205
RulesLang/CallExprRewriterCG.cpp
206206
RulesLang/CallExprRewriterWmma.cpp
207207
RulesSHMEM/CallExprRewriterNvshmem.cpp
208+
RulesTensor/CallExprRewriterCUTensor.cpp
208209
ErrorHandle/CrashRecovery.cpp
209210
Diagnostics/Diagnostics.cpp
210211
ErrorHandle/Error.cpp
@@ -244,6 +245,7 @@ add_clang_library(DPCT
244245
RulesCCL/NCCLAPIMigration.cpp
245246
RuleInfra/TypeLocRewriters.cpp
246247
RulesSHMEM/NVSHMEMAPIMigration.cpp
248+
RulesTensor/CUTensorAPIMigration.cpp
247249
Linux/AutoComplete.cpp
248250
RulesAsm/AsmMigration.cpp
249251
QueryAPIMapping/QueryAPIMapping.cpp

clang/lib/DPCT/DPCT.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,59 @@ void parseFormatStyle() {
463463
DpctGlobalInfo::setCodeFormatStyle(Style);
464464
}
465465

466+
void updateCompatibilityVersionInfo(clang::tooling::UnifiedPath OutRoot,
467+
std::string Major, std::string Minor) {
468+
const std::string CmakeHelpFile =
469+
appendPath(OutRoot.getCanonicalPath().str(), "dpct.cmake");
470+
std::ifstream InFile(CmakeHelpFile);
471+
if (!InFile) {
472+
std::string ErrMsg = "Failed to open file: " + CmakeHelpFile;
473+
ShowStatus(MigrationErrorReadWriteCMakeHelperFile, std::move(ErrMsg));
474+
dpctExit(MigrationErrorReadWriteCMakeHelperFile);
475+
}
476+
477+
const std::string VersionStr = Major + "." + Minor;
478+
const int CompatibilityValue = std::stoi(Major) * 10 + std::stoi(Minor);
479+
std::vector<std::string> Lines;
480+
std::string Line;
481+
bool Inserted = false;
482+
483+
// Constant block of content to insert
484+
const std::vector<std::string> CompatibilityBlock = {
485+
"set(COMPATIBILITY_VERSION " + VersionStr + ")",
486+
"set(COMPATIBILITY_VALUE " + std::to_string(CompatibilityValue) + ")",
487+
"set(COMPATIBILITY_VERSION_MAJOR " + Major + ")",
488+
"set(COMPATIBILITY_VERSION_MINOR " + Minor + ")",
489+
"" // Add an empty line for good format
490+
};
491+
492+
auto isCommentOrEmpty = [](const std::string &Line) {
493+
return Line.empty() || Line[0] == '#';
494+
};
495+
496+
while (std::getline(InFile, Line)) {
497+
// Insert the compatibility definition block after the first comment section
498+
if (!Inserted && !isCommentOrEmpty(Line)) {
499+
Lines.insert(Lines.end(), CompatibilityBlock.begin(),
500+
CompatibilityBlock.end());
501+
Inserted = true;
502+
}
503+
Lines.push_back(Line);
504+
}
505+
InFile.close();
506+
507+
std::ofstream OutFile(CmakeHelpFile);
508+
if (!OutFile) {
509+
std::string ErrMsg = "Failed to write to file: " + CmakeHelpFile;
510+
ShowStatus(MigrationErrorReadWriteCMakeHelperFile, std::move(ErrMsg));
511+
dpctExit(MigrationErrorReadWriteCMakeHelperFile);
512+
}
513+
for (const auto &Line : Lines) {
514+
OutFile << Line << "\n";
515+
}
516+
OutFile.close();
517+
}
518+
466519
static void loadMainSrcFileInfo(clang::tooling::UnifiedPath OutRoot) {
467520
std::string YamlFilePath = appendPath(OutRoot.getCanonicalPath().str(),
468521
DpctGlobalInfo::getYamlFileName());
@@ -471,7 +524,16 @@ static void loadMainSrcFileInfo(clang::tooling::UnifiedPath OutRoot) {
471524
if (loadFromYaml(YamlFilePath, *PreTU) != 0) {
472525
llvm::errs() << getLoadYamlFailWarning(YamlFilePath);
473526
}
527+
528+
if (MigrateBuildScriptOnly || DpctGlobalInfo::migrateCMakeScripts()) {
529+
std::string Major = PreTU->SDKVersionMajor;
530+
std::string Minor = PreTU->SDKVersionMinor;
531+
if (!Major.empty() && !Minor.empty()) {
532+
updateCompatibilityVersionInfo(OutRoot, Major, Minor);
533+
}
534+
}
474535
}
536+
475537
for (auto &Entry : PreTU->MainSourceFilesDigest) {
476538
if (Entry.HasCUDASyntax)
477539
MainSrcFilesHasCudaSyntex.insert(Entry.MainSourceFile);

clang/lib/DPCT/ErrorHandle/Error.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ void ShowStatus(int Status, std::string Message) {
220220
case MigrationErrorInvalidInstallPath:
221221
StatusString = "Error: " + Message + " not found.";
222222
break;
223+
case MigrationErrorReadWriteCMakeHelperFile:
224+
StatusString =
225+
"Error: " + Message + ". Please check the file access permission.";
226+
break;
223227
default:
224228
DpctLog() << "Unknown error.\n";
225229
dpctExit(-1);

clang/lib/DPCT/ErrorHandle/Error.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ enum ProcessStatus {
6767
MigrationErrorCannotWrite = -52,
6868
MigratePythonBuildScriptOnlyNotSpecifed = -53,
6969
MigratePythonBuildScriptSpecifiedButPythonRuleFileNotSpecified = -54,
70+
MigrationErrorReadWriteCMakeHelperFile = -55,
7071
};
7172

7273
namespace clang {

clang/lib/DPCT/IncMigration/ExternalReplacement.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ int save2Yaml(
6262
}
6363

6464
TUR.DpctVersion = clang::dpct::getDpctVersionStr();
65+
66+
auto Ver = clang::getCudaVersionPair(DpctGlobalInfo::getSDKVersion());
67+
TUR.SDKVersionMajor = std::to_string(Ver.first);
68+
TUR.SDKVersionMinor = std::to_string(Ver.second);
69+
6570
TUR.OptionMap = clang::dpct::DpctGlobalInfo::getCurrentOptMap();
6671

6772
YAMLOut << TUR;

clang/lib/DPCT/RuleInfra/APINames_removed.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
8+
// clang-format off
89
ENTRY(cublasInit, "this functionality is redundant in SYCL.")
910
ENTRY(cublasShutdown, "this functionality is redundant in SYCL.")
1011
ENTRY(cublasGetError, "this functionality is redundant in SYCL.")
@@ -42,4 +43,8 @@ ENTRY(cudaProfilerStop, "SYCL currently does not support this fun
4243
ENTRY(cuFuncSetAttribute, "SYCL currently does not support setting kernel function attributes")
4344
ENTRY(cuGetExportTable, "SYCL does not provide a standard API to export internal runtime or driver API. Check and implement the functionality corresponding to the function of the first parameter `const void **table` populated by the API.")
4445

46+
ENTRY(cuDevicePrimaryCtxSetFlags_v2, "SYCL currently does not support setting device context flags.")
47+
ENTRY(cuDevicePrimaryCtxGetState, "SYCL currently does not support querying device context flags.")
48+
4549
ENTRY(cudaGraphicsResourceSetMapFlags, "this functionality is deprecated in DX12 and hence is not supported in SYCL.")
50+
// clang-format on

0 commit comments

Comments
 (0)