Correct check for video group membership

* Continue with rocminfo even if video and kfd check fail.
* Color code informational lines (white) and warnings (red)

Change-Id: I739034c932fffca0924abc93ae9a929664a3e182


[ROCm/rocminfo commit: 141592e4f3]
Tento commit je obsažen v:
Chris Freehill
2019-07-15 14:02:12 -05:00
rodič 4e9009867d
revize 2fe33cf4e3
+76 -42
Zobrazit soubor
@@ -46,8 +46,9 @@
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <grp.h> #include <grp.h>
#include <unistd.h>
#include <pwd.h>
#include <stdio.h>
#include <vector> #include <vector>
#include <string> #include <string>
#include <sstream> #include <sstream>
@@ -55,27 +56,31 @@
#include "hsa/hsa.h" #include "hsa/hsa.h"
#include "hsa/hsa_ext_amd.h" #include "hsa/hsa_ext_amd.h"
#define RET_IF_HSA_INIT_ERR(err) { \ #define COL_BLU "\x1B[34m"
if ((err) != HSA_STATUS_SUCCESS) { \ #define COL_KCYN "\x1B[36m"
CheckInitError(err); \ #define COL_GRN "\x1B[32m"
RET_IF_HSA_ERR(err); \ #define COL_NRM "\x1B[0m"
} \ #define COL_RED "\x1B[31m"
} #define COL_MAG "\x1B[35m"
#define COL_WHT "\x1B[37m"
#define COL_YEL "\x1B[33m"
#define COL_RESET "\033[0m"
#define RET_IF_HSA_ERR(err) { \ #define RET_IF_HSA_ERR(err) { \
if ((err) != HSA_STATUS_SUCCESS) { \ if ((err) != HSA_STATUS_SUCCESS) { \
char err_val[12]; \ char err_val[12]; \
char* err_str = NULL; \ char* err_str = NULL; \
if (hsa_status_string(err, \ if (hsa_status_string(err, \
(const char**)&err_str) != HSA_STATUS_SUCCESS) { \ (const char**)&err_str) != HSA_STATUS_SUCCESS) { \
sprintf(&(err_val[0]), "%#x", (uint32_t)err); \ snprintf(&(err_val[0]), sizeof(err_val[12]), "%#x", (uint32_t)err); \
err_str = &(err_val[0]); \ err_str = &(err_val[0]); \
} \ } \
printf("hsa api call failure at: %s:%d\n", \ printf("%shsa api call failure at: %s:%d\n", \
__FILE__, __LINE__); \ COL_RED, __FILE__, __LINE__); \
printf("Call returned %s\n", err_str); \ printf("%sCall returned %s\n", COL_RED, err_str); \
return (err); \ printf("%s", COL_RESET); \
} \ return (err); \
} \
} }
// This structure holds system information acquired through hsa info related // This structure holds system information acquired through hsa info related
@@ -1017,41 +1022,69 @@ AcquireAndDisplayAgentInfo(hsa_agent_t agent, void* data) {
return HSA_STATUS_SUCCESS; return HSA_STATUS_SUCCESS;
} }
void CheckInitError(hsa_status_t err) { void CheckInitialState(void) {
printf("ROCm initialization failed\n");
// Check kernel module for ROCk is loaded // Check kernel module for ROCk is loaded
FILE *fd = popen("lsmod | grep amdgpu", "r"); FILE *fd = popen("lsmod | grep amdgpu", "r");
char buf[16]; char buf[16];
if (fread (buf, 1, sizeof (buf), fd) <= 0) { if (fread (buf, 1, sizeof (buf), fd) <= 0) {
printf("ROCk module is NOT loaded, possibly no GPU devices\n"); printf("%sROCk module is NOT loaded, possibly no GPU devices%s\n",
return; COL_RED, COL_RESET);
} else {
printf("%sROCk module is loaded%s\n", COL_WHT, COL_RESET);
} }
// Check if user belongs to group "video" // Check if user belongs to group "video"
// @note: User who are not members of "video" // @note: User who are not members of "video"
// group cannot access DRM services // group cannot access DRM services
int status = -1; char u_name[32];
bool member = false; bool member = false;
char gr_name[] = "video"; struct passwd *pw;
struct group* grp = NULL; int num_groups = 0;
do { gid_t *groups;
grp = getgrent();
if (grp == NULL) { struct group *gr_s = getgrnam("video"); // NOLINT
break; if (gr_s == nullptr) {
} printf("%sFailed to get group info to check"
status = memcmp(gr_name, grp->gr_name, sizeof(gr_name)); " for video group membership%s\n", COL_RED, COL_RESET);
if (status == 0) {
member = true;
break;
}
} while (grp != NULL);
if (member == false) {
printf("User is not member of \"video\" group\n");
return; return;
} }
if (getlogin_r(u_name, 32)) {
printf("%sFailed to get user name to check for"
" video group membership%s\n", COL_RED, COL_RESET);
return;
}
pw = getpwnam(u_name); // NOLINT
if (pw == NULL) {
printf("%sFailed to find pwd entry for user %s%s\n",
COL_RED, u_name, COL_RESET);
return;
}
(void)getgrouplist(u_name, pw->pw_gid, NULL, &num_groups);
groups = new gid_t[num_groups];
if (getgrouplist(u_name, pw->pw_gid, groups, &num_groups) == -1) {
printf("%sFailed to get user group list%s\n", COL_RED, COL_RESET);
delete []groups;
return;
}
for (int i = 0; i < num_groups; ++i) {
if (gr_s->gr_gid == groups[i]) {
printf("%s%s is member of video group%s\n", COL_WHT, u_name, COL_RESET);
member = true;
break;
}
}
if (member == false) {
printf("%s%s is not member of \"video\" group, the default DRM access "
"group. Users must be a member of the \"video\" group or another"
" DRM access group in order for ROCm applications to run "
"successfully%s.\n", COL_RED, u_name, COL_RESET);
}
delete []groups;
return; return;
} }
@@ -1064,8 +1097,9 @@ void CheckInitError(hsa_status_t err) {
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
hsa_status_t err; hsa_status_t err;
CheckInitialState();
err = hsa_init(); err = hsa_init();
RET_IF_HSA_INIT_ERR(err); RET_IF_HSA_ERR(err)
// Acquire and display system information // Acquire and display system information
system_info_t sys_info; system_info_t sys_info;