blob: 942dbb70bb8a04d03affb22d561f77148d83cdb1 [file] [log] [blame]
SiCong Lib63b1192022-01-28 18:24:39 +00001/*
2 * Copyright (c) 2022 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 ENABLE_EXPERIMENTAL_DYNAMIC_FUSION
25#error "This experimental feature must be enabled with -DENABLE_EXPERIMENTAL_DYNAMIC_FUSION"
26#endif /* ENABLE_EXPERIMENTAL_DYNAMIC_FUSION */
27#ifndef ARM_COMPUTE_EXPERIMENTAL_DYNAMICFUSION_IWORKLOAD_H
28#define ARM_COMPUTE_EXPERIMENTAL_DYNAMICFUSION_IWORKLOAD_H
29
30#include "arm_compute/core/Error.h"
31#include "arm_compute/core/ITensorInfo.h"
32#include "arm_compute/core/experimental/Types.h"
33
34#include "arm_compute/core/experimental/DependencyGraph.h"
35
36namespace arm_compute
37{
38namespace experimental
39{
40namespace dynamic_fusion
41{
42/** Describes when a Unit Workload is run.
43 *
44 */
45struct UnitWorkloadStage
46{
47 enum class Stage
48 {
49 Prepare, /**< Only run once at the beginning. */
50 Run, /**< Run every time after the first time. */
51 };
52 Stage stage;
53 friend bool operator==(const UnitWorkloadStage &stage0, const UnitWorkloadStage &stage1)
54 {
55 return stage0.stage == stage1.stage;
56 }
57};
58/** Type of memory used by a Workload Tensor
59 *
60 */
61enum class MemoryType
62{
63 Core = 0, /**< Core memory used by the Workload Tensor, e.g. for argument tensors */
64 Auxiliary = 1, /**< Auxiliary memory required by the Workload Tensor, e.g. for temporary tensors */
65};
66
67using AuxMemoryLifetime = MemoryLifetime;
68
69/** Memory Info for a @ref WorkloadTensor of Auxiliary memory type. This communicates to the user how much additional
70 * memory is required for auxiliary tensors
71 */
72struct AuxMemoryInfo
73{
74 AuxMemoryInfo() = default;
75
76 AuxMemoryInfo(size_t size, size_t alignment = 0) noexcept
77 : size(size),
78 alignment(alignment)
79 {
80 }
81
82 AuxMemoryInfo(AuxMemoryLifetime lifetime, size_t size, size_t alignment = 0) noexcept
83 : lifetime(lifetime),
84 size(size),
85 alignment(alignment)
86 {
87 }
88 friend bool operator==(const AuxMemoryInfo &info0, const AuxMemoryInfo &info1)
89 {
90 return info0.lifetime == info1.lifetime && info0.size == info1.size && info0.alignment == info1.alignment;
91 }
92
93 AuxMemoryLifetime lifetime{ AuxMemoryLifetime::Temporary }; /**< Memory lifetime*/
94 size_t size{ 0 }; /**< Total memory size in bytes */
95 size_t alignment{ 64 }; /**< Memory alignment in bytes */
96};
97
98/** A descriptor for IWorkload Tensors.
99 */
100struct WorkloadTensor
101{
102 using Id = DependencyGraph::Id;
103 Id id{}; /**< Id of the workload tensor */
104 ITensorInfo *info{}; /**< TensorInfo associated with the workload tensor */
105 MemoryType memory_type{}; /**< Memory type */
106 AuxMemoryInfo memory_info{}; /**< Auxiliary memory information. This can be ignored if the memory type is Core */
107};
108/** The basic atomic unit in an @ref IWorkload. It contains exactly one kernel to run.
109 *
110 */
111struct UnitWorkload
112{
113 using Id = DependencyGraph::Id;
114 Id id{}; /**< Id of the unit workload */
115 UnitWorkloadStage stage{}; /**< Stage */
116};
117
118/** Run-time-agnostic, platform-specific graph that describes everything required to run a workload
119 * It can be configured into an Arm Compute Library runtime, integrated into the runtime of another framework, or integrated into the compilation flow
120 */
121struct IWorkload
122{
123 using UnitWorkId = UnitWorkload::Id;
124 using Tid = WorkloadTensor::Id;
125 IWorkload() = default;
126 virtual ~IWorkload() = default;
127 DependencyGraph graph{}; /**< Dependency graph of the workload tensors and the unit workloads */
128};
129
130} // namespace dynamic_fusion
131} // namespace experimental
132} // namespace arm_compute
133#endif //ARM_COMPUTE_EXPERIMENTAL_DYNAMICFUSION_IWORKLOAD_H