blob: 2f9ab665ce93d8539bf5858ec99f7bc8028cac31 [file] [log] [blame]
Georgios Pinitasff421f22017-10-04 16:53:58 +01001/*
Georgios Pinitasd9eb2752018-04-03 13:44:29 +01002 * Copyright (c) 2018 ARM Limited.
Georgios Pinitasff421f22017-10-04 16:53:58 +01003 *
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 Pinitasd9eb2752018-04-03 13:44:29 +010024#ifndef __ARM_COMPUTE_GRAPH_GRAPH_CONTEXT_H__
25#define __ARM_COMPUTE_GRAPH_GRAPH_CONTEXT_H__
Georgios Pinitasff421f22017-10-04 16:53:58 +010026
27#include "arm_compute/graph/Types.h"
28
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010029#include "arm_compute/runtime/IMemoryManager.h"
30
31#include <map>
32#include <memory>
33
Georgios Pinitasff421f22017-10-04 16:53:58 +010034namespace arm_compute
35{
36namespace graph
37{
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010038/** Contains structs required for memory management */
39struct MemoryManagerContext
Georgios Pinitasff421f22017-10-04 16:53:58 +010040{
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010041 Target target = { Target::UNSPECIFIED }; /**< Target */
42 std::shared_ptr<arm_compute::IMemoryManager> mm = { nullptr }; /**< Memory manager */
Georgios Pinitasff421f22017-10-04 16:53:58 +010043};
44
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010045/** Graph context **/
46class GraphContext final
Georgios Pinitasff421f22017-10-04 16:53:58 +010047{
48public:
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010049 /** Constructor */
Georgios Pinitasff421f22017-10-04 16:53:58 +010050 GraphContext();
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010051 /** 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 /** Graph configuration accessor
Georgios Pinitasff421f22017-10-04 16:53:58 +010060 *
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010061 * @note Every alteration has to be done before graph finalization
Georgios Pinitasff421f22017-10-04 16:53:58 +010062 *
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010063 * @return The graph configuration
Georgios Pinitasff421f22017-10-04 16:53:58 +010064 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010065 const GraphConfig &config() const;
66 /** Sets graph configuration
67 *
68 * @param[in] config Configuration to use
69 */
70 void set_config(const GraphConfig &config);
71 /** Inserts a memory manager context
72 *
73 * @param[in] memory_ctx Memory manage context
74 *
75 * @return If the insertion succeeded else false
76 */
77 bool insert_memory_management_ctx(MemoryManagerContext &&memory_ctx);
78 /** Gets a memory manager context for a given target
79 *
80 * @param[in] target To retrieve the management context
81 *
82 * @return Management context for the target if exists else nullptr
83 */
84 MemoryManagerContext *memory_management_ctx(Target target);
85 /** Finalizes memory managers in graph context */
86 void finalize();
Georgios Pinitasff421f22017-10-04 16:53:58 +010087
88private:
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010089 GraphConfig _config; /**< Graph configuration */
90 std::map<Target, MemoryManagerContext> _memory_managers; /**< Memory managers for each target */
Georgios Pinitasff421f22017-10-04 16:53:58 +010091};
92} // namespace graph
93} // namespace arm_compute
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010094#endif /* __ARM_COMPUTE_GRAPH_GRAPH_CONTEXT_H__ */