Skip to content

Commit 359504a

Browse files
Merge pull request #31 from david-salinas/rocm-path-fix
Respect --rocm-path option over ROCM_PATH environment variable
2 parents ed44d8b + 7a8951e commit 359504a

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
@@ -85,9 +85,6 @@ HipBinAmd::HipBinAmd() {
8585
platformInfo.runtime = rocclr;
8686
platformInfo.compiler = clang;
8787
platformInfoAMD_ = platformInfo;
88-
constructRocclrHomePath(); // constructs RocclrHomePath
89-
constructHsaPath(); // constructs hsa path
90-
constructCompilerPath();
9188
}
9289

9390
// returns the Rocclr Home path
@@ -241,9 +238,6 @@ void HipBinAmd::constructCompilerPath() {
241238
hipClangPath_ = complierPath;
242239
}
243240

244-
245-
246-
247241
// returns clang path.
248242
const string& HipBinAmd::getCompilerPath() const {
249243
return hipClangPath_;
@@ -388,8 +382,6 @@ bool HipBinAmd::detectPlatform() {
388382
return detected;
389383
}
390384

391-
392-
393385
string HipBinAmd::getHipLibPath() const {
394386
string hipLibPath;
395387
const EnvVariables& env = getEnvVariables();
@@ -537,47 +529,10 @@ void HipBinAmd::executeHipCCCmd(vector<string> argv) {
537529
}
538530

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

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

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

amd/hipcc/src/hipBin_base.h

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

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

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

268268
// detects the OS information
@@ -331,7 +331,13 @@ void HipBinBase::constructHipPath() {
331331

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

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

525533
#endif // SRC_HIPBIN_BASE_H_

0 commit comments

Comments
 (0)