Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame] | 1 | /* |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018 ARM Limited. |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +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 | */ |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 24 | #ifndef __ARM_COMPUTE_GRAPH_GRAPH_CONTEXT_H__ |
| 25 | #define __ARM_COMPUTE_GRAPH_GRAPH_CONTEXT_H__ |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/graph/Types.h" |
| 28 | |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 29 | #include "arm_compute/runtime/IMemoryManager.h" |
| 30 | |
| 31 | #include <map> |
| 32 | #include <memory> |
| 33 | |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame] | 34 | namespace arm_compute |
| 35 | { |
| 36 | namespace graph |
| 37 | { |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 38 | /** Contains structs required for memory management */ |
| 39 | struct MemoryManagerContext |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame] | 40 | { |
Georgios Pinitas | 3d1489d | 2018-05-03 20:47:16 +0100 | [diff] [blame] | 41 | Target target = { Target::UNSPECIFIED }; /**< Target */ |
| 42 | std::shared_ptr<arm_compute::IMemoryManager> intra_mm = { nullptr }; /**< Intra-function memory manager */ |
| 43 | std::shared_ptr<arm_compute::IMemoryManager> cross_mm = { nullptr }; /**< Cross-function memory manager */ |
| 44 | std::shared_ptr<arm_compute::IMemoryGroup> cross_group = { nullptr }; /**< Cross-function memory group */ |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame] | 45 | }; |
| 46 | |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 47 | /** Graph context **/ |
| 48 | class GraphContext final |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame] | 49 | { |
| 50 | public: |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 51 | /** Constructor */ |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame] | 52 | GraphContext(); |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 53 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 54 | GraphContext(const GraphContext &) = delete; |
| 55 | /** Default move constructor */ |
| 56 | GraphContext(GraphContext &&) = default; |
| 57 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 58 | GraphContext &operator=(const GraphContext &) = delete; |
| 59 | /** Default move assignment operator */ |
| 60 | GraphContext &operator=(GraphContext &&) = default; |
| 61 | /** Graph configuration accessor |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame] | 62 | * |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 63 | * @note Every alteration has to be done before graph finalization |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame] | 64 | * |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 65 | * @return The graph configuration |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame] | 66 | */ |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 67 | const GraphConfig &config() const; |
| 68 | /** Sets graph configuration |
| 69 | * |
| 70 | * @param[in] config Configuration to use |
| 71 | */ |
| 72 | void set_config(const GraphConfig &config); |
| 73 | /** Inserts a memory manager context |
| 74 | * |
| 75 | * @param[in] memory_ctx Memory manage context |
| 76 | * |
| 77 | * @return If the insertion succeeded else false |
| 78 | */ |
| 79 | bool insert_memory_management_ctx(MemoryManagerContext &&memory_ctx); |
| 80 | /** Gets a memory manager context for a given target |
| 81 | * |
| 82 | * @param[in] target To retrieve the management context |
| 83 | * |
| 84 | * @return Management context for the target if exists else nullptr |
| 85 | */ |
| 86 | MemoryManagerContext *memory_management_ctx(Target target); |
Georgios Pinitas | 3d1489d | 2018-05-03 20:47:16 +0100 | [diff] [blame] | 87 | /** Gets the memory managers map |
| 88 | * |
| 89 | * @return Memory manager contexts |
| 90 | */ |
| 91 | std::map<Target, MemoryManagerContext> &memory_managers(); |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 92 | /** Finalizes memory managers in graph context */ |
| 93 | void finalize(); |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame] | 94 | |
| 95 | private: |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 96 | GraphConfig _config; /**< Graph configuration */ |
| 97 | std::map<Target, MemoryManagerContext> _memory_managers; /**< Memory managers for each target */ |
Georgios Pinitas | ff421f2 | 2017-10-04 16:53:58 +0100 | [diff] [blame] | 98 | }; |
| 99 | } // namespace graph |
| 100 | } // namespace arm_compute |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 101 | #endif /* __ARM_COMPUTE_GRAPH_GRAPH_CONTEXT_H__ */ |