blob: c3e867bffcd1f5fb1e205f32b7512c2aa2ab2814 [file] [log] [blame]
Georgios Pinitasc3c352e2021-03-18 10:59:40 +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"
25
26#include "src/common/IQueue.h"
27#include "src/common/utils/Macros.h"
28#include "src/common/utils/Validate.h"
29
30namespace
31{
32/** Check if queue options are valid
33 *
34 * @param[in] options Queue options
35 *
36 * @return true in case of success else false
37 */
38bool is_mode_valid(const AclQueueOptions *options)
39{
40 ARM_COMPUTE_ASSERT_NOT_NULLPTR(options);
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010041 return arm_compute::utils::is_in(options->mode, {AclTuningModeNone, AclRapid, AclNormal, AclExhaustive});
Georgios Pinitasc3c352e2021-03-18 10:59:40 +000042}
43} // namespace
44
45extern "C" AclStatus AclCreateQueue(AclQueue *external_queue, AclContext external_ctx, const AclQueueOptions *options)
46{
47 using namespace arm_compute;
48
49 auto ctx = get_internal(external_ctx);
50
51 StatusCode status = detail::validate_internal_context(ctx);
52 ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
53
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010054 if (options != nullptr && !is_mode_valid(options))
Georgios Pinitasc3c352e2021-03-18 10:59:40 +000055 {
56 ARM_COMPUTE_LOG_ERROR_ACL("Queue options are invalid");
57 return AclInvalidArgument;
58 }
59
60 auto queue = ctx->create_queue(options);
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010061 if (queue == nullptr)
Georgios Pinitasc3c352e2021-03-18 10:59:40 +000062 {
63 ARM_COMPUTE_LOG_ERROR_ACL("Couldn't allocate internal resources");
64 return AclOutOfMemory;
65 }
66
67 *external_queue = queue;
68
69 return AclSuccess;
70}
71
72extern "C" AclStatus AclQueueFinish(AclQueue external_queue)
73{
74 using namespace arm_compute;
75
76 auto queue = get_internal(external_queue);
77
78 StatusCode status = detail::validate_internal_queue(queue);
79 ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
80
81 status = queue->finish();
82 ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
83
84 return AclSuccess;
85}
86
87extern "C" AclStatus AclDestroyQueue(AclQueue external_queue)
88{
89 using namespace arm_compute;
90
91 auto queue = get_internal(external_queue);
92
93 StatusCode status = detail::validate_internal_queue(queue);
94 ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
95
96 delete queue;
97
98 return AclSuccess;
99}