Giorgio Arena | 232c452 | 2022-03-03 10:09:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2022 Arm Limited. |
| 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #if defined(ENABLE_EXPERIMENTAL_DYNAMIC_FUSION) |
| 25 | |
| 26 | #include "src/core/experimental/dynamic_fusion/ClKernelBuildingImpl/components/ClElementwiseAddKernelComponent.h" |
| 27 | |
| 28 | namespace arm_compute |
| 29 | { |
| 30 | namespace experimental |
| 31 | { |
| 32 | namespace dynamic_fusion |
| 33 | { |
| 34 | ComponentType ClElementwiseAddKernelComponent::get_component_type() const |
| 35 | { |
| 36 | return ComponentType::Simple; |
| 37 | } |
| 38 | |
| 39 | std::set<std::string> ClElementwiseAddKernelComponent::get_headers_list() const |
| 40 | { |
| 41 | return std::set<std::string> { "gemm_helpers.h", "repeat.h" }; |
| 42 | } |
| 43 | |
| 44 | std::string ClElementwiseAddKernelComponent::get_component_code() const |
| 45 | { |
| 46 | std::string code; |
| 47 | return R"_( |
| 48 | //------------------ START KERNEL {{meta_kernel_id}} ELTWISE_ADD --------------------- |
| 49 | // IN_0(Accumulator) {{acc}} |
| 50 | // IN_1(Addend) {{addend}} |
| 51 | |
| 52 | // c = addend + c (mix-precision, broadcast, boundary aware) |
| 53 | { |
| 54 | __global uchar *addend_addr = {{addend}}_ptr + {{addend}}_offset_first_element_in_bytes + (get_global_id(0) * (uint)N0 * sizeof(DATA_TYPE)) + (COMPUTE_M0_START_ROW(g_y, M0, PARTIAL_STORE_M0) * {{addend}}_stride_y) + get_global_id(2) * {{addend}}_stride_z; \ |
| 55 | LOAD_BLOCK_BOUNDARY_AWARE(M0, N0, DATA_TYPE, addend, addend_addr, 0, {{addend}}_stride_y, g_zero, PARTIAL_LOAD_M0, PARTIAL_LOAD_N0, PARTIAL_COND_Y, PARTIAL_COND_X); \ |
| 56 | MIXED_PRECISION_ELTWISE_OP_BLOCK(ADD_X_POS_0, M0, N0, {{acc}}, addend, DATA_TYPE_ACCUMULATOR, addend_hp); |
| 57 | } |
| 58 | //------------------ END KERNEL {{meta_kernel_id}} ELTWISE_ADD --------------------- |
| 59 | |
| 60 | )_"; |
| 61 | } |
| 62 | ClElementwiseAddKernelComponent::TagLUT ClElementwiseAddKernelComponent::allocate_vars(SharedVarTable &vtable) const |
| 63 | { |
| 64 | // Determine which argument is the accumulator |
| 65 | Link accumulator; |
| 66 | Link addend; |
| 67 | if(_lhs.group == SharedVarGroup::Automatic) |
| 68 | { |
| 69 | accumulator = _lhs; |
| 70 | addend = _rhs; |
| 71 | } |
| 72 | else if(_rhs.group == SharedVarGroup::Automatic) |
| 73 | { |
| 74 | accumulator = _rhs; |
| 75 | addend = _lhs; |
| 76 | } |
| 77 | else |
| 78 | { |
| 79 | ARM_COMPUTE_ERROR("Invalid elementwise component linking"); |
| 80 | } |
| 81 | return { |
| 82 | { "meta_kernel_id", id() }, |
| 83 | { "acc", vtable.add(accumulator, ClKernelArgRuntimeDescriptor(accumulator.arg_id, TensorArgType::Image_3D), "add_acc") }, |
| 84 | { "addend", vtable.add(addend, ClKernelArgRuntimeDescriptor(addend.arg_id, TensorArgType::Image_3D), "add_addend") }, |
| 85 | // {"dst", vtable.add(_dst, ClKernelArgRuntimeDescriptor(_dst.arg_id, TensorArgType::Image_3D), "dst")}, // dst is needed for the root version and/or non-inplace version should we need one |
| 86 | }; |
| 87 | } |
| 88 | } // namespace dynamic_fusion |
| 89 | } // namespace experimental |
| 90 | } // namespace arm_compute |
| 91 | |
| 92 | #endif // defined(ENABLE_EXPERIMENTAL_DYNAMIC_FUSION) |