-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NVPTX target specification #57937
NVPTX target specification #57937
Changes from 1 commit
d3903d5
97c8e82
ceacde3
8d53c92
6f86a70
899d936
3f62445
49931fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,10 @@ impl LinkerInfo { | |
LinkerFlavor::Lld(LldFlavor::Wasm) => { | ||
Box::new(WasmLd::new(cmd, sess, self)) as Box<dyn Linker> | ||
} | ||
|
||
LinkerFlavor::PtxLinker => { | ||
Box::new(PtxLinker { cmd, sess }) as Box<dyn Linker> | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -1080,3 +1084,124 @@ fn exported_symbols(tcx: TyCtxt, crate_type: CrateType) -> Vec<String> { | |
|
||
symbols | ||
} | ||
|
||
/// Much simplified and explicit CLI for the NVPTX linker. The linker operates | ||
/// with bitcode and uses LLVM backend to generate a PTX assembly. | ||
pub struct PtxLinker<'a> { | ||
cmd: Command, | ||
sess: &'a Session, | ||
} | ||
|
||
impl<'a> Linker for PtxLinker<'a> { | ||
fn link_rlib(&mut self, path: &Path) { | ||
self.cmd.arg("--rlib").arg(path); | ||
} | ||
|
||
fn link_whole_rlib(&mut self, path: &Path) { | ||
self.cmd.arg("--rlib").arg(path); | ||
} | ||
|
||
fn include_path(&mut self, path: &Path) { | ||
self.cmd.arg("-L").arg(path); | ||
} | ||
|
||
fn debuginfo(&mut self) { | ||
self.cmd.arg("--debug"); | ||
} | ||
|
||
fn add_object(&mut self, path: &Path) { | ||
self.cmd.arg("--bitcode").arg(path); | ||
} | ||
|
||
fn args(&mut self, args: &[String]) { | ||
self.cmd.args(args); | ||
} | ||
|
||
fn optimize(&mut self) { | ||
self.cmd.arg(match self.sess.opts.optimize { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels suspect. I’m not sure the optimisation level for the leaf crate should influence the optimisation level for the whole crate graph. It feels like this should at least in some way depend on the LTO flag? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I followed args pattern from other linkers here. Does Rust runs optimisations before emitting bitcode object files? If yes, it can be avoided on linker's side then. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes it does.
For Such global-program optimisation is what That could be left as a future endeavour as well, but invoking “LTO” just from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the explanation and suggestion, I overlooked I've also changed |
||
OptLevel::No => "-O0", | ||
OptLevel::Less => "-O1", | ||
OptLevel::Default => "-O2", | ||
OptLevel::Aggressive => "-O3", | ||
OptLevel::Size => "-Os", | ||
OptLevel::SizeMin => "-Os" | ||
}); | ||
} | ||
|
||
fn output_filename(&mut self, path: &Path) { | ||
self.cmd.arg("-o").arg(path); | ||
} | ||
|
||
fn finalize(&mut self) -> Command { | ||
::std::mem::replace(&mut self.cmd, Command::new("")) | ||
} | ||
|
||
fn link_dylib(&mut self, _lib: &str) { | ||
panic!("external dylibs not supported") | ||
} | ||
|
||
fn link_rust_dylib(&mut self, _lib: &str, _path: &Path) { | ||
panic!("external dylibs not supported") | ||
} | ||
|
||
fn link_staticlib(&mut self, _lib: &str) { | ||
panic!("staticlibs not supported") | ||
} | ||
|
||
fn link_whole_staticlib(&mut self, _lib: &str, _search_path: &[PathBuf]) { | ||
panic!("staticlibs not supported") | ||
} | ||
|
||
fn framework_path(&mut self, _path: &Path) { | ||
panic!("frameworks not supported") | ||
} | ||
|
||
fn link_framework(&mut self, _framework: &str) { | ||
panic!("frameworks not supported") | ||
} | ||
|
||
fn position_independent_executable(&mut self) { | ||
} | ||
|
||
fn full_relro(&mut self) { | ||
} | ||
|
||
fn partial_relro(&mut self) { | ||
} | ||
|
||
fn no_relro(&mut self) { | ||
} | ||
|
||
fn build_static_executable(&mut self) { | ||
} | ||
|
||
fn gc_sections(&mut self, _keep_metadata: bool) { | ||
} | ||
|
||
fn pgo_gen(&mut self) { | ||
} | ||
|
||
fn no_default_libraries(&mut self) { | ||
} | ||
|
||
fn build_dylib(&mut self, _out_filename: &Path) { | ||
} | ||
|
||
fn export_symbols(&mut self, _tmpdir: &Path, _crate_type: CrateType) { | ||
} | ||
|
||
fn subsystem(&mut self, _subsystem: &str) { | ||
} | ||
|
||
fn no_position_independent_executable(&mut self) { | ||
} | ||
|
||
fn group_start(&mut self) { | ||
} | ||
|
||
fn group_end(&mut self) { | ||
} | ||
|
||
fn cross_lang_lto(&mut self) { | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm… so we are depending on external project by default here. Something that users are very unlikely to have installed by default.
I wonder what the error looks like when
rust-ptx-linker
is not in$PATH
. Perhaps it would make sense to shiprust-ptx-linker
as part of rustlib like we do with e.g.lld
component for some targets...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true. On the other hand, to get started with CUDA development in Rust, users will follow either docs or tutorials, where it should be mentioned how to setup the environment.
The error message is, currently:
Personally, I would love to have the linker to be shipped via rustup. But perhaps, it will be preferable to implement this as a separate PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.