| 873 | } |
| 874 | |
| 875 | static 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 | |
| 902 | static bool SaveOutputsOneByOne(const Runtime* runtime) { |
| 903 | for (uint32_t c = 0; c < runtime->GetOutputCount(); ++c) { |
no test coverage detected