31 auto typeInfo =
session->GetInputTypeInfo(inputIdx);
32 auto tensorInfo = typeInfo.GetTensorTypeAndShapeInfo();
33 auto inputDims = tensorInfo.GetShape();
35 inputDims.begin(), inputDims.end(), [](int64_t &i) { return i < 0; }, 1);
37 size_t inputTensorSize = std::accumulate(inputDims.begin(), inputDims.end(),
38 1, std::multiplies<int>());
39 assert(inputTensorSize == input.size());
42 Ort::MemoryInfo::CreateCpu(OrtArenaAllocator, OrtMemTypeDefault);
43 auto inputTmp = Ort::Value::CreateTensor<float>(
44 memory_info, input.data(), inputTensorSize, inputDims.data(),
46 auto inputTensor = &inputTmp;
47 assert(inputTensor->IsTensor());
52 llvm::SmallVector<float, 100> &output) {
53 Ort::AllocatorWithDefaultOptions allocator;
55 int input_count =
session->GetInputCount();
56 llvm::SmallVector<llvm::SmallVector<float, 100>, 10> inputList;
57 inputList.push_back(input);
58 llvm::SmallVector<float, 100> dummy_input;
59 dummy_input.insert(dummy_input.end(), 1);
60 for (
int i = 1; i < input_count; i++) {
61 inputList.push_back(dummy_input);
64 llvm::SmallVector<std::string, 10> inputNameList;
65 for (
int i = 0; i < input_count; i++) {
66 auto inputName =
session->GetInputNameAllocated(i, allocator);
67 auto inputNameStr = inputName.get();
68 inputNameList.push_back(inputNameStr);
71 std::vector<Ort::Value> input_final;
72 llvm::SmallVector<const char *, 10> inputNameStr_final;
74 for (
int i = 0; i < input_count; i++) {
75 input_final.insert(input_final.end(),
getInputValue(inputList[i], i));
76 inputNameStr_final.insert(inputNameStr_final.end(),
77 inputNameList[i].c_str());
80 auto outputName =
session->GetOutputNameAllocated(0, allocator);
81 auto outputNameStr = outputName.get();
84 session->Run(Ort::RunOptions{
nullptr}, inputNameStr_final.data(),
85 input_final.data(), input_count, &outputNameStr, 1);
87 assert(outputTensors.size() == 1 && outputTensors.front().IsTensor());
90 outputTensors.front().GetTensorTypeAndShapeInfo().GetShape()[1];
92 auto outVal = outputTensors.front().GetTensorMutableData<
float>();
94 output = llvm::SmallVector<float, 100>(outVal, outVal + outputDims);
96 output.begin(), output.end(), [](
double x) { return std::isnan(x); },
void run(llvm::SmallVector< float, 100 > &input, llvm::SmallVector< float, 100 > &output)
Runs the ONNX model on the input and returns the output.