#pragma once #include #include #include #include #include namespace torch::jit { /* * MobileDebugTable: * Deserializes debug_pkl and callstack_map records from PT model's zip archive * and stores them in a map of debug handles to DebugInfoPair. Debug handles are * unique per model and runtime, be in lite interpreter or delegate, an * exception of BackendRuntimeException should raised using debug handles. * getSourceDebugString method is responsible for translating debug * handles to correspond debug information. * This debug informatin includes stack trace of model level source code and * module hierarchy where the exception occurred. */ class MobileDebugTable { public: MobileDebugTable() = default; MobileDebugTable( std::unique_ptr& reader, const std::shared_ptr& cu); template MobileDebugTable(It begin, It end) : callstack_ptr_map_(begin, end) {} std::string getSourceDebugString( const int64_t debug_handle, const std::string& top_module_type_name = "ModuleTypeUnknown") const; std::string getSourceDebugString( const std::vector& debug_handles, const std::string& top_module_type_name = "ModuleTypeUnknown") const; std::string getModuleHierarchyInfo( const int64_t debug_handle, const std::string& top_module_type_name = "ModuleTypeUnknown") const; std::string getModuleHierarchyInfo( const std::vector& debug_handles, const std::string& top_module_type_name = "ModuleTypeUnknown") const; const ska::flat_hash_map& getCallStackPtrMap() const { return callstack_ptr_map_; } private: std::pair getSourceDebugModuleHierarchyInfo( const std::vector& debug_handles, const std::string& top_module_type_name = "ModuleTypeUnknown") const; ska::flat_hash_map callstack_ptr_map_; }; } // namespace torch::jit