| 93 | } |
| 94 | |
| 95 | int main(void) { |
| 96 | const char* model_file = "tests/testdata/conv.onnx"; |
| 97 | |
| 98 | auto x86_engine = x86::EngineFactory::Create(x86::EngineOptions()); |
| 99 | vector<unique_ptr<Engine>> engines; |
| 100 | engines.emplace_back(unique_ptr<Engine>(x86_engine)); |
| 101 | |
| 102 | auto builder = unique_ptr<onnx::RuntimeBuilder>(onnx::RuntimeBuilderFactory::Create()); |
| 103 | if (!builder) { |
| 104 | cerr << "create RuntimeBuilder failed." << endl; |
| 105 | return -1; |
| 106 | } |
| 107 | |
| 108 | auto status = builder->LoadModel(model_file); |
| 109 | if (status != RC_SUCCESS) { |
| 110 | cerr << "init OnnxRuntimeBuilder failed: " << GetRetCodeStr(status) << endl; |
| 111 | return -1; |
| 112 | } |
| 113 | |
| 114 | vector<Engine*> engine_ptrs(engines.size()); |
| 115 | for (uint32_t i = 0; i < engines.size(); ++i) { |
| 116 | engine_ptrs[i] = engines[i].get(); |
| 117 | } |
| 118 | onnx::RuntimeBuilder::Resources resources; |
| 119 | resources.engines = engine_ptrs.data(); |
| 120 | resources.engine_num = engine_ptrs.size(); |
| 121 | |
| 122 | status = builder->SetResources(resources); |
| 123 | if (status != RC_SUCCESS) { |
| 124 | cerr << "onnx RuntimeBuilder SetResources failed: " << GetRetCodeStr(status) << endl; |
| 125 | return -1; |
| 126 | } |
| 127 | |
| 128 | status = builder->Preprocess(); |
| 129 | if (status != RC_SUCCESS) { |
| 130 | cerr << "builder preprocess failed: " << GetRetCodeStr(status) << endl; |
| 131 | return -1; |
| 132 | } |
| 133 | |
| 134 | auto runtime = unique_ptr<Runtime>(builder->CreateRuntime()); |
| 135 | if (!runtime) { |
| 136 | cerr << "CreateRuntime failed." << endl; |
| 137 | return -1; |
| 138 | } |
| 139 | |
| 140 | if (!SetRandomInputs(runtime.get())) { |
| 141 | cerr << "SetRandomInputs failed." << endl; |
| 142 | return -1; |
| 143 | } |
| 144 | |
| 145 | status = runtime->Run(); |
| 146 | if (status != RC_SUCCESS) { |
| 147 | cerr << "Run() failed: " << GetRetCodeStr(status) << endl; |
| 148 | return -1; |
| 149 | } |
| 150 | |
| 151 | PrintInputOutputInfo(runtime.get()); |
| 152 |
nothing calls this directly
no test coverage detected