This is an archive of the discontinued LLVM Phabricator instance.

Update MLIRContext to allow injecting an external ThreadPool (NFC)
ClosedPublic

Authored by mehdi_amini on Jul 1 2021, 11:31 AM.

Details

Summary

The context can be created with threading disabled, to avoid creating a thread pool
that may be destroyed when injecting another one later.

Diff Detail

Event Timeline

mehdi_amini created this revision.Jul 1 2021, 11:31 AM
mehdi_amini requested review of this revision.Jul 1 2021, 11:31 AM
mehdi_amini retitled this revision from Update MLIRContext to allow injecting an external ThreadPool to Update MLIRContext to allow injecting an external ThreadPool (NFC).Jul 1 2021, 11:45 AM
jpienaar accepted this revision.Jul 1 2021, 12:46 PM

Seems good

mlir/lib/IR/MLIRContext.cpp
595

This interaction was confusing to me initially, could you add a comment here? May also be good to document that threadPool != nullptr doesn't mean threading is enabled.

This revision is now accepted and ready to land.Jul 1 2021, 12:46 PM

Improve doc

stellaraccident accepted this revision.Jul 1 2021, 1:23 PM
stellaraccident added inline comments.
mlir/lib/IR/MLIRContext.cpp
606

So, if I want to bring my own thread pool and avoid thrashing things by having the context spin up a bunch of threads just to reset them, is the sequence:

llvm::ThreadPool myAwesomeThreadPool;
MLIRContext ctx(registry, Threading::disabled);
ctx.setThreadPool(myAwesomeThreadPool);
ctx.enableMultithreading();

I feel that a slight improvement might be to call ctx.enableMultithreading() from setThreadPool.

Also, since the comment says This method requires that multithreading is disabled for this context prior to the call., maybe add an assert() on that here?

rriddle accepted this revision.Jul 1 2021, 1:23 PM
rriddle added inline comments.
mlir/include/mlir/IR/MLIRContext.h
57

We generally capitalize the values of enums .

mlir/lib/IR/MLIRContext.cpp
264–272

This comment looks off, can you reword the first part?

600

Should you wrap this in the previous if?

Address comments:

  • More docs, in particular include an extended version of Stella's example in the class doc.
  • Enable multi-threading when setting an external pool
  • Add some asserts around the invariants for threadPool/ownedThreadPool.
mehdi_amini marked 5 inline comments as done.Jul 1 2021, 2:00 PM