From fa6e2694ce79274175b3e9e26bfbd254192ddb21 Mon Sep 17 00:00:00 2001 From: Johannes M Dieterich Date: Mon, 8 Nov 2021 10:18:12 -0600 Subject: [PATCH 1/3] Fix rocminfo when run within docker environments. Currently, rocminfo will fail when executed inside a docker container due to a missing ROCk module. This has impacts on rocprofiler use. However, a missing ROCk module is expected within a docker environment. Fix this by searching for the "docker" string within the self-cgroups. If it is found, we do not error on a missing ROCk module. --- rocminfo.cc | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/rocminfo.cc b/rocminfo.cc index ee01f60..fc405a3 100755 --- a/rocminfo.cc +++ b/rocminfo.cc @@ -51,6 +51,7 @@ #include #include +#include #include #include #include @@ -1040,7 +1041,24 @@ int CheckInitialState(void) { if (fread (buf, 1, sizeof (buf), fd) <= 0) { printf("%sROCk module is NOT loaded, possibly no GPU devices%s\n", COL_RED, COL_RESET); - return -1; + // Check if rocminfo is executed within a docker environment (where this is OK) + std::ifstream cgroups( "/proc/self/cgroup" ); + if (cgroups) { + std::stringstream buffer; + buffer << cgroups.rdbuf(); + cgroups.close(); + + std::string line; + bool docker_env = false; + while ( std::getline(buffer, line) ) { + if ( line.find( "docker" )) { + docker_env = true; + printf("Docker environment detected - missing ROCk module expected.\n"); + break; + } + } + if ( !docker_env ) return -1; + } } else { printf("%sROCk module is loaded%s\n", COL_WHT, COL_RESET); } From d78e31cd9f74cb9da1a63adafc5a49767492e5bd Mon Sep 17 00:00:00 2001 From: Johannes M Dieterich Date: Mon, 8 Nov 2021 10:21:24 -0600 Subject: [PATCH 2/3] Fix whitespace --- rocminfo.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rocminfo.cc b/rocminfo.cc index fc405a3..8b7bfee 100755 --- a/rocminfo.cc +++ b/rocminfo.cc @@ -1050,7 +1050,7 @@ int CheckInitialState(void) { std::string line; bool docker_env = false; - while ( std::getline(buffer, line) ) { + while ( std::getline(buffer, line) ) { if ( line.find( "docker" )) { docker_env = true; printf("Docker environment detected - missing ROCk module expected.\n"); From 27d7bfc8be3f1d5b887198efc87b35a5b0f809e9 Mon Sep 17 00:00:00 2001 From: Johannes M Dieterich Date: Mon, 8 Nov 2021 10:23:01 -0600 Subject: [PATCH 3/3] Catch one more case --- rocminfo.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rocminfo.cc b/rocminfo.cc index 8b7bfee..4d94b25 100755 --- a/rocminfo.cc +++ b/rocminfo.cc @@ -1058,6 +1058,9 @@ int CheckInitialState(void) { } } if ( !docker_env ) return -1; + } else { + // this is certainly weird - error + return -1; } } else { printf("%sROCk module is loaded%s\n", COL_WHT, COL_RESET);