blob: 0cb7af5b6142a4fcdd594e30b50cd74e30c9895b [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 "src/gpu/cl/ClQueue.h"
25
26#include "arm_compute/runtime/CL/CLScheduler.h"
27#include "arm_compute/runtime/CL/CLTuner.h"
28
29namespace arm_compute
30{
31namespace gpu
32{
33namespace opencl
34{
35namespace
36{
37CLTunerMode map_tuner_mode(AclTuningMode mode)
38{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010039 switch (mode)
Georgios Pinitasc3c352e2021-03-18 10:59:40 +000040 {
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
56std::unique_ptr<CLTuner> populate_tuner(const AclQueueOptions *options)
57{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010058 if (options == nullptr || options->mode == AclTuningModeNone)
Georgios Pinitasc3c352e2021-03-18 10:59:40 +000059 {
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
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010071ClQueue::ClQueue(IContext *ctx, const AclQueueOptions *options) : IQueue(ctx), _tuner(nullptr)
Georgios Pinitasc3c352e2021-03-18 10:59:40 +000072{
73 _tuner = populate_tuner(options);
74}
75
76arm_compute::CLScheduler &ClQueue::scheduler()
77{
78 return arm_compute::CLScheduler::get();
79}
80
81::cl::CommandQueue ClQueue::cl_queue()
82{
83 return arm_compute::CLScheduler::get().queue();
84}
85
86bool ClQueue::set_cl_queue(::cl::CommandQueue queue)
87{
88 // TODO: Check queue is from the same context
89 arm_compute::CLScheduler::get().set_queue(queue);
90 return true;
91}
92
93StatusCode ClQueue::finish()
94{
95 arm_compute::CLScheduler::get().queue().finish();
96 return StatusCode::Success;
97}
98
99} // namespace opencl
100} // namespace gpu
101} // namespace arm_compute