trevor-m commented on a change in pull request #6395: URL: https://github.com/apache/incubator-tvm/pull/6395#discussion_r492835284
########## File path: src/runtime/contrib/tensorrt/tensorrt_ops.h ########## @@ -0,0 +1,208 @@ +/* * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * \file runtime/contrib/tensorrt/tensorrt_ops.h + * \brief Converters from Relay ops into TensorRT layers. Converters should + * inherit from TrtOpConverter and implement the Convert() method. + */ + +#ifndef TVM_RUNTIME_CONTRIB_TENSORRT_TENSORRT_OPS_H_ +#define TVM_RUNTIME_CONTRIB_TENSORRT_TENSORRT_OPS_H_ + +#include <algorithm> +#include <cmath> +#include <memory> +#include <string> +#include <unordered_map> +#include <vector> + +#include "../json/json_node.h" +#include "NvInfer.h" +#include "tensorrt_utils.h" + +#if TRT_VERSION_GE(6, 0, 1) +#define TRT_HAS_IMPLICIT_BATCH(params) (params->network->hasImplicitBatchDimension()) +#else +#define TRT_HAS_IMPLICIT_BATCH(params) (true) +#endif + +namespace tvm { +namespace runtime { +namespace contrib { + +using JSONGraphNode = tvm::runtime::json::JSONGraphNode; + +/*! + * \brief An input to a op may be either kTensor in the case of nvinfer::ITensor* + * or kWeight for nvinfer1::Weights. + */ +enum TrtInputType { + kTensor, + kWeight, +}; + +/*! + * \brief An input to a TrtOpConverter. The type of the input is either kTensor + * or kWeight. For kTensor, "tensor" contains the input tensor. For kWeight, + * "weight" contains the input weight and "weight_shape" contains the shape. + */ +struct TrtOpInput { + /*! \brief If type is kTensor, will store input tensor. */ + nvinfer1::ITensor* tensor; + + /*! \brief If type is kWeight, will store input weight. */ + nvinfer1::Weights weight; + + /*! \brief Whether the input is in tensor or weight. */ + TrtInputType type; + + /*! \brief If type is kWeight, will store weight shape. */ + std::vector<int> weight_shape; + + explicit TrtOpInput(nvinfer1::ITensor* tensor) + : tensor(tensor), weight({nvinfer1::DataType::kFLOAT, nullptr, 0}), type(kTensor) {} + TrtOpInput(nvinfer1::Weights weight, const std::vector<int>& shape) + : tensor(nullptr), weight(weight), type(kWeight), weight_shape(shape) {} +}; + +/*! \brief Parameters to convert an Op from relay to TensorRT. */ +struct AddTrtLayerParams { Review comment: Renamed to `TensorRTOpConverterParams` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
