This is an archive of the discontinued LLVM Phabricator instance.

[mlgo] Hook up the interactive runner to the mlgo-ed passes
ClosedPublic

Authored by mtrofin on Feb 2 2023, 2:51 PM.

Details

Summary

This hooks up the interactive model runner to the passes that support
ml-based decisions. Because the interface to this runner is the exact
same as the one used during inference, we just reuse the exact same
setup we have for "release mode". This makes "release mode" a misnomer -
and that's something we needed to resolve sooner or later (e.g.
supporting more than one embedded model for the same problem was another
reason to drop that nomenclature). That will happen in a subsequent
change.

To use this evaluator, just enable the pass in (currently) "release"
mode, but also pass the base name for the 2 channel files via the
pass-specific flag.

The 2 files are the responsibilty of the hosting process. The added
tests use a minimal, toy such host, illustrating setup and
communication.

Diff Detail

Event Timeline

mtrofin created this revision.Feb 2 2023, 2:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 2 2023, 2:51 PM
mtrofin requested review of this revision.Feb 2 2023, 2:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 2 2023, 2:51 PM
kazu added inline comments.Feb 3 2023, 2:47 PM
llvm/lib/Analysis/models/interactive_host.py
2

Could you add some comments about what this script is for and how to use it (or a pointer to a .ll test that uses it)?

IIUC, the script invokes the compiler and acts as a bridge between the compiler proper and the user's model. The user is responsible for supplying the complete command line, including the compiler proper (clang, opt, etc) and the -regalloc-priority-interactive-channel-base= option to specify the base name (that is, without .in or .out) of the named pipes.

llvm/test/Transforms/Inline/ML/Inputs/interactive_main.py
12

Could you add a comment somewhere in this file?

IIUC, we say "yes, no, yes, no, ..." as expected by llvm/test/Transforms/Inline/ML/interactive-mode.ll.

mtrofin updated this revision to Diff 494750.Feb 3 2023, 3:03 PM
mtrofin marked 2 inline comments as done.

feedback

llvm/lib/Analysis/models/interactive_host.py
2

done - expanded a bit on the args, too.

kazu accepted this revision.Feb 3 2023, 3:19 PM

Thanks for the update!

This revision is now accepted and ready to land.Feb 3 2023, 3:19 PM
This revision was landed with ongoing or failed builds.Feb 3 2023, 4:23 PM
This revision was automatically updated to reflect the committed changes.
chapuni added a subscriber: chapuni.Feb 4 2023, 3:54 AM
chapuni added inline comments.
llvm/test/CodeGen/MLRegalloc/Inputs/interactive_main.py
12

Seems unsupported in py-3.8. Tweaked in e006c7dfa79a

dyung added a subscriber: dyung.Feb 4 2023, 11:50 AM

There still seems to be failures related to this change, can you take a look please?

https://lab.llvm.org/buildbot/#/builders/247/builds/1260

Traceback (most recent call last):
  File "/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/test/Transforms/Inline/ML/Output/interactive-mode.ll.tmp.rundir/interactive_main.py", line 21, in <module>
    main(sys.argv[1:])
  File "/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/test/Transforms/Inline/ML/Output/interactive-mode.ll.tmp.rundir/interactive_main.py", line 17, in main
    interactive_host.run_interactive(args[0], a.advice, args[1:])
  File "/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/test/Transforms/Inline/ML/Output/interactive-mode.ll.tmp.rundir/interactive_host.py", line 71, in run_interactive
    context, next_event, fc, tensor_specs, None)
  File "/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/test/Transforms/Inline/ML/Output/interactive-mode.ll.tmp.rundir/log_reader.py", line 100, in read_one_observation
    features.append(read_tensor(f, ts))
  File "/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/test/Transforms/Inline/ML/Output/interactive-mode.ll.tmp.rundir/log_reader.py", line 71, in read_tensor
    size = math.prod(ts.shape) * ctypes.sizeof(ts.element_type)
AttributeError: module 'math' has no attribute 'prod'
FileCheck error: '<stdin>' is empty.
FileCheck command line:  /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/bin/FileCheck /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/llvm/test/Transforms/Inline/ML/interactive-mode.ll

There still seems to be failures related to this change, can you take a look please?

https://lab.llvm.org/buildbot/#/builders/247/builds/1260

Fixed in 062380c86f061c7308c8b973a1b94e1f6323be5d.