From 2db5d50c54e65f812c83529ab752dd2a8d75d105 Mon Sep 17 00:00:00 2001 From: Tom Rix Date: Sun, 1 Sep 2024 13:09:33 -0700 Subject: [PATCH] Improve finding rocm_agent_enumerator On Fedora rocm_agent_enumerator is part of the distro and installed to /usr/bin. So it will not be located in /opt/rocm/bin/. Add some heuristics to find it. First try the environment variable ROCM_PATH Then /opt/rocm Last /usr Signed-off-by: Tom Rix --- catch/hipTestMain/hip_test_context.cc | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/catch/hipTestMain/hip_test_context.cc b/catch/hipTestMain/hip_test_context.cc index 05d71fb1a..440173a4b 100644 --- a/catch/hipTestMain/hip_test_context.cc +++ b/catch/hipTestMain/hip_test_context.cc @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -37,10 +38,29 @@ std::string TestContext::substringFound(std::vector list, std::stri std::string TestContext::getCurrentArch() { #if HT_LINUX - const char* cmd = "/opt/rocm/bin/rocm_agent_enumerator | sort -u | xargs | sed -e 's/ /;/g'"; + char* cmd; + size_t size_cmd = 128; + if (getenv("ROCM_PATH")) { + char *rocm_path = getenv("ROCM_PATH"); + size_cmd += strlen(rocm_path); + cmd = (char *) malloc (size_cmd); + snprintf(cmd, size_cmd, "%s", rocm_path); + } else { + cmd = (char *) malloc (size_cmd); + DIR *dir = opendir("/opt/rocm"); + if (dir) { + snprintf(cmd, size_cmd, "/opt/rocm"); + closedir(dir); + } else { + snprintf(cmd, size_cmd, "/usr"); + } + } + strncat(cmd, "/bin/rocm_agent_enumerator | sort -u | xargs | sed -e 's/ /;/g'", size_cmd); + std::array buffer; std::string result; std::unique_ptr pipe(popen(cmd, "r"), pclose); + free(cmd); if (!pipe) { printf("popen() failed!"); return "";