Class TensorRtBuilderConfig
- Namespace
- JYPPX.TensorRtSharp
- Assembly
- JYPPX.TensorRtSharp.dll
Managed wrapper around a TensorRT builder configuration. TensorRT builder 配置的托管封装。
public sealed class TensorRtBuilderConfig : IDisposable
- Inheritance
-
TensorRtBuilderConfig
- Implements
- Inherited Members
Properties
HasCalibrationProfile
Returns whether TensorRT currently has a calibration profile attached to this builder config. 返回 TensorRT 当前是否为此 builder config 附加了 calibration profile。
public bool HasCalibrationProfile { get; }
Property Value
HasProgressMonitor
Gets whether a TensorRT progress monitor is attached to this builder configuration. 获取当前 builder config 是否绑定了 TensorRT progress monitor。
public bool HasProgressMonitor { get; }
Property Value
HasTimingCache
Gets whether this TensorRT 11 builder configuration currently references a timing cache. 获取当前 TensorRT 11 构建配置是否已经绑定 timing cache。
public bool HasTimingCache { get; }
Property Value
IsProfileStreamSet
Returns whether this builder config has a profiling CUDA stream set. 返回当前 builder config 是否已经设置 profiling CUDA stream。
public bool IsProfileStreamSet { get; }
Property Value
Line
Gets the TensorRT API line used by this builder configuration. 获取当前 builder 配置使用的 TensorRT API line。
public TensorRtApiLine Line { get; }
Property Value
OptimizationProfileCount
Gets the number of optimization profiles currently attached to this builder config. 获取当前 builder config 已附加的 optimization profile 数量。
public int OptimizationProfileCount { get; }
Property Value
PluginToSerializeCount
Gets the number of plugin-library paths that TensorRT will serialize with compatible engines. 获取 TensorRT 将随兼容 engine 序列化的插件库路径数量。
public int PluginToSerializeCount { get; }
Property Value
Methods
AddOptimizationProfile(TensorRtOptimizationProfile)
Adds an optimization profile to this builder configuration. 向当前 builder 配置添加一个 optimization profile。
public int AddOptimizationProfile(TensorRtOptimizationProfile profile)
Parameters
profileTensorRtOptimizationProfileThe optimization profile to attach. 要附加的 optimization profile。
Returns
- int
The zero-based profile index assigned by TensorRT. TensorRT 分配的从零开始的 profile 索引。
CanRunOnDla(TensorRtLayer)
Checks whether TensorRT reports that a layer can run on DLA for this configuration. 查询 TensorRT 是否认为指定 layer 可在当前配置下运行于 DLA。
public bool CanRunOnDla(TensorRtLayer layer)
Parameters
layerTensorRtLayerThe layer to query. / 要查询的 layer。
Returns
ClearFlag(TensorRtBuilderFlag)
Clears one TensorRT builder flag. 清除一个 TensorRT builder 标志。
public void ClearFlag(TensorRtBuilderFlag flag)
Parameters
flagTensorRtBuilderFlagThe builder flag to clear. 要清除的 builder 标志。
ClearPluginsToSerialize()
Clears the plugin-library path list serialized into TensorRT 11 version-compatible engines. 清空会被序列化进 TensorRT 11 version-compatible engine 的插件库路径列表。
public void ClearPluginsToSerialize()
ClearProgressMonitor()
Clears any TensorRT progress monitor attached to this builder configuration. 清除当前 builder config 上绑定的 TensorRT progress monitor。
public void ClearProgressMonitor()
CreateTimingCache(byte[]?)
Creates a TensorRT timing cache from optional serialized bytes. 使用可选的序列化字节创建一个 TensorRT timing cache。
public TensorRtTimingCache CreateTimingCache(byte[]? serializedCache = null)
Parameters
serializedCachebyte[]Optional serialized timing-cache payload. 可选的序列化 timing cache 负载。
Returns
- TensorRtTimingCache
A TensorRT timing-cache wrapper. TensorRT timing cache 封装。
Dispose()
Releases the TensorRT builder-configuration handle. 释放 TensorRT builder 配置句柄。
public void Dispose()
GetAverageTimingIterations()
Gets the average timing-iteration count used by TensorRT tactic benchmarking. 获取 TensorRT tactic 基准测试使用的平均 timing 迭代次数。
public int GetAverageTimingIterations()
Returns
- int
The average timing-iteration count. 平均 timing 迭代次数。
GetDefaultDeviceType()
Gets the default TensorRT device type for layers. 获取 TensorRT layer 的默认设备类型。
public TensorRtDeviceType GetDefaultDeviceType()
Returns
GetDeploymentSnapshot()
Builds a TensorRT 11 deployment snapshot for this builder configuration. 为当前 builder configuration 构建 TensorRT 11 部署快照。
public TensorRtBuilderConfigDeploymentSnapshot GetDeploymentSnapshot()
Returns
- TensorRtBuilderConfigDeploymentSnapshot
A deployment snapshot with build-time knobs that affect engine portability and runtime behavior. 包含影响 engine 可移植性和运行时行为的构建参数快照。
Remarks
The snapshot is read-only and does not mutate the builder config. 该快照只读取当前配置,不会修改 builder config。
GetDlaCore()
Gets the selected DLA core index. 获取选中的 DLA core 索引。
public int GetDlaCore()
Returns
GetEngineCapability()
Gets the TensorRT engine capability currently configured for this builder config. 获取当前 builder config 中配置的 TensorRT engine capability。
public TensorRtEngineCapability GetEngineCapability()
Returns
- TensorRtEngineCapability
The configured engine capability. 已配置的 engine capability。
GetFlag(TensorRtBuilderFlag)
Returns whether one TensorRT builder flag is currently enabled. 返回某个 TensorRT builder 标志当前是否启用。
public bool GetFlag(TensorRtBuilderFlag flag)
Parameters
flagTensorRtBuilderFlagThe builder flag to query. 要查询的 builder 标志。
Returns
GetFlags()
Gets the complete TensorRT 11 builder flag bitmask. 获取完整的 TensorRT 11 builder flag 位掩码。
public TensorRtBuilderFlags GetFlags()
Returns
GetHardwareCompatibilityLevel()
Gets the configured TensorRT hardware compatibility level. 获取当前配置的 TensorRT 硬件兼容性级别。
public TensorRtHardwareCompatibilityLevel GetHardwareCompatibilityLevel()
Returns
- TensorRtHardwareCompatibilityLevel
The configured hardware compatibility level. 已配置的硬件兼容性级别。
GetL2LimitForTiling()
Gets the L2 byte limit used by TensorRT 11 tiling optimization. 获取 TensorRT 11 tiling 优化使用的 L2 字节上限。
public long GetL2LimitForTiling()
Returns
GetLayerDeviceType(TensorRtLayer)
Gets the TensorRT device type assigned to one layer. 获取一个 layer 当前分配到的 TensorRT device type。
public TensorRtDeviceType GetLayerDeviceType(TensorRtLayer layer)
Parameters
layerTensorRtLayerThe target layer. 目标 layer。
Returns
- TensorRtDeviceType
The configured TensorRT device type. 已配置的 TensorRT device type。
GetMaxAuxStreams()
Gets the maximum auxiliary CUDA stream count TensorRT may use. 获取 TensorRT 可使用的最大辅助 CUDA stream 数量。
public int GetMaxAuxStreams()
Returns
- int
The maximum auxiliary stream count. 最大辅助 stream 数量。
GetMaxTactics()
Gets the maximum number of TensorRT tactics considered during build. 获取构建时 TensorRT 最多考虑的 tactic 数量。
public int GetMaxTactics()
Returns
GetMemoryPoolLimit(TensorRtMemoryPoolType)
Gets a TensorRT memory-pool size limit. 获取一个 TensorRT memory pool 大小上限。
public ulong GetMemoryPoolLimit(TensorRtMemoryPoolType pool)
Parameters
poolTensorRtMemoryPoolTypeThe TensorRT memory pool. TensorRT 内存池。
Returns
- ulong
The size limit in bytes. 大小上限,单位为字节。
GetOptimizationLevel()
Gets the TensorRT builder optimization level. 获取 TensorRT builder 优化级别。
public int GetOptimizationLevel()
Returns
- int
The current optimization level. 当前优化级别。
GetPluginToSerialize(int)
Gets a plugin-library path from TensorRT's version-compatible serialization list. 从 TensorRT version-compatible 序列化列表中获取一个插件库路径。
public string GetPluginToSerialize(int index)
Parameters
indexintZero-based plugin path index. / 从零开始的插件路径索引。
Returns
- string
The plugin library path copied from TensorRT. / 从 TensorRT 复制出来的插件库路径。
GetPluginsToSerialize()
Gets every plugin-library path that TensorRT will serialize with a version-compatible engine. 获取 TensorRT 将随 version-compatible engine 序列化的全部插件库路径。
public IReadOnlyList<string> GetPluginsToSerialize()
Returns
- IReadOnlyList<string>
A snapshot of plugin-library paths copied from TensorRT. 从 TensorRT 复制出来的插件库路径快照。
Remarks
This is a read-only inventory helper; it does not load, create, own, or redistribute plugin binaries. 这是只读 inventory 辅助方法;它不会加载、创建、持有或再分发插件二进制。
GetPreviewFeature(TensorRtPreviewFeature)
Queries whether a TensorRT preview feature is enabled. 查询某个 TensorRT 预览特性是否已启用。
public bool GetPreviewFeature(TensorRtPreviewFeature feature)
Parameters
featureTensorRtPreviewFeatureThe preview feature. 预览特性。
Returns
- bool
truewhen the preview feature is enabled. 如果该预览特性已启用,则返回true。
GetProfilingVerbosity()
Gets TensorRT profiling verbosity for this builder configuration. 获取当前 builder 配置的 TensorRT profiling verbosity。
public TensorRtProfilingVerbosity GetProfilingVerbosity()
Returns
- TensorRtProfilingVerbosity
The configured profiling verbosity. 已配置的 profiling verbosity。
GetRemoteAutoTuningConfig()
Gets the TensorRT 11 remote auto-tuning configuration text. 获取 TensorRT 11 remote auto-tuning 配置文本。
public string GetRemoteAutoTuningConfig()
Returns
GetRuntimePlatform()
Gets the TensorRT 10.x runtime platform configured for this builder config. 获取当前 builder config 配置的 TensorRT 10.x runtime platform。
public TensorRtRuntimePlatform GetRuntimePlatform()
Returns
- TensorRtRuntimePlatform
The configured runtime platform. 已配置的 runtime platform。
Remarks
TensorRT 8.x does not expose this option and the native bridge returns NotSupported. TensorRT 8.x 不暴露该选项,原生桥接会返回 NotSupported。
GetTacticSources()
Gets the TensorRT tactic-source mask. 获取 TensorRT tactic source 掩码。
public TensorRtTacticSources GetTacticSources()
Returns
- TensorRtTacticSources
The enabled tactic sources. 已启用的 tactic sources。
GetTilingOptimizationLevel()
Gets the TensorRT 11 tiling optimization level. 获取 TensorRT 11 tiling 优化级别。
public TensorRtTilingOptimizationLevel GetTilingOptimizationLevel()
Returns
IsLayerDeviceTypeSet(TensorRtLayer)
Returns whether one layer has an explicit TensorRT device type. 返回一个 layer 是否具有显式 TensorRT device type。
public bool IsLayerDeviceTypeSet(TensorRtLayer layer)
Parameters
layerTensorRtLayerThe target layer. 目标 layer。
Returns
Reset()
Resets this TensorRT 11 builder configuration back to TensorRT defaults. 将当前 TensorRT 11 构建配置重置为 TensorRT 默认状态。
public void Reset()
Remarks
Use this only before building or after you intentionally discard all current options. Existing optimization profiles, flags, timing cache references, and deployment options may be cleared by TensorRT. 仅应在构建前或明确要丢弃当前配置时调用;TensorRT 可能会清除已有 optimization profile、flag、timing cache 引用和部署选项。
ResetLayerDeviceType(TensorRtLayer)
Removes the explicit TensorRT device-type assignment for one layer. 移除一个 layer 的显式 TensorRT device type 分配。
public void ResetLayerDeviceType(TensorRtLayer layer)
Parameters
layerTensorRtLayerThe target layer. 目标 layer。
SetAverageTimingIterations(int)
Sets the average timing-iteration count used by TensorRT tactic benchmarking. 设置 TensorRT tactic 基准测试使用的平均 timing 迭代次数。
public void SetAverageTimingIterations(int iterations)
Parameters
iterationsintThe average timing-iteration count. 平均 timing 迭代次数。
SetCalibrationProfile(TensorRtOptimizationProfile)
Sets the optimization profile TensorRT should use for INT8 calibration. 设置 TensorRT 在 INT8 calibration 中使用的 optimization profile。
public void SetCalibrationProfile(TensorRtOptimizationProfile profile)
Parameters
profileTensorRtOptimizationProfileThe calibration optimization profile. 用于 calibration 的 optimization profile。
Remarks
TensorRT 10 keeps this API for compatibility but marks it deprecated upstream; it is still useful for TensorRT 8/10 deployment migration. TensorRT 10 上游已将该 API 标记为 deprecated,但它对 TensorRT 8/10 部署迁移仍有实际价值。
SetDefaultDeviceType(TensorRtDeviceType)
Sets the default TensorRT device type for layers. 设置 TensorRT layer 的默认设备类型。
public void SetDefaultDeviceType(TensorRtDeviceType deviceType)
Parameters
deviceTypeTensorRtDeviceType
SetDlaCore(int)
Sets the selected DLA core index. 设置选中的 DLA core 索引。
public void SetDlaCore(int dlaCore)
Parameters
dlaCoreint
SetEngineCapability(TensorRtEngineCapability)
Sets the TensorRT engine capability used by the builder config. 设置 builder config 使用的 TensorRT engine capability。
public void SetEngineCapability(TensorRtEngineCapability capability)
Parameters
capabilityTensorRtEngineCapabilityThe target engine capability. 目标 engine capability。
SetFlag(TensorRtBuilderFlag, bool)
Enables or disables one TensorRT builder flag. 启用或禁用一个 TensorRT builder 标志。
public void SetFlag(TensorRtBuilderFlag flag, bool enabled = true)
Parameters
flagTensorRtBuilderFlagThe builder flag to change. 要修改的 builder 标志。
enabledboolWhether the flag should be enabled. 是否启用该标志。
SetFlags(TensorRtBuilderFlags)
Sets the complete TensorRT 11 builder flag bitmask. 设置完整的 TensorRT 11 builder flag 位掩码。
public void SetFlags(TensorRtBuilderFlags flags)
Parameters
flagsTensorRtBuilderFlagsThe full builder flag bitmask. / 完整 builder flag 位掩码。
SetHardwareCompatibilityLevel(TensorRtHardwareCompatibilityLevel)
Sets the hardware compatibility level for generated TensorRT engines. 设置生成 TensorRT engine 时使用的硬件兼容性级别。
public void SetHardwareCompatibilityLevel(TensorRtHardwareCompatibilityLevel level)
Parameters
levelTensorRtHardwareCompatibilityLevelThe hardware compatibility level. 硬件兼容性级别。
SetL2LimitForTiling(long)
Sets the L2 byte limit used by TensorRT 11 tiling optimization. 设置 TensorRT 11 tiling 优化使用的 L2 字节上限。
public bool SetL2LimitForTiling(long bytes)
Parameters
byteslongL2 byte limit. / L2 字节上限。
Returns
- bool
trueif TensorRT accepted the setting. / TensorRT 接受该设置时返回true。
SetLayerDeviceType(TensorRtLayer, TensorRtDeviceType)
Pins one layer to a specific TensorRT device type. 将一个 layer 固定到指定的 TensorRT device type。
public void SetLayerDeviceType(TensorRtLayer layer, TensorRtDeviceType deviceType)
Parameters
layerTensorRtLayerThe target layer. 目标 layer。
deviceTypeTensorRtDeviceTypeThe TensorRT device type. TensorRT 设备类型。
SetMaxAuxStreams(int)
Sets the maximum auxiliary CUDA stream count TensorRT may use. 设置 TensorRT 可使用的最大辅助 CUDA stream 数量。
public void SetMaxAuxStreams(int maxStreams)
Parameters
maxStreamsintThe maximum auxiliary stream count. 最大辅助 stream 数量。
SetMaxTactics(int)
Sets the maximum number of TensorRT tactics considered during build. 设置构建时 TensorRT 最多考虑的 tactic 数量。
public void SetMaxTactics(int maxTactics)
Parameters
maxTacticsint
SetMemoryPoolLimit(TensorRtMemoryPoolType, ulong)
Sets a TensorRT memory-pool size limit. 设置一个 TensorRT memory pool 大小上限。
public void SetMemoryPoolLimit(TensorRtMemoryPoolType pool, ulong bytes)
Parameters
poolTensorRtMemoryPoolTypeThe TensorRT memory pool. TensorRT 内存池。
bytesulongThe size limit in bytes. 大小上限,单位为字节。
SetOptimizationLevel(int)
Sets the TensorRT builder optimization level. 设置 TensorRT builder 优化级别。
public void SetOptimizationLevel(int level)
Parameters
levelintThe optimization level. 优化级别。
SetPluginsToSerialize(IReadOnlyList<string>)
Sets the plugin library paths that TensorRT 11 should serialize with the generated engine plan. 设置 TensorRT 11 在生成 engine plan 时需要一并序列化的插件库路径。
public bool SetPluginsToSerialize(IReadOnlyList<string> pluginLibraryPaths)
Parameters
pluginLibraryPathsIReadOnlyList<string>Plugin library paths visible to TensorRT during build and deployment. 构建和部署阶段 TensorRT 可访问的插件库路径。
Returns
Remarks
Passing an empty collection clears the list. The bridge only passes path strings; it does not load, own, or redistribute plugin binaries. 传入空集合会清空列表。桥接层只传递路径字符串,不负责加载、持有或再分发插件二进制文件。
SetPluginsToSerialize(params string[])
Sets the plugin library paths that TensorRT 11 should serialize with the generated engine plan. 设置 TensorRT 11 在生成 engine plan 时需要一并序列化的插件库路径。
public bool SetPluginsToSerialize(params string[] pluginLibraryPaths)
Parameters
pluginLibraryPathsstring[]Plugin library paths visible to TensorRT during build and deployment. 构建和部署阶段 TensorRT 可访问的插件库路径。
Returns
SetPreviewFeature(TensorRtPreviewFeature, bool)
Enables or disables a TensorRT preview feature. 启用或禁用 TensorRT 预览特性。
public void SetPreviewFeature(TensorRtPreviewFeature feature, bool enabled)
Parameters
featureTensorRtPreviewFeatureThe preview feature. 预览特性。
enabledboolWhether the feature should be enabled. 是否启用该特性。
SetProfileStream(CudaStream)
Sets the CUDA stream TensorRT uses for profiling work during engine building. 设置 TensorRT 在 engine 构建 profiling 阶段使用的 CUDA stream。
public void SetProfileStream(CudaStream stream)
Parameters
streamCudaStreamThe CUDA stream used by TensorRT profiling. TensorRT profiling 使用的 CUDA stream。
Remarks
The stream must remain alive until the build operation that uses this config has completed. 该 stream 必须至少存活到使用此 config 的构建操作结束。
SetProfilingVerbosity(TensorRtProfilingVerbosity)
Sets TensorRT profiling verbosity for build diagnostics. 设置构建诊断使用的 TensorRT profiling verbosity。
public void SetProfilingVerbosity(TensorRtProfilingVerbosity verbosity)
Parameters
verbosityTensorRtProfilingVerbosityThe profiling verbosity. profiling 详细程度。
SetRemoteAutoTuningConfig(string)
Sets the TensorRT 11 remote auto-tuning configuration text. 设置 TensorRT 11 remote auto-tuning 配置文本。
public bool SetRemoteAutoTuningConfig(string configText)
Parameters
configTextstringConfiguration text accepted by TensorRT. / TensorRT 可接受的配置文本。
Returns
- bool
trueif TensorRT accepted the setting. / TensorRT 接受该设置时返回true。
SetRuntimePlatform(TensorRtRuntimePlatform)
Sets the TensorRT 10.x runtime platform for cross-platform engine generation. 设置 TensorRT 10.x 用于跨平台 engine 生成的 runtime platform。
public void SetRuntimePlatform(TensorRtRuntimePlatform platform)
Parameters
platformTensorRtRuntimePlatformThe TensorRT runtime platform. TensorRT 运行时平台。
Remarks
TensorRT 8.x does not expose this option and the native bridge returns NotSupported. TensorRT 8.x 不暴露该选项,原生桥接会返回 NotSupported。
SetTacticSources(TensorRtTacticSources)
Sets the TensorRT tactic-source mask. 设置 TensorRT tactic source 掩码。
public void SetTacticSources(TensorRtTacticSources sources)
Parameters
sourcesTensorRtTacticSourcesThe enabled tactic sources. 已启用的 tactic sources。
SetTilingOptimizationLevel(TensorRtTilingOptimizationLevel)
Sets the TensorRT 11 tiling optimization level. 设置 TensorRT 11 tiling 优化级别。
public bool SetTilingOptimizationLevel(TensorRtTilingOptimizationLevel level)
Parameters
levelTensorRtTilingOptimizationLevelThe tiling optimization level. / tiling 优化级别。
Returns
- bool
trueif TensorRT accepted the setting. / TensorRT 接受该设置时返回true。
SetTimingCache(TensorRtTimingCache, bool)
Attaches a TensorRT timing cache to this builder configuration. 将一个 TensorRT timing cache 附加到当前 builder 配置。
public void SetTimingCache(TensorRtTimingCache cache, bool ignoreMismatch = false)
Parameters
cacheTensorRtTimingCacheThe timing cache to attach. 要附加的 timing cache。
ignoreMismatchboolWhether TensorRT should ignore cache mismatches. TensorRT 是否忽略 cache 不匹配。
TryGetPluginsToSerialize(out IReadOnlyList<string>, out string)
Tries to read the plugin-library path inventory without throwing for unsupported TensorRT lines. 尝试读取插件库路径 inventory;当当前 TensorRT 版本线不支持时不会抛出异常。
public bool TryGetPluginsToSerialize(out IReadOnlyList<string> pluginLibraryPaths, out string diagnostic)
Parameters
pluginLibraryPathsIReadOnlyList<string>The copied plugin-library paths when the query succeeds. 查询成功时复制出的插件库路径。
diagnosticstringA short diagnostic string describing success or the reason for failure. 描述成功或失败原因的简短诊断。