llvm-project
e63e55ca - [mlir][acc] Add ACCRecipeMaterialization pass and reduction ops (#184252)

Commit
260 days ago
[mlir][acc] Add ACCRecipeMaterialization pass and reduction ops (#184252) Pass ---- Add the `acc-recipe-materialization` pass, which materializes OpenACC privatization, firstprivate and reduction recipes by inlining their init, copy, combiner, and destroy regions into the operation for the construct. The pass runs on acc.parallel, acc.serial, acc.kernels, and acc.loop. - Firstprivate: Inserts acc.firstprivate_map so the initial value is available on the device, then clones the recipe init and copy regions into the construct and replaces uses with the materialized alloca. Optional destroy region is cloned before the region terminator. - Private: Clones the recipe init region into the construct (at region entry or at the loop op for acc.loop private). Replaces uses of the recipe result with the materialized alloca. Optional destroy region is cloned before the region terminator. - Reduction: Creates acc.reduction_init (init region inlined) and acc.reduction_combine_region (combiner region inlined). All uses of the reduction in the region are updated to the reduction init result. New operations -------------- - acc.reduction_init: Allocates and initializes a private reduction variable from a recipe. Takes the original reduction variable and reduction_operator; has a single region that must yield one value (the private storage) via acc.yield. Used by the pass to materialize acc.reduction_recipe init regions inside the compute construct. - acc.reduction_combine_region: Combines the private reduction value with the shared reduction variable. Takes the shared and private memrefs; has a single region (the recipe combiner) terminated by acc.yield with no operands. Used by the pass to materialize the reduction recipe combiner. Both ops implement RegionBranchOpInterface. acc.yield is updated to allow terminating ReductionInitOp and ReductionCombineRegionOp regions. Supporting changes ------------------ - OpenACCUtilsLoop: Factor cloneACCRegionInto out of the existing loop-conversion helper so the pass can clone recipe regions with optional result replacement; loop conversion now calls the shared helper. - Flang: Add ReductionInitOpFortranObjectViewModel (FortranObjectViewOpInterface) for acc.reduction_init and register it in OpenACC extensions. Tests ----- - MLIR: acc-recipe-materialization-{firstprivate,private,reduction, kernel-private,parallel}.mlir (memref dialect). - Flang: acc-recipe-materialization-{firstprivate,firstprivate-derived, private,reduction,kernel-private,parallel}.fir; firstprivate test has a second RUN with -acc-optimize-firstprivate-map. --------- Co-authored-by: Scott Manley <rscottmanley@gmail.com>
Parents
Loading