tensorRT插件

tensorRT自定义算子插件

enqueue
实际插件op的执行函数,我们自己实现的cuda操作就放到这里
https://oldpan.me/archives/tensorrt-plugin-one-post-get-it

TensorRT插件的存在目的,主要是为了让我们实现TensorRT目前还不支持的算子
https://zhuanlan.zhihu.com/p/297002406

 
https://github.com/zerollzeng/tiny-tensorrt/blob/master/docs/CustomPlugin-CN.md
例子 
https://github.com/zerollzeng/tiny-tensorrt/blob/master/plugin/PReLUPlugin/PReLUPlugin.cu


 
https://docs.nvidia.com/deeplearning/tensorrt/api/c_api/classnvinfer1_1_1_dims.html

c++的torch::Tensor操作

c++ 部署libtorch 时对Tensor块的常用操作API (例如vector转换为torch、squeeze、select、select_indxe、max等)
https://www.codenong.com/cs105839096/

at::Tensor pcl_losses_forward_cuda(const at::Tensor& pcl_probs,
    const at::Tensor& labels,
    const at::Tensor& cls_loss_weights,
    const at::Tensor& pc_labels,
    const at::Tensor& pc_probs,
    const at::Tensor& img_cls_loss_weights,
    const at::Tensor& im_labels) {
    int batch_size = pcl_probs.size(0);
    int channels = pcl_probs.size(1);
    int num_positive = pc_labels.size(1);
    at::Tensor output = at::empty({1, channels}, pcl_probs.options());
    cudaStream_t stream = at::cuda::getCurrentCUDAStream();
    PCLLossesForwardLaucher(
        pcl_probs.data<float>(),
        labels.data<float>(),
        cls_loss_weights.data<float>(),
        pc_labels.data<float>(),
        pc_probs.data<float>(),
        img_cls_loss_weights.data<float>(),
        im_labels.data<float>(),
        batch_size, channels, num_positive,
        output.data<float>(),
        stream
    );
    return output;
}
https://dongsky.github.io/2020/04/04/pytorch1xcppext/
 

PluginV2Layer must be V2DynamicExt when there are runtime input dimensions  Assertion failed: axis >= 0 && axis < nbDims

I have solved this Issue by Inheriting IPluginv2DynamicExt Class instead of IPluginv2Ext Class.
https://forums.developer.nvidia.com/t/pluginv2layer-must-be-v2dynamicext-when-there-are-runtime-input-dimensions/168992/5

Yes I believe you'll have to tweak the existing implementation to implement the IPluginV2DynamicExt interface instead. Please try this, and feel free to submit a pull request if you get a working implementation.
https://github.com/NVIDIA/TensorRT/issues/544

The error indicates your model using a dynamic shape, but the plugin only supports the static version.
Please provide a batch size parameter when generating the onnx model to get a static version.
https://forums.developer.nvidia.com/t/yolov4-tensorrt-pluginv2layer-must-be-v2dynamicext-when-there-are-runtime/161123

You should use the BatchedNMSDynamic_TRT plugin if you have dynamic shapes. This plugin is supported in TensorRT version > 7.2.
https://github.com/NVIDIA/TensorRT/issues/795

DimsExprs getOutputDimensions
https://forums.developer.nvidia.com/t/getoutputdimensions-for-ipluginv2dynamicext/149429
https://docs.nvidia.com/deeplearning/tensorrt/api/c_api/classnvinfer1_1_1_i_plugin_v2_dynamic_ext.html#a3d19937b5f81272b29ee7c986ca297ed

// First dimension of output is sum of input 
        // first dimensions.
        DimsExprs output(inputs[0]);
        output.d[0] = 
            exprBuilder.operation(DimensionOperation::kSUM, 
                inputs[0].d[0], inputs[1].d[0]);
https://www.codetd.com/article/12453558
 

I think that you should read first sentences of this section: https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#ptx-compatibility . NVIDIA GPUs have a notion of compute compatibility and some functions are not enabled by compiler by default unless you specify that you compile on a device with certain compute compatibility. For example, on my server, Titan X Tesla has compute compatibility 6.1, so I compiled it with compute_61 arch.

I think you should also refer to this table. https://docs.nvidia.com/deeplearning/tensorrt/support-matrix/index.html#hardware-precision-matrix  . You can find out immediately if the GPU on your server supports Fast FP16. For example, as I mentioned that Titan X (pascal) has compute capability 6.1 and the table indicates that it doesn't support fast fp16.
 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

WX Chen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值