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 #ifndef SRC_DYNAMIC_FUSION_SKETCH_GPU_COMPONENTS_CL_CLCOMPONENTELEMENTWISEBINARY
25 #define SRC_DYNAMIC_FUSION_SKETCH_GPU_COMPONENTS_CL_CLCOMPONENTELEMENTWISEBINARY
26 
27 #include "arm_compute/core/Error.h"
28 #include "src/dynamic_fusion/sketch/gpu/components/IGpuKernelComponent.h"
29 #include "src/dynamic_fusion/sketch/gpu/operators/internal/GpuElementwiseBinaryCommon.h"
30 
31 namespace arm_compute
32 {
33 /** Forward declaration */
34 class ITensorInfo;
35 namespace experimental
36 {
37 namespace dynamic_fusion
38 {
39 /** Forward declaration */
40 template <typename T>
41 class ArgumentPack;
42 
43 /** Forward declaration */
44 class ClTemplateElementwiseBinary;
45 
46 class ClComponentElementwiseBinary final : public IGpuKernelComponent
47 {
48 public:
49     /** Attributes are a set of backend-agnostic parameters that define what a component does */
50     using Attributes = ElementwiseBinaryCommonAttributes;
51 
52 public:
53     /** Validate the component
54      *
55      * @param[in,out] tensors    Tensor arguments to the component
56      * @param[in]     attributes Component attributes
57      *
58      * @return Status       Validation results
59      *
60      * Tensor argument names:
61      * - ACL_SRC_0: lhs
62      * - ACL_SRC_1: rhs
63      * - ACL_DST_0: dst
64      *
65      * Tensor argument constness:
66      * - ACL_SRC_0: Const
67      * - ACL_SRC_1: Const
68      * - ACL_DST_0: Const
69      *
70      * Valid data layouts:
71      * - All
72      *
73      * Valid data type configurations (for DIV FP32/FP16/S32 supported, for POWER only FP32/FP16 supported):
74      * |ACL_SRC_0      |ACL_SRC_1      |ACL_DST_0      |
75      * |:--------------|:--------------|:--------------|
76      * |F16            |F16            |F16            |
77      * |F32            |F32            |F32            |
78      * |S32            |S32            |S32            |
79      * |S16            |S16            |S16            |
80      * |U8             |U8             |U8             |
81      */
82     static Status validate(const ArgumentPack<ITensorInfo> &tensors, const ElementwiseBinaryCommonAttributes &attributes);
83 
84     /** Constructor
85      *
86      * Similar to @ref ClComponentElementwiseBinary::validate()
87      */
88     ClComponentElementwiseBinary(
89         ComponentId                      id,
90         const Properties                &properties,
91         const ArgumentPack<ITensorInfo> &tensors,
92         const Attributes                &attributes);
93 
94     /** Destructor */
95     ~ClComponentElementwiseBinary() override;
96     /** Prevent instances of this class from being copy constructed */
97     ClComponentElementwiseBinary(const ClComponentElementwiseBinary &component) = delete;
98     /** Prevent instances of this class from being copied */
99     ClComponentElementwiseBinary &operator=(const ClComponentElementwiseBinary &component) = delete;
100     /** Allow instances of this class to be move constructed */
101     ClComponentElementwiseBinary(ClComponentElementwiseBinary &&component) = default;
102     /** Allow instances of this class to be moved */
103     ClComponentElementwiseBinary &operator=(ClComponentElementwiseBinary &&component) = default;
104     /** Get template writer for the component */
105     const IGpuTemplateComponentWriter *template_writer() const override;
106     /** Get component type */
type()107     GpuComponentType type() const override
108     {
109         return GpuComponentType::Simple;
110     }
111 
112 private:
113     std::unique_ptr<ClTemplateElementwiseBinary> _component_writer;
114 };
115 } // namespace dynamic_fusion
116 } // namespace experimental
117 } // namespace arm_compute
118 #endif /* SRC_DYNAMIC_FUSION_SKETCH_GPU_COMPONENTS_CL_CLCOMPONENTELEMENTWISEBINARY */
119