Compute Library
 20.08
ICLTensor.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2019 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  * @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 
95 protected:
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 
113 private:
114  uint8_t *_mapping;
115 };
116 
117 using ICLImage = ICLTensor;
118 }
119 #endif /*ARM_COMPUTE_ICLTENSOR_H */
void map(cl::CommandQueue &q, bool blocking=true)
Enqueue a map operation of the allocated buffer on the given queue.
Definition: ICLTensor.cpp:35
Interface for NEON tensor.
Definition: ITensor.h:36
OpenCL quantization data.
Definition: CLTypes.h:62
Copyright (c) 2017-2020 Arm Limited.
uint8_t * buffer() const override
Interface to be implemented by the child class to return a pointer to CPU memory.
Definition: ICLTensor.cpp:53
void clear(cl::CommandQueue &q)
Clear the contents of the tensor synchronously.
Definition: ICLTensor.cpp:46
virtual ~ICLTensor()=default
Default virtual destructor.
void unmap(cl::CommandQueue &q)
Enqueue an unmap operation of the allocated and mapped buffer on the given queue.
Definition: ICLTensor.cpp:40
ICLTensor()
Default constructor.
Definition: ICLTensor.cpp:30
Interface for OpenCL tensor.
Definition: ICLTensor.h:42
ICLTensor & operator=(const ICLTensor &)=delete
Prevent instances of this class from being copied.
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 ...
virtual CLQuantization quantization() const =0
Interface to be implemented by the child class to return the wrapped quantization info data.