@@ -17,10 +17,12 @@ limitations under the License. */
1717#include  < sys/stat.h> 
1818#include  < cstdio> 
1919#include  < fstream> 
20+ #include  < memory> 
2021#include  < set> 
2122#include  < string> 
2223#include  < typeindex> 
2324#include  < unordered_map> 
25+ #include  < utility> 
2426#include  < vector> 
2527
2628#include  " paddle/fluid/framework/framework.pb.h" 
@@ -217,6 +219,35 @@ static std::string GetTrtCalibTableData(const std::string &model_opt_cache_dir,
217219  return  " " 
218220}
219221
222+ static  std::string GetTrtEngineSerializedPath (const  std::string &model_root,
223+                                               const  std::string &engine_key) {
224+   return  model_root + " /trt_serialized_" 
225+ }
226+ 
227+ static  std::string GetTrtEngineSerializedData (
228+     const  std::string &model_opt_cache_dir, const  std::string &engine_key) {
229+   std::string trt_serialized_path =
230+       GetTrtEngineSerializedPath (model_opt_cache_dir, engine_key);
231+   if  (FileExists (trt_serialized_path)) {
232+     VLOG (3 ) << " Trt serialized file: " 
233+             << " is found here" 
234+     std::ifstream infile (trt_serialized_path, std::ios::in);
235+     std::stringstream buffer;
236+     buffer << infile.rdbuf ();
237+     std::string trt_engine_serialized_data (buffer.str ());
238+     return  trt_engine_serialized_data;
239+   }
240+   return  " " 
241+ }
242+ 
243+ static  void  SaveTrtEngineSerializedDataToFile (
244+     const  std::string &trt_serialized_path,
245+     const  std::string &engine_serialized_data) {
246+   std::ofstream outfile (trt_serialized_path);
247+   outfile << engine_serialized_data;
248+   outfile.close ();
249+ }
250+ 
220251}  //  namespace analysis
221252}  //  namespace inference
222253}  //  namespace paddle
0 commit comments