Compute Library
 21.02
Workload.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2020 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  */
25 
29 
30 namespace arm_compute
31 {
32 namespace graph
33 {
35 {
37 }
38 
40 {
41  if(task.task)
42  {
43  task.task->run();
44  }
45 #ifdef ARM_COMPUTE_ASSERTS_ENABLED
46  // COMPMID-3012 - Hide the printing logic from the execute_task method in the graph API
47  else if(task.node->type() == NodeType::PrintLayer)
48  {
49  auto print_node = dynamic_cast<PrintLayerNode *>(task.node);
50  auto input_handle = print_node->input(0)->handle();
51  auto transform = print_node->transform();
52 
53  input_handle->map(true);
54  ITensor *input = transform ? transform(&input_handle->tensor()) : &input_handle->tensor();
55  input->print(print_node->stream(), print_node->format_info());
56  input_handle->unmap();
57  }
58 #endif // ARM_COMPUTE_ASSERTS_ENABLED
59 }
60 
62 {
63  if(task)
64  {
65  task->prepare();
66  }
67 }
68 
69 TaskExecutor::TaskExecutor()
70  : execute_function(execute_task)
71 {
72 }
73 
75 {
76  static TaskExecutor executor;
77  return executor;
78 }
79 } // namespace graph
80 } // namespace arm_compute
void operator()()
Function operator.
Definition: Workload.cpp:34
ITensorHandle * handle()
Backend tensor handle accessor.
Definition: Tensor.cpp:55
void prepare()
Prepare execution task.
Definition: Workload.cpp:61
Interface for Neon tensor.
Definition: ITensor.h:36
Copyright (c) 2017-2021 Arm Limited.
std::unique_ptr< arm_compute::IFunction > task
Task to execute.
Definition: Workload.h:87
void execute_task(ExecutionTask &task)
Definition: Workload.cpp:39
virtual void map(bool blocking)=0
Maps backend tensor object.
static TaskExecutor & get()
Task executor accessor.
Definition: Workload.cpp:74
void print(std::ostream &s, IOFormatInfo io_fmt=IOFormatInfo()) const
Print a tensor to a given stream using user defined formatting information.
virtual NodeType type() const =0
Returns node&#39;s type.
INode * node
Node bound to this workload.
Definition: Workload.h:88
Tensor * input(size_t idx) const
Returns the tensor of a given input of the node.
Definition: INode.cpp:150
std::function< decltype(execute_task)> execute_function
Function that is responsible for executing tasks.
Definition: Workload.h:63