blob: ba2503a9381036b6cd17b4f76caa77e19796099f [file] [log] [blame]
SiCong Lif44bbc52022-08-29 18:25:51 +01001/*
SiCong Li23882a92023-06-28 09:49:45 +01002 * 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_GPUKERNELCOMPONENTSTREAM
25#define SRC_DYNAMIC_FUSION_SKETCH_GPU_GPUKERNELCOMPONENTSTREAM
26
27#include "arm_compute/dynamic_fusion/sketch/MemoryDescriptor.h"
28#include "src/dynamic_fusion/sketch/gpu/GpuKernelComponentGroup.h"
29#include "src/dynamic_fusion/sketch/gpu/GpuWorkloadSourceCode.h"
30
31namespace arm_compute
32{
33namespace experimental
34{
35namespace dynamic_fusion
36{
37class GpuComponentServices;
38class IGpuKernelComponent;
39
40/** A linear sequence of component groups serialized from the @ref GpuKernelComponentGraph
41 * Each component group in the stream denotes a complete kernel that may consist of multiple components
42 *
43 * The main purposes of this class are:
44 * - Facilitate component fusion algorithm by allowing insertions of new component groups into the stream
45 * - Invoke kernel writer and assemble the final @ref GpuWorkloadSourceCode
46 */
47class GpuKernelComponentStream
48{
49public:
50 /** Constructor
51 *
SiCong Li23882a92023-06-28 09:49:45 +010052 * @param[in] context @ref GpuWorkloadContext to be used throughout the stream
SiCong Lif44bbc52022-08-29 18:25:51 +010053 * @param[in] services @ref GpuComponentServices to be used throughout the stream
54 * @param[in] mem_map @ref MemoryDescriptor map used to assemble the @ref GpuWorkloadSourceCode
55 */
SiCong Li23882a92023-06-28 09:49:45 +010056 GpuKernelComponentStream(GpuWorkloadContext *context, GpuComponentServices *services, const MemoryDescriptorMap &mem_map);
SiCong Lif44bbc52022-08-29 18:25:51 +010057 /** Allow instances of this class to be copy constructed */
58 GpuKernelComponentStream(const GpuKernelComponentStream &stream) = default;
59 /** Allow instances of this class to be copied */
60 GpuKernelComponentStream &operator=(const GpuKernelComponentStream &stream) = default;
61 /** Allow instances of this class to be move constructed */
62 GpuKernelComponentStream(GpuKernelComponentStream &&stream) = default;
63 /** Allow instances of this class to be moved */
64 GpuKernelComponentStream &operator=(GpuKernelComponentStream &&stream) = default;
65 /** Generate and assemble @ref GpuWorkloadSourceCode from the stream */
66 GpuWorkloadSourceCode write_workload_code();
67 /** Insert a new component group in the stream.
68 * Subsequent components are added to this group until end of stream or the next new_component_group is called
69 */
70 void new_component_group();
71 /** Add a component to the previously created component group
72 * Throw an error if no component group is present in the stream
73 *
74 * @param[in] component Component to be inserted
75 *
76 * @return true If the operation is successful
77 * @return false Otherwise
78 */
79 bool add_component(IGpuKernelComponent *component);
80
81private:
SiCong Li23882a92023-06-28 09:49:45 +010082 GpuWorkloadContext *_context;
SiCong Lif44bbc52022-08-29 18:25:51 +010083 GpuComponentServices *_services;
84 std::vector<GpuKernelComponentGroup> _component_groups{};
85 MemoryDescriptorMap _mem_map{};
86};
87} // namespace dynamic_fusion
88} // namespace experimental
89} // namespace arm_compute
90#endif /* SRC_DYNAMIC_FUSION_SKETCH_GPU_GPUKERNELCOMPONENTSTREAM */