94 lines
3.6 KiB
C++
94 lines
3.6 KiB
C++
#pragma once
|
|
|
|
#include <memory>
|
|
#include <unordered_map>
|
|
#include <map>
|
|
#include <vector>
|
|
#include <filesystem>
|
|
#include <optional>
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
#include "calrt_utils.h"
|
|
#include "elf_parser.hpp"
|
|
|
|
namespace calrt
|
|
{
|
|
class CALRT_API Calbin final
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Create a Parser object
|
|
*
|
|
* @param path
|
|
* @return std::unique_ptr<Calbin>
|
|
*/
|
|
static std::unique_ptr<Calbin> CreateCalbin(const std::string &path);
|
|
Calbin(const Calbin&) = delete;
|
|
Calbin& operator=(const Calbin&) = delete;
|
|
Calbin(Calbin &&) = default;
|
|
Calbin &operator=(Calbin &&other) = default;
|
|
~Calbin() = default;
|
|
|
|
CalrtCalbin& GetCalbinBrief();
|
|
|
|
CalbinModel* GetModelByName(std::string_view modelName);
|
|
std::vector<CalbinModel> *GetAllModels();
|
|
|
|
/**
|
|
* @brief Get the Model By Type object
|
|
* @note type: prefill, decode, kv_update
|
|
*
|
|
* @param type
|
|
* @return std::vector<CalbinModel*>
|
|
*/
|
|
std::vector<CalbinModel*> GetModelByType(std::string_view type);
|
|
|
|
std::vector<calc_efl::Parsed_Elf_s> &GetPairedElf(const std::string &model, const std::vector<uint32_t> &chipMask);
|
|
|
|
CalbinModel& GetGlobalMemInfo();
|
|
const CalbinLLM_s& GetLLMInfo() const;
|
|
|
|
/**
|
|
* @brief print out calbin essential info, llm info and kv-cache info.
|
|
*
|
|
*/
|
|
void Report();
|
|
|
|
CalbinSectionPlace_e GetStackLoc(const std::string &modelName);
|
|
|
|
const std::string &Version() const { return mVersion; }
|
|
|
|
uint64_t GetModelWorloadByName(const std::string &modelName);
|
|
|
|
std::vector<uint8_t> GetGoldenInputByModelName(const std::string &modelName);
|
|
std::vector<uint8_t> GetGoldenOutputByModelName(const std::string &modelName);
|
|
std::string GetRootPath() {return mRootPath;}
|
|
// std::pair<uint64_t, std::vector<uint8_t>> GetGoldenInputWithAddr(const char* modelName);
|
|
// std::pair<uint64_t, std::vector<uint8_t>> GetGoldenOutputWithAddr(const char* modelName);
|
|
|
|
private:
|
|
Calbin(std::string &&rootPath);
|
|
CalrtError_e GenCalrtCalbin(const std::unordered_map<std::string, std::vector<std::filesystem::path>> &modelMap);
|
|
void SetMaxElfSize(const std::string &modelName);
|
|
CalrtError_e InitSection(const std::vector<std::string> &vals, CalbinModel &mod, const std::string &fullTag, const std::string &filePath);
|
|
CalrtError_e RecordGlobalMem(const std::string &path);
|
|
|
|
CalrtError_e ParseMemFile(CalbinModel &tempModel, CalbinLLM_s &LLMInfo_, const std::filesystem::path &filePath);
|
|
CalrtError_e Validation();
|
|
|
|
std::unordered_map<std::string, CalbinSectionPlace_e> mStackLoc;
|
|
std::unordered_map<std::string, std::unordered_map<uint64_t, std::vector<calc_efl::Parsed_Elf_s> >> mModelPairedElf;
|
|
std::unordered_map<std::string, uint64_t> mModelWorkLoads; // modelName , workload
|
|
|
|
std::string mRootPath;
|
|
CalrtCalbin mCalbin;
|
|
CalbinModel mGlobalModel;
|
|
CalbinLLM_s mLLMInfo;
|
|
int32_t mCompatibility; // indicate compitable device model type: ks01 = 0, ks02 = 1.
|
|
std::string mVersion;
|
|
uint64_t mCalbinSize; // require for device memory size
|
|
};
|
|
} // namespace calrt
|