diff --git a/src/PIM/Common/IR/SubviewUtils.cpp b/src/PIM/Common/IR/SubviewUtils.cpp index 6284b00..32c3f4b 100644 --- a/src/PIM/Common/IR/SubviewUtils.cpp +++ b/src/PIM/Common/IR/SubviewUtils.cpp @@ -1,7 +1,6 @@ -#include "src/Accelerators/PIM/Common/IR/SubviewUtils.hpp" - #include "mlir/IR/BuiltinTypeInterfaces.h" +#include "src/Accelerators/PIM/Common/IR/SubviewUtils.hpp" #include "src/Accelerators/PIM/Common/PimCommon.hpp" using namespace mlir; diff --git a/src/PIM/Common/Support/ReportUtils.cpp b/src/PIM/Common/Support/ReportUtils.cpp index 49b0e7e..334b43b 100644 --- a/src/PIM/Common/Support/ReportUtils.cpp +++ b/src/PIM/Common/Support/ReportUtils.cpp @@ -1,8 +1,7 @@ -#include "src/Accelerators/PIM/Common/Support/ReportUtils.hpp" - #include "llvm/Support/Format.h" #include "src/Accelerators/PIM/Common/Support/FileSystemUtils.hpp" +#include "src/Accelerators/PIM/Common/Support/ReportUtils.hpp" namespace onnx_mlir { diff --git a/src/PIM/Common/Support/ReportUtils.hpp b/src/PIM/Common/Support/ReportUtils.hpp index dde9cb3..0c3a470 100644 --- a/src/PIM/Common/Support/ReportUtils.hpp +++ b/src/PIM/Common/Support/ReportUtils.hpp @@ -1,10 +1,9 @@ #pragma once -#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/Support/raw_ostream.h" -#include #include #include #include diff --git a/src/PIM/Compiler/PimBinaryFormat.hpp b/src/PIM/Compiler/PimBinaryFormat.hpp index 216a947..31b06a5 100644 --- a/src/PIM/Compiler/PimBinaryFormat.hpp +++ b/src/PIM/Compiler/PimBinaryFormat.hpp @@ -70,9 +70,7 @@ inline void writeUint32LE(llvm::raw_ostream& os, uint32_t value) { os.write(bytes.data(), bytes.size()); } -inline void writeInt32LE(llvm::raw_ostream& os, int32_t value) { - writeUint32LE(os, static_cast(value)); -} +inline void writeInt32LE(llvm::raw_ostream& os, int32_t value) { writeUint32LE(os, static_cast(value)); } inline void writeHeader(llvm::raw_ostream& os) { os.write(kMagic, sizeof(kMagic)); @@ -186,39 +184,39 @@ inline Opcode opcodeFromString(llvm::StringRef opName) { inline llvm::StringRef opcodeToString(Opcode opcode) { switch (opcode) { - case Opcode::nop: return "nop"; - case Opcode::sldi: return "sldi"; - case Opcode::sld: return "sld"; - case Opcode::sadd: return "sadd"; - case Opcode::ssub: return "ssub"; - case Opcode::smul: return "smul"; - case Opcode::saddi: return "saddi"; - case Opcode::smuli: return "smuli"; - case Opcode::setbw: return "setbw"; - case Opcode::mvmul: return "mvmul"; - case Opcode::vvadd: return "vvadd"; - case Opcode::vvsub: return "vvsub"; - case Opcode::vvmul: return "vvmul"; - case Opcode::vvdmul: return "vvdmul"; - case Opcode::vvmax: return "vvmax"; - case Opcode::vvsll: return "vvsll"; - case Opcode::vvsra: return "vvsra"; - case Opcode::vavg: return "vavg"; - case Opcode::vrelu: return "vrelu"; - case Opcode::vtanh: return "vtanh"; - case Opcode::vsigm: return "vsigm"; + case Opcode::nop: return "nop"; + case Opcode::sldi: return "sldi"; + case Opcode::sld: return "sld"; + case Opcode::sadd: return "sadd"; + case Opcode::ssub: return "ssub"; + case Opcode::smul: return "smul"; + case Opcode::saddi: return "saddi"; + case Opcode::smuli: return "smuli"; + case Opcode::setbw: return "setbw"; + case Opcode::mvmul: return "mvmul"; + case Opcode::vvadd: return "vvadd"; + case Opcode::vvsub: return "vvsub"; + case Opcode::vvmul: return "vvmul"; + case Opcode::vvdmul: return "vvdmul"; + case Opcode::vvmax: return "vvmax"; + case Opcode::vvsll: return "vvsll"; + case Opcode::vvsra: return "vvsra"; + case Opcode::vavg: return "vavg"; + case Opcode::vrelu: return "vrelu"; + case Opcode::vtanh: return "vtanh"; + case Opcode::vsigm: return "vsigm"; case Opcode::vsoftmax: return "vsoftmax"; - case Opcode::vmv: return "vmv"; - case Opcode::vrsu: return "vrsu"; - case Opcode::vrsl: return "vrsl"; - case Opcode::ld: return "ld"; - case Opcode::st: return "st"; - case Opcode::lldi: return "lldi"; - case Opcode::lmv: return "lmv"; - case Opcode::send: return "send"; - case Opcode::recv: return "recv"; - case Opcode::wait: return "wait"; - case Opcode::sync: return "sync"; + case Opcode::vmv: return "vmv"; + case Opcode::vrsu: return "vrsu"; + case Opcode::vrsl: return "vrsl"; + case Opcode::ld: return "ld"; + case Opcode::st: return "st"; + case Opcode::lldi: return "lldi"; + case Opcode::lmv: return "lmv"; + case Opcode::send: return "send"; + case Opcode::recv: return "recv"; + case Opcode::wait: return "wait"; + case Opcode::sync: return "sync"; } llvm_unreachable("Unsupported PIM binary opcode"); } @@ -235,9 +233,7 @@ inline InstructionRecord makeInstructionRecord(const llvm::json::Object& instruc case Opcode::sldi: case Opcode::saddi: case Opcode::smuli: - case Opcode::lldi: - record.r2OrImm = getOptionalInt(instruction, "imm"); - break; + case Opcode::lldi: record.r2OrImm = getOptionalInt(instruction, "imm"); break; case Opcode::mvmul: record.r2OrImm = getOptionalInt(instruction, "mbiw"); record.generic1 = getOptionalInt(instruction, "relu"); @@ -252,9 +248,7 @@ inline InstructionRecord makeInstructionRecord(const llvm::json::Object& instruc record.r2OrImm = getOptionalInt(instruction, "core"); record.generic3 = getOptionalInt(instruction, "size"); break; - default: - record.r2OrImm = getOptionalInt(instruction, "rs2"); - break; + default: record.r2OrImm = getOptionalInt(instruction, "rs2"); break; } if (record.opcode != Opcode::mvmul && record.opcode != Opcode::setbw) { @@ -371,8 +365,7 @@ inline llvm::json::Object makeInstructionJson(const InstructionRecord& record) { break; case Opcode::wait: case Opcode::sync: - case Opcode::nop: - break; + case Opcode::nop: break; } return instruction; diff --git a/src/PIM/Compiler/PimCodeGen.cpp b/src/PIM/Compiler/PimCodeGen.cpp index b4fe48a..ba6f288 100644 --- a/src/PIM/Compiler/PimCodeGen.cpp +++ b/src/PIM/Compiler/PimCodeGen.cpp @@ -367,7 +367,7 @@ void PimCodeGen::emitMemCopyOp(StringRef opName, instruction.generic1 = 0; instruction.generic2 = 0; instruction.generic3 = static_cast(size); - (void)sizeFieldName; + (void) sizeFieldName; emitInstruction(instruction); } diff --git a/src/PIM/Conversion/SpatialToPim/TensorPackingPatterns.cpp b/src/PIM/Conversion/SpatialToPim/TensorPackingPatterns.cpp index 651914d..9a65fc3 100644 --- a/src/PIM/Conversion/SpatialToPim/TensorPackingPatterns.cpp +++ b/src/PIM/Conversion/SpatialToPim/TensorPackingPatterns.cpp @@ -1,5 +1,4 @@ #include "src/Accelerators/PIM/Conversion/SpatialToPim/TensorPackingPatterns.hpp" - #include "src/Accelerators/PIM/Dialect/Pim/PimOps.hpp" using namespace mlir; @@ -75,16 +74,14 @@ struct PackSpatialConcatInputsPattern final : OpRewritePattern(concatOp.getOutput().getType()); - auto newConcat = pim::PimConcatOp::create(rewriter, - concatOp.getLoc(), - concatOp.getOutput().getType(), - concatOp.getAxisAttr(), - ValueRange(packedInputs), - tensor::EmptyOp::create(rewriter, - concatOp.getLoc(), - outputType.getShape(), - outputType.getElementType()) - .getResult()); + auto newConcat = pim::PimConcatOp::create( + rewriter, + concatOp.getLoc(), + concatOp.getOutput().getType(), + concatOp.getAxisAttr(), + ValueRange(packedInputs), + tensor::EmptyOp::create(rewriter, concatOp.getLoc(), outputType.getShape(), outputType.getElementType()) + .getResult()); rewriter.replaceOp(concatOp, newConcat.getOutput()); return success(); } diff --git a/src/PIM/Conversion/SpatialToPim/TensorPackingPatterns.hpp b/src/PIM/Conversion/SpatialToPim/TensorPackingPatterns.hpp index 34feea6..73997dd 100644 --- a/src/PIM/Conversion/SpatialToPim/TensorPackingPatterns.hpp +++ b/src/PIM/Conversion/SpatialToPim/TensorPackingPatterns.hpp @@ -1,7 +1,7 @@ #pragma once -#include "mlir/Dialect/Tensor/IR/Tensor.h" #include "mlir/Dialect/Func/IR/FuncOps.h" +#include "mlir/Dialect/Tensor/IR/Tensor.h" #include "mlir/IR/PatternMatch.h" #include "src/Accelerators/PIM/Dialect/Spatial/SpatialOps.hpp" diff --git a/src/PIM/Dialect/Pim/Transforms/StaticMemoryCoalescing/StaticMemoryCoalescing.cpp b/src/PIM/Dialect/Pim/Transforms/StaticMemoryCoalescing/StaticMemoryCoalescing.cpp index 46be194..47cb267 100644 --- a/src/PIM/Dialect/Pim/Transforms/StaticMemoryCoalescing/StaticMemoryCoalescing.cpp +++ b/src/PIM/Dialect/Pim/Transforms/StaticMemoryCoalescing/StaticMemoryCoalescing.cpp @@ -1,15 +1,15 @@ -#include "src/Accelerators/PIM/Dialect/Pim/Transforms/StaticMemoryCoalescing/StaticMemoryCoalescing.hpp" - #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/Interfaces/DestinationStyleOpInterface.h" #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/STLExtras.h" #include +#include "src/Accelerators/PIM/Dialect/Pim/Transforms/StaticMemoryCoalescing/StaticMemoryCoalescing.hpp" + using namespace mlir; namespace onnx_mlir { @@ -29,9 +29,8 @@ static uint64_t getTypeSizeBytes(MemRefType type) { return static_cast(type.getNumElements() * type.getElementTypeBitWidth() / 8); } -static FailureOr getLastUseInstruction(memref::AllocOp allocOp, - Block& body, - const DenseMap& opOrder) { +static FailureOr +getLastUseInstruction(memref::AllocOp allocOp, Block& body, const DenseMap& opOrder) { uint64_t endInstruction = opOrder.lookup(allocOp); SmallPtrSet visited; SmallVector pendingValues; @@ -45,10 +44,9 @@ static FailureOr getLastUseInstruction(memref::AllocOp allocOp, if (!visited.insert(user).second) continue; - if (isSupportedAliasOp(user)) { + if (isSupportedAliasOp(user)) for (Value result : user->getResults()) pendingValues.push_back(result); - } if (auto dpsOp = dyn_cast(user)) { for (OpResult result : user->getResults()) { diff --git a/src/PIM/Dialect/Pim/Transforms/StaticMemoryCoalescing/StaticMemoryCoalescing.hpp b/src/PIM/Dialect/Pim/Transforms/StaticMemoryCoalescing/StaticMemoryCoalescing.hpp index 62938ee..3c656f6 100644 --- a/src/PIM/Dialect/Pim/Transforms/StaticMemoryCoalescing/StaticMemoryCoalescing.hpp +++ b/src/PIM/Dialect/Pim/Transforms/StaticMemoryCoalescing/StaticMemoryCoalescing.hpp @@ -2,7 +2,6 @@ #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/IR/PatternMatch.h" -#include "mlir/IR/Operation.h" #include "llvm/ADT/SmallVector.h" diff --git a/src/PIM/Dialect/Pim/Transforms/StaticMemoryCoalescing/StaticMemoryCoalescingPass.cpp b/src/PIM/Dialect/Pim/Transforms/StaticMemoryCoalescing/StaticMemoryCoalescingPass.cpp index b0d4516..db550be 100644 --- a/src/PIM/Dialect/Pim/Transforms/StaticMemoryCoalescing/StaticMemoryCoalescingPass.cpp +++ b/src/PIM/Dialect/Pim/Transforms/StaticMemoryCoalescing/StaticMemoryCoalescingPass.cpp @@ -45,9 +45,7 @@ struct CoalescingReportEntry { CoalescingReportRow row; }; -static std::string formatMemory(uint64_t bytes) { - return formatReportMemory(bytes); -} +static std::string formatMemory(uint64_t bytes) { return formatReportMemory(bytes); } static SmallVector getBatchCoreIds(pim::PimCoreBatchOp coreBatchOp) { auto coreIdsAttr = coreBatchOp->getAttrOfType(onnx_mlir::kCoreIdsAttrName); @@ -58,9 +56,10 @@ static SmallVector getBatchCoreIds(pim::PimCoreBatchOp coreBatchOp) { static void printReportRow(raw_ostream& os, const CoalescingReportRow& row) { llvm::SmallVector fields = { {"Number of candidates", std::to_string(row.numCandidates)}, - {"Skipped allocations", std::to_string(row.numSkipped)}, - {"Removed allocations", std::to_string(row.numRemoved)}, - {"Saved memory", formatMemory(row.savedBytes)}}; + {"Skipped allocations", std::to_string(row.numSkipped) }, + {"Removed allocations", std::to_string(row.numRemoved) }, + {"Saved memory", formatMemory(row.savedBytes) } + }; printReportFlatFields(os, fields); } @@ -87,10 +86,12 @@ static void emitReport(ArrayRef entries) { totalRow.savedBytes += entryTotal.savedBytes; } - llvm::SmallVector totalFields = {{"Number of candidates", std::to_string(totalRow.numCandidates)}, - {"Skipped allocations", std::to_string(totalRow.numSkipped)}, - {"Removed allocations", std::to_string(totalRow.numRemoved)}, - {"Saved memory", formatMemory(totalRow.savedBytes)}}; + llvm::SmallVector totalFields = { + {"Number of candidates", std::to_string(totalRow.numCandidates)}, + {"Skipped allocations", std::to_string(totalRow.numSkipped) }, + {"Removed allocations", std::to_string(totalRow.numRemoved) }, + {"Saved memory", formatMemory(totalRow.savedBytes) } + }; printReportTotalsBlock(os, totalFields); if (!entries.empty()) os << "\n"; @@ -127,15 +128,17 @@ static void emitReport(ArrayRef entries) { if (sortedEntries[index].kind == CoalescingReportEntry::Kind::Batch) { llvm::SmallVector perCoreFields = { {"Number of candidates", std::to_string(sortedEntries[index].row.numCandidates)}, - {"Skipped allocations", std::to_string(sortedEntries[index].row.numSkipped)}, - {"Removed allocations", std::to_string(sortedEntries[index].row.numRemoved)}, - {"Saved memory", formatMemory(sortedEntries[index].row.savedBytes)}}; + {"Skipped allocations", std::to_string(sortedEntries[index].row.numSkipped) }, + {"Removed allocations", std::to_string(sortedEntries[index].row.numRemoved) }, + {"Saved memory", formatMemory(sortedEntries[index].row.savedBytes) } + }; CoalescingReportRow totalRow = getTotalRow(sortedEntries[index]); llvm::SmallVector totalFields = { {"Number of candidates", std::to_string(totalRow.numCandidates)}, - {"Skipped allocations", std::to_string(totalRow.numSkipped)}, - {"Removed allocations", std::to_string(totalRow.numRemoved)}, - {"Saved memory", formatMemory(totalRow.savedBytes)}}; + {"Skipped allocations", std::to_string(totalRow.numSkipped) }, + {"Removed allocations", std::to_string(totalRow.numRemoved) }, + {"Saved memory", formatMemory(totalRow.savedBytes) } + }; printReportPerCoreAndTotalFields(os, perCoreFields, totalFields); } else { @@ -196,8 +199,6 @@ struct StaticMemoryCoalescingPass : PassWrapper createPimStaticMemoryCoalescingPass() { - return std::make_unique(); -} +std::unique_ptr createPimStaticMemoryCoalescingPass() { return std::make_unique(); } } // namespace onnx_mlir diff --git a/src/PIM/Dialect/Spatial/Transforms/MergeComputeNodes/MergeComputeNodesPass.cpp b/src/PIM/Dialect/Spatial/Transforms/MergeComputeNodes/MergeComputeNodesPass.cpp index a60b64e..2b90118 100644 --- a/src/PIM/Dialect/Spatial/Transforms/MergeComputeNodes/MergeComputeNodesPass.cpp +++ b/src/PIM/Dialect/Spatial/Transforms/MergeComputeNodes/MergeComputeNodesPass.cpp @@ -818,13 +818,14 @@ void generateReport(func::FuncOp funcOp, const std::string& name, size_t usedCpu } } - llvm::SmallVector totalFields = {{"Used cores", std::to_string(usedCpuCount)}, - {"Number of top-level compute ops", std::to_string(totalComputeOps)}, - {"Number of logical computes", std::to_string(totalLogicalComputes)}, - {"Number of top-level batch compute ops", - std::to_string(totalBatchComputeOps)}, - {"Number of instructions", std::to_string(totalInstructionCount)}, - {"Number of used crossbars", std::to_string(totalWeightCount)}}; + llvm::SmallVector totalFields = { + {"Used cores", std::to_string(usedCpuCount) }, + {"Number of top-level compute ops", std::to_string(totalComputeOps) }, + {"Number of logical computes", std::to_string(totalLogicalComputes) }, + {"Number of top-level batch compute ops", std::to_string(totalBatchComputeOps) }, + {"Number of instructions", std::to_string(totalInstructionCount)}, + {"Number of used crossbars", std::to_string(totalWeightCount) } + }; printReportTotalsBlock(os, totalFields); if (!collectedData.empty()) os << "\n"; @@ -876,13 +877,15 @@ void generateReport(func::FuncOp funcOp, const std::string& name, size_t usedCpu llvm::SmallVector perCoreFields = { {"Number of logical computes", std::to_string(perCoreLogicalComputeCount)}, - {"Number of instructions", std::to_string(perCoreInstructionCount)}, - {"Number of used crossbars", std::to_string(perCoreWeightCount)}}; + {"Number of instructions", std::to_string(perCoreInstructionCount) }, + {"Number of used crossbars", std::to_string(perCoreWeightCount) } + }; if (current.isRebatched) { llvm::SmallVector totalEntryFields = { {"Number of logical computes", std::to_string(current.logicalComputeCount)}, - {"Number of instructions", std::to_string(totalEntryInstructionCount)}, - {"Number of used crossbars", std::to_string(current.weightCount)}}; + {"Number of instructions", std::to_string(totalEntryInstructionCount) }, + {"Number of used crossbars", std::to_string(current.weightCount) } + }; printReportPerCoreAndTotalFields(os, perCoreFields, totalEntryFields); } else { diff --git a/src/PIM/Pass/PimCodegen/HostConstantFolding/Patterns/Subview.cpp b/src/PIM/Pass/PimCodegen/HostConstantFolding/Patterns/Subview.cpp index ac8c5da..0e7e89e 100644 --- a/src/PIM/Pass/PimCodegen/HostConstantFolding/Patterns/Subview.cpp +++ b/src/PIM/Pass/PimCodegen/HostConstantFolding/Patterns/Subview.cpp @@ -66,8 +66,10 @@ static Value buildSubviewChunk(const StaticSubviewInfo& info, return memref::SubViewOp::create(rewriter, loc, info.source, chunkOffsets, chunkSizes, chunkStrides); } -static SmallVector -delinearizeIndexValue(Value linearIndex, ArrayRef shape, ArrayRef strides, PatternRewriter& rewriter) { +static SmallVector delinearizeIndexValue(Value linearIndex, + ArrayRef shape, + ArrayRef strides, + PatternRewriter& rewriter) { SmallVector indices; indices.reserve(shape.size()); @@ -112,7 +114,8 @@ static Value buildDynamicSubviewChunk(const StaticSubviewInfo& info, assert(info.strides[dim] == 1 && "loop-based subview rewrite requires unit strides"); chunkOffsets.push_back(addDynamicOffset(info.offsets[dim], outerIndices[dim], rewriter)); chunkSizes.push_back(rewriter.getIndexAttr(1)); - } else { + } + else { chunkOffsets.push_back(info.offsets[dim]); chunkSizes.push_back(rewriter.getIndexAttr(info.sizes.back())); } @@ -122,11 +125,8 @@ static Value buildDynamicSubviewChunk(const StaticSubviewInfo& info, return memref::SubViewOp::create(rewriter, loc, info.source, chunkOffsets, chunkSizes, chunkStrides); } -static Value buildContiguousChunk(Value source, - ArrayRef copyShape, - ArrayRef outerIndices, - Location loc, - PatternRewriter& rewriter) { +static Value buildContiguousChunk( + Value source, ArrayRef copyShape, ArrayRef outerIndices, Location loc, PatternRewriter& rewriter) { SmallVector chunkOffsets; SmallVector chunkSizes; SmallVector chunkStrides; @@ -203,7 +203,8 @@ static LogicalResult rewriteSubviewCopyLikeOp(CopyOp copyOp, rewriter.setInsertionPointToStart(loop.getBody()); SmallVector outerIndices = - outerShape.empty() ? SmallVector {} : delinearizeIndexValue(loop.getInductionVar(), outerShape, outerStrides, rewriter); + outerShape.empty() ? SmallVector {} + : delinearizeIndexValue(loop.getInductionVar(), outerShape, outerStrides, rewriter); Value chunkDst = splitDst ? buildDynamicSubviewChunk(*dstSubview, outerIndices, copyOp.getLoc(), rewriter) : buildContiguousChunk(dst, copyShape, outerIndices, copyOp.getLoc(), rewriter); Value chunkSrc = splitSrc ? buildDynamicSubviewChunk(*srcSubview, outerIndices, copyOp.getLoc(), rewriter) diff --git a/src/PIM/Pass/PimCodegen/VerificationPass.cpp b/src/PIM/Pass/PimCodegen/VerificationPass.cpp index fd2a09f..7a84202 100644 --- a/src/PIM/Pass/PimCodegen/VerificationPass.cpp +++ b/src/PIM/Pass/PimCodegen/VerificationPass.cpp @@ -6,10 +6,10 @@ #include "llvm/ADT/STLExtras.h" +#include "src/Accelerators/PIM/Common/IR/SubviewUtils.hpp" #include "src/Accelerators/PIM/Common/PimCommon.hpp" #include "src/Accelerators/PIM/Dialect/Pim/PimOps.hpp" #include "src/Accelerators/PIM/Dialect/Spatial/SpatialOps.hpp" -#include "src/Accelerators/PIM/Common/IR/SubviewUtils.hpp" using namespace mlir;