Compute Library
 20.08
CLSubTensor.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2019 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  */
25 
27 #include "arm_compute/core/Error.h"
29 
30 using namespace arm_compute;
31 
33  : _parent(nullptr), _info()
34 {
35 }
36 
37 CLSubTensor::CLSubTensor(ICLTensor *parent, const TensorShape &tensor_shape, const Coordinates &coords, bool extend_parent)
38  : _parent(nullptr), _info()
39 {
40  ARM_COMPUTE_ERROR_ON(parent == nullptr);
41  _info = SubTensorInfo(parent->info(), tensor_shape, coords, extend_parent);
42  _parent = parent;
43 }
44 
46 {
47  return &_info;
48 }
49 
51 {
52  return &_info;
53 }
54 
55 const cl::Buffer &CLSubTensor::cl_buffer() const
56 {
57  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
58  return _parent->cl_buffer();
59 }
60 
62 {
63  return _parent->quantization();
64 }
65 
67 {
68  return _parent;
69 }
70 
71 void CLSubTensor::map(bool blocking)
72 {
73  ICLTensor::map(CLScheduler::get().queue(), blocking);
74 }
75 
77 {
79 }
80 
81 uint8_t *CLSubTensor::do_map(cl::CommandQueue &q, bool blocking)
82 {
83  ARM_COMPUTE_ERROR_ON(cl_buffer().get() == nullptr);
84  return static_cast<uint8_t *>(q.enqueueMapBuffer(cl_buffer(), blocking ? CL_TRUE : CL_FALSE, CL_MAP_READ | CL_MAP_WRITE, 0, info()->total_size()));
85 }
86 
87 void CLSubTensor::do_unmap(cl::CommandQueue &q)
88 {
89  ARM_COMPUTE_ERROR_ON(cl_buffer().get() == nullptr);
90  q.enqueueUnmapMemObject(cl_buffer(), buffer());
91 }
void map(cl::CommandQueue &q, bool blocking=true)
Enqueue a map operation of the allocated buffer on the given queue.
Definition: ICLTensor.cpp:35
Shape of a tensor.
Definition: TensorShape.h:39
void map(bool blocking=true)
Enqueue a map operation of the allocated buffer.
Definition: CLSubTensor.cpp:71
static CLScheduler & get()
Access the scheduler singleton.
Definition: CLScheduler.cpp:99
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
Store the tensor's metadata.
Definition: ITensorInfo.h:40
OpenCL quantization data.
Definition: CLTypes.h:62
Store the sub tensor's metadata.
Definition: SubTensorInfo.h:42
Copyright (c) 2017-2020 Arm Limited.
CLSubTensor()
Default Constructor.
Definition: CLSubTensor.cpp:32
uint8_t * buffer() const override
Interface to be implemented by the child class to return a pointer to CPU memory.
Definition: ICLTensor.cpp:53
CLQuantization quantization() const override
Interface to be implemented by the child class to return the wrapped quantization info data.
Definition: CLSubTensor.cpp:61
void unmap(cl::CommandQueue &q)
Enqueue an unmap operation of the allocated and mapped buffer on the given queue.
Definition: ICLTensor.cpp:40
Coordinates of an item.
Definition: Coordinates.h:37
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
ICLTensor * parent()
Return the parent tensor of the subtensor.
Definition: CLSubTensor.cpp:66
ITensorInfo * info() const override
Interface to be implemented by the child class to return the tensor's metadata.
Definition: CLSubTensor.cpp:45
Interface for OpenCL tensor.
Definition: ICLTensor.h:42
void unmap()
Enqueue an unmap operation of the allocated and mapped buffer.
Definition: CLSubTensor.cpp:76
const cl::Buffer & cl_buffer() const override
Interface to be implemented by the child class to return a reference to the OpenCL buffer containing ...
Definition: CLSubTensor.cpp:55
virtual const cl::Buffer & cl_buffer() const =0
Interface to be implemented by the child class to return a reference to the OpenCL buffer containing ...
virtual CLQuantization quantization() const =0
Interface to be implemented by the child class to return the wrapped quantization info data.