summaryrefslogtreecommitdiff
blob: 5d0b2ed284bdb10377a89861f5aefde0f222c601 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/sys/module/amdgpu instead of lsmod for builtin amdgpu kernel module

https://github.com/RadeonOpenCompute/rocminfo/pull/43
https://github.com/RadeonOpenCompute/rocminfo/issues/42
From ea4f017ed035928b1970e2589b02ec9b348c863e Mon Sep 17 00:00:00 2001
From: YiyangWu <xgreenlandforwyy@gmail.com>
Date: Wed, 18 Aug 2021 21:05:20 +0800
Subject: [PATCH] Check /sys/module/amdgpu for ROCk instead of lsmod

Closes: #42

Signed-off-by: YiyangWu <xgreenlandforwyy@gmail.com>
---
 rocminfo.cc | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/rocminfo.cc b/rocminfo.cc
index 871f406..58c847d 100755
--- a/rocminfo.cc
+++ b/rocminfo.cc
@@ -995,6 +995,8 @@ AcquireAndDisplayAgentInfo(hsa_agent_t agent, void* data) {
   err = AcquireAgentInfo(agent, &agent_i);
   RET_IF_HSA_ERR(err);
 
+  std::string ind(kIndentSize, ' ');
+
   printLabel("*******", true);
   std::string agent_ind("Agent ");
   agent_ind += std::to_string(*agent_number).c_str();
@@ -1031,16 +1033,16 @@ AcquireAndDisplayAgentInfo(hsa_agent_t agent, void* data) {
 
 int CheckInitialState(void) {
   // Check kernel module for ROCk is loaded
-  FILE *fd = popen("lsmod | grep amdgpu", "r");
-  char buf[16];
-  if (fread (buf, 1, sizeof (buf), fd) == 0) {
+  int module_dir;
+  module_dir = open("/sys/module/amdgpu", O_DIRECTORY);
+  if (module_dir < 0) {
     printf("%sROCk module is NOT loaded, possibly no GPU devices%s\n",
                                                           COL_RED, COL_RESET);
     return -1;
   } else {
     printf("%sROCk module is loaded%s\n", COL_WHT, COL_RESET);
+	close(module_dir);
   }
-  pclose(fd);
 
   // Check if user belongs to the group for /dev/kfd (e.g. "video" or
   // "render")