Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016, 2017 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 | #ifndef __ARM_COMPUTE_ICLARRAY_H__ |
| 25 | #define __ARM_COMPUTE_ICLARRAY_H__ |
| 26 | |
| 27 | #include "arm_compute/core/CL/OpenCL.h" |
| 28 | #include "arm_compute/core/IArray.h" |
| 29 | #include "arm_compute/core/ITensor.h" |
| 30 | |
| 31 | namespace arm_compute |
| 32 | { |
| 33 | /** Interface for OpenCL Array */ |
| 34 | template <class T> |
| 35 | class ICLArray : public IArray<T> |
| 36 | { |
| 37 | public: |
| 38 | /* Constructor */ |
| 39 | explicit ICLArray(size_t max_num_values) |
| 40 | : IArray<T>(max_num_values), _mapping(nullptr) |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | ICLArray(const ICLArray &) = delete; |
| 45 | ICLArray &operator=(const ICLArray &) = delete; |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame^] | 46 | ICLArray(ICLArray &&) = default; |
| 47 | ICLArray &operator=(ICLArray &&) = default; |
| 48 | virtual ~ICLArray() = default; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 49 | /** Interface to be implemented by the child class to return a reference to the OpenCL buffer containing the array's data. |
| 50 | * |
| 51 | * @return A reference to an OpenCL buffer containing the array's data. |
| 52 | */ |
| 53 | virtual const cl::Buffer &cl_buffer() const = 0; |
| 54 | /** Enqueue a map operation of the allocated buffer on the given queue. |
| 55 | * |
| 56 | * @param[in,out] q The CL command queue to use for the mapping operation. |
| 57 | * @param[in] blocking If true, then the mapping will be ready to use by the time |
| 58 | * this method returns, else it is the caller's responsibility |
| 59 | * to flush the queue and wait for the mapping operation to have completed before using the returned mapping pointer. |
| 60 | * |
| 61 | * @return The mapping address. |
| 62 | */ |
| 63 | void map(cl::CommandQueue &q, bool blocking = true) |
| 64 | { |
| 65 | _mapping = do_map(q, blocking); |
| 66 | } |
| 67 | /** Enqueue an unmap operation of the allocated and mapped buffer on the given queue. |
| 68 | * |
| 69 | * @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 |
| 70 | * the memory is accessed by the device. |
| 71 | * |
| 72 | * @param[in,out] q The CL command queue to use for the mapping operation. |
| 73 | */ |
| 74 | void unmap(cl::CommandQueue &q) |
| 75 | { |
| 76 | do_unmap(q, _mapping); |
| 77 | _mapping = nullptr; |
| 78 | } |
| 79 | |
| 80 | // Inherited methods overridden: |
| 81 | T *buffer() const override |
| 82 | { |
| 83 | return reinterpret_cast<T *>(_mapping); |
| 84 | } |
| 85 | |
| 86 | protected: |
| 87 | /** Method to be implemented by the child class to map the OpenCL buffer |
| 88 | * |
| 89 | * @param[in,out] q The CL command queue to use for the mapping operation. |
| 90 | * @param[in] blocking If true, then the mapping will be ready to use by the time |
| 91 | * this method returns, else it is the caller's responsibility |
| 92 | * to flush the queue and wait for the mapping operation to have completed before using the returned mapping pointer. |
| 93 | */ |
| 94 | virtual uint8_t *do_map(cl::CommandQueue &q, bool blocking) = 0; |
| 95 | /** Method to be implemented by the child class to unmap the OpenCL buffer |
| 96 | * |
| 97 | * @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 |
| 98 | * the memory is accessed by the device. |
| 99 | * |
| 100 | * @param[in,out] q The CL command queue to use for the mapping operation. |
| 101 | * @param[in] mapping Pointer to the buffer to be unmapped. |
| 102 | */ |
| 103 | virtual void do_unmap(cl::CommandQueue &q, uint8_t *mapping) = 0; |
| 104 | |
| 105 | private: |
| 106 | uint8_t *_mapping; |
| 107 | }; |
| 108 | |
| 109 | using ICLKeyPointArray = ICLArray<KeyPoint>; |
| 110 | using ICLCoordinates2DArray = ICLArray<Coordinates2D>; |
| 111 | using ICLDetectionWindowArray = ICLArray<DetectionWindow>; |
SiCong Li | 3e36369 | 2017-07-04 15:02:10 +0100 | [diff] [blame] | 112 | using ICLROIArray = ICLArray<ROI>; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 113 | using ICLSize2DArray = ICLArray<Size2D>; |
| 114 | using ICLUInt8Array = ICLArray<cl_uchar>; |
| 115 | using ICLUInt16Array = ICLArray<cl_ushort>; |
| 116 | using ICLUInt32Array = ICLArray<cl_uint>; |
| 117 | using ICLInt16Array = ICLArray<cl_short>; |
| 118 | using ICLInt32Array = ICLArray<cl_int>; |
| 119 | using ICLFloatArray = ICLArray<cl_float>; |
| 120 | } |
| 121 | #endif /*__ARM_COMPUTE_ICLARRAY_H__*/ |