Compute Library
 22.11
arm_conv::depthwise::interleaves::quantized Namespace Reference

Functions

size_t get_storage_size (const DepthwiseArgs &args, const arm_gemm::VLType vl_type, const unsigned int accumulator_depth_vl)
 
template<typename T >
void pack_parameters (void *_buffer, const int32_t *biases, const T *weights, size_t ld_weight_col, size_t ld_weight_row, const DepthwiseArgs &args, const arm_gemm::Requantize32 &qp, const arm_gemm::VLType vl_type, const unsigned int accumulator_depth_vl)
 
template void pack_parameters (void *, const int32_t *, const int8_t *, size_t, size_t, const DepthwiseArgs &, const arm_gemm::Requantize32 &, arm_gemm::VLType, unsigned int)
 
template void pack_parameters (void *, const int32_t *, const uint8_t *, size_t, size_t, const DepthwiseArgs &, const arm_gemm::Requantize32 &, arm_gemm::VLType, unsigned int)
 

Function Documentation

◆ get_storage_size()

size_t get_storage_size ( const DepthwiseArgs &  args,
const arm_gemm::VLType  vl_type,
const unsigned int  accumulator_depth_vl 
)

Definition at line 33 of file generic_quantized_dot_product.cpp.

References arm_gemm::iceildiv().

Referenced by DepthfirstMultiplierStrategy< TInput, TWeight, TOutput, int32_t >::get_storage_size().

38 {
39  // We produce VL<int32_t> channels at a time, for each of these blocks of
40  // channels we store a vector of biases, weights (complicated) and
41  // requantize parameters.
42  const unsigned int iter_length = accumulator_depth_vl * arm_gemm::utils::get_vector_length<int32_t>(vl_type);
43  const unsigned int n_iters = args.input_channels * arm_gemm::iceildiv(args.channel_multiplier, iter_length);
44 
45  // Compute the cost of storing the weights
46  const unsigned int n_dots_per_kernel_row = arm_gemm::iceildiv(args.kernel_cols, 4u);
47 
48  return n_iters * iter_length * (
49  sizeof(int32_t) + // Bias
50  4 * n_dots_per_kernel_row * args.kernel_rows * sizeof(int8_t) + // Weights
51  2 * sizeof(int32_t) // Requantisation parameters
52  );
53 }
T iceildiv(const T a, const T b)
Definition: utils.hpp:65

◆ pack_parameters() [1/3]

void pack_parameters ( void *  _buffer,
const int32_t *  biases,
const T *  weights,
size_t  ld_weight_col,
size_t  ld_weight_row,
const DepthwiseArgs &  args,
const arm_gemm::Requantize32 qp,
const arm_gemm::VLType  vl_type,
const unsigned int  accumulator_depth_vl 
)

Definition at line 56 of file generic_quantized_dot_product.cpp.

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.

Referenced by DepthwiseDepthfirstGenericQuantized< Strategy, OutputRows, OutputCols >::pack_parameters(), DepthwiseDepthfirstQuantized< strategy >::pack_parameters(), and DepthwiseDepthfirstGeneric< TInput, TWeight, TOutput, TAccum, OutputStage >::pack_parameters().

64 {
65  auto buffer = static_cast<uint8_t *>(_buffer);
68 
69  const unsigned int iter_length = accumulator_depth_vl * arm_gemm::utils::get_vector_length<int32_t>(vl_type);
70  const unsigned int n_iters_per_input_channel = arm_gemm::iceildiv(args.channel_multiplier, iter_length);
71  const unsigned int n_dots_per_kernel_row = arm_gemm::iceildiv(args.kernel_cols, 4u);
72 
73  const size_t iter_stride = iter_length * (
74  sizeof(int32_t) + // Bias
75  4 * n_dots_per_kernel_row * args.kernel_rows * sizeof(T) + // Weights
76  2 * sizeof(int32_t) // Requantisation parameters
77  );
78 
79  ld_weight_col = (ld_weight_col == 0) ? args.input_channels * args.channel_multiplier : ld_weight_col;
80  ld_weight_row = (ld_weight_row == 0) ? args.kernel_cols * ld_weight_col : ld_weight_row;
81 
82  for (unsigned int input_channel = 0; input_channel < args.input_channels; input_channel++)
83  {
84  auto buffer_input_channel = buffer + input_channel * n_iters_per_input_channel * iter_stride;
85  auto weights_input_channel = weights + input_channel * args.channel_multiplier;
86 
87  for (unsigned int iter = 0; iter < n_iters_per_input_channel; iter++)
88  {
89  // Get a pointer to the start of this portion of the buffer; consequently
90  // derive pointers to the bias, weight and requantisation portions of
91  // this frame.
92  auto buffer_base = buffer_input_channel + iter_stride * iter;
93  auto buffer_biases = reinterpret_cast<int32_t *>(buffer_base);
94  auto buffer_weights = buffer_base + sizeof(int32_t) * iter_length;
95  auto buffer_requant_mul = reinterpret_cast<int32_t *>(
96  buffer_weights + args.kernel_rows * n_dots_per_kernel_row * 4 * iter_length);
97  auto buffer_requant_shift = buffer_requant_mul + iter_length;
98  auto weights_base = weights_input_channel + iter * iter_length;
99 
100  // Hence work through the data for this iteration, on a
101  // channel-by-channel basis.
102  const auto this_iter_length = std::min<unsigned int>(
103  iter_length, args.channel_multiplier - iter * iter_length
104  );
105  for (unsigned int i = 0; i < this_iter_length; i++)
106  {
107  auto weights_channel = weights_base + i;
108 
109  // Read the bias value, we modify this as we read the weights.
110  auto bias_value = biases == nullptr ? 0 : *(biases++);
111  int32_t elements_sum = 0;
112 
113  // Read through the kernel; for each row, marshal together as many dot
114  // product terms as are required.
115  for (unsigned int ki = 0; ki < args.kernel_rows; ki++)
116  {
117  auto buffer_row = buffer_weights + i*4 + ki * 4 * n_dots_per_kernel_row * iter_length;
118  auto weights_row = weights_channel + ki * ld_weight_row;
119 
120  unsigned int kj = 0;
121  for (; kj < args.kernel_cols; kj++)
122  {
123  // Determine which element to which we're writing
124  const auto dot = kj / 4;
125  const auto elem = kj % 4;
126 
127  // Copy the value; include in the sum
128  const auto val = weights_row[kj * ld_weight_col];
129  buffer_row[dot * 4 * iter_length + elem] = val;
130  elements_sum += val;
131  }
132  for (; kj < 4 * n_dots_per_kernel_row; kj++)
133  {
134  const auto dot = kj / 4;
135  const auto elem = kj % 4;
136  buffer_row[dot * 4 * iter_length + elem] = 0;
137  }
138 
139  buffer_row += 4 * n_dots_per_kernel_row * iter_length;
140  }
141 
142  // Write back the bias and offset values
143  *(buffer_biases++) =
144  bias_value - qp.a_offset * elements_sum +
145  args.kernel_rows * args.kernel_cols * qp.a_offset * qp.b_offset;
146 
147  // Write out the requantisation parameters
148  *(buffer_requant_mul++) = qp.per_channel_requant ? *(requant_muls++) : qp.per_layer_mul;
149  *(buffer_requant_shift++) = qp.per_channel_requant ? *(requant_shifts++) : qp.per_layer_right_shift;
150  }
151  }
152  }
153 }
T iceildiv(const T a, const T b)
Definition: utils.hpp:65
int32_t per_layer_right_shift
Definition: arm_gemm.hpp:179
const int32_t * per_channel_right_shifts
Definition: arm_gemm.hpp:182
const int32_t * requant_muls
const int32_t * requant_shifts
const int32_t * per_channel_muls
Definition: arm_gemm.hpp:183

◆ pack_parameters() [2/3]

template void arm_conv::depthwise::interleaves::quantized::pack_parameters ( void *  ,
const int32_t *  ,
const int8_t *  ,
size_t  ,
size_t  ,
const DepthwiseArgs &  ,
const arm_gemm::Requantize32 ,
arm_gemm::VLType  ,
unsigned  int 
)

◆ pack_parameters() [3/3]

template void arm_conv::depthwise::interleaves::quantized::pack_parameters ( void *  ,
const int32_t *  ,
const uint8_t *  ,
size_t  ,
size_t  ,
const DepthwiseArgs &  ,
const arm_gemm::Requantize32 ,
arm_gemm::VLType  ,
unsigned  int 
)