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