xref: /aosp_15_r20/external/ComputeLibrary/src/c/AclQueue.cpp (revision c217d954acce2dbc11938adb493fc0abd69584f3)
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 
26 #include "src/common/IQueue.h"
27 #include "src/common/utils/Macros.h"
28 #include "src/common/utils/Validate.h"
29 
30 namespace
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  */
is_mode_valid(const AclQueueOptions * options)38 bool is_mode_valid(const AclQueueOptions *options)
39 {
40     ARM_COMPUTE_ASSERT_NOT_NULLPTR(options);
41     return arm_compute::utils::is_in(options->mode, { AclTuningModeNone, AclRapid, AclNormal, AclExhaustive });
42 }
43 } // namespace
44 
AclCreateQueue(AclQueue * external_queue,AclContext external_ctx,const AclQueueOptions * options)45 extern "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 
54     if(options != nullptr && !is_mode_valid(options))
55     {
56         ARM_COMPUTE_LOG_ERROR_ACL("Queue options are invalid");
57         return AclInvalidArgument;
58     }
59 
60     auto queue = ctx->create_queue(options);
61     if(queue == nullptr)
62     {
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 
AclQueueFinish(AclQueue external_queue)72 extern "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 
AclDestroyQueue(AclQueue external_queue)87 extern "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 }
100