Compute Library
 23.08
ICLTensor.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2019, 2023 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_ICLTENSOR_H
25 #define ARM_COMPUTE_ICLTENSOR_H
26 
28 
30 
31 #include <cstdint>
32 
33 namespace cl
34 {
35 class Buffer;
36 class CommandQueue;
37 }
38 
39 namespace arm_compute
40 {
41 /** Interface for OpenCL tensor */
42 class ICLTensor : public ITensor
43 {
44 public:
45  /** Default constructor. */
46  ICLTensor();
47  /** Prevent instances of this class from being copy constructed */
48  ICLTensor(const ICLTensor &) = delete;
49  /** Prevent instances of this class from being copied */
50  ICLTensor &operator=(const ICLTensor &) = delete;
51  /** Allow instances of this class to be move constructed */
52  ICLTensor(ICLTensor &&) = default;
53  /** Allow instances of this class to be copied */
54  ICLTensor &operator=(ICLTensor &&) = default;
55  /** Default virtual destructor. */
56  virtual ~ICLTensor() = default;
57 
58  /** 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;
63  /** 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  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 
93 protected:
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 
111 private:
112  uint8_t *_mapping;
113 };
114 
116 }
117 #endif /*ARM_COMPUTE_ICLTENSOR_H */
CLTypes.h
arm_compute::ICLTensor::~ICLTensor
virtual ~ICLTensor()=default
Default virtual destructor.
arm_compute::ICLTensor::map
void map(cl::CommandQueue &q, bool blocking=true)
Enqueue a map operation of the allocated buffer on the given queue.
Definition: ICLTensor.cpp:35
arm_compute::ICLTensor
Interface for OpenCL tensor.
Definition: ICLTensor.h:42
arm_compute::ICLTensor::cl_buffer
virtual const cl::Buffer & cl_buffer() const =0
Interface to be implemented by the child class to return a reference to the OpenCL buffer containing ...
arm_compute::ITensor
Interface for CPU tensor.
Definition: ITensor.h:36
arm_compute::ICLTensor::quantization
virtual CLQuantization quantization() const =0
Interface to be implemented by the child class to return the wrapped quantization info data.
arm_compute::ICLTensor::operator=
ICLTensor & operator=(const ICLTensor &)=delete
Prevent instances of this class from being copied.
arm_compute::ICLTensor::buffer
uint8_t * buffer() const override
Interface to be implemented by the child class to return a pointer to CPU memory.
Definition: ICLTensor.cpp:53
arm_compute::CLQuantization
OpenCL quantization data.
Definition: CLTypes.h:63
arm_compute::ICLTensor::unmap
void unmap(cl::CommandQueue &q)
Enqueue an unmap operation of the allocated and mapped buffer on the given queue.
Definition: ICLTensor.cpp:40
arm_compute::ICLTensor::ICLTensor
ICLTensor()
Default constructor.
Definition: ICLTensor.cpp:30
arm_compute
Copyright (c) 2017-2023 Arm Limited.
Definition: introduction.dox:24
arm_compute::ICLTensor::clear
void clear(cl::CommandQueue &q)
Clear the contents of the tensor synchronously.
Definition: ICLTensor.cpp:46
ITensor.h
cl
Definition: ICLTensor.h:33