blob: fea4fe957724bb5f77f4df4dbd9fa43cb1b3ce92 [file] [log] [blame]
SiCong Lif44bbc52022-08-29 18:25:51 +01001/*
Gunes Bayir3a1e1252023-01-03 21:26:09 +00002 * Copyright (c) 2022-2023 Arm Limited.
SiCong Lif44bbc52022-08-29 18:25:51 +01003 *
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_GPUWORKLOADSKETCHIMPL
25#define SRC_DYNAMIC_FUSION_SKETCH_GPU_GPUWORKLOADSKETCHIMPL
26
27#include "arm_compute/dynamic_fusion/sketch/gpu/GpuWorkloadSketch.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010028#include "arm_compute/dynamic_fusion/sketch/MemoryDescriptor.h"
29
SiCong Lif44bbc52022-08-29 18:25:51 +010030#include "src/dynamic_fusion/sketch/gpu/GpuComponentServices.h"
31#include "src/dynamic_fusion/sketch/gpu/GpuKernelComponentGraph.h"
32#include "src/dynamic_fusion/sketch/gpu/GpuOperatorGroup.h"
SiCong Li23882a92023-06-28 09:49:45 +010033#include "src/dynamic_fusion/sketch/gpu/GpuWorkloadContextImpl.h"
Gunes Bayir3a1e1252023-01-03 21:26:09 +000034
SiCong Lif44bbc52022-08-29 18:25:51 +010035namespace arm_compute
36{
37namespace experimental
38{
39namespace dynamic_fusion
40{
41/** Internal implementation of @ref GpuWorkloadSketch */
42class GpuWorkloadSketch::Implementation
43{
44public:
45 /** Constructor
46 *
47 * @param[in] context global workload creation context
48 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010049 explicit Implementation(Context *context)
50 : _context{context}, _comp_services{}, _component_graph{_context, &_comp_services}, _operator_group{}
SiCong Lif44bbc52022-08-29 18:25:51 +010051 {
52 }
53 /** Prevent instances of this class from being copy constructed */
54 Implementation(const Implementation &impl) = delete;
55 /** Prevent instances of this class from being copied */
56 Implementation &operator=(const Implementation &impl) = delete;
57 /** Allow instances of this class to be move constructed */
58 Implementation(Implementation &&impl) = default;
59 /** Allow instances of this class to be moved */
60 Implementation &operator=(Implementation &&impl) = default;
61 /** Get workload context */
62 const Context *context() const
63 {
64 return _context;
65 }
66 /** Get component graph */
67 const GpuKernelComponentGraph &component_graph() const
68 {
69 return _component_graph;
70 }
71 /** Get component graph */
72 GpuKernelComponentGraph &component_graph()
73 {
74 return _component_graph;
75 }
76 /** Get operator group */
77 const GpuOperatorGroup &operator_group() const
78 {
79 return _operator_group;
80 }
81 /** Get operator group */
82 GpuOperatorGroup &operator_group()
83 {
84 return _operator_group;
85 }
SiCong Lif44bbc52022-08-29 18:25:51 +010086 /** Generate @ref GpuWorkloadSourceCode from the workload sketch
87 * @note The sketch must be valid. Any error encountered during the building of the code will be thrown.
88 *
89 * @return GpuWorkloadSourceCode The generated workload code
90 */
91 GpuWorkloadSourceCode generate_source_code() const
92 {
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +010093 const auto mem_map = _context->implementation().mem_map();
94 return component_graph().fuse(mem_map).write_workload_code();
SiCong Lif44bbc52022-08-29 18:25:51 +010095 }
SiCong Li5a2bc012023-01-12 12:54:49 +000096 /** Create a virtual (see @ref MemoryType) tensor info and save it
Gunes Bayir3a1e1252023-01-03 21:26:09 +000097 *
SiCong Li5a2bc012023-01-12 12:54:49 +000098 * @return ITensorInfo* The created virtual tensor info object pointer
Gunes Bayir3a1e1252023-01-03 21:26:09 +000099 */
SiCong Li5a2bc012023-01-12 12:54:49 +0000100 ITensorInfo *create_virtual_tensor()
Gunes Bayir3a1e1252023-01-03 21:26:09 +0000101 {
SiCong Li23882a92023-06-28 09:49:45 +0100102 return _context->implementation().create_virtual_tensor();
SiCong Li5a2bc012023-01-12 12:54:49 +0000103 }
104 /** Create an auxiliary (see @ref MemoryType) tensor info and save it
105 *
SiCong Li5a2bc012023-01-12 12:54:49 +0000106 * @param[in] tensor_info @ref ITensorInfo to copy from
107 *
108 * @return ITensorInfo* The created auxiliary tensor info object pointer
109 */
110 ITensorInfo *create_auxiliary_tensor(const ITensorInfo &tensor_info)
111 {
SiCong Li23882a92023-06-28 09:49:45 +0100112 return _context->implementation().create_auxiliary_tensor(tensor_info);
113 }
114
115 ITensorInfo *get_tensor_info(ITensorInfo::Id id)
116 {
117 return _context->implementation().get_tensor_info(id);
SiCong Li5a2bc012023-01-12 12:54:49 +0000118 }
SiCong Lif44bbc52022-08-29 18:25:51 +0100119
120private:
SiCong Li23882a92023-06-28 09:49:45 +0100121 Context *_context;
122 GpuComponentServices _comp_services;
123 GpuKernelComponentGraph _component_graph;
124 GpuOperatorGroup _operator_group;
SiCong Lif44bbc52022-08-29 18:25:51 +0100125};
126} // namespace dynamic_fusion
127} // namespace experimental
128} // namespace arm_compute
129#endif /* SRC_DYNAMIC_FUSION_SKETCH_GPU_GPUWORKLOADSKETCHIMPL */