Skip to content

Commit 332f1b1

Browse files
committed
Pass in autodiff items when starting the coordinator thread
As opposed to sending a message to the coordinator thread.
1 parent 797084d commit 332f1b1

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ pub(crate) fn start_async_codegen<B: ExtraBackendMethods>(
470470
backend: B,
471471
tcx: TyCtxt<'_>,
472472
target_cpu: String,
473+
autodiff_items: &[AutoDiffItem],
473474
) -> OngoingCodegen<B> {
474475
let (coordinator_send, coordinator_receive) = channel();
475476

@@ -488,6 +489,7 @@ pub(crate) fn start_async_codegen<B: ExtraBackendMethods>(
488489
backend.clone(),
489490
tcx,
490491
&crate_info,
492+
autodiff_items,
491493
shared_emitter,
492494
codegen_worker_send,
493495
coordinator_receive,
@@ -1044,9 +1046,6 @@ pub(crate) enum Message<B: WriteBackendMethods> {
10441046
/// Sent from a backend worker thread.
10451047
WorkItem { result: Result<WorkItemResult<B>, Option<WorkerFatalError>>, worker_id: usize },
10461048

1047-
/// A vector containing all the AutoDiff tasks that we have to pass to Enzyme.
1048-
AddAutoDiffItems(Vec<AutoDiffItem>),
1049-
10501049
/// The frontend has finished generating something (backend IR or a
10511050
/// post-LTO artifact) for a codegen unit, and it should be passed to the
10521051
/// backend. Sent from the main thread.
@@ -1113,6 +1112,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
11131112
backend: B,
11141113
tcx: TyCtxt<'_>,
11151114
crate_info: &CrateInfo,
1115+
autodiff_items: &[AutoDiffItem],
11161116
shared_emitter: SharedEmitter,
11171117
codegen_worker_send: Sender<CguMessage>,
11181118
coordinator_receive: Receiver<Box<dyn Any + Send>>,
@@ -1122,6 +1122,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
11221122
) -> thread::JoinHandle<Result<CompiledModules, ()>> {
11231123
let coordinator_send = tx_to_llvm_workers;
11241124
let sess = tcx.sess;
1125+
let autodiff_items = autodiff_items.to_vec();
11251126

11261127
let mut each_linked_rlib_for_lto = Vec::new();
11271128
drop(link::each_linked_rlib(crate_info, None, &mut |cnum, path| {
@@ -1375,7 +1376,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
13751376

13761377
// This is where we collect codegen units that have gone all the way
13771378
// through codegen and LLVM.
1378-
let mut autodiff_items = Vec::new();
13791379
let mut compiled_modules = vec![];
13801380
let mut compiled_allocator_module = None;
13811381
let mut needs_link = Vec::new();
@@ -1645,10 +1645,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
16451645
main_thread_state = MainThreadState::Idle;
16461646
}
16471647

1648-
Message::AddAutoDiffItems(mut items) => {
1649-
autodiff_items.append(&mut items);
1650-
}
1651-
16521648
Message::CodegenComplete => {
16531649
if codegen_state != Aborted {
16541650
codegen_state = Completed;
@@ -2117,10 +2113,6 @@ impl<B: ExtraBackendMethods> OngoingCodegen<B> {
21172113
drop(self.coordinator.sender.send(Box::new(Message::CodegenComplete::<B>)));
21182114
}
21192115

2120-
pub(crate) fn submit_autodiff_items(&self, items: Vec<AutoDiffItem>) {
2121-
drop(self.coordinator.sender.send(Box::new(Message::<B>::AddAutoDiffItems(items))));
2122-
}
2123-
21242116
pub(crate) fn check_for_errors(&self, sess: &Session) {
21252117
self.shared_emitter_main.check(sess, false);
21262118
}

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
647647
) -> OngoingCodegen<B> {
648648
// Skip crate items and just output metadata in -Z no-codegen mode.
649649
if tcx.sess.opts.unstable_opts.no_codegen || !tcx.sess.opts.output_types.should_codegen() {
650-
let ongoing_codegen = start_async_codegen(backend, tcx, target_cpu);
650+
let ongoing_codegen = start_async_codegen(backend, tcx, target_cpu, &[]);
651651

652652
ongoing_codegen.codegen_finished(tcx);
653653

@@ -667,7 +667,6 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
667667
// codegen units.
668668
let MonoItemPartitions { codegen_units, autodiff_items, .. } =
669669
tcx.collect_and_partition_mono_items(());
670-
let autodiff_fncs = autodiff_items.to_vec();
671670

672671
// Force all codegen_unit queries so they are already either red or green
673672
// when compile_codegen_unit accesses them. We are not able to re-execute
@@ -680,7 +679,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
680679
}
681680
}
682681

683-
let ongoing_codegen = start_async_codegen(backend.clone(), tcx, target_cpu);
682+
let ongoing_codegen = start_async_codegen(backend.clone(), tcx, target_cpu, autodiff_items);
684683

685684
// Codegen an allocator shim, if necessary.
686685
if let Some(kind) = allocator_kind_for_codegen(tcx) {
@@ -710,10 +709,6 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
710709
);
711710
}
712711

713-
if !autodiff_fncs.is_empty() {
714-
ongoing_codegen.submit_autodiff_items(autodiff_fncs);
715-
}
716-
717712
// For better throughput during parallel processing by LLVM, we used to sort
718713
// CGUs largest to smallest. This would lead to better thread utilization
719714
// by, for example, preventing a large CGU from being processed last and

0 commit comments

Comments
 (0)