blob: b6e9a29df4ccb47b944194da230d6a8c07d356da [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Georgios Pinitas652bde52018-01-10 15:33:28 +00002 * Copyright (c) 2017-2018 ARM Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +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 */
24#ifndef __ARM_COMPUTE_CLSUBTENSOR_H__
25#define __ARM_COMPUTE_CLSUBTENSOR_H__
26
27#include "arm_compute/core/SubTensorInfo.h"
28#include "arm_compute/runtime/CL/CLTensor.h"
29
30#include <cstdint>
31
32namespace arm_compute
33{
34class ITensorInfo;
35
36/** Basic implementation of the OpenCL sub-tensor interface */
37class CLSubTensor : public ICLTensor
38{
39public:
40 /** Constructor
41 *
Georgios Pinitas652bde52018-01-10 15:33:28 +000042 * @param[in] parent Parent tensor
43 * @param[in] tensor_shape Shape of the subtensor
44 * @param[in] coords Coordinates of the first subtensor element inside the parent tensor.
45 * @param[in] extend_parent (Optional) Extend parent with subtensor shape if subtensor indexes out of bounds
Anthony Barbier6ff3b192017-09-04 18:44:23 +010046 */
Georgios Pinitas652bde52018-01-10 15:33:28 +000047 CLSubTensor(ICLTensor *parent, const TensorShape &tensor_shape, const Coordinates &coords, bool extend_parent = false);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010048 /** Destructor: free the tensor's memory */
49 ~CLSubTensor() = default;
50 /** Restrict instances of this class to be copy constructed */
51 CLSubTensor(const CLSubTensor &) = delete;
52 /** Restrict instances of this class to be copied */
53 CLSubTensor &operator=(const CLSubTensor &) = delete;
54 /** Allow instances of this class to be move constructed */
55 CLSubTensor(CLSubTensor &&) = default;
56 /** Allow instances of this class to be moved */
57 CLSubTensor &operator=(CLSubTensor &&) = default;
58
59 /** Enqueue a map operation of the allocated buffer.
60 *
61 * @note Mapping a subtensor will lead to the mapping of the whole parent tensor for now.
62 *
63 * @param[in] blocking If true, then the mapping will be ready to use by the time
64 * this method returns, else it is the caller's responsibility
65 * to flush the queue and wait for the mapping operation to have completed.
66 */
67 void map(bool blocking = true);
68 using ICLTensor::map;
69 /** Enqueue an unmap operation of the allocated and mapped buffer.
70 *
71 * @note Unmapping a subtensor will lead to the unmapping of the whole parent tensor for now.
72 *
73 * @note This method simply enqueues the unmap operation, it is the caller's responsibility to flush the queue and make sure the unmap is finished before
74 * the memory is accessed by the device.
75 */
76 void unmap();
77 using ICLTensor::unmap;
78
79 /** Return the parent tensor of the subtensor
80 *
81 * @return Parent tensor
82 */
83 ICLTensor *parent();
84
85 // Inherited methods overridden:
86 ITensorInfo *info() const override;
87 ITensorInfo *info() override;
88 const cl::Buffer &cl_buffer() const override;
89
90protected:
91 // Inherited methods overridden:
92 uint8_t *do_map(cl::CommandQueue &q, bool blocking) override;
93 void do_unmap(cl::CommandQueue &q) override;
94
95private:
96 ICLTensor *_parent;
97 mutable SubTensorInfo _info;
98};
99}
100#endif /*__ARM_COMPUTE_CLSUBTENSOR_H__ */