Compute Library
 22.08
ClCompositeOperator Class Reference

Operator runtime to run a ClWorkload. More...

#include <ClCompositeOperator.h>

Public Member Functions

 ClCompositeOperator ()
 
 ~ClCompositeOperator ()
 
void configure (const CLCompileContext &ctx, const ClWorkload &workload)
 Configures a ClCompositeOperator with a ClWorkload This includes the compilation of Cl kernels inside the ClWorkload. More...
 
void prepare (TensorPackMap &tensor_pack_map)
 Enqueue prepare workloads. More...
 
void run (TensorPackMap &tensor_pack_map)
 Enqueue run workloads. More...
 

Static Public Member Functions

static Status validate (const ClWorkload &workload)
 Validate ClWorkload workload. More...
 

Detailed Description

Operator runtime to run a ClWorkload.

Note
User must explicitly call prepare before run otherwise run will fail.
Examples:
dynamic_fusion/cl_fused_conv2d_elementwise_add.cpp.

Definition at line 151 of file ClCompositeOperator.h.

Constructor & Destructor Documentation

◆ ClCompositeOperator()

Definition at line 167 of file ClCompositeOperator.cpp.

References ClCompositeOperator::~ClCompositeOperator().

168  : _impl{ std::make_unique<Implementation>() }
169 {
170 }

◆ ~ClCompositeOperator()

Member Function Documentation

◆ configure()

void configure ( const CLCompileContext ctx,
const ClWorkload workload 
)

Configures a ClCompositeOperator with a ClWorkload This includes the compilation of Cl kernels inside the ClWorkload.

Parameters
[in]ctxCLCompileContext
[in]workloadClWorkload to configure with

Definition at line 174 of file ClCompositeOperator.cpp.

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_THROW_ON, IWorkload::graph, arm_compute::test::validation::k, UnitWorkloadStage::Prepare, UnitWorkloadStage::Run, DependencyGraph::topological_sort(), ClWorkload::unit_workloads, ClCompositeOperator::validate(), and arm_compute::test::validation::workload.

Referenced by arm_compute::test::validation::TEST_CASE().

175 {
177  _impl->_workload = workload;
178 
179  // Traverse workloads in topological order
180  const auto sorted = workload.graph.topological_sort().second;
181  for(const auto &node : sorted)
182  {
183  auto work = workload.unit_workloads.at(node.op);
184  auto stage = work.stage.stage;
185  auto k = std::make_unique<ClCompositeKernel>();
186  k->configure(ctx, work.code);
187 
188  switch(stage)
189  {
191  _impl->_kernels.emplace(work.id, std::move(k));
192  break;
194  _impl->_kernels_prep.emplace(work.id, std::move(k));
195  break;
196  default:
197  ARM_COMPUTE_ERROR("Invalid stage");
198  }
199  break;
200  }
201 }
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
static Status validate(const ClWorkload &workload)
Validate ClWorkload workload.

◆ prepare()

void prepare ( TensorPackMap tensor_pack_map)

Enqueue prepare workloads.

Parameters
tensor_pack_mapTensors required by the prepare workloads

Definition at line 208 of file ClCompositeOperator.cpp.

References CLScheduler::enqueue_op(), CLScheduler::get(), and TensorPackMap::get_tensor_pack().

Referenced by arm_compute::test::validation::TEST_CASE().

209 {
210  if(!_impl->_is_prepared)
211  {
212  for(auto &id_kernel_pair : _impl->_kernels_prep)
213  {
214  const bool flush_queue = false;
215  const auto uwk_id = id_kernel_pair.first;
216  auto kernel = id_kernel_pair.second.get();
217  CLScheduler::get().enqueue_op(*kernel, tensor_pack_map.get_tensor_pack(uwk_id), ClExecutionDescriptor{}, flush_queue);
218  }
219 
220  _impl->_is_prepared = true;
221  }
222 }
static CLScheduler & get()
Access the scheduler singleton.
void enqueue_op(ICLKernel &kernel, ITensorPack &tensors, bool flush=true)
Schedule the execution of the passed kernel if possible.

◆ run()

void run ( TensorPackMap tensor_pack_map)

Enqueue run workloads.

Parameters
tensor_pack_mapTensors required by the run workloads

Definition at line 224 of file ClCompositeOperator.cpp.

References ARM_COMPUTE_ERROR_ON_MSG, CLScheduler::enqueue_op(), CLScheduler::get(), and TensorPackMap::get_tensor_pack().

Referenced by arm_compute::test::validation::TEST_CASE().

225 {
226  ARM_COMPUTE_ERROR_ON_MSG(!_impl->_is_prepared, "Operator is not prepared");
227 
228  for(auto &id_kernel_pair : _impl->_kernels)
229  {
230  // Flush the command queue on the last kernel
231  const bool flush_queue = false;
232  const auto uwk_id = id_kernel_pair.first;
233  auto kernel = id_kernel_pair.second.get();
234  CLScheduler::get().enqueue_op(*kernel, tensor_pack_map.get_tensor_pack(uwk_id), ClExecutionDescriptor{}, flush_queue);
235  }
236 }
static CLScheduler & get()
Access the scheduler singleton.
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
void enqueue_op(ICLKernel &kernel, ITensorPack &tensors, bool flush=true)
Schedule the execution of the passed kernel if possible.

◆ validate()

Status validate ( const ClWorkload workload)
static

Validate ClWorkload workload.

Parameters
[in]workloadClWorkload to be validated
Returns
Status

Definition at line 203 of file ClCompositeOperator.cpp.

References ClWorkload::status.

Referenced by ClCompositeOperator::configure(), and arm_compute::test::validation::TEST_CASE().

204 {
205  return workload.status;
206 }

The documentation for this class was generated from the following files: