Compute Library
 21.02
arm_compute::test::convolution_3d::detail Namespace Reference

Functions

bool is_valid_pixel (int i, int min, int max)
 
template<typename T , typename TW , typename TB , typename std::enable_if< validation::is_floating_point< T >::value &&validation::is_floating_point< TW >::value &&validation::is_floating_point< TB >::value, int >::type = 0>
void convolution3d (const SimpleTensor< T > &in, const SimpleTensor< TW > &weights, const SimpleTensor< TB > &bias, SimpleTensor< T > &out, int i_offset, int w_offset, int b_offset, int o_offset, int xi, int yi, int width_in, int height_in, int depth_in, int width_weights, int height_weights, int dilation_x=1, int dilation_y=1, int filter_id=0)
 

Function Documentation

◆ convolution3d()

void convolution3d ( const SimpleTensor< T > &  in,
const SimpleTensor< TW > &  weights,
const SimpleTensor< TB > &  bias,
SimpleTensor< T > &  out,
int  i_offset,
int  w_offset,
int  b_offset,
int  o_offset,
int  xi,
int  yi,
int  width_in,
int  height_in,
int  depth_in,
int  width_weights,
int  height_weights,
int  dilation_x = 1,
int  dilation_y = 1,
int  filter_id = 0 
)
inline

Definition at line 49 of file Convolution3d.h.

References ARM_COMPUTE_UNUSED, SimpleTensor< T >::data(), and is_valid_pixel().

Referenced by arm_compute::test::validation::reference::convolution_layer_nchw().

52 {
53  ARM_COMPUTE_UNUSED(filter_id);
54  const T *in_ptr = in.data() + i_offset;
55  const TW *w_ptr = weights.data() + w_offset;
56  const TB *b_ptr = bias.data() + b_offset;
57  T *out_ptr = out.data() + o_offset;
58 
59  const int half_width_weights_start = width_weights / 2;
60  const int half_width_weights_end = ((width_weights % 2) == 0) ? (half_width_weights_start - 1) : half_width_weights_start;
61  const int half_height_weights_start = height_weights / 2;
62  const int half_height_weights_end = ((height_weights % 2) == 0) ? (half_height_weights_start - 1) : half_height_weights_start;
63 
64  // Reset accumulator
65  T acc(0);
66 
67  // Compute a 2D convolution for each IFM and accumulate the result
68  for(int ifm = 0; ifm < depth_in; ++ifm)
69  {
70  // Compute the offset for the input slice
71  const int offset_slice_in = xi + yi * width_in + ifm * width_in * height_in;
72 
73  // Compute 2D convolution
74  for(int yk = -half_height_weights_start; yk <= half_height_weights_end; ++yk)
75  {
76  for(int xk = -half_width_weights_start; xk <= half_width_weights_end; ++xk)
77  {
78  // Check if the pixel is out-of-bound
79  if(is_valid_pixel(xi + xk * dilation_x, 0, width_in) && is_valid_pixel(yi + yk * dilation_y, 0, height_in))
80  {
81  const int idx = xk + half_width_weights_start;
82  const int idy = yk + half_height_weights_start;
83 
84  const T i_value = in_ptr[offset_slice_in + xk * dilation_x + yk * dilation_y * width_in];
85  const TW w_value = w_ptr[idx + idy * width_weights + ifm * width_weights * height_weights];
86 
87  acc += i_value * w_value;
88  }
89  }
90  }
91  }
92 
93  // Accumulate the bias and store the result
94  *out_ptr = acc + (*b_ptr);
95 }
bool is_valid_pixel(int i, int min, int max)
Definition: Convolution3d.h:40
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152

◆ is_valid_pixel()

bool arm_compute::test::convolution_3d::detail::is_valid_pixel ( int  i,
int  min,
int  max 
)
inline

Definition at line 40 of file Convolution3d.h.

Referenced by convolution3d().

41 {
42  return (i >= min && i < max);
43 }