Skip to content

Commit 6b53e88

Browse files
committed
Small fixes for using the new linker
1 parent b26635f commit 6b53e88

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[target.nvptx64-nvidia-cuda]
2-
rustflags = ["-Clink-args=--arch sm_35"]
2+
rustflags = ["-Clink-args=--arch sm_35", "-Clink-arg=-O3", "-Clink-arg=--lto"]
33

44
[unstable]
55
features = ["all"]

rust-cuda-derive/src/kernel/link/mod.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,10 @@ pub fn link_kernel(tokens: TokenStream) -> TokenStream {
104104
let type_layout_start_pattern = format!("\n\t// .globl\t{kernel_layout_name}");
105105

106106
if let Some(type_layout_start) = kernel_ptx.find(&type_layout_start_pattern) {
107-
const BEFORE_PARAM_PATTERN: &str = "\n.global .align 1 .b8 ";
107+
const BEFORE_PARAM_PATTERN: &str = ".global .align 1 .b8 ";
108108
const PARAM_LEN_PATTERN: &str = "[";
109109
const LEN_BYTES_PATTERN: &str = "] = {";
110-
const AFTER_BYTES_PATTERN: &str = "};\n";
111-
const BYTES_PARAM_PATTERN: &str = "};";
110+
const AFTER_BYTES_PATTERN: &str = "};";
112111

113112
let after_type_layout_start = type_layout_start + type_layout_start_pattern.len();
114113

@@ -178,7 +177,7 @@ pub fn link_kernel(tokens: TokenStream) -> TokenStream {
178177
});
179178

180179
next_type_layout =
181-
bytes_start + bytes_end_offset + BYTES_PARAM_PATTERN.len();
180+
bytes_start + bytes_end_offset + AFTER_BYTES_PATTERN.len();
182181
} else {
183182
next_type_layout = bytes_start;
184183
}
@@ -224,30 +223,31 @@ fn compile_kernel(
224223
args.to_string().to_uppercase()
225224
);
226225

227-
if let Ok(kernel_path) =
228-
build_kernel_with_specialisation(crate_path, &specialisation_var, specialisation)
229-
{
230-
let mut file = fs::File::open(&kernel_path)
231-
.unwrap_or_else(|_| panic!("Failed to open kernel file at {:?}.", &kernel_path));
226+
match build_kernel_with_specialisation(crate_path, &specialisation_var, specialisation) {
227+
Ok(kernel_path) => {
228+
let mut file = fs::File::open(&kernel_path)
229+
.unwrap_or_else(|_| panic!("Failed to open kernel file at {:?}.", &kernel_path));
232230

233-
let mut kernel_ptx = String::new();
231+
let mut kernel_ptx = String::new();
234232

235-
file.read_to_string(&mut kernel_ptx)
236-
.unwrap_or_else(|_| panic!("Failed to read kernel file at {:?}.", &kernel_path));
233+
file.read_to_string(&mut kernel_ptx)
234+
.unwrap_or_else(|_| panic!("Failed to read kernel file at {:?}.", &kernel_path));
237235

238-
colored::control::set_override(true);
239-
eprintln!(
240-
"{} {} compiling a PTX crate.",
241-
"[PTX]".bright_black().bold(),
242-
"Finished".green().bold()
243-
);
244-
colored::control::unset_override();
245-
246-
Some(kernel_ptx)
247-
} else {
248-
emit_ptx_build_error();
236+
colored::control::set_override(true);
237+
eprintln!(
238+
"{} {} compiling a PTX crate.",
239+
"[PTX]".bright_black().bold(),
240+
"Finished".green().bold()
241+
);
242+
colored::control::unset_override();
249243

250-
None
244+
Some(kernel_ptx)
245+
},
246+
Err(err) => {
247+
eprintln!("{err:?}");
248+
emit_ptx_build_error();
249+
None
250+
},
251251
}
252252
}
253253

rust-cuda-derive/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#![feature(box_patterns)]
33
#![feature(proc_macro_tracked_env)]
44
#![feature(proc_macro_span)]
5-
#![feature(non_exhaustive_omitted_patterns_lint)]
65
#![feature(if_let_guard)]
76
#![feature(let_chains)]
87
#![doc(html_root_url = "https://juntyr.github.io/rust-cuda/")]

0 commit comments

Comments
 (0)