Compute Library
 21.11
IOperator.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 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 SRC_COMMON_IOPERATOR_H_
25 #define SRC_COMMON_IOPERATOR_H_
26 
27 #include "src/common/IContext.h"
28 #include "src/common/IQueue.h"
29 
30 // TODO: Remove when all functions have been ported
34 
35 #include <vector>
36 
38 {
40 
41 protected:
42  AclOperator_() = default;
43  ~AclOperator_() = default;
44 };
45 
46 namespace arm_compute
47 {
48 // Forward declarations
49 class ITensorPack;
50 namespace experimental
51 {
52 class IOperator;
53 } // namespace experimental
54 
56 
57 /** Base class specifying the operator interface */
58 class IOperator : public AclOperator_
59 {
60 public:
61  /** Explict Operator Constructor
62  *
63  * @param[in] ctx Context to be used by the operator
64  */
65  explicit IOperator(IContext *ctx);
66  /** Destructor */
67  virtual ~IOperator();
68  /** Checks if an operator is valid
69  *
70  * @return True if successful otherwise false
71  */
72  bool is_valid() const;
73  /** Run the kernels contained in the function
74  *
75  * @param[in] queue Queue to use
76  * @param[in] tensors Vector that contains the tensors to operate on
77  */
78  virtual StatusCode run(IQueue &queue, ITensorPack &tensors);
79  /** Run the kernels contained in the function
80  *
81  * @param[in] tensors Vector that contains the tensors to operate on
82  */
83  virtual StatusCode run(ITensorPack &tensors);
84  /** Prepare the operator for execution
85  *
86  * Any one off pre-processing step required by the function is handled here
87  *
88  * @param[in] tensors Vector that contains the preparation tensors.
89  *
90  * @note Prepare stage might not need all the function's buffers' backing memory to be available in order to execute
91  */
92  virtual StatusCode prepare(ITensorPack &tensors);
93  /** Return the memory requirements required by the workspace
94  */
95  virtual MemoryRequirements workspace() const;
96 
97  void set_internal_operator(std::unique_ptr<experimental::IOperator> op)
98  {
99  _op = std::move(op);
100  }
101 
102 private:
103  std::unique_ptr<experimental::IOperator> _op{ nullptr };
104 };
105 
106 /** Extract internal representation of an Operator
107  *
108  * @param[in] op Opaque operator pointer
109  *
110  * @return The internal representation as an IOperator
111  */
113 {
114  return static_cast<IOperator *>(op);
115 }
116 
117 namespace detail
118 {
119 /** Check if an internal operator is valid
120  *
121  * @param[in] op Internal operator to check
122  *
123  * @return A status code
124  */
126 {
127  if(op == nullptr || !op->is_valid())
128  {
129  ARM_COMPUTE_LOG_ERROR_ACL("[IOperator]: Invalid operator object");
130  return StatusCode::InvalidArgument;
131  }
132  return StatusCode::Success;
133 }
134 } // namespace detail
135 } // namespace arm_compute
136 #endif /* SRC_COMMON_IOPERATOR_H_ */
void set_internal_operator(std::unique_ptr< experimental::IOperator > op)
Definition: IOperator.h:97
Base class specifying the queue interface.
Definition: IQueue.h:41
Base class for all async functions.
Definition: IOperator.h:37
arm_compute::detail::Header header
Definition: IOperator.h:39
#define ARM_COMPUTE_LOG_ERROR_ACL(msg)
Log an error message to the logger.
Definition: Log.h:77
Context interface.
Definition: IContext.h:50
Copyright (c) 2017-2021 Arm Limited.
std::vector< MemoryInfo > MemoryRequirements
Definition: Types.h:132
StatusCode validate_internal_operator(const IOperator *op)
Check if an internal operator is valid.
Definition: IOperator.h:125
StatusCode
Definition: Types.h:32
IOperator * get_internal(AclOperator op)
Extract internal representation of an Operator.
Definition: IOperator.h:112
Tensor packing service.
Definition: ITensorPack.h:39
experimental::MemoryRequirements MemoryRequirements
Definition: IOperator.h:55