blob: 76e425513ece94eb162193a136dcefc8bf99afee [file] [log] [blame]
SiCong Lif44bbc52022-08-29 18:25:51 +01001/*
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +00002 * Copyright (c) 2022-2024 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 */
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +000024#ifndef ACL_ARM_COMPUTE_DYNAMIC_FUSION_SKETCH_GPU_GPUWORKLOADCONTEXT_H
25#define ACL_ARM_COMPUTE_DYNAMIC_FUSION_SKETCH_GPU_GPUWORKLOADCONTEXT_H
SiCong Lif44bbc52022-08-29 18:25:51 +010026
27#include "arm_compute/core/GPUTarget.h"
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +010028#include "arm_compute/core/TensorInfo.h"
SiCong Lif44bbc52022-08-29 18:25:51 +010029
30#include <memory>
31
32namespace arm_compute
33{
34/** Forward declaration */
35class CLCompileContext;
36namespace experimental
37{
38namespace dynamic_fusion
39{
40/** Gpu Information such as the Gpu target (for example, G76) */
41using GpuTarget = ::arm_compute::GPUTarget;
42
43/** Gpu Language */
44enum 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 */
57class GpuWorkloadContext
58{
59public:
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +010060 class Impl;
61
SiCong Lif44bbc52022-08-29 18:25:51 +010062 /** Constructor */
63 GpuWorkloadContext(CLCompileContext *cl_compile_context);
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +010064 /** 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 Lif44bbc52022-08-29 18:25:51 +010070 /** Allow instances of this class to be move constructed */
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +010071 GpuWorkloadContext(GpuWorkloadContext &&config);
SiCong Lif44bbc52022-08-29 18:25:51 +010072 /** Allow instances of this class to be moved */
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +010073 GpuWorkloadContext &operator=(GpuWorkloadContext &&config);
SiCong Lif44bbc52022-08-29 18:25:51 +010074 /** 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 Do3fcf3dc2023-05-17 15:17:48 +010083 /** Create a @ref TensorInfo associated with the workload context.
84 *
85 * @return TensorInfo Newly created tensor info
86 */
87 template <typename... TArgs>
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +000088 ITensorInfo *create_tensor_info(TArgs &&...args)
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +010089 {
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +000090 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 Do3fcf3dc2023-05-17 15:17:48 +010096 }
97
98 /** Get the internal implementation */
99 Impl &implementation();
100
101 /** Get the internal implementation */
102 const Impl &implementation() const;
103
SiCong Lif44bbc52022-08-29 18:25:51 +0100104private:
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +0100105 /** Set a new ID to the tensor info and register its memory descriptor to the context.
106 *
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000107 * 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 Do3fcf3dc2023-05-17 15:17:48 +0100110 */
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000111 void register_user_tensor(std::unique_ptr<TensorInfo> &&tensor_info);
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +0100112
113 /** Internal implementation */
114 std::unique_ptr<Impl> _impl;
SiCong Lif44bbc52022-08-29 18:25:51 +0100115};
116
117} // namespace dynamic_fusion
118} // namespace experimental
119} // namespace arm_compute
120
Viet-Hoa Dofdf56fb2024-01-18 16:10:46 +0000121#endif // ACL_ARM_COMPUTE_DYNAMIC_FUSION_SKETCH_GPU_GPUWORKLOADCONTEXT_H