Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 Arm Limited. |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_IGCTENSOR_H |
| 25 | #define ARM_COMPUTE_IGCTENSOR_H |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/core/GLES_COMPUTE/OpenGLES.h" |
| 28 | #include "arm_compute/core/ITensor.h" |
| 29 | |
| 30 | #include <cstdint> |
| 31 | |
| 32 | namespace arm_compute |
| 33 | { |
| 34 | /** Interface for GLES Compute tensor */ |
| 35 | class IGCTensor : public ITensor |
| 36 | { |
| 37 | public: |
| 38 | /** Default constructor. */ |
| 39 | IGCTensor(); |
| 40 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 41 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 42 | IGCTensor(const IGCTensor &) = delete; |
| 43 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 44 | /** Prevent instances of this class from being copy assigned (As this class contains pointers) */ |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 45 | 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 Lei | 4406fd6 | 2018-02-01 14:47:14 +0800 | [diff] [blame] | 78 | /** 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 Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 90 | protected: |
| 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 | |
| 105 | private: |
| 106 | uint8_t *_mapping; |
Frank Lei | 4406fd6 | 2018-02-01 14:47:14 +0800 | [diff] [blame] | 107 | bool _needs_shifting; |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 108 | }; |
| 109 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 110 | /** Interface for GLES Compute image */ |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 111 | using IGCImage = IGCTensor; |
| 112 | } |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 113 | #endif /*ARM_COMPUTE_IGCTENSOR_H */ |