63 lines
1.9 KiB
C++
63 lines
1.9 KiB
C++
#include "llvm/Support/Format.h"
|
|
|
|
#include "src/Accelerators/PIM/Common/Support/FileSystemUtils.hpp"
|
|
#include "src/Accelerators/PIM/Common/Support/ReportUtils.hpp"
|
|
|
|
namespace onnx_mlir {
|
|
|
|
std::fstream openReportFile(const std::string& name) {
|
|
std::string outputDir = getOutputDir();
|
|
if (outputDir.empty())
|
|
return {};
|
|
|
|
std::string reportsDir = outputDir + "/reports";
|
|
createDirectory(reportsDir);
|
|
return std::fstream(reportsDir + "/" + name + ".txt", std::ios::out);
|
|
}
|
|
|
|
std::string formatReportMemory(uint64_t bytes) {
|
|
const char* units[] = {"B", "KB", "MB", "GB", "TB", "PB", "EB"};
|
|
int i = 0;
|
|
double size = static_cast<double>(bytes);
|
|
while (size >= 1024 && i < 6) {
|
|
size /= 1024;
|
|
i++;
|
|
}
|
|
|
|
std::string out;
|
|
llvm::raw_string_ostream rss(out);
|
|
rss << llvm::format("%.2f ", size) << units[i];
|
|
return rss.str();
|
|
}
|
|
|
|
void printReportFlatFields(llvm::raw_ostream& os, llvm::ArrayRef<ReportField> fields) {
|
|
for (const ReportField& field : fields)
|
|
os << "\t" << field.label << ": " << field.value << "\n";
|
|
}
|
|
|
|
void printReportFieldBlock(llvm::raw_ostream& os, llvm::StringRef title, llvm::ArrayRef<ReportField> fields) {
|
|
os << "\t" << title << ":\n";
|
|
for (const ReportField& field : fields)
|
|
os << "\t " << field.label << ": " << field.value << "\n";
|
|
}
|
|
|
|
void printReportTotalsBlock(llvm::raw_ostream& os, llvm::ArrayRef<ReportField> fields) {
|
|
os << "Totals:\n";
|
|
for (const ReportField& field : fields)
|
|
os << "\t" << field.label << ": " << field.value << "\n";
|
|
}
|
|
|
|
void printReportPerCoreAndTotalFields(llvm::raw_ostream& os,
|
|
llvm::ArrayRef<ReportField> perCoreFields,
|
|
llvm::ArrayRef<ReportField> totalFields) {
|
|
printReportFieldBlock(os, "Per core", perCoreFields);
|
|
printReportFieldBlock(os, "Total", totalFields);
|
|
}
|
|
|
|
void printReportEntrySeparator(llvm::raw_ostream& os, bool hasNextEntry) {
|
|
if (hasNextEntry)
|
|
os << "\n";
|
|
}
|
|
|
|
} // namespace onnx_mlir
|