This is an archive of the discontinued LLVM Phabricator instance.

[mlgo] Stream the training data
ClosedPublic

Authored by mtrofin on Jan 19 2023, 5:39 PM.

Details

Summary

This leverages the new logging format in that we don't need to buffer
the training data, we can just write it out.

Diff Detail

Event Timeline

mtrofin created this revision.Jan 19 2023, 5:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 19 2023, 5:39 PM
mtrofin requested review of this revision.Jan 19 2023, 5:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 19 2023, 5:39 PM
kazu accepted this revision.Jan 19 2023, 9:01 PM

LGTM. Just a minor comment about currentObservationID.

llvm/include/llvm/Analysis/Utils/TrainingLogger.h
122–124

If you only care about currentObservationID().has_value(), I wonder if you can rename this function to isObservationInProgress or something and do:

return ObservationIDs.count(CurrentContext);
This revision is now accepted and ready to land.Jan 19 2023, 9:01 PM
mtrofin marked an inline comment as done.Jan 20 2023, 7:00 AM
mtrofin added inline comments.
llvm/include/llvm/Analysis/Utils/TrainingLogger.h
122–124

good point, done!

This revision was landed with ongoing or failed builds.Jan 20 2023, 7:01 AM
This revision was automatically updated to reflect the committed changes.
mtrofin marked an inline comment as done.
MatzeB added inline comments.Feb 3 2023, 5:57 PM
llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
468–469

I think I am hitting this for cases where RegAllocGreedy bails out early in the if (!hasVirtRegAlloc()) return false; check and never initializes the advisor.

Replacing with Log->switchCurrentContext() for my experiments...

mtrofin added inline comments.Feb 3 2023, 6:02 PM
llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
468–469

ack. I'll take a look. Probably in that case (!hasVirtRegAlloc()) there's also no output to log, right?

MatzeB added inline comments.Feb 3 2023, 6:04 PM
llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
468–469

Guess I can also try to first test for hasObservationInProgress() and bail out on that before checking the function name... Rebuilding and testing right now...

MatzeB added inline comments.Feb 3 2023, 6:12 PM
llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
468–469

checking for hasObservationInProgress() first was not enough to avoid hitting those errors. (the "InProgress" part of the function name seems somewhat confusing anyway as this seems to be more of an "everHadAnObservation()" behavior rather than being in the middle of a startObservation() / endObservation() thingy...)

MatzeB added inline comments.Feb 3 2023, 6:21 PM
llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
468–469

I'm not sure it's really that early-exit in RAGreedy that makes me hit that error, but I am hitting it for multiple functions within many compilation units here; will continue digging next week...

mtrofin marked 4 inline comments as done.Feb 3 2023, 7:50 PM
mtrofin added inline comments.
llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
468–469

Ack, thanks - so in the case you're seeing, we did have an observation but we get to logRewardIfNeeded for a different function first? (lmk if you can share a repro, happy to help)

jacobhegna added inline comments.Feb 4 2023, 7:22 PM
llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
468–469

I am hitting this error when training the regalloc priority model as well.