[Ref] Drop legacy API (#20006)
* Drop legacy API - CoordinateTransform * Refactor AvgPool ref * Fix zero padding indices ceil rounding * Transpose 3D reshaped kernels * Reuse max_pool v8 ref in v1 * Change ref::slice params validation * Fix wrong alloc in max_pool ref * Drop legacy from TopK * Fix mvn ref * Deprecate unused * Drop ngraph from TopK op * Remove deprecated * Use OPENVINO_ASSERT * Replace headers paths * Replace headers paths * Add missing include * Address review comments * Clean up * Remove unused and duplicated code
This commit is contained in:
parent
8b089b60cd
commit
921e621404
@ -8,8 +8,7 @@
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
|
||||
#include "ngraph/axis_vector.hpp"
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
@ -23,7 +22,7 @@ inline size_t window_end(size_t idx, size_t arg_shape, size_t out_shape) {
|
||||
}
|
||||
template <typename T>
|
||||
T avg_div(const T sum, size_t n) {
|
||||
NGRAPH_CHECK(n != 0, "AdaptiveAvgPool elements == 0, must be non-zero");
|
||||
OPENVINO_ASSERT(n != 0, "AdaptiveAvgPool elements == 0, must be non-zero");
|
||||
|
||||
if (std::is_same<T, int8_t>::value || std::is_same<T, uint8_t>::value) {
|
||||
return static_cast<T>(std::nearbyint(static_cast<float>(sum) / n));
|
||||
@ -90,8 +89,8 @@ void adaptive_avg_pool_3d(const T* arg,
|
||||
} // namespace adaptive_pool
|
||||
template <typename T>
|
||||
void adaptive_avg_pool(const T* arg, T* out, const Shape& arg_shape, const Shape& out_shape) {
|
||||
NGRAPH_CHECK(arg_shape.size() == out_shape.size() && 2 < arg_shape.size() && arg_shape.size() < 6,
|
||||
"AdaptiveAvgPool supports only 3D, 4D and 5D input shape");
|
||||
OPENVINO_ASSERT(arg_shape.size() == out_shape.size() && 2 < arg_shape.size() && arg_shape.size() < 6,
|
||||
"AdaptiveAvgPool supports only 3D, 4D and 5D input shape");
|
||||
size_t channel_size = 1;
|
||||
for (size_t i = 2; i < arg_shape.size(); i++) {
|
||||
channel_size *= arg_shape[i];
|
||||
|
@ -8,8 +8,7 @@
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
|
||||
#include "ngraph/axis_vector.hpp"
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/reference/adaptive_avg_pool.hpp"
|
||||
|
||||
namespace ov {
|
||||
@ -19,7 +18,7 @@ void adaptive_max_pool_1d(const T* arg, T* out, IT* indices, size_t h_in, size_t
|
||||
for (size_t i = 0; i < h_out; i++) {
|
||||
auto from = arg + adaptive_pool::window_start(i, h_in, h_out);
|
||||
auto to = arg + adaptive_pool::window_end(i, h_in, h_out);
|
||||
NGRAPH_CHECK(to - from != 0, "AdaptiveMaxPool elements == 0, must be non-zero");
|
||||
OPENVINO_ASSERT(to - from != 0, "AdaptiveMaxPool elements == 0, must be non-zero");
|
||||
auto it = std::max_element(from, to);
|
||||
out[i] = static_cast<T>(*it);
|
||||
indices[i] = static_cast<IT>(it - arg);
|
||||
@ -33,7 +32,8 @@ void adaptive_max_pool_2d(const T* arg, T* out, IT* indices, size_t h_in, size_t
|
||||
for (size_t j = 0; j < w_out; j++) {
|
||||
size_t w_start = adaptive_pool::window_start(j, w_in, w_out);
|
||||
size_t w_end = adaptive_pool::window_end(j, w_in, w_out);
|
||||
NGRAPH_CHECK((w_end - w_start) * (h_end - h_start) != 0, "AdaptiveMaxPool elements == 0, must be non-zero");
|
||||
OPENVINO_ASSERT((w_end - w_start) * (h_end - h_start) != 0,
|
||||
"AdaptiveMaxPool elements == 0, must be non-zero");
|
||||
auto result = arg + h_start * w_in + w_start;
|
||||
for (size_t n = h_start; n < h_end; n++) {
|
||||
auto from = arg + n * w_in + w_start;
|
||||
@ -65,8 +65,8 @@ void adaptive_max_pool_3d(const T* arg,
|
||||
for (size_t k = 0; k < w_out; k++) {
|
||||
size_t w_start = adaptive_pool::window_start(k, w_in, w_out);
|
||||
size_t w_end = adaptive_pool::window_end(k, w_in, w_out);
|
||||
NGRAPH_CHECK((w_end - w_start) * (h_end - h_start) != 0,
|
||||
"AdaptiveMaxPool elements == 0, must be non-zero");
|
||||
OPENVINO_ASSERT((w_end - w_start) * (h_end - h_start) != 0,
|
||||
"AdaptiveMaxPool elements == 0, must be non-zero");
|
||||
auto result = arg + d_start * h_in * w_in + h_start * w_in + w_start;
|
||||
for (size_t n = d_start; n < d_end; n++) {
|
||||
for (size_t m = h_start; m < h_end; m++) {
|
||||
@ -84,8 +84,8 @@ void adaptive_max_pool_3d(const T* arg,
|
||||
}
|
||||
template <typename T, typename IT>
|
||||
void adaptive_max_pool(const T* arg, T* out, IT* selected_indices, const Shape& arg_shape, const Shape& out_shape) {
|
||||
NGRAPH_CHECK(arg_shape.size() == out_shape.size() && 2 < arg_shape.size() && arg_shape.size() < 6,
|
||||
"AdaptiveAvgPool supports only 3D, 4D and 5D input shape");
|
||||
OPENVINO_ASSERT(arg_shape.size() == out_shape.size() && 2 < arg_shape.size() && arg_shape.size() < 6,
|
||||
"AdaptiveAvgPool supports only 3D, 4D and 5D input shape");
|
||||
size_t channel_size = 1;
|
||||
for (size_t i = 2; i < arg_shape.size(); i++) {
|
||||
channel_size *= arg_shape[i];
|
||||
|
@ -6,8 +6,8 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include "ngraph/op/util/attr_types.hpp"
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/op/util/attr_types.hpp"
|
||||
#include "openvino/reference/autobroadcast_binop.hpp"
|
||||
|
||||
namespace ov {
|
||||
|
@ -8,8 +8,9 @@
|
||||
#include <numeric>
|
||||
#include <utility>
|
||||
|
||||
#include "ngraph/op/util/attr_types.hpp"
|
||||
#include "ngraph/shape_util.hpp"
|
||||
#include "openvino/core/shape_util.hpp"
|
||||
#include "openvino/op/util/attr_types.hpp"
|
||||
#include "openvino/reference/utils/coordinate_index.hpp"
|
||||
#include "openvino/reference/utils/coordinate_transform.hpp"
|
||||
|
||||
namespace ov {
|
||||
@ -103,13 +104,13 @@ void autobroadcast_binop(const T* arg0,
|
||||
}
|
||||
break;
|
||||
case op::AutoBroadcastType::NUMPY:
|
||||
// We'll be using CoordinateTransform to handle the broadcasting. The general
|
||||
// We'll be using CoordinateTransformBasic to handle the broadcasting. The general
|
||||
// procedure is as follows:
|
||||
//
|
||||
// (1) Left pad the shorter of the two shapes with ones.
|
||||
// (2) Squeeze (remove ones from) both shapes, and record the squeezed axis
|
||||
// indices.
|
||||
// (3) Using CoordinateTransform, broadcast both args to the final output
|
||||
// (3) Using CoordinateTransformBasic, broadcast both args to the final output
|
||||
// shape. The "broadcasted axes" will be those that were squeezed in step
|
||||
// 2.
|
||||
//
|
||||
@ -207,7 +208,7 @@ void autobroadcast_binop(const T* arg0,
|
||||
}
|
||||
break;
|
||||
case op::AutoBroadcastType::PDPD:
|
||||
// We'll be using CoordinateTransform to handle the broadcasting. No need to
|
||||
// We'll be using CoordinateTransformBasic to handle the broadcasting. No need to
|
||||
// process arg0 and output shape will be the same as arg0. We need to process
|
||||
// arg1 and the general procedure is as follows:
|
||||
//
|
||||
@ -216,7 +217,7 @@ void autobroadcast_binop(const T* arg0,
|
||||
// to align between arg0 and arg1.
|
||||
// (3) Squeeze (remove ones from) arg1 shape, and record the squeezed axis
|
||||
// indices.
|
||||
// (3) Using CoordinateTransform, broadcast arg1 to the final output
|
||||
// (3) Using CoordinateTransformBasic, broadcast arg1 to the final output
|
||||
// shape. The "broadcasted axes" will be those that were squeezed in step
|
||||
// 23.
|
||||
//
|
||||
@ -262,18 +263,15 @@ void autobroadcast_binop(const T* arg0,
|
||||
}
|
||||
}
|
||||
|
||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
||||
CoordinateTransform arg0_transform(arg0_shape);
|
||||
CoordinateTransform arg1_transform(arg1_squeezed_shape);
|
||||
CoordinateTransform output_transform(arg0_shape);
|
||||
const CoordinateTransformBasic output_transform{arg0_shape};
|
||||
|
||||
for (const Coordinate& output_coord : output_transform) {
|
||||
Coordinate arg1_coord = ngraph::reduce(output_coord, arg1_squeezed_axes, false);
|
||||
out[output_transform.index(output_coord)] =
|
||||
elementwise_functor(arg0[arg0_transform.index(output_coord)],
|
||||
arg1[arg1_transform.index(arg1_coord)]);
|
||||
const auto arg1_coord = util::reduce(output_coord, arg1_squeezed_axes);
|
||||
const auto out_index = coordinate_index(output_coord, arg0_shape);
|
||||
const auto arg0_index = coordinate_index(output_coord, arg0_shape);
|
||||
const auto arg1_index = coordinate_index(arg1_coord, arg1_squeezed_shape);
|
||||
out[out_index] = elementwise_functor(arg0[arg0_index], arg1[arg1_index]);
|
||||
}
|
||||
NGRAPH_SUPPRESS_DEPRECATED_END
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -366,10 +364,7 @@ void autobroadcast_select(const U* arg0,
|
||||
output_shape.push_back(std::max({arg0_padded_shape[i], arg2_padded_shape[i], arg1_padded_shape[i]}));
|
||||
}
|
||||
|
||||
CoordinateTransformBasic arg0_transform(arg0_squeezed_shape);
|
||||
CoordinateTransformBasic arg1_transform(arg1_squeezed_shape);
|
||||
CoordinateTransformBasic arg2_transform(arg2_squeezed_shape);
|
||||
CoordinateTransformBasic output_transform(output_shape);
|
||||
const CoordinateTransformBasic output_transform{output_shape};
|
||||
|
||||
const auto arg0_strides = row_major_strides(arg0_squeezed_shape);
|
||||
const auto arg1_strides = row_major_strides(arg1_squeezed_shape);
|
||||
@ -377,20 +372,14 @@ void autobroadcast_select(const U* arg0,
|
||||
const auto output_strides = row_major_strides(output_shape);
|
||||
|
||||
for (const Coordinate& output_coord : output_transform) {
|
||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
||||
const Coordinate arg0_coord = ngraph::reduce(output_coord, arg0_squeezed_axes, false);
|
||||
const Coordinate arg1_coord = ngraph::reduce(output_coord, arg1_squeezed_axes, false);
|
||||
const Coordinate arg2_coord = ngraph::reduce(output_coord, arg2_squeezed_axes, false);
|
||||
NGRAPH_SUPPRESS_DEPRECATED_END
|
||||
const auto arg0_coord = util::reduce(output_coord, arg0_squeezed_axes);
|
||||
const auto arg1_coord = util::reduce(output_coord, arg1_squeezed_axes);
|
||||
const auto arg2_coord = util::reduce(output_coord, arg2_squeezed_axes);
|
||||
|
||||
const size_t arg0_idx =
|
||||
std::inner_product(arg0_coord.begin(), arg0_coord.end(), arg0_strides.begin(), uint64_t(0));
|
||||
const size_t arg1_idx =
|
||||
std::inner_product(arg1_coord.begin(), arg1_coord.end(), arg1_strides.begin(), uint64_t(0));
|
||||
const size_t arg2_idx =
|
||||
std::inner_product(arg2_coord.begin(), arg2_coord.end(), arg2_strides.begin(), uint64_t(0));
|
||||
const size_t output_idx =
|
||||
std::inner_product(output_coord.begin(), output_coord.end(), output_strides.begin(), uint64_t(0));
|
||||
const size_t arg0_idx = coordinate_offset(arg0_coord, arg0_strides);
|
||||
const size_t arg1_idx = coordinate_offset(arg1_coord, arg1_strides);
|
||||
const size_t arg2_idx = coordinate_offset(arg2_coord, arg2_strides);
|
||||
const size_t output_idx = coordinate_offset(output_coord, output_strides);
|
||||
out[output_idx] = elementwise_functor(arg0[arg0_idx], arg1[arg1_idx], arg2[arg2_idx]);
|
||||
}
|
||||
}
|
||||
@ -446,29 +435,20 @@ void autobroadcast_select(const U* arg0,
|
||||
}
|
||||
}
|
||||
|
||||
CoordinateTransformBasic arg0_transform(arg0_squeezed_shape);
|
||||
CoordinateTransformBasic arg1_transform(arg1_shape);
|
||||
CoordinateTransformBasic arg2_transform(arg2_squeezed_shape);
|
||||
CoordinateTransformBasic output_transform(arg1_shape);
|
||||
const CoordinateTransformBasic output_transform{arg1_shape};
|
||||
|
||||
const auto arg0_strides = row_major_strides(arg0_squeezed_shape);
|
||||
const auto arg2_strides = row_major_strides(arg2_squeezed_shape);
|
||||
const auto output_strides = row_major_strides(arg1_shape);
|
||||
|
||||
for (const Coordinate& output_coord : output_transform) {
|
||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
||||
const Coordinate arg0_coord = ngraph::reduce(output_coord, arg0_squeezed_axes, false);
|
||||
const Coordinate arg2_coord = ngraph::reduce(output_coord, arg2_squeezed_axes, false);
|
||||
NGRAPH_SUPPRESS_DEPRECATED_END
|
||||
const auto arg0_coord = util::reduce(output_coord, arg0_squeezed_axes);
|
||||
const auto arg2_coord = util::reduce(output_coord, arg2_squeezed_axes);
|
||||
|
||||
const size_t arg0_idx =
|
||||
std::inner_product(arg0_coord.begin(), arg0_coord.end(), arg0_strides.begin(), uint64_t(0));
|
||||
const size_t arg1_idx =
|
||||
std::inner_product(output_coord.begin(), output_coord.end(), output_strides.begin(), uint64_t(0));
|
||||
const size_t arg2_idx =
|
||||
std::inner_product(arg2_coord.begin(), arg2_coord.end(), arg2_strides.begin(), uint64_t(0));
|
||||
const size_t output_idx =
|
||||
std::inner_product(output_coord.begin(), output_coord.end(), output_strides.begin(), uint64_t(0));
|
||||
const size_t arg0_idx = coordinate_offset(arg0_coord, arg0_strides);
|
||||
const size_t arg1_idx = coordinate_offset(output_coord, output_strides);
|
||||
const size_t arg2_idx = coordinate_offset(arg2_coord, arg2_strides);
|
||||
const size_t output_idx = coordinate_offset(output_coord, output_strides);
|
||||
|
||||
out[output_idx] = elementwise_functor(arg0[arg0_idx], arg1[arg1_idx], arg2[arg2_idx]);
|
||||
}
|
||||
|
@ -7,227 +7,168 @@
|
||||
#include <cfenv>
|
||||
#include <cmath>
|
||||
#include <numeric>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
#include "ngraph/axis_vector.hpp"
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/axis_vector.hpp"
|
||||
#include "openvino/core/coordinate.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/reference/rounding_guard.hpp"
|
||||
#include "openvino/reference/utils/coordinate_transform.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
template <typename T>
|
||||
void avg_pool_backprop(const T* delta,
|
||||
T* out,
|
||||
const Shape& delta_shape,
|
||||
const Shape& out_shape,
|
||||
const Shape& window_shape,
|
||||
const Strides& window_movement_strides,
|
||||
const Shape& padding_below,
|
||||
const Shape& padding_above,
|
||||
bool include_padding_in_avg_computation) {
|
||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
||||
CoordinateTransform out_transform(out_shape);
|
||||
|
||||
for (const Coordinate& out_coord : out_transform) {
|
||||
out[out_transform.index(out_coord)] = 0;
|
||||
}
|
||||
|
||||
CoordinateTransform delta_transform(delta_shape);
|
||||
|
||||
for (const Coordinate& delta_coord : delta_transform) {
|
||||
size_t img_index = delta_coord[0];
|
||||
size_t channel = delta_coord[1];
|
||||
|
||||
size_t n_image_dimensions = out_shape.size() - 2;
|
||||
Coordinate source_window_transform_start(2 + n_image_dimensions);
|
||||
Coordinate source_window_transform_end(2 + n_image_dimensions);
|
||||
Strides source_window_transform_source_strides(2 + n_image_dimensions, 1);
|
||||
AxisVector source_window_transform_source_axis_order(2 + n_image_dimensions);
|
||||
CoordinateDiff source_window_transform_padding_below(2 + n_image_dimensions);
|
||||
CoordinateDiff source_window_transform_padding_above(2 + n_image_dimensions);
|
||||
|
||||
source_window_transform_start[0] = img_index;
|
||||
source_window_transform_end[0] = img_index + 1;
|
||||
source_window_transform_start[1] = channel;
|
||||
source_window_transform_end[1] = channel + 1;
|
||||
source_window_transform_padding_below[0] = 0;
|
||||
source_window_transform_padding_below[1] = 0;
|
||||
source_window_transform_padding_above[0] = 0;
|
||||
source_window_transform_padding_above[1] = 0;
|
||||
|
||||
for (size_t i = 2; i < n_image_dimensions + 2; i++) {
|
||||
size_t window_shape_this_dim = window_shape[i - 2];
|
||||
size_t movement_stride = window_movement_strides[i - 2];
|
||||
|
||||
source_window_transform_start[i] = movement_stride * delta_coord[i];
|
||||
source_window_transform_end[i] = source_window_transform_start[i] + window_shape_this_dim;
|
||||
source_window_transform_padding_below[i] = padding_below[i - 2];
|
||||
source_window_transform_padding_above[i] = padding_above[i - 2];
|
||||
}
|
||||
std::iota(begin(source_window_transform_source_axis_order), end(source_window_transform_source_axis_order), 0);
|
||||
|
||||
CoordinateTransform source_window_transform(out_shape,
|
||||
source_window_transform_start,
|
||||
source_window_transform_end,
|
||||
source_window_transform_source_strides,
|
||||
source_window_transform_source_axis_order,
|
||||
source_window_transform_padding_below,
|
||||
source_window_transform_padding_above);
|
||||
|
||||
size_t num_elements_in_window = 0;
|
||||
|
||||
for (const Coordinate& source_window_coord : source_window_transform) {
|
||||
if (source_window_transform.has_source_coordinate(source_window_coord) ||
|
||||
include_padding_in_avg_computation) {
|
||||
num_elements_in_window++;
|
||||
}
|
||||
}
|
||||
|
||||
for (const Coordinate& source_window_coord : source_window_transform) {
|
||||
if (source_window_transform.has_source_coordinate(source_window_coord)) {
|
||||
size_t out_index = source_window_transform.index(source_window_coord);
|
||||
out[out_index] += delta[delta_transform.index(delta_coord)] / num_elements_in_window;
|
||||
}
|
||||
namespace {
|
||||
inline bool elem_in_padding_area(const Coordinate& kernel_position,
|
||||
const Coordinate& kernel_offset,
|
||||
const Shape& data_shape) {
|
||||
for (size_t dim = 0; dim + 2 < data_shape.size(); ++dim) {
|
||||
if (static_cast<int64_t>(kernel_position[dim]) + static_cast<int64_t>(kernel_offset[dim]) < 0LL ||
|
||||
kernel_position[dim] + kernel_offset[dim] >= data_shape[dim + 2]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
NGRAPH_SUPPRESS_DEPRECATED_END
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
inline Coordinate calculate_kernel_position(const Coordinate& out_elem_coord,
|
||||
const Strides& kernel_strides,
|
||||
const Shape& pads_begin) {
|
||||
Coordinate top_left_corner;
|
||||
top_left_corner.reserve(out_elem_coord.size());
|
||||
for (size_t i = 0u; i < out_elem_coord.size(); ++i) {
|
||||
top_left_corner.emplace_back(out_elem_coord[i] * kernel_strides[i] - pads_begin[i]);
|
||||
}
|
||||
return top_left_corner;
|
||||
}
|
||||
|
||||
namespace kernel {
|
||||
template <typename Values_t>
|
||||
void avg_pool_3d(const Values_t* data,
|
||||
Values_t* out,
|
||||
const Shape& data_shape,
|
||||
const Shape& out_shape,
|
||||
const Shape& kernel,
|
||||
const Strides& kernel_strides,
|
||||
const Shape& pads_begin,
|
||||
const Shape& pads_end,
|
||||
const bool pads_in_avg) {
|
||||
// helper constants(axes) denoting dimensions in the input data shape and kernel shape
|
||||
constexpr size_t data_D = 2, data_H = 3, data_W = 4;
|
||||
constexpr size_t kernel_D = 0, kernel_H = 1, kernel_W = 2;
|
||||
|
||||
// select max elem and its index for each "placeholder" in the out buffer (pointed to by out_idx)
|
||||
size_t out_idx = 0u;
|
||||
for (size_t out_channel = 0u; out_channel < out_shape[data_D]; ++out_channel) {
|
||||
for (size_t out_row = 0u; out_row < out_shape[data_H]; ++out_row) {
|
||||
for (size_t out_col = 0u; out_col < out_shape[data_W]; ++out_col) {
|
||||
auto sum = Values_t{0};
|
||||
auto count = size_t{0};
|
||||
|
||||
const auto kernel_position =
|
||||
calculate_kernel_position({out_channel, out_row, out_col}, kernel_strides, pads_begin);
|
||||
|
||||
for (size_t kernel_channel = 0; kernel_channel < kernel[kernel_D]; ++kernel_channel) {
|
||||
for (size_t kernel_row = 0; kernel_row < kernel[kernel_H]; ++kernel_row) {
|
||||
for (size_t kernel_col = 0; kernel_col < kernel[kernel_W]; ++kernel_col) {
|
||||
// offset from the top-left corner of the kernel for a given row and col
|
||||
const Coordinate kernel_offset{kernel_channel, kernel_row, kernel_col};
|
||||
|
||||
const auto in_padding = elem_in_padding_area(kernel_position, kernel_offset, data_shape);
|
||||
// ignore the elements in the padding area
|
||||
if (!in_padding) {
|
||||
// index of the flattened tensor element under the current row & column of the kernel
|
||||
const size_t data_elem_index =
|
||||
data_shape[data_H] * data_shape[data_W] *
|
||||
(kernel_offset[kernel_D] + kernel_position[kernel_D]) +
|
||||
data_shape[data_W] * (kernel_offset[kernel_H] + kernel_position[kernel_H]) +
|
||||
kernel_offset[kernel_W] + kernel_position[kernel_W];
|
||||
|
||||
sum += data[data_elem_index];
|
||||
}
|
||||
if (pads_in_avg || !in_padding) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count != 0) {
|
||||
if (std::is_same<Values_t, int8_t>::value || std::is_same<Values_t, uint8_t>::value) {
|
||||
out[out_idx] = static_cast<Values_t>(std::nearbyint(sum / count));
|
||||
} else {
|
||||
out[out_idx] = sum / static_cast<Values_t>(count);
|
||||
}
|
||||
} else {
|
||||
out[out_idx] = Values_t{0};
|
||||
}
|
||||
++out_idx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace kernel
|
||||
} // namespace
|
||||
|
||||
template <typename T>
|
||||
void avg_pool(const T* arg,
|
||||
T* out,
|
||||
void avg_pool(const T* const arg,
|
||||
T* const out,
|
||||
const Shape& arg_shape,
|
||||
const Shape& out_shape,
|
||||
const Shape& window_shape,
|
||||
const Strides& window_movement_strides,
|
||||
const Shape& padding_below,
|
||||
const Shape& padding_above,
|
||||
bool include_padding_in_avg_computation) {
|
||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
||||
auto old_mode = std::fegetround();
|
||||
std::fesetround(FE_TONEAREST);
|
||||
// At the outermost level we will walk over every output coordinate O.
|
||||
CoordinateTransform output_transform(out_shape);
|
||||
const bool include_padding_in_avg_computation) {
|
||||
if (window_shape.size() > 3)
|
||||
return;
|
||||
const RoundingGuard rounding_g{FE_TONEAREST};
|
||||
|
||||
for (const Coordinate& out_coord : output_transform) {
|
||||
// Our output coordinate O will have the form:
|
||||
//
|
||||
// (N,chan,i_1,...,i_n)
|
||||
const auto not_zero = [](size_t p) {
|
||||
return p != 0;
|
||||
};
|
||||
const auto pads_in_avg =
|
||||
include_padding_in_avg_computation && (std::any_of(padding_below.begin(), padding_below.end(), not_zero) ||
|
||||
std::any_of(padding_above.begin(), padding_above.end(), not_zero));
|
||||
|
||||
size_t batch_index = out_coord[0];
|
||||
size_t channel = out_coord[1];
|
||||
Shape arg_shape_3D{arg_shape};
|
||||
Shape out_shape_3D{out_shape};
|
||||
Shape window_shape_3D{window_shape};
|
||||
Strides window_movement_strides_3D{window_movement_strides};
|
||||
Shape padding_below_3D{padding_below};
|
||||
Shape padding_above_3D{padding_above};
|
||||
|
||||
// For the input data we need to iterate the coordinate:
|
||||
//
|
||||
// I:
|
||||
//
|
||||
// over the range (noninclusive on the right):
|
||||
//
|
||||
// (N,chan,s_1*i_1,s_2*i_2,...,s_n*i_n) ->
|
||||
//
|
||||
// (N+1,chan+1,s_1*i_1 + window_shape_1,...,s_n*i_n + window_shape_n)
|
||||
//
|
||||
// with unit stride.
|
||||
//
|
||||
// We iterate this over the *padded* data, so below we will need to check for
|
||||
// coordinates that fall in the padding area.
|
||||
|
||||
size_t n_spatial_dimensions = arg_shape.size() - 2;
|
||||
|
||||
Coordinate input_batch_transform_start(2 + n_spatial_dimensions);
|
||||
Coordinate input_batch_transform_end(2 + n_spatial_dimensions);
|
||||
Strides input_batch_transform_source_strides(2 + n_spatial_dimensions, 1);
|
||||
AxisVector input_batch_transform_source_axis_order(2 + n_spatial_dimensions);
|
||||
CoordinateDiff input_batch_transform_padding_below(2 + n_spatial_dimensions);
|
||||
CoordinateDiff input_batch_transform_padding_above(2 + n_spatial_dimensions);
|
||||
|
||||
input_batch_transform_start[0] = batch_index;
|
||||
input_batch_transform_end[0] = batch_index + 1;
|
||||
input_batch_transform_start[1] = channel;
|
||||
input_batch_transform_end[1] = channel + 1;
|
||||
input_batch_transform_padding_below[0] = 0;
|
||||
input_batch_transform_padding_below[1] = 0;
|
||||
input_batch_transform_padding_above[0] = 0;
|
||||
input_batch_transform_padding_above[1] = 0;
|
||||
|
||||
for (size_t i = 2; i < n_spatial_dimensions + 2; i++) {
|
||||
size_t window_shape_this_dim = window_shape[i - 2];
|
||||
size_t movement_stride = window_movement_strides[i - 2];
|
||||
|
||||
input_batch_transform_start[i] = movement_stride * out_coord[i];
|
||||
input_batch_transform_end[i] = input_batch_transform_start[i] + window_shape_this_dim;
|
||||
input_batch_transform_padding_below[i] = padding_below[i - 2];
|
||||
input_batch_transform_padding_above[i] = padding_above[i - 2];
|
||||
// If a window (kernel) is out of arg shape bounds, trim it to fit
|
||||
auto padded_upper_bound = arg_shape[i] + padding_below[i - 2] + padding_above[i - 2];
|
||||
if (input_batch_transform_end[i] > padded_upper_bound) {
|
||||
input_batch_transform_end[i] = padded_upper_bound;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < arg_shape.size(); i++) {
|
||||
input_batch_transform_source_axis_order[i] = i;
|
||||
}
|
||||
|
||||
CoordinateTransform input_batch_transform(arg_shape,
|
||||
input_batch_transform_start,
|
||||
input_batch_transform_end,
|
||||
input_batch_transform_source_strides,
|
||||
input_batch_transform_source_axis_order,
|
||||
input_batch_transform_padding_below,
|
||||
input_batch_transform_padding_above);
|
||||
|
||||
// As we go, we compute the sum value:
|
||||
//
|
||||
// output[O] := output[O] + arg[I]
|
||||
//
|
||||
// and the number of elements:
|
||||
//
|
||||
// n_elements := n_elements + 1
|
||||
|
||||
T result = 0;
|
||||
size_t n_elements = 0;
|
||||
|
||||
// The below conditions are to provide conformance between the ref and plugins:
|
||||
// If exclude_padding is disabled (include_padding... enabled), then:
|
||||
// The size of window doesn't change even if the window was clipped to fit the
|
||||
// input, number of elements will be equal to window_size.width *
|
||||
// window_size.height. The exception from this rule is if padding is not
|
||||
// present, then window size is calculated each time.
|
||||
|
||||
auto padding_present =
|
||||
padding_below[0] != 0 || padding_below[1] != 0 || padding_above[0] != 0 || padding_above[1] != 0;
|
||||
|
||||
if (include_padding_in_avg_computation && padding_present) {
|
||||
n_elements = shape_size(window_shape);
|
||||
}
|
||||
for (const Coordinate& input_batch_coord : input_batch_transform) {
|
||||
bool in_bounds = input_batch_transform.has_source_coordinate(input_batch_coord);
|
||||
|
||||
if (in_bounds || include_padding_in_avg_computation) {
|
||||
T v = in_bounds ? arg[input_batch_transform.index(input_batch_coord)] : static_cast<T>(0);
|
||||
result += v;
|
||||
if (!padding_present || (in_bounds && !include_padding_in_avg_computation)) {
|
||||
n_elements++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (n_elements != 0) {
|
||||
if (std::is_same<T, int8_t>::value || std::is_same<T, uint8_t>::value) {
|
||||
out[output_transform.index(out_coord)] =
|
||||
static_cast<T>(std::nearbyint(static_cast<float>(result) / n_elements));
|
||||
} else {
|
||||
out[output_transform.index(out_coord)] = result / static_cast<T>(n_elements);
|
||||
}
|
||||
} else {
|
||||
out[output_transform.index(out_coord)] = T{0};
|
||||
}
|
||||
|
||||
std::fesetround(old_mode);
|
||||
if (window_shape.size() < 3) {
|
||||
const size_t dim_diff = 3 - window_shape.size();
|
||||
arg_shape_3D.insert(std::next(arg_shape_3D.begin(), 2), dim_diff, 1);
|
||||
out_shape_3D.insert(std::next(out_shape_3D.begin(), 2), dim_diff, 1);
|
||||
window_shape_3D.insert(window_shape_3D.begin(), dim_diff, 1);
|
||||
window_movement_strides_3D.insert(window_movement_strides_3D.begin(), dim_diff, 1);
|
||||
padding_below_3D.insert(padding_below_3D.begin(), dim_diff, 0);
|
||||
padding_above_3D.insert(padding_above_3D.begin(), dim_diff, 0);
|
||||
}
|
||||
|
||||
const auto data_batch_elems = shape_size(std::begin(arg_shape) + 1, std::end(arg_shape));
|
||||
const auto data_channel_elems = shape_size(std::begin(arg_shape) + 2, std::end(arg_shape));
|
||||
|
||||
const auto out_batch_elems = shape_size(std::begin(out_shape) + 1, std::end(out_shape));
|
||||
const auto out_channel_elems = shape_size(std::begin(out_shape) + 2, std::end(out_shape));
|
||||
|
||||
for (size_t b = 0; b < arg_shape[0]; ++b) {
|
||||
for (size_t c = 0; c < arg_shape[1]; ++c) {
|
||||
const T* data_channel_first_elem = arg + b * data_batch_elems + c * data_channel_elems;
|
||||
T* out_channel_first_elem = out + b * out_batch_elems + c * out_channel_elems;
|
||||
kernel::avg_pool_3d(data_channel_first_elem,
|
||||
out_channel_first_elem,
|
||||
arg_shape_3D,
|
||||
out_shape_3D,
|
||||
window_shape_3D,
|
||||
window_movement_strides_3D,
|
||||
padding_below_3D,
|
||||
padding_above_3D,
|
||||
pads_in_avg);
|
||||
}
|
||||
}
|
||||
NGRAPH_SUPPRESS_DEPRECATED_END
|
||||
}
|
||||
} // namespace reference
|
||||
} // namespace ov
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/reference/utils/coordinate_transform.hpp"
|
||||
|
||||
namespace ov {
|
||||
@ -26,11 +26,10 @@ void batch_norm_inference(float eps,
|
||||
const T* variance,
|
||||
T* out,
|
||||
const Shape& in_shape) {
|
||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
||||
auto eps_casted = static_cast<T>(eps);
|
||||
|
||||
size_t in_idx = 0;
|
||||
CoordinateTransform in_transform(in_shape);
|
||||
const CoordinateTransformBasic in_transform{in_shape};
|
||||
for (Coordinate in_coord : in_transform) {
|
||||
auto ch_num = in_coord[1];
|
||||
auto ch_gamma = gamma[ch_num];
|
||||
@ -42,7 +41,6 @@ void batch_norm_inference(float eps,
|
||||
out[in_idx] = normalized * ch_gamma + ch_beta;
|
||||
in_idx++;
|
||||
}
|
||||
NGRAPH_SUPPRESS_DEPRECATED_END
|
||||
}
|
||||
} // namespace reference
|
||||
} // namespace ov
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/reference/convolution.hpp"
|
||||
|
||||
namespace ov {
|
||||
|
@ -4,8 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ngraph/axis_set.hpp"
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/axis_set.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -6,8 +6,8 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include "ngraph/type/element_type.hpp"
|
||||
#include "ngraph/type/float16.hpp"
|
||||
#include "openvino/core/type/element_type.hpp"
|
||||
#include "openvino/core/type/float16.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
@ -123,7 +123,7 @@ size_t count_out_of_f16_range(const float* arg, size_t count);
|
||||
// Convert values from f32 to f16 with claming to f16 min/max when value is out of normal finite numbers range
|
||||
void convert_from_f32_to_f16_with_clamp(const float* arg, float16* out, size_t count);
|
||||
|
||||
// overload to handle ngraph::boolean (it is stored as char)
|
||||
// overload to handle ov::boolean (it is stored as char)
|
||||
template <typename TI, typename TO>
|
||||
typename std::enable_if<std::is_same<TO, char>::value>::type convert(const TI* arg, TO* out, size_t count) {
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
|
@ -116,9 +116,9 @@ inline bool color_convert_nv12(const std::shared_ptr<Node>& op,
|
||||
static const size_t N_DIM = 0;
|
||||
static const size_t H_DIM = 1;
|
||||
static const size_t W_DIM = 2;
|
||||
NGRAPH_CHECK(op->get_input_size() == 1 || op->get_input_size() == 2,
|
||||
"NV12 conversion shall have one or 2 inputs, but it is ",
|
||||
op->get_input_size());
|
||||
OPENVINO_ASSERT(op->get_input_size() == 1 || op->get_input_size() == 2,
|
||||
"NV12 conversion shall have one or 2 inputs, but it is ",
|
||||
op->get_input_size());
|
||||
auto single_plane = op->get_input_size() == 1;
|
||||
|
||||
const auto& y_tensor = inputs[0];
|
||||
@ -163,9 +163,9 @@ inline bool color_convert_i420(const std::shared_ptr<Node>& op,
|
||||
static const size_t N_DIM = 0;
|
||||
static const size_t H_DIM = 1;
|
||||
static const size_t W_DIM = 2;
|
||||
NGRAPH_CHECK(op->get_input_size() == 1 || op->get_input_size() == 3,
|
||||
"I420 conversion shall have one or 3 inputs, but it is ",
|
||||
op->get_input_size());
|
||||
OPENVINO_ASSERT(op->get_input_size() == 1 || op->get_input_size() == 3,
|
||||
"I420 conversion shall have one or 3 inputs, but it is ",
|
||||
op->get_input_size());
|
||||
auto single_plane = op->get_input_size() == 1;
|
||||
|
||||
const auto& y_tensor = inputs[0];
|
||||
|
@ -6,7 +6,9 @@
|
||||
|
||||
#include <future>
|
||||
|
||||
#include "ngraph/util.hpp"
|
||||
#include "openvino/core/coordinate_diff.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/core/strides.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
@ -260,33 +262,33 @@ inline void validate_convolution_parameters(const Shape& in_shape,
|
||||
const CoordinateDiff& pads_begin,
|
||||
const CoordinateDiff& pads_end) {
|
||||
// this implementation supports 1D, 2D and 3D convolutions
|
||||
NGRAPH_CHECK(in_shape.size() >= 3 && in_shape.size() <= 5, "Unsupported input rank: ", in_shape);
|
||||
OPENVINO_ASSERT(in_shape.size() >= 3 && in_shape.size() <= 5, "Unsupported input rank: ", in_shape);
|
||||
|
||||
NGRAPH_CHECK(in_shape.size() == f_shape.size(),
|
||||
"Incompatible input ranks: ",
|
||||
in_shape.size(),
|
||||
" and ",
|
||||
f_shape.size());
|
||||
OPENVINO_ASSERT(in_shape.size() == f_shape.size(),
|
||||
"Incompatible input ranks: ",
|
||||
in_shape.size(),
|
||||
" and ",
|
||||
f_shape.size());
|
||||
|
||||
NGRAPH_CHECK(in_shape[in_channel_axis] == f_shape[filter_in_ch_axis],
|
||||
"Incompatible input channels in data batch and filters shapes: ",
|
||||
in_shape[in_channel_axis],
|
||||
" and ",
|
||||
f_shape[filter_in_ch_axis]);
|
||||
OPENVINO_ASSERT(in_shape[in_channel_axis] == f_shape[filter_in_ch_axis],
|
||||
"Incompatible input channels in data batch and filters shapes: ",
|
||||
in_shape[in_channel_axis],
|
||||
" and ",
|
||||
f_shape[filter_in_ch_axis]);
|
||||
|
||||
NGRAPH_CHECK(in_shape.size() == out_shape.size(),
|
||||
"Incompatible input and output ranks: ",
|
||||
in_shape.size(),
|
||||
" and ",
|
||||
out_shape.size());
|
||||
OPENVINO_ASSERT(in_shape.size() == out_shape.size(),
|
||||
"Incompatible input and output ranks: ",
|
||||
in_shape.size(),
|
||||
" and ",
|
||||
out_shape.size());
|
||||
|
||||
const auto spatial_dims = in_shape.size() - 2;
|
||||
NGRAPH_CHECK(strides.size() == spatial_dims, "Strides not definied for all and only spatial dimensions");
|
||||
OPENVINO_ASSERT(strides.size() == spatial_dims, "Strides not definied for all and only spatial dimensions");
|
||||
|
||||
NGRAPH_CHECK(dilations.size() == spatial_dims, "Dilations not defined for all and only spatial dimensions");
|
||||
OPENVINO_ASSERT(dilations.size() == spatial_dims, "Dilations not defined for all and only spatial dimensions");
|
||||
|
||||
NGRAPH_CHECK((pads_begin.size() == pads_end.size()) && (pads_begin.size() == spatial_dims),
|
||||
"Pads not defined for all and only spatial dimensions");
|
||||
OPENVINO_ASSERT((pads_begin.size() == pads_end.size()) && (pads_begin.size() == spatial_dims),
|
||||
"Pads not defined for all and only spatial dimensions");
|
||||
|
||||
Shape out_spatial_shape{std::next(out_shape.begin(), 2), std::end(out_shape)};
|
||||
Shape infered_out_spatial_shape{};
|
||||
@ -297,7 +299,7 @@ inline void validate_convolution_parameters(const Shape& in_shape,
|
||||
dilations,
|
||||
pads_begin,
|
||||
pads_end);
|
||||
NGRAPH_CHECK(out_spatial_shape == infered_out_spatial_shape, "Incorrect output shape provided");
|
||||
OPENVINO_ASSERT(out_spatial_shape == infered_out_spatial_shape, "Incorrect output shape provided");
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
@ -9,8 +9,6 @@
|
||||
#include <functional>
|
||||
#include <numeric>
|
||||
|
||||
#include "ngraph/axis_vector.hpp"
|
||||
#include "ngraph/util.hpp"
|
||||
#include "openvino/reference/convolution.hpp"
|
||||
#include "openvino/reference/reverse.hpp"
|
||||
|
||||
@ -105,36 +103,36 @@ inline void validate_convolution_backprop_parameters(const Shape& in_shape,
|
||||
const CoordinateDiff& pads_end,
|
||||
const CoordinateDiff& output_padding) {
|
||||
// this implementation supports 1D, 2D and 3D convolutions
|
||||
NGRAPH_CHECK(in_shape.size() >= 3 && in_shape.size() <= 5, "Unsupported input rank: ", in_shape);
|
||||
OPENVINO_ASSERT(in_shape.size() >= 3 && in_shape.size() <= 5, "Unsupported input rank: ", in_shape);
|
||||
|
||||
NGRAPH_CHECK(in_shape.size() == f_shape.size(),
|
||||
"Incompatible input ranks: ",
|
||||
in_shape.size(),
|
||||
" and ",
|
||||
f_shape.size());
|
||||
OPENVINO_ASSERT(in_shape.size() == f_shape.size(),
|
||||
"Incompatible input ranks: ",
|
||||
in_shape.size(),
|
||||
" and ",
|
||||
f_shape.size());
|
||||
|
||||
NGRAPH_CHECK(in_shape[in_channel_axis] == f_shape[filter_input_ch_axis],
|
||||
"Incompatible input channels in data batch and filters shapes: ",
|
||||
in_shape[in_channel_axis],
|
||||
" and ",
|
||||
f_shape[filter_input_ch_axis]);
|
||||
OPENVINO_ASSERT(in_shape[in_channel_axis] == f_shape[filter_input_ch_axis],
|
||||
"Incompatible input channels in data batch and filters shapes: ",
|
||||
in_shape[in_channel_axis],
|
||||
" and ",
|
||||
f_shape[filter_input_ch_axis]);
|
||||
|
||||
NGRAPH_CHECK(in_shape.size() == out_shape.size(),
|
||||
"Incompatible input and output ranks: ",
|
||||
in_shape.size(),
|
||||
" and ",
|
||||
out_shape.size());
|
||||
OPENVINO_ASSERT(in_shape.size() == out_shape.size(),
|
||||
"Incompatible input and output ranks: ",
|
||||
in_shape.size(),
|
||||
" and ",
|
||||
out_shape.size());
|
||||
|
||||
const auto spatial_dims = in_shape.size() - 2;
|
||||
NGRAPH_CHECK(strides.size() == spatial_dims, "Strides not definied for all and only spatial dimensions.");
|
||||
OPENVINO_ASSERT(strides.size() == spatial_dims, "Strides not definied for all and only spatial dimensions.");
|
||||
|
||||
NGRAPH_CHECK(dilations.size() == spatial_dims, "Dilations not defined for all and only spatial dimensions.");
|
||||
OPENVINO_ASSERT(dilations.size() == spatial_dims, "Dilations not defined for all and only spatial dimensions.");
|
||||
|
||||
NGRAPH_CHECK((pads_begin.size() == pads_end.size()) && (pads_begin.size() == spatial_dims),
|
||||
"Pads not defined for all and only spatial dimensions.");
|
||||
OPENVINO_ASSERT((pads_begin.size() == pads_end.size()) && (pads_begin.size() == spatial_dims),
|
||||
"Pads not defined for all and only spatial dimensions.");
|
||||
|
||||
NGRAPH_CHECK(!output_padding.empty() && output_padding.size() == spatial_dims,
|
||||
"Output padding not defined for all and only spatial dimensions.");
|
||||
OPENVINO_ASSERT(!output_padding.empty() && output_padding.size() == spatial_dims,
|
||||
"Output padding not defined for all and only spatial dimensions.");
|
||||
|
||||
Shape out_spatial_shape{std::next(out_shape.begin(), 2), std::end(out_shape)};
|
||||
Shape infered_out_spatial_shape{};
|
||||
@ -145,7 +143,7 @@ inline void validate_convolution_backprop_parameters(const Shape& in_shape,
|
||||
strides,
|
||||
dilations,
|
||||
output_padding);
|
||||
NGRAPH_CHECK(out_spatial_shape == infered_out_spatial_shape, "Incorrect output shape provided");
|
||||
OPENVINO_ASSERT(out_spatial_shape == infered_out_spatial_shape, "Incorrect output shape provided");
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
|
||||
#include "openvino/reference/utils/coordinate_transform.hpp"
|
||||
#include "openvino/reference/utils/coordinate_index.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
@ -20,16 +20,11 @@ void ctc_greedy_decoder(const T* data,
|
||||
const Shape& sequence_masks_shape,
|
||||
const Shape& out_shape,
|
||||
const bool ctc_merge_repeated) {
|
||||
OPENVINO_SUPPRESS_DEPRECATED_START
|
||||
const auto max_seq_len = data_shape[0];
|
||||
const auto batch_size = data_shape[1];
|
||||
const auto class_count = data_shape[2];
|
||||
const uint64_t blank_index = class_count - 1;
|
||||
|
||||
CoordinateTransform out_transform = CoordinateTransform(out_shape);
|
||||
CoordinateTransform data_transform = CoordinateTransform(data_shape);
|
||||
CoordinateTransform seq_masks_transform = CoordinateTransform(sequence_masks_shape);
|
||||
|
||||
// final sequences don't have to fill the whole output, elements that don't store
|
||||
// information are set to -1
|
||||
|
||||
@ -38,10 +33,10 @@ void ctc_greedy_decoder(const T* data,
|
||||
|
||||
for (unsigned int batch_ind = 0; batch_ind < batch_size; batch_ind++) {
|
||||
T previous_class_index = static_cast<T>(-1);
|
||||
auto out_index = out_transform.index({batch_ind, 0, 0, 0});
|
||||
auto out_index = coordinate_index({batch_ind, 0, 0, 0}, out_shape);
|
||||
for (unsigned int seq_ind = 0; seq_ind < max_seq_len; seq_ind++) {
|
||||
auto data_index = data_transform.index({seq_ind, batch_ind, 0});
|
||||
auto mask_index = seq_masks_transform.index({seq_ind, batch_ind});
|
||||
auto data_index = coordinate_index({seq_ind, batch_ind, 0}, data_shape);
|
||||
auto mask_index = coordinate_index({seq_ind, batch_ind}, sequence_masks_shape);
|
||||
|
||||
if (sequence_masks[mask_index] == T{0}) {
|
||||
break;
|
||||
@ -59,7 +54,6 @@ void ctc_greedy_decoder(const T* data,
|
||||
}
|
||||
}
|
||||
std::copy(tmp_out.begin(), tmp_out.end(), out);
|
||||
OPENVINO_SUPPRESS_DEPRECATED_END
|
||||
}
|
||||
} // namespace reference
|
||||
} // namespace ov
|
||||
|
@ -4,11 +4,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "ngraph/shape_util.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -21,17 +21,17 @@ inline void validate_deformable_convolution_params(const Shape& in_shape,
|
||||
const int64_t groups,
|
||||
const int64_t deformable_groups) {
|
||||
// this implementation supports 2D deformable convolutions
|
||||
NGRAPH_CHECK(in_shape.size() == 4, "Unsupported input rank: ", in_shape);
|
||||
NGRAPH_CHECK(o_shape.size() == 4, "Unsupported offset rank: ", o_shape);
|
||||
NGRAPH_CHECK(f_shape.size() == 4, "Unsupported kernel rank: ", f_shape);
|
||||
NGRAPH_CHECK(m_shape.size() == 4, "Unsupported mask rank: ", m_shape);
|
||||
OPENVINO_ASSERT(in_shape.size() == 4, "Unsupported input rank: ", in_shape);
|
||||
OPENVINO_ASSERT(o_shape.size() == 4, "Unsupported offset rank: ", o_shape);
|
||||
OPENVINO_ASSERT(f_shape.size() == 4, "Unsupported kernel rank: ", f_shape);
|
||||
OPENVINO_ASSERT(m_shape.size() == 4, "Unsupported mask rank: ", m_shape);
|
||||
|
||||
NGRAPH_CHECK(in_shape[1] % groups == 0,
|
||||
"Input channels of data batch input must be evenly divisible by "
|
||||
"'groups' attribute");
|
||||
NGRAPH_CHECK(f_shape[0] % groups == 0,
|
||||
"Output channels of filters must be evenly divisible by 'groups' "
|
||||
"attribute");
|
||||
OPENVINO_ASSERT(in_shape[1] % groups == 0,
|
||||
"Input channels of data batch input must be evenly divisible by "
|
||||
"'groups' attribute");
|
||||
OPENVINO_ASSERT(f_shape[0] % groups == 0,
|
||||
"Output channels of filters must be evenly divisible by 'groups' "
|
||||
"attribute");
|
||||
|
||||
const Shape scaled_f_shape = [f_shape](int64_t g) {
|
||||
Shape shape{f_shape};
|
||||
@ -46,14 +46,15 @@ inline void validate_deformable_convolution_params(const Shape& in_shape,
|
||||
const Shape m_spatial_shape{std::next(m_shape.begin(), 2), std::end(m_shape)};
|
||||
const Shape out_spatial_shape{std::next(out_shape.begin(), 2), std::end(out_shape)};
|
||||
|
||||
NGRAPH_CHECK(o_shape[1] == deformable_groups * shape_size(f_spatial_shape) * 2,
|
||||
"The channels dimension of offsets input is not "
|
||||
"compatible with filters and 'deformable group' attribute");
|
||||
NGRAPH_CHECK(m_shape[1] == deformable_groups * shape_size(f_spatial_shape),
|
||||
"The channels dimension of mask input is not "
|
||||
"compatible with filters and 'deformable group' attribute");
|
||||
NGRAPH_CHECK(out_spatial_shape == o_spatial_shape, "Spatial dimensions of output and offsets values must be equal");
|
||||
NGRAPH_CHECK(out_spatial_shape == m_spatial_shape, "Spatial dimensions of output and mask values must be equal");
|
||||
OPENVINO_ASSERT(o_shape[1] == deformable_groups * shape_size(f_spatial_shape) * 2,
|
||||
"The channels dimension of offsets input is not "
|
||||
"compatible with filters and 'deformable group' attribute");
|
||||
OPENVINO_ASSERT(m_shape[1] == deformable_groups * shape_size(f_spatial_shape),
|
||||
"The channels dimension of mask input is not "
|
||||
"compatible with filters and 'deformable group' attribute");
|
||||
OPENVINO_ASSERT(out_spatial_shape == o_spatial_shape,
|
||||
"Spatial dimensions of output and offsets values must be equal");
|
||||
OPENVINO_ASSERT(out_spatial_shape == m_spatial_shape, "Spatial dimensions of output and mask values must be equal");
|
||||
}
|
||||
|
||||
inline Shape shape_reduce(const Shape& s) {
|
||||
@ -295,7 +296,7 @@ void deformable_convolution(const T* in,
|
||||
const int64_t deformable_groups,
|
||||
const bool bilinear_interpolation_pad = false) {
|
||||
Shape m_shape = {o_shape[0], o_shape[1] / 2, o_shape[2], o_shape[3]};
|
||||
std::vector<T> mask(ngraph::shape_size(m_shape), 1);
|
||||
std::vector<T> mask(shape_size(m_shape), 1);
|
||||
deformable_convolution(in,
|
||||
offsets,
|
||||
filters,
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "clamp.hpp"
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -4,8 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ngraph/op/depth_to_space.hpp"
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/op/depth_to_space.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -6,12 +6,11 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "ngraph/op/detection_output.hpp"
|
||||
#include "ngraph/op/util/detection_output_base.hpp"
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/op/detection_output.hpp"
|
||||
#include "openvino/op/util/detection_output_base.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
@ -28,7 +27,7 @@ private:
|
||||
};
|
||||
using LabelBBox = std::map<int, std::vector<NormalizedBBox>>;
|
||||
|
||||
ngraph::op::util::DetectionOutputBase::AttributesBase attrs;
|
||||
op::util::DetectionOutputBase::AttributesBase attrs;
|
||||
size_t numImages;
|
||||
size_t priorSize;
|
||||
size_t numPriors;
|
||||
@ -417,10 +416,10 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
referenceDetectionOutput(const ngraph::op::DetectionOutputAttrs& _attrs,
|
||||
const ngraph::Shape& locShape,
|
||||
const ngraph::Shape& priorsShape,
|
||||
const ngraph::Shape& outShape)
|
||||
referenceDetectionOutput(const op::v0::DetectionOutput::Attributes& _attrs,
|
||||
const Shape& locShape,
|
||||
const Shape& priorsShape,
|
||||
const Shape& outShape)
|
||||
: attrs(_attrs) {
|
||||
numImages = locShape[0];
|
||||
priorSize = _attrs.normalized ? 4 : 5;
|
||||
@ -433,11 +432,11 @@ public:
|
||||
outTotalSize = shape_size(outShape);
|
||||
}
|
||||
|
||||
referenceDetectionOutput(const ngraph::op::util::DetectionOutputBase::AttributesBase& _attrs,
|
||||
const ngraph::Shape& locShape,
|
||||
const ngraph::Shape& classPredShape,
|
||||
const ngraph::Shape& priorsShape,
|
||||
const ngraph::Shape& outShape)
|
||||
referenceDetectionOutput(const op::util::DetectionOutputBase::AttributesBase& _attrs,
|
||||
const Shape& locShape,
|
||||
const Shape& classPredShape,
|
||||
const Shape& priorsShape,
|
||||
const Shape& outShape)
|
||||
: attrs(_attrs) {
|
||||
numImages = locShape[0];
|
||||
priorSize = _attrs.normalized ? 4 : 5;
|
||||
|
@ -8,10 +8,10 @@
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
|
||||
#include "ngraph/op/util/attr_types.hpp"
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "ngraph/type/bfloat16.hpp"
|
||||
#include "ngraph/type/float16.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/core/type/bfloat16.hpp"
|
||||
#include "openvino/core/type/float16.hpp"
|
||||
#include "openvino/op/util/attr_types.hpp"
|
||||
#include "openvino/reference/autobroadcast_binop.hpp"
|
||||
|
||||
namespace ov {
|
||||
|
@ -5,9 +5,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <ngraph/opsets/opset7.hpp>
|
||||
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/runtime/tensor.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ngraph/shape_util.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ngraph/shape_util.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ngraph/shape_util.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -11,8 +11,8 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include "ngraph/op/util/attr_types.hpp"
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/op/util/attr_types.hpp"
|
||||
#include "openvino/reference/autobroadcast_binop.hpp"
|
||||
|
||||
namespace ov {
|
||||
|
@ -8,9 +8,6 @@
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
|
||||
#include "ngraph/type/bfloat16.hpp"
|
||||
#include "ngraph/type/float16.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
template <typename T, typename std::enable_if<!std::is_integral<T>::value, bool>::type = true>
|
||||
|
@ -16,16 +16,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <ngraph/runtime/host_tensor.hpp>
|
||||
#include <vector>
|
||||
|
||||
#include "ngraph/node.hpp"
|
||||
#include "ngraph/op/util/op_types.hpp"
|
||||
#include "ngraph/ops.hpp"
|
||||
#include "ngraph/shape_util.hpp"
|
||||
#include "openvino/op/experimental_detectron_detection_output.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
@ -41,7 +36,7 @@ void experimental_detectron_detection_output(const float* input_rois,
|
||||
void experimental_detectron_detection_output_postprocessing(void* pboxes,
|
||||
void* pclasses,
|
||||
void* pscores,
|
||||
const ngraph::element::Type output_type,
|
||||
const element::Type output_type,
|
||||
const std::vector<float>& output_boxes,
|
||||
const std::vector<int32_t>& output_classes,
|
||||
const std::vector<float>& output_scores,
|
||||
|
@ -18,13 +18,8 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <ngraph/runtime/host_tensor.hpp>
|
||||
#include <vector>
|
||||
|
||||
#include "ngraph/node.hpp"
|
||||
#include "ngraph/op/util/op_types.hpp"
|
||||
#include "ngraph/ops.hpp"
|
||||
#include "ngraph/shape_util.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -4,16 +4,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <ngraph/runtime/host_tensor.hpp>
|
||||
#include <vector>
|
||||
|
||||
#include "ngraph/node.hpp"
|
||||
#include "ngraph/op/util/op_types.hpp"
|
||||
#include "ngraph/ops.hpp"
|
||||
#include "ngraph/shape_util.hpp"
|
||||
#include "openvino/op/experimental_detectron_generate_proposals.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
@ -32,7 +27,7 @@ void experimental_detectron_proposals_single_image(
|
||||
|
||||
void experimental_detectron_proposals_single_image_postprocessing(void* prois,
|
||||
void* pscores,
|
||||
const ngraph::element::Type output_type,
|
||||
const element::Type output_type,
|
||||
const std::vector<float>& output_rois,
|
||||
const std::vector<float>& output_scores,
|
||||
const Shape& output_rois_shape,
|
||||
|
@ -6,13 +6,9 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <ngraph/runtime/host_tensor.hpp>
|
||||
#include <vector>
|
||||
|
||||
#include "ngraph/node.hpp"
|
||||
#include "ngraph/op/util/op_types.hpp"
|
||||
#include "ngraph/ops.hpp"
|
||||
#include "ngraph/shape_util.hpp"
|
||||
#include "openvino/op/experimental_detectron_roi_feature.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
@ -25,7 +21,7 @@ void experimental_detectron_roi_feature_extractor(
|
||||
|
||||
void experimental_detectron_roi_feature_extractor_postprocessing(void* prois_features,
|
||||
void* prois,
|
||||
const ngraph::element::Type output_type,
|
||||
const element::Type output_type,
|
||||
const std::vector<float>& output_roi_features,
|
||||
const std::vector<float>& output_rois,
|
||||
const Shape& output_roi_features_shape,
|
||||
|
@ -4,16 +4,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <ngraph/runtime/host_tensor.hpp>
|
||||
#include <vector>
|
||||
|
||||
#include "ngraph/node.hpp"
|
||||
#include "ngraph/op/util/op_types.hpp"
|
||||
#include "ngraph/ops.hpp"
|
||||
#include "ngraph/shape_util.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -2,9 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <ngraph/ops.hpp>
|
||||
|
||||
#include "ngraph/shape_util.hpp"
|
||||
#include "openvino/op/extractimagepatches.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "utils/span.hpp"
|
||||
|
||||
namespace ov {
|
||||
|
@ -11,10 +11,10 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "ngraph/check.hpp"
|
||||
#include "ngraph/op/util/attr_types.hpp"
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "ngraph/shape_util.hpp"
|
||||
#include "openvino/core/except.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/core/shape_util.hpp"
|
||||
#include "openvino/op/util/attr_types.hpp"
|
||||
#include "openvino/reference/utils/coordinate_transform.hpp"
|
||||
|
||||
namespace ov {
|
||||
@ -65,11 +65,11 @@ void fake_quantize(const T* const arg,
|
||||
out[i] = q(arg[i]);
|
||||
}
|
||||
} else {
|
||||
NGRAPH_CHECK(in_low_shape.size() <= arg_shape.size() && in_high_shape.size() <= arg_shape.size() &&
|
||||
out_low_shape.size() <= arg_shape.size() && out_high_shape.size() <= arg_shape.size(),
|
||||
"Tensors with input\\output ranges should have rank less or "
|
||||
"equal to data tensor rank equal to ",
|
||||
arg_shape.size());
|
||||
OPENVINO_ASSERT(in_low_shape.size() <= arg_shape.size() && in_high_shape.size() <= arg_shape.size() &&
|
||||
out_low_shape.size() <= arg_shape.size() && out_high_shape.size() <= arg_shape.size(),
|
||||
"Tensors with input\\output ranges should have rank less or "
|
||||
"equal to data tensor rank equal to ",
|
||||
arg_shape.size());
|
||||
|
||||
Shape arg0_padded_shape = arg_shape;
|
||||
Shape arg1_padded_shape = in_low_shape;
|
||||
@ -156,13 +156,11 @@ void fake_quantize(const T* const arg,
|
||||
const auto output_strides = row_major_strides(output_shape);
|
||||
|
||||
for (const Coordinate& output_coord : output_transform) {
|
||||
OPENVINO_SUPPRESS_DEPRECATED_START
|
||||
const Coordinate arg0_coord = ngraph::reduce(output_coord, arg0_squeezed_axes, false);
|
||||
const Coordinate arg1_coord = ngraph::reduce(output_coord, arg1_squeezed_axes, false);
|
||||
const Coordinate arg2_coord = ngraph::reduce(output_coord, arg2_squeezed_axes, false);
|
||||
const Coordinate arg3_coord = ngraph::reduce(output_coord, arg3_squeezed_axes, false);
|
||||
const Coordinate arg4_coord = ngraph::reduce(output_coord, arg4_squeezed_axes, false);
|
||||
OPENVINO_SUPPRESS_DEPRECATED_END
|
||||
const auto arg0_coord = util::reduce(output_coord, arg0_squeezed_axes);
|
||||
const auto arg1_coord = util::reduce(output_coord, arg1_squeezed_axes);
|
||||
const auto arg2_coord = util::reduce(output_coord, arg2_squeezed_axes);
|
||||
const auto arg3_coord = util::reduce(output_coord, arg3_squeezed_axes);
|
||||
const auto arg4_coord = util::reduce(output_coord, arg4_squeezed_axes);
|
||||
|
||||
const size_t arg0_idx =
|
||||
std::inner_product(arg0_coord.begin(), arg0_coord.end(), arg0_strides.begin(), uint64_t(0));
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
|
||||
#include "ngraph/shape_util.hpp"
|
||||
#include "openvino/reference/autobroadcast_binop.hpp"
|
||||
|
||||
namespace ov {
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <numeric>
|
||||
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "utils/span.hpp"
|
||||
|
||||
namespace ov {
|
||||
|
@ -4,8 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "ngraph/type/element_type.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/core/type/element_type.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -4,9 +4,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <ngraph/op/gelu.hpp>
|
||||
|
||||
#include "openvino/op/gelu.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -4,16 +4,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <ngraph/runtime/host_tensor.hpp>
|
||||
#include <vector>
|
||||
|
||||
#include "ngraph/node.hpp"
|
||||
#include "ngraph/op/util/op_types.hpp"
|
||||
#include "ngraph/ops.hpp"
|
||||
#include "ngraph/shape_util.hpp"
|
||||
#include "openvino/op/generate_proposals.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
@ -33,8 +28,8 @@ void generate_proposals(const std::vector<float>& im_info,
|
||||
void generate_proposals_postprocessing(void* prois,
|
||||
void* pscores,
|
||||
void* proi_num,
|
||||
const ngraph::element::Type& output_type,
|
||||
const ngraph::element::Type& roi_num_type,
|
||||
const element::Type& output_type,
|
||||
const element::Type& roi_num_type,
|
||||
const std::vector<float>& output_rois,
|
||||
const std::vector<float>& output_scores,
|
||||
const std::vector<int64_t>& num_rois,
|
||||
|
@ -6,8 +6,8 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include "ngraph/op/util/attr_types.hpp"
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/op/util/attr_types.hpp"
|
||||
#include "openvino/reference/autobroadcast_binop.hpp"
|
||||
|
||||
namespace ov {
|
||||
|
@ -6,8 +6,8 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include "ngraph/op/util/attr_types.hpp"
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/op/util/attr_types.hpp"
|
||||
#include "openvino/reference/autobroadcast_binop.hpp"
|
||||
|
||||
namespace ov {
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include <cfenv>
|
||||
#include <cmath>
|
||||
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/op/grid_sample.hpp"
|
||||
|
||||
namespace ov {
|
||||
|
@ -4,7 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ngraph/util.hpp"
|
||||
#include "openvino/core/coordinate_diff.hpp"
|
||||
#include "openvino/core/strides.hpp"
|
||||
#include "openvino/reference/group_convolution.hpp"
|
||||
|
||||
namespace ov {
|
||||
@ -100,8 +101,8 @@ void group_convolution_backprop_data(const T* in,
|
||||
|
||||
// DEPRECATED, can't be removed currently due to arm-plugin dependency
|
||||
template <typename OUTPUT, typename FILTER, typename INPUT, typename ACCUMULATION = typename widen<INPUT>::type>
|
||||
NGRAPH_DEPRECATED("group_convolution_backprop_data function without output_paddings is deprecated, "
|
||||
"use the one with output_padding.")
|
||||
OPENVINO_DEPRECATED("group_convolution_backprop_data function without output_paddings is deprecated, "
|
||||
"use the one with output_padding.")
|
||||
void group_convolution_backprop_data(const INPUT* in,
|
||||
const FILTER* f,
|
||||
OUTPUT* out,
|
||||
@ -112,7 +113,7 @@ void group_convolution_backprop_data(const INPUT* in,
|
||||
const Strides& dilation,
|
||||
const CoordinateDiff& pads_begin,
|
||||
const CoordinateDiff& pads_end) {
|
||||
const ngraph::CoordinateDiff output_padding(in_shape.size() - 2, 0);
|
||||
const CoordinateDiff output_padding(in_shape.size() - 2, 0);
|
||||
|
||||
group_convolution_backprop_data(in,
|
||||
f,
|
||||
|
@ -13,16 +13,16 @@
|
||||
#include <map>
|
||||
|
||||
#include "interpolate_pil.hpp"
|
||||
#include "ngraph/op/interpolate.hpp"
|
||||
#include "ngraph/shape_util.hpp"
|
||||
#include "openvino/op/interpolate.hpp"
|
||||
#include "openvino/reference/utils/coordinate_index.hpp"
|
||||
#include "openvino/reference/utils/coordinate_transform.hpp"
|
||||
#include "transpose.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
using Nearest_mode = ngraph::op::v4::Interpolate::NearestMode;
|
||||
using Transform_mode = ngraph::op::v4::Interpolate::CoordinateTransformMode;
|
||||
using InterpolateMode = ngraph::op::v4::Interpolate::InterpolateMode;
|
||||
using Nearest_mode = op::v4::Interpolate::NearestMode;
|
||||
using Transform_mode = op::v4::Interpolate::CoordinateTransformMode;
|
||||
using InterpolateMode = op::v4::Interpolate::InterpolateMode;
|
||||
|
||||
/// \brief Calculation of nearest pixel.
|
||||
class GetNearestPixel final {
|
||||
@ -211,7 +211,7 @@ public:
|
||||
float prod_a;
|
||||
std::vector<float> a;
|
||||
std::vector<int64_t> r;
|
||||
Shape shape_for_indeces;
|
||||
Shape shape_for_indices;
|
||||
};
|
||||
|
||||
InfoForLinearMode get_info_for_linear_mode();
|
||||
@ -362,9 +362,7 @@ template <typename T>
|
||||
void InterpolateEval<T>::linear_func(const T* input_data, T* out) {
|
||||
auto info = helper.get_info_for_linear_mode();
|
||||
|
||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
||||
CoordinateTransform output_transform(m_out_shape);
|
||||
CoordinateTransform input_transform(m_input_data_shape);
|
||||
const CoordinateTransformBasic output_transform{m_out_shape};
|
||||
|
||||
for (const Coordinate& output_coord : output_transform) {
|
||||
auto icoords_data = helper.get_icoords(output_coord);
|
||||
@ -372,29 +370,30 @@ void InterpolateEval<T>::linear_func(const T* input_data, T* out) {
|
||||
float summa = 0.0f;
|
||||
float wsum = 0.0f;
|
||||
|
||||
CoordinateTransform indices{info.shape_for_indeces};
|
||||
const CoordinateTransformBasic indices{info.shape_for_indices};
|
||||
for (const auto& index : indices) {
|
||||
auto inner_result = helper.inner_calculation(output_coord, icoords_data, info, index);
|
||||
if (!inner_result.condition) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto input_index = coordinate_index(inner_result.inner_coord, m_input_data_shape);
|
||||
wsum += inner_result.w;
|
||||
summa += inner_result.w * static_cast<float>(input_data[input_transform.index(inner_result.inner_coord)]);
|
||||
summa += inner_result.w * static_cast<float>(input_data[input_index]);
|
||||
}
|
||||
|
||||
const auto out_index = coordinate_index(output_coord, m_out_shape);
|
||||
if (wsum == 0.0f) {
|
||||
out[output_transform.index(output_coord)] = T{};
|
||||
out[out_index] = T{};
|
||||
} else {
|
||||
if (std::is_integral<T>()) {
|
||||
// Round value for integral return types
|
||||
out[output_transform.index(output_coord)] = static_cast<T>(std::round(summa / wsum));
|
||||
out[out_index] = static_cast<T>(std::round(summa / wsum));
|
||||
} else {
|
||||
out[output_transform.index(output_coord)] = static_cast<T>(summa / wsum);
|
||||
out[out_index] = static_cast<T>(summa / wsum);
|
||||
}
|
||||
}
|
||||
}
|
||||
NGRAPH_SUPPRESS_DEPRECATED_END
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@ -532,9 +531,7 @@ void InterpolateEval<T>::cubic_func(const T* input_data, T* out) {
|
||||
size_t input_rank = m_input_data_shape.size();
|
||||
size_t num_of_axes = m_axes.size();
|
||||
|
||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
||||
CoordinateTransform output_transform(m_out_shape);
|
||||
CoordinateTransform input_transform(m_input_data_shape);
|
||||
const CoordinateTransformBasic output_transform{m_out_shape};
|
||||
Shape indices_shape{std::vector<size_t>(num_of_axes, 4)};
|
||||
|
||||
for (const Coordinate& output_coord : output_transform) {
|
||||
@ -551,7 +548,7 @@ void InterpolateEval<T>::cubic_func(const T* input_data, T* out) {
|
||||
}
|
||||
|
||||
float summa = 0.0f;
|
||||
CoordinateTransform indices{indices_shape};
|
||||
const CoordinateTransformBasic indices{indices_shape};
|
||||
|
||||
for (const Coordinate& idx : indices) {
|
||||
auto coords_for_sum = output_coord;
|
||||
@ -567,12 +564,12 @@ void InterpolateEval<T>::cubic_func(const T* input_data, T* out) {
|
||||
coeffs_prod *= cubic_coeffs[axis][idx[i]];
|
||||
}
|
||||
|
||||
summa += coeffs_prod * static_cast<float>(input_data[input_transform.index(coords_for_sum)]);
|
||||
const auto input_index = coordinate_index(coords_for_sum, m_input_data_shape);
|
||||
summa += coeffs_prod * static_cast<float>(input_data[input_index]);
|
||||
}
|
||||
|
||||
out[output_transform.index(output_coord)] = static_cast<T>(summa);
|
||||
out[coordinate_index(output_coord, m_out_shape)] = static_cast<T>(summa);
|
||||
}
|
||||
NGRAPH_SUPPRESS_DEPRECATED_END
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@ -677,15 +674,14 @@ void InterpolateEval<T>::multidim_pil_func(const T* input_data, T* out, const in
|
||||
|
||||
template <typename T>
|
||||
void InterpolateEval<T>::nearest_func(const T* input_data, T* out) {
|
||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
||||
CoordinateTransform output_transform(m_out_shape);
|
||||
CoordinateTransform input_transform(m_input_data_shape);
|
||||
const CoordinateTransformBasic output_transform{m_out_shape};
|
||||
|
||||
for (const Coordinate& output_coord : output_transform) {
|
||||
auto input_coord = helper.get_input_coords_for_nearest_mode(output_coord);
|
||||
out[output_transform.index(output_coord)] = input_data[input_transform.index(input_coord)];
|
||||
const auto input_index = coordinate_index(input_coord, m_input_data_shape);
|
||||
const auto out_index = coordinate_index(output_coord, m_out_shape);
|
||||
out[out_index] = input_data[input_index];
|
||||
}
|
||||
NGRAPH_SUPPRESS_DEPRECATED_END
|
||||
}
|
||||
|
||||
inline void pad_input_data(const uint8_t* data_ptr,
|
||||
@ -694,9 +690,7 @@ inline void pad_input_data(const uint8_t* data_ptr,
|
||||
const ov::Shape& input_shape,
|
||||
const ov::Shape& padded_input_shape,
|
||||
const std::vector<size_t>& pads_begin) {
|
||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
||||
CoordinateTransform input_transform(input_shape);
|
||||
CoordinateTransform padded_transform(padded_input_shape);
|
||||
const CoordinateTransformBasic input_transform{input_shape};
|
||||
|
||||
for (const Coordinate& input_coord : input_transform) {
|
||||
auto padded_coord = input_coord;
|
||||
@ -705,11 +699,10 @@ inline void pad_input_data(const uint8_t* data_ptr,
|
||||
padded_coord[i] += pad;
|
||||
++i;
|
||||
}
|
||||
uint8_t* dst_ptr = padded_data_ptr + type_size * padded_transform.index(padded_coord);
|
||||
const uint8_t* src_ptr = data_ptr + type_size * input_transform.index(input_coord);
|
||||
uint8_t* dst_ptr = padded_data_ptr + type_size * coordinate_index(padded_coord, padded_input_shape);
|
||||
const uint8_t* src_ptr = data_ptr + type_size * coordinate_index(input_coord, input_shape);
|
||||
memcpy(dst_ptr, src_ptr, type_size);
|
||||
}
|
||||
NGRAPH_SUPPRESS_DEPRECATED_END
|
||||
}
|
||||
|
||||
inline PartialShape get_padded_input_shape(const PartialShape& input_shape,
|
||||
|
@ -40,9 +40,9 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
|
||||
#include "ngraph/op/interpolate.hpp"
|
||||
#include "ngraph/shape_util.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -6,8 +6,8 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include "ngraph/op/util/attr_types.hpp"
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/op/util/attr_types.hpp"
|
||||
#include "openvino/reference/autobroadcast_binop.hpp"
|
||||
|
||||
namespace ov {
|
||||
|
@ -6,8 +6,8 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include "ngraph/op/util/attr_types.hpp"
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/op/util/attr_types.hpp"
|
||||
#include "openvino/reference/autobroadcast_binop.hpp"
|
||||
|
||||
namespace ov {
|
||||
|
@ -6,40 +6,39 @@
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "ngraph/shape_util.hpp"
|
||||
#include "openvino/core/shape_util.hpp"
|
||||
#include "openvino/reference/reduce_max.hpp"
|
||||
#include "openvino/reference/reduce_sum.hpp"
|
||||
#include "openvino/reference/utils/coordinate_index.hpp"
|
||||
#include "openvino/reference/utils/coordinate_transform.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
template <typename T>
|
||||
void log_softmax(const T* arg, T* out, const Shape& shape, const AxisSet& axes) {
|
||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
||||
auto temp_shape = ngraph::reduce(shape, axes, true);
|
||||
auto temp_elements = shape_size(temp_shape);
|
||||
const auto temp_shape = util::reduce_keep_dims(shape, axes);
|
||||
const auto temp_elements = shape_size(temp_shape);
|
||||
auto temp_max = std::vector<T>(temp_elements, 0);
|
||||
auto temp_sum = std::vector<T>(temp_elements, 0);
|
||||
|
||||
reduce_max(arg, temp_max.data(), shape, axes);
|
||||
|
||||
CoordinateTransform transform(shape);
|
||||
CoordinateTransform temp_transform(temp_shape);
|
||||
const CoordinateTransformBasic transform{shape};
|
||||
for (const Coordinate& coord : transform) {
|
||||
Coordinate temp_coord = ngraph::reduce(coord, axes, true);
|
||||
out[transform.index(coord)] =
|
||||
static_cast<T>(std::exp(arg[transform.index(coord)] - temp_max[temp_transform.index(temp_coord)]));
|
||||
const Coordinate temp_coord = util::reduce_keep_dims(coord, axes);
|
||||
const auto out_index = coordinate_index(coord, shape);
|
||||
const auto temp_index = coordinate_index(temp_coord, temp_shape);
|
||||
out[out_index] = static_cast<T>(std::exp(arg[out_index] - temp_max[temp_index]));
|
||||
}
|
||||
|
||||
reduce_sum(out, temp_sum.data(), shape, axes);
|
||||
|
||||
for (const Coordinate& coord : transform) {
|
||||
Coordinate temp_coord = ngraph::reduce(coord, axes, true);
|
||||
out[transform.index(coord)] =
|
||||
static_cast<T>((arg[transform.index(coord)] - temp_max[temp_transform.index(temp_coord)]) -
|
||||
std::log(temp_sum[temp_transform.index(temp_coord)]));
|
||||
const Coordinate temp_coord = util::reduce_keep_dims(coord, axes);
|
||||
const auto out_index = coordinate_index(coord, shape);
|
||||
const auto temp_index = coordinate_index(temp_coord, temp_shape);
|
||||
out[out_index] = static_cast<T>((arg[out_index] - temp_max[temp_index]) - std::log(temp_sum[temp_index]));
|
||||
}
|
||||
NGRAPH_SUPPRESS_DEPRECATED_END
|
||||
}
|
||||
} // namespace reference
|
||||
} // namespace ov
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include <cmath>
|
||||
#include <numeric>
|
||||
|
||||
#include "ngraph/shape_util.hpp"
|
||||
#include "openvino/core/shape_util.hpp"
|
||||
#include "openvino/reference/utils/coordinate_index.hpp"
|
||||
#include "openvino/reference/utils/coordinate_transform.hpp"
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <cmath>
|
||||
#include <numeric>
|
||||
|
||||
#include "ngraph/util.hpp"
|
||||
#include "openvino/reference/utils/coordinate_index.hpp"
|
||||
#include "openvino/reference/utils/coordinate_transform.hpp"
|
||||
|
||||
namespace ov {
|
||||
@ -61,7 +61,6 @@ void lrn(const T* arg,
|
||||
double dbeta,
|
||||
double dbias,
|
||||
size_t size) {
|
||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
||||
T alpha = static_cast<T>(dalpha);
|
||||
T beta = static_cast<T>(dbeta);
|
||||
T bias = static_cast<T>(dbias);
|
||||
@ -74,7 +73,7 @@ void lrn(const T* arg,
|
||||
axes_map[axis_coord] = true;
|
||||
}
|
||||
|
||||
CoordinateTransform input_transform(arg_shape);
|
||||
const CoordinateTransformBasic input_transform{arg_shape};
|
||||
for (const Coordinate& in_coord : input_transform) {
|
||||
// area determined by in_coord local neighborhood
|
||||
for (size_t i = 0; i < axes_map.size(); i++) {
|
||||
@ -89,11 +88,10 @@ void lrn(const T* arg,
|
||||
}
|
||||
|
||||
T square_sum = sum_region_across_axes(arg, slice_indices(arg_shape, begin_area, area_shape));
|
||||
auto index = input_transform.index(in_coord);
|
||||
const auto index = coordinate_index(in_coord, arg_shape);
|
||||
T x = arg[index];
|
||||
out[index] = x / static_cast<T>(std::pow(bias + scale * square_sum, beta));
|
||||
}
|
||||
NGRAPH_SUPPRESS_DEPRECATED_END
|
||||
}
|
||||
} // namespace reference
|
||||
} // namespace ov
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include <vector>
|
||||
|
||||
#include "ngraph/runtime/opt_kernel/reshape.hpp"
|
||||
#include "ngraph/shape_util.hpp"
|
||||
#include "openvino/reference/broadcast.hpp"
|
||||
|
||||
namespace ov {
|
||||
|
@ -4,20 +4,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <ngraph/runtime/host_tensor.hpp>
|
||||
#include <vector>
|
||||
|
||||
#include "ngraph/node.hpp"
|
||||
#include "ngraph/op/matrix_nms.hpp"
|
||||
#include "ngraph/op/util/op_types.hpp"
|
||||
#include "ngraph/shape_util.hpp"
|
||||
#include "openvino/op/matrix_nms.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -11,105 +11,6 @@
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
template <typename T>
|
||||
void max_pool(const T* arg,
|
||||
T* out,
|
||||
const Shape& arg_shape,
|
||||
const Shape& out_shape,
|
||||
const Shape& window_shape,
|
||||
const Strides& window_movement_strides,
|
||||
const Shape& padding_below,
|
||||
const Shape& padding_above) {
|
||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
||||
// At the outermost level we will walk over every output coordinate O.
|
||||
CoordinateTransform output_transform(out_shape);
|
||||
|
||||
for (const Coordinate& out_coord : output_transform) {
|
||||
// Our output coordinate O will have the form:
|
||||
//
|
||||
// (N,chan,i_1,...,i_n)
|
||||
|
||||
size_t batch_index = out_coord[0];
|
||||
size_t channel = out_coord[1];
|
||||
|
||||
// For the input data we need to iterate the coordinate:
|
||||
//
|
||||
// I:
|
||||
//
|
||||
// over the range (noninclusive on the right):
|
||||
//
|
||||
// (N,chan,s_1*i_1,s_2*i_2,...,s_n*i_n) ->
|
||||
//
|
||||
// (N+1,chan+1,s_1*i_1 + window_shape_1,...,s_n*i_n + window_shape_n)
|
||||
//
|
||||
// with unit stride.
|
||||
//
|
||||
// We iterate this over the *padded* data, so below we will need to check for
|
||||
// coordinates that fall in the padding area.
|
||||
|
||||
size_t n_spatial_dimensions = arg_shape.size() - 2;
|
||||
|
||||
Coordinate input_batch_transform_start(2 + n_spatial_dimensions);
|
||||
Coordinate input_batch_transform_end(2 + n_spatial_dimensions);
|
||||
Strides input_batch_transform_source_strides(2 + n_spatial_dimensions, 1);
|
||||
AxisVector input_batch_transform_source_axis_order(2 + n_spatial_dimensions);
|
||||
CoordinateDiff input_batch_transform_padding_below(2 + n_spatial_dimensions);
|
||||
CoordinateDiff input_batch_transform_padding_above(2 + n_spatial_dimensions);
|
||||
|
||||
input_batch_transform_start[0] = batch_index;
|
||||
input_batch_transform_end[0] = batch_index + 1;
|
||||
input_batch_transform_start[1] = channel;
|
||||
input_batch_transform_end[1] = channel + 1;
|
||||
input_batch_transform_padding_below[0] = 0;
|
||||
input_batch_transform_padding_below[1] = 0;
|
||||
input_batch_transform_padding_above[0] = 0;
|
||||
input_batch_transform_padding_above[1] = 0;
|
||||
|
||||
for (size_t i = 2; i < n_spatial_dimensions + 2; i++) {
|
||||
size_t window_shape_this_dim = window_shape[i - 2];
|
||||
size_t movement_stride = window_movement_strides[i - 2];
|
||||
|
||||
input_batch_transform_start[i] = movement_stride * out_coord[i];
|
||||
input_batch_transform_end[i] = input_batch_transform_start[i] + window_shape_this_dim;
|
||||
// If a window (kernel) is out of arg shape bounds, trim it to fit
|
||||
auto padded_upper_bound = arg_shape[i] + padding_below[i - 2] + padding_above[i - 2];
|
||||
if (input_batch_transform_end[i] > padded_upper_bound) {
|
||||
input_batch_transform_end[i] = padded_upper_bound;
|
||||
}
|
||||
input_batch_transform_padding_below[i] = padding_below[i - 2];
|
||||
input_batch_transform_padding_above[i] = padding_above[i - 2];
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < arg_shape.size(); i++) {
|
||||
input_batch_transform_source_axis_order[i] = i;
|
||||
}
|
||||
|
||||
CoordinateTransform input_batch_transform(arg_shape,
|
||||
input_batch_transform_start,
|
||||
input_batch_transform_end,
|
||||
input_batch_transform_source_strides,
|
||||
input_batch_transform_source_axis_order,
|
||||
input_batch_transform_padding_below,
|
||||
input_batch_transform_padding_above);
|
||||
|
||||
// As we go, we compute the maximum value:
|
||||
//
|
||||
// output[O] = max(output[O],arg[I])
|
||||
|
||||
T result = std::numeric_limits<T>::lowest();
|
||||
|
||||
for (const Coordinate& input_batch_coord : input_batch_transform) {
|
||||
if (input_batch_transform.has_source_coordinate(input_batch_coord)) {
|
||||
T x = arg[input_batch_transform.index(input_batch_coord)];
|
||||
result = x > result ? x : result;
|
||||
}
|
||||
}
|
||||
|
||||
out[output_transform.index(out_coord)] = result;
|
||||
}
|
||||
NGRAPH_SUPPRESS_DEPRECATED_END
|
||||
}
|
||||
|
||||
namespace {
|
||||
void validate_max_pool_kernel_params(const size_t dims,
|
||||
const Shape& kernel,
|
||||
@ -117,20 +18,20 @@ void validate_max_pool_kernel_params(const size_t dims,
|
||||
const Strides& kernel_dilations,
|
||||
const Shape& pads_begin,
|
||||
const Shape& pads_end) {
|
||||
NGRAPH_CHECK(kernel.size() == dims && kernel_strides.size() == dims && kernel_dilations.size() == dims &&
|
||||
pads_begin.size() == dims && pads_end.size() == dims,
|
||||
"One of the MaxPool params does not match the ",
|
||||
dims,
|
||||
"D implementation.\nkernel=",
|
||||
kernel,
|
||||
"\nkernel_strides=",
|
||||
kernel_strides,
|
||||
"\nkernel_dilations=",
|
||||
kernel_dilations,
|
||||
"\npads_begin=",
|
||||
pads_begin,
|
||||
"\npads_end=",
|
||||
pads_end);
|
||||
OPENVINO_ASSERT(kernel.size() == dims && kernel_strides.size() == dims && kernel_dilations.size() == dims &&
|
||||
pads_begin.size() == dims && pads_end.size() == dims,
|
||||
"One of the MaxPool params does not match the ",
|
||||
dims,
|
||||
"D implementation.\nkernel=",
|
||||
kernel,
|
||||
"\nkernel_strides=",
|
||||
kernel_strides,
|
||||
"\nkernel_dilations=",
|
||||
kernel_dilations,
|
||||
"\npads_begin=",
|
||||
pads_begin,
|
||||
"\npads_end=",
|
||||
pads_end);
|
||||
}
|
||||
|
||||
/// \brief A helper struct representing spatial coordinates of a tensor element. It can use signed numbers as the
|
||||
@ -390,10 +291,9 @@ void max_pool(const Values_t* data,
|
||||
pads_end,
|
||||
indices_offset);
|
||||
} else {
|
||||
NGRAPH_CHECK(false,
|
||||
"Unsupported input shape ",
|
||||
data_shape,
|
||||
" passed to the MaxPool reference implementation. Supported shapes: 3D, 4D and 5D.");
|
||||
OPENVINO_THROW("Unsupported input shape ",
|
||||
data_shape,
|
||||
" passed to the MaxPool reference implementation. Supported shapes: 3D, 4D and 5D.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -409,5 +309,28 @@ void max_pool(const Values_t* data,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Value_t>
|
||||
void max_pool(const Value_t* data,
|
||||
Value_t* values,
|
||||
const Shape& data_shape,
|
||||
const Shape& out_shape,
|
||||
const Shape& kernel,
|
||||
const Strides& strides,
|
||||
const Shape& pads_begin,
|
||||
const Shape& pads_end) {
|
||||
std::vector<int32_t> indices(shape_size(out_shape));
|
||||
const Strides dilations(kernel.size(), 1);
|
||||
max_pool<Value_t, int32_t>(data,
|
||||
values,
|
||||
indices.data(),
|
||||
data_shape,
|
||||
out_shape,
|
||||
kernel,
|
||||
strides,
|
||||
dilations,
|
||||
pads_begin,
|
||||
pads_end);
|
||||
}
|
||||
} // namespace reference
|
||||
} // namespace ov
|
||||
|
@ -6,8 +6,8 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include "ngraph/op/util/attr_types.hpp"
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/op/util/attr_types.hpp"
|
||||
#include "openvino/reference/autobroadcast_binop.hpp"
|
||||
|
||||
namespace ov {
|
||||
|
@ -6,8 +6,8 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include "ngraph/op/util/attr_types.hpp"
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/op/util/attr_types.hpp"
|
||||
#include "openvino/reference/autobroadcast_binop.hpp"
|
||||
|
||||
namespace ov {
|
||||
|
@ -4,20 +4,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <ngraph/runtime/host_tensor.hpp>
|
||||
#include <vector>
|
||||
|
||||
#include "ngraph/node.hpp"
|
||||
#include "ngraph/op/util/multiclass_nms_base.hpp"
|
||||
#include "ngraph/op/util/op_types.hpp"
|
||||
#include "ngraph/shape_util.hpp"
|
||||
#include "openvino/op/util/multiclass_nms_base.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -6,8 +6,8 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include "ngraph/op/util/attr_types.hpp"
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/op/util/attr_types.hpp"
|
||||
#include "openvino/reference/autobroadcast_binop.hpp"
|
||||
|
||||
namespace ov {
|
||||
|
@ -5,9 +5,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <ngraph/op/mvn.hpp>
|
||||
#include <ngraph/shape.hpp>
|
||||
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/op/mvn.hpp"
|
||||
#include "openvino/reference/add.hpp"
|
||||
#include "openvino/reference/divide.hpp"
|
||||
#include "openvino/reference/multiply.hpp"
|
||||
@ -18,7 +18,6 @@
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
OPENVINO_SUPPRESS_DEPRECATED_START
|
||||
template <typename T>
|
||||
void mvn(const T* arg,
|
||||
T* out,
|
||||
@ -26,7 +25,7 @@ void mvn(const T* arg,
|
||||
const bool normalize_variance,
|
||||
const AxisSet& reduction_axes,
|
||||
const double eps) {
|
||||
auto reduced_shape = ngraph::reduce(in_shape, reduction_axes, true);
|
||||
auto reduced_shape = util::reduce_keep_dims(in_shape, reduction_axes);
|
||||
std::vector<T> tmp_buffer(shape_size(in_shape));
|
||||
reduce_mean(arg, tmp_buffer.data(), in_shape, reduction_axes);
|
||||
subtract(arg, tmp_buffer.data(), out, in_shape, reduced_shape, op::AutoBroadcastType::NUMPY);
|
||||
@ -56,7 +55,7 @@ void mvn_6(const T* arg,
|
||||
bool normalize_variance,
|
||||
double eps,
|
||||
op::MVNEpsMode eps_mode) {
|
||||
auto reduced_shape = ngraph::reduce(in_shape, reduction_axes, true);
|
||||
auto reduced_shape = util::reduce_keep_dims(in_shape, reduction_axes);
|
||||
std::vector<T> tmp_buffer(shape_size(in_shape));
|
||||
reduce_mean(arg, tmp_buffer.data(), in_shape, reduction_axes);
|
||||
subtract(arg, tmp_buffer.data(), out, in_shape, reduced_shape, op::AutoBroadcastType::NUMPY);
|
||||
@ -87,7 +86,6 @@ void mvn_6(const T* arg,
|
||||
divide(out, tmp_buffer.data(), out, in_shape, reduced_shape, op::AutoBroadcastType::NUMPY, true);
|
||||
}
|
||||
}
|
||||
OPENVINO_SUPPRESS_DEPRECATED_END
|
||||
|
||||
template <typename T>
|
||||
AxisSet mvn_6_reduction_axes(const ov::Tensor& axes_input, size_t rank) {
|
||||
|
@ -4,20 +4,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <ngraph/runtime/host_tensor.hpp>
|
||||
#include <vector>
|
||||
|
||||
#include "ngraph/node.hpp"
|
||||
#include "ngraph/op/util/op_types.hpp"
|
||||
#include "ngraph/ops.hpp"
|
||||
#include "ngraph/shape_util.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/runtime/tensor.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
@ -37,11 +28,11 @@ void non_max_suppression5(const float* boxes_data,
|
||||
const bool sort_result_descending);
|
||||
|
||||
void nms5_postprocessing(ov::TensorVector& outputs,
|
||||
const ngraph::element::Type output_type,
|
||||
const element::Type output_type,
|
||||
const std::vector<int64_t>& selected_indices,
|
||||
const std::vector<float>& selected_scores,
|
||||
int64_t valid_outputs,
|
||||
const ngraph::element::Type selected_scores_type);
|
||||
const element::Type selected_scores_type);
|
||||
|
||||
void non_max_suppression(const float* boxes_data,
|
||||
const Shape& boxes_data_shape,
|
||||
@ -59,10 +50,10 @@ void non_max_suppression(const float* boxes_data,
|
||||
const bool sort_result_descending);
|
||||
|
||||
void nms_postprocessing(ov::TensorVector& outputs,
|
||||
const ngraph::element::Type output_type,
|
||||
const element::Type output_type,
|
||||
const std::vector<int64_t>& selected_indices,
|
||||
const std::vector<float>& selected_scores,
|
||||
int64_t valid_outputs,
|
||||
const ngraph::element::Type selected_scores_type);
|
||||
const element::Type selected_scores_type);
|
||||
} // namespace reference
|
||||
} // namespace ov
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -4,8 +4,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ngraph/op/normalize_l2.hpp>
|
||||
|
||||
#include "openvino/reference/autobroadcast_binop.hpp"
|
||||
#include "openvino/reference/reduce_sum.hpp"
|
||||
|
||||
|
@ -11,8 +11,8 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include "ngraph/op/util/attr_types.hpp"
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/op/util/attr_types.hpp"
|
||||
#include "openvino/reference/autobroadcast_binop.hpp"
|
||||
|
||||
namespace ov {
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -6,8 +6,8 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include "ngraph/op/util/attr_types.hpp"
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/op/util/attr_types.hpp"
|
||||
#include "openvino/reference/autobroadcast_binop.hpp"
|
||||
|
||||
namespace ov {
|
||||
|
@ -4,9 +4,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ngraph/coordinate_diff.hpp"
|
||||
#include "ngraph/op/util/attr_types.hpp" // for op::PadMode
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/coordinate_diff.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/op/util/attr_types.hpp" // for op::PadMode
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -7,8 +7,8 @@
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
|
||||
#include "ngraph/op/util/attr_types.hpp"
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/op/util/attr_types.hpp"
|
||||
#include "openvino/reference/autobroadcast_binop.hpp"
|
||||
|
||||
namespace ov {
|
||||
|
@ -6,9 +6,9 @@
|
||||
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <ngraph/op/util/attr_types.hpp>
|
||||
#include <ngraph/shape.hpp>
|
||||
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/op/util/attr_types.hpp"
|
||||
#include "openvino/reference/autobroadcast_binop.hpp"
|
||||
|
||||
namespace ov {
|
||||
@ -22,15 +22,9 @@ void prelu(const T* arg, const T* slope, T* out, const Shape& arg_shape, const S
|
||||
channel_slope_shape[channel_dim_idx] = slope_shape[0];
|
||||
std::swap(slope_shape_tmp, channel_slope_shape);
|
||||
}
|
||||
autobroadcast_binop(arg,
|
||||
slope,
|
||||
out,
|
||||
arg_shape,
|
||||
slope_shape_tmp,
|
||||
ngraph::op::AutoBroadcastType::NUMPY,
|
||||
[](T x, T y) -> T {
|
||||
return x < T(0) ? T(x * y) : x;
|
||||
});
|
||||
autobroadcast_binop(arg, slope, out, arg_shape, slope_shape_tmp, op::AutoBroadcastType::NUMPY, [](T x, T y) -> T {
|
||||
return x < T(0) ? T(x * y) : x;
|
||||
});
|
||||
}
|
||||
} // namespace reference
|
||||
} // namespace ov
|
||||
|
@ -6,9 +6,8 @@
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "ngraph/axis_vector.hpp"
|
||||
#include "ngraph/check.hpp"
|
||||
#include "ngraph/op/prior_box.hpp"
|
||||
#include "openvino/core/except.hpp"
|
||||
#include "openvino/op/prior_box.hpp"
|
||||
#include "openvino/reference/utils/coordinate_transform.hpp"
|
||||
|
||||
namespace ov {
|
||||
@ -50,7 +49,7 @@ void prior_box(const T* data,
|
||||
}
|
||||
|
||||
std::vector<float> variance = attrs.variance;
|
||||
NGRAPH_CHECK(variance.size() == 1 || variance.size() == 4 || variance.empty());
|
||||
OPENVINO_ASSERT(variance.size() == 1 || variance.size() == 4 || variance.empty());
|
||||
if (variance.empty())
|
||||
variance.push_back(0.1f);
|
||||
|
||||
|
@ -6,9 +6,8 @@
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "ngraph/axis_vector.hpp"
|
||||
#include "ngraph/check.hpp"
|
||||
#include "ngraph/op/prior_box_clustered.hpp"
|
||||
#include "openvino/core/except.hpp"
|
||||
#include "openvino/op/prior_box_clustered.hpp"
|
||||
#include "openvino/reference/utils/coordinate_transform.hpp"
|
||||
|
||||
namespace ov {
|
||||
@ -18,11 +17,11 @@ void prior_box_clustered(const T* data,
|
||||
const T* img,
|
||||
float* dst_data,
|
||||
const Shape& out_shape,
|
||||
const ngraph::op::PriorBoxClusteredAttrs& attrs) {
|
||||
const op::v0::PriorBoxClustered::Attributes& attrs) {
|
||||
size_t num_priors_ = attrs.widths.size();
|
||||
|
||||
auto variances = attrs.variances;
|
||||
NGRAPH_CHECK(variances.size() == 1 || variances.size() == 4 || variances.empty());
|
||||
OPENVINO_ASSERT(variances.size() == 1 || variances.size() == 4 || variances.empty());
|
||||
if (variances.empty())
|
||||
variances.push_back(0.1f);
|
||||
|
||||
|
@ -2,8 +2,8 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "ngraph/op/proposal.hpp"
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/op/proposal.hpp"
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
namespace details {
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
@ -29,7 +29,7 @@ void psroi_pooling(const T* input,
|
||||
} else if (mode_str == "bilinear") {
|
||||
mode = BILINEAR;
|
||||
} else {
|
||||
NGRAPH_CHECK(false, "Invalid PS ROI pooling mode: " + mode_str);
|
||||
OPENVINO_ASSERT(false, "Invalid PS ROI pooling mode: " + mode_str);
|
||||
}
|
||||
size_t channels_in = input_shape[1];
|
||||
size_t height = input_shape[2];
|
||||
|
@ -1,76 +0,0 @@
|
||||
// Copyright (C) 2018-2023 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ngraph/op/quantize.hpp"
|
||||
#include "ngraph/shape_util.hpp"
|
||||
#include "openvino/reference/utils/coordinate_transform.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
template <typename REAL, typename QUANT>
|
||||
void quantize(const REAL* input,
|
||||
const REAL* scale,
|
||||
const QUANT* zero_point,
|
||||
QUANT* output,
|
||||
const Shape& input_shape,
|
||||
const Shape& scale_zero_point_shape,
|
||||
const AxisSet& axes,
|
||||
op::Quantize::RoundMode round_mode) {
|
||||
CoordinateTransform input_transform(input_shape);
|
||||
CoordinateTransform scale_zero_point_transform(scale_zero_point_shape);
|
||||
|
||||
for (const Coordinate& input_coord : input_transform) {
|
||||
Coordinate scale_zero_point_coord = project(input_coord, axes);
|
||||
|
||||
// apply scale
|
||||
REAL qvalue =
|
||||
input[input_transform.index(input_coord)] / scale[scale_zero_point_transform.index(scale_zero_point_coord)];
|
||||
|
||||
// round
|
||||
if (round_mode == op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY) {
|
||||
REAL abs_qvalue = std::fabs(qvalue);
|
||||
REAL abs_qvalue_toward_inf = std::floor(abs_qvalue + static_cast<REAL>(0.5));
|
||||
qvalue = (qvalue < static_cast<REAL>(0.0)) ? -abs_qvalue_toward_inf : abs_qvalue_toward_inf;
|
||||
} else if (round_mode == op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_ZERO) {
|
||||
auto abs_qvalue = std::fabs(qvalue);
|
||||
auto abs_qvalue_toward_zero = std::ceil(abs_qvalue - static_cast<REAL>(0.5));
|
||||
qvalue = (qvalue < static_cast<REAL>(0.0)) ? -abs_qvalue_toward_zero : abs_qvalue_toward_zero;
|
||||
} else if (round_mode == op::Quantize::RoundMode::ROUND_NEAREST_UPWARD) {
|
||||
qvalue = std::floor(qvalue + static_cast<REAL>(0.5));
|
||||
} else if (round_mode == op::Quantize::RoundMode::ROUND_NEAREST_DOWNWARD) {
|
||||
qvalue = std::ceil(qvalue - static_cast<REAL>(0.5));
|
||||
} else if (round_mode == op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_EVEN) {
|
||||
auto up_qvalue = std::floor(qvalue + static_cast<REAL>(0.5));
|
||||
auto dn_qvalue = std::ceil(qvalue - static_cast<REAL>(0.5));
|
||||
auto rem = std::fmod(up_qvalue, 2.0);
|
||||
qvalue = (rem == 0.0) ? up_qvalue : dn_qvalue;
|
||||
} else if (round_mode == op::Quantize::RoundMode::ROUND_TOWARD_INFINITY) {
|
||||
auto abs_qvalue = std::fabs(qvalue);
|
||||
auto abs_qvalue_toward_inf = std::ceil(abs_qvalue);
|
||||
qvalue = (qvalue < static_cast<REAL>(0.0)) ? -abs_qvalue_toward_inf : abs_qvalue_toward_inf;
|
||||
} else if (round_mode == op::Quantize::RoundMode::ROUND_TOWARD_ZERO) {
|
||||
auto abs_qvalue = std::fabs(qvalue);
|
||||
auto abs_qvalue_toward_zero = std::floor(abs_qvalue);
|
||||
qvalue = (qvalue < static_cast<REAL>(0.0)) ? -abs_qvalue_toward_zero : abs_qvalue_toward_zero;
|
||||
} else if (round_mode == op::Quantize::RoundMode::ROUND_UP) {
|
||||
qvalue = std::ceil(qvalue);
|
||||
} else if (round_mode == op::Quantize::RoundMode::ROUND_DOWN) {
|
||||
qvalue = std::floor(qvalue);
|
||||
}
|
||||
|
||||
// apply zero_point
|
||||
qvalue += zero_point[scale_zero_point_transform.index(scale_zero_point_coord)];
|
||||
|
||||
// clamp
|
||||
qvalue = std::max<REAL>(qvalue, static_cast<REAL>(std::numeric_limits<QUANT>::min()));
|
||||
qvalue = std::min<REAL>(qvalue, static_cast<REAL>(std::numeric_limits<QUANT>::max()));
|
||||
|
||||
// cast
|
||||
output[input_transform.index(input_coord)] = static_cast<QUANT>(qvalue);
|
||||
}
|
||||
}
|
||||
} // namespace reference
|
||||
} // namespace ov
|
@ -5,9 +5,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <ctime>
|
||||
#include <ngraph/type/element_type.hpp>
|
||||
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/core/type/element_type.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
@ -28,7 +28,7 @@ std::pair<uint64_t, uint64_t> random_uniform(const uint64_t* out_shape,
|
||||
const char* max_val,
|
||||
char* out,
|
||||
const Shape& out_shape_shape,
|
||||
const ngraph::element::Type& elem_type,
|
||||
const element::Type& elem_type,
|
||||
uint64_t seed,
|
||||
uint64_t seed2,
|
||||
std::pair<uint64_t, uint64_t> prev_state);
|
||||
|
@ -7,10 +7,8 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
#include "ngraph/axis_vector.hpp"
|
||||
#include "ngraph/check.hpp"
|
||||
#include "ngraph/type/bfloat16.hpp"
|
||||
#include "ngraph/type/float16.hpp"
|
||||
#include "openvino/core/type/bfloat16.hpp"
|
||||
#include "openvino/core/type/float16.hpp"
|
||||
#include "openvino/reference/utils/coordinate_transform.hpp"
|
||||
|
||||
namespace ov {
|
||||
|
@ -17,13 +17,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <ngraph/runtime/host_tensor.hpp>
|
||||
#include <vector>
|
||||
|
||||
#include "ngraph/node.hpp"
|
||||
#include "ngraph/op/util/op_types.hpp"
|
||||
#include "ngraph/ops.hpp"
|
||||
#include "ngraph/shape_util.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
@ -57,7 +57,7 @@ void region_yolo(const T* input,
|
||||
const int regions,
|
||||
const bool do_softmax,
|
||||
const std::vector<int64_t>& mask) {
|
||||
NGRAPH_CHECK(input_shape.size() == 4);
|
||||
OPENVINO_ASSERT(input_shape.size() == 4);
|
||||
|
||||
const int batches = static_cast<int>(input_shape[0]);
|
||||
const int height = static_cast<int>(input_shape[2]);
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -4,8 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ngraph/axis_vector.hpp"
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/axis_vector.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -9,8 +9,6 @@
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
|
||||
#include "ngraph/shape.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
template <typename T>
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include <cmath>
|
||||
#include <numeric>
|
||||
|
||||
#include "ngraph/util.hpp"
|
||||
#include "openvino/reference/utils/coordinate_transform.hpp"
|
||||
|
||||
namespace ov {
|
||||
@ -25,8 +24,8 @@ void reverse_sequence(const T* arg,
|
||||
size_t batch_index = in_coord[batch_axis];
|
||||
auto orig_seq_index = static_cast<size_t>(sequence_lengths[batch_index]);
|
||||
|
||||
NGRAPH_CHECK(orig_seq_index <= arg_shape.at(sequence_axis),
|
||||
"One of the elements of sequence lengths is greater than sequence axis dimension");
|
||||
OPENVINO_ASSERT(orig_seq_index <= arg_shape.at(sequence_axis),
|
||||
"One of the elements of sequence lengths is greater than sequence axis dimension");
|
||||
|
||||
if (orig_seq_index == 0) {
|
||||
orig_seq_index = 1;
|
||||
|
@ -6,9 +6,11 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "ngraph/op/roi_align.hpp" // for ROIAlign:PoolingMode
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/op/roi_align.hpp"
|
||||
#include "openvino/reference/utils/coordinate_index.hpp"
|
||||
#include "openvino/reference/utils/coordinate_transform.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
using ROIPoolingMode = op::v3::ROIAlign::PoolingMode;
|
||||
@ -33,11 +35,6 @@ void roi_align(const T* feature_maps,
|
||||
auto feature_map_width = feature_maps_shape[3];
|
||||
auto num_rois = rois_shape[0];
|
||||
|
||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
||||
CoordinateTransform feature_maps_transform(feature_maps_shape);
|
||||
CoordinateTransform rois_transform(rois_shape);
|
||||
CoordinateTransform out_transform(out_shape);
|
||||
|
||||
bool aligned = false;
|
||||
T offset_src = static_cast<T>(0);
|
||||
T offset_dst = static_cast<T>(0);
|
||||
@ -64,10 +61,10 @@ void roi_align(const T* feature_maps,
|
||||
|
||||
for (unsigned int roi_index = 0; roi_index < num_rois; roi_index++) {
|
||||
// Get ROI`s corners
|
||||
T x1 = (rois[rois_transform.index({roi_index, 0})] + offset_src) * spatial_scale + offset_dst;
|
||||
T y1 = (rois[rois_transform.index({roi_index, 1})] + offset_src) * spatial_scale + offset_dst;
|
||||
T x2 = (rois[rois_transform.index({roi_index, 2})] + offset_src) * spatial_scale + offset_dst;
|
||||
T y2 = (rois[rois_transform.index({roi_index, 3})] + offset_src) * spatial_scale + offset_dst;
|
||||
T x1 = (rois[coordinate_index({roi_index, 0}, rois_shape)] + offset_src) * spatial_scale + offset_dst;
|
||||
T y1 = (rois[coordinate_index({roi_index, 1}, rois_shape)] + offset_src) * spatial_scale + offset_dst;
|
||||
T x2 = (rois[coordinate_index({roi_index, 2}, rois_shape)] + offset_src) * spatial_scale + offset_dst;
|
||||
T y2 = (rois[coordinate_index({roi_index, 3}, rois_shape)] + offset_src) * spatial_scale + offset_dst;
|
||||
|
||||
T roi_width = x2 - x1;
|
||||
T roi_height = y2 - y1;
|
||||
@ -83,7 +80,7 @@ void roi_align(const T* feature_maps,
|
||||
auto sampling_ratio_x = sampling_ratio == 0 ? static_cast<int>(ceil(bin_width)) : sampling_ratio;
|
||||
auto sampling_ratio_y = sampling_ratio == 0 ? static_cast<int>(ceil(bin_height)) : sampling_ratio;
|
||||
|
||||
NGRAPH_CHECK(sampling_ratio_x >= 0 && sampling_ratio_y >= 0);
|
||||
OPENVINO_ASSERT(sampling_ratio_x >= 0 && sampling_ratio_y >= 0);
|
||||
|
||||
uint64_t num_samples_in_bin = static_cast<uint64_t>(sampling_ratio_x) * static_cast<uint64_t>(sampling_ratio_y);
|
||||
|
||||
@ -169,26 +166,27 @@ void roi_align(const T* feature_maps,
|
||||
// the four parts are values of the four closest surrounding
|
||||
// neighbours of considered sample, then basing on all sampled
|
||||
// values in bin we calculate pooled value
|
||||
auto sample_part_1 = feature_maps[feature_maps_transform.index(
|
||||
{static_cast<unsigned int>(batch_indices[roi_index]),
|
||||
channel_index,
|
||||
pooling_points[sample_index].first,
|
||||
pooling_points[sample_index].second})];
|
||||
auto sample_part_2 = feature_maps[feature_maps_transform.index(
|
||||
{static_cast<unsigned int>(batch_indices[roi_index]),
|
||||
channel_index,
|
||||
pooling_points[sample_index + 1].first,
|
||||
pooling_points[sample_index + 1].second})];
|
||||
auto sample_part_3 = feature_maps[feature_maps_transform.index(
|
||||
{static_cast<unsigned int>(batch_indices[roi_index]),
|
||||
channel_index,
|
||||
pooling_points[sample_index + 2].first,
|
||||
pooling_points[sample_index + 2].second})];
|
||||
auto sample_part_4 = feature_maps[feature_maps_transform.index(
|
||||
{static_cast<unsigned int>(batch_indices[roi_index]),
|
||||
channel_index,
|
||||
pooling_points[sample_index + 3].first,
|
||||
pooling_points[sample_index + 3].second})];
|
||||
const auto batch_index = static_cast<size_t>(batch_indices[roi_index]);
|
||||
auto sample_part_1 = feature_maps[coordinate_index({batch_index,
|
||||
channel_index,
|
||||
pooling_points[sample_index].first,
|
||||
pooling_points[sample_index].second},
|
||||
feature_maps_shape)];
|
||||
auto sample_part_2 = feature_maps[coordinate_index({batch_index,
|
||||
channel_index,
|
||||
pooling_points[sample_index + 1].first,
|
||||
pooling_points[sample_index + 1].second},
|
||||
feature_maps_shape)];
|
||||
auto sample_part_3 = feature_maps[coordinate_index({batch_index,
|
||||
channel_index,
|
||||
pooling_points[sample_index + 2].first,
|
||||
pooling_points[sample_index + 2].second},
|
||||
feature_maps_shape)];
|
||||
auto sample_part_4 = feature_maps[coordinate_index({batch_index,
|
||||
channel_index,
|
||||
pooling_points[sample_index + 3].first,
|
||||
pooling_points[sample_index + 3].second},
|
||||
feature_maps_shape)];
|
||||
|
||||
T sample_value = pooling_weights[sample_index] * sample_part_1 +
|
||||
pooling_weights[sample_index + 1] * sample_part_2 +
|
||||
@ -210,17 +208,12 @@ void roi_align(const T* feature_maps,
|
||||
}
|
||||
}
|
||||
// save the calculations for all bins across this channel
|
||||
auto output_channel_offset = out_transform.index({static_cast<unsigned int>(roi_index),
|
||||
static_cast<unsigned int>(channel_index),
|
||||
static_cast<unsigned int>(0),
|
||||
static_cast<unsigned int>(0)});
|
||||
auto output_channel_offset = coordinate_index({roi_index, channel_index, 0ul, 0ul}, out_shape);
|
||||
std::copy(tmp_out.begin(), tmp_out.end(), out + output_channel_offset);
|
||||
|
||||
tmp_out.clear();
|
||||
}
|
||||
}
|
||||
NGRAPH_SUPPRESS_DEPRECATED_END
|
||||
return;
|
||||
}
|
||||
} // namespace reference
|
||||
} // namespace ov
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
@ -42,7 +42,7 @@ void roi_pooling(const T* feature_maps,
|
||||
int roi_batch_id = static_cast<int>(rois[roi_idx + 0]);
|
||||
|
||||
// ROI batch id must be in the range of [0, N-1]
|
||||
NGRAPH_CHECK(0 <= roi_batch_id && roi_batch_id < batches, "ROI batch id must be in the range of [0, N-1]");
|
||||
OPENVINO_ASSERT(0 <= roi_batch_id && roi_batch_id < batches, "ROI batch id must be in the range of [0, N-1]");
|
||||
|
||||
if (pooling_method == "max") {
|
||||
// ROI coordinates scaled to input feature maps
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/reference/utils/coordinate_transform.hpp"
|
||||
|
||||
namespace ov {
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include <type_traits>
|
||||
|
||||
#include "openvino/op/round.hpp"
|
||||
#include "openvino/reference/round_guard.hpp"
|
||||
#include "openvino/reference/rounding_guard.hpp"
|
||||
#include "openvino/reference/utils/type_util.hpp"
|
||||
|
||||
namespace ov {
|
||||
@ -50,7 +50,7 @@ T round_half_away_zero(T value) {
|
||||
*/
|
||||
template <typename T, typename std::enable_if<ov::is_floating_point<T>()>::type* = nullptr>
|
||||
void round(const T* arg, T* out, const size_t count, const op::v5::Round::RoundMode mode) {
|
||||
const ov::RoundGuard round_g{FE_TONEAREST};
|
||||
const ov::RoundingGuard round_g{FE_TONEAREST};
|
||||
const auto round_algo =
|
||||
(mode == op::v5::Round::RoundMode::HALF_TO_EVEN) ? round_to_nearest_even<T> : round_half_away_zero<T>;
|
||||
|
||||
|
@ -18,10 +18,10 @@ namespace ov {
|
||||
* - FE_UPWARD
|
||||
* see std <cfenv> header for details.
|
||||
*/
|
||||
class RoundGuard {
|
||||
class RoundingGuard {
|
||||
public:
|
||||
RoundGuard(int mode);
|
||||
~RoundGuard();
|
||||
RoundingGuard(int mode);
|
||||
~RoundingGuard();
|
||||
|
||||
private:
|
||||
int m_prev_round_mode;
|
@ -8,8 +8,8 @@
|
||||
#include <cstring>
|
||||
#include <iterator>
|
||||
|
||||
#include "ngraph/check.hpp"
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/except.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/op/scatter_elements_update.hpp"
|
||||
#include "openvino/reference/utils/coordinate_transform.hpp"
|
||||
|
||||
|
@ -7,8 +7,7 @@
|
||||
#include <cstring>
|
||||
#include <numeric>
|
||||
|
||||
#include "ngraph/coordinate.hpp"
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "utils/span.hpp"
|
||||
|
||||
namespace ov {
|
||||
|
@ -6,8 +6,7 @@
|
||||
|
||||
#include <numeric>
|
||||
|
||||
#include "ngraph/check.hpp"
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/reference/utils/coordinate_transform.hpp"
|
||||
#include "openvino/util/common_util.hpp"
|
||||
|
||||
@ -22,12 +21,10 @@ static const CoordinateTransformBasic get_target_shape(const Shape& data_shape,
|
||||
AxisVector axis_order(m_n_axes);
|
||||
std::iota(axis_order.begin(), axis_order.end(), 0);
|
||||
const Strides strides(m_n_axes, 1);
|
||||
OPENVINO_SUPPRESS_DEPRECATED_START
|
||||
for (size_t axis = 0; axis < m_n_axes; axis++) {
|
||||
target_shape.push_back(
|
||||
util::ceil_div(end_corner[axis_order[axis]] - start_corner[axis_order[axis]], strides[axis_order[axis]]));
|
||||
}
|
||||
OPENVINO_SUPPRESS_DEPRECATED_END
|
||||
return target_shape;
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ void cell_pass(CellType type,
|
||||
return new_shape;
|
||||
};
|
||||
|
||||
size_t x_shape_size = ngraph::shape_size(shapes[0]);
|
||||
size_t x_shape_size = shape_size(shapes[0]);
|
||||
|
||||
// split X
|
||||
size_t num_splits = shapes[0].at(1);
|
||||
@ -90,7 +90,7 @@ void cell_pass(CellType type,
|
||||
// split A
|
||||
std::vector<char> a_seqs;
|
||||
if (type == CellType::AUGRU) {
|
||||
const auto a_shape_size = ngraph::shape_size(shapes[6]);
|
||||
const auto a_shape_size = shape_size(shapes[6]);
|
||||
a_seqs.resize(a_shape_size * sizeof(T));
|
||||
std::vector<char*> a_pointers(num_splits);
|
||||
for (size_t i = 0; i < num_splits; ++i) {
|
||||
@ -100,18 +100,18 @@ void cell_pass(CellType type,
|
||||
}
|
||||
|
||||
Shape part_shape{batch, 1, hidden_size};
|
||||
size_t part_shape_size = ngraph::shape_size(part_shape);
|
||||
size_t part_shape_size = shape_size(part_shape);
|
||||
std::vector<std::vector<char>> h_list(num_splits, std::vector<char>(part_shape_size * sizeof(T), 0));
|
||||
std::vector<std::vector<char>> c_list(num_splits, std::vector<char>(part_shape_size * sizeof(T), 0));
|
||||
|
||||
// use outputs as a buffer for temporarily values
|
||||
char* H_i = outputs[1];
|
||||
std::memcpy(H_i, inputs[2], ngraph::shape_size(shapes[2]) * sizeof(T));
|
||||
std::memcpy(H_i, inputs[2], shape_size(shapes[2]) * sizeof(T));
|
||||
|
||||
char* C_i = nullptr; // LSTMCell only
|
||||
if ((type == CellType::LSTM) || (type == CellType::LSTM_v1)) {
|
||||
C_i = outputs[2];
|
||||
std::memcpy(C_i, inputs[3], ngraph::shape_size(shapes[3]) * sizeof(T));
|
||||
std::memcpy(C_i, inputs[3], shape_size(shapes[3]) * sizeof(T));
|
||||
}
|
||||
|
||||
for (size_t time_step = 0; time_step < num_splits; ++time_step) {
|
||||
@ -310,11 +310,11 @@ void lstm_sequence(const char* X,
|
||||
} else if (direction == op::RecurrentSequenceDirection::BIDIRECTIONAL) {
|
||||
// Split bidirectional case to forward + reverse passes.
|
||||
// split inputs
|
||||
std::vector<std::vector<char>> H_split(2, std::vector<char>(sizeof(T) * ngraph::shape_size(H_shape) / 2));
|
||||
std::vector<std::vector<char>> C_split(2, std::vector<char>(sizeof(T) * ngraph::shape_size(C_shape) / 2));
|
||||
std::vector<std::vector<char>> W_split(2, std::vector<char>(sizeof(T) * ngraph::shape_size(W_shape) / 2));
|
||||
std::vector<std::vector<char>> R_split(2, std::vector<char>(sizeof(T) * ngraph::shape_size(R_shape) / 2));
|
||||
std::vector<std::vector<char>> B_split(2, std::vector<char>(sizeof(T) * ngraph::shape_size(B_shape) / 2));
|
||||
std::vector<std::vector<char>> H_split(2, std::vector<char>(sizeof(T) * shape_size(H_shape) / 2));
|
||||
std::vector<std::vector<char>> C_split(2, std::vector<char>(sizeof(T) * shape_size(C_shape) / 2));
|
||||
std::vector<std::vector<char>> W_split(2, std::vector<char>(sizeof(T) * shape_size(W_shape) / 2));
|
||||
std::vector<std::vector<char>> R_split(2, std::vector<char>(sizeof(T) * shape_size(R_shape) / 2));
|
||||
std::vector<std::vector<char>> B_split(2, std::vector<char>(sizeof(T) * shape_size(B_shape) / 2));
|
||||
char* h_pointers[2] = {H_split[0].data(), H_split[1].data()};
|
||||
char* c_pointers[2] = {C_split[0].data(), C_split[1].data()};
|
||||
char* w_pointers[2] = {W_split[0].data(), W_split[1].data()};
|
||||
@ -428,12 +428,12 @@ void lstm_sequence_v1(const char* X,
|
||||
} else if (direction == op::RecurrentSequenceDirection::BIDIRECTIONAL) {
|
||||
// Split bidirectional case to forward + reverse passes.
|
||||
// split inputs
|
||||
std::vector<std::vector<char>> H_split(2, std::vector<char>(sizeof(T) * ngraph::shape_size(H_shape) / 2));
|
||||
std::vector<std::vector<char>> C_split(2, std::vector<char>(sizeof(T) * ngraph::shape_size(C_shape) / 2));
|
||||
std::vector<std::vector<char>> W_split(2, std::vector<char>(sizeof(T) * ngraph::shape_size(W_shape) / 2));
|
||||
std::vector<std::vector<char>> R_split(2, std::vector<char>(sizeof(T) * ngraph::shape_size(R_shape) / 2));
|
||||
std::vector<std::vector<char>> B_split(2, std::vector<char>(sizeof(T) * ngraph::shape_size(B_shape) / 2));
|
||||
std::vector<std::vector<char>> P_split(2, std::vector<char>(sizeof(T) * ngraph::shape_size(P_shape) / 2));
|
||||
std::vector<std::vector<char>> H_split(2, std::vector<char>(sizeof(T) * shape_size(H_shape) / 2));
|
||||
std::vector<std::vector<char>> C_split(2, std::vector<char>(sizeof(T) * shape_size(C_shape) / 2));
|
||||
std::vector<std::vector<char>> W_split(2, std::vector<char>(sizeof(T) * shape_size(W_shape) / 2));
|
||||
std::vector<std::vector<char>> R_split(2, std::vector<char>(sizeof(T) * shape_size(R_shape) / 2));
|
||||
std::vector<std::vector<char>> B_split(2, std::vector<char>(sizeof(T) * shape_size(B_shape) / 2));
|
||||
std::vector<std::vector<char>> P_split(2, std::vector<char>(sizeof(T) * shape_size(P_shape) / 2));
|
||||
char* h_pointers[2] = {H_split[0].data(), H_split[1].data()};
|
||||
char* c_pointers[2] = {C_split[0].data(), C_split[1].data()};
|
||||
char* w_pointers[2] = {W_split[0].data(), W_split[1].data()};
|
||||
@ -554,10 +554,10 @@ void gru_sequence(const char* X,
|
||||
} else if (direction == op::RecurrentSequenceDirection::BIDIRECTIONAL) {
|
||||
// Split bidirectional case to forward + reverse passes.
|
||||
// split inputs
|
||||
std::vector<std::vector<char>> H_split(2, std::vector<char>(sizeof(T) * ngraph::shape_size(H_shape) / 2));
|
||||
std::vector<std::vector<char>> W_split(2, std::vector<char>(sizeof(T) * ngraph::shape_size(W_shape) / 2));
|
||||
std::vector<std::vector<char>> R_split(2, std::vector<char>(sizeof(T) * ngraph::shape_size(R_shape) / 2));
|
||||
std::vector<std::vector<char>> B_split(2, std::vector<char>(sizeof(T) * ngraph::shape_size(B_shape) / 2));
|
||||
std::vector<std::vector<char>> H_split(2, std::vector<char>(sizeof(T) * shape_size(H_shape) / 2));
|
||||
std::vector<std::vector<char>> W_split(2, std::vector<char>(sizeof(T) * shape_size(W_shape) / 2));
|
||||
std::vector<std::vector<char>> R_split(2, std::vector<char>(sizeof(T) * shape_size(R_shape) / 2));
|
||||
std::vector<std::vector<char>> B_split(2, std::vector<char>(sizeof(T) * shape_size(B_shape) / 2));
|
||||
char* h_pointers[2] = {H_split[0].data(), H_split[1].data()};
|
||||
char* w_pointers[2] = {W_split[0].data(), W_split[1].data()};
|
||||
char* r_pointers[2] = {R_split[0].data(), R_split[1].data()};
|
||||
@ -645,10 +645,10 @@ void rnn_sequence(const char* X,
|
||||
} else if (direction == op::RecurrentSequenceDirection::BIDIRECTIONAL) {
|
||||
// Split bidirectional case to forward + reverse passes.
|
||||
// split inputs
|
||||
std::vector<std::vector<char>> H_split(2, std::vector<char>(sizeof(T) * ngraph::shape_size(H_shape) / 2));
|
||||
std::vector<std::vector<char>> W_split(2, std::vector<char>(sizeof(T) * ngraph::shape_size(W_shape) / 2));
|
||||
std::vector<std::vector<char>> R_split(2, std::vector<char>(sizeof(T) * ngraph::shape_size(R_shape) / 2));
|
||||
std::vector<std::vector<char>> B_split(2, std::vector<char>(sizeof(T) * ngraph::shape_size(B_shape) / 2));
|
||||
std::vector<std::vector<char>> H_split(2, std::vector<char>(sizeof(T) * shape_size(H_shape) / 2));
|
||||
std::vector<std::vector<char>> W_split(2, std::vector<char>(sizeof(T) * shape_size(W_shape) / 2));
|
||||
std::vector<std::vector<char>> R_split(2, std::vector<char>(sizeof(T) * shape_size(R_shape) / 2));
|
||||
std::vector<std::vector<char>> B_split(2, std::vector<char>(sizeof(T) * shape_size(B_shape) / 2));
|
||||
char* h_pointers[2] = {H_split[0].data(), H_split[1].data()};
|
||||
char* w_pointers[2] = {W_split[0].data(), W_split[1].data()};
|
||||
char* r_pointers[2] = {R_split[0].data(), R_split[1].data()};
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ngraph/type/element_type.hpp"
|
||||
#include "openvino/core/type/element_type.hpp"
|
||||
#include "openvino/reference/utils/coordinate_transform.hpp"
|
||||
|
||||
namespace ov {
|
||||
|
@ -6,39 +6,39 @@
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "ngraph/shape_util.hpp"
|
||||
#include "openvino/core/shape_util.hpp"
|
||||
#include "openvino/reference/reduce_max.hpp"
|
||||
#include "openvino/reference/reduce_sum.hpp"
|
||||
#include "openvino/reference/utils/coordinate_index.hpp"
|
||||
#include "openvino/reference/utils/coordinate_transform.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
template <typename T>
|
||||
void softmax(const T* arg, T* out, const Shape& shape, const AxisSet& axes) {
|
||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
||||
auto temp_shape = ngraph::reduce(shape, axes, true);
|
||||
auto temp_elements = shape_size(temp_shape);
|
||||
auto temp_ptr = new T[temp_elements];
|
||||
const auto temp_shape = util::reduce_keep_dims(shape, axes);
|
||||
const auto temp_elements = shape_size(temp_shape);
|
||||
auto temp_storage = std::vector<T>(temp_elements);
|
||||
const auto temp_ptr = temp_storage.data();
|
||||
|
||||
reduce_max(arg, temp_ptr, shape, axes);
|
||||
|
||||
CoordinateTransform transform(shape);
|
||||
CoordinateTransform temp_transform(temp_shape);
|
||||
for (const Coordinate& coord : transform) {
|
||||
Coordinate temp_coord = ngraph::reduce(coord, axes, true);
|
||||
out[transform.index(coord)] =
|
||||
std::exp(arg[transform.index(coord)] - temp_ptr[temp_transform.index(temp_coord)]);
|
||||
const CoordinateTransformBasic transform{shape};
|
||||
for (const auto& coord : transform) {
|
||||
const Coordinate temp_coord = util::reduce_keep_dims(coord, axes);
|
||||
const auto out_index = coordinate_index(coord, shape);
|
||||
const auto temp_index = coordinate_index(temp_coord, temp_shape);
|
||||
out[out_index] = std::exp(arg[out_index] - temp_ptr[temp_index]);
|
||||
}
|
||||
|
||||
reduce_sum(out, temp_ptr, shape, axes);
|
||||
|
||||
for (const Coordinate& coord : transform) {
|
||||
Coordinate temp_coord = ngraph::reduce(coord, axes, true);
|
||||
out[transform.index(coord)] /= temp_ptr[temp_transform.index(temp_coord)];
|
||||
for (const auto& coord : transform) {
|
||||
const Coordinate temp_coord = util::reduce_keep_dims(coord, axes);
|
||||
const auto out_index = coordinate_index(coord, shape);
|
||||
const auto temp_index = coordinate_index(temp_coord, temp_shape);
|
||||
out[out_index] /= temp_ptr[temp_index];
|
||||
}
|
||||
|
||||
delete[] temp_ptr;
|
||||
NGRAPH_SUPPRESS_DEPRECATED_END
|
||||
}
|
||||
} // namespace reference
|
||||
} // namespace ov
|
||||
|
@ -4,8 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ngraph/op/space_to_depth.hpp"
|
||||
#include "ngraph/shape.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/op/space_to_depth.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
|
||||
#include "ngraph/shape_util.hpp"
|
||||
#include "openvino/reference/autobroadcast_binop.hpp"
|
||||
|
||||
namespace ov {
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
|
||||
#include "openvino/core/shape.hpp"
|
||||
#include "openvino/op/util/attr_types.hpp"
|
||||
#include "openvino/reference/autobroadcast_binop.hpp"
|
||||
|
||||
namespace ov {
|
||||
|
@ -4,10 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "ngraph/type/element_type.hpp"
|
||||
#include "openvino/reference/utils/coordinate_transform.hpp"
|
||||
#include "openvino/core/shape.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace reference {
|
||||
|
@ -8,7 +8,8 @@
|
||||
#include <cmath>
|
||||
#include <numeric>
|
||||
|
||||
#include "ngraph/op/topk.hpp"
|
||||
#include "openvino/op/topk.hpp"
|
||||
#include "openvino/reference/utils/coordinate_index.hpp"
|
||||
#include "openvino/reference/utils/coordinate_transform.hpp"
|
||||
|
||||
namespace ov {
|
||||
@ -51,30 +52,21 @@ void topk(const T* arg,
|
||||
size_t k,
|
||||
bool compute_max,
|
||||
op::TopKSortType sort = op::TopKSortType::NONE) {
|
||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
||||
using namespace std;
|
||||
// reorder source axis visit order and make "axis" inner most
|
||||
size_t ndim = static_cast<size_t>(in_shape.size());
|
||||
Coordinate start_corner(ndim, 0);
|
||||
Coordinate end_corner(in_shape);
|
||||
end_corner[axis] = 1;
|
||||
Strides strides(ndim, 1);
|
||||
AxisVector axis_order(ndim);
|
||||
iota(axis_order.begin(), axis_order.end(), 0);
|
||||
axis_order.erase(axis_order.begin() + axis);
|
||||
axis_order.push_back(axis);
|
||||
// Create CoordinateTransforms that visits only the first element along "axis"
|
||||
CoordinateTransform input_transform(in_shape, start_corner, end_corner, strides, axis_order);
|
||||
CoordinateTransform output_transform(out_shape, start_corner, end_corner, strides, axis_order);
|
||||
// Create temp vector for sorting.
|
||||
vector<tuple<T, U>> workspace(in_shape[axis]);
|
||||
vector<size_t> in_strides = ngraph::row_major_strides(in_shape);
|
||||
vector<size_t> out_strides = ngraph::row_major_strides(out_shape);
|
||||
vector<size_t> in_strides = row_major_strides(in_shape);
|
||||
vector<size_t> out_strides = row_major_strides(out_shape);
|
||||
auto in_axis_stride = in_strides[axis];
|
||||
auto out_axis_stride = out_strides[axis];
|
||||
for (const Coordinate& coord : input_transform) {
|
||||
auto arg_index = input_transform.index(coord);
|
||||
auto out_index = output_transform.index(coord);
|
||||
|
||||
// Iterate over elements with 0 index at "axis" dimension
|
||||
auto traverse_shape = in_shape;
|
||||
traverse_shape[axis] = 1;
|
||||
CoordinateTransformBasic traverse_transform(traverse_shape);
|
||||
for (const Coordinate& coord : traverse_transform) {
|
||||
auto arg_index = coordinate_index(coord, in_shape);
|
||||
auto out_index = coordinate_index(coord, out_shape);
|
||||
// Fill the temp vector
|
||||
U i = 0;
|
||||
for (tuple<T, U>& entry : workspace) {
|
||||
@ -109,7 +101,6 @@ void topk(const T* arg,
|
||||
out_index += out_axis_stride;
|
||||
}
|
||||
}
|
||||
NGRAPH_SUPPRESS_DEPRECATED_END
|
||||
}
|
||||
} // namespace reference
|
||||
} // namespace ov
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user