blob: daf1be4f4436729c6816b631b3ebe0d5df403494 [file] [log] [blame]
Georgios Pinitas3f26ef42021-02-23 10:01:33 +00001/*
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"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010025
Sang-Hoon Parkc6fcfb42021-03-31 15:18:16 +010026#include "src/common/ITensorV2.h"
Georgios Pinitas3f26ef42021-02-23 10:01:33 +000027#include "src/common/TensorPack.h"
28#include "src/common/utils/Macros.h"
29
30namespace
31{
32using namespace arm_compute;
33StatusCode PackTensorInternal(TensorPack &pack, AclTensor external_tensor, int32_t slot_id)
34{
35 auto status = StatusCode::Success;
36 auto tensor = get_internal(external_tensor);
37
38 status = detail::validate_internal_tensor(tensor);
39
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010040 if (status != StatusCode::Success)
Georgios Pinitas3f26ef42021-02-23 10:01:33 +000041 {
42 return status;
43 }
44
45 pack.add_tensor(tensor, slot_id);
46
47 return status;
48}
49} // namespace
50
51extern "C" AclStatus AclCreateTensorPack(AclTensorPack *external_pack, AclContext external_ctx)
52{
53 using namespace arm_compute;
54
55 IContext *ctx = get_internal(external_ctx);
56
57 const StatusCode status = detail::validate_internal_context(ctx);
58 ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
59
60 auto pack = new TensorPack(ctx);
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010061 if (pack == nullptr)
Georgios Pinitas3f26ef42021-02-23 10:01:33 +000062 {
63 ARM_COMPUTE_LOG_ERROR_WITH_FUNCNAME_ACL("Couldn't allocate internal resources!");
64 return AclOutOfMemory;
65 }
66 *external_pack = pack;
67
68 return AclSuccess;
69}
70
71extern "C" AclStatus AclPackTensor(AclTensorPack external_pack, AclTensor external_tensor, int32_t slot_id)
72{
73 using namespace arm_compute;
74
75 auto pack = get_internal(external_pack);
76 ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(detail::validate_internal_pack(pack));
77 ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(PackTensorInternal(*pack, external_tensor, slot_id));
78 return AclStatus::AclSuccess;
79}
80
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010081extern "C" AclStatus
82AclPackTensors(AclTensorPack external_pack, AclTensor *external_tensors, int32_t *slot_ids, size_t num_tensors)
Georgios Pinitas3f26ef42021-02-23 10:01:33 +000083{
84 using namespace arm_compute;
85
86 auto pack = get_internal(external_pack);
87 ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(detail::validate_internal_pack(pack));
88
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010089 for (unsigned i = 0; i < num_tensors; ++i)
Georgios Pinitas3f26ef42021-02-23 10:01:33 +000090 {
91 ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(PackTensorInternal(*pack, external_tensors[i], slot_ids[i]));
92 }
93 return AclStatus::AclSuccess;
94}
95
96extern "C" AclStatus AclDestroyTensorPack(AclTensorPack external_pack)
97{
98 using namespace arm_compute;
99
100 auto pack = get_internal(external_pack);
101 StatusCode status = detail::validate_internal_pack(pack);
102 ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
103
104 delete pack;
105
106 return AclSuccess;
107}