blob: 001f892231cc4d24a0b981a0967630b9b56a4b9a [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Georgios Pinitas4c5469b2019-05-21 13:32:43 +01002 * Copyright (c) 2016-2019 ARM Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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 Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_ICLTENSOR_H
25#define ARM_COMPUTE_ICLTENSOR_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
27#include "arm_compute/core/ITensor.h"
28
Georgios Pinitas4c5469b2019-05-21 13:32:43 +010029#include "arm_compute/core/CL/CLTypes.h"
30
Anthony Barbier6ff3b192017-09-04 18:44:23 +010031#include <cstdint>
32
33namespace cl
34{
35class Buffer;
36class CommandQueue;
37}
38
39namespace arm_compute
40{
41/** Interface for OpenCL tensor */
42class ICLTensor : public ITensor
43{
44public:
Alex Gildayc357c472018-03-21 13:54:09 +000045 /** Default constructor. */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010046 ICLTensor();
Alex Gildayc357c472018-03-21 13:54:09 +000047 /** Prevent instances of this class from being copy constructed */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010048 ICLTensor(const ICLTensor &) = delete;
Alex Gildayc357c472018-03-21 13:54:09 +000049 /** Prevent instances of this class from being copied */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010050 ICLTensor &operator=(const ICLTensor &) = delete;
Alex Gildayc357c472018-03-21 13:54:09 +000051 /** Allow instances of this class to be move constructed */
52 ICLTensor(ICLTensor &&) = default;
53 /** Allow instances of this class to be copied */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010054 ICLTensor &operator=(ICLTensor &&) = default;
Alex Gildayc357c472018-03-21 13:54:09 +000055 /** Default virtual destructor. */
56 virtual ~ICLTensor() = default;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010057
Georgios Pinitas4c5469b2019-05-21 13:32:43 +010058 /** Interface to be implemented by the child class to return the wrapped quantization info data
59 *
60 * @return A wrapped quantization info object.
61 */
62 virtual CLQuantization quantization() const = 0;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010063 /** Interface to be implemented by the child class to return a reference to the OpenCL buffer containing the image's data.
64 *
65 * @return A reference to an OpenCL buffer containing the image's data.
66 */
67 virtual const cl::Buffer &cl_buffer() const = 0;
68 /** Enqueue a map operation of the allocated buffer on the given queue.
69 *
70 * @param[in,out] q The CL command queue to use for the mapping operation.
71 * @param[in] blocking 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(cl::CommandQueue &q, bool blocking = true);
78 /** Enqueue an unmap operation of the allocated and mapped buffer on the given queue.
79 *
80 * @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
81 * the memory is accessed by the device.
82 *
83 * @param[in,out] q The CL command queue to use for the mapping operation.
84 */
85 void unmap(cl::CommandQueue &q);
86 /** Clear the contents of the tensor synchronously.
87 *
88 * @param[in,out] q The CL command queue to use for the clear operation.
89 */
90 void clear(cl::CommandQueue &q);
91
92 // Inherited methods overridden:
93 uint8_t *buffer() const override;
94
95protected:
96 /** Method to be implemented by the child class to map the OpenCL buffer
97 *
98 * @param[in,out] q The CL command queue to use for the mapping operation.
99 * @param[in] blocking If true, then the mapping will be ready to use by the time
100 * this method returns, else it is the caller's responsibility
101 * to flush the queue and wait for the mapping operation to have completed before using the returned mapping pointer.
102 */
103 virtual uint8_t *do_map(cl::CommandQueue &q, bool blocking) = 0;
104 /** Method to be implemented by the child class to unmap the OpenCL buffer
105 *
106 * @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
107 * the memory is accessed by the device.
108 *
109 * @param[in,out] q The CL command queue to use for the mapping operation.
110 */
111 virtual void do_unmap(cl::CommandQueue &q) = 0;
112
113private:
114 uint8_t *_mapping;
115};
116
117using ICLImage = ICLTensor;
118}
Michalis Spyrouf4643372019-11-29 16:17:13 +0000119#endif /*ARM_COMPUTE_ICLTENSOR_H */