forked from OSchip/llvm-project
[hip] Fix HIP version parsing.
- Need trimming before parsing major or minor version numbers. This's required due to the different line ending on Windows. - In addition, the integer conversion may fail due to invalid char. Return that parsing function return `true` when the parsing fails. Differential Revision: https://reviews.llvm.org/D93587
This commit is contained in:
parent
f9190c8681
commit
2a29ce3034
|
@ -88,23 +88,30 @@ void RocmInstallationDetector::scanLibDevicePath(llvm::StringRef Path) {
|
|||
}
|
||||
}
|
||||
|
||||
void RocmInstallationDetector::ParseHIPVersionFile(llvm::StringRef V) {
|
||||
// Parse and extract version numbers from `.hipVersion`. Return `true` if
|
||||
// the parsing fails.
|
||||
bool RocmInstallationDetector::parseHIPVersionFile(llvm::StringRef V) {
|
||||
SmallVector<StringRef, 4> VersionParts;
|
||||
V.split(VersionParts, '\n');
|
||||
unsigned Major;
|
||||
unsigned Minor;
|
||||
unsigned Major = ~0U;
|
||||
unsigned Minor = ~0U;
|
||||
for (auto Part : VersionParts) {
|
||||
auto Splits = Part.split('=');
|
||||
if (Splits.first == "HIP_VERSION_MAJOR")
|
||||
Splits.second.getAsInteger(0, Major);
|
||||
else if (Splits.first == "HIP_VERSION_MINOR")
|
||||
Splits.second.getAsInteger(0, Minor);
|
||||
else if (Splits.first == "HIP_VERSION_PATCH")
|
||||
auto Splits = Part.rtrim().split('=');
|
||||
if (Splits.first == "HIP_VERSION_MAJOR") {
|
||||
if (Splits.second.getAsInteger(0, Major))
|
||||
return true;
|
||||
} else if (Splits.first == "HIP_VERSION_MINOR") {
|
||||
if (Splits.second.getAsInteger(0, Minor))
|
||||
return true;
|
||||
} else if (Splits.first == "HIP_VERSION_PATCH")
|
||||
VersionPatch = Splits.second.str();
|
||||
}
|
||||
if (Major == ~0U || Minor == ~0U)
|
||||
return true;
|
||||
VersionMajorMinor = llvm::VersionTuple(Major, Minor);
|
||||
DetectedVersion =
|
||||
(Twine(Major) + "." + Twine(Minor) + "." + VersionPatch).str();
|
||||
return false;
|
||||
}
|
||||
|
||||
// For candidate specified by --rocm-path we do not do strict check.
|
||||
|
@ -290,7 +297,8 @@ void RocmInstallationDetector::detectHIPRuntime() {
|
|||
continue;
|
||||
|
||||
if (HIPVersionArg.empty() && VersionFile)
|
||||
ParseHIPVersionFile((*VersionFile)->getBuffer());
|
||||
if (parseHIPVersionFile((*VersionFile)->getBuffer()))
|
||||
continue;
|
||||
|
||||
HasHIPRuntime = true;
|
||||
return;
|
||||
|
|
|
@ -103,7 +103,7 @@ private:
|
|||
}
|
||||
|
||||
void scanLibDevicePath(llvm::StringRef Path);
|
||||
void ParseHIPVersionFile(llvm::StringRef V);
|
||||
bool parseHIPVersionFile(llvm::StringRef V);
|
||||
SmallVector<Candidate, 4> getInstallationPathCandidates();
|
||||
|
||||
public:
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
# Auto-generated by cmake
|
||||
HIP_VERSION_MAJOR=3
|
||||
# NOTE: The trailing whitespace is added on purpose to verify that these
|
||||
# whitespaces are trimmed before paring.
|
||||
HIP_VERSION_MAJOR=3
|
||||
HIP_VERSION_MINOR=6
|
||||
HIP_VERSION_PATCH=20214-a2917cd
|
||||
|
|
Loading…
Reference in New Issue