Skip to content

Commit 99debc1

Browse files
[ExecuTorch][WebGPU] Add squeeze_copy + unsqueeze_copy (flat copies)
Pull Request resolved: #20392 Adds `aten.squeeze_copy.dims` and `aten.unsqueeze_copy.default` to the WebGPU delegate. Both are numel-preserving shape ops; on a dense row-major buffer backend they are the same flat copy as `view_copy` — only the shape metadata differs (mirrors the Vulkan delegate, which routes both through `add_view_copy_node`). Composition (no new kernel): - `squeeze/Squeeze.cpp` — reads `args = [self, dims, out]`, ignores the AOT-fixed `dims`, calls `add_flat_copy(graph, in, out)` from `runtime/ops/view_copy/view_copy.h`. - `unsqueeze/Unsqueeze.cpp` — reads `args = [self, dim, out]`, ignores the AOT-fixed `dim`, calls `add_flat_copy(graph, in, out)`. ghstack-source-id: 397026523 @exported-using-ghexport Differential Revision: [D108793153](https://our.internmc.facebook.com/intern/diff/D108793153/)
1 parent 028c3c8 commit 99debc1

3 files changed

Lines changed: 64 additions & 0 deletions

File tree

backends/webgpu/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ set(WEBGPU_SRCS
4545
runtime/ops/view_copy/ViewCopy.cpp
4646
runtime/ops/select/Select.cpp
4747
runtime/ops/sigmoid/UnaryOp.cpp
48+
runtime/ops/squeeze/Squeeze.cpp
49+
runtime/ops/unsqueeze/Unsqueeze.cpp
4850
)
4951

5052
add_library(webgpu_backend ${WEBGPU_SRCS})
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
#include <executorch/backends/webgpu/runtime/WebGPUGraph.h>
10+
#include <executorch/backends/webgpu/runtime/ops/OperatorRegistry.h>
11+
#include <executorch/backends/webgpu/runtime/ops/view_copy/view_copy.h>
12+
13+
#include <vector>
14+
15+
namespace executorch::backends::webgpu {
16+
17+
namespace {
18+
19+
// squeeze_copy.dims = numel-preserving flat copy (Vulkan Squeeze.cpp:102-104).
20+
void squeeze_copy_dims_impl(WebGPUGraph& graph, const std::vector<int>& args) {
21+
// args: [self, dims, out]; dims ignored (out shape fixed AOT).
22+
add_flat_copy(graph, args.at(0), args.at(args.size() - 1));
23+
}
24+
25+
} // namespace
26+
27+
WEBGPU_REGISTER_OPERATORS {
28+
WEBGPU_REGISTER_OP(aten.squeeze_copy.dims, squeeze_copy_dims_impl);
29+
}
30+
31+
} // namespace executorch::backends::webgpu
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
#include <executorch/backends/webgpu/runtime/WebGPUGraph.h>
10+
#include <executorch/backends/webgpu/runtime/ops/OperatorRegistry.h>
11+
#include <executorch/backends/webgpu/runtime/ops/view_copy/view_copy.h>
12+
13+
#include <vector>
14+
15+
namespace executorch::backends::webgpu {
16+
17+
namespace {
18+
19+
// unsqueeze_copy = numel-preserving flat copy (Vulkan Unsqueeze.cpp:101-103).
20+
void unsqueeze_copy_impl(WebGPUGraph& graph, const std::vector<int>& args) {
21+
// args: [self, dim, out]; dim ignored (out shape fixed AOT, like view_copy).
22+
add_flat_copy(graph, args.at(0), args.at(args.size() - 1));
23+
}
24+
25+
} // namespace
26+
27+
WEBGPU_REGISTER_OPERATORS {
28+
WEBGPU_REGISTER_OP(aten.unsqueeze_copy.default, unsqueeze_copy_impl);
29+
}
30+
31+
} // namespace executorch::backends::webgpu

0 commit comments

Comments
 (0)