This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][GPU] Run generic LLVM optimizations when serializing (on AMD)
ClosedPublic

Authored by krzysz00 on Nov 17 2021, 11:08 AM.

Details

Summary
  • Adds hooks that allow SerializeTo* passes to arbitrarily transform

the produced LLVM Module before it is passed to the code generation
passes.

  • Uses these hooks within the SerializeToHsaco pass in order to run

LLVM optimizations and to set the optimization level on the
TargetMachine.

  • Adds an optLevel parameter to SerializeToHsaco

Future work may include moving much of what's been added to
SerializeToHsaco to SerializeToBlob, but that would require
confirmation from the NVVM backend maintainers that it would be
appropriate to do so.

Depends on D114107

Diff Detail

Event Timeline

krzysz00 created this revision.Nov 17 2021, 11:08 AM
krzysz00 requested review of this revision.Nov 17 2021, 11:08 AM
mehdi_amini added inline comments.Nov 17 2021, 12:49 PM
mlir/include/mlir/Dialect/GPU/Passes.h
59

Will this method be overridden / specialized?

mlir/lib/Dialect/GPU/Transforms/SerializeToBlob.cpp
41

Nit: remove trivial braces

76

(same: remove trivial braces)

77

You have an extra copy here, take a reference (or std::move)?

mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp
174

Please use diagnostics

krzysz00 updated this revision to Diff 388288.Nov 18 2021, 12:30 PM
krzysz00 marked 3 inline comments as done.
  • Adress review comments
krzysz00 marked an inline comment as done.Nov 18 2021, 12:32 PM

Commends addressed

While addressing the comments, I found this file was never being compiled, and in fact couldn't be compiled with how CMake was written. So, we now have a dependency on D114184

mlir/include/mlir/Dialect/GPU/Passes.h
59

Not by anything we've got, and if anyone wants to specialize it in the future they could just make it virtual in the next revision. Good catch.

mlir/lib/Dialect/GPU/Transforms/SerializeToBlob.cpp
76

Is not having trivial braces the local style? I've removed them because the style guide is the style guide, but I'd like to be vaguely unhappy about this decision.

krzysz00 updated this revision to Diff 388311.Nov 18 2021, 1:45 PM
krzysz00 marked an inline comment as done.
  • Add comment, remove trivial braces
krzysz00 updated this revision to Diff 388314.Nov 18 2021, 1:49 PM
  • Remove commits sitting in a different revision
mehdi_amini accepted this revision.Nov 18 2021, 3:56 PM
This revision is now accepted and ready to land.Nov 18 2021, 3:56 PM
krzysz00 updated this revision to Diff 388527.Nov 19 2021, 9:12 AM
  • Adress review comments
  • Add comment, remove trivial braces
mehdi_amini added inline comments.Mar 8 2022, 12:37 PM
mlir/lib/Dialect/GPU/CMakeLists.txt
165

I just pushed https://github.com/llvm/llvm-project/commit/b743850b736e4a89378be8bed61c1b3489b56d19 because this does not seem to do what we need, can you look into this? What's the difference between this and my commit?

Herald added a project: Restricted Project. · View Herald Transcript
mehdi_amini added inline comments.Mar 8 2022, 12:40 PM
mlir/lib/Dialect/GPU/CMakeLists.txt
165

Actually forget it: my patch does not fix it either!

krzysz00 added inline comments.Mar 8 2022, 1:41 PM
mlir/lib/Dialect/GPU/CMakeLists.txt
165

Can I get some context as to the problem?

mehdi_amini added inline comments.Mar 9 2022, 2:04 PM
mlir/lib/Dialect/GPU/CMakeLists.txt
165

See: https://github.com/llvm/llvm-project/issues/54242

There is some sort of layering issue here as there is a dependency from a transform on the ExecutionEngine.

This is also somehow not necessary as you're just reusing a convenient wrapper to setup a LLVM pipeline here.

krzysz00 added inline comments.Mar 9 2022, 2:56 PM
mlir/lib/Dialect/GPU/CMakeLists.txt
165

Could we (I can try to do it tomorrow before I leave town on Friday, but maybe it makes more sense for y'all to do it) factor out that wrapper into a separate component that both this transformation and the execution engine can depend on?

The reason we're using this wrapper is so that we don't have to maintain our own copy of how to set up opt -On, which could bitrot.

mehdi_amini added inline comments.Mar 10 2022, 4:48 PM
mlir/lib/Dialect/GPU/CMakeLists.txt
165

To me " how to set up opt -On" isn't something that belongs to MLIR in the first place. If such a helper is desirable: it should be in LLVM.