-
Notifications
You must be signed in to change notification settings - Fork 544
/
RNNHelpers.hpp
41 lines (31 loc) · 1.85 KB
/
RNNHelpers.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
/*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <NvInfer.h>
#include <string>
#include <vector>
#include "TensorOrWeights.hpp"
#include "ImporterContext.hpp"
namespace onnx2trt
{
nvinfer1::ITensor* addRNNInput(ImporterContext* ctx, const ::ONNX_NAMESPACE::NodeProto& node, nvinfer1::ILoop* loop,
std::vector<TensorOrWeights>& inputs, const std::string& direction);
// Zeros out invalid timesteps in toMask. maxLen must be provided if reverse is true
nvinfer1::ITensor* clearMissingSequenceElements(ImporterContext* ctx, const ::ONNX_NAMESPACE::NodeProto& node,
nvinfer1::ILoop* loop, nvinfer1::ITensor* seqLens, nvinfer1::ITensor* toMask, nvinfer1::ITensor* maxLen,
bool reverse = false, nvinfer1::ITensor* counter = nullptr);
// Returns a bool tensor which is true during valid timesteps
nvinfer1::ITensor* getRaggedMask(ImporterContext* ctx, const ::ONNX_NAMESPACE::NodeProto& node, nvinfer1::ILoop* loop,
nvinfer1::ITensor* seqLens, nvinfer1::ITensor* maxLen = nullptr, bool reverse = false,
nvinfer1::ITensor* counter = nullptr);
// Selects between prevH and Ht to forward previous hidden state through invalid timesteps
nvinfer1::ITensor* maskRNNHidden(ImporterContext* ctx, const ::ONNX_NAMESPACE::NodeProto& node, nvinfer1::ILoop* loop,
nvinfer1::ITensor* seqLens, nvinfer1::ITensor* prevH, nvinfer1::ITensor* Ht, nvinfer1::ITensor* maxLen = nullptr,
bool reverse = false, nvinfer1::ITensor* counter = nullptr);
// Splits a bidirectional hidden state into forward and reverse passes, masks each using maskRNNHidden, then
// concatenates
nvinfer1::ITensor* maskBidirRNNHidden(ImporterContext* ctx, const ::ONNX_NAMESPACE::NodeProto& node,
nvinfer1::ILoop* loop, nvinfer1::ITensor* seqLens, nvinfer1::ITensor* maxLen, nvinfer1::ITensor* Ht1,
nvinfer1::ITensor* Ht, nvinfer1::ITensor* singlePassShape);
} // namespace onnx2trt