Skip to content

ExecuTorch CUDA graph replay stops replaying when buffers move and shapes change often #4991

Open

Description

@shoumikhin

Description

With #4983 (not merged yet), the ExecuTorch TensorRT delegate can replay a CUDA graph directly on the caller's buffers. When the caller passes different buffer addresses on every call, the delegate notices that the buffers keep moving and switches to copying them through its own staging buffers.

That learned state is reset every time the input shapes change. So each new set of shapes takes about 3 graph recordings before the first replay, where main needs 1. If the shapes change every 3 or 4 calls, it never replays: in one run of 24 calls it recorded 16 to 18 times and replayed 0 times, where main recorded 6 to 8 times and replayed 8 to 12 times. The outputs stay correct; only the speed is affected.

In a small benchmark of the replay code, with a stub in place of the TensorRT engine, that pattern cost 55 to 63 microseconds per call, against 37 to 39 on main. Callers with fixed buffers are not affected. Callers with moving buffers but fixed shapes pay the 2 extra recordings once, at the start.

To Reproduce

  1. Load a program with the TensorRT delegate and CUDA graph replay on.
  2. Call it with freshly allocated input and output buffers on every call.
  3. Change the input shapes every 3 or 4 calls.
  4. Count graph recordings per call, or time the calls.

Expected behavior

Once the delegate has seen that a caller's buffers move, it keeps that knowledge across shape changes. Then only the first set of shapes pays the extra recordings.

Environment

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions