Compute Library
 22.05
ClTensor.cpp
Go to the documentation of this file.
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 
27 
28 namespace arm_compute
29 {
30 namespace gpu
31 {
32 namespace opencl
33 {
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 
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 
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!");
64  }
65  _legacy_tensor->unmap();
66 
67  return StatusCode::Success;
68 }
69 
71 {
72  ARM_COMPUTE_ASSERT(_legacy_tensor.get() != nullptr);
73 
74  _legacy_tensor->allocator()->allocate();
75  return StatusCode::Success;
76 }
77 
79 {
80  ARM_COMPUTE_ASSERT(_legacy_tensor.get() != nullptr);
81  ARM_COMPUTE_UNUSED(type, handle);
82 
83  return StatusCode::Success;
84 }
85 
87 {
88  return _legacy_tensor.get();
89 }
90 } // namespace opencl
91 } // namespace gpu
92 } // namespace arm_compute
StatusCode unmap() override
Unmap tensor.
Definition: ClTensor.cpp:56
#define ARM_COMPUTE_ASSERT(cond)
Definition: Validate.h:37
StatusCode import(void *handle, ImportMemoryType type) override
Import external memory handle.
Definition: ClTensor.cpp:78
Base class specifying the tensor interface.
Definition: ITensorV2.h:45
arm_compute::ITensor * tensor() const override
Get the legacy tensor object.
Definition: ClTensor.cpp:86
TensorInfo convert_to_legacy_tensor_info(const AclTensorDescriptor &desc)
Convert a descriptor to a legacy format one.
void * map() override
Map tensor to a host pointer.
Definition: ClTensor.cpp:42
#define ARM_COMPUTE_LOG_ERROR_ACL(msg)
Log an error message to the logger.
Definition: Log.h:77
StatusCode allocate()
Allocates tensor.
Definition: ClTensor.cpp:70
Context interface.
Definition: IContext.h:50
decltype(strategy::transforms) typedef type
Interface for CPU tensor.
Definition: ITensor.h:36
Copyright (c) 2017-2022 Arm Limited.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
StatusCode
Definition: Types.h:32
Target type() const
Target type accessor.
Definition: IContext.h:66
ImportMemoryType
Definition: Types.h:57
ClTensor(IContext *ctx, const AclTensorDescriptor &desc)
Construct a new OpenCL Tensor object.
Definition: ClTensor.cpp:34