@@ -65,13 +65,16 @@ Before we can write any GPU kernels, we must add a few directives to our `lib.rs
65
65
feature(register_attr),
66
66
register_attr(nvvm_internal)
67
67
)]
68
+
69
+ use cuda_std :: * ;
68
70
```
69
71
70
72
This does a couple of things:
71
73
- It only applies the attributes if we are compiling the crate for the GPU (target_os = "cuda").
72
74
- It declares the crate to be ` no_std ` on CUDA targets.
73
75
- It registers a special attribute required by the codegen for things like figuring out
74
76
what functions are GPU kernels.
77
+ - It explicitly includes ` kernel ` macro and ` thread `
75
78
76
79
If you would like to use ` alloc ` or things like printing from GPU kernels (which requires alloc) then you need to declare ` alloc ` too:
77
80
@@ -191,6 +194,20 @@ static PTX: &str = include_str!("some/path.ptx");
191
194
192
195
Then execute it using cust.
193
196
197
+ Don't forget to include the current ` rust-toolchain ` in the top of your project:
198
+
199
+ ``` toml
200
+ # If you see this, run `rustup self update` to get rustup 1.23 or newer.
201
+
202
+ # NOTE: above comment is for older `rustup` (before TOML support was added),
203
+ # which will treat the first line as the toolchain name, and therefore show it
204
+ # to the user in the error, instead of "error: invalid channel name '[toolchain]'".
205
+
206
+ [toolchain ]
207
+ channel = " nightly-2021-12-04"
208
+ components = [" rust-src" , " rustc-dev" , " llvm-tools-preview" ]
209
+ ```
210
+
194
211
## Docker
195
212
196
213
There is also a [ Dockerfile] ( Dockerfile ) prepared as a quickstart with all the necessary libraries for base cuda development.
0 commit comments