SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 1 | /* |
Viet-Hoa Do | 3fcf3dc | 2023-05-17 15:17:48 +0100 | [diff] [blame^] | 2 | * Copyright (c) 2022-2023 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 | 3fcf3dc | 2023-05-17 15:17:48 +0100 | [diff] [blame^] | 24 | |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 25 | #include "arm_compute/dynamic_fusion/sketch/gpu/GpuWorkloadContext.h" |
| 26 | #include "arm_compute/core/CL/CLCompileContext.h" |
Viet-Hoa Do | 3fcf3dc | 2023-05-17 15:17:48 +0100 | [diff] [blame^] | 27 | #include "src/dynamic_fusion/sketch/gpu/GpuWorkloadContextImpl.h" |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 28 | |
| 29 | namespace arm_compute |
| 30 | { |
| 31 | namespace experimental |
| 32 | { |
| 33 | namespace dynamic_fusion |
| 34 | { |
Viet-Hoa Do | 3fcf3dc | 2023-05-17 15:17:48 +0100 | [diff] [blame^] | 35 | |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 36 | GpuWorkloadContext::GpuWorkloadContext(CLCompileContext *cl_compile_ctx) |
Viet-Hoa Do | 3fcf3dc | 2023-05-17 15:17:48 +0100 | [diff] [blame^] | 37 | : _impl { std::make_unique<Impl>(GpuLanguage::OpenCL, cl_compile_ctx) } |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 38 | { |
| 39 | } |
| 40 | |
Viet-Hoa Do | 3fcf3dc | 2023-05-17 15:17:48 +0100 | [diff] [blame^] | 41 | GpuWorkloadContext::~GpuWorkloadContext() = default; |
| 42 | |
| 43 | GpuWorkloadContext::GpuWorkloadContext(GpuWorkloadContext &&other) = default; |
| 44 | |
| 45 | GpuWorkloadContext &GpuWorkloadContext::operator=(GpuWorkloadContext &&other) = default; |
| 46 | |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 47 | GpuTarget GpuWorkloadContext::gpu_target() const |
| 48 | { |
Viet-Hoa Do | 3fcf3dc | 2023-05-17 15:17:48 +0100 | [diff] [blame^] | 49 | return _impl->cl_compile_context()->get_gpu_target(); |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | GpuLanguage GpuWorkloadContext::gpu_language() const |
| 53 | { |
Viet-Hoa Do | 3fcf3dc | 2023-05-17 15:17:48 +0100 | [diff] [blame^] | 54 | return _impl->gpu_language(); |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | const CLCompileContext *GpuWorkloadContext::cl_compile_context() const |
| 58 | { |
Viet-Hoa Do | 3fcf3dc | 2023-05-17 15:17:48 +0100 | [diff] [blame^] | 59 | return _impl->cl_compile_context(); |
| 60 | } |
| 61 | |
| 62 | void GpuWorkloadContext::register_user_tensor(ITensorInfo &tensor_info) |
| 63 | { |
| 64 | _impl->register_user_tensor(tensor_info); |
| 65 | } |
| 66 | |
| 67 | GpuWorkloadContext::Impl &GpuWorkloadContext::implementation() |
| 68 | { |
| 69 | return *_impl; |
| 70 | } |
| 71 | |
| 72 | const GpuWorkloadContext::Impl &GpuWorkloadContext::implementation() const |
| 73 | { |
| 74 | return *_impl; |
| 75 | } |
| 76 | |
| 77 | GpuWorkloadContext::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 | |
| 83 | GpuLanguage GpuWorkloadContext::Impl::gpu_language() const |
| 84 | { |
| 85 | return _gpu_language; |
| 86 | } |
| 87 | |
| 88 | const CLCompileContext *GpuWorkloadContext::Impl::cl_compile_context() const |
| 89 | { |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 90 | return _cl_compile_ctx; |
| 91 | } |
| 92 | |
Viet-Hoa Do | 3fcf3dc | 2023-05-17 15:17:48 +0100 | [diff] [blame^] | 93 | const MemoryDescriptorMap &GpuWorkloadContext::Impl::mem_map() const |
| 94 | { |
| 95 | return _mem_map; |
| 96 | } |
| 97 | |
| 98 | void 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 | |
| 108 | void 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 | |
| 118 | void 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 | |
| 128 | ITensorInfo::Id GpuWorkloadContext::Impl::next_tensor_id() |
| 129 | { |
| 130 | return _next_tensor_id++; |
| 131 | } |
| 132 | |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 133 | } // namespace dynamic_fusion |
| 134 | } // namespace experimental |
| 135 | } // namespace arm_compute |