Skip to content
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

Target option to require explicit cpu #135030

Merged
merged 1 commit into from
Jan 30, 2025
Merged

Conversation

Flakebi
Copy link
Contributor

@Flakebi Flakebi commented Jan 2, 2025

Some targets have many different CPUs and no generic CPU that can be used as a default. For these targets, the user needs to explicitly specify a CPU through -C target-cpu=.

Add an option for targets and an error message if no CPU is set.

This affects the proposed amdgpu and avr targets.

amdgpu tracking issue: #135024
AVR MCP: rust-lang/compiler-team#800

@rustbot
Copy link
Collaborator

rustbot commented Jan 2, 2025

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Nadrieril (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 2, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jan 2, 2025

These commits modify compiler targets.
(See the Target Tier Policy.)

@rust-log-analyzer

This comment has been minimized.

@Nadrieril
Copy link
Member

Looks reasonable but I lack context.

r? compiler

@rustbot rustbot assigned estebank and unassigned Nadrieril Jan 2, 2025
if tcx.sess.target.need_explicit_cpu && tcx.sess.opts.cg.target_cpu.is_none() {
// The target has no default cpu, but none is set explicitly
tcx.dcx().emit_fatal(errors::CpuRequired);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should instead error when creating the Session? If target features depend on -Ctarget-cpu, the current code would allow a check build to be done with the wrong target features available through #[cfg(target_feature)] if -Ctarget-cpu isn't used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I tried moving the code into validate_commandline_args_with_session_available, but that makes basic commands fail that don’t try to compile any code.

$ rustc --print target-cpus --target amdgcn-amd-amdhsa
error: target requires to explicitly specify a cpu with `-C target-cpu`

and for cargo

$ cargo check
error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `rustc - --crate-name ___ --print=file-names --target amdgcn-amd-amdhsa --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=split-debuginfo --print=crate-name --print=cfg` (exit status: 1)
  --- stderr
  error: target requires to explicitly specify a cpu with `-C target-cpu`

(I also tried running cargo check without moving the code and it failed without -Ctarget-cpu.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. Checking it when building the Session would prevent anything that internally uses the Session from working without -Ctarget-cpu, including those that don't need to know about the target cpu.

Some targets have many different CPUs and no generic CPU that can be
used as a default. For these targets, the user needs to explicitly
specify a CPU through `-C target-cpu=`.

Add an option for targets and an error message if no CPU is set.

This affects the proposed amdgpu and avr targets.
@rustbot rustbot added the A-run-make Area: port run-make Makefiles to rmake.rs label Jan 16, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jan 16, 2025

This PR modifies tests/run-make/. If this PR is trying to port a Makefile
run-make test to use rmake.rs, please update the
run-make port tracking issue
so we can track our progress. You can either modify the tracking issue
directly, or you can comment on the tracking issue and link this PR.

cc @jieyouxu

@Flakebi
Copy link
Contributor Author

Flakebi commented Jan 16, 2025

  • Fix review comments
  • Implement target json (de)serialization
  • Add tests

Diff

@workingjubilee
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jan 30, 2025

📌 Commit 53238c3 has been approved by workingjubilee

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 30, 2025
@workingjubilee
Copy link
Member

This is blocking PRs which are blocking PRs.

@bors p=2

@bors
Copy link
Contributor

bors commented Jan 30, 2025

⌛ Testing commit 53238c3 with merge a730edc...

@bors
Copy link
Contributor

bors commented Jan 30, 2025

☀️ Test successful - checks-actions
Approved by: workingjubilee
Pushing a730edc to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jan 30, 2025
@bors bors merged commit a730edc into rust-lang:master Jan 30, 2025
7 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Jan 30, 2025
@Flakebi Flakebi deleted the require-cpu branch January 31, 2025 00:19
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (a730edc): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results (secondary 0.7%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.7% [3.7%, 3.7%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.3% [-2.3%, -2.3%] 1
All ❌✅ (primary) - - 0

Cycles

Results (secondary 2.1%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
4.0% [3.9%, 4.2%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.9% [-1.9%, -1.9%] 1
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 778.592s -> 778.256s (-0.04%)
Artifact size: 328.95 MiB -> 328.97 MiB (0.01%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-run-make Area: port run-make Makefiles to rmake.rs merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants