compact memory contiguity with for loops
Validate Operations / validate-operations (push) Has been cancelled

This commit is contained in:
NiccoloN
2026-05-31 18:47:59 +02:00
parent ab63498f3f
commit b678e55d3c
14 changed files with 550 additions and 331 deletions
@@ -121,13 +121,14 @@ struct FoldConstantCoreMapPattern final : OpRewritePattern<linalg::MapOp> {
rewriter.setInsertionPoint(mapOp);
auto getGlobalOp = memref::GetGlobalOp::create(rewriter, mapOp.getLoc(), initType, globalOp.getName());
auto sizeInBytes = getShapedTypeSizeInBytes(initType);
Value zeroOffset = getOrCreateIndexConstant(rewriter, mapOp, 0);
pim::PimMemCopyOp::create(rewriter,
mapOp.getLoc(),
initType,
zeroOffset,
zeroOffset,
mapOp.getInit(),
getGlobalOp.getResult(),
rewriter.getI32IntegerAttr(0),
rewriter.getI32IntegerAttr(0),
rewriter.getI32IntegerAttr(sizeInBytes));
rewriter.eraseOp(mapOp);
return success();
@@ -487,7 +488,9 @@ struct FoldConstantMemCpPattern final : OpRewritePattern<pim::PimMemCopyOp> {
if (!allocType || !allocType.hasStaticShape())
return failure();
if (copyOp.getTargetOffset() != 0 || copyOp.getSourceOffset() != 0)
auto targetOffset = resolveIndexValue(copyOp.getTargetOffset());
auto sourceOffset = resolveIndexValue(copyOp.getSourceOffset());
if (failed(targetOffset) || failed(sourceOffset) || *targetOffset != 0 || *sourceOffset != 0)
return failure();
auto moduleOp = copyOp->getParentOfType<ModuleOp>();
@@ -13,6 +13,7 @@
#include "src/Accelerators/PIM/Common/PimCommon.hpp"
#include "src/Accelerators/PIM/Common/Support/Diagnostics.hpp"
#include "src/Accelerators/PIM/Dialect/Pim/PimOps.hpp"
#include "src/Accelerators/PIM/Dialect/Pim/Transforms/Bufferization/ContiguityPatterns.hpp"
#include "src/Accelerators/PIM/Dialect/Spatial/SpatialOps.hpp"
using namespace mlir;
@@ -333,6 +334,12 @@ private:
}
if (auto storeOp = dyn_cast<pim::PimMemCopyDevToHostOp>(op)) {
if (!pim::isNormalizedCopyOp(storeOp)) {
diagnostics.report(&op, [](Operation* illegalOp) {
illegalOp->emitOpError("must use base memref operands plus explicit byte offsets after bufferization");
});
hasFailure = true;
}
if (failed(resolveIndexValue(storeOp.getHostTargetOffset(), knowledge))
|| failed(resolveIndexValue(storeOp.getDeviceSourceOffset(), knowledge))) {
diagnostics.report(&op, [](Operation* illegalOp) {
@@ -343,6 +350,12 @@ private:
}
if (auto loadOp = dyn_cast<pim::PimMemCopyHostToDevOp>(op)) {
if (!pim::isNormalizedCopyOp(loadOp)) {
diagnostics.report(&op, [](Operation* illegalOp) {
illegalOp->emitOpError("must use base memref operands plus explicit byte offsets after bufferization");
});
hasFailure = true;
}
if (failed(resolveIndexValue(loadOp.getDeviceTargetOffset(), knowledge))
|| failed(resolveIndexValue(loadOp.getHostSourceOffset(), knowledge))) {
diagnostics.report(&op, [](Operation* illegalOp) {
@@ -351,6 +364,22 @@ private:
hasFailure = true;
}
}
if (auto copyOp = dyn_cast<pim::PimMemCopyOp>(op)) {
if (!pim::isNormalizedCopyOp(copyOp)) {
diagnostics.report(&op, [](Operation* illegalOp) {
illegalOp->emitOpError("must use base memref operands plus explicit byte offsets after bufferization");
});
hasFailure = true;
}
if (failed(resolveIndexValue(copyOp.getTargetOffset(), knowledge))
|| failed(resolveIndexValue(copyOp.getSourceOffset(), knowledge))) {
diagnostics.report(&op, [](Operation* illegalOp) {
illegalOp->emitOpError("offset operands must be statically evaluable for PIM codegen");
});
hasFailure = true;
}
}
return success(!hasFailure);
});
}