forked from onnx/onnx-tensorrt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConditionalHelpers.hpp
45 lines (36 loc) · 1.84 KB
/
ConditionalHelpers.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
* SPDX-License-Identifier: Apache-2.0
*
* Helper functions used for importing the ONNX If-operator follow below.
*
*/
#pragma once
#include "ImporterContext.hpp"
#include "Status.hpp"
#include <NvInfer.h>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
namespace onnx2trt
{
// Given a subgraph, find all of its external inputs (tensors entering the subgraph).
// The result is returned in `subgraphInputs`, which is a map indexed by ITensor (a tensor entering the subgraph) and
// with values indicating a set of external input indices.
Status getSubgraphInputs(std::vector<nvinfer1::ILayer*> const& newLayers,
std::unordered_map<nvinfer1::ITensor*, std::set<int32_t>>& subgraphInputs);
// Given a subgraph, find all of its external outputs (tensors exiting the subgraph).
// The result is returned in `subgraphInputs`, which is a map indexed by ITensor (a tensor exiting the subgraph) and
// with values indicating a set of external outputs indices.
Status getSubgraphOutputs(const std::vector<nvinfer1::ILayer*>& newLayers,
std::unordered_map<nvinfer1::ITensor*, std::set<int32_t>>& subgraphOutputs,
const std::vector<std::string>& reportedOutputs);
// Take a snapshot of the network before and after parsing the subgraph and return a list
// of newly added network layers.
Status importSubgraph(ImporterContext* ctx, ::ONNX_NAMESPACE::GraphProto const& subgraph,
std::vector<nvinfer1::ILayer*>& newLayers, std::vector<TensorOrWeights>& subgraphTensors);
using InputsMap = std::unordered_map<std::string, nvinfer1::IIfConditionalInputLayer*>;
// Add IIfConditionalInputLayers to the inputs of the subgraph indicated by `subgraph`.
onnx2trt::Status addIfInputLayers(ImporterContext* ctx, nvinfer1::IIfConditional* conditional, InputsMap& inputsMap,
const std::vector<nvinfer1::ILayer*>& newLayers);
} // namespace onnx2trt