================
@@ -1399,19 +1399,27 @@ void NVPTXAsmPrinter::emitFunctionParamList(const 
Function *F, raw_ostream &O) {
       if (PTy) {
         O << "\t.param .u" << PTySizeInBits << " .ptr";
 
+        bool IsCUDA = static_cast<NVPTXTargetMachine &>(TM).getDrvInterface() 
==
+                      NVPTX::CUDA;
         switch (PTy->getAddressSpace()) {
         default:
           break;
         case ADDRESS_SPACE_GLOBAL:
           O << " .global";
           break;
         case ADDRESS_SPACE_SHARED:
+          if (IsCUDA)
+            report_fatal_error(".shared ptr kernel args unsupported in CUDA.");
           O << " .shared";
           break;
         case ADDRESS_SPACE_CONST:
+          if (IsCUDA)
+            report_fatal_error(".const ptr kernel args unsupported in CUDA.");
----------------
LewisCrawford wrote:

I've updated the patch to fix the `CodeGenCUDA/memcpy-libcall.cu` test, which 
shows that even the clang frontend with a `-cuda` triple can still generate 
invalid PTX which will crash when executed in a CUDA context. This will cause a 
confusing `CUDA_ERROR_INVALID_IMAGE` error message at run-time (similar to the 
one experienced here 
https://github.com/llvm/llvm-project/pull/114874#issuecomment-2658056661 ), 
rather than failing to compile and giving the more explicit error message I've 
introduced in this patch.

Unfortunately, this issue about CUDA only supporting .global and .generic 
pointers in kernel args, is one of several cases that are missing in the PTX 
documentation, where the PTX is technically legal according to the spec, but is 
invalid when used within the CUDA API (some texture-related queries is another 
case of this incompatibilty). We plan on adding public documentation about this 
soon though.

In the mean-time, it seems better to me to have some kind of readable error 
message about this to help implementers of various front-ends, even if the docs 
are currently missing it, since the `CUDA_ERROR_INVALID_IMAGE` caused when 
running this does not provide any useful information about the problem.

https://github.com/llvm/llvm-project/pull/138706
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to