blob: c18df8086a0deca43b58e7b2f09925437918eb02 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-2019 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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_CLSUBTENSOR_H
25#define ARM_COMPUTE_CLSUBTENSOR_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
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:
Georgios Pinitasd8734b52017-12-22 15:27:52 +000040 /** Default Constructor */
41 CLSubTensor();
Anthony Barbier6ff3b192017-09-04 18:44:23 +010042 /** Constructor
43 *
Georgios Pinitas652bde52018-01-10 15:33:28 +000044 * @param[in] parent Parent tensor
45 * @param[in] tensor_shape Shape of the subtensor
46 * @param[in] coords Coordinates of the first subtensor element inside the parent tensor.
47 * @param[in] extend_parent (Optional) Extend parent with subtensor shape if subtensor indexes out of bounds
Anthony Barbier6ff3b192017-09-04 18:44:23 +010048 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010049 CLSubTensor(ICLTensor *parent,
50 const TensorShape &tensor_shape,
51 const Coordinates &coords,
52 bool extend_parent = false);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010053 /** Destructor: free the tensor's memory */
54 ~CLSubTensor() = default;
55 /** Restrict instances of this class to be copy constructed */
56 CLSubTensor(const CLSubTensor &) = delete;
57 /** Restrict instances of this class to be copied */
58 CLSubTensor &operator=(const CLSubTensor &) = delete;
59 /** Allow instances of this class to be move constructed */
60 CLSubTensor(CLSubTensor &&) = default;
61 /** Allow instances of this class to be moved */
62 CLSubTensor &operator=(CLSubTensor &&) = default;
63
64 /** Enqueue a map operation of the allocated buffer.
65 *
66 * @note Mapping a subtensor will lead to the mapping of the whole parent tensor for now.
67 *
68 * @param[in] blocking If true, then the mapping will be ready to use by the time
69 * this method returns, else it is the caller's responsibility
70 * to flush the queue and wait for the mapping operation to have completed.
71 */
72 void map(bool blocking = true);
73 using ICLTensor::map;
74 /** Enqueue an unmap operation of the allocated and mapped buffer.
75 *
76 * @note Unmapping a subtensor will lead to the unmapping of the whole parent tensor for now.
77 *
78 * @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
79 * the memory is accessed by the device.
80 */
81 void unmap();
82 using ICLTensor::unmap;
83
84 /** Return the parent tensor of the subtensor
85 *
86 * @return Parent tensor
87 */
88 ICLTensor *parent();
89
90 // Inherited methods overridden:
91 ITensorInfo *info() const override;
92 ITensorInfo *info() override;
93 const cl::Buffer &cl_buffer() const override;
Georgios Pinitas4c5469b2019-05-21 13:32:43 +010094 CLQuantization quantization() const override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010095
96protected:
97 // Inherited methods overridden:
98 uint8_t *do_map(cl::CommandQueue &q, bool blocking) override;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010099 void do_unmap(cl::CommandQueue &q) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100100
101private:
102 ICLTensor *_parent;
103 mutable SubTensorInfo _info;
104};
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100105} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000106#endif /*ARM_COMPUTE_CLSUBTENSOR_H */