From 227326d7b3bd52d3f6d51f830a5eba17945617e6 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauldmccarthy@gmail.com>
Date: Mon, 17 Aug 2020 16:39:36 +0100
Subject: [PATCH] MNT: Tweaks to cuda compile flags (more to come). Clean
 target removes FXFILES and lib files. Ignore CPPFLAGS from the environment.

---
 config/common/buildSettings.mk | 34 +++++++++++++++++++---------------
 config/common/rules.mk         |  3 ++-
 config/common/vars.mk          | 12 +++++++-----
 3 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/config/common/buildSettings.mk b/config/common/buildSettings.mk
index 8842e47..243b565 100644
--- a/config/common/buildSettings.mk
+++ b/config/common/buildSettings.mk
@@ -84,29 +84,37 @@ endif # if Linux
 
 #####################################################################
 #
-# Linux specific sys vars and ext libs
+# CUDA specific sys vars and ext libs
 #
 #####################################################################
 
-# CUDA library
+# CUDA/nvcc compiler options
 ifneq ($(shell which nvcc), )
+
+  # TODO Allow override, don't
+  #      assume CUDADIR=FSLDIR
   NVCC          = nvcc
   CUDAVER       = $(shell nvcc --version | grep -Po "release \K[0-9\.]+")
   GENCODE_FLAGS = $(shell ${FSLDIR}/config/common/supportedGencodes.sh ${CUDAVER})
   CUDADIR       = ${FSLDIR}
 
-  CUDACXXFLAGS = -I${CUDADIR}/include \
-                 ${GENCODE_FLAGS} \
-                 --compiler-options \
-                 "-fexpensive-optimizations -Wall -Wno-long-long -fPIC" \
-                 -DARMA_ALLOW_FAKE_GCC
-  CUDALDFLAGS  = -L${CUDADIR}/lib -lcuda -lcurand -lcudart
-
-  $(info "GPU enable")
+  # nvcc-specific tweaks:
+  #  - Define ARMA_ALLOW_FAKE_GCC, otherwise byte-alignment issues
+  #    may occur with armadillo datatypes (see compiler_setup.hpp
+  #    from the armadillo project)
+  #  - Do not use -pedantic, otherwise *every single line* of
+  #    transpiled cuda code will trigger "warning: style of line
+  #    directive is a GCC extension".
+  CUDACXXFLAGS  = -I${CUDADIR}/include  \
+                  ${GENCODE_FLAGS}      \
+                  -DARMA_ALLOW_FAKE_GCC \
+                  --compiler-options    \
+                  "$(filter-out -pedantic, ${ARCHCXXFLAGS})"
+  CUDALDFLAGS   = -lcurand -lcudart
 
   ifeq ($(SYSTYPE), Darwin)
 
-    #Project specific variables
+    # Project specific variables
     EDDYBUILDPARAMETERS = "cuda=1 CUDAVER=7.5" "cpu=1"
     FDT_COMPILE_GPU     = 0
     PTX2_COMPILE_GPU    = 0
@@ -120,8 +128,4 @@ ifneq ($(shell which nvcc), )
     FDT_COMPILE_GPU     = 1
     PTX2_COMPILE_GPU    = 1
   endif # if Linux
-else
-  $(info "GPU disable")
-  FDT_COMPILE_GPU  = 0
-  PTX2_COMPILE_GPU = 0
 endif
diff --git a/config/common/rules.mk b/config/common/rules.mk
index 0554fa1..bc62e0d 100644
--- a/config/common/rules.mk
+++ b/config/common/rules.mk
@@ -6,7 +6,8 @@ help:
 	@echo " make install Install into your local FSLDEVDIR";
 
 clean:
-	${RM} -f *.o *.a *.so *.exe depend.mk ${XFILES} ${TESTXFILES}
+	${RM} -f *.o *.a *.so *.exe depend.mk \
+      ${XFILES} ${FXFILES} ${SOFILES} ${AFILES} ${TESTXFILES}
 
 install:
 	@${MAKE} "DESTDIR=${FSLDEVDIR}" master-install-script
diff --git a/config/common/vars.mk b/config/common/vars.mk
index c7e9770..f84da98 100644
--- a/config/common/vars.mk
+++ b/config/common/vars.mk
@@ -54,6 +54,7 @@ INCFLAGS = ${USRINCFLAGS} -I. -I${DEVINCDIR} -I${INCDIR}
 # Ignore flags provided by the environment
 CFLAGS   =
 CXXFLAGS =
+CPPFLAGS =
 LDFLAGS  =
 
 # All projects must use these flags for
@@ -64,8 +65,9 @@ LDFLAGS  =
 #
 # LDFLAGS *must* come at the end, to ensure proper linking.
 
-LDFLAGS  += ${ARCHLDFLAGS} ${USRLDFLAGS} \
-            -L. -L${DEVLIBDIR} -L${LIBDIR} \
-            ${LIBS} ${ARCHLIBS}
-CFLAGS   += ${ARCHCFLAGS}   ${USRCFLAGS}   ${INCFLAGS}
-CXXFLAGS += ${ARCHCXXFLAGS} ${USRCXXFLAGS} ${INCFLAGS}
+LDFLAGS      += ${ARCHLDFLAGS} ${USRLDFLAGS} \
+                -L. -L${DEVLIBDIR} -L${LIBDIR} \
+                ${LIBS} ${ARCHLIBS}
+CFLAGS       += ${ARCHCFLAGS}   ${USRCFLAGS}   ${INCFLAGS}
+CXXFLAGS     += ${ARCHCXXFLAGS} ${USRCXXFLAGS} ${INCFLAGS}
+CUDACXXFLAGS +=                                ${INCFLAGS}
-- 
GitLab