Skip to content

Commit 7a8951e

Browse files
author
David Salinas
committed
Respect --rocm-path option over ROCM_PATH environment variable
1 parent 55c9432 commit 7a8951e

File tree

2 files changed

+76
-60
lines changed

2 files changed

+76
-60
lines changed

amd/hipcc/src/hipBin_amd.h

Lines changed: 57 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ HipBinAmd::HipBinAmd() {
8484
platformInfo.runtime = rocclr;
8585
platformInfo.compiler = clang;
8686
platformInfoAMD_ = platformInfo;
87-
constructRocclrHomePath(); // constructs RocclrHomePath
88-
constructHsaPath(); // constructs hsa path
89-
constructCompilerPath();
9087
}
9188

9289
// returns the Rocclr Home path
@@ -240,9 +237,6 @@ void HipBinAmd::constructCompilerPath() {
240237
hipClangPath_ = complierPath;
241238
}
242239

243-
244-
245-
246240
// returns clang path.
247241
const string& HipBinAmd::getCompilerPath() const {
248242
return hipClangPath_;
@@ -387,8 +381,6 @@ bool HipBinAmd::detectPlatform() {
387381
return detected;
388382
}
389383

390-
391-
392384
string HipBinAmd::getHipLibPath() const {
393385
string hipLibPath;
394386
const EnvVariables& env = getEnvVariables();
@@ -536,47 +528,10 @@ void HipBinAmd::executeHipCCCmd(vector<string> argv) {
536528
}
537529

538530
string HIPLDARCHFLAGS;
539-
540-
initializeHipCXXFlags();
541-
initializeHipCFlags();
542-
initializeHipLdFlags();
543531
string HIPCXXFLAGS, HIPCFLAGS, HIPLDFLAGS;
544-
HIPCFLAGS = getHipCFlags();
545-
HIPCXXFLAGS = getHipCXXFlags();
546-
HIPLDFLAGS = getHipLdFlags();
547-
string hipLibPath;
548-
string hipIncludePath, deviceLibPath;
549-
hipLibPath = getHipLibPath();
550-
const string& roccmPath = getRoccmPath();
551-
const string& hipPath = getHipPath();
552-
const PlatformInfo& platformInfo = getPlatformInfo();
553-
const string& rocclrHomePath = getRocclrHomePath();
554-
const string& hipClangPath = getCompilerPath();
555-
hipIncludePath = getHipInclude();
556-
deviceLibPath = getDeviceLibPath();
557-
const string& hipVersion = getHipVersion();
558-
if (verbose & 0x2) {
559-
cout << "HIP_PATH=" << hipPath << endl;
560-
cout << "HIP_PLATFORM=" << PlatformTypeStr(platformInfo.platform) <<endl;
561-
cout << "HIP_COMPILER=" << CompilerTypeStr(platformInfo.compiler) <<endl;
562-
cout << "HIP_RUNTIME=" << RuntimeTypeStr(platformInfo.runtime) <<endl;
563-
cout << "ROCM_PATH=" << roccmPath << endl;
564-
cout << "HIP_ROCCLR_HOME="<< rocclrHomePath << endl;
565-
cout << "HIP_CLANG_PATH=" << hipClangPath <<endl;
566-
cout << "HIP_INCLUDE_PATH="<< hipIncludePath <<endl;
567-
cout << "HIP_LIB_PATH="<< hipLibPath <<endl;
568-
cout << "DEVICE_LIB_PATH="<< deviceLibPath <<endl;
569-
}
570-
571-
if (verbose & 0x4) {
572-
cout << "hipcc-args: ";
573-
for (unsigned int i = 1; i< argv.size(); i++) {
574-
cout << argv.at(i) << " ";
575-
}
576-
cout << endl;
577-
}
578-
579532

533+
// ARGV Processing Loop
534+
// TODO(hipcc): create a proper Options Processing function/routine
580535
for (unsigned int argcount = 1; argcount < argv.size(); argcount++) {
581536
// Save $arg, it can get changed in the loop.
582537
string arg = argv.at(argcount);
@@ -612,6 +567,11 @@ void HipBinAmd::executeHipCCCmd(vector<string> argv) {
612567
setStdLib = 1;
613568
}
614569

570+
// Process --rocm-path option
571+
const string& rocmPathOption = "--rocm-path=";
572+
if (arg.compare(0,rocmPathOption.length(),rocmPathOption) == 0)
573+
rocm_pathOption_ = arg.substr(rocmPathOption.length());
574+
615575
// Check target selection option: --offload-arch= and --amdgpu-target=...
616576
for (unsigned int i = 0; i <targetOpts.size(); i++) {
617577
string targetOpt = targetOpts.at(i);
@@ -948,8 +908,56 @@ void HipBinAmd::executeHipCCCmd(vector<string> argv) {
948908
if (!swallowArg)
949909
toolArgs += " " + arg;
950910
prevArg = arg;
951-
} // end of for loop
952-
// No AMDGPU target specified at commandline. So look for HCC_AMDGPU_TARGET
911+
} // end of ARGV Processing Loop
912+
913+
// now construct Paths ...
914+
constructRoccmPath(); // constructs Roccm Path
915+
constructHipPath(); // constructs HIP Path
916+
readHipVersion(); // stores the hip version
917+
constructCompilerPath();
918+
constructRocclrHomePath();
919+
constructHsaPath();
920+
921+
initializeHipCXXFlags();
922+
initializeHipCFlags();
923+
initializeHipLdFlags();
924+
HIPCFLAGS = getHipCFlags();
925+
HIPCXXFLAGS = getHipCXXFlags();
926+
HIPLDFLAGS = getHipLdFlags();
927+
928+
string hipLibPath;
929+
string hipIncludePath, deviceLibPath;
930+
hipLibPath = getHipLibPath();
931+
const string& roccmPath = getRoccmPath();
932+
const string& hipPath = getHipPath();
933+
const PlatformInfo& platformInfo = getPlatformInfo();
934+
const string& rocclrHomePath = getRocclrHomePath();
935+
const string& hipClangPath = getCompilerPath();
936+
hipIncludePath = getHipInclude();
937+
deviceLibPath = getDeviceLibPath();
938+
const string& hipVersion = getHipVersion();
939+
if (verbose & 0x2) {
940+
cout << "HIP_PATH=" << hipPath << endl;
941+
cout << "HIP_PLATFORM=" << PlatformTypeStr(platformInfo.platform) <<endl;
942+
cout << "HIP_COMPILER=" << CompilerTypeStr(platformInfo.compiler) <<endl;
943+
cout << "HIP_RUNTIME=" << RuntimeTypeStr(platformInfo.runtime) <<endl;
944+
cout << "ROCM_PATH=" << roccmPath << endl;
945+
cout << "HIP_ROCCLR_HOME="<< rocclrHomePath << endl;
946+
cout << "HIP_CLANG_PATH=" << hipClangPath <<endl;
947+
cout << "HIP_INCLUDE_PATH="<< hipIncludePath <<endl;
948+
cout << "HIP_LIB_PATH="<< hipLibPath <<endl;
949+
cout << "DEVICE_LIB_PATH="<< deviceLibPath <<endl;
950+
}
951+
952+
if (verbose & 0x4) {
953+
cout << "hipcc-args: ";
954+
for (unsigned int i = 1; i< argv.size(); i++) {
955+
cout << argv.at(i) << " ";
956+
}
957+
cout << endl;
958+
}
959+
960+
// No AMDGPU target specified at commandline. So look for HCC_AMDGPU_TARGET
953961
if (default_amdgpu_target == 1) {
954962
if (!var.hccAmdGpuTargetEnv_.empty()) {
955963
targetsStr = var.hccAmdGpuTargetEnv_;

amd/hipcc/src/hipBin_base.h

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -238,30 +238,30 @@ class HipBinBase {
238238
void printUsage() const;
239239
bool canRunCompiler(string exeName, string& cmdOut);
240240
HipBinCommand gethipconfigCmd(string argument);
241+
const string& getrocm_pathOption() const;
241242

242243
protected:
243244
// hipBinUtilPtr used by derived platforms
244245
// so therefore its protected
245246
HipBinUtil* hipBinUtilPtr_;
246-
247-
private:
248-
EnvVariables envVariables_, variables_;
249-
OsType osInfo_;
250-
string hipVersion_;
247+
string rocm_pathOption_ = "";
251248
void readOSInfo();
252249
void readEnvVariables();
253250
void constructHipPath();
254251
void constructRoccmPath();
255252
void readHipVersion();
253+
254+
private:
255+
EnvVariables envVariables_, variables_;
256+
OsType osInfo_;
257+
string hipVersion_;
258+
256259
};
257260

258261
HipBinBase::HipBinBase() {
259262
hipBinUtilPtr_ = hipBinUtilPtr_->getInstance();
260263
readOSInfo(); // detects if windows or linux
261-
readEnvVariables(); // reads the envirnoment variables
262-
constructHipPath(); // constructs HIP Path
263-
constructRoccmPath(); // constructs Roccm Path
264-
readHipVersion(); // stores the hip version
264+
readEnvVariables(); // reads the environment variables
265265
}
266266

267267
// detects the OS information
@@ -330,7 +330,13 @@ void HipBinBase::constructHipPath() {
330330

331331
// constructs the ROCM path
332332
void HipBinBase::constructRoccmPath() {
333-
if (envVariables_.roccmPathEnv_.empty()) {
333+
// we need to use --rocm-path option
334+
string rocm_path_name = getrocm_pathOption();
335+
336+
// chose the --rocm-path option first, if specified.
337+
if (!rocm_path_name.empty())
338+
variables_.roccmPathEnv_ = rocm_path_name;
339+
else if (envVariables_.roccmPathEnv_.empty()) {
334340
const string& hipPath = getHipPath();
335341
fs::path roccm_path(hipPath);
336342
roccm_path = roccm_path.parent_path();
@@ -339,7 +345,6 @@ void HipBinBase::constructRoccmPath() {
339345
if (!fs::exists(rocm_agent_enumerator_file)) {
340346
roccm_path = "/opt/rocm";
341347
}
342-
variables_.roccmPathEnv_ = roccm_path.string();
343348
} else {
344349
variables_.roccmPathEnv_ = envVariables_.roccmPathEnv_;}
345350
}
@@ -520,5 +525,8 @@ HipBinCommand HipBinBase::gethipconfigCmd(string argument) {
520525
return full; // default is full. return full if no commands are matched
521526
}
522527

528+
const string& HipBinBase::getrocm_pathOption() const {
529+
return rocm_pathOption_;
530+
}
523531

524532
#endif // SRC_HIPBIN_BASE_H_

0 commit comments

Comments
 (0)