#pragma once #include #include #include #include #include #include #include #include #include #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 */ static std::unique_ptr 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 *GetAllModels(); /** * @brief Get the Model By Type object * @note type: prefill, decode, kv_update * * @param type * @return std::vector */ std::vector GetModelByType(std::string_view type); std::vector &GetPairedElf(const std::string &model, const std::vector &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 GetGoldenInputByModelName(const std::string &modelName); std::vector GetGoldenOutputByModelName(const std::string &modelName); std::string GetRootPath() {return mRootPath;} // std::pair> GetGoldenInputWithAddr(const char* modelName); // std::pair> GetGoldenOutputWithAddr(const char* modelName); private: Calbin(std::string &&rootPath); CalrtError_e GenCalrtCalbin(const std::unordered_map> &modelMap); void SetMaxElfSize(const std::string &modelName); CalrtError_e InitSection(const std::vector &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 mStackLoc; std::unordered_map >> mModelPairedElf; std::unordered_map 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