Xilinx / mlir-aie

An MLIR-based toolchain for AMD AI Engine-enabled devices.
Other
259 stars 76 forks source link

MLIR::loopUnrollByFactor fails for small loops #1556

Open AndraBisca opened 3 weeks ago

AndraBisca commented 3 weeks ago

After #1545 designs with loops that have less iterations than the unroll factor fail silently.

It was caught by one of @eddierichter-amd designs.

The example here shows this error and expected output. The loop has 4 iterations and the unroll factor is 6.

@jtuyls

makslevental commented 2 weeks ago

You can use this to compute the trip count of an scf.for with static bounds and step: https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/Dialect/Utils/StaticValueUtils.h#L175.

makslevental commented 2 weeks ago
          if (!forLoop.getSingleLowerBound() ||
              !forLoop.getSingleUpperBound() || !forLoop.getSingleStep() ||
              constantTripCount(*forLoop.getSingleLowerBound(),
                                *forLoop.getSingleUpperBound(),
                                *forLoop.getSingleStep())
                      .value_or(0) < unrollFactor)
            forLoop.emitOpError()
                << "could not be unrolled because tripcount < unrollFactor: "
                << unrollFactor << "\n"