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()) {


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()) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to