From c3c2e45f9446d54b58c7255946723cd089e4d408 Mon Sep 17 00:00:00 2001 From: Edgar Gabriel Date: Wed, 10 May 2023 13:12:33 +0000 Subject: [PATCH] UCT/ROCM: check kernel config for dmabuf support 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. (cherry picked from commit a4080426a3397ab51f91fcc1c151bc8a3b12059b) --- src/uct/rocm/base/rocm_base.c | 41 ++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/src/uct/rocm/base/rocm_base.c b/src/uct/rocm/base/rocm_base.c index 2b23385b345..d3d206fadaa 100644 --- a/src/uct/rocm/base/rocm_base.c +++ b/src/uct/rocm/base/rocm_base.c @@ -11,7 +11,7 @@ #include #include - +#include #include #define MAX_AGENTS 63 @@ -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; }