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 */ 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 31 namespace arm_compute 32 { 33 namespace experimental 34 { 35 namespace dynamic_fusion 36 { 37 class GpuComponentServices; 38 class 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 */ 47 class GpuKernelComponentStream 48 { 49 public: 50 /** Constructor 51 * 52 * @param[in] services @ref GpuComponentServices to be used throughout the stream 53 * @param[in] mem_map @ref MemoryDescriptor map used to assemble the @ref GpuWorkloadSourceCode 54 */ 55 GpuKernelComponentStream(GpuComponentServices *services, const MemoryDescriptorMap &mem_map); 56 /** Allow instances of this class to be copy constructed */ 57 GpuKernelComponentStream(const GpuKernelComponentStream &stream) = default; 58 /** Allow instances of this class to be copied */ 59 GpuKernelComponentStream &operator=(const GpuKernelComponentStream &stream) = default; 60 /** Allow instances of this class to be move constructed */ 61 GpuKernelComponentStream(GpuKernelComponentStream &&stream) = default; 62 /** Allow instances of this class to be moved */ 63 GpuKernelComponentStream &operator=(GpuKernelComponentStream &&stream) = default; 64 /** Generate and assemble @ref GpuWorkloadSourceCode from the stream */ 65 GpuWorkloadSourceCode write_workload_code(); 66 /** Insert a new component group in the stream. 67 * Subsequent components are added to this group until end of stream or the next new_component_group is called 68 */ 69 void new_component_group(); 70 /** Add a component to the previously created component group 71 * Throw an error if no component group is present in the stream 72 * 73 * @param[in] component Component to be inserted 74 * 75 * @return true If the operation is successful 76 * @return false Otherwise 77 */ 78 bool add_component(IGpuKernelComponent *component); 79 80 private: 81 GpuComponentServices *_services; 82 std::vector<GpuKernelComponentGroup> _component_groups{}; 83 MemoryDescriptorMap _mem_map{}; 84 }; 85 } // namespace dynamic_fusion 86 } // namespace experimental 87 } // namespace arm_compute 88 #endif /* SRC_DYNAMIC_FUSION_SKETCH_GPU_GPUKERNELCOMPONENTSTREAM */ 89