blob: 50f34d9c1452bb0261447dc71d6840175a2bf02b [file] [log] [blame]
SiCong Lif44bbc52022-08-29 18:25:51 +01001/*
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +01002 * Copyright (c) 2022-2023 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 Do3fcf3dc2023-05-17 15:17:48 +010024
SiCong Lif44bbc52022-08-29 18:25:51 +010025#include "arm_compute/dynamic_fusion/sketch/gpu/GpuWorkloadContext.h"
26#include "arm_compute/core/CL/CLCompileContext.h"
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +010027#include "src/dynamic_fusion/sketch/gpu/GpuWorkloadContextImpl.h"
SiCong Lif44bbc52022-08-29 18:25:51 +010028
29namespace arm_compute
30{
31namespace experimental
32{
33namespace dynamic_fusion
34{
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +010035
SiCong Lif44bbc52022-08-29 18:25:51 +010036GpuWorkloadContext::GpuWorkloadContext(CLCompileContext *cl_compile_ctx)
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +010037 : _impl { std::make_unique<Impl>(GpuLanguage::OpenCL, cl_compile_ctx) }
SiCong Lif44bbc52022-08-29 18:25:51 +010038{
39}
40
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +010041GpuWorkloadContext::~GpuWorkloadContext() = default;
42
43GpuWorkloadContext::GpuWorkloadContext(GpuWorkloadContext &&other) = default;
44
45GpuWorkloadContext &GpuWorkloadContext::operator=(GpuWorkloadContext &&other) = default;
46
SiCong Lif44bbc52022-08-29 18:25:51 +010047GpuTarget GpuWorkloadContext::gpu_target() const
48{
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +010049 return _impl->cl_compile_context()->get_gpu_target();
SiCong Lif44bbc52022-08-29 18:25:51 +010050}
51
52GpuLanguage GpuWorkloadContext::gpu_language() const
53{
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +010054 return _impl->gpu_language();
SiCong Lif44bbc52022-08-29 18:25:51 +010055}
56
57const CLCompileContext *GpuWorkloadContext::cl_compile_context() const
58{
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +010059 return _impl->cl_compile_context();
60}
61
62void GpuWorkloadContext::register_user_tensor(ITensorInfo &tensor_info)
63{
64 _impl->register_user_tensor(tensor_info);
65}
66
67GpuWorkloadContext::Impl &GpuWorkloadContext::implementation()
68{
69 return *_impl;
70}
71
72const GpuWorkloadContext::Impl &GpuWorkloadContext::implementation() const
73{
74 return *_impl;
75}
76
77GpuWorkloadContext::Impl::Impl(GpuLanguage gpu_language, CLCompileContext *cl_compile_ctx)
78 : _gpu_language(gpu_language), _cl_compile_ctx(cl_compile_ctx),
79 _next_tensor_id(1), _mem_map()
80{
81}
82
83GpuLanguage GpuWorkloadContext::Impl::gpu_language() const
84{
85 return _gpu_language;
86}
87
88const CLCompileContext *GpuWorkloadContext::Impl::cl_compile_context() const
89{
SiCong Lif44bbc52022-08-29 18:25:51 +010090 return _cl_compile_ctx;
91}
92
Viet-Hoa Do3fcf3dc2023-05-17 15:17:48 +010093const MemoryDescriptorMap &GpuWorkloadContext::Impl::mem_map() const
94{
95 return _mem_map;
96}
97
98void GpuWorkloadContext::Impl::register_user_tensor(ITensorInfo &tensor_info)
99{
100 ARM_COMPUTE_ERROR_ON(tensor_info.has_valid_id());
101
102 const auto tensor_id = next_tensor_id();
103
104 tensor_info.set_id(tensor_id);
105 _mem_map[tensor_id] = MemoryDescriptor{ MemoryType::User };
106}
107
108void GpuWorkloadContext::Impl::register_aux_tensor(ITensorInfo &tensor_info, const AuxMemoryInfo &mem_info)
109{
110 ARM_COMPUTE_ERROR_ON(tensor_info.has_valid_id());
111
112 const auto tensor_id = next_tensor_id();
113
114 tensor_info.set_id(tensor_id);
115 _mem_map[tensor_id] = MemoryDescriptor{ MemoryType::Auxiliary, mem_info };
116}
117
118void GpuWorkloadContext::Impl::register_virtual_tensor(ITensorInfo &tensor_info)
119{
120 ARM_COMPUTE_ERROR_ON(tensor_info.has_valid_id());
121
122 const auto tensor_id = -next_tensor_id();
123
124 tensor_info.set_id(tensor_id);
125 _mem_map[tensor_id] = MemoryDescriptor{ MemoryType::Virtual };
126}
127
128ITensorInfo::Id GpuWorkloadContext::Impl::next_tensor_id()
129{
130 return _next_tensor_id++;
131}
132
SiCong Lif44bbc52022-08-29 18:25:51 +0100133} // namespace dynamic_fusion
134} // namespace experimental
135} // namespace arm_compute