blob: 78d3757e593af9e5d38faa3e646847a429518dc0 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
ramy.elgammal@arm.coma2561f02023-06-16 20:45:48 +01002 * Copyright (c) 2016-2019, 2023 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.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010074 */
75 void map(cl::CommandQueue &q, bool blocking = true);
76 /** Enqueue an unmap operation of the allocated and mapped buffer on the given queue.
77 *
78 * @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
79 * the memory is accessed by the device.
80 *
81 * @param[in,out] q The CL command queue to use for the mapping operation.
82 */
83 void unmap(cl::CommandQueue &q);
84 /** Clear the contents of the tensor synchronously.
85 *
86 * @param[in,out] q The CL command queue to use for the clear operation.
87 */
88 void clear(cl::CommandQueue &q);
89
90 // Inherited methods overridden:
91 uint8_t *buffer() const override;
92
93protected:
94 /** Method to be implemented by the child class to map the OpenCL buffer
95 *
96 * @param[in,out] q The CL command queue to use for the mapping operation.
97 * @param[in] blocking If true, then the mapping will be ready to use by the time
98 * this method returns, else it is the caller's responsibility
99 * to flush the queue and wait for the mapping operation to have completed before using the returned mapping pointer.
100 */
101 virtual uint8_t *do_map(cl::CommandQueue &q, bool blocking) = 0;
102 /** Method to be implemented by the child class to unmap the OpenCL buffer
103 *
104 * @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
105 * the memory is accessed by the device.
106 *
107 * @param[in,out] q The CL command queue to use for the mapping operation.
108 */
109 virtual void do_unmap(cl::CommandQueue &q) = 0;
110
111private:
112 uint8_t *_mapping;
113};
114
115using ICLImage = ICLTensor;
116}
Michalis Spyrouf4643372019-11-29 16:17:13 +0000117#endif /*ARM_COMPUTE_ICLTENSOR_H */