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 | */ |
SiCong Li | 4e9f568 | 2022-05-10 10:15:59 +0100 | [diff] [blame] | 24 | #ifdef ENABLE_EXPERIMENTAL_DYNAMIC_FUSION |
Giorgio Arena | 232c452 | 2022-03-03 10:09:01 +0000 | [diff] [blame] | 25 | |
| 26 | #ifndef ARM_COMPUTE_EXPERIMENTAL_CLKERNELBUILDINGAPI_H |
| 27 | #define ARM_COMPUTE_EXPERIMENTAL_CLKERNELBUILDINGAPI_H |
| 28 | |
| 29 | #include "arm_compute/core/CL/CLCompileContext.h" |
| 30 | #include "arm_compute/core/Window.h" |
SiCong Li | b63b119 | 2022-01-28 18:24:39 +0000 | [diff] [blame] | 31 | #include "arm_compute/core/experimental/ClWorkload.h" |
| 32 | #include "arm_compute/core/experimental/DependencyGraph.h" |
| 33 | #include "src/core/experimental/dynamic_fusion/WorkloadImpl/ClKernelDescriptors.h" |
Giorgio Arena | 232c452 | 2022-03-03 10:09:01 +0000 | [diff] [blame] | 34 | |
| 35 | namespace arm_compute |
| 36 | { |
| 37 | namespace experimental |
| 38 | { |
| 39 | namespace dynamic_fusion |
| 40 | { |
SiCong Li | b63b119 | 2022-01-28 18:24:39 +0000 | [diff] [blame] | 41 | using ArgumentID = DependencyGraph::Id; |
Giorgio Arena | 232c452 | 2022-03-03 10:09:01 +0000 | [diff] [blame] | 42 | |
SiCong Li | b63b119 | 2022-01-28 18:24:39 +0000 | [diff] [blame] | 43 | static constexpr ArgumentID g_arg_placeholder = DependencyGraph::empty_id(); |
Giorgio Arena | 232c452 | 2022-03-03 10:09:01 +0000 | [diff] [blame] | 44 | |
| 45 | /** Intermediate representation of the final, complete kernel source. */ |
| 46 | class ClKernelBlueprint |
| 47 | { |
| 48 | public: |
| 49 | ClKernelBlueprint(); |
| 50 | ~ClKernelBlueprint(); |
| 51 | |
| 52 | private: |
| 53 | struct Implementation; |
| 54 | std::unique_ptr<Implementation> _impl; |
| 55 | |
| 56 | public: |
| 57 | Implementation &impl(); |
| 58 | const Implementation &impl() const; |
| 59 | }; |
| 60 | |
| 61 | ///// Kernel Components ///// |
Michalis Spyrou | b1fcefd | 2022-06-15 19:02:28 +0100 | [diff] [blame] | 62 | /** Component: Eltwise Operator */ |
| 63 | Status add_kcomp_eltwise_op(ClKernelBlueprint &, const ClElementwiseKernelDescriptor &, ArgumentID src0_id, |
| 64 | ArgumentID src1_id, ArgumentID &dst_id); |
| 65 | |
| 66 | /** Component: Floor */ |
| 67 | Status add_kcomp_floor(ClKernelBlueprint &, const ClFloorKernelDescriptor &, ArgumentID src_id, |
| 68 | ArgumentID &dst_id); |
Giorgio Arena | 232c452 | 2022-03-03 10:09:01 +0000 | [diff] [blame] | 69 | |
| 70 | /** Component: Activation */ |
SiCong Li | b63b119 | 2022-01-28 18:24:39 +0000 | [diff] [blame] | 71 | Status add_kcomp_activation(ClKernelBlueprint &, const ClActivationKernelDescriptor &, ArgumentID src_id, ArgumentID &dst_id); |
Giorgio Arena | 232c452 | 2022-03-03 10:09:01 +0000 | [diff] [blame] | 72 | |
Gunes Bayir | 16c5697 | 2022-03-28 21:32:33 +0100 | [diff] [blame] | 73 | /** Component: Direct Convolution **/ |
SiCong Li | b63b119 | 2022-01-28 18:24:39 +0000 | [diff] [blame] | 74 | Status add_kcomp_direct_conv2d(ClKernelBlueprint &, const ClDirectConv2dKernelDescriptor &, |
| 75 | ArgumentID src_id, ArgumentID weight_id, ArgumentID bias_id, ArgumentID &dst_id); |
Gunes Bayir | 16c5697 | 2022-03-28 21:32:33 +0100 | [diff] [blame] | 76 | |
SiCong Li | b63b119 | 2022-01-28 18:24:39 +0000 | [diff] [blame] | 77 | Status add_kcomp_store(ClKernelBlueprint &, const StoreType &store_type, ArgumentID src_id, ArgumentID dst_id); |
Giorgio Arena | 232c452 | 2022-03-03 10:09:01 +0000 | [diff] [blame] | 78 | |
SiCong Li | b63b119 | 2022-01-28 18:24:39 +0000 | [diff] [blame] | 79 | Status add_tensor(ClKernelBlueprint &, ITensorInfo *, ArgumentID &, ArgumentID merge_point = DependencyGraph::empty_id()); |
Giorgio Arena | 232c452 | 2022-03-03 10:09:01 +0000 | [diff] [blame] | 80 | |
| 81 | ///// Kernel Components ///// |
| 82 | |
| 83 | ///// Building ///// |
| 84 | |
SiCong Li | b63b119 | 2022-01-28 18:24:39 +0000 | [diff] [blame] | 85 | /** Update existing merge tensor @p merge_point to point to @p t_id |
| 86 | * |
| 87 | * @param t_id |
| 88 | * @param merge_point |
| 89 | * @return Status |
| 90 | */ |
| 91 | Status update_merge_point(ClKernelBlueprint &, ArgumentID t_id, ArgumentID merge_point); |
Giorgio Arena | 232c452 | 2022-03-03 10:09:01 +0000 | [diff] [blame] | 92 | |
SiCong Li | b63b119 | 2022-01-28 18:24:39 +0000 | [diff] [blame] | 93 | /** Get dependency graph |
| 94 | * |
| 95 | * @return DependencyGraph |
| 96 | */ |
| 97 | DependencyGraph get_dependency_graph(const ClKernelBlueprint &blueprint); |
Giorgio Arena | 232c452 | 2022-03-03 10:09:01 +0000 | [diff] [blame] | 98 | |
| 99 | /** All information required for building the @ref ClKernelCode */ |
| 100 | struct ClCodeBuilderContext |
| 101 | { |
| 102 | GpuInfo gpu_info{}; |
| 103 | }; |
| 104 | |
| 105 | Status set_tile_info(ClKernelBlueprint &, const TileDescriptor &); |
| 106 | |
| 107 | /** Build final kernel source from KernelBlueprint */ |
| 108 | Status build(ClKernelCode &code, const ClCodeBuilderContext &, ClKernelBlueprint &); |
| 109 | |
| 110 | ///// Building ///// |
| 111 | |
| 112 | ///// Tuning ///// |
Giorgio Arena | 232c452 | 2022-03-03 10:09:01 +0000 | [diff] [blame] | 113 | |
| 114 | Status tune_static(ClExecutionDescriptor &, const ClKernelCode &); |
| 115 | |
| 116 | ///// Tuning ///// |
| 117 | |
| 118 | } // namespace dynamic_fusion |
| 119 | } // namespace experimental |
| 120 | } // namespace arm_compute |
SiCong Li | 4e9f568 | 2022-05-10 10:15:59 +0100 | [diff] [blame] | 121 | #endif //ARM_COMPUTE_EXPERIMENTAL_CLKERNELBUILDINGAPI_H |
| 122 | #endif /* ENABLE_EXPERIMENTAL_DYNAMIC_FUSION */ |