Skip to content

Commit bf2103d

Browse files
YufengShi-duduper
andauthored
Arm backend: Fuse canonical flow-offset grid sampling (pytorch#21775)
Recognize grid_sample calls that add a two-channel flow slice to an align-corners base grid: base_grid ---------\ add -> permute -> grid_sample(image, grid) flow[:, i:i+2] ----/ Replace the complete expression with: image, flow -> fused flow-offset custom shader This avoids materializing the normalized sampling grid at runtime. Require SNORM-compatible image and output quantization ranges. Vulkan's signed normalized 8-bit image format maps both -128 and -127 to -1.0, so only fuse tensors using the range [-127, 127]. The flow tensor keeps the full int8 range because the shader reads it directly as a tensor. If glslc is unavailable or compilation fails, leave the graph unchanged for generic grid-sampler lowering. Cover supported rewrites, invalid patterns, SNORM ranges, and compiler fallback behavior. Authored with Codex. Change-Id: Ia19b4387c169bd24f8db837a5bfee7c91d4e55ce cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @rascani Signed-off-by: Yufeng Shi <yufeng.shi@arm.com> Co-authored-by: Per Åstrand <per.astrand@arm.com>
1 parent 8de0262 commit bf2103d

7 files changed

Lines changed: 1295 additions & 4 deletions

File tree

‎backends/arm/BUCK‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ fbcode_target(
9696
srcs = [
9797
"vgf/__init__.py",
9898
"vgf/_passes/__init__.py",
99+
"vgf/_passes/fuse_grid_sampler_flow_offset.py",
99100
"vgf/_passes/insert_grid_sampler_grid_dequant_pass.py",
100101
"vgf/_passes/rewrite_grid_sampler_to_tosa_custom.py",
101102
"vgf/backend.py",
@@ -107,6 +108,7 @@ fbcode_target(
107108
"vgf/shaders/grid_sampler.py",
108109
],
109110
resources = [
111+
"vgf/shaders/flow_offset_grid_sampler_int8_align_corners.glsl",
110112
"vgf/shaders/grid_sampler.glsl",
111113
"vgf/shaders/grid_sampler.spirv.b64",
112114
"vgf/shaders/grid_sampler_sampler.glsl",

0 commit comments

Comments
 (0)