Skip to content

Execution context management for TensorRT profiles - #36664

Merged
tensorflow-copybara merged 12 commits into
tensorflow:masterfrom
tfeher:trt_engine_context_management
Feb 21, 2020
Merged

tensorflow-copybara merged 12 commits into
tensorflow:masterfrom
tfeher:trt_engine_context_management

Conversation

@tfeher

@tfeher tfeher commented Feb 11, 2020 •

Copy link
Copy Markdown
Contributor

This PR adds a mechanism to handle multiple execution context for a TensorRT engine, which is a step towards enabling dynamic shape mode with multiple profiles.

This PR is not expected to change any existing behavior: inference in implicit batch mode, in explicit batch and in dynamic shapes mode remains the same.

What changes is the engine lookup. Until now the EngineContext object contained a reference to a singe ICudaEngine and a corresponding IExecutionContext. We plan to have one execution context for each profile, therefore we introduce a vector of IExecutionContexts in EngineContext.

Correspondingly the GetEngine function changes: it does not only return the pointer to the EngineContext but also gives the indexd of the IExecutionContext that can be used for inference.

An alternative method for handling multiple profiles would be to keep a single IExecutionContext, and switch profile before we enqueue the new inference task. This could lead to problems with asynchronous inference, because we would need to ensure there are "no enqueued operations pending in the context prior to switching profiles".

Dynamic shape mode is an experimental feature. The advantage of dynamic shapes is that we can use a single engine with multiple profiles to handle input data with different shapes. This saves memory: all input profiles for an engine can share the same weights. Input dimensions that do not influence the number of model parameters can be dynamic (batch size, sequence length, even image dimensions for fully convolutional networks). A single profile can handle a range of input parameters, or we could have multiple profiles each optimized for a certain input shape (e.g. one profile for each expected batch size).

Although this PR implements the mechanism to handle multiple profiles and the corresponding execution contexts, one still needs a method to define these profiles. Such profile generation feature is implemented in PR #36729.

@tensorflow-bot tensorflow-bot Bot added the size:XL CL Change Size:Extra Large label Feb 11, 2020
@tfeher
tfeher requested a review from bixia1 February 11, 2020 15:12
@gbaned gbaned self-assigned this Feb 12, 2020
@gbaned gbaned added the comp:gpu:tensorrt Issues specific to TensorRT label Feb 12, 2020
@gbaned

gbaned commented Feb 12, 2020

Copy link
Copy Markdown
Contributor

@tfeher Can you please resolve conflicts? Thanks!

@gbaned

gbaned commented Feb 19, 2020

Copy link
Copy Markdown
Contributor

@tfeher Still, conflicts are appearing. Can you please resolve? Thanks!

@gbaned gbaned added the stat:awaiting response Status - Awaiting response from author label Feb 19, 2020

@tfeher tfeher left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @bixia1, thank you for the review, I have addressed the issues.

@bixia1 bixia1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please resolve conflicts.

@bixia1 bixia1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved it for further testing.

@tensorflow-bot tensorflow-bot Bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Feb 21, 2020
@kokoro-team kokoro-team removed kokoro:force-run Tests on submitted change labels Feb 21, 2020
@tensorflow-copybara
tensorflow-copybara merged commit d7b846b into tensorflow:master Feb 21, 2020
@gbaned gbaned removed the stat:awaiting response Status - Awaiting response from author label Feb 24, 2020
@tfeher
tfeher deleted the trt_engine_context_management branch May 16, 2022 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes comp:gpu:tensorrt Issues specific to TensorRT ready to pull PR ready for merge process size:XL CL Change Size:Extra Large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants