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 28 #include "arm_compute/core/GLES_COMPUTE/IGCTensor.h" 29 #include "arm_compute/runtime/GLES_COMPUTE/GCTensorAllocator.h" 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 */ 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; 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 */ 104 using GCImage = GCTensor; 105 } // namespace arm_compute 106 #endif /*ARM_COMPUTE_GCTENSOR_H */ 107