]> git.lizzy.rs Git - rust.git/blob - src/doc/unstable-book/src/abi-ptx.md
change the format of the linked issue number
[rust.git] / src / doc / unstable-book / src / abi-ptx.md
1 # `abi_ptx`
2
3 The tracking issue for this feature is: [#38788]
4
5 [#38788]: https://github.com/rust-lang/rust/issues/38788
6
7 ------------------------
8
9 When emitting PTX code, all vanilla Rust functions (`fn`) get translated to
10 "device" functions. These functions are *not* callable from the host via the
11 CUDA API so a crate with only device functions is not too useful!
12
13 OTOH, "global" functions *can* be called by the host; you can think of them
14 as the real public API of your crate. To produce a global function use the
15 `"ptx-kernel"` ABI.
16
17 <!-- NOTE(ignore) this example is specific to the nvptx targets -->
18
19 ``` rust,ignore
20 #![feature(abi_ptx)]
21 #![no_std]
22
23 pub unsafe extern "ptx-kernel" fn global_function() {
24     device_function();
25 }
26
27 pub fn device_function() {
28     // ..
29 }
30 ```
31
32 ``` text
33 $ xargo rustc --target nvptx64-nvidia-cuda --release -- --emit=asm
34
35 $ cat $(find -name '*.s')
36 //
37 // Generated by LLVM NVPTX Back-End
38 //
39
40 .version 3.2
41 .target sm_20
42 .address_size 64
43
44         // .globl       _ZN6kernel15global_function17h46111ebe6516b382E
45
46 .visible .entry _ZN6kernel15global_function17h46111ebe6516b382E()
47 {
48
49
50         ret;
51 }
52
53         // .globl       _ZN6kernel15device_function17hd6a0e4993bbf3f78E
54 .visible .func _ZN6kernel15device_function17hd6a0e4993bbf3f78E()
55 {
56
57
58         ret;
59 }
60 ```