Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions projects/rocr-runtime/libhsakmt/src/fmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
#define MPOL_F_STATIC_NODES (1 << 15)
#endif

#ifndef MPOL_F_RELATIVE_NODES
#define MPOL_F_RELATIVE_NODES (1 << 14)
#endif

#define NON_VALID_GPU_ID 0

#define INIT_MANAGEABLE_APERTURE(base_value, limit_value) { \
Expand Down Expand Up @@ -2885,6 +2889,22 @@ static void *fmm_allocate_host_cpu(HsaKFDContext *ctx, void *address, uint64_t M
return mem;
}

/* Returns true if the calling process set an explicit NUMA memory policy
* (e.g. via numactl -m / set_mempolicy). When it did, ROCr should not override
* it with a per-agent mbind; the process policy governs host placement.
*/
static bool process_has_explicit_mempolicy(void)
Comment thread
cfreeamd marked this conversation as resolved.
Resolved
{
int mode = MPOL_DEFAULT;

/* flags=0, addr=NULL => returns the calling thread's default policy. */
if (get_mempolicy(&mode, NULL, 0, NULL, 0) != 0)
return false;

mode &= ~(MPOL_F_STATIC_NODES | MPOL_F_RELATIVE_NODES);
return mode != MPOL_DEFAULT;
}

static int bind_mem_to_numa(uint32_t numa_node_id, void *mem,
uint64_t SizeInBytes, HsaMemFlags mflags)
{
Expand All @@ -2904,6 +2924,15 @@ static int bind_mem_to_numa(uint32_t numa_node_id, void *mem,
return 0;
}

/* Honor an explicit process memory policy (e.g. numactl -m): if the
* application set one, leave placement to that policy instead of forcing
* the per-agent node. HSA_FORCE_MBIND=1 restores the legacy per-agent
* binding. Returning 0 lets the allocation proceed under the process
* policy (also correct for NoSubstitute).
*/
if (!hsakmt_force_mbind && process_has_explicit_mempolicy())
return 0;
Comment thread
cfreeamd marked this conversation as resolved.
Resolved

num_node = numa_max_node() + 1;

/* Single NUMA node: bind is a no-op; don't fail NoSubstitute (udmabuf). */
Expand Down
4 changes: 4 additions & 0 deletions projects/rocr-runtime/libhsakmt/src/globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ int hsakmt_page_shift;
/* zfb is mainly used during emulation */
int hsakmt_zfb_support;
int hsakmt_pm4_target_xcc;
/* HSA_FORCE_MBIND=1 forces the legacy per-agent mbind even when the process
* has set an explicit NUMA memory policy (e.g. numactl -m).
*/
int hsakmt_force_mbind;
1 change: 1 addition & 0 deletions projects/rocr-runtime/libhsakmt/src/libhsakmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ extern pthread_mutex_t hsakmt_mutex;
extern bool hsakmt_is_dgpu;
extern int hsakmt_zfb_support;
extern int hsakmt_pm4_target_xcc;
extern int hsakmt_force_mbind;

extern HsaVersionInfo hsakmt_kfd_version_info;
extern HsaKFDContext hsakmt_primary_kfd_ctx;
Expand Down
7 changes: 7 additions & 0 deletions projects/rocr-runtime/libhsakmt/src/openclose.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ static HSAKMT_STATUS init_vars_from_env(void)
envvar = getenv("PM4_TARGET_XCC");
if (envvar)
hsakmt_pm4_target_xcc = hsakmt_safe_env_to_int(envvar, 0);

/* Force the legacy per-agent mbind even when the process set an explicit
* NUMA memory policy (e.g. numactl -m).
*/
envvar = getenv("HSA_FORCE_MBIND");
if (envvar)
hsakmt_force_mbind = hsakmt_safe_env_to_int(envvar, 0);
return HSAKMT_STATUS_SUCCESS;
}

Expand Down
Loading