blob: 3dccdd7351c867a59d5974e93cb8f03ab51eea5d [file] [log] [blame]
Giorgio Arena232c4522022-03-03 10:09:01 +00001/*
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 Lib63b1192022-01-28 18:24:39 +000024#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 Arena232c4522022-03-03 10:09:01 +000027
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 Lib63b1192022-01-28 18:24:39 +000033#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 Arena232c4522022-03-03 10:09:01 +000036
37namespace arm_compute
38{
39namespace experimental
40{
41namespace dynamic_fusion
42{
SiCong Lib63b1192022-01-28 18:24:39 +000043using ArgumentID = DependencyGraph::Id;
Giorgio Arena232c4522022-03-03 10:09:01 +000044
SiCong Lib63b1192022-01-28 18:24:39 +000045static constexpr ArgumentID g_arg_placeholder = DependencyGraph::empty_id();
Giorgio Arena232c4522022-03-03 10:09:01 +000046
47/** Intermediate representation of the final, complete kernel source. */
48class ClKernelBlueprint
49{
50public:
51 ClKernelBlueprint();
52 ~ClKernelBlueprint();
53
54private:
55 struct Implementation;
56 std::unique_ptr<Implementation> _impl;
57
58public:
59 Implementation &impl();
60 const Implementation &impl() const;
61};
62
63///// Kernel Components /////
Giorgio Arena232c4522022-03-03 10:09:01 +000064/** Component: Eltwise Add */
SiCong Lib63b1192022-01-28 18:24:39 +000065Status add_kcomp_eltwise_add(ClKernelBlueprint &, const ClEltwiseAddKernelDescriptor &, ArgumentID src0_id,
Giorgio Arena232c4522022-03-03 10:09:01 +000066 ArgumentID src1_id, ArgumentID &dst_id);
67
68/** Component: Activation */
SiCong Lib63b1192022-01-28 18:24:39 +000069Status add_kcomp_activation(ClKernelBlueprint &, const ClActivationKernelDescriptor &, ArgumentID src_id, ArgumentID &dst_id);
Giorgio Arena232c4522022-03-03 10:09:01 +000070
Gunes Bayir16c56972022-03-28 21:32:33 +010071/** Component: Direct Convolution **/
SiCong Lib63b1192022-01-28 18:24:39 +000072Status add_kcomp_direct_conv2d(ClKernelBlueprint &, const ClDirectConv2dKernelDescriptor &,
73 ArgumentID src_id, ArgumentID weight_id, ArgumentID bias_id, ArgumentID &dst_id);
Gunes Bayir16c56972022-03-28 21:32:33 +010074
SiCong Lib63b1192022-01-28 18:24:39 +000075Status add_kcomp_store(ClKernelBlueprint &, const StoreType &store_type, ArgumentID src_id, ArgumentID dst_id);
Giorgio Arena232c4522022-03-03 10:09:01 +000076
SiCong Lib63b1192022-01-28 18:24:39 +000077Status add_tensor(ClKernelBlueprint &, ITensorInfo *, ArgumentID &, ArgumentID merge_point = DependencyGraph::empty_id());
Giorgio Arena232c4522022-03-03 10:09:01 +000078
79///// Kernel Components /////
80
81///// Building /////
82
SiCong Lib63b1192022-01-28 18:24:39 +000083/** 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 */
89Status update_merge_point(ClKernelBlueprint &, ArgumentID t_id, ArgumentID merge_point);
Giorgio Arena232c4522022-03-03 10:09:01 +000090
SiCong Lib63b1192022-01-28 18:24:39 +000091/** Get dependency graph
92 *
93 * @return DependencyGraph
94 */
95DependencyGraph get_dependency_graph(const ClKernelBlueprint &blueprint);
Giorgio Arena232c4522022-03-03 10:09:01 +000096
97/** All information required for building the @ref ClKernelCode */
98struct ClCodeBuilderContext
99{
100 GpuInfo gpu_info{};
101};
102
103Status set_tile_info(ClKernelBlueprint &, const TileDescriptor &);
104
105/** Build final kernel source from KernelBlueprint */
106Status build(ClKernelCode &code, const ClCodeBuilderContext &, ClKernelBlueprint &);
107
108///// Building /////
109
110///// Tuning /////
Giorgio Arena232c4522022-03-03 10:09:01 +0000111
112Status tune_static(ClExecutionDescriptor &, const ClKernelCode &);
113
114///// Tuning /////
115
116} // namespace dynamic_fusion
117} // namespace experimental
118} // namespace arm_compute
SiCong Lib63b1192022-01-28 18:24:39 +0000119#endif //ARM_COMPUTE_EXPERIMENTAL_CLKERNELBUILDINGAPI_H