From b0447d616b1ce7fa572dda33be9993a382f10d92 Mon Sep 17 00:00:00 2001 From: Jade Abraham Date: Mon, 3 Jun 2024 08:33:36 -0700 Subject: [PATCH 1/5] fix chunk hooks Signed-off-by: Jade Abraham --- runtime/src/mem/jemalloc/mem-jemalloc.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/runtime/src/mem/jemalloc/mem-jemalloc.c b/runtime/src/mem/jemalloc/mem-jemalloc.c index 33dce9c32937..66d1268553f1 100644 --- a/runtime/src/mem/jemalloc/mem-jemalloc.c +++ b/runtime/src/mem/jemalloc/mem-jemalloc.c @@ -47,10 +47,8 @@ unsigned CHPL_JE_LG_ARENA; // Decide whether or not to try to use jemalloc's chunk hooks interface // jemalloc < 4.0 didn't support chunk_hooks_t // jemalloc 4.1 changed opt.nareas from size_t to unsigned -// .. so we use chunk hooks interface for jemalloc >= 4.1 -#if JEMALLOC_VERSION_MAJOR > 4 -#define USE_JE_CHUNK_HOOKS -#endif +// jemalloc 5.x migrated to an extent API +// .. so we use chunk hooks interface for jemalloc >= 4.1 and < 5.0 #if (JEMALLOC_VERSION_MAJOR == 4) && (JEMALLOC_VERSION_MINOR >= 1) #define USE_JE_CHUNK_HOOKS #endif @@ -302,7 +300,7 @@ static void replaceChunkHooks(void) { } } #else - chpl_internal_error("cannot init multi-locale heap: please rebuild with jemalloc >= 4.1"); + chpl_internal_error("cannot init multi-locale heap: please rebuild with jemalloc >= 4.1 and < 5.0"); #endif } From c26cdd08f333a3c338ab841035f37c6d30b91f1d Mon Sep 17 00:00:00 2001 From: Jade Abraham Date: Mon, 3 Jun 2024 08:33:47 -0700 Subject: [PATCH 2/5] add include paths Signed-off-by: Jade Abraham --- third-party/qthread/Makefile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/third-party/qthread/Makefile b/third-party/qthread/Makefile index c1216c858261..c5b4fb0e4dbc 100644 --- a/third-party/qthread/Makefile +++ b/third-party/qthread/Makefile @@ -76,8 +76,8 @@ ifeq ($(CFLAGS_NEEDS_RT_INCLUDES), y) # seems to cause Chapel programs built with the result to hang during # exit when shutting down Qthreads. # - # We also need to provide paths to system hwloc if its enabled - # since it might not be in default compiler search paths. + # We also need to provide paths to system hwloc and jemalloc if they are + # enabled, since it might not be in default compiler search paths. # # Note that we call compileline with CHPL_MAKE_COMM=none. Under # CHPL_MAKE_COMM=gasnet, compileline will fail if gasnet is not built, @@ -92,6 +92,9 @@ ifeq ($(CFLAGS_NEEDS_RT_INCLUDES), y) ifeq ($(CHPL_MAKE_HWLOC),system) SYSTEM_INCS_DEFS := $(SYSTEM_INCS_DEFS)\|hwloc endif + ifeq ($(CHPL_MAKE_TARGET_JEMALLOC),system) + SYSTEM_INCS_DEFS := $(SYSTEM_INCS_DEFS)\|jemalloc + endif COMPILELINE_STDERR_REDIRECT=2> /dev/null COMM_NONE_CHPLENV_CACHE := $(shell echo "$(CHPL_MAKE_CHPLENV_CACHE)" | sed 's/|CHPL_MAKE_COMM=[^|]*|/|CHPL_MAKE_COMM=none|/') From 15a3529cf64ecd8529e6d1d24c3bb99f6c3355ff Mon Sep 17 00:00:00 2001 From: Jade Abraham Date: Mon, 3 Jun 2024 09:29:10 -0700 Subject: [PATCH 3/5] add more patches from #23409 Signed-off-by: Jade Abraham --- util/chplenv/chpl_jemalloc.py | 26 ++++++++++++++++++++++++- util/chplenv/compile_link_args_utils.py | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/util/chplenv/chpl_jemalloc.py b/util/chplenv/chpl_jemalloc.py index 40598f7c8e6e..f9ffa6fb451b 100644 --- a/util/chplenv/chpl_jemalloc.py +++ b/util/chplenv/chpl_jemalloc.py @@ -92,6 +92,19 @@ def get_compile_args(flag): ucp_val = get_uniq_cfg_path(flag) return third_party_utils.get_bundled_compile_args('jemalloc', ucp=ucp_val) + elif jemalloc_val == 'system': + # try pkg-config + args = third_party_utils.pkgconfig_get_system_compile_args('jemalloc') + if args != (None, None): + return args + # try homebrew + jemalloc_prefix = chpl_platform.get_homebrew_prefix('jemalloc') + if jemalloc_prefix: + return ([], ['-I{0}'.format(os.path.join(jemalloc_prefix, 'include'))]) + + envname = "CHPL_TARGET_JEMALLOC" if flag == "target" else "CHPL_HOST_JEMALLOC" + error("Could not find a suitable jemalloc installation. Please install jemalloc or set {}=bundled".format(envname, envname)) + return ([ ], [ ]) # flag is host or target @@ -116,7 +129,18 @@ def get_link_args(flag): return (libs, morelibs) if jemalloc_val == 'system': - return ([ ], ['-ljemalloc']) + # try pkg-config + args = third_party_utils.pkgconfig_get_system_link_args('jemalloc') + if args != (None, None): + return args + # try homebrew + jemalloc_prefix = chpl_platform.get_homebrew_prefix('jemalloc') + if jemalloc_prefix: + return ([], ['-L{0}'.format(os.path.join(jemalloc_prefix, 'lib')), + '-ljemalloc']) + + envname = "CHPL_TARGET_JEMALLOC" if flag == "target" else "CHPL_HOST_JEMALLOC" + error("Could not find a suitable jemalloc installation. Please install jemalloc or set {}=bundled or {}=none.".format(envname, envname)) return ([ ], [ ]) diff --git a/util/chplenv/compile_link_args_utils.py b/util/chplenv/compile_link_args_utils.py index c7371c5226e8..bf543d5469a9 100644 --- a/util/chplenv/compile_link_args_utils.py +++ b/util/chplenv/compile_link_args_utils.py @@ -73,7 +73,7 @@ def get_runtime_includes_and_defines(): system.append("-isystem" + os.path.join(sdk_path, "hip", "include")) system.append("-isystem" + os.path.join(sdk_path, "hsa", "include")) - if mem == "jemalloc": + if mem == "jemalloc" and chpl_jemalloc.get('target') == "bundled": # set -DCHPL_JEMALLOC_PREFIX=chpl_je_ # this is needed since it affects code inside of headers bundled.append("-DCHPL_JEMALLOC_PREFIX=chpl_je_") From 8771fd8c2ac020b18716ea008497516f63471581 Mon Sep 17 00:00:00 2001 From: Jade Abraham Date: Mon, 3 Jun 2024 09:29:24 -0700 Subject: [PATCH 4/5] fix third-party-pkgs Signed-off-by: Jade Abraham --- util/chplenv/third-party-pkgs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/util/chplenv/third-party-pkgs b/util/chplenv/third-party-pkgs index 7acb50c8189c..434faef0e156 100755 --- a/util/chplenv/third-party-pkgs +++ b/util/chplenv/third-party-pkgs @@ -45,6 +45,8 @@ def generate_subdir_map(): pkg_aliases['CHPL_GMP-bundled'] = 'gmp' pkg_aliases['CHPL_HWLOC-bundled'] = 'hwloc' pkg_aliases['CHPL_JEMALLOC-bundled'] = 'jemalloc' + pkg_aliases['CHPL_TARGET_JEMALLOC-bundled'] = 'jemalloc' + pkg_aliases['CHPL_HOST_JEMALLOC-bundled'] = 'jemalloc' pkg_aliases['CHPL_LIBFABRIC-bundled'] = 'libfabric' pkg_aliases['CHPL_LLVM-bundled'] = 'llvm' pkg_aliases['CHPL_UNWIND-bundled'] = 'libunwind' @@ -71,7 +73,10 @@ def compute_required_pkgs(): (var, val) = var.strip(), val.strip() # Ignore platform variables # Ignore CHPL_MEM (use CHPL_JEMALLOC) - if not (var.endswith('_PLATFORM') or var == 'CHPL_MEM'): + # Ignore CHPL_HOST_MEM (use CHPL_JEMALLOC) + # Ignore CHPL_TARGET_MEM (use CHPL_JEMALLOC) + ignore_vars = ['CHPL_MEM', 'CHPL_HOST_MEM', 'CHPL_TARGET_MEM'] + if not (var.endswith('_PLATFORM') or var in ignore_vars): if val in get_all_pkgs(): req_pkgs.add(val) elif var + '-' + val in pkg_aliases: From 6bebce5aa0536474e57ce2f8de6757307470e417 Mon Sep 17 00:00:00 2001 From: Jade Abraham Date: Mon, 3 Jun 2024 09:29:33 -0700 Subject: [PATCH 5/5] fix warning with CHPL_DEVELOPER Signed-off-by: Jade Abraham --- runtime/src/mem/jemalloc/mem-jemalloc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/src/mem/jemalloc/mem-jemalloc.c b/runtime/src/mem/jemalloc/mem-jemalloc.c index 66d1268553f1..a6a4d830f365 100644 --- a/runtime/src/mem/jemalloc/mem-jemalloc.c +++ b/runtime/src/mem/jemalloc/mem-jemalloc.c @@ -64,6 +64,7 @@ static struct shared_heap { } heap; +#ifdef USE_JE_CHUNK_HOOKS // compute aligned index into our shared heap, alignment must be a power of 2 static inline void* alignHelper(void* base_ptr, size_t offset, size_t alignment) { uintptr_t p; @@ -73,6 +74,7 @@ static inline void* alignHelper(void* base_ptr, size_t offset, size_t alignment) p = (p + alignment - 1) & ~(alignment - 1); return(void*) p; } +#endif // *** Chunk hook replacements *** //