Add support for generics in offloadand remove no_mangle attribute - #159566
Add support for generics in offloadand remove no_mangle attribute#159566Sa4dUs wants to merge 6 commits into
offloadand remove no_mangle attribute#159566Conversation
This comment has been minimized.
This comment has been minimized.
| // core/std/allocators/etc. For example symbols used to hook up allocation | ||
| // are not considered for export | ||
| let codegen_fn_attrs = tcx.codegen_fn_attrs(sym_def_id); | ||
| let is_extern = codegen_fn_attrs.contains_extern_indicator(); |
There was a problem hiding this comment.
Perhaps contains_extern_indicator should return true for offload functions?
|
Great improvement ( I'll review later). |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
These commits modify the If this was unintentional then you should revert the changes before this PR is merged. |
|
Very nice!
On a sidenote: As due to 1., no more hash suffix is added to kernels, we should ensure that we fail compilation if someone tries to compile a program that defines the same mangled kernel name twice. |
| .iter() | ||
| .any(|o| matches!(o, rustc_session::config::Offload::HostMetadata(_))); | ||
| if is_host_metadata { | ||
| let crate_items = tcx.hir_crate_items(()); |
There was a problem hiding this comment.
What about trait_items? The impl_items note says it also covers traits, but he owners function on ModuleItems still collects both so they might not be exactly the same?
This comment has been minimized.
This comment has been minimized.
2c1b875 to
7860122
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
7860122 to
3686d5c
Compare
| .emit("obj") | ||
| .run(); | ||
|
|
||
| assert!(object_contains_any_symbol_substring("generic.o", &["6kernelfEB2_"])); |
There was a problem hiding this comment.
Can you explicitely set the mangling version for that? We just moved to v0 so I don't think it will change soon, but just in case.
| fn kernel(_x: f32) {} //~ ERROR symbol `_RNvC19collision_kernels_a6kernel` is already defined | ||
|
|
||
| fn main() { | ||
| _RNvC19collision_kernels_a6kernel(0.0); |
There was a problem hiding this comment.
same here, otherwise this test silently becomes useless in the (tbh probably far) future.
| /// produced by a previous `HostMetadata` pass. An empty manifest | ||
| /// means all kernel instantiations are discovered via monomorphization. | ||
| Device(String), | ||
| /// Second step in the offload pipeline, generates the host code to call kernels. |
There was a problem hiding this comment.
That's the third step now, right?
And maybe describe Device(String) above as the second step.
| Device, | ||
| /// Reads a manifest of required generic kernel instantiations | ||
| /// produced by a previous `HostMetadata` pass. An empty manifest | ||
| /// means all kernel instantiations are discovered via monomorphization. |
There was a problem hiding this comment.
The last sentence is imho a little too complicated for people not aware of how gpu compilation works. Can you clarify that it means there are either no generic kernels at all, or that generic functions are only called from non-generic gpu entry points, but never from the Host (cpu), so we don't need to track it?
| } | ||
| Offload::Device | ||
| } | ||
| "Device" => { |
There was a problem hiding this comment.
This seems risky. Do we throw a good error if there's a generic kernel but a user passes Device without a path? I'd expect he only get's a cryptic error, or?
| /// (which differs between host and device passes). | ||
| pub fn mangle_offload_export<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> String { | ||
| let instantiating_crate = if is_generic(instance) { | ||
| Some(instance.upstream_monomorphization(tcx).unwrap_or(LOCAL_CRATE)) |
There was a problem hiding this comment.
While we might compile a lot of code for the gpu, few functions will be entry points, so I guess it will be ok-ish. Otherwise we can think of smarter mangling in the future.
|
Lgtm in general and from the offload side, but let's ping @oli-obk since we talked about it at RustWeek. Is that roughly what you had in mind, or do you see any general issues? |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Add support for generics in `offload`and remove `no_mangle` attribute
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (427b2a9): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. @bors rollup=never rustc-perf Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary -5.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 3.0%, secondary -7.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 457.798s -> 460.645s (0.62%) |
View all comments
implements a 3rd pass where we collect kernel instantiations required by offload to work
also enforces consistent mangling for offload functions between host and device
closes: #150985
r? @ZuseZ4