blob: 0565950fe06c93248502a17ce2bb8f393970e952 [file] [log] [blame]
Anthony Barbier7068f992017-10-26 15:23:08 +01001/*
Georgios Pinitas26014cf2019-09-09 19:00:57 +01002 * 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 */
24
Michalis Spyrouf4643372019-11-29 16:17:13 +000025#ifndef ARM_COMPUTE_GCTENSOR_H
26#define ARM_COMPUTE_GCTENSOR_H
Anthony Barbier7068f992017-10-26 15:23:08 +010027
28#include "arm_compute/core/GLES_COMPUTE/IGCTensor.h"
29#include "arm_compute/runtime/GLES_COMPUTE/GCTensorAllocator.h"
30
31namespace arm_compute
32{
33class ITensorAllocator;
34class ITensorInfo;
Pablo Tellodb8485a2019-09-24 11:03:47 +010035class IRuntimeContext;
Anthony Barbier7068f992017-10-26 15:23:08 +010036
37/** Interface for OpenGL ES tensor */
Georgios Pinitas26014cf2019-09-09 19:00:57 +010038class GCTensor : public IGCTensor, public IMemoryManageable
Anthony Barbier7068f992017-10-26 15:23:08 +010039{
40public:
Pablo Tellodb8485a2019-09-24 11:03:47 +010041 /** Default constructor
42 *
43 * @param[in] ctx (Optional) Pointer to the runtime context.
44 *
45 */
46 GCTensor(IRuntimeContext *ctx = nullptr);
Anthony Barbier7068f992017-10-26 15:23:08 +010047
Alex Gildayc357c472018-03-21 13:54:09 +000048 /** Prevent instances of this class from being copied (As this class contains pointers) */
Anthony Barbier7068f992017-10-26 15:23:08 +010049 GCTensor(const GCTensor &) = delete;
50
Alex Gildayc357c472018-03-21 13:54:09 +000051 /** Prevent instances of this class from being copy assigned (As this class contains pointers) */
Anthony Barbier7068f992017-10-26 15:23:08 +010052 GCTensor &operator=(const GCTensor &) = delete;
53
54 /** Allow instances of this class to be moved */
55 GCTensor(GCTensor &&) = default;
56
57 /** Allow instances of this class to be moved */
58 GCTensor &operator=(GCTensor &&) = default;
59
60 /** Virtual destructor */
61 virtual ~GCTensor() = default;
62
63 /** Return a pointer to the tensor's allocator
64 *
65 * @return A pointer to the tensor's allocator
66 */
67 ITensorAllocator *allocator();
68
69 /** Enqueue a map operation of the allocated buffer on the given queue.
70 *
71 * @param[in] blocking (Optional) If true, then the mapping will be ready to use by the time
72 * this method returns, else it is the caller's responsibility
73 * to flush the queue and wait for the mapping operation to have completed before using the returned mapping pointer.
74 *
75 * @return The mapping address.
76 */
77 void map(bool blocking = true);
78
79 /** Enqueue an unmap operation of the allocated and mapped buffer on the given queue.
80 *
81 * @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
82 * the memory is accessed by the device.
83 *
84 */
85 void unmap();
86
87 // Inherited methods overridden:
88 TensorInfo *info() const override;
89 TensorInfo *info() override;
90 uint8_t *buffer() const override;
91 GLuint gc_buffer() const override;
Georgios Pinitas26014cf2019-09-09 19:00:57 +010092 void associate_memory_group(IMemoryGroup *memory_group) override;
Anthony Barbier7068f992017-10-26 15:23:08 +010093
94protected:
95 // Inherited methods overridden:
96 uint8_t *do_map(bool blocking) override;
97 void do_unmap() override;
98
99private:
Michalis Spyrou9e9cbaf2018-03-15 14:41:34 +0000100 mutable GCTensorAllocator _allocator; /**< Instance of the OpenGL ES tensor allocator */
Anthony Barbier7068f992017-10-26 15:23:08 +0100101};
102
Alex Gildayc357c472018-03-21 13:54:09 +0000103/** OpenGL ES Image */
Anthony Barbier7068f992017-10-26 15:23:08 +0100104using GCImage = GCTensor;
Georgios Pinitas26014cf2019-09-09 19:00:57 +0100105} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000106#endif /*ARM_COMPUTE_GCTENSOR_H */