| 25 | using namespace ppl::common; |
| 26 | |
| 27 | static bool SetRandomInputs(Runtime* runtime) { |
| 28 | for (uint32_t c = 0; c < runtime->GetInputCount(); ++c) { |
| 29 | auto t = runtime->GetInputTensor(c); |
| 30 | auto& shape = *t->GetShape(); |
| 31 | |
| 32 | auto nr_element = shape.CalcBytesIncludingPadding() / sizeof(float); |
| 33 | vector<float> buffer(nr_element); |
| 34 | |
| 35 | // fill random input data |
| 36 | std::default_random_engine eng; |
| 37 | std::uniform_real_distribution<float> dis(-1.0f, 1.0f); |
| 38 | for (uint32_t i = 0; i < nr_element; ++i) { |
| 39 | buffer[i] = dis(eng); |
| 40 | } |
| 41 | |
| 42 | // our random data is treated as NDARRAY |
| 43 | ppl::nn::TensorShape src_desc = *t->GetShape(); |
| 44 | src_desc.SetDataFormat(DATAFORMAT_NDARRAY); |
| 45 | |
| 46 | // input tensors may require different data format |
| 47 | auto status = t->ConvertFromHost(buffer.data(), src_desc); |
| 48 | if (status != RC_SUCCESS) { |
| 49 | cerr << "set tensor[" << t->GetName() << "] content failed: " << GetRetCodeStr(status) << endl; |
| 50 | return false; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | return true; |
| 55 | } |
| 56 | |
| 57 | static void PrintInputOutputInfo(const Runtime* runtime) { |
| 58 | cout << "----- input info -----" << endl; |
no test coverage detected