From 7c4a146742e469aa3382e728c1eaa35072fade8b Mon Sep 17 00:00:00 2001 From: Longlong Yao Date: Mon, 16 Dec 2024 18:46:18 -0800 Subject: [PATCH] Use /dev/dxg to detect wsl environment Since wslinfo does not exist in docker running on wsl, change the way to detect wsl environment. Change-Id: I215eb985a227caeef47483cd51818c84bf1d8a4c Signed-off-by: Longlong Yao [ROCm/rocminfo commit: 22ed708c39d38ea20d082f72ace1233900a4fb61] --- projects/rocminfo/rocminfo.cc | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/projects/rocminfo/rocminfo.cc b/projects/rocminfo/rocminfo.cc index 6d7329ad6c..af495e5d92 100755 --- a/projects/rocminfo/rocminfo.cc +++ b/projects/rocminfo/rocminfo.cc @@ -56,14 +56,9 @@ #include #include -#include -#include - #include "hsa/hsa.h" #include "hsa/hsa_ext_amd.h" -using namespace std; - #define COL_BLU "\x1B[34m" #define COL_KCYN "\x1B[36m" #define COL_GRN "\x1B[32m" @@ -233,31 +228,12 @@ std::string int_to_string(uint32_t i, return sd.str(); } -pair exec(const char* cmd) { - array buffer; - string result; - int return_code = -1; - auto pclose_wrapper = [&return_code](FILE* cmd){ return_code = pclose(cmd); }; - { // scope is important, have to make sure the ptr goes out of scope first - const unique_ptr pipe(popen(cmd, "r"), pclose_wrapper); - if (pipe) { - while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { - result += buffer.data(); - } - } - } - return make_pair(result, return_code); -} - static void DetectWSLEnvironment() { - auto process_ret = exec("which wslinfo > /dev/null 2>&1"); - if (process_ret.second) - return; - - process_ret = exec("wslinfo --msal-proxy-path"); - if (process_ret.second == 0 && - strcasestr(process_ret.first.c_str(), "msal.wsl.proxy.exe") != nullptr) { + const char *filePath = "/dev/dxg"; + FILE *file = fopen(filePath, "r"); + if (file) { printf("WSL environment detected.\n"); + fclose(file); wsl_env = true; } }