[Ref_Impl] Rename file paths to openvino relative (#19284)

* Move files to new directories

* Use quotes for openvino includes

* Provide proxy calls for transition

of dependant components.

* Correct includes style

* Redo proxies

* Fix deprecated

* Move aliases to proxy files

* Apply code style
This commit is contained in:
Tomasz Jankowski 2023-08-25 04:43:06 +02:00 committed by GitHub
parent 20e4c629e9
commit bcad953f5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
421 changed files with 929 additions and 832 deletions

View File

@ -4,8 +4,8 @@
#include "snippets/op/broadcastload.hpp"
#include "openvino/reference/broadcast.hpp"
#include "snippets/itt.hpp"
#include <ngraph/runtime/reference/broadcast.hpp>
namespace ov {
namespace snippets {

View File

@ -3,20 +3,20 @@
//
#include "snippets/pass/fq_decomposition.hpp"
#include "snippets/op/convert_saturation.hpp"
#include "snippets/itt.hpp"
#include "openvino/opsets/opset1.hpp"
#include "openvino/pass/pattern/op/wrap_type.hpp"
#include "openvino/core/rt_info.hpp"
#include "openvino/pass/constant_folding.hpp"
#include "openvino/pass/validate.hpp"
#include "openvino/pass/manager.hpp"
#include <ngraph/runtime/reference/autobroadcast_binop.hpp>
#include <ngraph/runtime/reference/broadcast.hpp>
#include <numeric>
#include "ngraph/runtime/reference/autobroadcast_binop.hpp"
#include "openvino/core/rt_info.hpp"
#include "openvino/opsets/opset1.hpp"
#include "openvino/pass/constant_folding.hpp"
#include "openvino/pass/manager.hpp"
#include "openvino/pass/pattern/op/wrap_type.hpp"
#include "openvino/pass/validate.hpp"
#include "openvino/reference/broadcast.hpp"
#include "snippets/itt.hpp"
#include "snippets/op/convert_saturation.hpp"
namespace {
bool isValidRangesInputs(const std::shared_ptr<ov::opset1::FakeQuantize>& fq) {
auto il = fq->input_value(1);

View File

@ -5,12 +5,12 @@
#include "transformations/common_optimizations/compress_float_constants.hpp"
#include "itt.hpp"
#include "ngraph/runtime/reference/convert.hpp"
#include "openvino/core/rt_info.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/convert.hpp"
#include "openvino/op/parameter.hpp"
#include "openvino/pass/pattern/op/wrap_type.hpp"
#include "openvino/reference/convert.hpp"
#include "transformations/rt_info/decompression.hpp"
#include "transformations/rt_info/disable_fp16_compression.hpp"
#include "transformations/rt_info/old_api_map_element_type_attribute.hpp"

View File

@ -8,7 +8,6 @@
#include <vector>
#include "itt.hpp"
#include "ngraph/runtime/reference/convert.hpp"
#include "openvino/opsets/opset1.hpp"
#include "openvino/opsets/opset10.hpp"
#include "openvino/opsets/opset11.hpp"
@ -20,6 +19,7 @@
#include "openvino/opsets/opset9.hpp"
#include "openvino/pass/constant_folding.hpp"
#include "openvino/pass/manager.hpp"
#include "openvino/reference/convert.hpp"
#include "ov_ops/type_relaxed.hpp"
#include "transformations/fp16_compression/align_mixed_fp32_fp16_types.hpp"
#include "transformations/fp16_compression/mark_decompression_convert_constant_folding.hpp"

View File

@ -4,91 +4,12 @@
#pragma once
#include <cstddef>
#include <numeric>
#include <utility>
#include "ngraph/coordinate_transform.hpp"
#include "ngraph/op/util/attr_types.hpp"
#include "ngraph/shape_util.hpp"
#include "openvino/reference/autobroadcast_binop.hpp"
// Proxy calls for dependant components transition to ov::reference namespace
namespace ngraph {
namespace runtime {
namespace reference {
namespace internal {
inline void row_major_strides(const Shape& shape, size_t* strides, size_t size) noexcept {
size_t* st = strides + size - 1;
size_t s = 1;
for (auto d = shape.rbegin(); d != shape.rend(); d++) {
*st-- = s;
s *= *d;
}
std::fill(strides, st + 1, s);
}
template <typename C, typename T>
inline T value_with_padding_or(const C& arr, size_t padding, size_t idx, T&& default_value) {
return idx < padding ? std::forward<T>(default_value) : static_cast<T>(arr[idx - padding]);
}
template <int A0, int A1, typename T, typename U, typename Functor>
inline void numpy_autobroadcast_binop(const T* arg0,
const T* arg1,
U* out,
const Shape& shape0,
const Shape& shape1,
const size_t* strides0,
const size_t* strides1,
const size_t padding0,
const size_t padding1,
const Shape& output_shape,
const size_t axis,
const size_t stride,
Functor elementwise_functor) {
for (CoordinateIterator it(output_shape), ite = CoordinateIterator::end();;) {
for (size_t i = 0; i < stride; ++i)
*out++ = elementwise_functor(arg0[i * A0], arg1[i * A1]);
arg0 += A0 ? stride : 1;
arg1 += A1 ? stride : 1;
auto p = it.advance(axis);
if (it == ite)
break;
if (value_with_padding_or(shape0, padding0, p, 1) == 1)
arg0 -= strides0[p];
if (value_with_padding_or(shape1, padding1, p, 1) == 1)
arg1 -= strides1[p];
}
}
inline size_t calculate_fixed_axis(size_t axis, const size_t* strides) {
while (axis > 0 && strides[axis - 1] == 1)
--axis;
return axis;
}
} // namespace internal
/// \brief Helper function to implement autobroadcasting elementwise binop references.
///
/// \tparam T Element type of the input tensors.
/// \tparam U Element type of the output tensor.
/// \tparam Functor Type of the functor for the elementwise operation. Must support
/// operator()(T,T), and operator()(T,T) must return a value of type
/// U.
///
/// \param arg0 Pointer to the buffer for left operand input tensor.
/// \param arg1 Pointer to the buffer for right operand input tensor.
/// \param out Pointer to the buffer for output tensor. This must be pre-allocated by
/// the caller, and must be large enough to hold a tensor of the correct
/// shape.
/// \param broadcast_spec Specification of the auto-broadcasting scheme.
/// \param elementwise_functor Functor implementing the elementwise operation to be
/// applied across the input tensors. Must accept two
/// arguments of type T, and return a value of type U.
template <typename T, typename U, typename Functor>
void autobroadcast_binop(const T* arg0,
const T* arg1,
@ -97,208 +18,9 @@ void autobroadcast_binop(const T* arg0,
const Shape& arg1_shape,
const op::AutoBroadcastSpec& broadcast_spec,
Functor elementwise_functor) {
switch (broadcast_spec.m_type) {
case op::AutoBroadcastType::NONE:
for (size_t i = 0; i < shape_size(arg0_shape); i++) {
out[i] = static_cast<U>(elementwise_functor(arg0[i], arg1[i]));
}
break;
case op::AutoBroadcastType::NUMPY:
// We'll be using CoordinateTransform 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
// shape. The "broadcasted axes" will be those that were squeezed in step
// 2.
//
// Example:
//
// Input shape->Padded shape->Squeezed Shape/Squeezed Axes
// ----------- ------------ ----------------------------
// a: [ 3, 2, 1] [ 3, 2, 1] [ 3, 2 ] {2}
// b: [ 1, 6] [ 1, 1, 6] [ 6] {0,1}
// | | |
// v v v
// Output shape
// ------------
// [ 3, 2, 6]
{
using namespace internal;
size_t const shape_rank = std::max(arg0_shape.size(), arg1_shape.size()) + 1;
// TODO: Use compiler-specific alloca() or variable-length array
std::vector<size_t> tmp(shape_rank * 2);
size_t* strides0 = tmp.data();
size_t* strides1 = tmp.data() + shape_rank;
row_major_strides(arg0_shape, strides0, shape_rank);
row_major_strides(arg1_shape, strides1, shape_rank);
size_t const padding0 = shape_rank - arg0_shape.size();
size_t const padding1 = shape_rank - arg1_shape.size();
Shape output_shape(shape_rank, 0);
size_t axis = 0;
for (size_t i = 0; i < shape_rank; i++) {
auto const dim0 = value_with_padding_or(arg0_shape, padding0, i, 1);
auto const dim1 = value_with_padding_or(arg1_shape, padding1, i, 1);
output_shape[i] = std::max(dim0, dim1);
if (dim0 != dim1)
axis = std::max(axis, i);
}
if (axis == 0) {
for (size_t i = 0, end = strides0[0]; i < end; ++i)
out[i] = elementwise_functor(arg0[i], arg1[i]);
} else if (strides0[axis] == 1 && value_with_padding_or(arg0_shape, padding0, axis, 1) == 1) {
axis = calculate_fixed_axis(axis, strides0);
numpy_autobroadcast_binop<0, 1>(arg0,
arg1,
out,
arg0_shape,
arg1_shape,
strides0,
strides1,
padding0,
padding1,
output_shape,
axis,
strides1[axis],
elementwise_functor);
} else if (strides1[axis] == 1 && value_with_padding_or(arg1_shape, padding1, axis, 1) == 1) {
axis = calculate_fixed_axis(axis, strides1);
numpy_autobroadcast_binop<1, 0>(arg0,
arg1,
out,
arg0_shape,
arg1_shape,
strides0,
strides1,
padding0,
padding1,
output_shape,
axis,
strides0[axis],
elementwise_functor);
} else
numpy_autobroadcast_binop<1, 1>(arg0,
arg1,
out,
arg0_shape,
arg1_shape,
strides0,
strides1,
padding0,
padding1,
output_shape,
axis,
strides0[axis],
elementwise_functor);
}
break;
case op::AutoBroadcastType::PDPD:
// We'll be using CoordinateTransform 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:
//
// (1) Trim trailing ones from arg1 shape.
// (2) Left and right pad arg1 to match arg0 shape. Axis is the index start
// 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
// shape. The "broadcasted axes" will be those that were squeezed in step
// 23.
//
// Example:
//
// Input shape-> Padded shape-> Squeezed Shape/Squeezed Axes
// ----------- ------------ ----------------------------
// a: [ 3, 4, 5, 6] [ 3, 4, 5, 6] [ 3, 4, 5, 6]
// b: [ 4, 5, ] [ 1, 4, 5, 1] [ 4, 5 ] {0,3}
// | | |
// v v v
// Output shape
// ------------
// [ 3, 4, 5, 6]
{
int64_t axis = broadcast_spec.m_axis;
if (axis == -1) {
axis = arg0_shape.size() - arg1_shape.size();
}
Shape arg1_padded_shape = arg1_shape;
// Trim trailing ones
while (arg1_padded_shape.size() > 0 && arg1_padded_shape.back() == 1) {
arg1_padded_shape.pop_back();
}
for (int64_t i = 0; i < axis; ++i) {
arg1_padded_shape.insert(arg1_padded_shape.begin(), 1);
}
while (arg1_padded_shape.size() < arg0_shape.size()) {
arg1_padded_shape.insert(arg1_padded_shape.end(), 1);
}
Shape arg1_squeezed_shape;
AxisSet arg1_squeezed_axes;
for (size_t i = 0; i < arg0_shape.size(); i++) {
if (arg1_padded_shape[i] == 1) {
arg1_squeezed_axes.insert(i);
} else {
arg1_squeezed_shape.push_back(arg1_padded_shape[i]);
}
}
NGRAPH_SUPPRESS_DEPRECATED_START
CoordinateTransform arg0_transform(arg0_shape);
CoordinateTransform arg1_transform(arg1_squeezed_shape);
CoordinateTransform output_transform(arg0_shape);
for (const Coordinate& output_coord : output_transform) {
Coordinate arg1_coord = 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)]);
}
NGRAPH_SUPPRESS_DEPRECATED_END
}
}
ov::reference::autobroadcast_binop(arg0, arg1, out, arg0_shape, arg1_shape, broadcast_spec, elementwise_functor);
}
/// \brief Helper function to implement autobroadcasting elementwise ternaryop
/// references.
///
/// \tparam U Element type of the selector tensor.
/// \tparam T Element type of the input tensors.
/// \tparam Functor Type of the functor for the elementwise operation. Must support
/// operator()(U,T,T), and operator()(U,T,T) must return a value of type
/// T.
///
/// \param arg0 Pointer to the buffer for selector tensor.
/// \param arg1 Pointer to the buffer for left operand input tensor.
/// \param arg2 Pointer to the buffer for right operand input tensor.
/// \param out Pointer to the buffer for output tensor. This must be pre-allocated by
/// the caller, and must be large enough to hold a tensor of the correct
/// shape.
/// \param broadcast_spec Specification of the auto-broadcasting scheme.
/// \param elementwise_functor Functor implementing the elementwise operation to be
/// applied across the input tensors. Must accept an argument
/// of
/// type U and two of type T, and return a value of type T.
template <typename T, typename U, typename Functor>
void autobroadcast_select(const U* arg0,
const T* arg1,
@ -309,172 +31,15 @@ void autobroadcast_select(const U* arg0,
const Shape& arg2_shape,
const op::AutoBroadcastSpec& broadcast_spec,
Functor elementwise_functor) {
switch (broadcast_spec.m_type) {
case op::AutoBroadcastType::NONE:
for (size_t i = 0; i < shape_size(arg0_shape); i++) {
out[i] = elementwise_functor(arg0[i], arg1[i], arg2[i]);
}
break;
case op::AutoBroadcastType::NUMPY:
// Uses same approach as autobroadcast_binop.
{
Shape arg0_padded_shape = arg0_shape;
Shape arg1_padded_shape = arg1_shape;
Shape arg2_padded_shape = arg2_shape;
size_t max_shape_size =
std::max({arg0_padded_shape.size(), arg1_padded_shape.size(), arg2_padded_shape.size()});
while (arg0_padded_shape.size() < max_shape_size) {
arg0_padded_shape.insert(arg0_padded_shape.begin(), 1);
}
while (arg1_padded_shape.size() < max_shape_size) {
arg1_padded_shape.insert(arg1_padded_shape.begin(), 1);
}
while (arg2_padded_shape.size() < max_shape_size) {
arg2_padded_shape.insert(arg2_padded_shape.begin(), 1);
}
Shape arg0_squeezed_shape;
Shape arg1_squeezed_shape;
Shape arg2_squeezed_shape;
AxisSet arg0_squeezed_axes;
AxisSet arg1_squeezed_axes;
AxisSet arg2_squeezed_axes;
Shape output_shape;
for (size_t i = 0; i < max_shape_size; i++) {
if (arg1_padded_shape[i] == 1) {
arg1_squeezed_axes.insert(i);
} else {
arg1_squeezed_shape.push_back(arg1_padded_shape[i]);
}
if (arg2_padded_shape[i] == 1) {
arg2_squeezed_axes.insert(i);
} else {
arg2_squeezed_shape.push_back(arg2_padded_shape[i]);
}
if (arg0_padded_shape[i] == 1) {
arg0_squeezed_axes.insert(i);
} else {
arg0_squeezed_shape.push_back(arg0_padded_shape[i]);
}
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 auto arg0_strides = row_major_strides(arg0_squeezed_shape);
const auto arg1_strides = row_major_strides(arg1_squeezed_shape);
const auto arg2_strides = row_major_strides(arg2_squeezed_shape);
const auto output_strides = row_major_strides(output_shape);
for (const Coordinate& output_coord : output_transform) {
NGRAPH_SUPPRESS_DEPRECATED_START
const Coordinate arg0_coord = reduce(output_coord, arg0_squeezed_axes, false);
const Coordinate arg1_coord = reduce(output_coord, arg1_squeezed_axes, false);
const Coordinate arg2_coord = reduce(output_coord, arg2_squeezed_axes, false);
NGRAPH_SUPPRESS_DEPRECATED_END
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));
out[output_idx] = elementwise_functor(arg0[arg0_idx], arg1[arg1_idx], arg2[arg2_idx]);
}
}
break;
case op::AutoBroadcastType::PDPD: {
// arg0 and arg2 are broadcast to arg1 shape
int64_t axis = broadcast_spec.m_axis;
if (axis == -1) {
axis = arg1_shape.size() - arg2_shape.size();
}
Shape arg0_padded_shape = arg0_shape;
Shape arg2_padded_shape = arg2_shape;
// Trim trailing ones
while (arg0_padded_shape.size() > 0 && arg0_padded_shape.back() == 1) {
arg0_padded_shape.pop_back();
}
for (int64_t i = 0; (i < axis) && (arg0_padded_shape.size() < arg1_shape.size()); ++i) {
arg0_padded_shape.insert(arg0_padded_shape.begin(), 1);
}
while (arg0_padded_shape.size() < arg1_shape.size()) {
arg0_padded_shape.insert(arg0_padded_shape.end(), 1);
}
while (arg2_padded_shape.size() > 0 && arg2_padded_shape.back() == 1) {
arg2_padded_shape.pop_back();
}
for (int64_t i = 0; (i < axis) && (arg2_padded_shape.size() < arg1_shape.size()); ++i) {
arg2_padded_shape.insert(arg2_padded_shape.begin(), 1);
}
while (arg2_padded_shape.size() < arg1_shape.size()) {
arg2_padded_shape.insert(arg2_padded_shape.end(), 1);
}
Shape arg0_squeezed_shape;
AxisSet arg0_squeezed_axes;
Shape arg2_squeezed_shape;
AxisSet arg2_squeezed_axes;
for (size_t i = 0; i < arg1_shape.size(); i++) {
if (arg0_padded_shape[i] == 1) {
arg0_squeezed_axes.insert(i);
} else {
arg0_squeezed_shape.push_back(arg0_padded_shape[i]);
}
if (arg2_padded_shape[i] == 1) {
arg2_squeezed_axes.insert(i);
} else {
arg2_squeezed_shape.push_back(arg2_padded_shape[i]);
}
}
CoordinateTransformBasic arg0_transform(arg0_squeezed_shape);
CoordinateTransformBasic arg1_transform(arg1_shape);
CoordinateTransformBasic arg2_transform(arg2_squeezed_shape);
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 = reduce(output_coord, arg0_squeezed_axes, false);
const Coordinate arg2_coord = reduce(output_coord, arg2_squeezed_axes, false);
NGRAPH_SUPPRESS_DEPRECATED_END
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));
out[output_idx] = elementwise_functor(arg0[arg0_idx], arg1[arg1_idx], arg2[arg2_idx]);
}
}
}
ov::reference::autobroadcast_select(arg0,
arg1,
arg2,
out,
arg0_shape,
arg1_shape,
arg2_shape,
broadcast_spec,
elementwise_functor);
}
} // namespace reference
} // namespace runtime

View File

@ -4,21 +4,16 @@
#pragma once
#include <cmath>
#include <cstddef>
#include "ngraph/op/util/attr_types.hpp"
#include "ngraph/runtime/reference/autobroadcast_binop.hpp"
#include "ngraph/shape.hpp"
#include "openvino/reference/power.hpp"
// Proxy calls for dependant components transition to ov::reference namespace
namespace ngraph {
namespace runtime {
namespace reference {
template <typename T>
void power(const T* arg0, const T* arg1, T* out, size_t count) {
for (size_t i = 0; i < count; i++) {
out[i] = static_cast<T>(std::pow(arg0[i], arg1[i]));
}
ov::reference::power(arg0, arg1, out, count);
}
template <typename T>
@ -28,10 +23,9 @@ void power(const T* arg0,
const Shape& arg0_shape,
const Shape& arg1_shape,
const op::AutoBroadcastSpec& broadcast_spec) {
autobroadcast_binop(arg0, arg1, out, arg0_shape, arg1_shape, broadcast_spec, [](T x, T y) -> T {
return static_cast<T>(std::pow(x, y));
});
ov::reference::power(arg0, arg1, out, arg0_shape, arg1_shape, broadcast_spec);
}
} // namespace reference
} // namespace runtime
} // namespace ngraph

View File

@ -4,42 +4,15 @@
#pragma once
#include <cmath>
#include "ngraph/coordinate_transform.hpp"
#include "ngraph/runtime/reference/max.hpp"
#include "ngraph/runtime/reference/sum.hpp"
#include "ngraph/shape_util.hpp"
#include "openvino/reference/softmax.hpp"
// Proxy call for dependant components transition to ov::reference namespace
namespace ngraph {
namespace runtime {
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 = reduce(shape, axes, true);
auto temp_elements = shape_size(temp_shape);
auto temp_ptr = new T[temp_elements];
max(arg, temp_ptr, shape, axes);
CoordinateTransform transform(shape);
CoordinateTransform temp_transform(temp_shape);
for (const Coordinate& coord : transform) {
Coordinate temp_coord = reduce(coord, axes, true);
out[transform.index(coord)] =
std::exp(arg[transform.index(coord)] - temp_ptr[temp_transform.index(temp_coord)]);
}
sum(out, temp_ptr, shape, axes);
for (const Coordinate& coord : transform) {
Coordinate temp_coord = reduce(coord, axes, true);
out[transform.index(coord)] /= temp_ptr[temp_transform.index(temp_coord)];
}
delete[] temp_ptr;
NGRAPH_SUPPRESS_DEPRECATED_END
ov::reference::softmax(arg, out, shape, axes);
}
} // namespace reference
} // namespace runtime

View File

@ -0,0 +1,482 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <cstddef>
#include <numeric>
#include <utility>
#include "ngraph/coordinate_transform.hpp"
#include "ngraph/op/util/attr_types.hpp"
#include "ngraph/shape_util.hpp"
namespace ov {
namespace reference {
namespace internal {
inline void row_major_strides(const Shape& shape, size_t* strides, size_t size) noexcept {
size_t* st = strides + size - 1;
size_t s = 1;
for (auto d = shape.rbegin(); d != shape.rend(); d++) {
*st-- = s;
s *= *d;
}
std::fill(strides, st + 1, s);
}
template <typename C, typename T>
inline T value_with_padding_or(const C& arr, size_t padding, size_t idx, T&& default_value) {
return idx < padding ? std::forward<T>(default_value) : static_cast<T>(arr[idx - padding]);
}
template <int A0, int A1, typename T, typename U, typename Functor>
inline void numpy_autobroadcast_binop(const T* arg0,
const T* arg1,
U* out,
const Shape& shape0,
const Shape& shape1,
const size_t* strides0,
const size_t* strides1,
const size_t padding0,
const size_t padding1,
const Shape& output_shape,
const size_t axis,
const size_t stride,
Functor elementwise_functor) {
using ngraph::CoordinateIterator;
for (CoordinateIterator it(output_shape), ite = CoordinateIterator::end();;) {
for (size_t i = 0; i < stride; ++i)
*out++ = elementwise_functor(arg0[i * A0], arg1[i * A1]);
arg0 += A0 ? stride : 1;
arg1 += A1 ? stride : 1;
auto p = it.advance(axis);
if (it == ite)
break;
if (value_with_padding_or(shape0, padding0, p, 1) == 1)
arg0 -= strides0[p];
if (value_with_padding_or(shape1, padding1, p, 1) == 1)
arg1 -= strides1[p];
}
}
inline size_t calculate_fixed_axis(size_t axis, const size_t* strides) {
while (axis > 0 && strides[axis - 1] == 1)
--axis;
return axis;
}
} // namespace internal
/// \brief Helper function to implement autobroadcasting elementwise binop references.
///
/// \tparam T Element type of the input tensors.
/// \tparam U Element type of the output tensor.
/// \tparam Functor Type of the functor for the elementwise operation. Must support
/// operator()(T,T), and operator()(T,T) must return a value of type
/// U.
///
/// \param arg0 Pointer to the buffer for left operand input tensor.
/// \param arg1 Pointer to the buffer for right operand input tensor.
/// \param out Pointer to the buffer for output tensor. This must be pre-allocated by
/// the caller, and must be large enough to hold a tensor of the correct
/// shape.
/// \param broadcast_spec Specification of the auto-broadcasting scheme.
/// \param elementwise_functor Functor implementing the elementwise operation to be
/// applied across the input tensors. Must accept two
/// arguments of type T, and return a value of type U.
template <typename T, typename U, typename Functor>
void autobroadcast_binop(const T* arg0,
const T* arg1,
U* out,
const Shape& arg0_shape,
const Shape& arg1_shape,
const op::AutoBroadcastSpec& broadcast_spec,
Functor elementwise_functor) {
switch (broadcast_spec.m_type) {
case op::AutoBroadcastType::NONE:
for (size_t i = 0; i < shape_size(arg0_shape); i++) {
out[i] = static_cast<U>(elementwise_functor(arg0[i], arg1[i]));
}
break;
case op::AutoBroadcastType::NUMPY:
// We'll be using CoordinateTransform 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
// shape. The "broadcasted axes" will be those that were squeezed in step
// 2.
//
// Example:
//
// Input shape->Padded shape->Squeezed Shape/Squeezed Axes
// ----------- ------------ ----------------------------
// a: [ 3, 2, 1] [ 3, 2, 1] [ 3, 2 ] {2}
// b: [ 1, 6] [ 1, 1, 6] [ 6] {0,1}
// | | |
// v v v
// Output shape
// ------------
// [ 3, 2, 6]
{
using namespace internal;
size_t const shape_rank = std::max(arg0_shape.size(), arg1_shape.size()) + 1;
// TODO: Use compiler-specific alloca() or variable-length array
std::vector<size_t> tmp(shape_rank * 2);
size_t* strides0 = tmp.data();
size_t* strides1 = tmp.data() + shape_rank;
row_major_strides(arg0_shape, strides0, shape_rank);
row_major_strides(arg1_shape, strides1, shape_rank);
size_t const padding0 = shape_rank - arg0_shape.size();
size_t const padding1 = shape_rank - arg1_shape.size();
Shape output_shape(shape_rank, 0);
size_t axis = 0;
for (size_t i = 0; i < shape_rank; i++) {
auto const dim0 = value_with_padding_or(arg0_shape, padding0, i, 1);
auto const dim1 = value_with_padding_or(arg1_shape, padding1, i, 1);
output_shape[i] = std::max(dim0, dim1);
if (dim0 != dim1)
axis = std::max(axis, i);
}
if (axis == 0) {
for (size_t i = 0, end = strides0[0]; i < end; ++i)
out[i] = elementwise_functor(arg0[i], arg1[i]);
} else if (strides0[axis] == 1 && value_with_padding_or(arg0_shape, padding0, axis, 1) == 1) {
axis = calculate_fixed_axis(axis, strides0);
numpy_autobroadcast_binop<0, 1>(arg0,
arg1,
out,
arg0_shape,
arg1_shape,
strides0,
strides1,
padding0,
padding1,
output_shape,
axis,
strides1[axis],
elementwise_functor);
} else if (strides1[axis] == 1 && value_with_padding_or(arg1_shape, padding1, axis, 1) == 1) {
axis = calculate_fixed_axis(axis, strides1);
numpy_autobroadcast_binop<1, 0>(arg0,
arg1,
out,
arg0_shape,
arg1_shape,
strides0,
strides1,
padding0,
padding1,
output_shape,
axis,
strides0[axis],
elementwise_functor);
} else
numpy_autobroadcast_binop<1, 1>(arg0,
arg1,
out,
arg0_shape,
arg1_shape,
strides0,
strides1,
padding0,
padding1,
output_shape,
axis,
strides0[axis],
elementwise_functor);
}
break;
case op::AutoBroadcastType::PDPD:
// We'll be using CoordinateTransform 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:
//
// (1) Trim trailing ones from arg1 shape.
// (2) Left and right pad arg1 to match arg0 shape. Axis is the index start
// 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
// shape. The "broadcasted axes" will be those that were squeezed in step
// 23.
//
// Example:
//
// Input shape-> Padded shape-> Squeezed Shape/Squeezed Axes
// ----------- ------------ ----------------------------
// a: [ 3, 4, 5, 6] [ 3, 4, 5, 6] [ 3, 4, 5, 6]
// b: [ 4, 5, ] [ 1, 4, 5, 1] [ 4, 5 ] {0,3}
// | | |
// v v v
// Output shape
// ------------
// [ 3, 4, 5, 6]
{
int64_t axis = broadcast_spec.m_axis;
if (axis == -1) {
axis = arg0_shape.size() - arg1_shape.size();
}
Shape arg1_padded_shape = arg1_shape;
// Trim trailing ones
while (arg1_padded_shape.size() > 0 && arg1_padded_shape.back() == 1) {
arg1_padded_shape.pop_back();
}
for (int64_t i = 0; i < axis; ++i) {
arg1_padded_shape.insert(arg1_padded_shape.begin(), 1);
}
while (arg1_padded_shape.size() < arg0_shape.size()) {
arg1_padded_shape.insert(arg1_padded_shape.end(), 1);
}
Shape arg1_squeezed_shape;
AxisSet arg1_squeezed_axes;
for (size_t i = 0; i < arg0_shape.size(); i++) {
if (arg1_padded_shape[i] == 1) {
arg1_squeezed_axes.insert(i);
} else {
arg1_squeezed_shape.push_back(arg1_padded_shape[i]);
}
}
NGRAPH_SUPPRESS_DEPRECATED_START
ngraph::CoordinateTransform arg0_transform(arg0_shape);
ngraph::CoordinateTransform arg1_transform(arg1_squeezed_shape);
ngraph::CoordinateTransform 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)]);
}
NGRAPH_SUPPRESS_DEPRECATED_END
}
}
}
/// \brief Helper function to implement autobroadcasting elementwise ternaryop
/// references.
///
/// \tparam U Element type of the selector tensor.
/// \tparam T Element type of the input tensors.
/// \tparam Functor Type of the functor for the elementwise operation. Must support
/// operator()(U,T,T), and operator()(U,T,T) must return a value of type
/// T.
///
/// \param arg0 Pointer to the buffer for selector tensor.
/// \param arg1 Pointer to the buffer for left operand input tensor.
/// \param arg2 Pointer to the buffer for right operand input tensor.
/// \param out Pointer to the buffer for output tensor. This must be pre-allocated by
/// the caller, and must be large enough to hold a tensor of the correct
/// shape.
/// \param broadcast_spec Specification of the auto-broadcasting scheme.
/// \param elementwise_functor Functor implementing the elementwise operation to be
/// applied across the input tensors. Must accept an argument
/// of
/// type U and two of type T, and return a value of type T.
template <typename T, typename U, typename Functor>
void autobroadcast_select(const U* arg0,
const T* arg1,
const T* arg2,
T* out,
const Shape& arg0_shape,
const Shape& arg1_shape,
const Shape& arg2_shape,
const op::AutoBroadcastSpec& broadcast_spec,
Functor elementwise_functor) {
using ngraph::CoordinateTransformBasic;
switch (broadcast_spec.m_type) {
case op::AutoBroadcastType::NONE:
for (size_t i = 0; i < shape_size(arg0_shape); i++) {
out[i] = elementwise_functor(arg0[i], arg1[i], arg2[i]);
}
break;
case op::AutoBroadcastType::NUMPY:
// Uses same approach as autobroadcast_binop.
{
Shape arg0_padded_shape = arg0_shape;
Shape arg1_padded_shape = arg1_shape;
Shape arg2_padded_shape = arg2_shape;
size_t max_shape_size =
std::max({arg0_padded_shape.size(), arg1_padded_shape.size(), arg2_padded_shape.size()});
while (arg0_padded_shape.size() < max_shape_size) {
arg0_padded_shape.insert(arg0_padded_shape.begin(), 1);
}
while (arg1_padded_shape.size() < max_shape_size) {
arg1_padded_shape.insert(arg1_padded_shape.begin(), 1);
}
while (arg2_padded_shape.size() < max_shape_size) {
arg2_padded_shape.insert(arg2_padded_shape.begin(), 1);
}
Shape arg0_squeezed_shape;
Shape arg1_squeezed_shape;
Shape arg2_squeezed_shape;
AxisSet arg0_squeezed_axes;
AxisSet arg1_squeezed_axes;
AxisSet arg2_squeezed_axes;
Shape output_shape;
for (size_t i = 0; i < max_shape_size; i++) {
if (arg1_padded_shape[i] == 1) {
arg1_squeezed_axes.insert(i);
} else {
arg1_squeezed_shape.push_back(arg1_padded_shape[i]);
}
if (arg2_padded_shape[i] == 1) {
arg2_squeezed_axes.insert(i);
} else {
arg2_squeezed_shape.push_back(arg2_padded_shape[i]);
}
if (arg0_padded_shape[i] == 1) {
arg0_squeezed_axes.insert(i);
} else {
arg0_squeezed_shape.push_back(arg0_padded_shape[i]);
}
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 auto arg0_strides = row_major_strides(arg0_squeezed_shape);
const auto arg1_strides = row_major_strides(arg1_squeezed_shape);
const auto arg2_strides = row_major_strides(arg2_squeezed_shape);
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 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));
out[output_idx] = elementwise_functor(arg0[arg0_idx], arg1[arg1_idx], arg2[arg2_idx]);
}
}
break;
case op::AutoBroadcastType::PDPD: {
// arg0 and arg2 are broadcast to arg1 shape
int64_t axis = broadcast_spec.m_axis;
if (axis == -1) {
axis = arg1_shape.size() - arg2_shape.size();
}
Shape arg0_padded_shape = arg0_shape;
Shape arg2_padded_shape = arg2_shape;
// Trim trailing ones
while (arg0_padded_shape.size() > 0 && arg0_padded_shape.back() == 1) {
arg0_padded_shape.pop_back();
}
for (int64_t i = 0; (i < axis) && (arg0_padded_shape.size() < arg1_shape.size()); ++i) {
arg0_padded_shape.insert(arg0_padded_shape.begin(), 1);
}
while (arg0_padded_shape.size() < arg1_shape.size()) {
arg0_padded_shape.insert(arg0_padded_shape.end(), 1);
}
while (arg2_padded_shape.size() > 0 && arg2_padded_shape.back() == 1) {
arg2_padded_shape.pop_back();
}
for (int64_t i = 0; (i < axis) && (arg2_padded_shape.size() < arg1_shape.size()); ++i) {
arg2_padded_shape.insert(arg2_padded_shape.begin(), 1);
}
while (arg2_padded_shape.size() < arg1_shape.size()) {
arg2_padded_shape.insert(arg2_padded_shape.end(), 1);
}
Shape arg0_squeezed_shape;
AxisSet arg0_squeezed_axes;
Shape arg2_squeezed_shape;
AxisSet arg2_squeezed_axes;
for (size_t i = 0; i < arg1_shape.size(); i++) {
if (arg0_padded_shape[i] == 1) {
arg0_squeezed_axes.insert(i);
} else {
arg0_squeezed_shape.push_back(arg0_padded_shape[i]);
}
if (arg2_padded_shape[i] == 1) {
arg2_squeezed_axes.insert(i);
} else {
arg2_squeezed_shape.push_back(arg2_padded_shape[i]);
}
}
CoordinateTransformBasic arg0_transform(arg0_squeezed_shape);
CoordinateTransformBasic arg1_transform(arg1_shape);
CoordinateTransformBasic arg2_transform(arg2_squeezed_shape);
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 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));
out[output_idx] = elementwise_functor(arg0[arg0_idx], arg1[arg1_idx], arg2[arg2_idx]);
}
}
}
}
} // namespace reference
} // namespace ov

View File

@ -4,8 +4,8 @@
#pragma once
#include "ngraph/runtime/reference/convolution.hpp"
#include "ngraph/shape.hpp"
#include "openvino/reference/convolution.hpp"
namespace ngraph {
namespace runtime {

View File

@ -411,4 +411,4 @@ void convolution(const T* in,
} // namespace ngraph
// can't be removed currently due to arm-plugin dependency
#include "ngraph/runtime/reference/convolution_backprop_data.hpp"
#include "openvino/reference/convolution_backprop_data.hpp"

View File

@ -10,9 +10,9 @@
#include <numeric>
#include "ngraph/axis_vector.hpp"
#include "ngraph/runtime/reference/convolution.hpp"
#include "ngraph/runtime/reference/reverse.hpp"
#include "ngraph/util.hpp"
#include "openvino/reference/convolution.hpp"
#include "openvino/reference/reverse.hpp"
namespace ngraph {
namespace runtime {

View File

@ -4,7 +4,7 @@
#pragma once
#include "ngraph/runtime/reference/convolution.hpp"
#include "openvino/reference/convolution.hpp"
namespace ngraph {
namespace runtime {

View File

@ -4,7 +4,7 @@
#pragma once
#include "ngraph/runtime/reference/normalize_l2.hpp"
#include "openvino/reference/normalize_l2.hpp"
namespace ngraph {
namespace runtime {

View File

@ -4,8 +4,8 @@
#pragma once
#include "ngraph/runtime/reference/convolution.hpp"
#include "ngraph/runtime/reference/helpers.hpp"
#include "openvino/reference/convolution.hpp"
#include "openvino/reference/helpers.hpp"
namespace {
constexpr size_t filter_group_axis = 0;

View File

@ -4,8 +4,8 @@
#pragma once
#include "ngraph/runtime/reference/group_convolution.hpp"
#include "ngraph/util.hpp"
#include "openvino/reference/group_convolution.hpp"
namespace ngraph {
namespace runtime {

View File

@ -7,9 +7,9 @@
#include <cmath>
#include <numeric>
#include "ngraph/runtime/reference/mean.hpp"
#include "ngraph/runtime/reference/sum.hpp"
#include "openvino/core/shape.hpp"
#include "openvino/reference/mean.hpp"
#include "openvino/reference/sum.hpp"
namespace ov {
namespace reference {

View File

@ -5,15 +5,16 @@
#pragma once
#include <cmath>
#include <ngraph/runtime/reference/add.hpp>
#include <ngraph/runtime/reference/clamp.hpp>
#include <ngraph/runtime/reference/matmul.hpp>
#include <ngraph/runtime/reference/multiply.hpp>
#include <ngraph/runtime/reference/relu.hpp>
#include <ngraph/runtime/reference/sigmoid.hpp>
#include <ngraph/runtime/reference/split.hpp>
#include <ngraph/runtime/reference/subtract.hpp>
#include <ngraph/runtime/reference/tanh.hpp>
#include "openvino/reference/add.hpp"
#include "openvino/reference/clamp.hpp"
#include "openvino/reference/matmul.hpp"
#include "openvino/reference/multiply.hpp"
#include "openvino/reference/relu.hpp"
#include "openvino/reference/sigmoid.hpp"
#include "openvino/reference/split.hpp"
#include "openvino/reference/subtract.hpp"
#include "openvino/reference/tanh.hpp"
namespace ngraph {
namespace runtime {

View File

@ -7,9 +7,9 @@
#include <cmath>
#include "ngraph/coordinate_transform.hpp"
#include "ngraph/runtime/reference/max.hpp"
#include "ngraph/runtime/reference/sum.hpp"
#include "ngraph/shape_util.hpp"
#include "openvino/reference/max.hpp"
#include "openvino/reference/sum.hpp"
namespace ngraph {
namespace runtime {

View File

@ -5,15 +5,16 @@
#pragma once
#include <cmath>
#include <ngraph/runtime/reference/add.hpp>
#include <ngraph/runtime/reference/clamp.hpp>
#include <ngraph/runtime/reference/matmul.hpp>
#include <ngraph/runtime/reference/multiply.hpp>
#include <ngraph/runtime/reference/relu.hpp>
#include <ngraph/runtime/reference/sigmoid.hpp>
#include <ngraph/runtime/reference/split.hpp>
#include <ngraph/runtime/reference/subtract.hpp>
#include <ngraph/runtime/reference/tanh.hpp>
#include "openvino/reference/add.hpp"
#include "openvino/reference/clamp.hpp"
#include "openvino/reference/matmul.hpp"
#include "openvino/reference/multiply.hpp"
#include "openvino/reference/relu.hpp"
#include "openvino/reference/sigmoid.hpp"
#include "openvino/reference/split.hpp"
#include "openvino/reference/subtract.hpp"
#include "openvino/reference/tanh.hpp"
namespace ngraph {
namespace runtime {

View File

@ -10,8 +10,8 @@
#include <vector>
#include "ngraph/runtime/opt_kernel/reshape.hpp"
#include "ngraph/runtime/reference/broadcast.hpp"
#include "ngraph/shape_util.hpp"
#include "openvino/reference/broadcast.hpp"
namespace ngraph {
namespace runtime {

Some files were not shown because too many files have changed in this diff Show More