xref: /aosp_15_r20/external/ComputeLibrary/src/gpu/cl/ClQueue.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 "src/gpu/cl/ClQueue.h"
25 
26 #include "arm_compute/runtime/CL/CLScheduler.h"
27 #include "arm_compute/runtime/CL/CLTuner.h"
28 
29 namespace arm_compute
30 {
31 namespace gpu
32 {
33 namespace opencl
34 {
35 namespace
36 {
map_tuner_mode(AclTuningMode mode)37 CLTunerMode map_tuner_mode(AclTuningMode mode)
38 {
39     switch(mode)
40     {
41         case AclRapid:
42             return CLTunerMode::RAPID;
43             break;
44         case AclNormal:
45             return CLTunerMode::NORMAL;
46             break;
47         case AclExhaustive:
48             return CLTunerMode::EXHAUSTIVE;
49             break;
50         default:
51             ARM_COMPUTE_ERROR("Invalid tuner mode");
52             break;
53     }
54 }
55 
populate_tuner(const AclQueueOptions * options)56 std::unique_ptr<CLTuner> populate_tuner(const AclQueueOptions *options)
57 {
58     if(options == nullptr || options->mode == AclTuningModeNone)
59     {
60         return nullptr;
61     }
62 
63     CLTuningInfo tune_info;
64     tune_info.tuner_mode = map_tuner_mode(options->mode);
65     tune_info.tune_wbsm  = false;
66 
67     return std::make_unique<CLTuner>(true /* tune_new_kernels */, tune_info);
68 }
69 } // namespace
70 
ClQueue(IContext * ctx,const AclQueueOptions * options)71 ClQueue::ClQueue(IContext *ctx, const AclQueueOptions *options)
72     : IQueue(ctx), _tuner(nullptr)
73 {
74     _tuner = populate_tuner(options);
75 }
76 
scheduler()77 arm_compute::CLScheduler &ClQueue::scheduler()
78 {
79     return arm_compute::CLScheduler::get();
80 }
81 
cl_queue()82 ::cl::CommandQueue ClQueue::cl_queue()
83 {
84     return arm_compute::CLScheduler::get().queue();
85 }
86 
set_cl_queue(::cl::CommandQueue queue)87 bool ClQueue::set_cl_queue(::cl::CommandQueue queue)
88 {
89     // TODO: Check queue is from the same context
90     arm_compute::CLScheduler::get().set_queue(queue);
91     return true;
92 }
93 
finish()94 StatusCode ClQueue::finish()
95 {
96     arm_compute::CLScheduler::get().queue().finish();
97     return StatusCode::Success;
98 }
99 
100 } // namespace opencl
101 } // namespace gpu
102 } // namespace arm_compute
103