{"id":"1a9d0641084b954a","repo":"rust-lang/rust","slug":"architecture-arch-does-not-support-gpukernel-cal","errorCode":null,"errorMessage":"Architecture {arch} does not support GpuKernel calling convention","messagePattern":"Architecture (.+?) does not support GpuKernel calling convention","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/rustc_codegen_llvm/src/abi.rs","lineNumber":740,"sourceCode":"        CanonAbi::C | CanonAbi::Rust => llvm::CCallConv,\n        CanonAbi::RustCold => llvm::PreserveMost,\n        CanonAbi::RustPreserveNone => match &sess.target.arch {\n            Arch::X86_64 | Arch::AArch64 => llvm::PreserveNone,\n            _ => llvm::CCallConv,\n        },\n        CanonAbi::RustTail => match &sess.target.arch {\n            Arch::X86 | Arch::X86_64 | Arch::AArch64 => llvm::Tail,\n            _ => sess.dcx().fatal(\"extern \\\"tail\\\" is only supported on x86, x86_64 and aarch64\"),\n        },\n        // Functions with this calling convention can only be called from assembly, but it is\n        // possible to declare an `extern \"custom\"` block, so the backend still needs a calling\n        // convention for declaring foreign functions.\n        CanonAbi::Custom => llvm::CCallConv,\n        CanonAbi::Swift => llvm::SwiftCallConv,\n        CanonAbi::GpuKernel => match &sess.target.arch {\n            Arch::AmdGpu => llvm::AmdgpuKernel,\n            Arch::Nvptx64 => llvm::PtxKernel,\n            arch => panic!(\"Architecture {arch} does not support GpuKernel calling convention\"),\n        },\n        CanonAbi::Interrupt(interrupt_kind) => match interrupt_kind {\n            InterruptKind::Avr => llvm::AvrInterrupt,\n            InterruptKind::AvrNonBlocking => llvm::AvrNonBlockingInterrupt,\n            InterruptKind::Msp430 => llvm::Msp430Intr,\n            InterruptKind::RiscvMachine | InterruptKind::RiscvSupervisor => llvm::CCallConv,\n            InterruptKind::X86 => llvm::X86_Intr,\n        },\n        CanonAbi::Arm(arm_call) => match arm_call {\n            ArmCall::Aapcs => llvm::ArmAapcsCallConv,\n            ArmCall::CCmseNonSecureCall | ArmCall::CCmseNonSecureEntry => llvm::CCallConv,\n        },\n        CanonAbi::X86(x86_call) => match x86_call {\n            X86Call::Fastcall => llvm::X86FastcallCallConv,\n            X86Call::Stdcall => llvm::X86StdcallCallConv,\n            X86Call::SysV64 => llvm::X86_64_SysV,\n            X86Call::Thiscall => llvm::X86_ThisCall,\n            X86Call::Vectorcall => llvm::X86_VectorCall,","sourceCodeStart":722,"sourceCodeEnd":758,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_codegen_llvm/src/abi.rs#L722-L758","documentation":"`panic!(\"Architecture {arch} does not support GpuKernel calling convention\")` in `to_llvm_calling_convention` for `CanonAbi::GpuKernel`. LLVM only assigns a kernel calling convention for `Arch::AmdGpu` (`llvm::AmdgpuKernel`) and `Arch::Nvptx64` (`llvm::PtxKernel`); any other target arch hits the catch-all and aborts. It fires when source declares `extern \"gpu-kernel\"` (the kernel ABI used by `rustc`'s GPU targets) but is being compiled for a non-GPU target.","triggerScenarios":"An `extern \"gpu-kernel\" fn` (or a crate that exposes one) is compiled with `--target` set to x86_64, aarch64, wasm32, etc. instead of an `amdgcn-*` or `nvptx64-*` target triple. Also triggered by proc-macro/host builds of GPU kernel crates that don't gate the ABI behind `#[cfg(target_arch = \"amdgpu\" | \"nvptx64\")]`.","commonSituations":"Building a GPU crate (e.g. a `rust-gpu`/CUDA/ROCm kernel) without setting the right `--target`; CI building the host crate graph and accidentally compiling GPU-only code; a generic library that re-exports a `gpu-kernel` ABI symbol for all targets.","solutions":["Set the target triple to a GPU target: `--target amdgcn-amd-amdhsa` or `--target nvptx64-nvidia-cuda`.","Gate `extern \"gpu-kernel\"` items behind `#[cfg(target_arch = \"amdgpu\")]` / `#[cfg(target_arch = \"nvptx64\")]`.","Split GPU kernel code into a separate crate compiled only for the GPU target; keep host crates free of the ABI.","If using rust-gpu / a build script, ensure it emits the kernel target and does not also build for the host arch."],"exampleFix":"// before\nextern \"gpu-kernel\" fn add(a: f32, b: f32) -> f32 { a + b }\n\n// after — only emit the kernel ABI on GPU targets\n#[cfg(any(target_arch = \"amdgpu\", target_arch = \"nvptx64\"))]\nextern \"gpu-kernel\" fn add(a: f32, b: f32) -> f32 { a + b }\n\n#[cfg(not(any(target_arch = \"amdgpu\", target_arch = \"nvptx64\")))]\ncompile_error!(\"`add` is a GPU kernel; compile with a gpu target\");","handlingStrategy":"validation","validationCode":"// Validate target architecture before using extern \"gpu-kernel\" ABI\nfn supports_gpu_kernel(arch: &str) -> bool {\n    matches!(arch, \"amdgcn\" | \"nvptx64\")\n}\n\nfn validate_gpu_target() -> Result<(), String> {\n    let arch = std::env::var(\"CARGO_CFG_TARGET_ARCH\")\n        .or_else(|_| std::env::var(\"TARGET_ARCH\"))\n        .map_err(|_| \"TARGET_ARCH not set\")?;\n    if !supports_gpu_kernel(&arch) {\n        return Err(format!(\n            \"Architecture '{}' does not support GpuKernel calling convention. \\\n             Supported: amdgcn, nvptx64. Compile with --target nvptx64-nvidia-cuda \\\n             or amdgcn-amd-amdhsa.\",\n            arch\n        ));\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Gate GPU kernel functions behind #[cfg(target_arch = \"nvptx64\")] or #[cfg(target_arch = \"amdgcn\")] so they only compile for GPU targets","Provide a CPU fallback implementation under #[cfg(not(any(target_arch = \"nvptx64\", target_arch = \"amdgcn\")))]","Always specify --target explicitly (e.g. cargo build --target nvptx64-nvidia-cuda) rather than relying on host defaults","Check CARGO_CFG_TARGET_ARCH in build.rs and fail early with a clear message instead of letting the compiler panic mid-build"],"tags":["rustc-codegen-llvm","abi","gpu","amdgpu","nvptx64","calling-convention","panic"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}