• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "arm_compute/AclEntrypoints.h"
25 #include "src/common/ITensorV2.h"
26 #include "src/common/TensorPack.h"
27 #include "src/common/utils/Macros.h"
28 
29 namespace
30 {
31 using namespace arm_compute;
PackTensorInternal(TensorPack & pack,AclTensor external_tensor,int32_t slot_id)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 
AclCreateTensorPack(AclTensorPack * external_pack,AclContext external_ctx)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 
56     const StatusCode status = detail::validate_internal_context(ctx);
57     ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
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 
AclPackTensor(AclTensorPack external_pack,AclTensor external_tensor,int32_t slot_id)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);
75     ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(detail::validate_internal_pack(pack));
76     ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(PackTensorInternal(*pack, external_tensor, slot_id));
77     return AclStatus::AclSuccess;
78 }
79 
AclPackTensors(AclTensorPack external_pack,AclTensor * external_tensors,int32_t * slot_ids,size_t num_tensors)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);
85     ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(detail::validate_internal_pack(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 
AclDestroyTensorPack(AclTensorPack external_pack)94 extern "C" AclStatus AclDestroyTensorPack(AclTensorPack external_pack)
95 {
96     using namespace arm_compute;
97 
98     auto       pack   = get_internal(external_pack);
99     StatusCode status = detail::validate_internal_pack(pack);
100     ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
101 
102     delete pack;
103 
104     return AclSuccess;
105 }
106