blob: 98dd28f43d3da1e0d79a1bcab37486424b766ca3 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Georgios Pinitas4c5469b2019-05-21 13:32:43 +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 */
Georgios Pinitas652bde52018-01-10 15:33:28 +000049 CLSubTensor(ICLTensor *parent, const TensorShape &tensor_shape, const Coordinates &coords, bool extend_parent = false);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010050 /** Destructor: free the tensor's memory */
51 ~CLSubTensor() = default;
52 /** Restrict instances of this class to be copy constructed */
53 CLSubTensor(const CLSubTensor &) = delete;
54 /** Restrict instances of this class to be copied */
55 CLSubTensor &operator=(const CLSubTensor &) = delete;
56 /** Allow instances of this class to be move constructed */
57 CLSubTensor(CLSubTensor &&) = default;
58 /** Allow instances of this class to be moved */
59 CLSubTensor &operator=(CLSubTensor &&) = default;
60
61 /** Enqueue a map operation of the allocated buffer.
62 *
63 * @note Mapping a subtensor will lead to the mapping of the whole parent tensor for now.
64 *
65 * @param[in] blocking If true, then the mapping will be ready to use by the time
66 * this method returns, else it is the caller's responsibility
67 * to flush the queue and wait for the mapping operation to have completed.
68 */
69 void map(bool blocking = true);
70 using ICLTensor::map;
71 /** Enqueue an unmap operation of the allocated and mapped buffer.
72 *
73 * @note Unmapping a subtensor will lead to the unmapping of the whole parent tensor for now.
74 *
75 * @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
76 * the memory is accessed by the device.
77 */
78 void unmap();
79 using ICLTensor::unmap;
80
81 /** Return the parent tensor of the subtensor
82 *
83 * @return Parent tensor
84 */
85 ICLTensor *parent();
86
87 // Inherited methods overridden:
88 ITensorInfo *info() const override;
89 ITensorInfo *info() override;
90 const cl::Buffer &cl_buffer() const override;
Georgios Pinitas4c5469b2019-05-21 13:32:43 +010091 CLQuantization quantization() const override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010092
93protected:
94 // Inherited methods overridden:
95 uint8_t *do_map(cl::CommandQueue &q, bool blocking) override;
96 void do_unmap(cl::CommandQueue &q) override;
97
98private:
99 ICLTensor *_parent;
100 mutable SubTensorInfo _info;
101};
102}
Michalis Spyrouf4643372019-11-29 16:17:13 +0000103#endif /*ARM_COMPUTE_CLSUBTENSOR_H */