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_COMPONENTS_GPUKERNELCOMPONENTFACTORY 25 #define SRC_DYNAMIC_FUSION_SKETCH_GPU_COMPONENTS_GPUKERNELCOMPONENTFACTORY 26 27 #include "Types.h" 28 #include "src/dynamic_fusion/sketch/gpu/components/IGpuKernelComponent.h" 29 #include <memory> 30 31 namespace arm_compute 32 { 33 namespace experimental 34 { 35 namespace dynamic_fusion 36 { 37 /** Factory class that creates new instances of @ref IGpuKernelComponent by assigning new component ids 38 */ 39 class GpuKernelComponentFactory 40 { 41 public: 42 /** Create a new kernel component 43 * 44 * @tparam T Any polymorphic type descending from @ref IGpuKernelComponent 45 * @tparam Args Argument types to construct the kernel component 46 * 47 * @param[in] args Arguments to construct the kernel component 48 * 49 * @return std::unique_ptr<IGpuKernelComponent> 50 */ 51 template <typename T, typename... Args> create(Args &&...args)52 std::unique_ptr<IGpuKernelComponent> create(Args &&... args) 53 { 54 return std::make_unique<T>(_count++, std::forward<Args>(args)...); 55 } 56 57 private: 58 ComponentId _count{ 0 }; 59 }; 60 61 } // namespace dynamic_fusion 62 } // namespace experimental 63 } // namespace arm_compute 64 #endif /* SRC_DYNAMIC_FUSION_SKETCH_GPU_COMPONENTS_GPUKERNELCOMPONENTFACTORY */ 65