Compute Library
 21.11
AclTensorPack.cpp
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  */
25 #include "src/common/ITensorV2.h"
26 #include "src/common/TensorPack.h"
28 
29 namespace
30 {
31 using namespace arm_compute;
32 StatusCode PackTensorInternal(TensorPack &pack, AclTensor external_tensor, int32_t slot_id)
33 {
34  auto status = StatusCode::Success;
35  auto tensor = get_internal(external_tensor);
36 
37  status = detail::validate_internal_tensor(tensor);
38 
39  if(status != StatusCode::Success)
40  {
41  return status;
42  }
43 
44  pack.add_tensor(tensor, slot_id);
45 
46  return status;
47 }
48 } // namespace
49 
50 extern "C" AclStatus AclCreateTensorPack(AclTensorPack *external_pack, AclContext external_ctx)
51 {
52  using namespace arm_compute;
53 
54  IContext *ctx = get_internal(external_ctx);
55 
58 
59  auto pack = new TensorPack(ctx);
60  if(pack == nullptr)
61  {
62  ARM_COMPUTE_LOG_ERROR_WITH_FUNCNAME_ACL("Couldn't allocate internal resources!");
63  return AclOutOfMemory;
64  }
65  *external_pack = pack;
66 
67  return AclSuccess;
68 }
69 
70 extern "C" AclStatus AclPackTensor(AclTensorPack external_pack, AclTensor external_tensor, int32_t slot_id)
71 {
72  using namespace arm_compute;
73 
74  auto pack = get_internal(external_pack);
76  ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(PackTensorInternal(*pack, external_tensor, slot_id));
77  return AclStatus::AclSuccess;
78 }
79 
80 extern "C" AclStatus AclPackTensors(AclTensorPack external_pack, AclTensor *external_tensors, int32_t *slot_ids, size_t num_tensors)
81 {
82  using namespace arm_compute;
83 
84  auto pack = get_internal(external_pack);
86 
87  for(unsigned i = 0; i < num_tensors; ++i)
88  {
89  ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(PackTensorInternal(*pack, external_tensors[i], slot_ids[i]));
90  }
91  return AclStatus::AclSuccess;
92 }
93 
94 extern "C" AclStatus AclDestroyTensorPack(AclTensorPack external_pack)
95 {
96  using namespace arm_compute;
97 
98  auto pack = get_internal(external_pack);
101 
102  delete pack;
103 
104  return AclSuccess;
105 }
#define ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status)
Definition: Macros.h:29
AclStatus add_tensor(ITensorV2 *tensor, int32_t slot_id)
Add tensor to the pack.
Definition: TensorPack.cpp:44
StatusCode validate_internal_context(const IContext *ctx)
Check if an internal context is valid.
Definition: IContext.h:140
StatusCode validate_internal_tensor(const ITensorV2 *tensor)
Check if an internal tensor is valid.
Definition: ITensorV2.h:129
Context interface.
Definition: IContext.h:50
Copyright (c) 2017-2021 Arm Limited.
Call succeeded, leading to valid state for all involved objects/data.
Definition: AclTypes.h:51
StatusCode
Definition: Types.h:32
AclStatus AclPackTensor(AclTensorPack external_pack, AclTensor external_tensor, int32_t slot_id)
Add a tensor to a tensor pack.
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
Call failed due to failure to allocate resources.
Definition: AclTypes.h:53
AclStatus AclCreateTensorPack(AclTensorPack *external_pack, AclContext external_ctx)
Creates a tensor pack.
AclStatus AclPackTensors(AclTensorPack external_pack, AclTensor *external_tensors, int32_t *slot_ids, size_t num_tensors)
A list of tensors to a tensor pack.
#define ARM_COMPUTE_LOG_ERROR_WITH_FUNCNAME_ACL(msg)
Log an error message to the logger with function name before the message.
Definition: Log.h:88
IContext * get_internal(AclContext ctx)
Extract internal representation of a Context.
Definition: IContext.h:127
AclStatus
Definition: AclTypes.h:49
AclStatus AclDestroyTensorPack(AclTensorPack external_pack)
Destroy a given tensor pack object.