blob: c382095846244156caa9cfa988848e75d865a436 [file] [log] [blame]
Anthony Barbier7068f992017-10-26 15:23:08 +01001/*
Michalis Spyrouf4643372019-11-29 16:17:13 +00002 * Copyright (c) 2017-2019 ARM Limited.
Anthony Barbier7068f992017-10-26 15:23:08 +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_IGCTENSOR_H
25#define ARM_COMPUTE_IGCTENSOR_H
Anthony Barbier7068f992017-10-26 15:23:08 +010026
27#include "arm_compute/core/GLES_COMPUTE/OpenGLES.h"
28#include "arm_compute/core/ITensor.h"
29
30#include <cstdint>
31
32namespace arm_compute
33{
34/** Interface for GLES Compute tensor */
35class IGCTensor : public ITensor
36{
37public:
38 /** Default constructor. */
39 IGCTensor();
40
Alex Gildayc357c472018-03-21 13:54:09 +000041 /** Prevent instances of this class from being copied (As this class contains pointers) */
Anthony Barbier7068f992017-10-26 15:23:08 +010042 IGCTensor(const IGCTensor &) = delete;
43
Alex Gildayc357c472018-03-21 13:54:09 +000044 /** Prevent instances of this class from being copy assigned (As this class contains pointers) */
Anthony Barbier7068f992017-10-26 15:23:08 +010045 IGCTensor &operator=(const IGCTensor &) = delete;
46
47 /** Allow instances of this class to be moved */
48 IGCTensor(IGCTensor &&) = default;
49
50 /** Allow instances of this class to be moved */
51 IGCTensor &operator=(IGCTensor &&) = default;
52
53 /** Virtual destructor */
54 virtual ~IGCTensor() = default;
55
56 /** Map on an allocated buffer.
57 *
58 * @param[in] blocking (Optional) If true, then the mapping will be ready to use by the time
59 * this method returns, else it is the caller's responsibility
60 * to flush the queue and wait for the mapping operation to have completed before using the returned mapping pointer.
61 */
62 void map(bool blocking = true);
63 /** Unmap an allocated and mapped buffer.
64 */
65 void unmap();
66 /** Clear the contents of the tensor synchronously.
67 */
68 void clear();
69
70 // Inherited methods overridden:
71 uint8_t *buffer() const override;
72 /** Interface to be implemented by the child class to return the tensor's gles compute buffer id.
73 *
74 * @return A SSBO buffer id.
75 */
76 virtual GLuint gc_buffer() const = 0;
77
Frank Lei4406fd62018-02-01 14:47:14 +080078 /** Flag indicating whether the tensor has been left aligned by a kernel and therefore needs shifting.
79 *
80 * @return True if the tensor is left aligned.
81 */
82 bool needs_shifting() const;
83 /** Set the flag indicating whether or not a tensor needs shifting.
84 *
85 * @param[in] needs_shifting Indicates if the tensor is left aligned or not.
86 *
87 */
88 void set_needs_shifting(bool needs_shifting);
89
Anthony Barbier7068f992017-10-26 15:23:08 +010090protected:
91 /** Method to be implemented by the child class to map the SSBO.
92 *
93 * @param[in] blocking If true, then the mapping will be ready to use by the time
94 * this method returns, else it is the caller's responsibility
95 * to flush the queue and wait for the mapping operation to have completed before using the returned mapping pointer.
96 */
97 virtual uint8_t *do_map(bool blocking) = 0;
98 /** Method to be implemented by the child class to unmap the SSBO.
99 *
100 * @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
101 * the memory is accessed by the device.
102 */
103 virtual void do_unmap() = 0;
104
105private:
106 uint8_t *_mapping;
Frank Lei4406fd62018-02-01 14:47:14 +0800107 bool _needs_shifting;
Anthony Barbier7068f992017-10-26 15:23:08 +0100108};
109
Alex Gildayc357c472018-03-21 13:54:09 +0000110/** Interface for GLES Compute image */
Anthony Barbier7068f992017-10-26 15:23:08 +0100111using IGCImage = IGCTensor;
112}
Michalis Spyrouf4643372019-11-29 16:17:13 +0000113#endif /*ARM_COMPUTE_IGCTENSOR_H */