|
| 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/ops/impl/utils/KernelUtils.h> |
| 12 | +#include <executorch/backends/vulkan/runtime/graph/ops/impl/utils/TensorUtils.h> |
| 13 | + |
| 14 | +#include <executorch/backends/vulkan/runtime/graph/ops/utils/ShaderNameUtils.h> |
| 15 | + |
| 16 | +namespace vkcompute { |
| 17 | + |
| 18 | +void resize_full_node( |
| 19 | + ComputeGraph* graph, |
| 20 | + const std::vector<ArgGroup>& args, |
| 21 | + const std::vector<ValueRef>& extra_args) { |
| 22 | + vTensorPtr out = graph->get_tensor(args[0].refs[0]); |
| 23 | + std::vector<int64_t> out_sizes = *graph->get_int_list(extra_args[0]); |
| 24 | + |
| 25 | + out->virtual_resize(out_sizes); |
| 26 | +} |
| 27 | + |
| 28 | +void add_full_node( |
| 29 | + ComputeGraph& graph, |
| 30 | + const ValueRef size, |
| 31 | + const ValueRef fill_value, |
| 32 | + const ValueRef out) { |
| 33 | + float fill_value_val = graph.extract_scalar<float>(fill_value); |
| 34 | + vTensorPtr t_out = graph.get_tensor(out); |
| 35 | + |
| 36 | + api::utils::uvec3 global_size = t_out->extents(); |
| 37 | + api::utils::uvec3 local_size = adaptive_work_group_size(global_size); |
| 38 | + |
| 39 | + std::string kernel_name("full"); |
| 40 | + kernel_name.reserve(kShaderNameReserve); |
| 41 | + |
| 42 | + add_dtype_suffix(kernel_name, *t_out); |
| 43 | + |
| 44 | + graph.execute_nodes().emplace_back(new ExecuteNode( |
| 45 | + graph, |
| 46 | + VK_KERNEL_FROM_STR(kernel_name), |
| 47 | + global_size, |
| 48 | + local_size, |
| 49 | + // Inputs and Outputs |
| 50 | + {{out, api::MemoryAccessType::WRITE}}, |
| 51 | + // Shader params buffers |
| 52 | + {t_out->gpu_sizes_ubo(), |
| 53 | + t_out->cpu_sizes_ubo(), |
| 54 | + graph.create_params_buffer(fill_value_val)}, |
| 55 | + // Resizing |
| 56 | + resize_full_node, |
| 57 | + {size})); |
| 58 | +} |
| 59 | + |
| 60 | +void full(ComputeGraph& graph, const std::vector<ValueRef>& args) { |
| 61 | + return add_full_node(graph, args[0], args[1], args[6]); |
| 62 | +} |
| 63 | + |
| 64 | +REGISTER_OPERATORS { |
| 65 | + VK_REGISTER_OP(aten.full.default, full); |
| 66 | +} |
| 67 | + |
| 68 | +} // namespace vkcompute |
0 commit comments