Compute Library
 21.02
GCTensor.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2019 Arm Limited.
3  *
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 
25 #ifndef ARM_COMPUTE_GCTENSOR_H
26 #define ARM_COMPUTE_GCTENSOR_H
27 
30 
31 namespace arm_compute
32 {
33 class ITensorAllocator;
34 class ITensorInfo;
35 class IRuntimeContext;
36 
37 /** Interface for OpenGL ES tensor */
38 class GCTensor : public IGCTensor, public IMemoryManageable
39 {
40 public:
41  /** Default constructor
42  *
43  * @param[in] ctx (Optional) Pointer to the runtime context.
44  *
45  */
46  GCTensor(IRuntimeContext *ctx = nullptr);
47 
48  /** Prevent instances of this class from being copied (As this class contains pointers) */
49  GCTensor(const GCTensor &) = delete;
50 
51  /** Prevent instances of this class from being copy assigned (As this class contains pointers) */
52  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  */
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;
92  void associate_memory_group(IMemoryGroup *memory_group) override;
93 
94 protected:
95  // Inherited methods overridden:
96  uint8_t *do_map(bool blocking) override;
97  void do_unmap() override;
98 
99 private:
100  mutable GCTensorAllocator _allocator; /**< Instance of the OpenGL ES tensor allocator */
101 };
102 
103 /** OpenGL ES Image */
105 } // namespace arm_compute
106 #endif /*ARM_COMPUTE_GCTENSOR_H */
Memory group interface.
Definition: IMemoryGroup.h:37
void associate_memory_group(IMemoryGroup *memory_group) override
Associates a memory managable object with the memory group that manages it.
Definition: GCTensor.cpp:59
Basic implementation of a GLES memory tensor allocator.
Interface for GLES Compute tensor.
Definition: IGCTensor.h:35
GCTensor & operator=(const GCTensor &)=delete
Prevent instances of this class from being copy assigned (As this class contains pointers) ...
GCTensor(IRuntimeContext *ctx=nullptr)
Default constructor.
Definition: GCTensor.cpp:29
Interface for OpenGL ES tensor.
Definition: GCTensor.h:38
Copyright (c) 2017-2021 Arm Limited.
virtual ~GCTensor()=default
Virtual destructor.
GLuint gc_buffer() const override
Interface to be implemented by the child class to return the tensor&#39;s gles compute buffer id...
Definition: GCTensor.cpp:54
uint8_t * buffer() const override
Interface to be implemented by the child class to return a pointer to CPU memory. ...
Definition: GCTensor.cpp:49
void unmap()
Enqueue an unmap operation of the allocated and mapped buffer on the given queue. ...
Definition: GCTensor.cpp:69
Interface of an object than can be memory managed.
Definition: IMemoryGroup.h:69
TensorInfo * info() const override
Interface to be implemented by the child class to return the tensor&#39;s metadata.
Definition: GCTensor.cpp:39
void map(bool blocking=true)
Enqueue a map operation of the allocated buffer on the given queue.
Definition: GCTensor.cpp:64
Store the tensor&#39;s metadata.
Definition: TensorInfo.h:45
Interface to allocate tensors.
ITensorAllocator * allocator()
Return a pointer to the tensor&#39;s allocator.
Definition: GCTensor.cpp:34