Compute Library
 23.11
AclQueue.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 
26 #include "src/common/IQueue.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  */
38 bool is_mode_valid(const AclQueueOptions *options)
39 {
41  return arm_compute::utils::is_in(options->mode, {AclTuningModeNone, AclRapid, AclNormal, AclExhaustive});
42 }
43 } // namespace
44 
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 
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 
72 extern "C" AclStatus AclQueueFinish(AclQueue external_queue)
73 {
74  using namespace arm_compute;
75 
76  auto queue = get_internal(external_queue);
77 
80 
81  status = queue->finish();
83 
84  return AclSuccess;
85 }
86 
87 extern "C" AclStatus AclDestroyQueue(AclQueue external_queue)
88 {
89  using namespace arm_compute;
90 
91  auto queue = get_internal(external_queue);
92 
95 
96  delete queue;
97 
98  return AclSuccess;
99 }
AclEntrypoints.h
AclStatus
AclStatus
Definition: AclTypes.h:50
AclSuccess
@ AclSuccess
Call succeeded, leading to valid state for all involved objects/data.
Definition: AclTypes.h:52
ARM_COMPUTE_LOG_ERROR_ACL
#define ARM_COMPUTE_LOG_ERROR_ACL(msg)
Definition: Log.h:32
AclQueueOptions::mode
AclTuningMode mode
Tuning mode.
Definition: AclTypes.h:158
AclOutOfMemory
@ AclOutOfMemory
Call failed due to failure to allocate resources.
Definition: AclTypes.h:54
arm_compute::detail::validate_internal_context
StatusCode validate_internal_context(const IContext *ctx)
Check if an internal context is valid.
Definition: IContext.h:140
arm_compute::StatusCode
StatusCode
Definition: Types.h:32
Validate.h
ARM_COMPUTE_ASSERT_NOT_NULLPTR
#define ARM_COMPUTE_ASSERT_NOT_NULLPTR(ptr)
Definition: Validate.h:38
arm_compute::utils::is_in
bool is_in(E check, std::initializer_list< E > list)
Check if the given value is in the given enum value list.
Definition: Utils.h:75
AclInvalidArgument
@ AclInvalidArgument
Call failed as invalid argument was passed.
Definition: AclTypes.h:58
AclCreateQueue
AclStatus AclCreateQueue(AclQueue *external_queue, AclContext external_ctx, const AclQueueOptions *options)
Create an operator queue.
Definition: AclQueue.cpp:45
AclDestroyQueue
AclStatus AclDestroyQueue(AclQueue external_queue)
Destroy a given queue object.
Definition: AclQueue.cpp:87
arm_compute
Copyright (c) 2017-2023 Arm Limited.
Definition: introduction.dox:24
Macros.h
AclQueue_
Definition: IQueue.h:29
arm_compute::get_internal
IContext * get_internal(AclContext ctx)
Extract internal representation of a Context.
Definition: IContext.h:127
IQueue.h
AclContext_
Definition: IContext.h:34
AclQueueOptions
Definition: AclTypes.h:156
AclQueueFinish
AclStatus AclQueueFinish(AclQueue external_queue)
Wait until all elements on the queue have been completed.
Definition: AclQueue.cpp:72
ARM_COMPUTE_RETURN_CENUM_ON_FAILURE
#define ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status)
Definition: Macros.h:29
arm_compute::detail::validate_internal_queue
StatusCode validate_internal_queue(const IQueue *queue)
Check if an internal queue is valid.
Definition: IQueue.h:89