Skip to content

Commit

Permalink
Merge branch 'an/debug_fix' of https://github.com/allnes/openvino int…
Browse files Browse the repository at this point in the history
…o an/debug_fix
  • Loading branch information
allnes committed Nov 2, 2023
2 parents 6f40540 + 961cd3c commit 30e6cee
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 79 deletions.
5 changes: 1 addition & 4 deletions src/core/include/openvino/op/floor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ class OPENVINO_API Floor : public util::UnaryElementwiseArithmetic {
/// \param arg Node that produces the input tensor.
Floor(const Output<Node>& arg);

bool visit_attributes(AttributeVisitor& visitor) override;
std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const override;
OPENVINO_SUPPRESS_DEPRECATED_START
bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override;
OPENVINO_SUPPRESS_DEPRECATED_END
bool evaluate(TensorVector& outputs, const TensorVector& inputs) const override;
bool has_evaluate() const override;
};
} // namespace v0
Expand Down
33 changes: 28 additions & 5 deletions src/core/reference/include/openvino/reference/floor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,36 @@
#include <cmath>
#include <cstddef>

#include "openvino/reference/copy.hpp"
#include "openvino/reference/utils/type_util.hpp"

namespace ov {
namespace reference {
template <typename T>
void floor(const T* arg, T* out, size_t count) {
for (size_t i = 0; i < count; i++) {
out[i] = std::floor(arg[i]);
}

/**
* @brief Reference implementation of Floor operator (integral types).
*
* @param arg Input pointer to data.
* @param out Output pointer to results.
* @param count Number of elements in input buffer.
*/
template <class T, typename std::enable_if<std::is_integral<T>::value>::type* = nullptr>
void floor(const T* arg, T* out, const size_t count) {
reference::copy(arg, out, count);
}

/**
* @brief Reference implementation of Floor operator (floating point types).
*
* @param arg Input pointer to data.
* @param out Output pointer to results.
* @param count Number of elements in input buffer.
*/
template <class T, typename std::enable_if<ov::is_floating_point<T>()>::type* = nullptr>
void floor(const T* arg, T* out, const size_t count) {
std::transform(arg, arg + count, out, [](const T v) {
return std::floor(v);
});
}
} // namespace reference
} // namespace ov
118 changes: 48 additions & 70 deletions src/core/src/op/floor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,95 +2,73 @@
// SPDX-License-Identifier: Apache-2.0
//

#include "ngraph/op/floor.hpp"
#include "openvino/op/floor.hpp"

#include "element_visitor.hpp"
#include "itt.hpp"
#include "ngraph/op/util/eval_copy.hpp"
#include "ngraph/runtime/host_tensor.hpp"
#include "openvino/reference/copy.hpp"
#include "openvino/reference/floor.hpp"

using namespace std;
using namespace ngraph;
namespace ov {
namespace op {
namespace floor {

op::Floor::Floor(const Output<Node>& arg) : UnaryElementwiseArithmetic(arg) {
constructor_validate_and_infer_types();
}
struct Evaluate : element::NoAction<bool> {
using element::NoAction<bool>::visit;

bool ngraph::op::v0::Floor::visit_attributes(AttributeVisitor& visitor) {
OV_OP_SCOPE(v0_Floor_visit_attributes);
return true;
}
template <element::Type_t ET, class T = fundamental_type_for<ET>>
static result_type visit(const Tensor& arg, Tensor& out, const size_t count) {
reference::floor(arg.data<const T>(), out.data<T>(), count);
return true;
}
};
} // namespace floor

shared_ptr<Node> op::Floor::clone_with_new_inputs(const OutputVector& new_args) const {
OV_OP_SCOPE(v0_Floor_clone_with_new_inputs);
check_new_args_count(this, new_args);
return make_shared<Floor>(new_args.at(0));
}
namespace v0 {

OPENVINO_SUPPRESS_DEPRECATED_START
namespace floorop {
namespace {
// function used by TYPE_CASE
template <element::Type_t ET>
inline bool evaluate(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) {
using T = typename element_type_traits<ET>::value_type;
ov::reference::floor<T>(arg0->get_data_ptr<ET>(), out->get_data_ptr<ET>(), count);
return true;
Floor::Floor(const Output<Node>& arg) : UnaryElementwiseArithmetic(arg) {
constructor_validate_and_infer_types();
}

// function used by COPY_TENSOR
template <element::Type_t ET>
inline bool copy_tensor(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) {
ov::reference::copy(arg0->get_data_ptr<ET>(), out->get_data_ptr<ET>(), count);
return true;
std::shared_ptr<Node> Floor::clone_with_new_inputs(const OutputVector& new_args) const {
OV_OP_SCOPE(v0_Floor_clone_with_new_inputs);
check_new_args_count(this, new_args);
return std::make_shared<Floor>(new_args.at(0));
}

bool evaluate_floor(const HostTensorPtr& arg0, const HostTensorPtr& out, const size_t count) {
bool rc = true;
out->set_unary(arg0);
bool Floor::evaluate(TensorVector& outputs, const TensorVector& inputs) const {
OV_OP_SCOPE(v0_Floor_evaluate);
OPENVINO_ASSERT(outputs.size() == 1);
OPENVINO_ASSERT(inputs.size() == 1);

switch (arg0->get_element_type()) {
OPENVINO_COPY_TENSOR(evaluate_floor, i8, arg0, out, count);
OPENVINO_COPY_TENSOR(evaluate_floor, i16, arg0, out, count);
OPENVINO_COPY_TENSOR(evaluate_floor, i32, arg0, out, count);
OPENVINO_COPY_TENSOR(evaluate_floor, i64, arg0, out, count);
OPENVINO_COPY_TENSOR(evaluate_floor, u8, arg0, out, count);
OPENVINO_COPY_TENSOR(evaluate_floor, u16, arg0, out, count);
OPENVINO_COPY_TENSOR(evaluate_floor, u32, arg0, out, count);
OPENVINO_COPY_TENSOR(evaluate_floor, u64, arg0, out, count);
OPENVINO_TYPE_CASE(evaluate_floor, f16, arg0, out, count);
OPENVINO_TYPE_CASE(evaluate_floor, f32, arg0, out, count);
default:
rc = false;
break;
}
return rc;
}
} // namespace
} // namespace floorop
const auto& in_shape = inputs[0].get_shape();
outputs[0].set_shape(in_shape);

bool op::Floor::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const {
OV_OP_SCOPE(v0_Floor_evaluate);
return floorop::evaluate_floor(inputs[0], outputs[0], shape_size(inputs[0]->get_shape()));
using namespace ov::element;
return IfTypeOf<f16, f32, i8, i16, i32, i64, u8, u16, u32, u64>::apply<floor::Evaluate>(
inputs[0].get_element_type(),
inputs[0],
outputs[0],
shape_size(in_shape));
}

bool op::Floor::has_evaluate() const {
bool Floor::has_evaluate() const {
OV_OP_SCOPE(v0_Floor_has_evaluate);
switch (get_input_element_type(0)) {
case ngraph::element::i8:
case ngraph::element::i16:
case ngraph::element::i32:
case ngraph::element::i64:
case ngraph::element::u8:
case ngraph::element::u16:
case ngraph::element::u32:
case ngraph::element::u64:
case ngraph::element::f16:
case ngraph::element::f32:
case element::f16:
case element::f32:
case element::i8:
case element::i16:
case element::i32:
case element::i64:
case element::u8:
case element::u16:
case element::u32:
case element::u64:
return true;
default:
break;
return false;
}
return false;
}
} // namespace v0
} // namespace op
} // namespace ov

0 comments on commit 30e6cee

Please sign in to comment.