Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 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 | #ifndef __ARM_COMPUTE_GRAPH2_GRAPH_CONTEXT_H__ |
| 25 | #define __ARM_COMPUTE_GRAPH2_GRAPH_CONTEXT_H__ |
| 26 | |
| 27 | #include "arm_compute/graph2/Types.h" |
| 28 | |
| 29 | #include "arm_compute/runtime/IMemoryManager.h" |
| 30 | |
| 31 | #include <map> |
| 32 | #include <memory> |
| 33 | |
| 34 | namespace arm_compute |
| 35 | { |
| 36 | namespace graph2 |
| 37 | { |
| 38 | /** Contains structs required for memory management */ |
| 39 | struct MemoryManagerContext |
| 40 | { |
| 41 | Target target = { Target::UNSPECIFIED }; |
| 42 | std::shared_ptr<arm_compute::IMemoryManager> mm = { nullptr }; |
| 43 | }; |
| 44 | |
| 45 | /** Graph context **/ |
| 46 | class GraphContext final |
| 47 | { |
| 48 | public: |
| 49 | /** Constructor */ |
| 50 | GraphContext(); |
| 51 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 52 | GraphContext(const GraphContext &) = delete; |
| 53 | /** Default move constructor */ |
| 54 | GraphContext(GraphContext &&) = default; |
| 55 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 56 | GraphContext &operator=(const GraphContext &) = delete; |
| 57 | /** Default move assignment operator */ |
| 58 | GraphContext &operator=(GraphContext &&) = default; |
| 59 | /** Enables tuning |
| 60 | * |
| 61 | * @param[in] enable_tuning Enables tuning if true |
| 62 | */ |
| 63 | void enable_tuning(bool enable_tuning); |
| 64 | /** Checks if tuning is enabled |
| 65 | * |
| 66 | * @return True if tuning is enabled else false |
| 67 | */ |
| 68 | bool is_tuning_enabled() const; |
| 69 | /** Enables memory management |
| 70 | * |
| 71 | * @param[in] enable_mm Enables mm if true |
| 72 | */ |
| 73 | void enable_memory_managenent(bool enable_mm); |
| 74 | /** Checks if memory management is enabled |
| 75 | * |
| 76 | * @return True if memory management is enabled else false |
| 77 | */ |
| 78 | bool is_memory_management_enabled(); |
| 79 | /** Inserts a memory manager context |
| 80 | * |
| 81 | * @param[in] memory_ctx Memory manage context |
| 82 | * |
| 83 | * @return If the insertion succeeded else false |
| 84 | */ |
| 85 | bool insert_memory_management_ctx(MemoryManagerContext &&memory_ctx); |
| 86 | /** Gets a memory manager context for a given target |
| 87 | * |
| 88 | * @param[in] target To retrieve the management context |
| 89 | * |
| 90 | * @return Management context for the target if exists else nullptr |
| 91 | */ |
| 92 | MemoryManagerContext *memory_management_ctx(Target target); |
| 93 | /** Finalizes memory managers in graph context */ |
| 94 | void finalize(); |
| 95 | |
| 96 | private: |
| 97 | bool _tunable; /**< Specifies if the Graph should use a tunable object */ |
| 98 | bool _memory_managed; /**< Specifies if the Graph should use a memory managed */ |
| 99 | std::map<Target, MemoryManagerContext> _memory_managers; /**< Memory managers for each target */ |
| 100 | }; |
| 101 | } // namespace graph2 |
| 102 | } // namespace arm_compute |
| 103 | #endif /* __ARM_COMPUTE_GRAPH2_GRAPH_CONTEXT_H__ */ |