Skip to content

Commit

Permalink
Bugfix in ptxas path. (#487)
Browse files Browse the repository at this point in the history
Bug: "ret" value is destroyed when a failing "ptxas --version" is run
overwriting the previous valid "ret" value.

Fix: keep rets only for those runs which are successful. Pick the first
one
  • Loading branch information
apd10 authored and daadaada committed Apr 12, 2022
1 parent 2aba5f4 commit d4804e7
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions lib/driver/llvm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ static bool find_and_replace(std::string& str, const std::string& begin, const s
}

std::string path_to_ptxas(int& version) {
std::vector<std::string> rets;
std::string ret;
// search pathes for ptxas
std::vector<std::string> ptxas_prefixes = {"", "/usr/local/cuda/bin/"};
Expand All @@ -105,8 +106,10 @@ std::string path_to_ptxas(int& version) {
for(std::string prefix: ptxas_prefixes){
std::string ptxas = prefix + "ptxas";
bool works = tools::exec(ptxas + " --version 2>&1", ret) == 0;
if(works)
if(works) {
working_ptxas.push_back(ptxas);
rets.push_back(ret);
}
}
// error if no working ptxas was found
if(working_ptxas.empty())
Expand All @@ -116,13 +119,20 @@ std::string path_to_ptxas(int& version) {
// parse version
std::regex version_regex("release (\\d+)\\.(\\d+)");
std::smatch match;
if(std::regex_search(ret, match, version_regex)){
int major = std::stoi(match[1]);
int minor = std::stoi(match[2]);
version = major*1000 + minor*10;
bool found = false;
// currently choosing the first ptxas. Other logics can be implemented in future
for(std::string ret : rets) {
if(std::regex_search(ret, match, version_regex)){
int major = std::stoi(match[1]);
int minor = std::stoi(match[2]);
version = major*1000 + minor*10;
found = true;
break;
}
}
if ( not found) {
throw std::runtime_error("Error in parsing version");
}
else
throw std::runtime_error("couldn't parse ptxas version: " + ret);
return ptxas;
}

Expand Down

0 comments on commit d4804e7

Please sign in to comment.