Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 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_CLSUBTENSOR_H__ |
| 25 | #define __ARM_COMPUTE_CLSUBTENSOR_H__ |
| 26 | |
| 27 | #include "arm_compute/core/SubTensorInfo.h" |
| 28 | #include "arm_compute/runtime/CL/CLTensor.h" |
| 29 | |
| 30 | #include <cstdint> |
| 31 | |
| 32 | namespace arm_compute |
| 33 | { |
| 34 | class ITensorInfo; |
| 35 | |
| 36 | /** Basic implementation of the OpenCL sub-tensor interface */ |
| 37 | class CLSubTensor : public ICLTensor |
| 38 | { |
| 39 | public: |
| 40 | /** Constructor |
| 41 | * |
| 42 | * @param[in] parent Parent tensor |
| 43 | * @param[in] tensor_shape Shape of the subtensor |
| 44 | * @param[in] coords Coordinates of the first subtensor element inside the parent tensor. |
| 45 | */ |
| 46 | CLSubTensor(ICLTensor *parent, const TensorShape &tensor_shape, const Coordinates &coords); |
| 47 | /** Destructor: free the tensor's memory */ |
| 48 | ~CLSubTensor() = default; |
| 49 | /** Restrict instances of this class to be copy constructed */ |
| 50 | CLSubTensor(const CLSubTensor &) = delete; |
| 51 | /** Restrict instances of this class to be copied */ |
| 52 | CLSubTensor &operator=(const CLSubTensor &) = delete; |
| 53 | /** Allow instances of this class to be move constructed */ |
| 54 | CLSubTensor(CLSubTensor &&) = default; |
| 55 | /** Allow instances of this class to be moved */ |
| 56 | CLSubTensor &operator=(CLSubTensor &&) = default; |
| 57 | |
| 58 | /** Enqueue a map operation of the allocated buffer. |
| 59 | * |
| 60 | * @note Mapping a subtensor will lead to the mapping of the whole parent tensor for now. |
| 61 | * |
| 62 | * @param[in] blocking If true, then the mapping will be ready to use by the time |
| 63 | * this method returns, else it is the caller's responsibility |
| 64 | * to flush the queue and wait for the mapping operation to have completed. |
| 65 | */ |
| 66 | void map(bool blocking = true); |
| 67 | using ICLTensor::map; |
| 68 | /** Enqueue an unmap operation of the allocated and mapped buffer. |
| 69 | * |
| 70 | * @note Unmapping a subtensor will lead to the unmapping of the whole parent tensor for now. |
| 71 | * |
| 72 | * @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 |
| 73 | * the memory is accessed by the device. |
| 74 | */ |
| 75 | void unmap(); |
| 76 | using ICLTensor::unmap; |
| 77 | |
| 78 | /** Return the parent tensor of the subtensor |
| 79 | * |
| 80 | * @return Parent tensor |
| 81 | */ |
| 82 | ICLTensor *parent(); |
| 83 | |
| 84 | // Inherited methods overridden: |
| 85 | ITensorInfo *info() const override; |
| 86 | ITensorInfo *info() override; |
| 87 | const cl::Buffer &cl_buffer() const override; |
| 88 | |
| 89 | protected: |
| 90 | // Inherited methods overridden: |
| 91 | uint8_t *do_map(cl::CommandQueue &q, bool blocking) override; |
| 92 | void do_unmap(cl::CommandQueue &q) override; |
| 93 | |
| 94 | private: |
| 95 | ICLTensor *_parent; |
| 96 | mutable SubTensorInfo _info; |
| 97 | }; |
| 98 | } |
| 99 | #endif /*__ARM_COMPUTE_CLSUBTENSOR_H__ */ |