Skip to content

Commit 6df8f3c

Browse files
authored
Merge pull request #10800 from tvegas1/cuda_build
BUILD: Add ability to build CUDA code
2 parents fb13ad5 + 502a12b commit 6df8f3c

File tree

6 files changed

+80
-26
lines changed

6 files changed

+80
-26
lines changed

config/cuda.am

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#
2+
# Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2025. ALL RIGHTS RESERVED.
3+
# See file LICENSE for terms.
4+
#
5+
6+
SUFFIXES = .cu
7+
8+
NVCC_CMD = $(NVCC) $(NVCCFLAGS) \
9+
-c $< -MD -MT $@ -MF $(DEPDIR)/cuda/[email protected] -o $@ \
10+
-DHAVE_CONFIG_H $(BASE_NVCCFLAGS)
11+
NVCC_LT_CMD = $(LIBTOOL) --tag=CXX --mode=compile $(NVCC_CMD)
12+
13+
define nvcc-build
14+
@$(MKDIR_P) $(shell dirname $(DEPDIR)/cuda/$@)
15+
@if $(AM_V_P); then set -x; else echo " NVCC $@"; fi; \
16+
$(if $(filter .o,$(suffix $@)),$(NVCC_CMD),$(NVCC_LT_CMD)) $($(1))
17+
endef
18+
19+
define nvcc-source
20+
EXTRA_DIST += $(2)
21+
$(1): $(2)
22+
$$(call nvcc-build,$(3))
23+
endef
24+
25+
# Default rules when no target-specific compile flags are required
26+
.cu.o:
27+
$(call nvcc-build)
28+
29+
.cu.lo:
30+
$(call nvcc-build)
31+
32+
CUDA_DEP_FILES := $(shell find $(DEPDIR)/cuda/ -type f -name *.d 2>/dev/null)
33+
-include $(CUDA_DEP_FILES)

config/m4/compiler.m4

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ AC_ARG_ENABLE(debug,
4646
[enable_debug=no])
4747
AS_IF([test "x$enable_debug" = xyes],
4848
[BASE_CFLAGS="-D_DEBUG $BASE_CFLAGS"
49-
BASE_CXXFLAGS="-D_DEBUG" $BASE_CXXFLAGS],
49+
BASE_CXXFLAGS="-D_DEBUG" $BASE_CXXFLAGS
50+
BASE_NVCCFLAGS="$BASE_NVCCFLAGS -G"],
5051
[])
5152

5253

@@ -71,9 +72,11 @@ AS_IF([test "x$enable_compiler_opt" = "xyes"], [BASE_CFLAGS="-O3 $BASE_CFLAGS"],
7172
[test "x$enable_compiler_opt" = "xnone"],
7273
[AS_IF([test "x$enable_debug" = xyes -o "x$enable_gcov" = xyes],
7374
[BASE_CFLAGS="-O0 $BASE_CFLAGS"
74-
BASE_CXXFLAGS="-O0 $BASE_CXXFLAGS"],
75+
BASE_CXXFLAGS="-O0 $BASE_CXXFLAGS"
76+
BASE_NVCCFLAGS="-O0 $BASE_NVCCFLAGS"],
7577
[BASE_CFLAGS="-O3 $BASE_CFLAGS"
76-
BASE_CXXFLAGS="-O0 $BASE_CXXFLAGS"])],
78+
BASE_CXXFLAGS="-O0 $BASE_CXXFLAGS"
79+
BASE_NVCCFLAGS="-O3 $BASE_NVCCFLAGS"])],
7780
[test "x$enable_compiler_opt" = "xno"], [],
7881
[BASE_CFLAGS="-O$enable_compiler_opt $BASE_CFLAGS"])
7982

@@ -629,8 +632,11 @@ AC_SUBST([LDFLAGS_DYNAMIC_LIST_DATA])
629632
#
630633
# Set common C preprocessor flags
631634
#
635+
SRC_INCLUDES="-I\${abs_top_srcdir}/src -I\${abs_top_builddir} -I\${abs_top_builddir}/src"
636+
632637
BASE_CPPFLAGS="-DCPU_FLAGS=\"$OPT_CFLAGS\""
633-
BASE_CPPFLAGS="$BASE_CPPFLAGS -I\${abs_top_srcdir}/src"
634-
BASE_CPPFLAGS="$BASE_CPPFLAGS -I\${abs_top_builddir}"
635-
BASE_CPPFLAGS="$BASE_CPPFLAGS -I\${abs_top_builddir}/src"
638+
BASE_CPPFLAGS="$BASE_CPPFLAGS $SRC_INCLUDES"
639+
BASE_NVCCFLAGS="$BASE_NVCCFLAGS $SRC_INCLUDES"
640+
636641
AC_SUBST([BASE_CPPFLAGS], [$BASE_CPPFLAGS])
642+
AC_SUBST([BASE_NVCCFLAGS], [$BASE_NVCCFLAGS])

config/m4/cuda.m4

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ AS_IF([test "x$cuda_checked" != "xyes"],
1010
AC_ARG_WITH([cuda],
1111
[AS_HELP_STRING([--with-cuda=(DIR)], [Enable the use of CUDA (default is guess).])],
1212
[], [with_cuda=guess])
13+
AC_ARG_WITH([nvcc],
14+
AS_HELP_STRING([--with-nvcc], [Enable NVCC compiler support (default is guess)]),
15+
[],
16+
[with_nvcc="guess"])
17+
AC_ARG_WITH([nvcc-gencode],
18+
AS_HELP_STRING([--with-nvcc-gencode=(OPTS)], [Build for specific GPU architectures]),
19+
[],
20+
[with_nvcc_gencode="-gencode=arch=compute_80,code=sm_80"])
1321
1422
AS_IF([test "x$with_cuda" = "xno"],
1523
[
@@ -97,14 +105,19 @@ AS_IF([test "x$cuda_checked" != "xyes"],
97105
98106
# Check NVCC exists and able to compile
99107
nvcc_happy="no"
100-
AC_PATH_PROGS(NVCC, nvcc, "", $CUDA_BIN_PATH:$PATH)
108+
AC_ARG_VAR([NVCC], [nvcc compiler path])
109+
AC_ARG_VAR([NVCCFLAGS], [nvcc compiler flags])
110+
AS_IF([test "x$with_nvcc" != "xno"],
111+
[AC_PATH_PROGS(NVCC, nvcc, "", $CUDA_BIN_PATH:$PATH)])
112+
101113
AS_IF([test "x$NVCC" != "x"],
102114
[AC_LANG_PUSH([C])
103115
AC_LANG_CONFTEST([AC_LANG_SOURCE([[#include <cuda_runtime.h>]])])
104116
mv conftest.c conftest.cu
105117
AC_MSG_CHECKING([$NVCC can compile])
106118
AS_IF([$NVCC -c conftest.cu 2>&AS_MESSAGE_LOG_FD],
107119
[AC_MSG_RESULT([yes])
120+
BASE_NVCCFLAGS="$BASE_NVCCFLAGS $with_nvcc_gencode -g -lineinfo"
108121
nvcc_happy="yes"],
109122
[AC_MSG_RESULT([no])
110123
cat conftest.cu >&AS_MESSAGE_LOG_FD])
@@ -116,6 +129,10 @@ AS_IF([test "x$cuda_checked" != "xyes"],
116129
LDFLAGS="$save_LDFLAGS"
117130
LIBS="$save_LIBS"
118131
132+
AS_IF([test "x$with_nvcc" = "xyes" -a "x$nvcc_happy" = "xno"],
133+
[AC_MSG_ERROR([nvcc compiler is not functional])],
134+
[])
135+
119136
AS_IF([test "x$cuda_happy" = "xyes"],
120137
[AC_SUBST([CUDA_CPPFLAGS], ["$CUDA_CPPFLAGS"])
121138
AC_SUBST([CUDA_LDFLAGS], ["$CUDA_LDFLAGS"])

configure.ac

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,10 @@ AC_MSG_NOTICE([ ROCM modules: <$(echo ${uct_rocm_modules}|tr ':' ' ') >
426426
AC_MSG_NOTICE([ IB modules: <$(echo ${uct_ib_modules}|tr ':' ' ') >])
427427
AC_MSG_NOTICE([ UCM modules: <$(echo ${ucm_modules}|tr ':' ' ') >])
428428
AC_MSG_NOTICE([ Perf modules: <$(echo ${ucx_perftest_modules}|tr ':' ' ') >])
429+
AS_IF([test "x$NVCC" != "xno"], [
430+
AC_MSG_NOTICE([ NVCC: ${NVCC}])
431+
AC_MSG_NOTICE([ NVCCFLAGS: ${NVCCFLAGS}])
432+
])
429433
AS_IF([test "x$enable_ucg" != "xno"], [
430434
AC_MSG_NOTICE([ UCG modules: <$(echo ${ucg_modules}|tr ':' ' ') >])])
431435
])

contrib/ctags.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ cd $(dirname $0)/..
99
echo "Using $PWD"
1010

1111
rm -f tags || :
12-
ctags -R -f tags .
12+
ctags -R --langmap=c++:+.cu.cuh -f tags .
1313

1414
find . -name "*.inl" -type f -exec \
1515
ctags -R -f tags \

test/apps/Makefile.am

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,20 @@ test_cuda_hook_static_LDADD = $(top_builddir)/src/ucp/libucp.la \
9898
endif
9999

100100
if HAVE_NVCC
101+
102+
include $(top_srcdir)/config/cuda.am
103+
104+
# Could be simply added as .cu to _SOURCES if there was no specific CPPFLAGS
105+
$(eval $(call nvcc-source, custom-test_cuda_get_symbol_address.o, \
106+
test_cuda_get_symbol_address.cu,CUDA_CPPFLAGS))
107+
101108
noinst_PROGRAMS += test_cuda_get_symbol_address
102-
test_cuda_get_symbol_address_SOURCES = test_cuda_get_symbol_address.cu
103-
test_cuda_get_symbol_address_CPPFLAGS = $(BASE_CPPFLAGS) $(CUDA_CPPFLAGS)
109+
test_cuda_get_symbol_address_SOURCES =
104110
test_cuda_get_symbol_address_LDFLAGS = $(CUDA_LDFLAGS)
105-
test_cuda_get_symbol_address_LDADD = $(top_builddir)/src/ucp/libucp.la \
106-
$(top_builddir)/src/ucm/libucm.la \
107-
$(CUDART_LIBS)
108-
test_cuda_get_symbol_address_DEPBASE = $(DEPDIR)/test_cuda_get_symbol_address
109-
test_cuda_get_symbol_address_COMPILE = \
110-
$(NVCC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
111-
$(test_cuda_get_symbol_address_CPPFLAGS)
111+
test_cuda_get_symbol_address_LDADD = $(CUDART_LIBS) custom-test_cuda_get_symbol_address.o \
112+
$(top_builddir)/src/ucp/libucp.la \
113+
$(top_builddir)/src/ucm/libucm.la
114+
112115
endif
113116

114117
endif
@@ -121,12 +124,3 @@ test_tcmalloc_CFLAGS = $(BASE_CFLAGS)
121124
test_tcmalloc_LDADD = -ldl $(TCMALLOC_LIB) \
122125
$(top_builddir)/src/ucp/libucp.la
123126
endif
124-
125-
.cu.o : ; $(NVCC) -c -o $@ $<
126-
127-
test_cuda_get_symbol_address.o: test_cuda_get_symbol_address.cu
128-
@am__fastdepCC_TRUE@ $(AM_V_CC)$(test_cuda_get_symbol_address_COMPILE) -MT $@ -MD -MF $(test_cuda_get_symbol_address_DEPBASE).Tpo -c -o $@ `test -f '$(<F)' || echo '$(srcdir)/'`$(<F)
129-
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(test_cuda_get_symbol_address_DEPBASE).Tpo $(test_cuda_get_symbol_address_DEPBASE).Po
130-
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$(<F)' object='$@' libtool=no @AMDEPBACKSLASH@
131-
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
132-
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(test_cuda_get_symbol_address_COMPILE) -Xcompiler "-fPIC" -c -o $@ `test -f '$(<F)' || echo '$(srcdir)/'`$(<F)

0 commit comments

Comments
 (0)