blob: 8de5423762090b81dd26c5861f6c06eda69c0121 [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
Georgios Pinitas4c5469b2019-05-21 13:32:43 +010027#include "arm_compute/core/CL/CLTypes.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010028#include "arm_compute/core/ITensor.h"
Georgios Pinitas4c5469b2019-05-21 13:32:43 +010029
Anthony Barbier6ff3b192017-09-04 18:44:23 +010030#include <cstdint>
31
32namespace cl
33{
34class Buffer;
35class CommandQueue;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010036} // namespace cl
Anthony Barbier6ff3b192017-09-04 18:44:23 +010037
38namespace arm_compute
39{
40/** Interface for OpenCL tensor */
41class ICLTensor : public ITensor
42{
43public:
Alex Gildayc357c472018-03-21 13:54:09 +000044 /** Default constructor. */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010045 ICLTensor();
Alex Gildayc357c472018-03-21 13:54:09 +000046 /** Prevent instances of this class from being copy constructed */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010047 ICLTensor(const ICLTensor &) = delete;
Alex Gildayc357c472018-03-21 13:54:09 +000048 /** Prevent instances of this class from being copied */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010049 ICLTensor &operator=(const ICLTensor &) = delete;
Alex Gildayc357c472018-03-21 13:54:09 +000050 /** Allow instances of this class to be move constructed */
51 ICLTensor(ICLTensor &&) = default;
52 /** Allow instances of this class to be copied */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010053 ICLTensor &operator=(ICLTensor &&) = default;
Alex Gildayc357c472018-03-21 13:54:09 +000054 /** Default virtual destructor. */
55 virtual ~ICLTensor() = default;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010056
Georgios Pinitas4c5469b2019-05-21 13:32:43 +010057 /** Interface to be implemented by the child class to return the wrapped quantization info data
58 *
59 * @return A wrapped quantization info object.
60 */
61 virtual CLQuantization quantization() const = 0;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010062 /** Interface to be implemented by the child class to return a reference to the OpenCL buffer containing the image's data.
63 *
64 * @return A reference to an OpenCL buffer containing the image's data.
65 */
66 virtual const cl::Buffer &cl_buffer() const = 0;
67 /** Enqueue a map operation of the allocated buffer on the given queue.
68 *
69 * @param[in,out] q The CL command queue to use for the mapping operation.
70 * @param[in] blocking If true, then the mapping will be ready to use by the time
71 * this method returns, else it is the caller's responsibility
72 * 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 +010073 */
74 void map(cl::CommandQueue &q, bool blocking = true);
75 /** Enqueue an unmap operation of the allocated and mapped buffer on the given queue.
76 *
77 * @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
78 * the memory is accessed by the device.
79 *
80 * @param[in,out] q The CL command queue to use for the mapping operation.
81 */
82 void unmap(cl::CommandQueue &q);
83 /** Clear the contents of the tensor synchronously.
84 *
85 * @param[in,out] q The CL command queue to use for the clear operation.
86 */
87 void clear(cl::CommandQueue &q);
88
89 // Inherited methods overridden:
90 uint8_t *buffer() const override;
91
92protected:
93 /** Method to be implemented by the child class to map the OpenCL buffer
94 *
95 * @param[in,out] q The CL command queue to use for the mapping operation.
96 * @param[in] blocking If true, then the mapping will be ready to use by the time
97 * this method returns, else it is the caller's responsibility
98 * to flush the queue and wait for the mapping operation to have completed before using the returned mapping pointer.
99 */
100 virtual uint8_t *do_map(cl::CommandQueue &q, bool blocking) = 0;
101 /** Method to be implemented by the child class to unmap the OpenCL buffer
102 *
103 * @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
104 * the memory is accessed by the device.
105 *
106 * @param[in,out] q The CL command queue to use for the mapping operation.
107 */
108 virtual void do_unmap(cl::CommandQueue &q) = 0;
109
110private:
111 uint8_t *_mapping;
112};
113
114using ICLImage = ICLTensor;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100115} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000116#endif /*ARM_COMPUTE_ICLTENSOR_H */