Repository navigation
[MUSA]Feat: musa support #12107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
[MUSA]Feat: musa support #12107
Changes from 17 commits
c5bc473
4d26217
09f719a
02cefad
cb94498
e9e9f7b
939deda
b180dae
5b3a01d
4180e72
f9bcec2
87e3b03
1ea92e7
7ef53c1
7e627d0
e575e96
171799b
b7b3ce7
c71f28b
aabae58
765171e
40dd086
283f7e4
e91befa
db52c5a
268026a
260dbb4
35d82c6
9fb1f39
e797e0d
7515f80
6d7b017
e386e24
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| # | ||
| # Copyright (C) MThreads 2026. ALL RIGHTS RESERVED. | ||
| # See file LICENSE for terms. | ||
| # | ||
|
|
||
| AC_DEFUN([UCX_CHECK_MUSA],[ | ||
| AS_IF([test "x$musa_checked" != "xyes"], [ | ||
| AC_ARG_WITH([musa], | ||
| [AS_HELP_STRING([--with-musa=(DIR)], | ||
| [Enable MUSA support (default is guess).])], | ||
| [], | ||
| [with_musa=guess]) | ||
|
|
||
| musa_happy=no | ||
| MUSA_CPPFLAGS="" | ||
| MUSA_LDFLAGS="" | ||
| MUSA_LIBS="" | ||
| MUSA_ROOT="" | ||
|
|
||
| AS_IF([test "x$with_musa" = "xno"], [ | ||
| AC_MSG_WARN([MUSA support was explicitly disabled]) | ||
| ], [ | ||
| AS_IF([test "x$with_musa" = "xyes" || | ||
| test "x$with_musa" = "xguess"], [ | ||
| AS_IF([test -d /usr/local/musa], | ||
|
superleo marked this conversation as resolved.
Resolved
|
||
| [MUSA_ROOT=/usr/local/musa]) | ||
|
superleo marked this conversation as resolved.
Resolved
|
||
| ], [ | ||
| MUSA_ROOT="$with_musa" | ||
| ]) | ||
|
|
||
| AS_IF([test -n "$MUSA_ROOT"], [ | ||
| MUSA_CPPFLAGS="-I$MUSA_ROOT/include" | ||
| MUSA_LDFLAGS="-L$MUSA_ROOT/lib -L$MUSA_ROOT/lib64" | ||
| MUSA_LIBS="-lmusart -lmusa" | ||
|
|
||
| musa_happy=yes | ||
| save_CPPFLAGS="$CPPFLAGS" | ||
| save_LDFLAGS="$LDFLAGS" | ||
| save_LIBS="$LIBS" | ||
|
|
||
| CPPFLAGS="$MUSA_CPPFLAGS $CPPFLAGS" | ||
| LDFLAGS="$MUSA_LDFLAGS $LDFLAGS" | ||
| LIBS="$MUSA_LIBS $LIBS" | ||
|
|
||
| AC_CHECK_HEADERS([musa_runtime_api.h], | ||
|
superleo marked this conversation as resolved.
Resolved
|
||
| [], | ||
| [musa_happy=no]) | ||
| AC_CHECK_HEADERS([musa.h], | ||
| [], | ||
| [musa_happy=no]) | ||
|
|
||
| AS_IF([test "x$musa_happy" = "xyes"], [ | ||
| AC_CHECK_LIB([musart], [musaGetDeviceCount], | ||
| [], | ||
| [musa_happy=no]) | ||
| ]) | ||
| AS_IF([test "x$musa_happy" = "xyes"], [ | ||
| AC_CHECK_LIB([musart], [musaMalloc], | ||
|
superleo marked this conversation as resolved.
Resolved
|
||
| [], | ||
| [musa_happy=no]) | ||
| AC_CHECK_LIB([musart], [musaFree], | ||
| [], | ||
| [musa_happy=no]) | ||
| AC_CHECK_LIB([musart], [musaMemcpy], | ||
| [], | ||
| [musa_happy=no]) | ||
| AC_CHECK_LIB([musart], [musaHostRegister], | ||
| [], | ||
| [musa_happy=no]) | ||
| AC_CHECK_LIB([musart], [musaHostUnregister], | ||
| [], | ||
| [musa_happy=no]) | ||
| AC_CHECK_LIB([musart], [musaDeviceGetPCIBusId], | ||
| [], | ||
| [musa_happy=no]) | ||
| ]) | ||
| AS_IF([test "x$musa_happy" = "xyes"], [ | ||
| AC_CHECK_LIB([musa], [muMemGetAddressRange], | ||
| [], | ||
| [musa_happy=no]) | ||
| ]) | ||
| AS_IF([test "x$musa_happy" = "xyes"], [ | ||
| AC_CHECK_LIB([musa], [muMemGetHandleForAddressRange], | ||
|
superleo marked this conversation as resolved.
Resolved
|
||
| [AC_DEFINE([HAVE_MUSA_DMABUF], [1], | ||
| [MUSA supports DMA-BUF export])], | ||
| []) | ||
| ]) | ||
| AS_IF([test "x$musa_happy" = "xyes"], [ | ||
| AC_LINK_IFELSE( | ||
|
superleo marked this conversation as resolved.
Resolved
|
||
| [AC_LANG_PROGRAM( | ||
| [[#include <stddef.h> | ||
| #include <musa.h> | ||
| #include <musa_runtime_api.h>]], | ||
| [[int count = 0; | ||
| int device = 0; | ||
| void *address = 0; | ||
| MUdeviceptr base = 0; | ||
| size_t size = 0; | ||
| musaGetDeviceCount(&count); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. musaMalloc is in the link probe now. The probe structure was also reworked (mandatory vs. optional symbols) — see the separate thread about the single large probe. @svc-nvidia-pr-review |
||
| musaGetDevice(&device); | ||
| musaSetDevice(device); | ||
| musaPointerGetAttributes(NULL, address); | ||
| musaGetErrorString(musaSuccess); | ||
| muMemGetAddressRange(&base, &size, | ||
| (MUdeviceptr)address); | ||
| return count < 0;]])], | ||
| [], | ||
| [musa_happy=no]) | ||
| ]) | ||
|
|
||
| CPPFLAGS="$save_CPPFLAGS" | ||
| LDFLAGS="$save_LDFLAGS" | ||
| LIBS="$save_LIBS" | ||
| ]) | ||
|
|
||
| AS_IF([test "x$musa_happy" = "xyes"], [ | ||
| AC_DEFINE([HAVE_MUSA], [1], [Enable MUSA support]) | ||
| AC_SUBST([MUSA_CPPFLAGS]) | ||
| AC_SUBST([MUSA_LDFLAGS]) | ||
| AC_SUBST([MUSA_LIBS]) | ||
| AC_SUBST([MUSA_ROOT]) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @svc-nvidia-pr-review ,We prefer no rpath: verified that the built libuct_musa.so /libucm_musa.so carry no RUNPATH and load fine both via the system loader configuration and via an explicit LD_LIBRARY_PATH. Since the SDK location can differ between build and deployment hosts, baking the build-time path into the modules seemed more likely to cause problems than to fix them. |
||
| ], [ | ||
| AS_IF([test "x$with_musa" != "xguess"], [ | ||
| AC_MSG_ERROR([MUSA support was requested but MUSA headers and libraries were not found]) | ||
| ], [ | ||
| AC_MSG_WARN([MUSA headers and libraries not found]) | ||
| ]) | ||
| ]) | ||
| ]) | ||
|
|
||
| musa_checked=yes | ||
| AM_CONDITIONAL([HAVE_MUSA], [test "x$musa_happy" = "xyes"]) | ||
| ]) | ||
| ]) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |
| # See file LICENSE for terms. | ||
| # | ||
|
|
||
| SUBDIRS = . cuda rocm ze | ||
| SUBDIRS = . cuda musa rocm ze | ||
|
superleo marked this conversation as resolved.
Resolved
|
||
|
|
||
| lib_LTLIBRARIES = libucm.la | ||
| libucm_ladir = $(includedir)/ucm | ||
|
|
@@ -62,4 +62,3 @@ libucm_la_SOURCES += \ | |
| noinst_HEADERS += \ | ||
| ptmalloc286/malloc-2.8.6.h | ||
| endif | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor: pls drop this unrelated trailing-newline removal (same in |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # | ||
| # Copyright (C) MThreads 2026. ALL RIGHTS RESERVED. | ||
| # See file LICENSE for terms. | ||
| # | ||
|
|
||
| if HAVE_MUSA | ||
| module_LTLIBRARIES = libucm_musa.la | ||
| libucm_musa_la_CPPFLAGS = $(BASE_CPPFLAGS) $(MUSA_CPPFLAGS) | ||
| libucm_musa_la_CFLAGS = $(BASE_CFLAGS) $(MUSA_CFLAGS) $(LT_CFLAGS) | ||
| libucm_musa_la_LIBADD = ../libucm.la $(MUSA_LIBS) | ||
| libucm_musa_la_LDFLAGS = $(UCM_MODULE_LDFLAGS) \ | ||
| $(patsubst %, -Xlinker %, $(MUSA_LDFLAGS)) \ | ||
| -version-info $(SOVERSION) $(UCX_LT_RELEASE) | ||
|
|
||
| libucm_musa_la_SOURCES = \ | ||
| musamem.c | ||
|
|
||
| include $(top_srcdir)/config/module.am | ||
| endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # | ||
| # Copyright (C) MThreads 2026. ALL RIGHTS RESERVED. | ||
| # See file LICENSE for terms. | ||
| # | ||
|
|
||
| UCX_CHECK_MUSA | ||
| AS_IF([test "x$musa_happy" = "xyes"], | ||
| [ucm_modules="${ucm_modules}:musa"]) | ||
| AC_CONFIG_FILES([src/ucm/musa/Makefile]) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| /* | ||
| * Copyright (C) MThreads 2026. ALL RIGHTS RESERVED. | ||
| * See file LICENSE for terms. | ||
| */ | ||
|
|
||
| #ifdef HAVE_CONFIG_H | ||
| # include "config.h" | ||
| #endif | ||
|
|
||
| #include <musa.h> | ||
| #include <musa_runtime_api.h> | ||
|
|
||
| #include <ucm/event/event.h> | ||
| #include <ucm/util/log.h> | ||
| #include <ucm/util/reloc.h> | ||
| #include <ucm/util/replace.h> | ||
| #include <ucm/util/sys.h> | ||
| #include <ucs/sys/compiler.h> | ||
| #include <ucs/sys/preprocessor.h> | ||
|
|
||
| #include <pthread.h> | ||
| #include <string.h> | ||
| #include <sys/mman.h> | ||
|
|
||
| static musaError_t ucm_musaMalloc(void **address, size_t size); | ||
| static musaError_t ucm_musaFree(void *address); | ||
|
|
||
| UCM_DEFINE_REPLACE_DLSYM_FUNC(musaMalloc, musaError_t, musaErrorUnknown, | ||
| void **, size_t) | ||
| UCM_DEFINE_REPLACE_DLSYM_FUNC(musaFree, musaError_t, musaErrorUnknown, void *) | ||
|
|
||
| static void | ||
| ucm_dispatch_musa_mem_type_event(ucm_event_type_t event_type, void *address, | ||
| size_t length) | ||
| { | ||
| ucm_event_t event; | ||
|
|
||
| if (address == NULL) { | ||
| return; | ||
| } | ||
|
|
||
| event.mem_type.address = address; | ||
| event.mem_type.size = length; | ||
| event.mem_type.mem_type = UCS_MEMORY_TYPE_MUSA; | ||
|
superleo marked this conversation as resolved.
Resolved
superleo marked this conversation as resolved.
Resolved
|
||
| event.mem_type.sys_dev = UCS_SYS_DEVICE_ID_UNKNOWN; | ||
| event.mem_type.mem_flags = UCS_MEM_FLAG_REGISTRABLE; | ||
| ucm_event_dispatch(event_type, &event); | ||
| } | ||
|
|
||
| static size_t ucm_musa_mem_size(void *address) | ||
| { | ||
| MUdeviceptr base; | ||
| size_t length; | ||
|
|
||
| if ((address == NULL) || | ||
| (muMemGetAddressRange(&base, &length, (MUdeviceptr)address) != | ||
| MUSA_SUCCESS)) { | ||
| return 1; | ||
| } | ||
|
|
||
| return length; | ||
| } | ||
|
|
||
| static musaError_t ucm_musaMalloc(void **address, size_t size) | ||
|
superleo marked this conversation as resolved.
Resolved
|
||
| { | ||
| musaError_t status; | ||
|
|
||
| ucm_event_enter(); | ||
| status = ucm_orig_musaMalloc(address, size); | ||
| if ((status == musaSuccess) && (address != NULL) && (*address != NULL)) { | ||
| ucm_dispatch_musa_mem_type_event(UCM_EVENT_MEM_TYPE_ALLOC, *address, | ||
| size); | ||
| } | ||
| ucm_event_leave(); | ||
| return status; | ||
| } | ||
|
|
||
| static musaError_t ucm_musaFree(void *address) | ||
| { | ||
| musaError_t status; | ||
| size_t length; | ||
|
|
||
| ucm_event_enter(); | ||
| length = ucm_musa_mem_size(address); | ||
| ucm_dispatch_musa_mem_type_event(UCM_EVENT_MEM_TYPE_FREE, address, length); | ||
| status = ucm_orig_musaFree(address); | ||
| ucm_event_leave(); | ||
| return status; | ||
| } | ||
|
|
||
| static ucm_reloc_patch_t ucm_musa_patches[] = { | ||
| {UCS_PP_MAKE_STRING(musaMalloc), ucm_override_musaMalloc}, | ||
|
superleo marked this conversation as resolved.
Resolved
|
||
| {UCS_PP_MAKE_STRING(musaFree), ucm_override_musaFree}, | ||
| {NULL, NULL} | ||
| }; | ||
|
|
||
| static ucs_status_t ucm_musamem_install(int events) | ||
| { | ||
| static int installed; | ||
| static pthread_mutex_t install_mutex = PTHREAD_MUTEX_INITIALIZER; | ||
| ucm_reloc_patch_t *patch; | ||
| ucs_status_t status = UCS_OK; | ||
|
|
||
| if (!(events & (UCM_EVENT_MEM_TYPE_ALLOC | UCM_EVENT_MEM_TYPE_FREE))) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hooks cannot be disabled: |
||
| return UCS_OK; | ||
| } | ||
|
|
||
| pthread_mutex_lock(&install_mutex); | ||
| if (installed) { | ||
| goto out; | ||
| } | ||
|
|
||
| for (patch = ucm_musa_patches; patch->symbol != NULL; ++patch) { | ||
|
superleo marked this conversation as resolved.
Resolved
|
||
| status = ucm_reloc_modify(patch); | ||
| if (status != UCS_OK) { | ||
| ucm_warn("failed to install MUSA hook for '%s'", patch->symbol); | ||
| goto out; | ||
| } | ||
| } | ||
|
|
||
| installed = 1; | ||
| ucm_info("MUSA memory hooks are ready"); | ||
|
|
||
| out: | ||
| pthread_mutex_unlock(&install_mutex); | ||
| return status; | ||
| } | ||
|
|
||
| static int | ||
| ucm_musamem_scan_regions_cb(void *arg, void *addr, size_t length, int prot, | ||
| const char *path) | ||
| { | ||
| static const char musa_path_pattern[] = "/dev/musa"; | ||
|
superleo marked this conversation as resolved.
Resolved
superleo marked this conversation as resolved.
Resolved
|
||
| ucm_event_handler_t *handler = arg; | ||
| ucm_event_t event; | ||
|
|
||
| if ((prot & (PROT_READ | PROT_WRITE | PROT_EXEC)) && | ||
| strncmp(path, musa_path_pattern, sizeof(musa_path_pattern) - 1)) { | ||
| return 0; | ||
| } | ||
|
|
||
| event.mem_type.address = addr; | ||
| event.mem_type.size = length; | ||
| event.mem_type.mem_type = UCS_MEMORY_TYPE_LAST; | ||
| event.mem_type.sys_dev = UCS_SYS_DEVICE_ID_UNKNOWN; | ||
| event.mem_type.mem_flags = UCS_MEM_FLAG_REGISTRABLE; | ||
|
|
||
| ucm_event_enter(); | ||
| handler->cb(UCM_EVENT_MEM_TYPE_ALLOC, &event, handler->arg); | ||
| ucm_event_leave(); | ||
| return 0; | ||
| } | ||
|
|
||
| static void ucm_musamem_get_existing_alloc(ucm_event_handler_t *handler) | ||
| { | ||
| if (handler->events & UCM_EVENT_MEM_TYPE_ALLOC) { | ||
| ucm_parse_proc_self_maps(ucm_musamem_scan_regions_cb, handler); | ||
| } | ||
| } | ||
|
|
||
| static ucm_event_installer_t ucm_musa_initializer = { | ||
| .install = ucm_musamem_install, | ||
| .get_existing_alloc = ucm_musamem_get_existing_alloc | ||
| }; | ||
|
|
||
| UCS_STATIC_INIT | ||
| { | ||
| ucs_list_add_tail(&ucm_event_installer_list, &ucm_musa_initializer.list); | ||
| } | ||
|
|
||
| UCS_STATIC_CLEANUP | ||
| { | ||
| ucs_list_del(&ucm_musa_initializer.list); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.