<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/121655>121655</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Should NVPTX kernel functions be callable?
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          workingjubilee
      </td>
    </tr>
</table>

<pre>
    If we attempt to call an `amdgpu_kernel` function from a device function, the LLVM backend will reject this, as entry points for host calls are not meant to be entered again by the device functions. If we attempt to call a `ptx_kernel` function from a device function using LLVMIR, however, it seems to compile fine. Is this an intentional difference due to a runtime distinction, or is this just erroneous behavior that the backend nonetheless accepts because LLVM prefers to comply with requests to generate code, no matter how completely nonsensical they might be?

```llvm
source_filename = "example.9817a48348e8a2e6-cgu.0"
target datalayout = "e-i64:64-i128:128-v16:16-v32:32-n16:32:64"
target triple = "nvptx64-nvidia-cuda"

define ptx_kernel void @global_function() unnamed_addr #0 !dbg !6 {
  br label %bb1, !dbg !11

bb1: ; preds = %bb1, %start
  br label %bb1, !dbg !11
}

define void @_ZN7example15device_function17hba176ca620cc4fa0E() unnamed_addr #0 !dbg !12 {
  call ptx_kernel void @global_function() #1, !dbg !13
  ret void, !dbg !14
}

attributes #0 = { nounwind "target-cpu"="sm_86" }
attributes #1 = { nounwind }

!llvm.module.flags = !{!0, !1, !2}
!llvm.ident = !{!3}
!llvm.dbg.cu = !{!4}

!0 = !{i32 8, !"PIC Level", i32 2}
!1 = !{i32 2, !"Dwarf Version", i32 4}
!2 = !{i32 2, !"Debug Info Version", i32 3}
!3 = !{!"rustc version 1.85.0-nightly (4363f9b6f 2025-01-02)"}
!4 = distinct !DICompileUnit(language: DW_LANG_Rust, file: !5, producer: "clang LLVM (rustc version 1.85.0-nightly (4363f9b6f 2025-01-02))", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
!5 = !DIFile(filename: "/app/example.rs/@/example.9817a48348e8a2e6-cgu.0", directory: "/app")
!6 = distinct !DISubprogram(name: "global_function", scope: !8, file: !7, line: 5, type: !9, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !4, templateParams: !10)
!7 = !DIFile(filename: "example.rs", directory: "/app", checksumkind: CSK_MD5, checksum: "630ff75de1299520699c6090d4e43a8e")
!8 = !DINamespace(name: "example", scope: null)
!9 = !DISubroutineType(types: !10)
!10 = !{}
!11 = !DILocation(line: 6, column: 5, scope: !6)
!12 = distinct !DISubprogram(name: "device_function", linkageName: "_ZN7example15device_function17hba176ca620cc4fa0E", scope: !8, file: !7, line: 9, type: !9, scopeLine: 9, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !4, templateParams: !10)
!13 = !DILocation(line: 10, column: 14, scope: !12)
!14 = !DILocation(line: 11, column: 2, scope: !12)
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8V12P27oR_TX0y8CGRH1YevCDs66Lxd27De6madEXg5JGMrMUqfLDjvvrC9KyZW82TdKHCxiwSM4czpkzHErMGN5JxBXJPpBsM2PO7pVeHZV-5bL74iouEGeVak6rxxaOCMxa7AcLVkHNhAAmgeQR65tucLtX1BIFySNonawtVxJarXpg0OCB13idJvQB7B7h6enz71Cx-hVlA0cuBGj8grUFu-fGGzEDKK0-waC4tAZapWGvjA2bG2AaQSoLPTIZYqrQ26PGBljHuITqFDZ6s79ZwHfoeDaD_frzVMAZLrvA5PEPH_JeHfGA2j9yCwaxNwFe9QMXCC2XuIBHEyj69HFpUXokJqDhbYsaZY3QOPRuDLSTlvcIDTeWT-lTGvgI8sUZC6i1kqicgQr37MCVBrtnNrC_ZFgqiXaPAo0BVtc4WG9dM2dGKQaNLeprvOIER273oPHfDo0N8x1K1Mwi1KpBH4hU0Ps0emGOZze0KE5-N4PS8JoJH8UJet7tLVRIki2J1v6XR-efEIee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