48 lines
1.5 KiB
C++
48 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
#include "llvm/ADT/STLExtras.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include <fstream>
|
|
#include <limits>
|
|
#include <string>
|
|
|
|
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<ReportField> fields);
|
|
void printReportFieldBlock(llvm::raw_ostream& os, llvm::StringRef title, llvm::ArrayRef<ReportField> fields);
|
|
void printReportTotalsBlock(llvm::raw_ostream& os, llvm::ArrayRef<ReportField> fields);
|
|
void printReportPerCoreAndTotalFields(llvm::raw_ostream& os,
|
|
llvm::ArrayRef<ReportField> perCoreFields,
|
|
llvm::ArrayRef<ReportField> totalFields);
|
|
void printReportEntrySeparator(llvm::raw_ostream& os, bool hasNextEntry);
|
|
|
|
template <typename EntryTy>
|
|
int32_t getFirstReportCoreId(const EntryTy& entry) {
|
|
if (entry.coreIds.empty())
|
|
return std::numeric_limits<int32_t>::max();
|
|
return entry.coreIds.front();
|
|
}
|
|
|
|
template <typename EntryRange>
|
|
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
|