Commit 0989165a authored by Valerii Hlushkov's avatar Valerii Hlushkov Committed by Tomasz Zawadzki
Browse files

cuda: add configure and build environment for .cu files



Added --with-cuda option to build and link native .cu files with nvcc.
Use CU_SRCS in a Makefile to specify your files to build.

Change-Id: Ibefd78fa0c89cd4bbc486a6a7210ebc1bbfb64dc
Signed-off-by: default avatarValerii Hlushkov <valerii.hlushkov@datacore.com>
Reviewed-on: https://review.spdk.io/c/spdk/spdk/+/26620


Tested-by: default avatarSPDK Automated Test System <spdkbot@gmail.com>
Reviewed-by: default avatarJim Harris <jim.harris@nvidia.com>
Reviewed-by: default avatarBen Walker <ben@nvidia.com>
Community-CI: Mellanox Build Bot
parent 52ecd5ce
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -256,3 +256,6 @@ CONFIG_HAVE_LZ4=n

# libaio has the RW flags (version >= 0.3.111)
CONFIG_AIO_HAVE_RW_FLAGS=n

# Build with cuda and related modules
CONFIG_CUDA=n
+18 −0
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ function usage() {
	echo " --without-crypto          Disable isa-l-crypto and vbdev crypto module."
	echo " --with-fio[=DIR]          Build fio_plugin."
	echo " --without-fio             default: /usr/src/fio"
	echo " --with-cuda               Enable the CUDA accel module."
	echo " --with-xnvme              Build xNVMe bdev module."
	echo " --without-xnvme           No path required."
	echo " --with-vhost              Build vhost target. Enabled by default."
@@ -564,6 +565,12 @@ for i in "$@"; do
		--without-xnvme)
			CONFIG[XNVME]=n
			;;
		--with-cuda)
			CONFIG[CUDA]=y
			;;
		--without-cuda)
			CONFIG[CUDA]=n
			;;
		--with-fio) ;&
		--with-fio=*)
			if [[ ${i#*=} != "$i" ]]; then
@@ -1383,6 +1390,17 @@ if [[ "${CONFIG[DEBUG]}" = "y" && $arch = aarch64* && "$CC_TYPE" = "gcc" ]]; the
	fi
fi

if [[ "${CONFIG[CUDA]}" = "y" ]]; then
	if [[ $sys_name != "Linux" ]]; then
		echo "--with-cuda is supported only in Linux!"
		exit 1
	fi
	if [[ $(command -v nvcc) = "" ]]; then
		echo "--with-cuda requires cuda build tools!"
		exit 1
	fi
fi

# We are now ready to generate final configuration. But first do sanity
# check to see if all keys in CONFIG array have its reflection in CONFIG file.
if (($(grep -cE "^\s*CONFIG_[[:alnum:]_]+=" "$rootdir/CONFIG") != ${#CONFIG[@]})); then
+24 −0
Original line number Diff line number Diff line
@@ -404,6 +404,25 @@ COMPILE_CXX=\
	$(CXX) -o $@ $(DEPFLAGS) $(CXXFLAGS) -c $< && \
	mv -f $*.d.tmp $*.d && touch -c $@

ifeq ($(CONFIG_CUDA),y)
CU_SRCS += $(CU_SRCS-y)

OBJS += $(CU_SRCS:.cu=.o)

CUDA_ARCH ?= 60

CUFLAGS = -O2 -DNODEBUG -Xcompiler -fno-exceptions -restrict --gpu-architecture=sm_$(CUDA_ARCH) \
	-cudart shared -I$(SPDK_ROOT_DIR)/include $(CU_CFLAGS)

SYS_LIBS += -ldl -lcudart -lcuda -lrt -lstdc++

COMPILE_CU=\
	$(Q)echo "  NVCC $(CUFLAGS) $S/$@"; \
	nvcc -c -o $@ $(CUFLAGS) $< && \
	nvcc -c -MM -MF $*.d.tmp $(CUFLAGS) $< && \
	mv -f $*.d.tmp $*.d && touch -c $@
endif

ENV_LDFLAGS = $(if $(SPDK_NO_LINK_ENV),,$(ENV_LINKER_ARGS))

# LTO build results in lots of false positive maybe-uninitialized warnings during linking
@@ -542,6 +561,11 @@ UNINSTALL_HEADER=\
%.o: %.cpp %.d $(MAKEFILE_LIST)
	$(COMPILE_CXX)

ifeq ($(CONFIG_CUDA),y)
%.o: %.cu %.d $(MAKEFILE_LIST)
	$(COMPILE_CU)
endif

%.d: ;

define spdk_lib_list_to_static_libs