TensorRT 10.8.0
nvinfer1::IExecutionContext 类参考

用于使用引擎执行推理的上下文,具有功能上不安全的功能。 更多...

#include <NvInferRuntime.h>

nvinfer1::IExecutionContext 的继承关系图
nvinfer1::INoCopy

公共成员函数

virtual ~IExecutionContext () noexcept=default
 
void setDebugSync (bool sync) noexcept
 设置调试同步标志。 更多...
 
bool getDebugSync () const noexcept
 获取调试同步标志。 更多...
 
void setProfiler (IProfiler *profiler) noexcept
 设置性能分析器。 更多...
 
IProfilergetProfiler () const noexcept
 获取性能分析器。 更多...
 
ICudaEngine const & getEngine () const noexcept
 获取关联的引擎。 更多...
 
void setName (char const *name) noexcept
 设置执行上下文的名称。 更多...
 
char const * getName () const noexcept
 返回执行上下文的名称。 更多...
 
void setDeviceMemory (void *memory) noexcept
 设置此执行上下文使用的设备内存。 更多...
 
void setDeviceMemoryV2 (void *memory, int64_t size) noexcept
 设置此执行上下文使用的设备内存及其相应大小。 更多...
 
Dims getTensorStrides (char const *tensorName) const noexcept
 返回给定张量名称的缓冲区的步幅。 更多...
 
int32_t getOptimizationProfile () const noexcept
 获取当前选定的优化配置文件的索引。 更多...
 
bool setInputShape (char const *tensorName, Dims const &dims) noexcept
 设置给定输入的形状。 更多...
 
Dims getTensorShape (char const *tensorName) const noexcept
 返回给定输入或输出的形状。 更多...
 
bool allInputDimensionsSpecified () const noexcept
 是否已指定输入张量的所有动态维度。 更多...
 
TRT_DEPRECATED bool allInputShapesSpecified () const noexcept
 是否已指定所有输入形状绑定。 更多...
 
void setErrorRecorder (IErrorRecorder *recorder) noexcept
 为此接口设置 ErrorRecorder。 更多...
 
IErrorRecordergetErrorRecorder () const noexcept
 获取分配给此接口的 ErrorRecorder。 更多...
 
bool executeV2 (void *const *bindings) noexcept
 同步执行网络。 更多...
 
bool setOptimizationProfileAsync (int32_t profileIndex, cudaStream_t stream) noexcept
 使用异步语义为当前上下文选择一个优化配置文件。 更多...
 
void setEnqueueEmitsProfile (bool enqueueEmitsProfile) noexcept
 设置入队是否将层计时信息发送到性能分析器。 更多...
 
bool getEnqueueEmitsProfile () const noexcept
 获取 enqueueEmitsProfile 状态。 更多...
 
bool reportToProfiler () const noexcept
 IExecutionContext 中计算当前优化配置文件的层计时信息,并在一次推理启动后更新性能分析器。 更多...
 
bool setTensorAddress (char const *tensorName, void *data) noexcept
 设置给定输入或输出张量的内存地址。 更多...
 
void const * getTensorAddress (char const *tensorName) const noexcept
 获取绑定到给定输入或输出张量的内存地址,如果提供的名称未映射到输入或输出张量,则返回 nullptr。 更多...
 
bool setOutputTensorAddress (char const *tensorName, void *data) noexcept
 设置给定输出张量的内存地址。 更多...
 
bool setInputTensorAddress (char const *tensorName, void const *data) noexcept
 设置给定输入的内存地址。 更多...
 
void * getOutputTensorAddress (char const *tensorName) const noexcept
 获取给定输出的内存地址。 更多...
 
int32_t inferShapes (int32_t nbMaxNames, char const **tensorNames) noexcept
 运行形状计算。 更多...
 
size_t updateDeviceMemorySizeForShapes () noexcept
 基于当前的输入形状重新计算内部激活缓冲区大小,并返回所需的总内存量。 更多...
 
bool setInputConsumedEvent (cudaEvent_t event) noexcept
 标记输入为已消耗。 更多...
 
cudaEvent_t getInputConsumedEvent () const noexcept
 与消耗输入关联的事件。 更多...
 
bool setOutputAllocator (char const *tensorName, IOutputAllocator *outputAllocator) noexcept
 设置用于给定名称的输出张量的输出分配器。传递 nullptr 给 outputAllocator 以取消设置。分配器由 enqueueV3() 调用。 更多...
 
IOutputAllocatorgetOutputAllocator (char const *tensorName) const noexcept
 获取与给定名称的输出张量关联的输出分配器,如果提供的名称未映射到输出张量,则返回 nullptr。 更多...
 
int64_t getMaxOutputSize (char const *tensorName) const noexcept
 基于当前的优化配置文件和输入维度,获取输出张量大小(以字节为单位)的上限。 更多...
 
bool setTemporaryStorageAllocator (IGpuAllocator *allocator) noexcept
 指定用于内部临时存储的分配器。 更多...
 
IGpuAllocatorgetTemporaryStorageAllocator () const noexcept
 获取由 setTemporaryStorageAllocator 设置的分配器。 更多...
 
bool enqueueV3 (cudaStream_t stream) noexcept
 在流上入队推理。 更多...
 
void setPersistentCacheLimit (size_t size) noexcept
 设置持久缓存使用的最大大小。 更多...
 
size_t getPersistentCacheLimit () const noexcept
 获取持久缓存使用的最大大小。 更多...
 
bool setNvtxVerbosity (ProfilingVerbosity verbosity) noexcept
 设置执行上下文中 NVTX 标记的详细程度。 更多...
 
ProfilingVerbosity getNvtxVerbosity () const noexcept
 获取执行上下文的 NVTX 详细程度。 更多...
 
void setAuxStreams (cudaStream_t *auxStreams, int32_t nbStreams) noexcept
 设置 TensorRT 应在下一次 enqueueV3() 调用中在其上启动内核的辅助流。 更多...
 
bool setDebugListener (IDebugListener *listener) noexcept
 为此执行上下文设置 DebugListener。 更多...
 
IDebugListenergetDebugListener () noexcept
 获取此执行上下文的 DebugListener。 更多...
 
bool setTensorDebugState (char const *name, bool flag) noexcept
 设置给定张量名称的张量的调试状态。 更多...
 
bool setAllTensorsDebugState (bool flag) noexcept
 
bool getDebugState (char const *name) const noexcept
 

保护属性

apiv::VExecutionContext * mImpl
 

附加的继承成员

- 继承自 nvinfer1::INoCopy 的保护成员函数
 INoCopy ()=default
 
virtual ~INoCopy ()=default
 
 INoCopy (INoCopy const &other)=delete
 
INoCopyoperator= (INoCopy const &other)=delete
 
 INoCopy (INoCopy &&other)=delete
 
INoCopyoperator= (INoCopy &&other)=delete
 

详细描述

用于使用引擎执行推理的上下文,具有功能上不安全的功能。

一个 ICudaEngine 实例可以存在多个执行上下文,从而允许同一个引擎同时用于执行多个批次。如果引擎支持动态形状,则并发使用的每个执行上下文都必须使用单独的优化配置文件。

警告
不要从此类继承,因为这样做会破坏 API 和 ABI 的向前兼容性。

构造函数 & 析构函数文档

◆ ~IExecutionContext()

virtual nvinfer1::IExecutionContext::~IExecutionContext ( )
virtualdefaultnoexcept

成员函数文档

◆ allInputDimensionsSpecified()

bool nvinfer1::IExecutionContext::allInputDimensionsSpecified ( ) const
inlinenoexcept

是否已指定输入张量的所有动态维度。

返回值
如果已通过调用 setInputShape() 指定了输入张量的所有动态维度,则为 True。

如果网络没有动态形状的输入张量,则始终为 true。

不适用于基于名称的接口,例如 IExecutionContext::setInputShape()。请改用 IExecutionContext::inferShapes()

◆ allInputShapesSpecified()

TRT_DEPRECATED bool nvinfer1::IExecutionContext::allInputShapesSpecified ( ) const
inlinenoexcept

是否已指定所有输入形状绑定。

返回值
如果已通过 setInputShapeBinding() 指定了所有输入形状绑定,则为 True。

如果网络没有输入形状绑定,则始终为 true。

不适用于基于名称的接口,例如 IExecutionContext::setInputShape()。请改用 IExecutionContext::inferShapes()

已弃用
在 TensorRT 10.0 中已弃用。setInputShapeBinding() 自 TensorRT 10.0 起已移除。

◆ enqueueV3()

bool nvinfer1::IExecutionContext::enqueueV3 ( cudaStream_t  stream)
inlinenoexcept

在流上入队推理。

参数
stream将在其上入队推理内核的 CUDA 流。
返回值
如果内核成功入队,则为 True,否则为 false。

在流同步或传递给 setInputConsumedEvent 的事件被触发之前,修改或释放已为张量注册的内存会导致未定义的行为。输入张量可以在 setInputConsumedEvent 之后释放,而输出张量需要流同步。

警告
由于 TensorRT 为了确保正确的同步而进行的额外 cudaDeviceSynchronize() 调用,使用默认流可能会导致性能问题。请改用非默认流。
如果引擎正在流式传输权重,则 enqueueV3 将变为同步,并且图将不可捕获。

◆ executeV2()

bool nvinfer1::IExecutionContext::executeV2 ( void *const *  bindings)
inlinenoexcept

同步执行网络。

此方法需要输入和输出缓冲区数组。可以使用 ICudaEngine::getIOTensorName() 查询从索引到张量名称的映射。

参数
bindings网络输入和输出缓冲区的指针数组。
返回值
如果执行成功,则为 True。
另请参阅
ICudaEngine::getIOTensorName()

◆ getDebugListener()

IDebugListener * nvinfer1::IExecutionContext::getDebugListener ( )
inlinenoexcept

获取此执行上下文的 DebugListener。

返回值
此执行上下文的 DebugListener。

◆ getDebugState()

bool nvinfer1::IExecutionContext::getDebugState ( char const *  name) const
inlinenoexcept

获取调试状态。

返回值
如果存在具有给定名称的调试张量并且已开启调试状态,则为 true。

◆ getDebugSync()

bool nvinfer1::IExecutionContext::getDebugSync ( ) const
inlinenoexcept

获取调试同步标志。

另请参阅
setDebugSync()

◆ getEngine()

ICudaEngine const & nvinfer1::IExecutionContext::getEngine ( ) const
inlinenoexcept

获取关联的引擎。

另请参阅
ICudaEngine

◆ getEnqueueEmitsProfile()

bool nvinfer1::IExecutionContext::getEnqueueEmitsProfile ( ) const
inlinenoexcept

获取 enqueueEmitsProfile 状态。

返回值
enqueueEmitsProfile 状态。
另请参阅
IExecutionContext::setEnqueueEmitsProfile()

◆ getErrorRecorder()

IErrorRecorder * nvinfer1::IExecutionContext::getErrorRecorder ( ) const
inlinenoexcept

获取分配给此接口的 ErrorRecorder。

检索给定类别的已分配错误记录器对象。如果未设置错误处理程序,则将返回 nullptr。

返回值
指向已注册的 IErrorRecorder 对象的指针。
另请参阅
setErrorRecorder()

◆ getInputConsumedEvent()

cudaEvent_t nvinfer1::IExecutionContext::getInputConsumedEvent ( ) const
inlinenoexcept

与消耗输入关联的事件。

返回值
CUDA 事件。如果尚未设置事件,则将返回 Nullptr。

◆ getMaxOutputSize()

int64_t nvinfer1::IExecutionContext::getMaxOutputSize ( char const *  tensorName) const
inlinenoexcept

基于当前的优化配置文件和输入维度,获取输出张量大小(以字节为单位)的上限。

如果尚未设置配置文件或输入维度,或者提供的名称未映射到输出,则返回 -1。

参数
tensorName输出张量的名称。
返回值
以字节为单位的上限。
警告
字符串 tensorName 必须以 null 结尾,并且包括终止符在内最多为 4096 字节。

◆ getName()

char const * nvinfer1::IExecutionContext::getName ( ) const
inlinenoexcept

返回执行上下文的名称。

另请参阅
setName()

◆ getNvtxVerbosity()

ProfilingVerbosity nvinfer1::IExecutionContext::getNvtxVerbosity ( ) const
inlinenoexcept

获取执行上下文的 NVTX 详细程度。

返回值
执行上下文的当前 NVTX 详细程度。
另请参阅
setNvtxVerbosity()

◆ getOptimizationProfile()

int32_t nvinfer1::IExecutionContext::getOptimizationProfile ( ) const
inlinenoexcept

获取当前选定的优化配置文件的索引。

如果尚未设置配置文件索引(如果尚未将其他执行上下文设置为配置文件 0,则隐式设置为 0,或者为所有后续上下文显式设置),则将返回无效值 -1,并且所有对 enqueueV3()/executeV2() 的调用都将失败,直到设置了有效的配置文件索引。此行为在 TensorRT 8.6 中已弃用,所有配置文件都将默认为优化配置文件 0,并且不再返回 -1。

◆ getOutputAllocator()

IOutputAllocator * nvinfer1::IExecutionContext::getOutputAllocator ( char const *  tensorName) const
inlinenoexcept

获取与给定名称的输出张量关联的输出分配器,如果提供的名称未映射到输出张量,则返回 nullptr。

警告
字符串 tensorName 必须以 null 结尾,并且包括终止符在内最多为 4096 字节。
另请参阅
IOutputAllocator

◆ getOutputTensorAddress()

void * nvinfer1::IExecutionContext::getOutputTensorAddress ( char const *  tensorName) const
inlinenoexcept

获取给定输出的内存地址。

参数
tensorName输出张量的名称。
返回值
给定输出张量的原始输出数据指针 (void*),如果提供的名称未映射到输出张量,则返回 nullptr。

如果只需要 (void const*) 指针,则另一种方法是调用方法 getTensorAddress()

警告
字符串 tensorName 必须以 null 结尾,并且包括终止符在内最多为 4096 字节。
另请参阅
getTensorAddress()

◆ getPersistentCacheLimit()

size_t nvinfer1::IExecutionContext::getPersistentCacheLimit ( ) const
inlinenoexcept

获取持久缓存使用的最大大小。

返回值
持久缓存限制的大小
另请参阅
setPersistentCacheLimit

◆ getProfiler()

IProfiler * nvinfer1::IExecutionContext::getProfiler ( ) const
inlinenoexcept

获取性能分析器。

另请参阅
IProfiler setProfiler()

◆ getTemporaryStorageAllocator()

IGpuAllocator * nvinfer1::IExecutionContext::getTemporaryStorageAllocator ( ) const
inlinenoexcept

获取由 setTemporaryStorageAllocator 设置的分配器。

如果使用 setTemporaryStorageAllocator() 传递了 nullptr,则返回 nullptr。

◆ getTensorAddress()

void const * nvinfer1::IExecutionContext::getTensorAddress ( char const *  tensorName) const
inlinenoexcept

获取绑定到给定输入或输出张量的内存地址,如果提供的名称未映射到输入或输出张量,则返回 nullptr。

参数
tensorName输入或输出张量的名称。

如果需要输出张量的非 const 指针,请使用方法 getOutputTensorAddress()

警告
字符串 tensorName 必须以 null 结尾,并且包括终止符在内最多为 4096 字节。
另请参阅
getOutputTensorAddress()

◆ getTensorShape()

Dims nvinfer1::IExecutionContext::getTensorShape ( char const *  tensorName) const
inlinenoexcept

返回给定输入或输出的形状。

参数
tensorName输入或输出张量的名称。

如果提供的名称未映射到输入或输出张量,则返回 Dims{-1, {}}。否则,返回输入或输出张量的形状。

如果以下所有条件都为真,则输入张量中的维度将具有 -1 通配符值

  • 尚未为此张量调用 setInputShape()
  • 该维度是运行时维度,并且未隐式约束为单个值。

如果维度依赖于执行张量的值,或者如果以下所有条件都为真,则输出张量中的维度将具有 -1 通配符值

  • 它是一个运行时维度。
  • 尚未为具有运行时形状的某些输入张量调用 setInputShape()
  • 尚未为 isShapeInferenceIO() = true 的某些输入张量调用 setTensorAddress()

如果输出张量的形状取决于提供给 enqueueV3() 的张量的值,则输出张量也可能具有 -1 通配符维度。

如果请求的是具有运行时维度的输出张量的形状,则所有 isShapeInferenceIO() = true 的输入张量都应已设置其值,因为可能需要这些值来计算输出形状。

隐式约束为单个值的输入维度的示例

  • 优化配置文件指定了相等的最小和最大值。
  • 该维度已命名,并且只有一个值满足该名称的维度的优化配置文件要求。
警告
字符串 tensorName 必须以 null 结尾,并且包括终止符在内最多为 4096 字节。

◆ getTensorStrides()

Dims nvinfer1::IExecutionContext::getTensorStrides ( char const *  tensorName) const
inlinenoexcept

返回给定张量名称的缓冲区的步幅。

步幅以元素为单位,而不是以组件或字节为单位。例如,对于 TensorFormat::kHWC8,步幅为 1 跨越 8 个标量。

请注意,对于具有动态形状的不同执行上下文,步幅可能不同。

如果提供的名称未映射到输入或输出张量,或者存在尚未设置的动态维度,则返回 Dims{-1, {}}

参数
tensorName输入或输出张量的名称。
警告
字符串 tensorName 必须以 null 结尾,并且包括终止符在内最多为 4096 字节。

◆ inferShapes()

int32_t nvinfer1::IExecutionContext::inferShapes ( int32_t  nbMaxNames,
char const **  tensorNames 
)
inlinenoexcept

运行形状计算。

参数
nbMaxNames要写入 tensorNames 的最大名称数量。当返回值是正值 n 且 tensorNames != nullptr 时,未充分指定的输入张量的名称将写入 tensorNames 中的 min(n,nbMaxNames) 个。
tensorNames用于放置未充分指定的输入张量的名称的缓冲区。
返回值
成功时为 0。如果 n 个输入张量未充分指定,则为正值 n。对于其他错误,则为 -1。

如果满足以下任一条件,则输入张量未充分指定

  • 它具有动态维度,并且其运行时维度尚未通过 IExecutionContext::setInputShape 指定。
  • isShapeInferenceIO(t)=true 且尚未设置张量的地址。

如果输出张量具有 isShapeInferenceIO(t)=true 且已指定其地址,则会写入其值。

如果 tensorNames == nullptr 且 nbMaxNames != 0,则返回 -1。如果 nbMaxNames < 0,则返回 -1。如果张量的维度无效,例如张量最终具有负维度,则返回 -1。

◆ reportToProfiler()

bool nvinfer1::IExecutionContext::reportToProfiler ( ) const
inlinenoexcept

IExecutionContext 中计算当前优化配置文件的层计时信息,并在一次推理启动后更新性能分析器。

如果 IExecutionContext::getEnqueueEmitsProfile() 返回 true,则如果提供了性能分析器,则入队函数将隐式计算层计时。此函数返回 true 且不执行任何操作。

如果 IExecutionContext::getEnqueueEmitsProfile() 返回 false,则如果提供了性能分析器,则入队函数将记录 CUDA 事件计时器。但它不会执行层计时计算。需要显式调用 IExecutionContext::reportToProfiler() 以计算上一次推理启动的层计时。

在 CUDA 图启动场景中,如果图是从启用了性能分析器的 IExecutionContext 捕获的,它将记录与常规入队函数中相同的一组 CUDA 事件。需要在图启动后调用此函数,以将层计时信息报告给性能分析器。

警告
仅从 CUDA 11.1 起提供分析 CUDA 图的功能。
reportToProfiler 使用上一次入队调用的流,因此流必须处于活动状态,否则行为未定义。
返回值
如果调用成功,则为 true,否则为 false(例如,未提供性能分析器,处于 CUDA 图捕获模式等)
另请参阅
IExecutionContext::setEnqueueEmitsProfile()
IExecutionContext::getEnqueueEmitsProfile()

◆ setAllTensorsDebugState()

bool nvinfer1::IExecutionContext::setAllTensorsDebugState ( bool  flag)
inlinenoexcept

打开或关闭所有调试张量的调试状态。

参数
flag如果打开调试状态,则为 true,如果关闭调试状态,则为 false。
返回值
如果成功,则为 true,否则为 false。

默认情况下为关闭。

◆ setAuxStreams()

void nvinfer1::IExecutionContext::setAuxStreams ( cudaStream_t *  auxStreams,
int32_t  nbStreams 
)
inlinenoexcept

设置 TensorRT 应在下一次 enqueueV3() 调用中在其上启动内核的辅助流。

如果已设置,TensorRT 将使用用户通过此 API 提供的流来启动本应在辅助流上运行的内核。如果在 enqueueV3() 调用之前未调用此 API,则 TensorRT 将使用 TensorRT 内部创建的辅助流。

TensorRT 将始终在通过 enqueueV3() 调用提供的主流和辅助流之间插入事件同步

  • enqueueV3() 调用的开始,TensorRT 将确保所有辅助流等待主流上的活动。
  • enqueueV3() 调用的结束,TensorRT 将确保主流等待所有辅助流上的活动。
参数
auxStreams指向 cudaStream_t 数组的指针,数组长度等于 nbStreams。
nbStreams提供的辅助流的数量。如果 nbStreams 大于 engine->getNbAuxStreams(),则只会使用前 engine->getNbAuxStreams() 个流。如果 nbStreams 小于 engine->getNbAuxStreams(),例如将 nbStreams 设置为 0,那么 TensorRT 将为前 nbStreams 个辅助流使用提供的流,并将内部创建额外的流用于其余的辅助流。
注意
提供的辅助流不能是默认流,并且必须全部不同,以避免死锁。
另请参阅
enqueueV3(), IBuilderConfig::setMaxAuxStreams(), ICudaEngine::getNbAuxStreams()

◆ setDebugListener()

bool nvinfer1::IExecutionContext::setDebugListener ( IDebugListener listener)
inlinenoexcept

为此执行上下文设置 DebugListener。

参数
listener此执行上下文的 DebugListener。
返回值
成功时为 true,失败时为 false。

◆ setDebugSync()

void nvinfer1::IExecutionContext::setDebugSync ( bool  sync)
inlinenoexcept

设置调试同步标志。

如果此标志设置为 true,引擎将在 executeV2() 期间记录每个内核的成功执行。当使用 enqueueV3() 时,它不起作用。

另请参阅
getDebugSync()

◆ setDeviceMemory()

void nvinfer1::IExecutionContext::setDeviceMemory ( void *  memory)
inlinenoexcept

为此执行上下文设置设备内存以供使用。

内存必须与 CUDA 内存对齐属性(使用 cudaGetDeviceProperties())对齐,并且其大小必须足够大,以便使用给定的网络输入执行推理。getDeviceMemorySize() 和 getDeviceMemorySizeForProfile() 报告大小的上限。如果报告的大小为 0,则可以将内存设置为 nullptr。如果使用 enqueueV3() 运行网络,则内存从调用 enqueueV3() 开始使用,直到网络执行完成。如果使用 executeV2(),则内存将一直使用到 executeV2() 返回。在此期间释放内存或将其用于其他目的,包括在并行运行的另一个执行上下文中使用它,将导致未定义的行为。

已弃用
在 TensorRT 10.1 中已弃用。已被 setDeviceMemoryV2() 取代。
警告
如果通过此 API 设置内存,TensorRT 将分配与权重流相关的暂存内存。请改用 setDeviceMemoryV2()
另请参阅
ICudaEngine::getDeviceMemorySize()
ICudaEngine::getDeviceMemorySizeForProfile()
ExecutionContextAllocationStrategy
ICudaEngine::createExecutionContext()
ICudaEngine::createExecutionContextWithoutDeviceMemory()

◆ setDeviceMemoryV2()

void nvinfer1::IExecutionContext::setDeviceMemoryV2 ( void *  memory,
int64_t  size 
)
inlinenoexcept

为此执行上下文设置设备内存及其对应的大小以供使用。

内存必须与 CUDA 内存对齐属性(使用 cudaGetDeviceProperties())对齐,并且其大小必须足够大,以便使用给定的网络输入执行推理。getDeviceMemorySize() 和 getDeviceMemorySizeForProfile() 报告大小的上限。如果报告的大小为 0,则可以将内存设置为 nullptr。如果使用 enqueueV3() 运行网络,则内存从调用 enqueueV3() 开始使用,直到网络执行完成。如果使用 executeV2(),则内存将一直使用到 executeV2() 返回。在此期间释放内存或将其用于其他目的,包括在并行运行的另一个执行上下文中使用它,将导致未定义的行为。

另请参阅
ICudaEngine::getDeviceMemorySizeV2()
ICudaEngine::getDeviceMemorySizeForProfileV2()
ExecutionContextAllocationStrategy
ICudaEngine::createExecutionContext()
ICudaEngine::createExecutionContextWithoutDeviceMemory()

◆ setEnqueueEmitsProfile()

void nvinfer1::IExecutionContext::setEnqueueEmitsProfile ( bool  enqueueEmitsProfile)
inlinenoexcept

设置 enqueue 是否向分析器发出层计时信息。

如果设置为 true(默认值),则 enqueue 是同步的,并且如果附加了分析器,则会隐式执行层计时分析。如果设置为 false,并且附加了分析器,则 enqueue 将是异步的。需要调用额外的方法 reportToProfiler() 以获取分析数据并报告给附加的分析器。

另请参阅
IExecutionContext::getEnqueueEmitsProfile()
IExecutionContext::reportToProfiler()

◆ setErrorRecorder()

void nvinfer1::IExecutionContext::setErrorRecorder ( IErrorRecorder recorder)
inlinenoexcept

为此接口设置 ErrorRecorder。

将 ErrorRecorder 分配给此接口。ErrorRecorder 将跟踪执行期间的所有错误。此函数将至少调用一次已注册的 ErrorRecorder 的 incRefCount。将 recorder 设置为 nullptr 将取消注册接口的记录器,如果已注册记录器,则会导致调用 decRefCount。

如果未设置错误记录器,消息将发送到全局日志流。

参数
recorder要在此接口中注册的错误记录器。
另请参阅
getErrorRecorder()

◆ setInputConsumedEvent()

bool nvinfer1::IExecutionContext::setInputConsumedEvent ( cudaEvent_t  event)
inlinenoexcept

标记输入为已消耗。

参数
event在所有输入张量都被消耗后触发的 CUDA 事件。
警告
设置的事件在推理期间必须有效。
返回值
成功时返回 True,发生错误时返回 false。

传递 event==nullptr 会移除已设置的任何事件(如果有)。

◆ setInputShape()

bool nvinfer1::IExecutionContext::setInputShape ( char const *  tensorName,
Dims const &  dims 
)
inlinenoexcept

设置给定输入的形状。

参数
tensorName输入张量的名称。
dims输入张量的形状。
返回值
成功时返回 True,如果提供的名称未映射到输入张量,或者发生其他错误,则返回 false。

除非后者为 -1,否则每个维度都必须与网络维度一致。

警告
字符串 tensorName 必须以 null 结尾,并且包括终止符在内最多为 4096 字节。

◆ setInputTensorAddress()

bool nvinfer1::IExecutionContext::setInputTensorAddress ( char const *  tensorName,
void const *  data 
)
inlinenoexcept

设置给定输入的内存地址。

参数
tensorName输入张量的名称。
data用户拥有的 const 数据的指针 (void const*)。
返回值
成功时返回 True,如果提供的名称未映射到输入张量、不满足对齐要求或发生其他错误,则返回 false。

也可以使用方法 setTensorAddress 设置输入地址,该方法需要 (void*)。

有关对齐和数据类型约束,请参阅方法 setTensorAddress() 的描述。

警告
字符串 tensorName 必须以 null 结尾,并且包括终止符在内最多为 4096 字节。
另请参阅
setTensorAddress()

◆ setName()

void nvinfer1::IExecutionContext::setName ( char const *  name)
inlinenoexcept

设置执行上下文的名称。

此方法复制名称字符串。

警告
字符串名称必须以 null 结尾,并且包括终止符在内最多为 4096 字节。
另请参阅
getName()

◆ setNvtxVerbosity()

bool nvinfer1::IExecutionContext::setNvtxVerbosity ( ProfilingVerbosity  verbosity)
inlinenoexcept

设置执行上下文中 NVTX 标记的详细程度。

以 kDETAILED 详细程度构建通常会增加 enqueueV3() 中的延迟。在运行时调用此方法以选择此执行上下文中的 NVTX 详细程度。

默认值是构建引擎时使用的详细程度,并且详细程度可能不会高于该级别。

此函数不影响 IEngineInspector 与引擎的交互方式。

参数
verbosityNVTX 标记的详细程度。
返回值
如果成功设置 NVTX 详细程度,则为 True。如果提供的详细程度级别高于相应引擎的分析详细程度,则为 False。
另请参阅
getNvtxVerbosity()
ICudaEngine::getProfilingVerbosity()

◆ setOptimizationProfileAsync()

bool nvinfer1::IExecutionContext::setOptimizationProfileAsync ( int32_t  profileIndex,
cudaStream_t  stream 
)
inlinenoexcept

使用异步语义为当前上下文选择优化配置文件。

参数
profileIndex配置文件的索引。该值必须介于 0 和 getEngine().getNbOptimizationProfiles() - 1 之间
stream可能在上面排队 cudaMemcpyAsync 的 CUDA 流

当通过此 API 切换优化配置文件时,TensorRT 可能需要通过 cudaMemcpyAsync 复制数据。应用程序有责任保证配置文件同步流和 enqueue 流之间发生同步。

所选配置文件将用于后续对 executeV2()/enqueueV3() 的调用。如果关联的 CUDA 引擎具有动态形状的输入,则在调用 execute 或 enqueue 之前,必须使用其对应的 profileIndex 设置优化配置文件。新创建的执行上下文将被分配优化配置文件 0。

如果关联的 CUDA 引擎没有具有动态形状的输入,则不需要调用此方法,在这种情况下,将使用默认配置文件索引 0。

在为所有动态输入张量或输入形状张量调用 setInputShape() 之前,必须调用 setOptimizationProfileAsync(),而 setInputShape() 又必须在 executeV2()/enqueueV3() 之前调用。

警告
此函数将在下次调用 executeV2()/enqueueV3() 时触发层资源更新,这可能会导致性能瓶颈。
不将 enqueue 时使用的流与使用此 API 异步设置优化配置文件时使用的流同步将导致未定义的行为。
返回值
如果调用成功,则为 true,否则为 false(例如,输入超出范围)
另请参阅
ICudaEngine::getNbOptimizationProfiles()

◆ setOutputAllocator()

bool nvinfer1::IExecutionContext::setOutputAllocator ( char const *  tensorName,
IOutputAllocator outputAllocator 
)
inlinenoexcept

设置用于给定名称的输出张量的输出分配器。传递 nullptr 给 outputAllocator 以取消设置。分配器由 enqueueV3() 调用。

参数
tensorName输出张量的名称。
outputAllocator张量的 IOutputAllocator
返回值
成功时返回 True,如果提供的名称未映射到输出,或者发生其他错误,则返回 false。
警告
字符串 tensorName 必须以 null 结尾,并且包括终止符在内最多为 4096 字节。
另请参阅
enqueueV3() IOutputAllocator

◆ setOutputTensorAddress()

bool nvinfer1::IExecutionContext::setOutputTensorAddress ( char const *  tensorName,
void *  data 
)
inlinenoexcept

为给定的输出张量设置内存地址。

参数
tensorName输出张量的名称。
data要将输出写入的缓冲区的指针。
返回值
成功时返回 True,如果提供的名称未映射到输出张量、不满足对齐要求或发生其他错误,则返回 false。

输出地址也可以使用方法 setTensorAddress 设置。提供此方法是为了方便应用程序喜欢使用不同的方法来设置输入和输出张量。

有关对齐和数据类型约束,请参阅 setTensorAddress()

警告
字符串 tensorName 必须以 null 结尾,并且包括终止符在内最多为 4096 字节。
另请参阅
setTensorAddress()

◆ setPersistentCacheLimit()

void nvinfer1::IExecutionContext::setPersistentCacheLimit ( size_t  size)
inlinenoexcept

设置持久缓存使用的最大大小。

此函数设置此执行上下文可能用于激活缓存的最大持久 L2 缓存。并非所有架构都支持激活缓存 - 有关详细信息,请参阅开发者指南中的“TensorRT 如何使用内存”

参数
size持久缓存限制的大小(以字节为单位)。默认值为 0 字节。
另请参阅
getPersistentCacheLimit

◆ setProfiler()

void nvinfer1::IExecutionContext::setProfiler ( IProfiler profiler)
inlinenoexcept

设置分析器。

另请参阅
IProfiler getProfiler()

◆ setTemporaryStorageAllocator()

bool nvinfer1::IExecutionContext::setTemporaryStorageAllocator ( IGpuAllocator allocator)
inlinenoexcept

指定用于内部临时存储的分配器。

此分配器仅由 enqueueV3() 用于大小无法在 enqueueV3() 之前预测的临时存储。它不用于输出张量,因为这些张量的内存分配由 setOutputAllocator() 设置的分配器分配。所有分配的内存都在 enqueueV3() 返回时释放。

参数
allocator要使用的分配器的指针。传递 nullptr 以恢复为使用 TensorRT 的默认分配器。
返回值
成功时返回 True,发生错误时返回 false。
另请参阅
enqueueV3() setOutputAllocator()

◆ setTensorAddress()

bool nvinfer1::IExecutionContext::setTensorAddress ( char const *  tensorName,
void *  data 
)
inlinenoexcept

设置给定输入或输出张量的内存地址。

参数
tensorName输入或输出张量的名称。
data用户拥有的数据指针 (void*)。
返回值
成功时返回 True,发生错误时返回 false。

地址默认为 nullptr。传递 data=nullptr 以重置为默认状态。

如果提供的名称未映射到输入或输出张量,则返回 false。

如果输入指针的类型为 (void const*),请改用 setInputTensorAddress()

在调用 enqueueV3() 之前,每个输入都必须具有非空地址,并且每个输出都必须具有非空地址或 IOutputAllocator 以稍后设置它。

如果张量的 TensorLocation 为 kHOST

  • 指针必须指向足够大小的主机缓冲区。
  • 表示形状值的数据直到调用 enqueueV3 时才会被复制。

如果张量的 TensorLocation 为 kDEVICE

  • 指针必须指向足够大小和对齐的设备缓冲区,或
  • 如果张量是输出张量,将由 IOutputAllocator 分配,则为 nullptr。

如果在设置所有输入形状后,getTensorShape(name) 报告输出的任何维度为 -1,请使用 setOutputAllocator() 以关联一个 IOutputAllocator,已知维度时将报告给它。

允许为同一输出同时调用 setTensorAddress 和 setOutputAllocator(),并且对于预分配内存,然后在内存不够大时重新分配内存可能很有用。

指针必须至少具有 256 字节的对齐。

警告
字符串 tensorName 必须以 null 结尾,并且包括终止符在内最多为 4096 字节。
另请参阅
setInputTensorAddress() setOutputTensorAddress() getTensorShape() setOutputAllocator() IOutputAllocator

◆ setTensorDebugState()

bool nvinfer1::IExecutionContext::setTensorDebugState ( char const *  name,
bool  flag 
)
inlinenoexcept

设置给定张量的调试状态,指定张量名称。

打开或关闭张量的调试状态。具有参数张量名称的张量必须存在于网络中,并且该张量必须在构建时标记为调试张量。否则,将抛出错误。

参数
name目标张量的名称。
flagTrue 表示打开调试状态,false 表示关闭张量的调试状态。默认值为关闭。
返回值
成功时返回 True,否则返回 false。

◆ updateDeviceMemorySizeForShapes()

size_t nvinfer1::IExecutionContext::updateDeviceMemorySizeForShapes ( )
inlinenoexcept

根据当前的输入形状重新计算内部激活缓冲区大小,并返回所需的总内存量。

用户可以根据返回的大小分配设备内存,并使用 IExecutionContext::setDeviceMemory() 将内存提供给 TRT。必须在调用此函数之前指定所有输入形状和要使用的优化配置文件,否则分区将失效。

返回值
成功时返回所需的总内存量,如果发生错误,则返回 0。
另请参阅
IExecutionContext::setDeviceMemory()

成员数据文档

◆ mImpl

apiv::VExecutionContext* nvinfer1::IExecutionContext::mImpl
protected

此类文档从以下文件生成

  版权所有 © 2024 NVIDIA Corporation
  隐私政策 | 管理我的隐私 | 请勿出售或分享我的数据 | 服务条款 | 无障碍访问 | 公司政策 | 产品安全 | 联系我们