Skip to content

Commit

Permalink
UCT/ROCM: check kernel config for dmabuf support
Browse files Browse the repository at this point in the history
The kernel has to have certain options enabled in order for dmabuf
support to be fully functional. This commit adds a check whether the
kernel has the required options.
  • Loading branch information
edgargabriel committed May 22, 2023
1 parent fdd5935 commit a408042
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions src/uct/rocm/base/rocm_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include <ucs/sys/string.h>
#include <ucs/sys/module.h>

#include <sys/utsname.h>
#include <pthread.h>

#define MAX_AGENTS 63
Expand Down Expand Up @@ -292,9 +292,44 @@ int uct_rocm_base_is_dmabuf_supported()
int dmabuf_supported = 0;

#if HAVE_HSA_AMD_PORTABLE_EXPORT_DMABUF
dmabuf_supported = 1;
const char kernel_opt1[] = "CONFIG_DMABUF_MOVE_NOTIFY=y";
const char kernel_opt2[] = "CONFIG_PCI_P2PDMA=y";
int found_opt1 = 0;
int found_opt2 = 0;
FILE *fp;
struct utsname utsname;
char kernel_conf_file[128];
char buf[256];

if (uname(&utsname) == -1) {
ucs_trace("could not get kernel name");
goto out;
}

ucs_snprintf_safe(kernel_conf_file, sizeof(kernel_conf_file),
"/boot/config-%s", utsname.release);
fp = fopen(kernel_conf_file, "r");
if (fp == NULL) {
ucs_trace("could not open kernel conf file %s error: %m",
kernel_conf_file);
goto out;
}

while (fgets(buf, sizeof(buf), fp) != NULL) {
if (strstr(buf, kernel_opt1) != NULL) {
found_opt1 = 1;
}
if (strstr(buf, kernel_opt2) != NULL) {
found_opt2 = 1;
}
if (found_opt1 && found_opt2) {
dmabuf_supported = 1;
break;
}
}
fclose(fp);
#endif

out:
return dmabuf_supported;
}

Expand Down

0 comments on commit a408042

Please sign in to comment.