Compute Library
 22.08
arm_conv::depthwise::interleaves Namespace Reference

Namespaces

 quantized
 

Data Structures

struct  PackingArguments
 

Functions

size_t get_storage_size_generic (const PackingArguments &packing_args, const DepthwiseArgs &args)
 
void pack_parameters_generic (const PackingArguments &packing_args, const DepthwiseArgs &args, void *buffer_raw, const void *biases_raw, const void *weights_raw, size_t ld_weight_col, size_t ld_weight_row)
 

Function Documentation

◆ get_storage_size_generic()

size_t get_storage_size_generic ( const PackingArguments packing_args,
const DepthwiseArgs &  args 
)

Definition at line 45 of file generic.cpp.

References PackingArguments::accumulator_depth_vl, PackingArguments::accumulator_element_size, PackingArguments::bias_element_size, arm_gemm::iceildiv(), PackingArguments::include_bias, PackingArguments::kernel_points(), PackingArguments::vl_type, and PackingArguments::weight_element_size.

Referenced by DepthfirstStrategy< TInput, TWeight, TOutput, TAccum, Nothing >::get_storage_size(), DepthfirstMultiplierStrategy< TInput, TWeight, TOutput, TAccum >::get_storage_size(), GenericDepthfirstStrategy< TInput, TWeight, TOutput, TAccum, OutputStage >::get_storage_size(), DepthwiseDepthfirstStrategy< TInput, TWeight, TOutput, int32_t >::get_storage_size(), PlanarStrategy< TInput, TWeight, TOutput, TAccum, OutputStage >::get_storage_size(), GenericDepthfirstMultiplierStrategy< TInput, TWeight, TOutput, TAccum, OutputStage >::get_storage_size(), PackingArguments::kernel_points(), and pack_parameters_generic().

46 {
47  // If the channel multiplier is greater than one, then we treat this as a
48  // repeated packing of `channel_multiplier`-sized problems.
49  if (args.channel_multiplier > 1)
50  {
51  DepthwiseArgs args_per_input_channel(args);
52  args_per_input_channel.input_channels = args.channel_multiplier;
53  args_per_input_channel.channel_multiplier = 1;
54 
55  return args.input_channels * get_storage_size_generic(packing_args, args_per_input_channel);
56  }
57 
58  const unsigned int vl =
59  packing_args.accumulator_depth_vl *
60  arm_gemm::utils::get_vector_length<uint8_t>(packing_args.vl_type) / packing_args.accumulator_element_size;
61  const unsigned int n_packs = arm_gemm::iceildiv(args.input_channels, vl);
62  const auto pack_size = (packing_args.include_bias ? packing_args.bias_element_size : 0) +
63  packing_args.kernel_points() * packing_args.weight_element_size;
64  return n_packs * pack_size * vl;
65 }
T iceildiv(const T a, const T b)
Definition: utils.hpp:65
size_t get_storage_size_generic(const PackingArguments &packing_args, const DepthwiseArgs &args)
Definition: generic.cpp:45

◆ pack_parameters_generic()

void pack_parameters_generic ( const PackingArguments packing_args,
const DepthwiseArgs &  args,
void *  buffer_raw,
const void *  biases_raw,
const void *  weights_raw,
size_t  ld_weight_col,
size_t  ld_weight_row 
)

Definition at line 67 of file generic.cpp.

References PackingArguments::accumulator_depth_vl, PackingArguments::accumulator_element_size, PackingArguments::bias_element_size, arm_compute::test::validation::for(), get_storage_size_generic(), PackingArguments::get_weight_pos, PackingArguments::include_bias, PackingArguments::kernel_cols, arm_compute::test::validation::n, PackingArguments::vl_type, and PackingArguments::weight_element_size.

Referenced by PackingArguments::kernel_points(), DepthfirstMultiplierStrategy< TInput, TWeight, TOutput, TAccum >::pack_parameters(), DepthfirstStrategy< TInput, TWeight, TOutput, TAccum, Nothing >::pack_parameters(), GenericDepthfirstStrategy< TInput, TWeight, TOutput, TAccum, OutputStage >::pack_parameters(), DepthwiseDepthfirstStrategy< TInput, TWeight, TOutput, int32_t >::pack_parameters(), PlanarStrategy< TInput, TWeight, TOutput, TAccum, OutputStage >::pack_parameters(), and GenericDepthfirstMultiplierStrategy< TInput, TWeight, TOutput, TAccum, OutputStage >::pack_parameters().

76 {
77  // Cast the pointers to byte sizes
78  auto *buffer = static_cast<uint8_t *>(buffer_raw);
79  auto *biases = static_cast<const uint8_t *>(biases_raw);
80  auto *weights = static_cast<const uint8_t *>(weights_raw);
81 
82  // If the channel multiplier is greater than one, then we treat this as a
83  // repeated packing of `channel_multiplier`-sized problems.
84  if (args.channel_multiplier > 1)
85  {
86  // Get a modified copy of the depthwise arguments
87  DepthwiseArgs args_per_input_channel(args);
88  args_per_input_channel.input_channels = args.channel_multiplier;
89  args_per_input_channel.channel_multiplier = 1;
90 
91  // Resolve the strides here
92  ld_weight_col = ld_weight_col ? ld_weight_col : args.input_channels * args.channel_multiplier;
93  ld_weight_row = ld_weight_row ? ld_weight_row : ld_weight_col * packing_args.kernel_cols;
94 
95  auto per_input_channel_size = get_storage_size_generic(packing_args, args_per_input_channel);
96 
97  for (unsigned int c = 0; c < args.input_channels; c++)
98  {
100  packing_args, args_per_input_channel, buffer, biases, weights, ld_weight_col, ld_weight_row);
101 
102  // Update the pointers
103  buffer += per_input_channel_size;
104  biases += (biases == nullptr) ? 0 : packing_args.bias_element_size * args.channel_multiplier;
105  weights += packing_args.weight_element_size * args.channel_multiplier;
106  }
107  return;
108  }
109 
110  // Finalise the weight strides
111  ld_weight_col = (ld_weight_col == 0) ? args.input_channels : ld_weight_col;
112  ld_weight_row = (ld_weight_row == 0) ? packing_args.kernel_cols * ld_weight_col : ld_weight_row;
113 
114  const unsigned int vl =
115  packing_args.accumulator_depth_vl *
116  arm_gemm::utils::get_vector_length<uint8_t>(packing_args.vl_type) / packing_args.accumulator_element_size;
117 
118  for (unsigned int n = 0; n < args.input_channels; n += vl)
119  {
120  const unsigned int todo = std::min(vl, args.input_channels - n);
121 
122  if (packing_args.include_bias)
123  {
124  if (biases != nullptr)
125  {
126  memcpy(buffer, biases, todo * packing_args.bias_element_size);
127  biases += todo * packing_args.bias_element_size;
128  }
129  else
130  {
131  memset(buffer, 0, vl * packing_args.bias_element_size);
132  }
133 
134  buffer += vl * packing_args.bias_element_size;
135  }
136 
137  // Copy each of the weights in turn
138  unsigned int kx, ky;
139  for (int kindex = 0; packing_args.get_weight_pos(kindex, kx, ky); kindex++)
140  {
141  const auto src_ptr = weights + (kx*ld_weight_row + ky*ld_weight_col + n) * packing_args.weight_element_size;
142  memcpy(buffer, src_ptr, todo * packing_args.weight_element_size);
143  buffer += vl * packing_args.weight_element_size;
144  }
145  }
146 }
for(size_t k=0;k< _target.size();++k)
Definition: Unstack.cpp:91
size_t get_storage_size_generic(const PackingArguments &packing_args, const DepthwiseArgs &args)
Definition: generic.cpp:45
void pack_parameters_generic(const PackingArguments &packing_args, const DepthwiseArgs &args, void *buffer_raw, const void *biases_raw, const void *weights_raw, size_t ld_weight_col, size_t ld_weight_row)
Definition: generic.cpp:67