-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[NFC][AMDGPU] Do not flush after printing every instruction #95237
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
Conversation
It's very expensive and doesn't achieve anything. I one test I did, it saves almost 10s on a 2m23s build, bringing it down to 2m15s using a downstream branch.
@llvm/pr-subscribers-backend-amdgpu Author: Pierre van Houtryve (Pierre-vh) ChangesIt's very expensive and doesn't achieve anything. I one test I did, it saves almost 10s on a 2m23s build, bringing it down to 2m15s using a downstream branch. Full diff: https://github.com/llvm/llvm-project/pull/95237.diff 1 Files Affected:
diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp
index 883b6c4407fe5..227b7383e16d5 100644
--- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp
+++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp
@@ -43,7 +43,6 @@ void AMDGPUInstPrinter::printRegName(raw_ostream &OS, MCRegister Reg) const {
void AMDGPUInstPrinter::printInst(const MCInst *MI, uint64_t Address,
StringRef Annot, const MCSubtargetInfo &STI,
raw_ostream &OS) {
- OS.flush();
printInstruction(MI, Address, STI, OS);
printAnnotation(OS, Annot);
}
|
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.
Nice! Does it speed up lit testing?
Could do the same in |
Answering my own question, |
Looks like this breaks tests: http://45.33.8.238/linux/140380/step_11.txt Please take a look and revert for now if it takes a while to fix. |
Investigating |
I reverted, it's some weird interaction with the order in which the output is expected in the test. |
Is it because we have some output/print are via stdout and some via stderr? |
Yes, and the test relies on this ordering for its output. I think the right move in the end is to move all those |
I would suggest changing the test to have two RUN lines, one to test stdout and one to test stderr. It should not be relying on Or, only flush stdout just before emitting an error message to stderr??? |
Yes! |
Reland of llvm#95237 With fix to failing test. It's very expensive and doesn't achieve anything. I one test I did, it saves almost 10s on a 2m23s build, bringing it down to 2m15s using a downstream branch.
…95237)" It's very expensive and doesn't achieve anything. I one test I did, it saves almost 10s on a 2m23s build, bringing it down to 2m15s using a downstream branch.
This causes MC/Disassembler/AMDGPU/decode-err.txt to fail in amd-gfx11-true16 downstream. Same reason -- stderr is getting flushed before there's enough to flush to stdout, which doesn't agree with the order of the check lines there.
I don't see how this resolves the problem. Given two streams are getting flushed interleaved at random points, it's not even guaranteed that the combined output contains complete lines. Also not going to work where check lines match both stdout and stderr and thus expect them to come in a particular order.
I would prefer that to having extra run lines. I remember introducing a utility, called errcat, for one of LLVM-based projects in the past that collects output from the streams and combines them such that the stderr part always come after the stdout one, which worked well. |
You can redirect stderr to a temp file and then just have another FileCheck run |
It resolves the problem because checking stderr/stdout being interleaved isn't a particularly good idea, IMO. With that pattern you only need to check stderr.
I think this is the right way to do it, yes. Though, I'm intrigued by the possibility that stdout/stderr could overlap in the output, like in the terminal. I'd need to see a real example of it happening though before I do any changes in that direction |
Easy, but probably not ideal from performance and disk wearing perspectives.
So it's necessary to update the tests that employ that then. |
Flushing too often - just because some tests aren't updated - is very likely way worse for performance (and your disk's lifespan). When I removed this flush call after every instruction, It reduced one build's time by almost 10%. 8 seconds wasted doing thousand of premature writes to disk.
Yes, because it's easy to fix and it's not a good pattern. |
Agree, we still should not flush on every instruction. It's just that there are probably better ways than writing to a file. |
I've always hated having the error and non error tests mixed. It would be way easier to understand split tests |
If the test is small and you really don't want to create a file (I don't understand why though), you could just run it twice, and one captures errors while the other captures stdout.
It'd be nice to have a way to have separate check lines for stderr and stdout without an intermediate file |
It fails downstream now that llvm#95237 removed flushing the output stream on printing every instruction.
It fails downstream now that #95237 removed flushing the output stream on printing every instruction.
It fails downstream now that llvm#95237 removed flushing the output stream on printing every instruction.
It fails downstream now that llvm#95237 removed flushing the output stream on printing every instruction.
It's very expensive and doesn't achieve anything.
I one test I did, it saves almost 10s on a 2m23s build, bringing it down to 2m15s using a downstream branch.