MCPcopy Create free account
hub / github.com/OpenPPL/ppl.nn / SaveInputsAllInOne

Function SaveInputsAllInOne

tools/pplnn.cc:875–900  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

873}
874
875static bool SaveInputsAllInOne(const Runtime* runtime) {
876 const string in_file_name = g_flag_save_data_dir + "/pplnn_input.dat";
877 ofstream ofs(in_file_name, ios_base::out | ios_base::binary | ios_base::trunc);
878 if (!ofs.is_open()) {
879 LOG(ERROR) << "open file[" << in_file_name << "] failed.";
880 return false;
881 }
882
883 for (uint32_t c = 0; c < runtime->GetInputCount(); ++c) {
884 auto t = runtime->GetInputTensor(c);
885 auto bytes = t->GetShape()->CalcBytesIncludingPadding();
886 vector<char> buffer(bytes);
887
888 ppl::nn::TensorShape src_desc = *t->GetShape();
889 src_desc.SetDataFormat(DATAFORMAT_NDARRAY);
890 auto status = t->ConvertToHost((void*)buffer.data(), src_desc);
891 if (status != RC_SUCCESS) {
892 LOG(ERROR) << "convert data failed: " << GetRetCodeStr(status);
893 return false;
894 }
895
896 ofs.write(buffer.data(), bytes);
897 }
898
899 return true;
900}
901
902static bool SaveOutputsOneByOne(const Runtime* runtime) {
903 for (uint32_t c = 0; c < runtime->GetOutputCount(); ++c) {

Callers 1

mainFunction · 0.70

Calls 4

GetInputTensorMethod · 0.80
GetInputCountMethod · 0.45
GetShapeMethod · 0.45
ConvertToHostMethod · 0.45

Tested by

no test coverage detected