|
| 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/vulkan/runtime/graph/ops/OperatorRegistry.h> |
| 10 | + |
| 11 | +#include <executorch/backends/vulkan/runtime/graph/Logging.h> |
| 12 | + |
| 13 | +#include <executorch/backends/vulkan/runtime/graph/ops/impl/utils/KernelUtils.h> |
| 14 | +#include <executorch/backends/vulkan/runtime/graph/ops/impl/utils/TensorUtils.h> |
| 15 | +#include <executorch/backends/vulkan/runtime/graph/ops/utils/ShaderNameUtils.h> |
| 16 | + |
| 17 | +namespace vkcompute { |
| 18 | + |
| 19 | +void add_clone_node( |
| 20 | + ComputeGraph& graph, |
| 21 | + const ValueRef in, |
| 22 | + const ValueRef out) { |
| 23 | + vTensorPtr t_out = graph.get_tensor(out); |
| 24 | + |
| 25 | + std::string kernel_name = "clone"; |
| 26 | + add_dtype_suffix(kernel_name, *t_out); |
| 27 | + |
| 28 | + api::utils::uvec3 global_size = t_out->extents(); |
| 29 | + api::utils::uvec3 local_size = adaptive_work_group_size(global_size); |
| 30 | + |
| 31 | + graph.execute_nodes().emplace_back(new ExecuteNode( |
| 32 | + graph, |
| 33 | + VK_KERNEL_FROM_STR(kernel_name), |
| 34 | + global_size, |
| 35 | + local_size, |
| 36 | + {{out, api::MemoryAccessType::WRITE}, {in, api::MemoryAccessType::READ}}, |
| 37 | + {t_out->texture_limits_ubo()})); |
| 38 | +} |
| 39 | + |
| 40 | +void clone(ComputeGraph& graph, const std::vector<ValueRef>& args) { |
| 41 | + // The vulkan delegate does not support changing memory format. |
| 42 | + return add_clone_node(graph, args[0], args[2]); |
| 43 | +} |
| 44 | + |
| 45 | +// Clone node is not the most efficient implementation for the aten.clone |
| 46 | +// operation. A more efficient implementation can be achieved during vulkan |
| 47 | +// export with the use of shared object. This clone node is introduced to enable |
| 48 | +// a "copy" mechanism if there is no alternative (e.g. during direct |
| 49 | +// ComputeGraph manipulation, we need to make a copy of a Tensor). |
| 50 | + |
| 51 | +REGISTER_OPERATORS { |
| 52 | + VK_REGISTER_OP(aten.clone.default, clone); |
| 53 | +} |
| 54 | + |
| 55 | +} // namespace vkcompute |
0 commit comments