[PATCH] D78726: [CUDA] Define __CUDACC_DEBUG__ when compiling device code in debug mode

Raul Tambre via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 23 09:43:36 PDT 2020


tambre created this revision.
tambre added a reviewer: tra.
Herald added subscribers: cfe-commits, yaxunl.
Herald added a project: clang.

NVCC defines __CUDACC_DEBUG__ when compiling device code in debug mode.
Let's do the same to help with compatibility between the two and possibly enable users to select debug-friendly code.

Implements PR45596.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78726

Files:
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/test/Driver/cuda-options.cu


Index: clang/test/Driver/cuda-options.cu
===================================================================
--- clang/test/Driver/cuda-options.cu
+++ clang/test/Driver/cuda-options.cu
@@ -183,6 +183,9 @@
 // RUN:   -c %s 2>&1 \
 // RUN: | FileCheck -check-prefixes FATBIN-COMMON,PTX-SM35,PTX-SM30 %s
 
+// Verify that -g adds __CUDACC_DEBUG__ define.
+// RUN: %clang -### -target x86_64-linux-gnu -g %s 2>&1 \
+// RUN: | FileCheck -check-prefix DEBUG %s
 
 // ARCH-SM20: "-cc1"{{.*}}"-target-cpu" "sm_20"
 // NOARCH-SM20-NOT: "-cc1"{{.*}}"-target-cpu" "sm_20"
@@ -287,3 +290,5 @@
 // FATBIN-COMMON: "--image=profile=sm_35,file=
 // PTX-SM35: "--image=profile=compute_35,file=
 // NOPTX-SM35-NOT: "--image=profile=compute_35,file=
+
+// DEBUG: -D__CUDACC_DEBUG__
Index: clang/lib/Driver/ToolChains/Cuda.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -626,6 +626,11 @@
   if (DriverArgs.hasArg(options::OPT_nogpulib))
     return;
 
+  // NVCC defines __CUDACC_DEBUG__ for device code when compiling with debug
+  // info.
+  if (mustEmitDebugInfo(DriverArgs) == EmitSameDebugInfoAsHost)
+    CC1Args.push_back("-D__CUDACC_DEBUG__");
+
   std::string LibDeviceFile = CudaInstallation.getLibDeviceFile(GpuArch);
 
   if (LibDeviceFile.empty()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78726.259601.patch
Type: text/x-patch
Size: 1354 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200423/b133ec31/attachment-0001.bin>


More information about the cfe-commits mailing list