Skip to content

Commit

Permalink
Merge pull request #31 from david-salinas/rocm-path-fix
Browse files Browse the repository at this point in the history
Respect --rocm-path option over ROCM_PATH environment variable
  • Loading branch information
david-salinas authored Nov 19, 2022
2 parents ed44d8b + 7a8951e commit 359504a
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 60 deletions.
106 changes: 57 additions & 49 deletions amd/hipcc/src/hipBin_amd.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ HipBinAmd::HipBinAmd() {
platformInfo.runtime = rocclr;
platformInfo.compiler = clang;
platformInfoAMD_ = platformInfo;
constructRocclrHomePath(); // constructs RocclrHomePath
constructHsaPath(); // constructs hsa path
constructCompilerPath();
}

// returns the Rocclr Home path
Expand Down Expand Up @@ -241,9 +238,6 @@ void HipBinAmd::constructCompilerPath() {
hipClangPath_ = complierPath;
}




// returns clang path.
const string& HipBinAmd::getCompilerPath() const {
return hipClangPath_;
Expand Down Expand Up @@ -388,8 +382,6 @@ bool HipBinAmd::detectPlatform() {
return detected;
}



string HipBinAmd::getHipLibPath() const {
string hipLibPath;
const EnvVariables& env = getEnvVariables();
Expand Down Expand Up @@ -537,47 +529,10 @@ void HipBinAmd::executeHipCCCmd(vector<string> argv) {
}

string HIPLDARCHFLAGS;

initializeHipCXXFlags();
initializeHipCFlags();
initializeHipLdFlags();
string HIPCXXFLAGS, HIPCFLAGS, HIPLDFLAGS;
HIPCFLAGS = getHipCFlags();
HIPCXXFLAGS = getHipCXXFlags();
HIPLDFLAGS = getHipLdFlags();
string hipLibPath;
string hipIncludePath, deviceLibPath;
hipLibPath = getHipLibPath();
const string& roccmPath = getRoccmPath();
const string& hipPath = getHipPath();
const PlatformInfo& platformInfo = getPlatformInfo();
const string& rocclrHomePath = getRocclrHomePath();
const string& hipClangPath = getCompilerPath();
hipIncludePath = getHipInclude();
deviceLibPath = getDeviceLibPath();
const string& hipVersion = getHipVersion();
if (verbose & 0x2) {
cout << "HIP_PATH=" << hipPath << endl;
cout << "HIP_PLATFORM=" << PlatformTypeStr(platformInfo.platform) <<endl;
cout << "HIP_COMPILER=" << CompilerTypeStr(platformInfo.compiler) <<endl;
cout << "HIP_RUNTIME=" << RuntimeTypeStr(platformInfo.runtime) <<endl;
cout << "ROCM_PATH=" << roccmPath << endl;
cout << "HIP_ROCCLR_HOME="<< rocclrHomePath << endl;
cout << "HIP_CLANG_PATH=" << hipClangPath <<endl;
cout << "HIP_INCLUDE_PATH="<< hipIncludePath <<endl;
cout << "HIP_LIB_PATH="<< hipLibPath <<endl;
cout << "DEVICE_LIB_PATH="<< deviceLibPath <<endl;
}

if (verbose & 0x4) {
cout << "hipcc-args: ";
for (unsigned int i = 1; i< argv.size(); i++) {
cout << argv.at(i) << " ";
}
cout << endl;
}


// ARGV Processing Loop
// TODO(hipcc): create a proper Options Processing function/routine
for (unsigned int argcount = 1; argcount < argv.size(); argcount++) {
// Save $arg, it can get changed in the loop.
string arg = argv.at(argcount);
Expand Down Expand Up @@ -613,6 +568,11 @@ void HipBinAmd::executeHipCCCmd(vector<string> argv) {
setStdLib = 1;
}

// Process --rocm-path option
const string& rocmPathOption = "--rocm-path=";
if (arg.compare(0,rocmPathOption.length(),rocmPathOption) == 0)
rocm_pathOption_ = arg.substr(rocmPathOption.length());

// Check target selection option: --offload-arch= and --amdgpu-target=...
for (unsigned int i = 0; i <targetOpts.size(); i++) {
string targetOpt = targetOpts.at(i);
Expand Down Expand Up @@ -949,8 +909,56 @@ void HipBinAmd::executeHipCCCmd(vector<string> argv) {
if (!swallowArg)
toolArgs += " " + arg;
prevArg = arg;
} // end of for loop
// No AMDGPU target specified at commandline. So look for HCC_AMDGPU_TARGET
} // end of ARGV Processing Loop

// now construct Paths ...
constructRoccmPath(); // constructs Roccm Path
constructHipPath(); // constructs HIP Path
readHipVersion(); // stores the hip version
constructCompilerPath();
constructRocclrHomePath();
constructHsaPath();

initializeHipCXXFlags();
initializeHipCFlags();
initializeHipLdFlags();
HIPCFLAGS = getHipCFlags();
HIPCXXFLAGS = getHipCXXFlags();
HIPLDFLAGS = getHipLdFlags();

string hipLibPath;
string hipIncludePath, deviceLibPath;
hipLibPath = getHipLibPath();
const string& roccmPath = getRoccmPath();
const string& hipPath = getHipPath();
const PlatformInfo& platformInfo = getPlatformInfo();
const string& rocclrHomePath = getRocclrHomePath();
const string& hipClangPath = getCompilerPath();
hipIncludePath = getHipInclude();
deviceLibPath = getDeviceLibPath();
const string& hipVersion = getHipVersion();
if (verbose & 0x2) {
cout << "HIP_PATH=" << hipPath << endl;
cout << "HIP_PLATFORM=" << PlatformTypeStr(platformInfo.platform) <<endl;
cout << "HIP_COMPILER=" << CompilerTypeStr(platformInfo.compiler) <<endl;
cout << "HIP_RUNTIME=" << RuntimeTypeStr(platformInfo.runtime) <<endl;
cout << "ROCM_PATH=" << roccmPath << endl;
cout << "HIP_ROCCLR_HOME="<< rocclrHomePath << endl;
cout << "HIP_CLANG_PATH=" << hipClangPath <<endl;
cout << "HIP_INCLUDE_PATH="<< hipIncludePath <<endl;
cout << "HIP_LIB_PATH="<< hipLibPath <<endl;
cout << "DEVICE_LIB_PATH="<< deviceLibPath <<endl;
}

if (verbose & 0x4) {
cout << "hipcc-args: ";
for (unsigned int i = 1; i< argv.size(); i++) {
cout << argv.at(i) << " ";
}
cout << endl;
}

// No AMDGPU target specified at commandline. So look for HCC_AMDGPU_TARGET
if (default_amdgpu_target == 1) {
if (!var.hccAmdGpuTargetEnv_.empty()) {
targetsStr = var.hccAmdGpuTargetEnv_;
Expand Down
30 changes: 19 additions & 11 deletions amd/hipcc/src/hipBin_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,30 +239,30 @@ class HipBinBase {
void printUsage() const;
bool canRunCompiler(string exeName, string& cmdOut);
HipBinCommand gethipconfigCmd(string argument);
const string& getrocm_pathOption() const;

protected:
// hipBinUtilPtr used by derived platforms
// so therefore its protected
HipBinUtil* hipBinUtilPtr_;

private:
EnvVariables envVariables_, variables_;
OsType osInfo_;
string hipVersion_;
string rocm_pathOption_ = "";
void readOSInfo();
void readEnvVariables();
void constructHipPath();
void constructRoccmPath();
void readHipVersion();

private:
EnvVariables envVariables_, variables_;
OsType osInfo_;
string hipVersion_;

};

HipBinBase::HipBinBase() {
hipBinUtilPtr_ = hipBinUtilPtr_->getInstance();
readOSInfo(); // detects if windows or linux
readEnvVariables(); // reads the envirnoment variables
constructHipPath(); // constructs HIP Path
constructRoccmPath(); // constructs Roccm Path
readHipVersion(); // stores the hip version
readEnvVariables(); // reads the environment variables
}

// detects the OS information
Expand Down Expand Up @@ -331,7 +331,13 @@ void HipBinBase::constructHipPath() {

// constructs the ROCM path
void HipBinBase::constructRoccmPath() {
if (envVariables_.roccmPathEnv_.empty()) {
// we need to use --rocm-path option
string rocm_path_name = getrocm_pathOption();

// chose the --rocm-path option first, if specified.
if (!rocm_path_name.empty())
variables_.roccmPathEnv_ = rocm_path_name;
else if (envVariables_.roccmPathEnv_.empty()) {
const string& hipPath = getHipPath();
fs::path roccm_path(hipPath);
roccm_path = roccm_path.parent_path();
Expand All @@ -340,7 +346,6 @@ void HipBinBase::constructRoccmPath() {
if (!fs::exists(rocm_agent_enumerator_file)) {
roccm_path = "/opt/rocm";
}
variables_.roccmPathEnv_ = roccm_path.string();
} else {
variables_.roccmPathEnv_ = envVariables_.roccmPathEnv_;}
}
Expand Down Expand Up @@ -521,5 +526,8 @@ HipBinCommand HipBinBase::gethipconfigCmd(string argument) {
return full; // default is full. return full if no commands are matched
}

const string& HipBinBase::getrocm_pathOption() const {
return rocm_pathOption_;
}

#endif // SRC_HIPBIN_BASE_H_

0 comments on commit 359504a

Please sign in to comment.