[PATCH] D104516: [mlir] Add a ThreadPool to MLIRContext and refactor MLIR threading usage

River Riddle via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 18 03:31:03 PDT 2021


rriddle created this revision.
rriddle added reviewers: mehdi_amini, lattner, stellaraccident.
Herald added subscribers: dcaballe, cota, teijeong, dexonsmith, rdzhabarov, tatianashp, msifontes, jurahul, Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, lucyrfox, mgester, arpith-jacob, antiagainst, shauheen, jfb, bollu, hiraditya, eraman.
Herald added a reviewer: aartbik.
rriddle requested review of this revision.
Herald added a reviewer: nicolasvasilache.
Herald added subscribers: llvm-commits, stephenneuendorffer, nicolasvasilache.
Herald added projects: MLIR, LLVM.

This revision refactors the usage of multithreaded utilities in MLIR to use a common
thread pool within the MLIR context, in addition to a new utility that makes writing
multi-threaded code in MLIR less error prone. Using a unified thread pool brings about
several advantages:

- Better thread usage and more control

We currently use the static llvm threading utilities, which do not allow multiple
levels of asynchronous scheduling (even if there are open threads). This is due to
how the current TaskGroup structure works, which only allows one truly multithreaded
instance at a time. By having our own ThreadPool we gain more control and flexibility
over our job/thread scheduling, and in a followup can enable threading more parts of
the compiler.

- The static nature of TaskGroup causes issues in certain configurations

Due to the static nature of TaskGroup, there have been quite a few problems related to
destruction that have caused several downstream projects to disable threading. See
D104207 <https://reviews.llvm.org/D104207> for discussion on some related fallout. By having a ThreadPool scoped to
the context, we don't have to worry about destruction and can ensure that any
additional MLIR thread usage ends when the context is destroyed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104516

Files:
  llvm/include/llvm/Support/ThreadPool.h
  llvm/lib/Support/ThreadPool.cpp
  mlir/include/mlir/IR/MLIRContext.h
  mlir/include/mlir/IR/ThreadingUtilities.h
  mlir/lib/IR/MLIRContext.cpp
  mlir/lib/IR/Verifier.cpp
  mlir/lib/Pass/Pass.cpp
  mlir/lib/Transforms/Inliner.cpp
  mlir/test/Dialect/Affine/SuperVectorize/compose_maps.mlir
  mlir/test/Dialect/Affine/slicing-utils.mlir

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104516.352961.patch
Type: text/x-patch
Size: 18348 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210618/0df3dc8b/attachment.bin>


More information about the llvm-commits mailing list