Compute Library
 22.11
GemvPretransposed< strategy, To, Tr, OutputStage > Class Template Reference

#include <gemv_pretransposed.hpp>

Collaboration diagram for GemvPretransposed< strategy, To, Tr, OutputStage >:
[legend]

Public Member Functions

 GemvPretransposed (GemvPretransposed &)=delete
 
GemvPretransposedoperator= (GemvPretransposed &)=delete
 
 GemvPretransposed (const GemmArgs &args, const OutputStage &os={})
 
ndrange_t get_window_size () const override
 
void execute (const ndcoord_t &work_range, const ndcoord_t &, int) override
 Main execute member fucntion. More...
 
bool B_is_pretransposed () const override
 
bool B_pretranspose_required () const override
 
size_t get_B_pretransposed_array_size () const override
 
void requantize_bias (void *in_buffer, const To *B, const int ldb, const int B_multi_stride) override
 
void pretranspose_B_array (void *buffer, const To *B, const int ldb, const int B_multi_stride) override
 
void set_pretransposed_B_data (void *buffer) override
 
GemmConfig get_config () override
 
- Public Member Functions inherited from GemmCommon< To, Tr >
virtual void set_arrays (const To *A, const int lda, const int A_batch_stride, const int A_multi_stride, const To *B, const int ldb, const int B_multi_stride, Tr *C, const int ldc, const int C_batch_stride, const int C_multi_stride, const Tr *bias, const int bias_multi_stride)
 
void set_arrays_generic (const void *A, const int lda, const int A_batch_stride, const int A_multi_stride, const void *B, const int ldb, const int B_multi_stride, void *C, const int ldc, const int C_batch_stride, const int C_multi_stride, const void *bias, const int bias_multi_stride) override
 
void pretranspose_B_array_generic (void *out, const void *in, const int row_stride, const int multi_stride) override
 
virtual void set_indirect_parameters (size_t, const To *const *const *)
 
void set_indirect_parameters_generic (size_t sz, const void *const *const *ptr) override
 
- Public Member Functions inherited from IGemmCommon
virtual void set_nthreads (int)
 
virtual bool supports_dynamic_scheduling () const
 
virtual size_t get_working_size () const
 
virtual void set_working_space (void *)
 
virtual void set_quantized_bias (const int32_t *, size_t)
 
virtual void set_convolution_parameters (ConvolutionParameters)
 
virtual ~IGemmCommon ()
 

Detailed Description

template<typename strategy, typename To, typename Tr, typename OutputStage = Nothing>
class arm_gemm::GemvPretransposed< strategy, To, Tr, OutputStage >

Definition at line 88 of file gemv_pretransposed.hpp.

Constructor & Destructor Documentation

◆ GemvPretransposed() [1/2]

GemvPretransposed ( GemvPretransposed< strategy, To, Tr, OutputStage > &  )
delete

◆ GemvPretransposed() [2/2]

GemvPretransposed ( const GemmArgs args,
const OutputStage &  os = {} 
)
inline

Definition at line 119 of file gemv_pretransposed.hpp.

References GemmArgs::_cfg, GemmArgs::_Ksize, GemmArgs::_Nsize, GemmConfig::inner_block_size, GemmConfig::outer_block_size, and arm_gemm::roundup().

119  {})
120  : _args(args),
121  _buffer_per_multi(roundup(args._Ksize, strategy::k_unroll()) * roundup(args._Nsize, strategy::out_width())),
122  _os(os) {
123  /* For now don't do any blocking. TODO: figure out if we should. */
124  if (strategy::supports_accumulate() && args._cfg && args._cfg->inner_block_size) {
125  k_block = args._cfg->inner_block_size;
126  } else {
127  k_block = args._Ksize;
128  }
129 
130  if (args._cfg && args._cfg->outer_block_size) {
131  n_block = args._cfg->outer_block_size;
132  } else {
133  n_block = args._Nsize;
134  }
135  }
T roundup(const T a, const T b)
Definition: utils.hpp:70

Member Function Documentation

◆ B_is_pretransposed()

bool B_is_pretransposed ( ) const
inlineoverridevirtual

Reimplemented from IGemmCommon.

Definition at line 191 of file gemv_pretransposed.hpp.

191  {
192  return true;
193  }

◆ B_pretranspose_required()

bool B_pretranspose_required ( ) const
inlineoverridevirtual

Reimplemented from IGemmCommon.

Definition at line 195 of file gemv_pretransposed.hpp.

195  {
196  /* Transpose is required if _B_pretransposed is still nullptr */
197  return (_B_pretransposed == nullptr);
198  }

◆ execute()

void execute ( const ndcoord_t work_range,
const ndcoord_t thread_locator,
int  threadid 
)
inlineoverridevirtual

Main execute member fucntion.

Parameters
[in]work_rangespecifies the range of work we want to be computed, total range defined by get_window_size()
[in]thread_locatorwhere are we inside of the thread space
[in]threadida unique threadid

Implements IGemmCommon.

Definition at line 143 of file gemv_pretransposed.hpp.

References GemmArgs::_act, GemmArgs::_ci, GemmArgs::_Ksize, GemmArgs::_Nsize, arm_compute::mlgo::parser::end(), NDCoordinate< N >::get_position(), NDCoordinate< N >::get_position_end(), arm_gemm::iceildiv(), arm_compute::test::validation::if(), arm_compute::test::validation::n, arm_gemm::roundup(), arm_compute::test::validation::run(), and strategy.

143  {
144 #ifdef CYCLE_PROFILING
145  profiler prof;
146 #endif
147  strategy strat(_args._ci);
148 
149  const auto start = work_range.get_position(0);
150  const auto end = work_range.get_position_end(0);
151 
152  /* Break the window values down into multis of interest... */
153  const unsigned int window_per_multi = iceildiv(_args._Nsize, strategy::out_width());
154  const unsigned int multi_0 = start / window_per_multi;
155  const unsigned int multi_end = end / window_per_multi;
156 
157  /* ... and figure out where we start and end in the first and last multi. */
158  const unsigned int n_0 = (start - (multi_0 * window_per_multi)) * strategy::out_width();
159  const unsigned int n_max = (end - (multi_end * window_per_multi)) * strategy::out_width();
160 
161  static_assert(std::is_same<Tr, Tri>::value, "GemvPretransposed: Result types must be the same.");
162 
163  for (unsigned int multi=multi_0; multi<=multi_end; multi++) {
164  const unsigned int n_start = (multi==multi_0) ? n_0 : 0;
165  const unsigned int n_end = (multi==multi_end) ? n_max : _args._Nsize;
166 
167  if (n_end <= n_start)
168  continue;
169 
170  for (unsigned int k0=0; k0<_args._Ksize; k0+=k_block) {
171  unsigned int kmax = std::min(k0 + k_block, _args._Ksize);
172 
173  for (unsigned int n=n_start; n<n_end; n+=n_block) {
174  unsigned int nmax = std::min(n + n_block, n_end);
175 #ifdef CYCLE_PROFILING
176  auto p = prof.ScopedProfiler(PROFILE_KERNEL, (kmax-k0) * (nmax-n));
177 #endif
178  run_gemv_kernel<OutputStage>::run(strat, this->_Aptr + (multi * this->_A_multi_stride) + k0,
179  _B_pretransposed + (multi * _buffer_per_multi) + (n * roundup(_args._Ksize, strategy::k_unroll())) + (k0 * strategy::out_width()),
180  this->_Cptr + (multi * this->_C_multi_stride) + n,
181  (nmax - n), (kmax-k0),
182  this->_bias ? this->_bias + (multi * this->_bias_multi_stride) + n : nullptr,
183  _args._act, (k0 != 0),
184  _os, col_bias, n + (_args._Nsize * multi));
185  }
186  }
187  }
188  }
T roundup(const T a, const T b)
Definition: utils.hpp:70
const CPUInfo * _ci
Definition: arm_gemm.hpp:145
unsigned int _Nsize
Definition: arm_gemm.hpp:147
Activation _act
Definition: arm_gemm.hpp:153
T iceildiv(const T a, const T b)
Definition: utils.hpp:65
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
const StratType * strategy
unsigned int _Ksize
Definition: arm_gemm.hpp:148

◆ get_B_pretransposed_array_size()

size_t get_B_pretransposed_array_size ( ) const
inlineoverridevirtual

Reimplemented from IGemmCommon.

Definition at line 200 of file gemv_pretransposed.hpp.

References GemmArgs::_nmulti.

200  {
201  return _buffer_per_multi * _args._nmulti * sizeof(To) + get_col_sum_size();
202  }
unsigned int _nmulti
Definition: arm_gemm.hpp:151

◆ get_config()

GemmConfig get_config ( )
inlineoverridevirtual

Implements IGemmCommon.

Definition at line 238 of file gemv_pretransposed.hpp.

References GemmConfig::filter, arm_gemm::GEMV_PRETRANSPOSED, GemmConfig::inner_block_size, GemmConfig::method, and GemmConfig::outer_block_size.

238  {
239  GemmConfig c;
240 
242  c.inner_block_size = k_block;
243  c.outer_block_size = n_block;
244  c.filter = get_type_name<strategy>();
245 
246  return c;
247  }

◆ get_window_size()

ndrange_t get_window_size ( ) const
inlineoverridevirtual
Returns
an ndrange containing ranges of the compute space which can be broken up and parallelised over

Implements IGemmCommon.

Definition at line 138 of file gemv_pretransposed.hpp.

References GemmArgs::_nmulti, GemmArgs::_Nsize, and arm_gemm::iceildiv().

138  {
139  return { iceildiv(_args._Nsize, strategy::out_width()) * _args._nmulti };
140  }
unsigned int _nmulti
Definition: arm_gemm.hpp:151
unsigned int _Nsize
Definition: arm_gemm.hpp:147
T iceildiv(const T a, const T b)
Definition: utils.hpp:65

◆ operator=()

GemvPretransposed& operator= ( GemvPretransposed< strategy, To, Tr, OutputStage > &  )
delete

◆ pretranspose_B_array()

void pretranspose_B_array ( void *  buffer,
const To *  B,
const int  ldb,
const int  B_multi_stride 
)
inlineoverridevirtual

Reimplemented from GemmCommon< To, Tr >.

Definition at line 218 of file gemv_pretransposed.hpp.

References GemmArgs::_ci, GemmArgs::_Ksize, GemmArgs::_nmulti, GemmArgs::_Nsize, and strategy.

218  {
219  requantize_bias(buffer, B, ldb, B_multi_stride);
220 
221  // The actual transposed buffer goes after the column sums (if any)
222  uintptr_t buffer_int = reinterpret_cast<uintptr_t>(buffer);
223  Toi *B_buffer = reinterpret_cast<Toi *>(buffer_int + get_col_sum_size());
224 
225  strategy strat(_args._ci);
226 
227  for (unsigned int multi=0; multi<_args._nmulti; multi++) {
228  strat.transforms.PrepareB(B_buffer + (multi * _buffer_per_multi), B + (multi * B_multi_stride), ldb, 0, _args._Nsize, 0, _args._Ksize);
229  }
230 
231  _B_pretransposed = B_buffer;
232  }
const CPUInfo * _ci
Definition: arm_gemm.hpp:145
unsigned int _nmulti
Definition: arm_gemm.hpp:151
unsigned int _Nsize
Definition: arm_gemm.hpp:147
void requantize_bias(void *in_buffer, const To *B, const int ldb, const int B_multi_stride) override
const StratType * strategy
unsigned int _Ksize
Definition: arm_gemm.hpp:148

◆ requantize_bias()

void requantize_bias ( void *  in_buffer,
const To *  B,
const int  ldb,
const int  B_multi_stride 
)
inlineoverridevirtual

Reimplemented from GemmCommon< To, Tr >.

Definition at line 204 of file gemv_pretransposed.hpp.

References GemmArgs::_Ksize, GemmArgs::_nmulti, GemmArgs::_Nsize, and arm_gemm::compute_col_sums().

204  {
205  // Column sums go on the front of the pretransposed buffer in requantized cases.
206  // We could optimize here in case we don't actually need to sum the columns, but this code is only run on setup.
207  if (std::is_same<OutputStage, Requantize32>::value) {
208  col_bias = reinterpret_cast<int32_t *>(in_buffer);
209 
210  Requantize32 *qp_ptr = reinterpret_cast<Requantize32 *>(&_os);
211 
212  for (unsigned int i=0; i<_args._nmulti; i++) {
213  compute_col_sums(*qp_ptr, _args._Nsize, _args._Ksize, B + (i * B_multi_stride), ldb, col_bias + (i * _args._Nsize), _args._Ksize, i, 0);
214  }
215  }
216  }
unsigned int _nmulti
Definition: arm_gemm.hpp:151
unsigned int _Nsize
Definition: arm_gemm.hpp:147
void compute_col_sums(const Requantize32 &qp, unsigned int width, unsigned int height, const T *input, unsigned int in_stride, int32_t *col_bias, unsigned int depth, unsigned int multi, unsigned int first_col)
unsigned int _Ksize
Definition: arm_gemm.hpp:148

◆ set_pretransposed_B_data()

void set_pretransposed_B_data ( void *  buffer)
inlineoverridevirtual

Reimplemented from IGemmCommon.

Definition at line 234 of file gemv_pretransposed.hpp.

234  {
235  _B_pretransposed = reinterpret_cast<Toi *>(buffer);
236  }

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