Class TensorRtLogger
- Namespace
- JYPPX.TensorRtSharp
- Assembly
- JYPPX.TensorRtSharp.dll
Managed wrapper around a TensorRT logger. TensorRT logger 的托管封装。
public sealed class TensorRtLogger : IDisposable
- Inheritance
-
TensorRtLogger
- Implements
- Inherited Members
Constructors
TensorRtLogger(TensorRtApiLine)
Creates a TensorRT logger for one TensorRT API line. 为一个 TensorRT API line 创建 TensorRT logger。
public TensorRtLogger(TensorRtApiLine line)
Parameters
lineTensorRtApiLineThe TensorRT API line. TensorRT API 版本线。
TensorRtLogger(TensorRtApiLine, TensorRtLogHandler, TensorRtLogSeverity)
Creates a TensorRT logger that forwards native logger messages to a managed handler. 创建一个会把 native logger 消息转发给托管处理器的 TensorRT logger。
public TensorRtLogger(TensorRtApiLine line, TensorRtLogHandler handler, TensorRtLogSeverity minimumSeverity = TensorRtLogSeverity.Warning)
Parameters
lineTensorRtApiLineThe TensorRT API line. TensorRT API 版本线。
handlerTensorRtLogHandlerThe managed log handler. The handler is kept alive until this logger is disposed. 托管日志处理器,其生命周期会保持到 logger 释放。
minimumSeverityTensorRtLogSeverityThe least severe message that should be forwarded. 数值不高于该级别的消息会被转发。
Remarks
The native bridge owns the TensorRT logger object while this wrapper owns the managed callback state.
TensorRT owners borrow the native logger pointer. If this logger is disposed while a managed owner still borrows it,
native release is deferred until the owner detaches. Exceptions thrown by handler are swallowed by
the managed trampoline and reported through CallbackFailureCount and LastCallbackException;
they are never allowed to cross the native ABI boundary.
native bridge 拥有 TensorRT logger 对象;当前托管封装拥有回调状态。释放 logger 前应先释放借用该 logger 的 TensorRT owner。
如果还有托管 owner 借用 logger,native 释放会延迟到 owner 解除借用之后。handler 抛出的异常会被托管
trampoline 吞吐,并通过 CallbackFailureCount 和 LastCallbackException 记录,不会跨 native ABI 边界抛出。
Properties
ApiLanguage
Gets copied TensorRT versioned-interface API language metadata for this logger on TensorRT 11. 获取 TensorRT 11 logger 的 versioned-interface API language 元数据副本。
public TensorRtApiLanguage ApiLanguage { get; }
Property Value
Remarks
The native bridge returns the scalar enum value and does not expose the logger pointer. TensorRT 8 and TensorRT 10 loggers are not versioned interfaces in the NVIDIA headers used by this bridge. native bridge 只返回标量 enum 值,不暴露 logger 指针。TensorRT 8 和 TensorRT 10 的 logger 在当前 bridge 使用的 NVIDIA 头文件中不是 versioned interface。
CallbackFailureCount
Gets the number of managed callback exceptions swallowed at the ABI boundary. 获取在 ABI 边界被吞吐的托管回调异常次数。
public long CallbackFailureCount { get; }
Property Value
CallbackInvocationCount
Gets the number of managed callback invocations observed by this logger. 获取当前 logger 观察到的托管回调调用次数。
public long CallbackInvocationCount { get; }
Property Value
HasManagedCallback
Gets whether this logger owns a managed callback state. 获取当前 logger 是否拥有托管回调状态。
public bool HasManagedCallback { get; }
Property Value
InterfaceInfo
Gets copied TensorRT versioned-interface metadata for this logger on TensorRT 11. 获取 TensorRT 11 logger 的 versioned-interface 元数据副本。
public TensorRtInterfaceInfo InterfaceInfo { get; }
Property Value
Remarks
TensorRT 8 and TensorRT 10 loggers are not versioned interfaces in the NVIDIA headers used by this bridge. TensorRT 8 和 TensorRT 10 的 logger 在当前 bridge 使用的 NVIDIA 头文件中不是 versioned interface。
IsAttached
Gets whether this logger is currently borrowed by at least one TensorRT owner wrapper. 获取当前 logger 是否正被至少一个 TensorRT owner 托管封装借用。
public bool IsAttached { get; }
Property Value
LastCallbackException
Gets the last exception thrown by the managed callback, if any. 获取托管回调最近一次抛出的异常。
public Exception? LastCallbackException { get; }
Property Value
Line
Gets the TensorRT API line used by this logger. 获取当前 logger 使用的 TensorRT API line。
public TensorRtApiLine Line { get; }
Property Value
Methods
Dispose()
Releases the TensorRT logger handle. 释放 TensorRT logger 句柄。
public void Dispose()
EmitDiagnostic(TensorRtLogSeverity, string)
Synchronously emits a diagnostic message through the native logger object. 通过 native logger 对象同步发送一条诊断消息。
public bool EmitDiagnostic(TensorRtLogSeverity severity, string message)
Parameters
severityTensorRtLogSeverityThe severity to use. 要使用的严重级别。
messagestringThe message to copy to native UTF-8 memory for the call. 调用时复制到 native UTF-8 内存的消息。
Returns
- bool
truewhen the message was accepted without a managed callback exception; otherwisefalse. 若消息未触发托管回调异常则返回true,否则返回false。
Remarks
This method is intended for diagnostics and smoke tests. It does not expose the native logger pointer and does not change logger ownership. 该方法用于诊断和 smoke 测试;它不会暴露 native logger 指针,也不会改变 logger 所有权。
~TensorRtLogger()
Releases logger callback resources if Dispose() was not called. 如果调用方未调用 Dispose(),则释放 logger callback 资源。
protected ~TensorRtLogger()
TryGetApiLanguage(out TensorRtApiLanguage)
Tries to get copied TensorRT API language metadata for this logger without exposing the native pointer. 尝试获取当前 logger 的 TensorRT API language 元数据副本;不会暴露 native 指针。
public bool TryGetApiLanguage(out TensorRtApiLanguage apiLanguage)
Parameters
apiLanguageTensorRtApiLanguageThe copied API language when the query succeeds. 查询成功时复制出的 API language。
Returns
- bool
true when API language metadata is available for this TensorRT line. 当前 TensorRT 版本线支持该元数据时返回 true。
TryGetApiLanguage(out TensorRtApiLanguage, out string)
Tries to get copied TensorRT API language metadata for this logger without exposing the native pointer. 尝试获取当前 logger 的 TensorRT API language 元数据副本;不会暴露 native 指针。
public bool TryGetApiLanguage(out TensorRtApiLanguage apiLanguage, out string diagnostic)
Parameters
apiLanguageTensorRtApiLanguageThe copied API language when the query succeeds. 查询成功时复制出的 API language。
diagnosticstringA short diagnostic string describing success or the reason for failure. 描述成功或失败原因的简短诊断。
Returns
- bool
true when API language metadata is available for this TensorRT line. 当前 TensorRT 版本线支持该元数据时返回 true。
TryGetInterfaceInfo(out TensorRtInterfaceInfo)
Tries to get copied TensorRT versioned-interface metadata for this logger without exposing the native pointer. 尝试获取当前 logger 的 TensorRT versioned-interface 元数据副本;不会暴露 native 指针。
public bool TryGetInterfaceInfo(out TensorRtInterfaceInfo interfaceInfo)
Parameters
interfaceInfoTensorRtInterfaceInfoThe copied interface metadata when the query succeeds. 查询成功时复制出的 interface 元数据。
Returns
- bool
true when interface metadata is available for this TensorRT line. 当前 TensorRT 版本线支持该元数据时返回 true。
TryGetInterfaceInfo(out TensorRtInterfaceInfo, out string)
Tries to get copied TensorRT versioned-interface metadata for this logger without exposing the native pointer. 尝试获取当前 logger 的 TensorRT versioned-interface 元数据副本;不会暴露 native 指针。
public bool TryGetInterfaceInfo(out TensorRtInterfaceInfo interfaceInfo, out string diagnostic)
Parameters
interfaceInfoTensorRtInterfaceInfoThe copied interface metadata when the query succeeds. 查询成功时复制出的 interface 元数据。
diagnosticstringA short diagnostic string describing success or the reason for failure. 描述成功或失败原因的简短诊断。
Returns
- bool
true when interface metadata is available for this TensorRT line. 当前 TensorRT 版本线支持该元数据时返回 true。