Skip to content

Commit

Permalink
Merge branch 'update_evaluates' of github.com:mikhail-treskin/openvin…
Browse files Browse the repository at this point in the history
…o into update_evaluates

� Conflicts:
�	ngraph/test/runtime/pass/opset0_downgrade.cpp
  • Loading branch information
Mikhail Treskin committed Sep 10, 2020
2 parents 167073f + d910235 commit 0ea28db
Show file tree
Hide file tree
Showing 36 changed files with 1,158 additions and 945 deletions.
3 changes: 2 additions & 1 deletion ngraph/core/include/ngraph/op/depth_to_space.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ namespace ngraph

virtual std::shared_ptr<Node>
clone_with_new_inputs(const OutputVector& new_args) const override;
bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override;
bool evaluate(const HostTensorVector& outputs,
const HostTensorVector& inputs) const override;

protected:
std::size_t m_blocksize;
Expand Down
1 change: 0 additions & 1 deletion ngraph/core/include/ngraph/op/embedding_segments_sum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ namespace ngraph
clone_with_new_inputs(const OutputVector& new_args) const override;

virtual bool visit_attributes(AttributeVisitor& visitor) override { return true; }

private:
static constexpr int EMB_TABLE = 0;
static constexpr int INDICES = 1;
Expand Down
1 change: 0 additions & 1 deletion ngraph/core/include/ngraph/op/mvn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ namespace ngraph
bool get_normalize_variance() const { return m_normalize_variance; }
AxisSet get_reduction_axes() const { return m_reduction_axes; }
void set_reduction_axes(AxisSet axes) { m_reduction_axes = axes; }

private:
double m_eps = 1e-9;
bool m_across_channels;
Expand Down
4 changes: 3 additions & 1 deletion ngraph/core/include/ngraph/op/shuffle_channels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ namespace ngraph

int64_t get_axis() const { return m_axis; }
int64_t get_group() const { return m_group; }
bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override;
bool evaluate(const HostTensorVector& outputs,
const HostTensorVector& inputs) const override;

private:
/// \brief Generates a shape required to permute the data
///
Expand Down
3 changes: 2 additions & 1 deletion ngraph/core/include/ngraph/op/space_to_depth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ namespace ngraph
virtual std::shared_ptr<Node>
clone_with_new_inputs(const OutputVector& new_args) const override;

bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override;
bool evaluate(const HostTensorVector& outputs,
const HostTensorVector& inputs) const override;

protected:
std::size_t m_blocksize;
Expand Down
58 changes: 38 additions & 20 deletions ngraph/core/include/ngraph/runtime/reference/mvn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,62 @@
#pragma once

#include <cstddef>
#include <ngraph/shape.hpp>
#include <ngraph/runtime/reference/mean.hpp>
#include <ngraph/runtime/opt_kernel/broadcast.hpp>
#include <ngraph/runtime/reference/subtract.hpp>
#include <ngraph/runtime/reference/mean.hpp>
#include <ngraph/runtime/reference/multiply.hpp>
#include <ngraph/runtime/reference/sum.hpp>
#include <ngraph/runtime/reference/sqrt.hpp>
#include <ngraph/runtime/reference/subtract.hpp>
#include <ngraph/runtime/reference/sum.hpp>
#include <ngraph/shape.hpp>

namespace ngraph {
namespace runtime {
namespace reference {
template<typename T>
void mvn(const T *arg, T *out, const Shape &in_shape, bool normalize_variance, AxisSet reduction_axes,
double eps) {
namespace ngraph
{
namespace runtime
{
namespace reference
{
template <typename T>
void mvn(const T* arg,
T* out,
const Shape& in_shape,
bool normalize_variance,
AxisSet reduction_axes,
double eps)
{
auto reduced_shape = reduce(in_shape, reduction_axes, true);
std::vector<T> mean_val(shape_size(reduced_shape));
mean(arg, mean_val.data(), in_shape, reduction_axes, true);
std::vector<T> broadcast_mean_data(shape_size(in_shape));
broadcast(mean_val.data(), broadcast_mean_data.data(), reduced_shape, in_shape, reduction_axes);
broadcast(mean_val.data(),
broadcast_mean_data.data(),
reduced_shape,
in_shape,
reduction_axes);
subtract(arg, broadcast_mean_data.data(), out, shape_size(in_shape));

if (normalize_variance) {
if (normalize_variance)
{
std::vector<T> multiply_val(shape_size(in_shape));
multiply(out, out, multiply_val.data(),shape_size(in_shape));
multiply(out, out, multiply_val.data(), shape_size(in_shape));
std::vector<T> sum_val(shape_size(reduced_shape));
sum(multiply_val.data(), sum_val.data(), in_shape, reduction_axes, true);
std::vector<T> broadcast_sum(shape_size(in_shape));
broadcast(sum_val.data(), broadcast_sum.data(), reduced_shape, in_shape, reduction_axes);
broadcast(sum_val.data(),
broadcast_sum.data(),
reduced_shape,
in_shape,
reduction_axes);
T n = 1;
for (auto i : reduction_axes) {
for (auto i : reduction_axes)
{
n *= in_shape[i];
}
for (size_t i = 0; i < shape_size(in_shape); ++i) {
for (size_t i = 0; i < shape_size(in_shape); ++i)
{
out[i] /= std::sqrt(broadcast_sum[i] / n) + eps;
}

}
}
} // namespace reference
} // namespace runtime
} // namespace ngraph
} // namespace reference
} // namespace runtime
} // namespace ngraph
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ namespace ngraph

if (in_bounds || include_padding_in_avg_computation)
{
T v =
in_bounds ? arg[input_batch_transform.index(input_batch_coord)] : static_cast<T>(0);
T v = in_bounds ? arg[input_batch_transform.index(input_batch_coord)]
: static_cast<T>(0);
result += v;
n_elements++;
}
Expand Down
Loading

0 comments on commit 0ea28db

Please sign in to comment.