|
6 | 6 | from torch_tensorrt.dynamo.utils import input_is_dynamic, unwrap_tensor_shape |
7 | 7 |
|
8 | 8 |
|
| 9 | +@torch.library.register_fake("aten::cudnn_grid_sampler") # type: ignore |
| 10 | +def fake_aten_cudnn_grid_sampler( |
| 11 | + input: torch.Tensor, |
| 12 | + grid: torch.Tensor, |
| 13 | + interpolation_mode: int = 0, |
| 14 | + padding_mode: int = 0, |
| 15 | + align_corners: bool = True, |
| 16 | +) -> torch.Tensor: |
| 17 | + """ |
| 18 | + Meta kernel for aten::cudnn_grid_sampler to enable FakeTensor/compile flows. |
| 19 | + Shapes follow grid_sampler semantics: |
| 20 | + - 2D: input [N, C, H_in, W_in], grid [N, H_out, W_out, 2] -> output [N, C, H_out, W_out] |
| 21 | + - 3D: input [N, C, D_in, H_in, W_in], grid [N, D_out, H_out, W_out, 3] -> output [N, C, D_out, H_out, W_out] |
| 22 | + """ |
| 23 | + if grid.dim() == 4: |
| 24 | + n, h_out, w_out, _ = grid.shape |
| 25 | + c = input.shape[1] |
| 26 | + out_shape = [n, c, h_out, w_out] |
| 27 | + elif grid.dim() == 5: |
| 28 | + n, d_out, h_out, w_out, _ = grid.shape |
| 29 | + c = input.shape[1] |
| 30 | + out_shape = [n, c, d_out, h_out, w_out] |
| 31 | + else: |
| 32 | + raise RuntimeError( |
| 33 | + f"aten::cudnn_grid_sampler: unexpected grid rank {grid.dim()}" |
| 34 | + ) |
| 35 | + return torch.empty(out_shape, dtype=input.dtype, device=input.device) |
| 36 | + |
| 37 | + |
9 | 38 | @torch.library.register_fake("tensorrt::execute_engine") # type: ignore |
10 | 39 | def fake_tensorrt_execute_engine( |
11 | 40 | inputs: List[torch.Tensor], fake_trt_engine: Any |
|
0 commit comments