Tensor Registry#
-
class TensorRegistry#
Central registry of all tensor specs needed by a TRT engine.
TensorRegistry holds tensor specs with symbolic shape templates.
bindAll()resolves all shapes from InferenceDims and callssetTensorAddress+setInputShapein a single pass, replacing many manual binding calls. Per-layer tensors (e.g. KV cache) are auto-expanded fromdtemplates.Public Functions
-
void addTensor(TensorSpec spec)#
Add a tensor specification to the registry.
- Parameters:
spec – The tensor specification to add
- bool bindAll(
- nvinfer1::IExecutionContext *ctx,
- TensorMap const &tensorMap,
- InferenceDims const &inferenceDims
Bind all registered tensors to a TRT execution context.
Resolves symbolic shapes from
inferenceDims, then callssetTensorAddressand (for inputs)setInputShapeon each tensor.- Parameters:
ctx – TRT execution context
tensorMap – Name-to-tensor mapping
inferenceDims – Current symbolic dimension values
- Returns:
True if all tensors were bound successfully
- std::vector<int64_t InferenceDims::*> const &referencedMembers(
Return the set of
InferenceDimsmembers referenced by any symbolicShapeDimin the registry.Used by
EngineExecutor::prepareto restrict its field-completeness assertion to dims the engine actually consumes. Computed once (lazily) when the expanded spec set is materialized; cached across calls.- Returns:
Vector of
int64_t InferenceDims::*— deduplicated
-
std::vector<std::string> allTensorNames() const#
Return all tensor names after per-layer expansion.
- Returns:
Vector of concrete tensor names
-
bool contains(std::string_view name) const#
Test whether a tensor name is registered (post-expansion).
Used by
EngineExecutor::prepareto skip the registry-managed bindings in its fall-back loop: those are already covered bybindAll, so re-binding them via the tensor map’s actual TRTDims would override the registry-computed shape.- Parameters:
name – Concrete tensor name (after
dexpansion if applicable)- Returns:
True if the registry has a spec for
name
-
std::vector<TensorSpec> const &allExpandedSpecs() const#
Return all tensor specs after per-layer expansion.
- Returns:
Vector of expanded TensorSpec objects
- nvinfer1::Dims resolveShape(
- std::vector<ShapeDim> const &shape,
- InferenceDims const &inferenceDims
Resolve a shape template into concrete TRT Dims.
Fixed dimensions are used as-is. Symbolic dimensions are looked up from
inferenceDims.- Parameters:
shape – Shape template with fixed and/or symbolic dims
inferenceDims – Current symbolic dimension values
- Returns:
Resolved TRT Dims
-
void addTensor(TensorSpec spec)#
-
struct TensorSpec#
Declarative specification for a single tensor binding.
Per-layer tensors use a printf-style
dplaceholder in the name and a positiveperLayercount; the registry expands these into concrete specs at query time.