Compute Library
 22.08
SharedVarTable Class Reference

A table of all the variables used in the kernel / blueprint Because we limit the DependencyGraph in the blueprint to a Linear Sequence for now, we only allow ** a single global variable (the accumulator) **. More...

#include <Common.h>

Data Structures

class  Arguments
 
struct  SharedVar
 A fully realized SharedVarLink. More...
 

Public Member Functions

void add (SharedVarLink var_link, SharedVarGroup group, ClKernelArgDescriptor runtime_desc, const std::string &name="unnamed")
 Create a SharedVar for a corresponding SharedVarLink (contains ArgumentID). More...
 
SharedVar get (const SharedVarLink &var_link) const
 Get the SharedVar associated with var_link. More...
 
Arguments get_kernel_arguments () const
 

Detailed Description

A table of all the variables used in the kernel / blueprint Because we limit the DependencyGraph in the blueprint to a Linear Sequence for now, we only allow ** a single global variable (the accumulator) **.

NOTE: the order they appear in the table is the order of their "declaration" in the component code, and is also their ID NOTE: the variables all have the scope of the full kernel function

Definition at line 92 of file Common.h.

Member Function Documentation

◆ add()

void add ( SharedVarLink  var_link,
SharedVarGroup  group,
ClKernelArgDescriptor  runtime_desc,
const std::string &  name = "unnamed" 
)
inline

Create a SharedVar for a corresponding SharedVarLink (contains ArgumentID).

If one has already been created for the SharedVarLink, simply return it instead of creating a new one

Note
: The order of insertion is important. There is one precondition: PRECOND: The components have been sorted topologically / is being traversed in topological order This ensures that all the consumer var links (Output, Automatic Links) can consume (return) the producer var links when they're referred

Definition at line 153 of file Common.h.

References SharedVarLink::arg_id, arm_compute::experimental::dynamic_fusion::Argument, ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_MSG, arm_compute::experimental::dynamic_fusion::Automatic, SharedVarLink::io, SharedVarLink::is_empty(), name, arm_compute::experimental::dynamic_fusion::Output, and arm_compute::test::validation::ss().

Referenced by ClStoreBlockBoundaryAwareKernelComponent::allocate_shared_vars(), ClDirectConvolutionKernelComponent::allocate_shared_vars(), ClFloorKernelComponent::allocate_shared_vars(), ClElementwiseKernelComponent::allocate_shared_vars(), and ClStoreIndirectWidthSelectKernelComponent::allocate_shared_vars().

154  {
155  ARM_COMPUTE_ERROR_ON_MSG(var_link.is_empty(), "Non-empty SharedVarLink expected");
156  if(!get(var_link).is_empty())
157  {
158  return;
159  }
160 
161  auto var_id = _num_var;
162  std::stringstream ss;
163  ss << name << "_" << var_id;
164  const auto uniq_name = ss.str();
165  SharedVar var{ var_link.arg_id, var_link.io, group, uniq_name, runtime_desc };
166 
167  if(group == SharedVarGroup::Argument)
168  {
169  _arguments.emplace(var_id, var);
170  _arg_id_map.emplace(var_link.arg_id, var_id);
171  _num_var++;
172  }
173  else if(group == SharedVarGroup::Automatic)
174  {
175  if(_global_vars.empty())
176  {
177  if(var_link.io == SharedVarIO::Output)
178  {
179  _global_vars.emplace(var_id, var);
180  _arg_id_map.emplace(var_link.arg_id, var_id);
181  _num_var++;
182  }
183  else
184  {
185  ARM_COMPUTE_ERROR("Component likely not traversed in topological order");
186  }
187  }
188  else
189  {
190  // Associate additional SharedVarLinks with the single global shared variable
191  const auto global_var_id = _global_vars.begin()->first;
192  _arg_id_map[var_link.arg_id] = global_var_id;
193  }
194  }
195  else
196  {
197  ARM_COMPUTE_ERROR("Unrecognised SharedVarGroup");
198  }
199  }
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
std::stringstream ss(mlgo_str)
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
const char * name

◆ get()

SharedVar get ( const SharedVarLink var_link) const
inline

Get the SharedVar associated with var_link.

Parameters
var_link
Returns
SharedVar

Definition at line 206 of file Common.h.

Referenced by ClStoreBlockBoundaryAwareKernelComponent::get_tag_lut(), ClDirectConvolutionKernelComponent::get_tag_lut(), ClFloorKernelComponent::get_tag_lut(), ClElementwiseKernelComponent::get_tag_lut(), and ClStoreIndirectWidthSelectKernelComponent::get_tag_lut().

207  {
208  const SharedVar empty_var{};
209  if(_arg_id_map.find(var_link.arg_id) != _arg_id_map.end())
210  {
211  const auto var_id = _arg_id_map.at(var_link.arg_id);
212  const auto arg_var = _arguments.find(var_id);
213  if(arg_var != _arguments.end())
214  {
215  return arg_var->second;
216  }
217  else
218  {
219  return _global_vars.at(var_id);
220  }
221  }
222  return empty_var;
223  }

◆ get_kernel_arguments()

Arguments get_kernel_arguments ( ) const
inline
Note
The arguments are returned in the order they are added

Definition at line 227 of file Common.h.

References GemmTuner::args.

228  {
229  Arguments args{};
230  for(const auto &a : _arguments)
231  {
232  args.add_var(a.second);
233  }
234  return args;
235  }

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