[PATCH] CUDA host device code with two code paths

Reid Kleckner rnk at google.com
Wed Dec 3 10:59:14 PST 2014


================
Comment at: include/clang/Basic/LangOptions.def:160
@@ -159,2 +159,3 @@
 LANGOPT(OpenMP            , 1, 0, "OpenMP support")
+BENIGN_LANGOPT(CUDAIsDevice, 1, 0, "Compiling for CUDA device")
 
----------------
I think you just want regular LANGOPT, given the description of BENIGN_LANGOPT:
  // BENIGN_LANGOPT: for options that don't affect the construction of the AST in
  //     any way (that is, the value can be different between an implicit module
  //     and the user of that module).

================
Comment at: lib/Basic/Targets.cpp:1381
@@ +1380,3 @@
+
+  // The GPU profiles supported by the NVPTX
+  enum GPUKind {
----------------
"... the NVPTX backend." maybe?

================
Comment at: lib/Frontend/InitPreprocessor.cpp:873-878
@@ -872,1 +872,8 @@
 
+  // CUDA device path compilaton
+  if (LangOpts.CUDAIsDevice) {
+    // The CUDA_ARCH value is set for the GPU target specified in the NVPTX
+    // backend's target defines.
+    Builder.defineMacro("__CUDA_ARCH__");
+  }
+
----------------
I guess this definition is intended to satisfy targeting hypothetical non-NVPTX targets from CUDA. OK.

================
Comment at: lib/Sema/SemaCUDA.cpp:91
@@ +90,3 @@
+  // however, in which case the function is compiled for both the host and the
+  // device. The __CUDA_ARCH__ macro... can be used to differentiate code paths
+  // between host and device."
----------------
The predominant style in clang for eliding text from a quotation is to use "text [...] text". I'm not trying to be pedantic, this actually threw me off when I read it. :)

I guess this applies equally to the CUDA reference quotes above.

http://reviews.llvm.org/D6457






More information about the cfe-commits mailing list