Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 1 | /* |
Georgios Pinitas | 7ae80a9 | 2019-10-25 18:25:17 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 ARM Limited. |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 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 | |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 25 | #ifndef ARM_COMPUTE_GCSCHEDULER_H |
| 26 | #define ARM_COMPUTE_GCSCHEDULER_H |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 27 | |
| 28 | #include "arm_compute/core/GLES_COMPUTE/IGCKernel.h" |
| 29 | #include "arm_compute/core/Types.h" |
| 30 | |
| 31 | namespace arm_compute |
| 32 | { |
Georgios Pinitas | 7ae80a9 | 2019-10-25 18:25:17 +0100 | [diff] [blame] | 33 | // Forward declarations |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 34 | class IGCKernel; |
| 35 | |
| 36 | /** Provides global access to a OpenGL ES context and command queue. */ |
Georgios Pinitas | 7ae80a9 | 2019-10-25 18:25:17 +0100 | [diff] [blame] | 37 | class GCScheduler final |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 38 | { |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 39 | public: |
Georgios Pinitas | 7ae80a9 | 2019-10-25 18:25:17 +0100 | [diff] [blame] | 40 | /** Constructor */ |
| 41 | GCScheduler(); |
| 42 | /** Destructor */ |
| 43 | ~GCScheduler(); |
| 44 | /** Prevent instances of this class from being copied */ |
| 45 | GCScheduler(const GCScheduler &) = delete; |
| 46 | /** Prevent instances of this class from being copied */ |
| 47 | GCScheduler &operator=(const GCScheduler &) = delete; |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 48 | /** Access the scheduler singleton. |
| 49 | * |
| 50 | * @return The scheduler |
| 51 | */ |
| 52 | static GCScheduler &get(); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 53 | /** Initialises the context and command queue used by the scheduler to default values |
| 54 | * and sets a default device and kernel path for the @ref GCKernelLibrary. |
| 55 | */ |
| 56 | void default_init(); |
Georgios Pinitas | 7ae80a9 | 2019-10-25 18:25:17 +0100 | [diff] [blame] | 57 | /** Initializes the context and display used by the Scheduler. |
| 58 | * |
| 59 | * @param[in] display Display to use |
| 60 | * @param[in] ctx Context to use |
| 61 | */ |
| 62 | void default_init_with_context(EGLDisplay display, EGLContext ctx); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 63 | /** Schedule the execution of the passed kernel if possible. |
| 64 | * |
| 65 | * @param[in] kernel Kernel to execute. |
| 66 | * @param[in] flush (Optional) Specifies if the command queue will be flushed after running the kernel. |
| 67 | */ |
Joel Liang | eb8f71e | 2017-12-27 13:16:00 +0800 | [diff] [blame] | 68 | void dispatch(IGCKernel &kernel, bool flush = true); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 69 | /** Initialises the display and context to be used by the scheduler. |
| 70 | * |
| 71 | * @param[in] dpy The EGL display connection |
| 72 | * @param[in] ctx The EGL rendering context |
| 73 | */ |
| 74 | void init(EGLDisplay dpy, EGLContext ctx); |
Joel Liang | eb8f71e | 2017-12-27 13:16:00 +0800 | [diff] [blame] | 75 | /** Defines a barrier ordering memory transactions. */ |
| 76 | void memory_barrier(); |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 77 | /** Get the target GPU. |
| 78 | * |
| 79 | * @return The target GPU. |
| 80 | */ |
| 81 | GPUTarget get_target() const |
| 82 | { |
| 83 | return _target; |
| 84 | } |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 85 | /** Accessor to set target GPU to be used by the scheduler. |
| 86 | * |
| 87 | * @param[in] target The target GPU. |
| 88 | */ |
| 89 | void set_target(GPUTarget target) |
| 90 | { |
| 91 | _target = target; |
| 92 | } |
| 93 | |
Ioan-Cristian Szabo | 77eb21f | 2017-12-22 17:32:17 +0000 | [diff] [blame] | 94 | private: |
Ioan-Cristian Szabo | 77eb21f | 2017-12-22 17:32:17 +0000 | [diff] [blame] | 95 | /** Set up EGL context */ |
| 96 | void setup_context(); |
| 97 | |
| 98 | /** Flag to ensure symbols initialisation is happening before Scheduler creation */ |
| 99 | static std::once_flag _initialize_symbols; |
| 100 | |
| 101 | EGLDisplay _display; /**< Underlying EGL Display. */ |
| 102 | EGLContext _context; /**< Underlying EGL Context. */ |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 103 | |
| 104 | GPUTarget _target; |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 105 | }; |
| 106 | } |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 107 | #endif /* ARM_COMPUTE_GCSCHEDULER_H */ |