Compute Library
 21.11
TensorPack.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_ITENSORPACK_H_
25 #define SRC_COMMON_ITENSORPACK_H_
26 
28 #include "src/common/IContext.h"
29 
31 {
33 
34 protected:
35  AclTensorPack_() = default;
36  ~AclTensorPack_() = default;
37 };
38 
39 namespace arm_compute
40 {
41 // Forward declaration
42 class ITensor;
43 class ITensorV2;
44 
45 /** Tensor packing service
46  *
47  * Class is responsible for creating and managing a collection of tensors.
48  * Tensor packs can be passed to operators to be part of the mutable data of the execution.
49  */
50 class TensorPack : public AclTensorPack_
51 {
52 public:
53  /** Constructor
54  *
55  * @param[in] ctx Context to be used
56  */
57  explicit TensorPack(IContext *ctx);
58  /** Destructor */
59  ~TensorPack();
60  /** Add tensor to the pack
61  *
62  * @param[in] tensor Tensor to add
63  * @param[in] slot_id Slot identification in respect to the operator of the tensor to add
64  *
65  * @return Status code
66  */
67  AclStatus add_tensor(ITensorV2 *tensor, int32_t slot_id);
68  /** Pack size accessor
69  *
70  * @return Number of tensors registered to the pack
71  */
72  size_t size() const;
73  /** Checks if pack is empty
74  *
75  * @return True if empty else false
76  */
77  bool empty() const;
78  /** Checks if an object is valid
79  *
80  * @return True if valid else false
81  */
82  bool is_valid() const;
83  /** Get tensor of a given id from the pac
84  *
85  * @param[in] slot_id Slot identification of tensor to extract
86  *
87  * @return The pointer to the tensor if exist and is non-const else nullptr
88  */
89  arm_compute::ITensor *get_tensor(int32_t slot_id);
90  /** Get legacy tensor pack
91  *
92  * @return Legacy tensor pack
93  */
94  arm_compute::ITensorPack &get_tensor_pack();
95 
96 private:
97  arm_compute::ITensorPack _pack; /**< Pack that currently redirects to the existing TensorPack */
98 };
99 
100 /** Extract internal representation of a TensoPack
101  *
102  * @param[in] pack Opaque tensor pack pointer
103  *
104  * @return The internal representation as an TensorPack
105  */
107 {
108  return static_cast<TensorPack *>(pack);
109 }
110 
111 namespace detail
112 {
113 /** Check if an internal TensorPack is valid
114  *
115  * @param[in] pack Internal tensor pack to check
116  *
117  * @return A status code
118  */
120 {
121  if(pack == nullptr || !pack->is_valid())
122  {
123  ARM_COMPUTE_LOG_ERROR_ACL("[TensorPack]: Invalid tensor pack object");
124  return StatusCode::InvalidArgument;
125  }
126  return StatusCode::Success;
127 }
128 } // namespace detail
129 } // namespace arm_compute
130 #endif /* SRC_COMMON_ITENSORPACK_H_ */
TensorPack * get_internal(AclTensorPack pack)
Extract internal representation of a TensoPack.
Definition: TensorPack.h:106
Base class specifying the tensor interface.
Definition: ITensorV2.h:45
bool is_valid() const
Checks if an object is valid.
Definition: TensorPack.cpp:60
#define ARM_COMPUTE_LOG_ERROR_ACL(msg)
Log an error message to the logger.
Definition: Log.h:77
Context interface.
Definition: IContext.h:50
Interface for CPU tensor.
Definition: ITensor.h:36
Copyright (c) 2017-2021 Arm Limited.
StatusCode
Definition: Types.h:32
arm_compute::detail::Header header
Definition: TensorPack.h:32
Tensor packing service.
Definition: TensorPack.h:50
StatusCode validate_internal_pack(const TensorPack *pack)
Check if an internal TensorPack is valid.
Definition: TensorPack.h:119
Tensor packing service.
Definition: ITensorPack.h:39
AclStatus
Definition: AclTypes.h:49