Compute Library
 22.11
ClWorkload.cpp
Go to the documentation of this file.
1 /*
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 #ifdef ENABLE_EXPERIMENTAL_DYNAMIC_FUSION
29 
30 namespace arm_compute
31 {
32 namespace experimental
33 {
34 namespace dynamic_fusion
35 {
37 {
38  workload.context = ctx;
39  ClKernelGraph kernel_graph;
40  workload.status = validate(op_graph);
42  workload.status = translate(kernel_graph, *op_graph.impl());
44  ClFusedKernelGraph fused_k_graph;
45  std::tie(workload.status, fused_k_graph) = init_fusion_graph(kernel_graph);
47  workload.status = fuse(fused_k_graph);
49  workload.status = generate(workload, ctx, fused_k_graph);
51 
52  // Get operator tensor id to workload tensor id map
53  const auto op_tensor_to_kernel_tensor = fused_k_graph.original_graph->graph.get_merge_points();
54  const auto kernel_tensor_to_workload_tensor = workload.graph.get_merge_points();
55  for(const auto op_t : op_graph.impl()->graph.src_tensors())
56  {
57  const auto kernel_t = op_tensor_to_kernel_tensor.at(op_t);
58  const auto workload_t = kernel_tensor_to_workload_tensor.at(kernel_t);
59  workload.op_tensor_id_lut[workload_t] = op_t;
60  }
61  for(const auto op_t : op_graph.impl()->graph.dst_tensors())
62  {
63  const auto kernel_t = op_tensor_to_kernel_tensor.at(op_t);
64  const auto workload_t = kernel_tensor_to_workload_tensor.at(kernel_t);
65  workload.op_tensor_id_lut[workload_t] = op_t;
66  }
67  return workload.status;
68 }
69 } // namespace dynamic_fusion
70 } // namespace experimental
71 } // namespace arm_compute
72 #endif /* ENABLE_EXPERIMENTAL_DYNAMIC_FUSION */
Status validate(const OperatorGraph &op_graph)
Return the validity of op_graph, usually after performing an operation (e.g.
DependencyGraph graph
Dependency graph of the workload tensors and the unit workloads.
Definition: IWorkload.h:125
std::map< Id, Id > get_merge_points() const
Get the merge points object.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
Context (device capabilities, platform details) associated with a ClWorkload.
Definition: ClWorkload.h:162
Graph of operators to execute within a Workload.
Definition: OperatorGraph.h:42
Status class.
Definition: Error.h:52
ClWorkloadContext context
Workload context.
Definition: ClWorkload.h:198
Status translate(ClKernelGraph &kernel_graph, const OperatorGraph::Implementation &op_graph)
Copyright (c) 2017-2022 Arm Limited.
Status generate(ClWorkload &workload, const ClWorkloadContext &ctx, const ClFusedKernelGraph &fused_kernel_graph)
std::vector< Id > src_tensors(Id op) const
Get source tensors to an operator.
Status fuse(ClFusedKernelGraph &fused_kernel_graph)
std::vector< Id > dst_tensors(Id op) const
Get destination tensors to an operator.
Status status
For compatibility with the IOperator validate method.
Definition: ClWorkload.h:202
Status build(ClWorkload &workload, const OperatorGraph &op_graph, const ClWorkloadContext &ctx)
Build a ClWorkload from an OperatorGraph.
Definition: ClWorkload.cpp:36
std::map< Tid, OpTensor::Id > op_tensor_id_lut
Map from ClWorkloadTensor to SRC and DST Operator Tensors (no need to store "intermediate" Operator T...
Definition: ClWorkload.h:201
std::pair< Status, ClFusedKernelGraph > init_fusion_graph(const ClKernelGraph &kernel_graph)