Files
rocm-systems/src/Makefile
T

139 lines
4.5 KiB
Makefile
Raw Normal View History

2018-09-24 16:06:59 -07:00
#
2022-01-07 06:39:55 -08:00
# Copyright (c) 2015-2022, NVIDIA CORPORATION. All rights reserved.
2018-09-24 16:06:59 -07:00
#
# See LICENSE.txt for license information
#
include ../makefiles/common.mk
include ../makefiles/version.mk
##### src files
2018-11-13 10:37:20 -08:00
INCEXPORTS := nccl.h nccl_net.h
2023-09-26 05:47:28 -07:00
LIBSRCFILES := \
bootstrap.cc channel.cc collectives.cc debug.cc enqueue.cc group.cc \
2024-02-05 05:06:02 -08:00
init.cc init_nvtx.cc net.cc proxy.cc transport.cc register.cc \
2023-09-26 05:47:28 -07:00
$(wildcard graph/*.cc) \
$(wildcard misc/*.cc) \
$(wildcard transport/*.cc)
2018-09-24 16:06:59 -07:00
##### lib files
LIBNAME := libnccl.so
STATICLIBNAME := libnccl_static.a
2019-04-08 18:16:54 +02:00
##### pkgconfig files
PKGCONFIGFILE := nccl.pc
2018-09-24 16:06:59 -07:00
##### dirs
BUILDDIR ?= $(abspath ../build)
INCDIR := $(BUILDDIR)/include
LIBDIR := $(BUILDDIR)/lib
OBJDIR := $(BUILDDIR)/obj
2019-04-08 18:16:54 +02:00
PKGDIR := $(BUILDDIR)/lib/pkgconfig
2018-09-24 16:06:59 -07:00
##### target files
2019-05-07 20:35:14 -04:00
CUDARTLIB ?= cudart_static
ifeq ($(CUDARTLIB), cudart_static)
# Use compatibility shim only with static cudart; see https://github.com/NVIDIA/nccl/issues/658
LIBSRCFILES += enhcompat.cc
endif
2018-09-24 16:06:59 -07:00
INCTARGETS := $(INCEXPORTS:%=$(INCDIR)/%)
LIBSONAME := $(LIBNAME:%=%.$(NCCL_MAJOR))
LIBTARGET := $(LIBNAME:%=%.$(NCCL_MAJOR).$(NCCL_MINOR).$(NCCL_PATCH))
STATICLIBTARGET := $(STATICLIBNAME)
2019-04-08 18:16:54 +02:00
PKGTARGET := $(PKGCONFIGFILE)
2019-03-14 19:39:20 -07:00
LIBOBJ := $(LIBSRCFILES:%.cc=$(OBJDIR)/%.o)
2018-09-24 16:06:59 -07:00
DEPFILES := $(LIBOBJ:%.o=%.d)
2019-05-07 20:35:14 -04:00
LDFLAGS += -L${CUDA_LIB} -l$(CUDARTLIB) -lpthread -lrt -ldl
2018-09-24 16:06:59 -07:00
2023-09-26 05:47:28 -07:00
DEVMANIFEST := $(BUILDDIR)/obj/device/manifest
2018-09-24 16:06:59 -07:00
##### rules
build : lib staticlib
2019-04-08 18:16:54 +02:00
lib : $(INCTARGETS) $(LIBDIR)/$(LIBTARGET) $(PKGDIR)/$(PKGTARGET)
2018-09-24 16:06:59 -07:00
staticlib : $(LIBDIR)/$(STATICLIBTARGET)
2023-09-26 05:47:28 -07:00
$(DEVMANIFEST): ALWAYS_REBUILD $(INCTARGETS)
$(MAKE) -C ./device
2018-09-24 16:06:59 -07:00
2018-12-13 15:56:12 -08:00
# Empty target to force rebuild
ALWAYS_REBUILD:
2018-09-24 16:06:59 -07:00
-include $(DEPFILES)
$(LIBDIR)/$(LIBTARGET) $(LIBDIR)/$(STATICLIBTARGET) : $(LIBOBJ)
2023-02-27 02:48:21 -08:00
$(INCDIR)/nccl.h : nccl.h.in ../makefiles/version.mk
2021-04-12 16:00:11 -07:00
# NCCL_VERSION(X,Y,Z) ((X) * 10000 + (Y) * 100 + (Z))
@$(eval NCCL_VERSION := $(shell printf "%d%02d%02d" $(NCCL_MAJOR) $(NCCL_MINOR) $(NCCL_PATCH)))
2018-11-09 14:00:41 -08:00
mkdir -p $(INCDIR)
2019-04-08 18:16:54 +02:00
@printf "Generating %-35s > %s\n" $< $@
2018-09-24 16:06:59 -07:00
sed -e "s/\$${nccl:Major}/$(NCCL_MAJOR)/g" \
-e "s/\$${nccl:Minor}/$(NCCL_MINOR)/g" \
-e "s/\$${nccl:Patch}/$(NCCL_PATCH)/g" \
-e "s/\$${nccl:Suffix}/$(NCCL_SUFFIX)/g" \
-e "s/\$${nccl:Version}/$(NCCL_VERSION)/g" \
$< > $@
2023-09-26 05:47:28 -07:00
$(LIBDIR)/$(LIBTARGET): $(LIBOBJ) $(DEVMANIFEST)
2018-09-24 16:06:59 -07:00
@printf "Linking %-35s > %s\n" $(LIBTARGET) $@
mkdir -p $(LIBDIR)
2023-09-26 05:47:28 -07:00
$(CXX) $(CXXFLAGS) -shared -Wl,--no-as-needed -Wl,-soname,$(LIBSONAME) -o $@ $(LIBOBJ) $$(cat $(DEVMANIFEST)) $(LDFLAGS)
2018-09-24 16:06:59 -07:00
ln -sf $(LIBSONAME) $(LIBDIR)/$(LIBNAME)
ln -sf $(LIBTARGET) $(LIBDIR)/$(LIBSONAME)
2023-09-26 05:47:28 -07:00
$(LIBDIR)/$(STATICLIBTARGET): $(LIBOBJ) $(DEVMANIFEST)
2018-09-24 16:06:59 -07:00
@printf "Archiving %-35s > %s\n" $(STATICLIBTARGET) $@
mkdir -p $(LIBDIR)
2023-09-26 05:47:28 -07:00
ar cr $@ $(LIBOBJ) $$(cat $(DEVMANIFEST))
2018-09-24 16:06:59 -07:00
2019-04-08 18:16:54 +02:00
$(PKGDIR)/nccl.pc : nccl.pc.in
mkdir -p $(PKGDIR)
@printf "Generating %-35s > %s\n" $< $@
sed -e 's|$${nccl:Prefix}|\$(PREFIX)|g' \
-e "s/\$${nccl:Major}/$(NCCL_MAJOR)/g" \
-e "s/\$${nccl:Minor}/$(NCCL_MINOR)/g" \
-e "s/\$${nccl:Patch}/$(NCCL_PATCH)/g" \
$< > $@
2018-09-24 16:06:59 -07:00
$(INCDIR)/%.h : %.h
@printf "Grabbing %-35s > %s\n" $< $@
mkdir -p $(INCDIR)
2019-11-19 14:57:39 -08:00
install -m 644 $< $@
2018-09-24 16:06:59 -07:00
2018-11-13 10:37:20 -08:00
$(INCDIR)/nccl_%.h : include/nccl_%.h
@printf "Grabbing %-35s > %s\n" $< $@
mkdir -p $(INCDIR)
2019-11-19 14:57:39 -08:00
install -m 644 $< $@
2018-11-13 10:37:20 -08:00
2019-04-08 18:16:54 +02:00
$(PKGDIR)/%.pc : %.pc
@printf "Grabbing %-35s > %s\n" $< $@
mkdir -p $(PKGDIR)
2019-11-19 14:57:39 -08:00
install -m 644 $< $@
2019-04-08 18:16:54 +02:00
2020-07-03 00:07:43 +08:00
$(OBJDIR)/%.o : %.cc $(INCTARGETS)
2018-09-24 16:06:59 -07:00
@printf "Compiling %-35s > %s\n" $< $@
mkdir -p `dirname $@`
2019-03-14 19:39:20 -07:00
$(CXX) -I. -I$(INCDIR) $(CXXFLAGS) -Iinclude -c $< -o $@
@$(CXX) -I. -I$(INCDIR) $(CXXFLAGS) -Iinclude -M $< > $(@:%.o=%.d.tmp)
2018-09-24 16:06:59 -07:00
@sed "0,/^.*:/s//$(subst /,\/,$@):/" $(@:%.o=%.d.tmp) > $(@:%.o=%.d)
@sed -e 's/.*://' -e 's/\\$$//' < $(@:%.o=%.d.tmp) | fmt -1 | \
sed -e 's/^ *//' -e 's/$$/:/' >> $(@:%.o=%.d)
@rm -f $(@:%.o=%.d.tmp)
clean :
2023-09-26 05:47:28 -07:00
$(MAKE) -C device clean
2019-11-19 14:57:39 -08:00
rm -rf ${INCDIR} ${LIBDIR} ${PKGDIR} ${OBJDIR}
2018-09-24 16:06:59 -07:00
2022-04-04 16:10:51 +02:00
install : build
2018-09-24 16:06:59 -07:00
mkdir -p $(PREFIX)/lib
2019-04-08 18:16:54 +02:00
mkdir -p $(PREFIX)/lib/pkgconfig
2018-09-24 16:06:59 -07:00
mkdir -p $(PREFIX)/include
2019-04-08 18:16:54 +02:00
cp -P -v $(BUILDDIR)/lib/lib* $(PREFIX)/lib/
cp -P -v $(BUILDDIR)/lib/pkgconfig/* $(PREFIX)/lib/pkgconfig/
2018-09-24 16:06:59 -07:00
cp -v $(BUILDDIR)/include/* $(PREFIX)/include/
2021-04-12 16:00:11 -07:00
FILESTOFORMAT := $(shell find . -name ".\#*" -prune -o \( -name "*.cc" -o -name "*.h" \) -print | grep -v -E 'ibvwrap.h|nvmlwrap.h|gdrwrap.h|nccl.h')
2018-09-24 16:06:59 -07:00
# Note that formatting.mk defines a new target so in order to not overwrite the default target,
# it shouldn't be included at the top. Also, it uses the above definition of FILESTOFORMAT as well
# as the BUILDDIR variable.
include ../makefiles/formatting.mk