From 055025c0a6f78c993bf11d65b66cc2f19f10752b Mon Sep 17 00:00:00 2001 From: Sheng Zha Date: Sun, 23 Sep 2018 12:35:06 -0700 Subject: [PATCH 1/2] allow custom path and static linking for custom mallocs --- Makefile | 129 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 81 insertions(+), 48 deletions(-) diff --git a/Makefile b/Makefile index 6c1d96ef9c44..941ac8e43eaf 100644 --- a/Makefile +++ b/Makefile @@ -227,63 +227,96 @@ endif # gperftools malloc library (tcmalloc) ifeq ($(USE_GPERFTOOLS), 1) -# FIND_LIBNAME=tcmalloc_and_profiler - FIND_LIBNAME=tcmalloc - FIND_LIBFILEEXT=so - FIND_LIBFILE=$(wildcard /lib/lib$(FIND_LIBNAME).$(FIND_LIBFILEEXT)) - ifeq (,$(FIND_LIBFILE)) - FIND_LIBFILE=$(wildcard /usr/lib/lib$(FIND_LIBNAME).$(FIND_LIBFILEEXT)) - ifeq (,$(FIND_LIBFILE)) - FIND_LIBFILE=$(wildcard /usr/local/lib/lib$(FIND_LIBNAME).$(FIND_LIBFILEEXT)) - ifeq (,$(FIND_LIBFILE)) - FIND_LIBFILE=$(wildcard /usr/lib64/lib$(FIND_LIBNAME).$(FIND_LIBFILEEXT)) - ifeq (,$(FIND_LIBFILE)) - USE_GPERFTOOLS=0 - endif - endif - endif - endif - ifeq ($(USE_GPERFTOOLS), 1) - CFLAGS += -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free - LDFLAGS += $(FIND_LIBFILE) - endif +FIND_LIBFILE=$(wildcard $(USE_GPERFTOOLS_PATH)/libtcmalloc.a) +ifeq (,$(FIND_LIBFILE)) +FIND_LIBFILE=$(wildcard $(USE_GPERFTOOLS_PATH)/libtcmalloc.so) +ifeq (,$(FIND_LIBFILE)) +FIND_LIBFILE=$(wildcard /lib/libtcmalloc.a) +ifeq (,$(FIND_LIBFILE)) +FIND_LIBFILE=$(wildcard /lib/libtcmalloc.so) +ifeq (,$(FIND_LIBFILE)) +FIND_LIBFILE=$(wildcard /usr/lib/libtcmalloc.a) +ifeq (,$(FIND_LIBFILE)) +FIND_LIBFILE=$(wildcard /usr/lib/libtcmalloc.so) +ifeq (,$(FIND_LIBFILE)) +FIND_LIBFILE=$(wildcard /usr/local/lib/libtcmalloc.a) +ifeq (,$(FIND_LIBFILE)) +FIND_LIBFILE=$(wildcard /usr/local/lib/libtcmalloc.so) +ifeq (,$(FIND_LIBFILE)) +FIND_LIBFILE=$(wildcard /usr/lib64/libtcmalloc.a) +ifeq (,$(FIND_LIBFILE)) +FIND_LIBFILE=$(wildcard /usr/lib64/libtcmalloc.so) +ifeq (,$(FIND_LIBFILE)) + USE_GPERFTOOLS=0 +endif +endif +endif +endif +endif +endif +endif +endif +endif +endif +ifeq ($(USE_GPERFTOOLS), 1) + CFLAGS += -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free + LDFLAGS += $(FIND_LIBFILE) endif # jemalloc malloc library (if not using gperftools) -ifneq ($(USE_GPERFTOOLS), 1) - ifeq ($(USE_JEMALLOC), 1) - FIND_LIBNAME=jemalloc - FIND_LIBFILEEXT=so - FIND_LIBFILE=$(wildcard /lib/lib$(FIND_LIBNAME).$(FIND_LIBFILEEXT)) - ifeq (,$(FIND_LIBFILE)) - FIND_LIBFILE=$(wildcard /usr/lib/lib$(FIND_LIBNAME).$(FIND_LIBFILEEXT)) - ifeq (,$(FIND_LIBFILE)) - FIND_LIBFILE=$(wildcard /usr/local/lib/lib$(FIND_LIBNAME).$(FIND_LIBFILEEXT)) - ifeq (,$(FIND_LIBFILE)) - FIND_LIBFILE=$(wildcard /usr/lib/x86_64-linux-gnu/lib$(FIND_LIBNAME).$(FIND_LIBFILEEXT)) - ifeq (,$(FIND_LIBFILE)) - FIND_LIBFILE=$(wildcard /usr/lib64/lib$(FIND_LIBNAME).$(FIND_LIBFILEEXT)) - ifeq (,$(FIND_LIBFILE)) - USE_JEMALLOC=0 - endif - endif - endif - endif - endif - ifeq ($(USE_JEMALLOC), 1) - CFLAGS += -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc \ - -fno-builtin-free -DUSE_JEMALLOC - LDFLAGS += $(FIND_LIBFILE) - endif - endif +else +ifeq ($(USE_JEMALLOC), 1) +FIND_LIBFILE=$(wildcard $(USE_JEMALLOC_PATH)/libjemalloc.a) +ifeq (,$(FIND_LIBFILE)) +FIND_LIBFILE=$(wildcard $(USE_JEMALLOC_PATH)/libjemalloc.so) +ifeq (,$(FIND_LIBFILE)) +FIND_LIBFILE=$(wildcard /lib/libjemalloc.a) +ifeq (,$(FIND_LIBFILE)) +FIND_LIBFILE=$(wildcard /lib/libjemalloc.so) +ifeq (,$(FIND_LIBFILE)) +FIND_LIBFILE=$(wildcard /usr/lib/libjemalloc.a) +ifeq (,$(FIND_LIBFILE)) +FIND_LIBFILE=$(wildcard /usr/lib/libjemalloc.so) +ifeq (,$(FIND_LIBFILE)) +FIND_LIBFILE=$(wildcard /usr/local/lib/libjemalloc.a) +ifeq (,$(FIND_LIBFILE)) +FIND_LIBFILE=$(wildcard /usr/local/lib/libjemalloc.so) +ifeq (,$(FIND_LIBFILE)) +FIND_LIBFILE=$(wildcard /usr/lib/x86_64-linux-gnu/libjemalloc.a) +ifeq (,$(FIND_LIBFILE)) +FIND_LIBFILE=$(wildcard /usr/lib/x86_64-linux-gnu/libjemalloc.so) +ifeq (,$(FIND_LIBFILE)) +FIND_LIBFILE=$(wildcard /usr/lib64/libjemalloc.a) +ifeq (,$(FIND_LIBFILE)) +FIND_LIBFILE=$(wildcard /usr/lib64/libjemalloc.so) +ifeq (,$(FIND_LIBFILE)) + USE_JEMALLOC=0 +endif +endif +endif +endif +endif +endif +endif +endif +endif +endif +endif +endif +ifeq ($(USE_JEMALLOC), 1) + CFLAGS += -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc \ + -fno-builtin-free -DUSE_JEMALLOC + LDFLAGS += $(FIND_LIBFILE) +endif +endif endif # If not using tcmalloc or jemalloc, print a warning (user should consider installing) ifneq ($(USE_GPERFTOOLS), 1) - ifneq ($(USE_JEMALLOC), 1) +ifneq ($(USE_JEMALLOC), 1) $(warning WARNING: Significant performance increases can be achieved by installing and \ enabling gperftools or jemalloc development packages) - endif +endif endif ifeq ($(USE_THREADED_ENGINE), 1) From 6a50f146ae413682219881b6463202b17ba21f1a Mon Sep 17 00:00:00 2001 From: Sheng Zha Date: Sun, 23 Sep 2018 17:50:20 -0700 Subject: [PATCH 2/2] add config entry --- make/config.mk | 6 ++++++ make/crosscompile.jetson.mk | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/make/config.mk b/make/config.mk index b65f77c605f7..2fd8f6ec22f6 100644 --- a/make/config.mk +++ b/make/config.mk @@ -179,9 +179,15 @@ USE_OPERATOR_TUNING = 1 # Use gperftools if found USE_GPERFTOOLS = 1 +# path to gperftools (tcmalloc) library in case of a non-standard installation +USE_GPERFTOOLS_PATH = + # Use JEMalloc if found, and not using gperftools USE_JEMALLOC = 1 +# path to jemalloc library in case of a non-standard installation +USE_JEMALLOC_PATH = + #---------------------------- # additional operators #---------------------------- diff --git a/make/crosscompile.jetson.mk b/make/crosscompile.jetson.mk index 5bb4961bf01e..a1468f4496d3 100644 --- a/make/crosscompile.jetson.mk +++ b/make/crosscompile.jetson.mk @@ -164,9 +164,15 @@ USE_OPERATOR_TUNING = 1 # Use gperftools if found USE_GPERFTOOLS = 1 +# path to gperftools (tcmalloc) library in case of a non-standard installation +USE_GPERFTOOLS_PATH = + # Use JEMalloc if found, and not using gperftools USE_JEMALLOC = 1 +# path to jemalloc library in case of a non-standard installation +USE_JEMALLOC_PATH = + #---------------------------- # additional operators #----------------------------