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

Failed to detect tcmalloc or jemalloc for Fedora 26 #8617

Closed
expnn opened this issue Nov 11, 2017 · 4 comments
Closed

Failed to detect tcmalloc or jemalloc for Fedora 26 #8617

expnn opened this issue Nov 11, 2017 · 4 comments
Labels

Comments

@expnn
Copy link

expnn commented Nov 11, 2017

The wildcard given by the current Makefile failed to detect the gperftools/jemalloc malloc libraries.
Currently, it uses the following snippet to detect these libraries, which assumes the .so file is located in the '*/lib' subdirectories.
https://github.com/apache/incubator-mxnet/blob/35ceea73ccc1acfb2ec62cdaa841822e51c13456/Makefile#L168-L213

This is not true for Fedora 26 (and for many 64-bit systems), which put the shared library files into 'lib64' subdirectories. For example, on my system, it is located in the /usr/lib64 directory.

$ locate libtcmalloc.so
/usr/lib64/libtcmalloc.so.4
/usr/lib64/libtcmalloc.so.4.4.5

I suggest to using the following snippet to replace the above-mentioned codes.
It simply replaces 'lib' into 'lib*' in the wildcard matching.

# 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))
				USE_GPERFTOOLS=0
			endif
		endif
	endif
	ifeq ($(USE_GPERFTOOLS), 1)
		CFLAGS += -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free
		LDFLAGS += $(FIND_LIBFILE)
	endif
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))
						USE_JEMALLOC=0
					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
@eric-haibin-lin
Copy link
Member

@cjolivier01 do you know how to resolve this issue?

@cjolivier01
Copy link
Member

cjolivier01 commented Nov 13, 2017

Of course you may submit a PR.
How do you handle libtcmalloc.so.3 and libtcmalloc.so.4 in the same directory?
You might also offering to override the directory with a variable from config.mk

@cjolivier01
Copy link
Member

cjolivier01 commented Nov 21, 2017

I think we're probably going to deprecate Makefile and use cmake. Does it find it ok with cmake?

See discussion: #8702

@cjolivier01
Copy link
Member

Please reopen if necessary, but I think we're just going to standardize on cmake. Let me know if cmake doesn't find it.,

@cjolivier01 cjolivier01 reopened this Nov 23, 2017
leezu added a commit to leezu/dotfiles that referenced this issue Jan 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants