Table of Contents

Class TensorRtBuilder

Namespace
JYPPX.TensorRtSharp
Assembly
JYPPX.TensorRtSharp.dll

Managed wrapper around a TensorRT builder. TensorRT builder 的托管封装。

public sealed class TensorRtBuilder : IDisposable
Inheritance
TensorRtBuilder
Implements
Inherited Members

Constructors

TensorRtBuilder(TensorRtLogger)

Creates a TensorRT builder from a logger. 使用 logger 创建一个 TensorRT builder。

public TensorRtBuilder(TensorRtLogger logger)

Parameters

logger TensorRtLogger

The TensorRT logger used by the builder. builder 使用的 TensorRT logger。

Properties

DlaCoreCount

Gets the number of available DLA cores. 获取可用 DLA core 数量。

public int DlaCoreCount { get; }

Property Value

int

HasErrorRecorder

Gets whether a native TensorRT error recorder is currently attached to this builder. 获取当前 builder 是否绑定了 TensorRT 原生 error recorder。

public bool HasErrorRecorder { get; }

Property Value

bool

Line

Gets the TensorRT API line used by this builder. 获取当前 builder 使用的 TensorRT API line。

public TensorRtApiLine Line { get; }

Property Value

TensorRtApiLine

MaxDlaBatchSize

Gets TensorRT 11's maximum DLA batch size for legacy DLA checks. 获取 TensorRT 11 用于传统 DLA 检查的最大 DLA batch size。

public int MaxDlaBatchSize { get; }

Property Value

int

Remarks

TensorRT reports that this value does not apply to dynamic shapes. Use it as a compatibility diagnostic, not as a dynamic-shape capacity limit. TensorRT 官方说明该值不适用于 dynamic shape;请把它作为兼容性诊断信息,而不是动态 shape 的容量上限。

MaxThreads

Gets TensorRT 11's current builder worker-thread limit. 获取 TensorRT 11 当前 builder 工作线程上限。

public int MaxThreads { get; }

Property Value

int

PlatformHasFastFp16

Gets whether the platform reports fast FP16 support. 获取平台是否报告支持快速 FP16。

public bool PlatformHasFastFp16 { get; }

Property Value

bool

PlatformHasFastInt8

Gets whether the platform reports fast INT8 support. 获取平台是否报告支持快速 INT8。

public bool PlatformHasFastInt8 { get; }

Property Value

bool

PlatformHasTf32

Gets whether the platform reports TF32 support. 获取平台是否报告支持 TF32。

public bool PlatformHasTf32 { get; }

Property Value

bool

Methods

BuildEngineWithConfig(TensorRtNetworkDefinition, TensorRtBuilderConfig)

Builds a TensorRT 11 CUDA engine directly from a network and builder configuration. 直接从 network 和 builder config 构建 TensorRT 11 CUDA engine。

public TensorRtEngine BuildEngineWithConfig(TensorRtNetworkDefinition network, TensorRtBuilderConfig config)

Parameters

network TensorRtNetworkDefinition

The TensorRT network definition to build. 要构建的 TensorRT network definition。

config TensorRtBuilderConfig

The TensorRT builder configuration. TensorRT 构建配置。

Returns

TensorRtEngine

A managed CUDA engine wrapper. 托管 CUDA engine 封装对象。

Remarks

This exposes TensorRT's IBuilder::buildEngineWithConfig path. For version-compatible deployment and persistence, prefer BuildSerializedNetwork(TensorRtNetworkDefinition, TensorRtBuilderConfig). 该方法对应 TensorRT 的 IBuilder::buildEngineWithConfig 路径;如果需要版本兼容部署或持久化,请优先使用 BuildSerializedNetwork(TensorRtNetworkDefinition, TensorRtBuilderConfig)

BuildSerializedNetwork(TensorRtNetworkDefinition, TensorRtBuilderConfig)

Builds a serialized TensorRT engine from a network and configuration. 使用 network 和配置构建序列化的 TensorRT engine。

public TensorRtHostMemory BuildSerializedNetwork(TensorRtNetworkDefinition network, TensorRtBuilderConfig config)

Parameters

network TensorRtNetworkDefinition

The source network definition. 源 network definition。

config TensorRtBuilderConfig

The builder configuration. builder 配置。

Returns

TensorRtHostMemory

The serialized engine memory. 序列化 engine 内存。

BuildSerializedNetworkWithKernelText(TensorRtNetworkDefinition, TensorRtBuilderConfig)

Builds a serialized TensorRT 11 network and captures optional kernel text emitted by TensorRT. 构建 TensorRT 11 序列化网络,并获取 TensorRT 可选生成的 kernel text。

public TensorRtSerializedNetworkWithKernelText BuildSerializedNetworkWithKernelText(TensorRtNetworkDefinition network, TensorRtBuilderConfig config)

Parameters

network TensorRtNetworkDefinition

The TensorRT network definition to build. 要构建的 TensorRT network definition。

config TensorRtBuilderConfig

The TensorRT builder configuration. TensorRT 构建配置。

Returns

TensorRtSerializedNetworkWithKernelText

The serialized plan plus optional kernel text. 序列化 plan 以及可选 kernel text。

ClearErrorRecorder()

Clears the native TensorRT error recorder attached to this builder. 清除当前 builder 上绑定的 TensorRT 原生 error recorder。

public void ClearErrorRecorder()

ClearGpuAllocator()

Clears the custom GPU allocator on this TensorRT 11 builder. 清除当前 TensorRT 11 builder 上绑定的自定义 GPU allocator。

public void ClearGpuAllocator()

Remarks

The bridge currently exposes clearing only. Installing a managed allocator is intentionally left out until callback ownership is designed. 当前桥接层只暴露清除操作;托管 allocator 回调涉及生命周期和线程边界,暂不在普通高层 API 中暴露。

CreateBuilderConfig()

Creates a builder configuration object. 创建一个 builder 配置对象。

public TensorRtBuilderConfig CreateBuilderConfig()

Returns

TensorRtBuilderConfig

A TensorRT builder configuration wrapper. TensorRT builder 配置封装。

CreateNetwork(TensorRtNetworkDefinitionCreationFlags)

Creates a network definition owned by this builder. 创建一个由当前 builder 拥有的 network definition。

public TensorRtNetworkDefinition CreateNetwork(TensorRtNetworkDefinitionCreationFlags flags = TensorRtNetworkDefinitionCreationFlags.None)

Parameters

flags TensorRtNetworkDefinitionCreationFlags

The network-definition creation flags. network definition 创建标志。

Returns

TensorRtNetworkDefinition

A TensorRT network-definition wrapper. TensorRT network definition 封装。

CreateOptimizationProfile()

Creates an optimization profile. 创建一个优化 profile。

public TensorRtOptimizationProfile CreateOptimizationProfile()

Returns

TensorRtOptimizationProfile

A TensorRT optimization-profile wrapper. TensorRT optimization profile 封装。

Dispose()

Releases the TensorRT builder handle. 释放 TensorRT builder 句柄。

public void Dispose()

GetPluginRegistryInventory()

Gets a read-only snapshot of TensorRT plugin creators registered for this builder. 获取当前 builder 可见的 TensorRT plugin creator 只读快照。

public TensorRtPluginRegistryInventory GetPluginRegistryInventory()

Returns

TensorRtPluginRegistryInventory

A plugin registry inventory snapshot. Plugin registry inventory 快照。

Remarks

This method does not create plugins, deserialize plugins, load plugin libraries, or take ownership of creator objects. 该方法不会创建 plugin、反序列化 plugin、加载 plugin library,也不会接管 creator 对象所有权。

IsNetworkSupported(TensorRtNetworkDefinition, TensorRtBuilderConfig)

Checks whether TensorRT 11 can build the supplied network with the supplied builder config. 检查 TensorRT 11 是否支持使用指定 builder config 构建给定 network。

public bool IsNetworkSupported(TensorRtNetworkDefinition network, TensorRtBuilderConfig config)

Parameters

network TensorRtNetworkDefinition

The network definition to validate. / 要验证的 network definition。

config TensorRtBuilderConfig

The builder config used for validation. / 用于验证的 builder config。

Returns

bool

true when TensorRT reports the network as supported. / TensorRT 报告该 network 可支持时返回 true

Reset()

Resets TensorRT 11 builder state back to its default configuration. 将 TensorRT 11 builder 状态重置为默认配置。

public void Reset()

SetMaxThreads(int)

Sets TensorRT 11's builder worker-thread limit. 设置 TensorRT 11 的 builder 工作线程上限。

public bool SetMaxThreads(int maxThreads)

Parameters

maxThreads int

The desired worker-thread limit. / 期望的工作线程上限。

Returns

bool

true when TensorRT accepted the setting. / TensorRT 接受该设置时返回 true

TryGetPluginRegistryInventory(out TensorRtPluginRegistryInventory, out string)

Tries to get a plugin registry inventory without throwing for unsupported TensorRT lines. 尝试获取 plugin registry inventory;当 TensorRT line 不支持时不抛出异常。

public bool TryGetPluginRegistryInventory(out TensorRtPluginRegistryInventory inventory, out string diagnostic)

Parameters

inventory TensorRtPluginRegistryInventory

The inventory snapshot when the query succeeds. 查询成功时的 inventory 快照。

diagnostic string

A diagnostic string describing success or failure. 描述成功或失败原因的诊断字符串。

Returns

bool

true when the inventory was collected successfully. 成功收集 inventory 时返回 true