Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions core/conversion/conversionctx/ConversionCtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,17 @@ ConversionCtx::ConversionCtx(BuilderSettings build_settings)
cudaSetDevice(settings.device.gpu_id) == cudaSuccess, "Unable to set gpu id: " << settings.device.gpu_id);
}

builder = make_trt(nvinfer1::createInferBuilder(logger));
net = make_trt(
builder->createNetworkV2(1U << static_cast<uint32_t>(nvinfer1::NetworkDefinitionCreationFlag::kEXPLICIT_BATCH)));
builder = nvinfer1::make_trt(nvinfer1::createInferBuilder(logger));
net = nvinfer1::make_trt(builder->createNetworkV2(0U));

LOG_INFO(settings);
cfg = make_trt(builder->createBuilderConfig());
cfg = nvinfer1::make_trt(builder->createBuilderConfig());

for (auto p = settings.enabled_precisions.begin(); p != settings.enabled_precisions.end(); ++p) {
switch (*p) {
case nvinfer1::DataType::kHALF:
// tensorrt_rtx is strong typed, cannot set fp16 by builder config, only do this for tensorrt build
#ifndef TRT_MAJOR_RTX
TORCHTRT_CHECK(
builder->platformHasFastFp16(), "Requested inference in FP16 but platform does not support FP16");
cfg->setFlag(nvinfer1::BuilderFlag::kFP16);
break;
#endif
Expand Down Expand Up @@ -158,7 +155,7 @@ void ConversionCtx::RecordNewITensor(const torch::jit::Value* value, nvinfer1::I

std::string ConversionCtx::SerializeEngine() {
#if defined(TRT_MAJOR_RTX) || (NV_TENSORRT_MAJOR > 7)
auto serialized_network = make_trt(builder->buildSerializedNetwork(*net, *cfg));
auto serialized_network = nvinfer1::make_trt(builder->buildSerializedNetwork(*net, *cfg));
if (!serialized_network) {
TORCHTRT_THROW_ERROR("Building serialized network failed in TensorRT");
}
Expand Down
8 changes: 5 additions & 3 deletions core/conversion/converters/impl/batch_norm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,14 @@ bool InstanceNormConverter(ConversionCtx* ctx, const torch::jit::Node* n, args&
fc.nbFields = f.size();
fc.fields = f.data();

auto creator = getPluginRegistry()->getPluginCreator("InstanceNormalization_TRT", "1", "");
auto instance_norm_plugin = creator->createPlugin("instance_norm", &fc);
auto creator = static_cast<nvinfer1::IPluginCreatorV3One*>(
getPluginRegistry()->getCreator("InstanceNormalization_TRT", "1", ""));
auto instance_norm_plugin = creator->createPlugin("instance_norm", &fc, nvinfer1::TensorRTPhase::kBUILD);

TORCHTRT_CHECK(instance_norm_plugin, "Unable to create instance_norm plugin from TensorRT plugin registry" << *n);

auto new_layer = ctx->net->addPluginV2(reinterpret_cast<nvinfer1::ITensor* const*>(&input), 1, *instance_norm_plugin);
auto new_layer =
ctx->net->addPluginV3(reinterpret_cast<nvinfer1::ITensor* const*>(&input), 1, nullptr, 0, *instance_norm_plugin);

new_layer->setName(util::node_info(n).c_str());
auto out_tensor = ctx->AssociateValueAndTensor(n->outputs()[0], new_layer->getOutput(0));
Expand Down
8 changes: 5 additions & 3 deletions core/conversion/converters/impl/interpolate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ void create_plugin(

fc.nbFields = f.size();
fc.fields = f.data();
auto creator = getPluginRegistry()->getPluginCreator("Interpolate", "1", "torch_tensorrt");
auto interpolate_plugin = creator->createPlugin(name, &fc);
auto creator = static_cast<nvinfer1::IPluginCreatorV3One*>(
getPluginRegistry()->getCreator("Interpolate", "1", "torch_tensorrt"));
auto interpolate_plugin = creator->createPlugin(name, &fc, nvinfer1::TensorRTPhase::kBUILD);

auto resize_layer = ctx->net->addPluginV2(reinterpret_cast<nvinfer1::ITensor* const*>(&in), 1, *interpolate_plugin);
auto resize_layer =
ctx->net->addPluginV3(reinterpret_cast<nvinfer1::ITensor* const*>(&in), 1, nullptr, 0, *interpolate_plugin);
TORCHTRT_CHECK(resize_layer, "Unable to create interpolation plugin from node" << *n);

resize_layer->setName(util::node_info(n).c_str());
Expand Down
8 changes: 5 additions & 3 deletions core/conversion/converters/impl/normalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ void create_plugin(
}
}

auto creator = getPluginRegistry()->getPluginCreator("NormalizePlugin", "1", "torch_tensorrt");
auto plugin = creator->createPlugin(name, &fc);
auto normalize_layer = ctx->net->addPluginV2(reinterpret_cast<nvinfer1::ITensor* const*>(&in), 1, *plugin);
auto creator = static_cast<nvinfer1::IPluginCreatorV3One*>(
getPluginRegistry()->getCreator("NormalizePlugin", "1", "torch_tensorrt"));
auto plugin = creator->createPlugin(name, &fc, nvinfer1::TensorRTPhase::kBUILD);
auto normalize_layer =
ctx->net->addPluginV3(reinterpret_cast<nvinfer1::ITensor* const*>(&in), 1, nullptr, 0, *plugin);
TORCHTRT_CHECK(normalize_layer, "Unable to create normalization plugin from node" << *n);

normalize_layer->setName(util::node_info(n).c_str());
Expand Down
8 changes: 5 additions & 3 deletions core/conversion/converters/impl/pooling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ bool AdaptivePoolingConverter(
LOG_WARNING(
"Adaptive pooling layer will be using Aten library kernels in pytorch for execution. TensorRT does not support adaptive pooling natively. Consider switching to non-adaptive pooling if this is an issue");

auto creator = getPluginRegistry()->getPluginCreator("Interpolate", "1", "torch_tensorrt");
auto interpolate_plugin = creator->createPlugin(mode.c_str(), &fc);
auto creator = static_cast<nvinfer1::IPluginCreatorV3One*>(
getPluginRegistry()->getCreator("Interpolate", "1", "torch_tensorrt"));
auto interpolate_plugin = creator->createPlugin(mode.c_str(), &fc, nvinfer1::TensorRTPhase::kBUILD);

new_layer = ctx->net->addPluginV2(reinterpret_cast<nvinfer1::ITensor* const*>(&in), 1, *interpolate_plugin);
new_layer =
ctx->net->addPluginV3(reinterpret_cast<nvinfer1::ITensor* const*>(&in), 1, nullptr, 0, *interpolate_plugin);
TORCHTRT_CHECK(new_layer, "Unable to create pooling (interpolation) plugin from node" << *n);

new_layer->setName(util::node_info(n).c_str());
Expand Down
Loading
Loading