blob: 0f5dba923bf3793f9f62f6482cb7df308011c8c2 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Alex Gildayc357c472018-03-21 13:54:09 +00002 * Copyright (c) 2016-2018 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 */
24#ifndef __ARM_COMPUTE_ICLTENSOR_H__
25#define __ARM_COMPUTE_ICLTENSOR_H__
26
27#include "arm_compute/core/ITensor.h"
28
29#include <cstdint>
30
31namespace cl
32{
33class Buffer;
34class CommandQueue;
35}
36
37namespace arm_compute
38{
39/** Interface for OpenCL tensor */
40class ICLTensor : public ITensor
41{
42public:
Alex Gildayc357c472018-03-21 13:54:09 +000043 /** Default constructor. */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010044 ICLTensor();
Alex Gildayc357c472018-03-21 13:54:09 +000045 /** Prevent instances of this class from being copy constructed */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010046 ICLTensor(const ICLTensor &) = delete;
Alex Gildayc357c472018-03-21 13:54:09 +000047 /** Prevent instances of this class from being copied */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010048 ICLTensor &operator=(const ICLTensor &) = delete;
Alex Gildayc357c472018-03-21 13:54:09 +000049 /** Allow instances of this class to be move constructed */
50 ICLTensor(ICLTensor &&) = default;
51 /** Allow instances of this class to be copied */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010052 ICLTensor &operator=(ICLTensor &&) = default;
Alex Gildayc357c472018-03-21 13:54:09 +000053 /** Default virtual destructor. */
54 virtual ~ICLTensor() = default;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010055
56 /** Interface to be implemented by the child class to return a reference to the OpenCL buffer containing the image's data.
57 *
58 * @return A reference to an OpenCL buffer containing the image's data.
59 */
60 virtual const cl::Buffer &cl_buffer() const = 0;
61 /** Enqueue a map operation of the allocated buffer on the given queue.
62 *
63 * @param[in,out] q The CL command queue to use for the mapping operation.
64 * @param[in] blocking If true, then the mapping will be ready to use by the time
65 * this method returns, else it is the caller's responsibility
66 * to flush the queue and wait for the mapping operation to have completed before using the returned mapping pointer.
67 *
68 * @return The mapping address.
69 */
70 void map(cl::CommandQueue &q, bool blocking = true);
71 /** Enqueue an unmap operation of the allocated and mapped buffer on the given queue.
72 *
73 * @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
74 * the memory is accessed by the device.
75 *
76 * @param[in,out] q The CL command queue to use for the mapping operation.
77 */
78 void unmap(cl::CommandQueue &q);
79 /** Clear the contents of the tensor synchronously.
80 *
81 * @param[in,out] q The CL command queue to use for the clear operation.
82 */
83 void clear(cl::CommandQueue &q);
84
85 // Inherited methods overridden:
86 uint8_t *buffer() const override;
87
88protected:
89 /** Method to be implemented by the child class to map the OpenCL buffer
90 *
91 * @param[in,out] q The CL command queue to use for the mapping operation.
92 * @param[in] blocking If true, then the mapping will be ready to use by the time
93 * this method returns, else it is the caller's responsibility
94 * to flush the queue and wait for the mapping operation to have completed before using the returned mapping pointer.
95 */
96 virtual uint8_t *do_map(cl::CommandQueue &q, bool blocking) = 0;
97 /** Method to be implemented by the child class to unmap the OpenCL buffer
98 *
99 * @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
100 * the memory is accessed by the device.
101 *
102 * @param[in,out] q The CL command queue to use for the mapping operation.
103 */
104 virtual void do_unmap(cl::CommandQueue &q) = 0;
105
106private:
107 uint8_t *_mapping;
108};
109
110using ICLImage = ICLTensor;
111}
112#endif /*__ARM_COMPUTE_ICLTENSOR_H__ */