libhsakmt: query/use render node fds that libdrm uses.

Query render node fds that libdrm uses for current process and
use them at Thunk if available.

v2: avoid naming conflict with amdgpu_device_get_fd from amdgpu.h

Signed-off-by: Xiaogang Chen<Xiaogang.Chen@amd.com>
Change-Id: Id7288c03730f4a4c9c3644e37ca4725fec71a471


[ROCm/ROCR-Runtime commit: ac1db60fc2]
This commit is contained in:
Xiaogang Chen
2022-11-15 12:18:27 -06:00
committed by Xiaogang Chen
parent 6800fbec43
commit dd8954e83e
6 changed files with 95 additions and 9 deletions
+15
View File
@@ -23,6 +23,11 @@
* DEALINGS IN THE SOFTWARE.
*/
/* glibc macro that enables access some nonstandard GNU/Linux extensions
* such as RTLD_DEFAULT used by dlsym
*/
#define _GNU_SOURCE
#include "libhsakmt.h"
#include <stdlib.h>
@@ -34,6 +39,9 @@
#include <stdio.h>
#include <strings.h>
#include "fmm.h"
#include <dlfcn.h>
int (*fn_amdgpu_device_get_fd)(HsaAMDGPUDeviceHandle device_handle);
static const char kfd_device_name[] = "/dev/kfd";
static pid_t parent_pid = -1;
@@ -143,6 +151,7 @@ HSAKMT_STATUS HSAKMTAPI hsaKmtOpenKFD(void)
HSAKMT_STATUS result;
int fd = -1;
HsaSystemProperties sys_props;
char *error;
pthread_mutex_lock(&hsakmt_mutex);
@@ -156,6 +165,12 @@ HSAKMT_STATUS HSAKMTAPI hsaKmtOpenKFD(void)
if (kfd_open_count == 0) {
static bool atfork_installed = false;
fn_amdgpu_device_get_fd = dlsym(RTLD_DEFAULT, "amdgpu_device_get_fd");
if ((error = dlerror()) != NULL)
pr_err("amdgpu_device_get_fd is not available: %s\n", error);
else
pr_info("amdgpu_device_get_fd is available %p\n", fn_amdgpu_device_get_fd);
result = init_vars_from_env();
if (result != HSAKMT_STATUS_SUCCESS)
goto open_failed;