#pragma once #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/raw_ostream.h" #include #include #include namespace onnx_mlir { std::fstream openReportFile(const std::string& name); std::string formatReportMemory(uint64_t bytes); struct ReportField { std::string label; std::string value; }; void printReportFlatFields(llvm::raw_ostream& os, llvm::ArrayRef fields); void printReportFieldBlock(llvm::raw_ostream& os, llvm::StringRef title, llvm::ArrayRef fields); void printReportTotalsBlock(llvm::raw_ostream& os, llvm::ArrayRef fields); void printReportPerCoreAndTotalFields(llvm::raw_ostream& os, llvm::ArrayRef perCoreFields, llvm::ArrayRef totalFields); void printReportEntrySeparator(llvm::raw_ostream& os, bool hasNextEntry); template int32_t getFirstReportCoreId(const EntryTy& entry) { if (entry.coreIds.empty()) return std::numeric_limits::max(); return entry.coreIds.front(); } template void sortReportEntriesByFirstCore(EntryRange& entries) { llvm::stable_sort(entries, [](const auto& lhs, const auto& rhs) { int32_t lhsFirstCore = getFirstReportCoreId(lhs); int32_t rhsFirstCore = getFirstReportCoreId(rhs); if (lhsFirstCore != rhsFirstCore) return lhsFirstCore < rhsFirstCore; return lhs.id < rhs.id; }); } } // namespace onnx_mlir