Georgios Pinitas | 12833d0 | 2019-07-25 13:31:10 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2019 Arm Limited. |
Georgios Pinitas | 12833d0 | 2019-07-25 13:31:10 +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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_TEST_PARAMETERS_LIBRARY_H |
| 25 | #define ARM_COMPUTE_TEST_PARAMETERS_LIBRARY_H |
Georgios Pinitas | 12833d0 | 2019-07-25 13:31:10 +0100 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/runtime/IRuntimeContext.h" |
| 28 | #include "arm_compute/runtime/Tensor.h" |
Pablo Tello | db8485a | 2019-09-24 11:03:47 +0100 | [diff] [blame] | 29 | #if ARM_COMPUTE_CL |
| 30 | #include "arm_compute/runtime/CL/CLRuntimeContext.h" |
| 31 | #include "arm_compute/runtime/CL/CLTensor.h" |
| 32 | #endif /* ARM_COMPUTE_CL */ |
| 33 | #ifdef ARM_COMPUTE_GC |
Georgios Pinitas | 7ae80a9 | 2019-10-25 18:25:17 +0100 | [diff] [blame] | 34 | #include "arm_compute/runtime/GLES_COMPUTE/GCRuntimeContext.h" |
Pablo Tello | db8485a | 2019-09-24 11:03:47 +0100 | [diff] [blame] | 35 | #include "arm_compute/runtime/GLES_COMPUTE/GCTensor.h" |
| 36 | #endif /* ARM_COMPUTE_GC */ |
Georgios Pinitas | 12833d0 | 2019-07-25 13:31:10 +0100 | [diff] [blame] | 37 | |
| 38 | #include <memory> |
| 39 | |
| 40 | namespace arm_compute |
| 41 | { |
| 42 | namespace test |
| 43 | { |
| 44 | // Return type trait helper |
| 45 | template <class T> |
| 46 | struct ContextType |
| 47 | { |
| 48 | using type = void; |
| 49 | }; |
| 50 | template <> |
| 51 | struct ContextType<Tensor> |
| 52 | { |
| 53 | using type = IRuntimeContext; |
| 54 | }; |
| 55 | |
Pablo Tello | db8485a | 2019-09-24 11:03:47 +0100 | [diff] [blame] | 56 | #if ARM_COMPUTE_CL |
| 57 | template <> |
| 58 | struct ContextType<CLTensor> |
| 59 | { |
| 60 | using type = CLRuntimeContext; |
| 61 | }; |
| 62 | #endif /* ARM_COMPUTE_CL */ |
| 63 | |
| 64 | #ifdef ARM_COMPUTE_GC |
| 65 | template <> |
| 66 | struct ContextType<GCTensor> |
| 67 | { |
Georgios Pinitas | 7ae80a9 | 2019-10-25 18:25:17 +0100 | [diff] [blame] | 68 | using type = GCRuntimeContext; |
Pablo Tello | db8485a | 2019-09-24 11:03:47 +0100 | [diff] [blame] | 69 | }; |
| 70 | #endif /* ARM_COMPUTE_GC */ |
| 71 | |
Georgios Pinitas | 12833d0 | 2019-07-25 13:31:10 +0100 | [diff] [blame] | 72 | /** Class that contains all the global parameters used by the tests */ |
| 73 | class ParametersLibrary final |
| 74 | { |
| 75 | public: |
| 76 | /** Default constructor */ |
| 77 | ParametersLibrary() = default; |
| 78 | /** Set cpu context to be used by the tests |
| 79 | * |
| 80 | * @param[in] cpu_ctx CPU context to use |
| 81 | */ |
| 82 | void set_cpu_ctx(std::unique_ptr<IRuntimeContext> cpu_ctx); |
Pablo Tello | db8485a | 2019-09-24 11:03:47 +0100 | [diff] [blame] | 83 | /** Set gpu context to be used by the tests |
| 84 | * |
Georgios Pinitas | 7ae80a9 | 2019-10-25 18:25:17 +0100 | [diff] [blame] | 85 | * @param[in] cl_ctx GPU context to use |
Pablo Tello | db8485a | 2019-09-24 11:03:47 +0100 | [diff] [blame] | 86 | */ |
Georgios Pinitas | 7ae80a9 | 2019-10-25 18:25:17 +0100 | [diff] [blame] | 87 | void set_cl_ctx(std::unique_ptr<IRuntimeContext> cl_ctx); |
| 88 | /** Set gpu context to be used by the tests |
| 89 | * |
| 90 | * @param[in] gc_ctx GPU context to use |
| 91 | */ |
| 92 | void set_gc_ctx(std::unique_ptr<IRuntimeContext> gc_ctx); |
Georgios Pinitas | 12833d0 | 2019-07-25 13:31:10 +0100 | [diff] [blame] | 93 | /** Get context given a tensor type |
| 94 | * |
| 95 | * @tparam TensorType |
| 96 | * |
| 97 | * @return Pointer to the context |
| 98 | */ |
| 99 | template <typename TensorType> |
| 100 | typename ContextType<TensorType>::type *get_ctx() |
| 101 | { |
| 102 | return nullptr; |
| 103 | } |
| 104 | |
| 105 | private: |
| 106 | std::unique_ptr<IRuntimeContext> _cpu_ctx{ nullptr }; |
Georgios Pinitas | 7ae80a9 | 2019-10-25 18:25:17 +0100 | [diff] [blame] | 107 | std::unique_ptr<IRuntimeContext> _cl_ctx{ nullptr }; |
| 108 | std::unique_ptr<IRuntimeContext> _gc_ctx{ nullptr }; |
Georgios Pinitas | 12833d0 | 2019-07-25 13:31:10 +0100 | [diff] [blame] | 109 | }; |
| 110 | } // namespace test |
| 111 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 112 | #endif //ARM_COMPUTE_TEST_PARAMETERS_LIBRARY_H |