Debian Codegraph @

arm_compute/dynamic_fusion/sketch/gpu/GpuWorkloadContext.h

raw
1 /*
2 * Copyright (c) 2022-2024 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 ACL_ARM_COMPUTE_DYNAMIC_FUSION_SKETCH_GPU_GPUWORKLOADCONTEXT_H
25 #define ACL_ARM_COMPUTE_DYNAMIC_FUSION_SKETCH_GPU_GPUWORKLOADCONTEXT_H
26
27 #include "arm_compute/core/GPUTarget.h"
28 #include "arm_compute/core/TensorInfo.h"
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:
60 class Impl;
61
62 /** Constructor */
63 GpuWorkloadContext(CLCompileContext *cl_compile_context);
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;
70 /** Allow instances of this class to be move constructed */
71 GpuWorkloadContext(GpuWorkloadContext &&config);
72 /** Allow instances of this class to be moved */
73 GpuWorkloadContext &operator=(GpuWorkloadContext &&config);
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
83 /** Create a @ref TensorInfo associated with the workload context.
84 *
85 * @return TensorInfo Newly created tensor info
86 */
87 template <typename... TArgs>
88 ITensorInfo *create_tensor_info(TArgs &&...args)
89 {
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;
96 }
97
98 /** Get the internal implementation */
99 Impl &implementation();
100
101 /** Get the internal implementation */
102 const Impl &implementation() const;
103
104 private:
105 /** Set a new ID to the tensor info and register its memory descriptor to the context.
106 *
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.
110 */
111 void register_user_tensor(std::unique_ptr<TensorInfo> &&tensor_info);
112
113 /** Internal implementation */
114 std::unique_ptr<Impl> _impl;
115 };
116
117 } // namespace dynamic_fusion
118 } // namespace experimental
119 } // namespace arm_compute
120
121 #endif // ACL_ARM_COMPUTE_DYNAMIC_FUSION_SKETCH_GPU_GPUWORKLOADCONTEXT_H