Skip to main content

rustc_target/spec/targets/
nvptx64_nvidia_cuda.rs

1use crate::spec::{
2    Arch, LinkSelfContainedDefault, LinkerFlavor, MergeFunctions, Os, PanicStrategy, Target,
3    TargetMetadata, TargetOptions, cvs,
4};
5
6pub(crate) fn target() -> Target {
7    Target {
8        arch: Arch::Nvptx64,
9        data_layout: "e-p6:32:32-i64:64-i128:128-i256:256-v16:16-v32:32-n16:32:64".into(),
10        llvm_target: "nvptx64-nvidia-cuda".into(),
11        metadata: TargetMetadata {
12            description: Some("--emit=asm generates PTX code that runs on NVIDIA GPUs".into()),
13            tier: Some(2),
14            host_tools: Some(false),
15            std: Some(false),
16        },
17        pointer_width: 64,
18
19        options: TargetOptions {
20            os: Os::Cuda,
21            vendor: "nvidia".into(),
22            linker_flavor: LinkerFlavor::Llbc,
23
24            // With `ptx-linker` approach, it can be later overridden via link flags.
25            cpu: "sm_70".into(),
26
27            // No longer supported architectures
28            unsupported_cpus: cvs!(
29                "sm_20", "sm_21", "sm_30", "sm_32", "sm_35", "sm_37", "sm_50", "sm_52", "sm_53",
30                "sm_60", "sm_61", "sm_62"
31            ),
32
33            // FIXME: create tests for the atomics.
34            max_atomic_width: Some(64),
35
36            // Unwinding on CUDA is neither feasible nor useful.
37            panic_strategy: PanicStrategy::Abort,
38
39            // Needed to use `dylib` and `bin` crate types and the linker.
40            dynamic_linking: true,
41
42            // Avoid using dylib because it contain metadata not supported
43            // by LLVM NVPTX backend.
44            only_cdylib: true,
45
46            // Let the `ptx-linker` to handle LLVM lowering into MC / assembly.
47            obj_is_bitcode: true,
48
49            // Clearly a GPU
50            is_like_gpu: true,
51
52            // Convenient and predicable naming scheme.
53            dll_prefix: "".into(),
54            dll_suffix: ".ptx".into(),
55            exe_suffix: ".ptx".into(),
56
57            // Disable MergeFunctions LLVM optimisation pass because it can
58            // produce kernel functions that call other kernel functions.
59            // This behavior is not supported by PTX ISA.
60            merge_functions: MergeFunctions::Disabled,
61
62            // The LLVM backend does not support stack canaries for this target
63            supports_stack_protector: false,
64
65            // Support using `self-contained` linkers like the llvm-bitcode-linker
66            link_self_contained: LinkSelfContainedDefault::True,
67
68            // Static initializers must not have cycles on this target
69            static_initializer_must_be_acyclic: true,
70
71            ..Default::default()
72        },
73    }
74}