Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
allow custom path and static linking for custom mallocs in make (#12645)
Browse files Browse the repository at this point in the history
* allow custom path and static linking for custom mallocs

* add config entry
  • Loading branch information
szha authored and eric-haibin-lin committed Sep 24, 2018
1 parent 3caf2ca commit c93c78e
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 48 deletions.
129 changes: 81 additions & 48 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions make/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
#----------------------------
Expand Down
6 changes: 6 additions & 0 deletions make/crosscompile.jetson.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
#----------------------------
Expand Down

0 comments on commit c93c78e

Please sign in to comment.