Skip to content

Commit

Permalink
UCM/ROCM: fix rocmem initialization
Browse files Browse the repository at this point in the history
fix the initialization of the rocm ucm component to ensure that the
memtype cache is correctly recording rocm device addresses.

(cherry picked from commit f8fa567)
  • Loading branch information
edgargabriel committed Feb 21, 2022
1 parent fcdffe6 commit e4a2c84
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/ucm/rocm/rocmmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
#include <ucm/util/reloc.h>
#include <ucm/util/replace.h>
#include <ucs/debug/assert.h>
#include <ucm/util/sys.h>
#include <ucs/sys/compiler.h>
#include <ucs/sys/preprocessor.h>

#include <sys/mman.h>

#include <unistd.h>
#include <pthread.h>
#include <stdlib.h>
Expand Down Expand Up @@ -176,8 +179,36 @@ static ucs_status_t ucm_rocmmem_install(int events)
return status;
}

static int ucm_rocm_scan_regions_cb(void *arg, void *addr, size_t length,
int prot, const char *path)
{
static const char *rocm_path_pattern = "/dev/dri";
ucm_event_handler_t *handler = arg;
ucm_event_t event;

if ((prot & (PROT_READ | PROT_WRITE | PROT_EXEC)) &&
strncmp(path, rocm_path_pattern, strlen(rocm_path_pattern))) {
return 0;
}
ucm_debug("dispatching initial memtype allocation for %p..%p %s", addr,
UCS_PTR_BYTE_OFFSET(addr, length), path);

event.mem_type.address = addr;
event.mem_type.size = length;
event.mem_type.mem_type = UCS_MEMORY_TYPE_LAST; /* unknown memory type */

ucm_event_enter();
handler->cb(UCM_EVENT_MEM_TYPE_ALLOC, &event, handler->arg);
ucm_event_leave();

return 0;
}

static void ucm_rocmmem_get_existing_alloc(ucm_event_handler_t *handler)
{
if (handler->events & UCM_EVENT_MEM_TYPE_ALLOC) {
ucm_parse_proc_self_maps(ucm_rocm_scan_regions_cb, handler);
}
}

static ucm_event_installer_t ucm_rocm_initializer = {
Expand Down

0 comments on commit e4a2c84

Please sign in to comment.