From e85c7a7fc7cd48349905d543884300e1e726174a Mon Sep 17 00:00:00 2001 From: apd10 <57877560+apd10@users.noreply.github.com> Date: Wed, 30 Mar 2022 22:45:41 -0500 Subject: [PATCH] Bugfix in ptxas path. (#487) 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 --- lib/driver/llvm.cc | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/driver/llvm.cc b/lib/driver/llvm.cc index 726ac9a97..463f45712 100644 --- a/lib/driver/llvm.cc +++ b/lib/driver/llvm.cc @@ -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 rets; std::string ret; // search pathes for ptxas std::vector ptxas_prefixes = {"", "/usr/local/cuda/bin/"}; @@ -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()) @@ -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; }