| 606 | } |
| 607 | |
| 608 | static bool SetInputsAllInOne(const string& input_file, const vector<vector<int64_t>>& input_shapes, Runtime* runtime, |
| 609 | vector<string>* input_data) { |
| 610 | Mmap fm; |
| 611 | auto status = fm.Init(input_file.c_str(), Mmap::READ); |
| 612 | if (status != RC_SUCCESS) { |
| 613 | LOG(ERROR) << "mapping file[" << input_file << "] failed."; |
| 614 | return false; |
| 615 | } |
| 616 | |
| 617 | auto data = fm.GetData(); |
| 618 | const string file_name = GetBasename(input_file); |
| 619 | uint64_t expect_input_size = 0; |
| 620 | for (uint32_t c = 0; c < runtime->GetInputCount(); ++c) { |
| 621 | auto t = runtime->GetInputTensor(c); |
| 622 | |
| 623 | if (!input_shapes.empty()) { |
| 624 | t->GetShape()->Reshape(input_shapes[c]); |
| 625 | } |
| 626 | |
| 627 | expect_input_size += t->GetShape()->CalcBytesExcludingPadding(); |
| 628 | } |
| 629 | if (fm.GetSize() < expect_input_size) { |
| 630 | LOG(ERROR) << "input file[" << file_name << "] size(" << fm.GetSize() << ") is less than expected size(" |
| 631 | << expect_input_size << ")"; |
| 632 | return false; |
| 633 | } |
| 634 | if (fm.GetSize() > expect_input_size) { |
| 635 | LOG(WARNING) << "input file[" << file_name << "] size(" << fm.GetSize() << ") is bigger than expected size(" |
| 636 | << expect_input_size << ")"; |
| 637 | } |
| 638 | |
| 639 | for (uint32_t c = 0; c < runtime->GetInputCount(); ++c) { |
| 640 | auto t = runtime->GetInputTensor(c); |
| 641 | |
| 642 | ppl::nn::TensorShape src_desc = *t->GetShape(); |
| 643 | src_desc.SetDataFormat(DATAFORMAT_NDARRAY); |
| 644 | auto status = t->ConvertFromHost(data, src_desc); |
| 645 | if (status != RC_SUCCESS) { |
| 646 | LOG(ERROR) << "convert tensor[" << t->GetName() << "] content failed: " << GetRetCodeStr(status); |
| 647 | return false; |
| 648 | } |
| 649 | |
| 650 | const uint64_t content_size = src_desc.CalcBytesIncludingPadding(); |
| 651 | input_data->emplace_back(string(data, content_size)); |
| 652 | data += content_size; |
| 653 | } |
| 654 | |
| 655 | return true; |
| 656 | } |
| 657 | |
| 658 | static const pair<string, datatype_t> g_str2datatype[] = { |
| 659 | {"fp64", DATATYPE_FLOAT64}, {"fp32", DATATYPE_FLOAT32}, {"fp16", DATATYPE_FLOAT16}, {"int32", DATATYPE_INT32}, |
no test coverage detected