aboutsummaryrefslogtreecommitdiff
path: root/tests/validation/TensorOperations.h
diff options
context:
space:
mode:
Diffstat (limited to 'tests/validation/TensorOperations.h')
-rw-r--r--tests/validation/TensorOperations.h146
1 files changed, 0 insertions, 146 deletions
diff --git a/tests/validation/TensorOperations.h b/tests/validation/TensorOperations.h
index 84aa965a9f..f4d2110387 100644
--- a/tests/validation/TensorOperations.h
+++ b/tests/validation/TensorOperations.h
@@ -59,100 +59,6 @@ struct is_floating_point
{
};
-bool is_valid_pixel(int i, int min, int max)
-{
- return (i >= min && i < max);
-}
-
-// 3D convolution for floating point type
-template <typename T, typename std::enable_if<is_floating_point<T>::value, int>::type * = nullptr>
-void convolution3d(const T *in, const T *weights, const T *bias, T *out, int xi, int yi, int width_in, int height_in, int depth_in, int width_weights, int height_weights, int8_t fixed_point_position)
-{
- const int half_width_weights = width_weights / 2;
- const int half_height_weights = height_weights / 2;
-
- // Reset accumulator
- T acc = static_cast<T>(0);
-
- // Compute a 2D convolution for each IFM and accumulate the result
- for(int ifm = 0; ifm < depth_in; ++ifm)
- {
- // Compute the offset for the input slice
- const int offset_slice_in = xi + yi * width_in + ifm * width_in * height_in;
-
- // Compute 2D convolution
- for(int yk = -half_height_weights; yk <= half_height_weights; ++yk)
- {
- for(int xk = -half_width_weights; xk <= half_width_weights; ++xk)
- {
- // Check if the pixel is out-of-bound
- if(is_valid_pixel(xi + xk, 0, width_in) && is_valid_pixel(yi + yk, 0, height_in))
- {
- const int idx = xk + half_width_weights;
- const int idy = yk + half_height_weights;
-
- const T i_value = in[offset_slice_in + xk + yk * width_in];
- const T w_value = weights[idx + idy * width_weights + ifm * width_weights * height_weights];
-
- acc += i_value * w_value;
- }
- }
- }
- }
-
- // Accumulate the bias and store the result
- *out = acc + (*bias);
-}
-
-// 3D convolution for fixed point type
-template <typename T, typename std::enable_if<std::is_integral<T>::value, int>::type * = nullptr>
-void convolution3d(const T *in, const T *weights, const T *bias, T *out, int xi, int yi, int width_in, int height_in, int depth_in, int width_weights, int height_weights,
- int8_t fixed_point_position)
-{
- const int half_width_weights = width_weights / 2;
- const int half_height_weights = height_weights / 2;
-
- using namespace fixed_point_arithmetic;
- using promoted_type = typename fixed_point_arithmetic::traits::promote<T>::type;
-
- // Reset accumulator
- fixed_point<promoted_type> acc(0, fixed_point_position);
-
- // Compute a 2D convolution for each IFM and accumulate the result
- for(int ifm = 0; ifm < depth_in; ++ifm)
- {
- // Compute the offset for the input slice
- const int offset_slice_in = xi + yi * width_in + ifm * width_in * height_in;
-
- // Compute 2D convolution
- for(int yk = -half_height_weights; yk <= half_height_weights; ++yk)
- {
- for(int xk = -half_width_weights; xk <= half_width_weights; ++xk)
- {
- // Check if the pixel is out-of-bound
- if(is_valid_pixel(xi + xk, 0, width_in) && is_valid_pixel(yi + yk, 0, height_in))
- {
- const int idx = xk + half_width_weights;
- const int idy = yk + half_height_weights;
-
- const fixed_point<promoted_type> i_value(in[offset_slice_in + xk + yk * width_in], fixed_point_position, true);
- const fixed_point<promoted_type> w_value(weights[idx + idy * width_weights + ifm * width_weights * height_weights], fixed_point_position, true);
- const fixed_point<promoted_type> iw = i_value * w_value;
- acc = iw + acc;
- }
- }
- }
- }
-
- // Get the bias
- const fixed_point<promoted_type> b(*bias, fixed_point_position, true);
-
- // Accumulate the bias and covert back
- acc = acc + b;
- fixed_point<T> res(acc);
- *out = res.raw();
-}
-
template <typename T, typename std::enable_if<is_floating_point<T>::value, int>::type * = nullptr>
void vector_matrix_multiply(const T *in, const T *weights, const T *bias, T *out, int cols_weights, int rows_weights, uint8_t fixed_point_position)
{
@@ -999,58 +905,6 @@ void batch_normalization_layer(const Tensor<T> &in, Tensor<T> &out, const Tensor
}
}
-// Convolution layer
-template <typename T>
-void convolution_layer(const Tensor<T> &in, const Tensor<T> &weights, const Tensor<T> &bias, Tensor<T> &out, const PadStrideInfo &conv_info)
-{
- const int width_in = in.shape().x();
- const int height_in = in.shape().y();
- const int depth_in = in.shape().z();
- const int width_out = out.shape().x();
- const int height_out = out.shape().y();
- const int depth_out = out.shape().z();
- const int width_weights = weights.shape().x();
- const int height_weights = weights.shape().y();
- const int depth_weights = weights.shape().z();
- const int pad_xi = std::min(static_cast<int>(conv_info.pad().first), width_weights / 2);
- const int pad_yi = std::min(static_cast<int>(conv_info.pad().second), height_weights / 2);
- const int start_xi = width_weights / 2 - pad_xi;
- const int start_yi = height_weights / 2 - pad_yi;
- const int end_xi = width_in - start_xi;
- const int end_yi = height_in - start_yi;
- const int stride_xi = conv_info.stride().first;
- const int stride_yi = conv_info.stride().second;
- const int num_batches = in.shape().total_size() / (width_in * height_in * depth_in);
-
- for(int r = 0; r < num_batches; ++r)
- {
- for(int yi = start_yi; yi < end_yi; yi += stride_yi)
- {
- for(int xi = start_xi; xi < end_xi; xi += stride_xi)
- {
- for(int ofm = 0; ofm < depth_out; ++ofm)
- {
- // Compute input and output offsets
- const int offset_in = r * width_in * height_in * depth_in;
- const int xo = (xi - start_xi) / stride_xi;
- const int yo = (yi - start_yi) / stride_yi;
- const int offset_out = xo + yo * width_out + ofm * width_out * height_out + r * width_out * height_out * depth_out;
-
- // Compute 3D convolution
- convolution3d(in.data() + offset_in,
- weights.data() + ofm * width_weights * height_weights * depth_weights,
- bias.data() + ofm,
- out.data() + offset_out,
- xi, yi,
- width_in, height_in, depth_in,
- width_weights, height_weights,
- static_cast<int8_t>(in.fixed_point_position()));
- }
- }
- }
- }
-}
-
// Fully connected layer
template <typename T>
void fully_connected_layer(const Tensor<T> &in, const Tensor<T> &weights, const Tensor<T> &bias, Tensor<T> &out)