[clang] [llvm] [NVPTX] Add errors for incorrect CUDA addrpaces (PR #138706)
Lewis Crawford via llvm-commits
llvm-commits at lists.llvm.org
Thu May 15 04:34:42 PDT 2025
================
@@ -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:
>Is it the argument declaration as a the pointer in non-generic/global AS that causes the runtime failure?
Or is that dereferencing of that pointer?
The example in https://github.com/llvm/llvm-project/pull/114874#issuecomment-2658056661 is an empty program that does not dereference anything. Merely launching a kernel with a pointer declared in those address-spaces is enough to trigger a run-time error, even if the pointer declarations are unused.
I agree that Asm printer is a convenient but suboptimal place for this. I'll look in to moving this to an IR validation step somewhere earlier in the pipeline.
https://github.com/llvm/llvm-project/pull/138706
More information about the llvm-commits
mailing list