Add DCP alghoritm, partial working test

This commit is contained in:
ilgeco
2026-04-07 22:05:39 +02:00
parent ef4743c986
commit ca56e3d4f1
17 changed files with 1313 additions and 33 deletions

View File

@@ -0,0 +1,52 @@
#include "mlir/IR/OpDefinition.h"
#include "mlir/IR/Value.h"
#include "mlir/IR/ValueRange.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Casting.h"
#include <iterator>
#include "../SpatialOps.hpp"
#include "DCPAnalysis.hpp"
#include "Graph.hpp"
#include "src/Support/TypeUtilities.hpp"
namespace onnx_mlir {
namespace spatial {
using namespace mlir;
DCPAnalysisResult DCPAnalysis::runAnalysis() {
using EdgesIndex = std::tuple<int64_t, int64_t, int64_t>;
llvm::SmallVector<SpatWeightedCompute, 10> spatWeightedComputes;
llvm::SmallVector<EdgesIndex, 10> edges;
for (auto& regions : entryOp->getRegions())
for (SpatWeightedCompute spatWeightedCompute : regions.getOps<SpatWeightedCompute>())
spatWeightedComputes.push_back(spatWeightedCompute);
for (auto [indexEndEdge, spatWeightedCompute] : llvm::enumerate(spatWeightedComputes)) {
for (Value input : spatWeightedCompute.getInputs()) {
if (auto spatWeightedComputeArgOp = llvm::dyn_cast_if_present<SpatWeightedCompute>(input.getDefiningOp());
spatWeightedComputeArgOp) {
auto elemIter = llvm::find(spatWeightedComputes, spatWeightedComputeArgOp);
assert(elemIter != spatWeightedComputes.end());
auto indexStartEdge = std::distance(spatWeightedComputes.begin(), elemIter);
ResultRange outputs = spatWeightedComputeArgOp.getResults();
int64_t totalSize = 0;
for (auto output : outputs) {
ShapedType result = cast<ShapedType>(output.getType());
totalSize += getSizeInBytes(result);
}
edges.push_back({indexStartEdge, indexEndEdge, totalSize});
}
}
}
GraphDCP graphDCP(spatWeightedComputes, edges);
graphDCP.DCP();
return graphDCP.getResult();
}
} // namespace spatial
} // namespace onnx_mlir