Georgios Pinitas | 8a5146f | 2021-01-12 15:51:07 +0000 | [diff] [blame] | 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 | */ |
Georgios Pinitas | 3f26ef4 | 2021-02-23 10:01:33 +0000 | [diff] [blame] | 24 | #ifndef SRC_GPU_CLCONTEXT_H |
| 25 | #define SRC_GPU_CLCONTEXT_H |
Georgios Pinitas | 8a5146f | 2021-01-12 15:51:07 +0000 | [diff] [blame] | 26 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/CL/OpenCL.h" |
| 28 | |
Georgios Pinitas | 8a5146f | 2021-01-12 15:51:07 +0000 | [diff] [blame] | 29 | #include "src/common/IContext.h" |
| 30 | #include "src/runtime/CL/mlgo/MLGOHeuristics.h" |
| 31 | |
Georgios Pinitas | 8a5146f | 2021-01-12 15:51:07 +0000 | [diff] [blame] | 32 | namespace arm_compute |
| 33 | { |
| 34 | namespace gpu |
| 35 | { |
| 36 | namespace opencl |
| 37 | { |
| 38 | /** OpenCL context implementation class */ |
| 39 | class ClContext final : public IContext |
| 40 | { |
| 41 | public: |
| 42 | /** Default Constructor |
| 43 | * |
| 44 | * @param[in] options Creational options |
| 45 | */ |
| 46 | explicit ClContext(const AclContextOptions *options); |
Georgios Pinitas | c3c352e | 2021-03-18 10:59:40 +0000 | [diff] [blame] | 47 | |
Georgios Pinitas | 8a5146f | 2021-01-12 15:51:07 +0000 | [diff] [blame] | 48 | /** Extract MLGO heuristics |
| 49 | * |
| 50 | * @return Heuristics tree |
| 51 | */ |
| 52 | const mlgo::MLGOHeuristics &mlgo() const; |
| 53 | |
| 54 | /** Underlying cl context accessor |
| 55 | * |
| 56 | * @return the cl context used |
| 57 | */ |
| 58 | ::cl::Context cl_ctx(); |
Georgios Pinitas | c3c352e | 2021-03-18 10:59:40 +0000 | [diff] [blame] | 59 | |
| 60 | /** Underlying cl device accessor |
| 61 | * |
| 62 | * @return the cl device used |
| 63 | */ |
| 64 | ::cl::Device cl_dev(); |
| 65 | |
Georgios Pinitas | 8a5146f | 2021-01-12 15:51:07 +0000 | [diff] [blame] | 66 | /** Update/inject an underlying cl context object |
| 67 | * |
| 68 | * @warning Context will be able to set if the object doesn't have any pending reference to other objects |
| 69 | * |
| 70 | * @param[in] ctx Underlying cl context to be used |
| 71 | * |
| 72 | * @return true if the context was set successfully else falseS |
| 73 | */ |
| 74 | bool set_cl_ctx(::cl::Context ctx); |
| 75 | |
Georgios Pinitas | 3f26ef4 | 2021-02-23 10:01:33 +0000 | [diff] [blame] | 76 | // Inherrited methods overridden |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 77 | ITensorV2 *create_tensor(const AclTensorDescriptor &desc, bool allocate) override; |
| 78 | IQueue *create_queue(const AclQueueOptions *options) override; |
| 79 | std::tuple<IOperator *, StatusCode> create_activation(const AclTensorDescriptor &src, |
Georgios Pinitas | 4164814 | 2021-08-03 08:24:00 +0100 | [diff] [blame] | 80 | const AclTensorDescriptor &dst, |
| 81 | const AclActivationDescriptor &act, |
| 82 | bool is_validate) override; |
Georgios Pinitas | 3f26ef4 | 2021-02-23 10:01:33 +0000 | [diff] [blame] | 83 | |
Georgios Pinitas | 8a5146f | 2021-01-12 15:51:07 +0000 | [diff] [blame] | 84 | private: |
| 85 | mlgo::MLGOHeuristics _mlgo_heuristics; |
Georgios Pinitas | c3c352e | 2021-03-18 10:59:40 +0000 | [diff] [blame] | 86 | ::cl::Context _cl_ctx; |
| 87 | ::cl::Device _cl_dev; |
Georgios Pinitas | 8a5146f | 2021-01-12 15:51:07 +0000 | [diff] [blame] | 88 | }; |
| 89 | } // namespace opencl |
| 90 | } // namespace gpu |
| 91 | } // namespace arm_compute |
| 92 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 93 | #endif /* SRC_GPU_CLCONTEXT_H */ |