1 /*
2 * Copyright (c) 2021 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 #include "src/gpu/cl/ClTensor.h"
25
26 #include "src/common/utils/LegacySupport.h"
27
28 namespace arm_compute
29 {
30 namespace gpu
31 {
32 namespace opencl
33 {
ClTensor(IContext * ctx,const AclTensorDescriptor & desc)34 ClTensor::ClTensor(IContext *ctx, const AclTensorDescriptor &desc)
35 : ITensorV2(ctx), _legacy_tensor()
36 {
37 ARM_COMPUTE_ASSERT((ctx != nullptr) && (ctx->type() == Target::GpuOcl));
38 _legacy_tensor = std::make_unique<CLTensor>();
39 _legacy_tensor->allocator()->init(arm_compute::detail::convert_to_legacy_tensor_info(desc));
40 }
41
map()42 void *ClTensor::map()
43 {
44 ARM_COMPUTE_ASSERT(_legacy_tensor.get() != nullptr);
45
46 if(_legacy_tensor == nullptr)
47 {
48 ARM_COMPUTE_LOG_ERROR_ACL("[ClTensor:map]: Backing tensor does not exist!");
49 return nullptr;
50 }
51
52 _legacy_tensor->map();
53 return _legacy_tensor->buffer();
54 }
55
unmap()56 StatusCode ClTensor::unmap()
57 {
58 ARM_COMPUTE_ASSERT(_legacy_tensor.get() != nullptr);
59
60 if(_legacy_tensor == nullptr)
61 {
62 ARM_COMPUTE_LOG_ERROR_ACL("[ClTensor:unmap]: Backing tensor does not exist!");
63 return StatusCode::RuntimeError;
64 }
65 _legacy_tensor->unmap();
66
67 return StatusCode::Success;
68 }
69
allocate()70 StatusCode ClTensor::allocate()
71 {
72 ARM_COMPUTE_ASSERT(_legacy_tensor.get() != nullptr);
73
74 _legacy_tensor->allocator()->allocate();
75 return StatusCode::Success;
76 }
77
import(void * handle,ImportMemoryType type)78 StatusCode ClTensor::import(void *handle, ImportMemoryType type)
79 {
80 ARM_COMPUTE_ASSERT(_legacy_tensor.get() != nullptr);
81 ARM_COMPUTE_UNUSED(type, handle);
82
83 return StatusCode::Success;
84 }
85
tensor() const86 arm_compute::ITensor *ClTensor::tensor() const
87 {
88 return _legacy_tensor.get();
89 }
90 } // namespace opencl
91 } // namespace gpu
92 } // namespace arm_compute
93