-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Implement aten._to_copy. Currently we are only interested in fp32 <-> fp16 conversions, but it should theoritically support other dtype conversions too. I noticed an issue with int conversions so limited it to just fp32 and fp16 for now. Note: Most driver implementations of fp16 cast does not "round up" the result, therefore there might be 1 bit difference between vulkan output and cpu torch.to. Explained in greater detail in the comments. Differential Revision: D64080303
- Loading branch information
1 parent
f41ed5d
commit c2297a5
Showing
3 changed files
with
150 additions
and
0 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,48 @@ | ||
/* | ||
* 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/BlitNode.h> | ||
#include <executorch/backends/vulkan/runtime/graph/ops/OperatorRegistry.h> | ||
#include <executorch/backends/vulkan/runtime/graph/ops/impl/Staging.h> | ||
#include <executorch/backends/vulkan/runtime/graph/ops/utils/ShaderNameUtils.h> | ||
#include <set> | ||
|
||
namespace vkcompute { | ||
|
||
void resize_to_copy_op_node( | ||
ComputeGraph* graph, | ||
const std::vector<ArgGroup>& args, | ||
const std::vector<ValueRef>& extra_args) { | ||
(void)extra_args; | ||
vTensorPtr out = graph->get_tensor(args[0].refs[0]); | ||
vTensorPtr self = graph->get_tensor(args[1].refs[0]); | ||
|
||
out->virtual_resize(self->sizes()); | ||
} | ||
|
||
void add_to_copy_node(ComputeGraph& graph, ValueRef in, ValueRef out) { | ||
ValueRef arg = prepack_if_tensor_ref(graph, in); | ||
vTensorPtr t_in = graph.get_tensor(in); | ||
vTensorPtr t_out = graph.get_tensor(out); | ||
std::set<vkapi::ScalarType> supported_types = { | ||
vkapi::ScalarType::Float, vkapi::ScalarType::Half}; | ||
VK_CHECK_COND( | ||
supported_types.find(t_in->dtype()) != supported_types.end() && | ||
supported_types.find(t_out->dtype()) != supported_types.end(), | ||
"Unsupported dtype for to_copy, only Float and Half are currently supported"); | ||
graph.execute_nodes().emplace_back(new BlitNode(graph, arg, out)); | ||
} | ||
|
||
void to_copy(ComputeGraph& graph, const std::vector<ValueRef>& args) { | ||
return add_to_copy_node(graph, args[0], args[7]); | ||
} | ||
|
||
REGISTER_OPERATORS { | ||
VK_REGISTER_OP(aten._to_copy.default, to_copy); | ||
} | ||
} // 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