|
| 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/api/api.h> |
| 12 | +#include <executorch/backends/vulkan/runtime/graph/Logging.h> |
| 13 | + |
| 14 | +#include <executorch/backends/vulkan/runtime/graph/ops/impl/utils/KernelUtils.h> |
| 15 | +#include <executorch/backends/vulkan/runtime/graph/ops/impl/utils/TensorUtils.h> |
| 16 | +#include <executorch/backends/vulkan/runtime/graph/ops/utils/ShaderNameUtils.h> |
| 17 | + |
| 18 | +#include <iostream> |
| 19 | + |
| 20 | +namespace vkcompute { |
| 21 | + |
| 22 | +void add_copy_offset_node( |
| 23 | + ComputeGraph& graph, |
| 24 | + const ValueRef in, |
| 25 | + const api::utils::ivec3& range, |
| 26 | + const api::utils::ivec3& src_offset, |
| 27 | + const api::utils::ivec3& dst_offset, |
| 28 | + const ValueRef out) { |
| 29 | + vTensorPtr t_in = graph.get_tensor(in); |
| 30 | + vTensorPtr t_out = graph.get_tensor(out); |
| 31 | + |
| 32 | + VK_CHECK_COND(check_memory_layout_is(*t_in, api::kChannelsPacked)); |
| 33 | + VK_CHECK_COND(check_memory_layout_is(*t_out, api::kChannelsPacked)); |
| 34 | + |
| 35 | + std::string kernel_name = "copy_offset"; |
| 36 | + kernel_name.reserve(kShaderNameReserve); |
| 37 | + add_dtype_suffix(kernel_name, *t_out); |
| 38 | + |
| 39 | + api::utils::uvec3 global_size = api::utils::make_uvec3(range); |
| 40 | + api::utils::uvec3 local_size = adaptive_work_group_size(global_size); |
| 41 | + |
| 42 | + const struct Block final { |
| 43 | + api::utils::ivec3 range; |
| 44 | + int32_t unused0; |
| 45 | + api::utils::ivec3 src_offset; |
| 46 | + int32_t unused1; |
| 47 | + api::utils::ivec3 dst_offset; |
| 48 | + int32_t unused2; |
| 49 | + } offset_params{ |
| 50 | + range, |
| 51 | + 0, |
| 52 | + src_offset, |
| 53 | + 0, |
| 54 | + dst_offset, |
| 55 | + 0, |
| 56 | + }; |
| 57 | + |
| 58 | + auto shader = VK_KERNEL_FROM_STR(kernel_name); |
| 59 | + |
| 60 | + graph.execute_nodes().emplace_back(new ExecuteNode( |
| 61 | + graph, |
| 62 | + VK_KERNEL_FROM_STR(kernel_name), |
| 63 | + global_size, |
| 64 | + local_size, |
| 65 | + // Inputs and Outputs |
| 66 | + {{out, api::MemoryAccessType::WRITE}, {in, api::MemoryAccessType::READ}}, |
| 67 | + // Parameter buffers |
| 68 | + {t_out->texture_limits_ubo(), |
| 69 | + t_in->texture_limits_ubo(), |
| 70 | + graph.create_params_buffer(offset_params)}, |
| 71 | + // Specialization Constants |
| 72 | + {})); |
| 73 | +} |
| 74 | + |
| 75 | +} // namespace vkcompute |
0 commit comments