SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 1 | /* |
Viet-Hoa Do | fdf56fb | 2024-01-18 16:10:46 +0000 | [diff] [blame] | 2 | * Copyright (c) 2022-2024 Arm Limited. |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 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 | */ |
Viet-Hoa Do | fdf56fb | 2024-01-18 16:10:46 +0000 | [diff] [blame] | 24 | #ifndef ACL_ARM_COMPUTE_DYNAMIC_FUSION_SKETCH_GPU_GPUWORKLOADCONTEXT_H |
| 25 | #define ACL_ARM_COMPUTE_DYNAMIC_FUSION_SKETCH_GPU_GPUWORKLOADCONTEXT_H |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/core/GPUTarget.h" |
Viet-Hoa Do | 3fcf3dc | 2023-05-17 15:17:48 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/TensorInfo.h" |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 29 | |
| 30 | #include <memory> |
| 31 | |
| 32 | namespace arm_compute |
| 33 | { |
| 34 | /** Forward declaration */ |
| 35 | class CLCompileContext; |
| 36 | namespace experimental |
| 37 | { |
| 38 | namespace dynamic_fusion |
| 39 | { |
| 40 | /** Gpu Information such as the Gpu target (for example, G76) */ |
| 41 | using GpuTarget = ::arm_compute::GPUTarget; |
| 42 | |
| 43 | /** Gpu Language */ |
| 44 | enum class GpuLanguage |
| 45 | { |
| 46 | OpenCL, |
| 47 | Unknown |
| 48 | }; |
| 49 | /** Provide context necessary for the creation and configuration of a workload |
| 50 | * e.g. gpu targets and capabilities, cl::Device for querying OpenCl extensions. Both can affect how a kernel is generated |
| 51 | * |
| 52 | * This context is shared between different operators within a sketch, and has to stay valid for the entire workload creation session. |
| 53 | * This context may also be shared between different sketches. |
| 54 | * |
| 55 | * This class only contains information for workload creation, but not for runtime (e.g. cl::Queue for enqueueing the kernels) |
| 56 | */ |
| 57 | class GpuWorkloadContext |
| 58 | { |
| 59 | public: |
Viet-Hoa Do | 3fcf3dc | 2023-05-17 15:17:48 +0100 | [diff] [blame] | 60 | class Impl; |
| 61 | |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 62 | /** Constructor */ |
| 63 | GpuWorkloadContext(CLCompileContext *cl_compile_context); |
Viet-Hoa Do | 3fcf3dc | 2023-05-17 15:17:48 +0100 | [diff] [blame] | 64 | /** Destructor */ |
| 65 | ~GpuWorkloadContext(); |
| 66 | /** Prohibit instances of this class to be copy constructed */ |
| 67 | GpuWorkloadContext(const GpuWorkloadContext &config) = delete; |
| 68 | /** Prohibit instances of this class to be copied */ |
| 69 | GpuWorkloadContext &operator=(const GpuWorkloadContext &config) = delete; |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 70 | /** Allow instances of this class to be move constructed */ |
Viet-Hoa Do | 3fcf3dc | 2023-05-17 15:17:48 +0100 | [diff] [blame] | 71 | GpuWorkloadContext(GpuWorkloadContext &&config); |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 72 | /** Allow instances of this class to be moved */ |
Viet-Hoa Do | 3fcf3dc | 2023-05-17 15:17:48 +0100 | [diff] [blame] | 73 | GpuWorkloadContext &operator=(GpuWorkloadContext &&config); |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 74 | /** Get @ref GpuLanguage of the context */ |
| 75 | GpuLanguage gpu_language() const; |
| 76 | /** Get @ref GpuTarget of the context */ |
| 77 | GpuTarget gpu_target() const; |
| 78 | /** Get @ref CLCompileContext |
| 79 | * If the gpu language is not OpenCL, then return nullptr |
| 80 | */ |
| 81 | const CLCompileContext *cl_compile_context() const; |
| 82 | |
Viet-Hoa Do | 3fcf3dc | 2023-05-17 15:17:48 +0100 | [diff] [blame] | 83 | /** Create a @ref TensorInfo associated with the workload context. |
| 84 | * |
| 85 | * @return TensorInfo Newly created tensor info |
| 86 | */ |
| 87 | template <typename... TArgs> |
Viet-Hoa Do | fdf56fb | 2024-01-18 16:10:46 +0000 | [diff] [blame] | 88 | ITensorInfo *create_tensor_info(TArgs &&...args) |
Viet-Hoa Do | 3fcf3dc | 2023-05-17 15:17:48 +0100 | [diff] [blame] | 89 | { |
Viet-Hoa Do | fdf56fb | 2024-01-18 16:10:46 +0000 | [diff] [blame] | 90 | auto tensor_info = std::make_unique<TensorInfo>(std::forward<TArgs>(args)...); |
| 91 | auto *tensor_info_ptr = tensor_info.get(); |
| 92 | |
| 93 | register_user_tensor(std::move(tensor_info)); |
| 94 | |
| 95 | return tensor_info_ptr; |
Viet-Hoa Do | 3fcf3dc | 2023-05-17 15:17:48 +0100 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | /** Get the internal implementation */ |
| 99 | Impl &implementation(); |
| 100 | |
| 101 | /** Get the internal implementation */ |
| 102 | const Impl &implementation() const; |
| 103 | |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 104 | private: |
Viet-Hoa Do | 3fcf3dc | 2023-05-17 15:17:48 +0100 | [diff] [blame] | 105 | /** Set a new ID to the tensor info and register its memory descriptor to the context. |
| 106 | * |
Viet-Hoa Do | fdf56fb | 2024-01-18 16:10:46 +0000 | [diff] [blame] | 107 | * The ownership of the tensor info object will be transfered to this context object. |
| 108 | * |
| 109 | * @param[in] tensor_info @ref TensorInfo to be registered. |
Viet-Hoa Do | 3fcf3dc | 2023-05-17 15:17:48 +0100 | [diff] [blame] | 110 | */ |
Viet-Hoa Do | fdf56fb | 2024-01-18 16:10:46 +0000 | [diff] [blame] | 111 | void register_user_tensor(std::unique_ptr<TensorInfo> &&tensor_info); |
Viet-Hoa Do | 3fcf3dc | 2023-05-17 15:17:48 +0100 | [diff] [blame] | 112 | |
| 113 | /** Internal implementation */ |
| 114 | std::unique_ptr<Impl> _impl; |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | } // namespace dynamic_fusion |
| 118 | } // namespace experimental |
| 119 | } // namespace arm_compute |
| 120 | |
Viet-Hoa Do | fdf56fb | 2024-01-18 16:10:46 +0000 | [diff] [blame] | 121 | #endif // ACL_ARM_COMPUTE_DYNAMIC_FUSION_SKETCH_GPU_GPUWORKLOADCONTEXT_H |