This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][GPU] Link in device libraries during HSA compilation if needed
ClosedPublic

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

Details

Summary

To perform some operations, such as sin() or printf(), code compiled
for AMD GPUs must be linked to a series of device libraries. This
commit adds support for linking in these libraries.

However, since these device libraries are delivered as LLVM bitcode,
raising the possibility of version incompatibilities, this commit only
links in libraries when the functions from those libraries are called
by the code being compiled.

This code also sets the math flags to their most conservative values,
as MLIR doesn't have a -ffast-math equivalent.

Depends on D114114

Diff Detail

Event Timeline

krzysz00 created this revision.Nov 17 2021, 11:40 AM
krzysz00 requested review of this revision.Nov 17 2021, 11:40 AM

Can this all be exercised by a test?

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

Please avoid auto (here and elsewhere) when the type isn't obvious (or it does not improve readability)

155

I'm concerned about the use of llvm streams in the compiler: can you replace all of these with the usual diagnostics?

178

Nit: remove trivial braces (the two conditional above)

200
224

Can you add a comment describing this?

260

Nit: trivial braces

279

(again: trivial braces)

288

Can we avoid poking at the environment and use only the pass options here? That'll keep the pass as reproducible as possible.

311

Can you add a comment on this?

krzysz00 updated this revision to Diff 388328.Nov 18 2021, 2:34 PM
krzysz00 marked 2 inline comments as done.
  • Address first round of review comments
krzysz00 updated this revision to Diff 388330.Nov 18 2021, 2:38 PM
krzysz00 marked 7 inline comments as done.
  • Remove one more set of trivial braces

Thanks for all the feedback on this code!

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

I have no idea what sort of weirdness people are or aren't doing on their supercomputers,, but hopefully if they use our stuff they'll find out how to set --rocm-path or we'll go add the hooks downstream of SerializeToHsaco to set query the environment

mehdi_amini accepted this revision.Nov 18 2021, 3:58 PM
This revision is now accepted and ready to land.Nov 18 2021, 3:58 PM
krzysz00 updated this revision to Diff 388603.Nov 19 2021, 12:53 PM
  • Re-push due to dependencies landing