-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement aten.squeeze_copy.dims (#4223)
Summary: Pull Request resolved: #4223 Implement aten.squeeze_copy.dims operator This op is compiled from `torch.squeeze(x, dims=0)`. bypass-github-export-checks bypass-github-pytorch-ci-checks bypass-github-executorch-ci-checks Reviewed By: jorgep31415 Differential Revision: D59605342 fbshipit-source-id: 2acabe080360875937e4e48d427d6cc7fae802ff
- Loading branch information
1 parent
9221ab6
commit 7047162
Showing
6 changed files
with
125 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <executorch/backends/vulkan/runtime/api/api.h> | ||
|
||
#include <executorch/backends/vulkan/runtime/graph/ComputeGraph.h> | ||
|
||
namespace vkcompute { | ||
|
||
void add_clone_node(ComputeGraph& graph, const ValueRef in, const ValueRef out); | ||
|
||
} // namespace vkcompute |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include <executorch/backends/vulkan/runtime/graph/ops/OperatorRegistry.h> | ||
|
||
#include <executorch/backends/vulkan/runtime/graph/ops/impl/Clone.h> | ||
#include <executorch/backends/vulkan/runtime/graph/ops/impl/Permute.h> | ||
#include <executorch/backends/vulkan/runtime/graph/ops/impl/utils/KernelUtils.h> | ||
#include <executorch/backends/vulkan/runtime/graph/ops/utils/ShaderNameUtils.h> | ||
|
||
namespace vkcompute { | ||
|
||
void add_squeeze_copy_dims_node( | ||
ComputeGraph& graph, | ||
ValueRef in, | ||
ValueRef dims_ref, | ||
ValueRef out) { | ||
vTensorPtr t_in = graph.get_tensor(in); | ||
vTensorPtr t_out = graph.get_tensor(out); | ||
|
||
IntListPtr dims = graph.get_int_list(dims_ref); | ||
std::vector<int64_t> squeeze_dims; | ||
// Filter out edge cases that we don't need squeeze: | ||
// 1. The size of squeeze dim is larger than 1. | ||
// 2. Squeeze outter most dim | ||
// For these cases, just pass input to output via clone. | ||
for (int i = 0; i < dims->size(); ++i) { | ||
if (dims->at(i) != 0 && t_in->sizes().at(dims->at(i)) == 1) { | ||
squeeze_dims.push_back(dims->at(i)); | ||
} | ||
} | ||
if (squeeze_dims.size() == 0) { | ||
add_clone_node(graph, in, out); | ||
} else { | ||
std::vector<int64_t> permute_dims(t_in->dim()); | ||
for (int i = 0; i < t_in->dim(); ++i) { | ||
permute_dims.at(i) = i; | ||
} | ||
for (auto& elem : squeeze_dims) { | ||
auto it = std::find(permute_dims.begin(), permute_dims.end(), elem); | ||
VK_CHECK_COND( | ||
it != permute_dims.end(), "Squeeze dim not found in permute_dims"); | ||
std::rotate(permute_dims.begin(), it, it + 1); | ||
} | ||
|
||
add_permute_node(graph, in, permute_dims, out); | ||
} | ||
} | ||
|
||
void squeeze_copy_dims(ComputeGraph& graph, const std::vector<ValueRef>& args) { | ||
return add_squeeze_copy_dims_node(graph, args[0], args[1], args[2]); | ||
} | ||
|
||
REGISTER_OPERATORS { | ||
VK_REGISTER_OP(aten.squeeze_copy.dims, squeeze_copy_dims); | ||
} | ||
|
||
} // namespace vkcompute |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters