Compute Library
 22.05
DepthwiseDepthfirstWithMultiplierQuantized< strategy > Class Template Reference

#include <depthwise_depthfirst_multiplier_quantized.hpp>

Collaboration diagram for DepthwiseDepthfirstWithMultiplierQuantized< strategy >:
[legend]

Public Member Functions

 DepthwiseDepthfirstWithMultiplierQuantized (const DepthwiseArgs &args, const arm_gemm::Requantize32 &qp)
 
 DepthwiseDepthfirstWithMultiplierQuantized (DepthwiseDepthfirstWithMultiplierQuantized &)=delete
 
DepthwiseDepthfirstWithMultiplierQuantizedoperator= (DepthwiseDepthfirstWithMultiplierQuantized &)=delete
 
size_t get_storage_size (void) const override
 
void pack_parameters (void *_buffer, const void *_biases, const void *_weights, size_t ld_weight_col, size_t ld_weight_row) override
 
size_t get_working_size (const unsigned int n_threads, const unsigned int n_channels) const override
 
void execute (const unsigned int batches, const unsigned int input_height, const unsigned int input_width, const unsigned int input_channels, const PaddingValues &padding, const void *const _input, const size_t ld_input_col, const size_t ld_input_row, const size_t ld_input_batch, const void *const parameters, const unsigned int output_height, const unsigned int output_width, void *const _output, const size_t ld_output_col, const size_t ld_output_row, const size_t ld_output_batch, void *const _working_space, const unsigned int thread_id, const unsigned int n_threads) const override
 

Detailed Description

template<class strategy>
class arm_conv::depthwise::DepthwiseDepthfirstWithMultiplierQuantized< strategy >

Definition at line 33 of file depthwise_depthfirst_multiplier_quantized.hpp.

Constructor & Destructor Documentation

◆ DepthwiseDepthfirstWithMultiplierQuantized() [1/2]

DepthwiseDepthfirstWithMultiplierQuantized ( const DepthwiseArgs &  args,
const arm_gemm::Requantize32 qp 
)
inline

Definition at line 55 of file depthwise_depthfirst_multiplier_quantized.hpp.

References DepthwiseDepthfirstWithMultiplierQuantized< strategy >::operator=().

56  : Parent(args), m_qp(qp)
57  {
58  }

◆ DepthwiseDepthfirstWithMultiplierQuantized() [2/2]

Member Function Documentation

◆ execute()

void execute ( const unsigned int  batches,
const unsigned int  input_height,
const unsigned int  input_width,
const unsigned int  input_channels,
const PaddingValues &  padding,
const void *const  _input,
const size_t  ld_input_col,
const size_t  ld_input_row,
const size_t  ld_input_batch,
const void *const  parameters,
const unsigned int  output_height,
const unsigned int  output_width,
void *const  _output,
const size_t  ld_output_col,
const size_t  ld_output_row,
const size_t  ld_output_batch,
void *const  _working_space,
const unsigned int  thread_id,
const unsigned int  n_threads 
) const
inlineoverride

Definition at line 189 of file depthwise_depthfirst_multiplier_quantized.hpp.

References Requantize32::a_offset, batches, DepthwiseDepthfirstWithMultiplierQuantized< strategy >::get_working_size(), arm_gemm::iceildiv(), input_height, input_width, outptr_array, arm_compute::test::parameters, and strategy.

210  {
211  strategy strat(this->m_args.cpu_info);
212 #ifdef CYCLE_PROFILING
213  arm_gemm::profiler prof;
214 #endif
215 
216  auto executefn = [strat, this] (
217  const TInput *const *const inptrs,
218  TOutput *const *const outptr_array,
219  const void *const params
220  ) {
221  strat.kernel(inptrs, outptr_array, params, this->m_args.channel_multiplier, m_qp);
222  };
223 
224  // Get working space for this thread
225  uint8_t *const working_space = static_cast<uint8_t *>(_working_space) + get_working_size(1, input_channels) * thread_id;
226 
227  // Determine the stride across blocks of parameters
228  const unsigned int iter_length =
229  arm_gemm::utils::get_vector_length<int32_t>(strategy::vl_type);
230  const unsigned int n_iters_per_input_channel = arm_gemm::iceildiv(this->m_args.channel_multiplier, iter_length);
231  const unsigned int n_dots_per_kernel_row = arm_gemm::iceildiv(strategy::kernel_cols, 4u);
232  const size_t param_stride = n_iters_per_input_channel * iter_length * (
233  sizeof(int32_t) + // Bias
234  4 * n_dots_per_kernel_row * strategy::kernel_rows * sizeof(int8_t) + // Weights
235  2 * sizeof(int32_t) // Requantisation parameters
236  );
237 
238  common::depthwise_multiplier_execute<strategy>(
239  executefn, m_qp.a_offset, this->m_args,
240  batches, input_height, input_width, input_channels, padding,
241  _input, ld_input_col, ld_input_row, ld_input_batch,
242  parameters, param_stride,
243  output_height, output_width,
244  _output, ld_output_col, ld_output_row, ld_output_batch,
245  working_space, thread_id, n_threads
246  );
247  }
T iceildiv(const T a, const T b)
Definition: utils.hpp:65
size_t get_working_size(const unsigned int n_threads, const unsigned int n_channels) const override
const size_t input_height
Definition: impl.cpp:61
const size_t input_width
Definition: impl.cpp:62
std::unique_ptr< ParametersLibrary > parameters
Definition: Framework.cpp:46
const StratType * strategy
unsigned int batches
T ** outptr_array

◆ get_storage_size()

size_t get_storage_size ( void  ) const
inlineoverride

Definition at line 63 of file depthwise_depthfirst_multiplier_quantized.hpp.

References arm_gemm::iceildiv().

64  {
65  // We produce VL<int32_t> channels at a time, for each of these blocks of
66  // channels we store a vector of biases, weights (complicated) and
67  // requantize parameters.
68  const unsigned int iter_length =
69  arm_gemm::utils::get_vector_length<int32_t>(strategy::vl_type);
70  const unsigned int n_iters =
71  this->m_args.input_channels * arm_gemm::iceildiv(this->m_args.channel_multiplier, iter_length);
72 
73  // Compute the cost of storing the weights
74  const unsigned int n_dots_per_kernel_row = arm_gemm::iceildiv(strategy::kernel_cols, 4u);
75 
76  return n_iters * iter_length * (
77  sizeof(int32_t) + // Bias
78  4 * n_dots_per_kernel_row * strategy::kernel_rows * sizeof(TWeight) + // Weights
79  2 * sizeof(int32_t) // Requantisation parameters
80  );
81  }
T iceildiv(const T a, const T b)
Definition: utils.hpp:65

◆ get_working_size()

size_t get_working_size ( const unsigned int  n_threads,
const unsigned int  n_channels 
) const
inlineoverride

Definition at line 182 of file depthwise_depthfirst_multiplier_quantized.hpp.

Referenced by DepthwiseDepthfirstWithMultiplierQuantized< strategy >::execute().

183  {
184  const unsigned int n_output_channels = n_channels * this->m_args.channel_multiplier;
185  return n_threads * sizeof_output_buffer(n_output_channels);
186  }

◆ operator=()

◆ pack_parameters()

void pack_parameters ( void *  _buffer,
const void *  _biases,
const void *  _weights,
size_t  ld_weight_col,
size_t  ld_weight_row 
)
inlineoverride

Definition at line 85 of file depthwise_depthfirst_multiplier_quantized.hpp.

References Requantize32::a_offset, Requantize32::b_offset, arm_gemm::iceildiv(), Requantize32::per_channel_muls, Requantize32::per_channel_requant, Requantize32::per_channel_right_shifts, Requantize32::per_layer_mul, Requantize32::per_layer_right_shift, requant_muls, and requant_shifts.

86  {
87  auto buffer = static_cast<uint8_t *>(_buffer);
88  auto biases = static_cast<const int32_t *>(_biases);
89  auto weights = static_cast<const TWeight *>(_weights);
90  auto requant_muls = m_qp.per_channel_muls;
92 
93  const unsigned int iter_length =
94  arm_gemm::utils::get_vector_length<int32_t>(strategy::vl_type);
95  const unsigned int n_iters_per_input_channel =
96  arm_gemm::iceildiv(this->m_args.channel_multiplier, iter_length);
97 
98  const unsigned int n_dots_per_kernel_row = arm_gemm::iceildiv(strategy::kernel_cols, 4u);
99 
100  const size_t iter_stride = iter_length * (
101  sizeof(int32_t) + // Bias
102  4 * n_dots_per_kernel_row * strategy::kernel_rows * sizeof(int8_t) + // Weights
103  2 * sizeof(int32_t) // Requantisation parameters
104  );
105 
106  ld_weight_col = (ld_weight_col == 0) ? this->m_args.input_channels * this->m_args.channel_multiplier : ld_weight_col;
107  ld_weight_row = (ld_weight_row == 0) ? this->m_args.kernel_cols * ld_weight_col : ld_weight_row;
108 
109  for (unsigned int input_channel = 0; input_channel < this->m_args.input_channels; input_channel++)
110  {
111  auto buffer_input_channel = buffer + input_channel * n_iters_per_input_channel * iter_stride;
112  auto weights_input_channel = weights + input_channel * this->m_args.channel_multiplier;
113 
114  for (unsigned int iter = 0; iter < n_iters_per_input_channel; iter++)
115  {
116  // Get a pointer to the start of this portion of the buffer; consequently
117  // derive pointers to the bias, weight and requantisation portions of
118  // this frame.
119  auto buffer_base = buffer_input_channel + iter_stride * iter;
120  auto buffer_biases = reinterpret_cast<int32_t *>(buffer_base);
121  auto buffer_weights = buffer_base + sizeof(int32_t) * iter_length;
122  auto buffer_requant_mul = reinterpret_cast<int32_t *>(
123  buffer_weights + strategy::kernel_rows * n_dots_per_kernel_row * 4 * iter_length);
124  auto buffer_requant_shift = buffer_requant_mul + iter_length;
125  auto weights_base = weights_input_channel + iter * iter_length;
126 
127  // Hence work through the data for this iteration, on a
128  // channel-by-channel basis.
129  const auto this_iter_length = std::min<unsigned int>(
130  iter_length, this->m_args.channel_multiplier - iter * iter_length
131  );
132  for (unsigned int i = 0; i < this_iter_length; i++)
133  {
134  auto weights_channel = weights_base + i;
135 
136  // Read the bias value, we modify this as we read the weights.
137  auto bias_value = biases == nullptr ? 0 : *(biases++);
138  int32_t elements_sum = 0;
139 
140  // Read through the kernel; for each row, marshal together as many dot
141  // product terms as are required.
142  for (unsigned int ki = 0; ki < strategy::kernel_rows; ki++)
143  {
144  auto buffer_row = buffer_weights + i*4 + ki * 4 * n_dots_per_kernel_row * iter_length;
145  auto weights_row = weights_channel + ki * ld_weight_row;
146 
147  unsigned int kj = 0;
148  for (; kj < strategy::kernel_cols; kj++)
149  {
150  // Determine which element to which we're writing
151  const auto dot = kj / 4;
152  const auto elem = kj % 4;
153 
154  // Copy the value; include in the sum
155  const auto val = weights_row[kj * ld_weight_col];
156  buffer_row[dot * 4 * iter_length + elem] = val;
157  elements_sum += val;
158  }
159  for (; kj < 4 * n_dots_per_kernel_row; kj++)
160  {
161  const auto dot = kj / 4;
162  const auto elem = kj % 4;
163  buffer_row[dot * 4 * iter_length + elem] = 0;
164  }
165 
166  buffer_row += 4 * n_dots_per_kernel_row * iter_length;
167  }
168 
169  // Write back the bias and offset values
170  *(buffer_biases++) =
171  bias_value - m_qp.a_offset * elements_sum +
172  strategy::kernel_rows * strategy::kernel_cols * m_qp.a_offset * m_qp.b_offset;
173 
174  // Write out the requantisation parameters
175  *(buffer_requant_mul++) = m_qp.per_channel_requant ? *(requant_muls++) : m_qp.per_layer_mul;
176  *(buffer_requant_shift++) = m_qp.per_channel_requant ? *(requant_shifts++) : m_qp.per_layer_right_shift;
177  }
178  }
179  }
180  }
T iceildiv(const T a, const T b)
Definition: utils.hpp:65
int32_t per_layer_right_shift
Definition: arm_gemm.hpp:137
const int32_t * per_channel_right_shifts
Definition: arm_gemm.hpp:140
const int32_t * requant_muls
const int32_t * requant_shifts
const int32_t * per_channel_muls
Definition: arm_gemm.hpp:141

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