LITE_ON_TINY_PUBLISH
| 836 | } |
| 837 | #endif // LITE_ON_TINY_PUBLISH |
| 838 | void LoadModelFbsFromFile(model_parser::BinaryFileReader *reader, |
| 839 | Scope *scope, |
| 840 | cpp::ProgramDesc *cpp_prog, |
| 841 | uint16_t meta_version) { |
| 842 | CHECK(cpp_prog); |
| 843 | CHECK(scope); |
| 844 | CHECK_EQ(cpp_prog->BlocksSize(), 0); |
| 845 | |
| 846 | // get opt version |
| 847 | char opt_version[16]; |
| 848 | const uint64_t opt_version_length = 16 * sizeof(char); |
| 849 | reader->Read(opt_version, opt_version_length); |
| 850 | VLOG(4) << "Opt_version:" << static_cast<const char *>(opt_version); |
| 851 | // check version, opt's version should be consistent with current Paddle-Lite |
| 852 | // version. |
| 853 | const std::string paddle_version = version(); |
| 854 | const std::string opt_version_str = opt_version; |
| 855 | if (paddle_version != opt_version_str) { |
| 856 | LOG(WARNING) << "\nwarning: the version of opt that transformed this model " |
| 857 | "is not consistent with current Paddle-Lite version." |
| 858 | "\n version of opt:" |
| 859 | << static_cast<const char *>(opt_version) |
| 860 | << "\n version of current Paddle-Lite:" << paddle_version; |
| 861 | } |
| 862 | // (3)get topo_size |
| 863 | uint64_t topo_size; |
| 864 | reader->Read(&topo_size, sizeof(uint64_t)); |
| 865 | VLOG(4) << "topo_size: " << topo_size; |
| 866 | |
| 867 | #ifdef LITE_ON_FLATBUFFERS_DESC_VIEW |
| 868 | lite::model_parser::Buffer buf(topo_size); |
| 869 | reader->Read(buf.data(), topo_size); |
| 870 | cpp_prog->Init(std::move(buf)); |
| 871 | #elif LITE_ON_TINY_PUBLISH |
| 872 | LOG(FATAL) << "Since no data structure of Flatbuffers has been constructed, " |
| 873 | "the model cannot be loaded."; |
| 874 | #else |
| 875 | lite::model_parser::Buffer buf(topo_size); |
| 876 | reader->Read(buf.data(), topo_size); |
| 877 | fbs::ProgramDesc program(buf); |
| 878 | TransformProgramDescAnyToCpp(program, cpp_prog); |
| 879 | #endif |
| 880 | |
| 881 | /* 2. Load scope from params.fbs */ |
| 882 | switch (meta_version) { |
| 883 | case 1: { |
| 884 | /* load scope from param.fbs with meta_version=1 */ |
| 885 | lite::model_parser::Buffer buf(reader->length() - reader->current()); |
| 886 | reader->Read(buf.data(), reader->length() - reader->current()); |
| 887 | fbs::CombinedParamsDescView params(std::move(buf)); |
| 888 | fbs::deprecated::SetScopeWithCombinedParams(scope, params); |
| 889 | break; |
| 890 | } |
| 891 | case 2: { |
| 892 | /* load scope from param.fbs with meta_version=2 */ |
| 893 | fbs::ParamDeserializer deserializer(reader); |
| 894 | deserializer.ForwardRead(scope); |
| 895 | break; |
no test coverage detected