Skip to content

Commit

Permalink
Merge branch 'master' into surya/enable_options
Browse files Browse the repository at this point in the history
  • Loading branch information
suryasidd committed Nov 15, 2023
2 parents bae0f69 + afc5995 commit ff2d4a1
Show file tree
Hide file tree
Showing 192 changed files with 2,288 additions and 1,568 deletions.
3 changes: 3 additions & 0 deletions src/core/include/openvino/core/except.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ class OPENVINO_API NotImplemented : public AssertFailure {
/// \throws ::ov::Exception if the macro is executed.
#define OPENVINO_THROW(...) OPENVINO_THROW_HELPER(::ov::Exception, ov::Exception::default_msg, __VA_ARGS__)

#define OPENVINO_THROW_NOT_IMPLEMENTED(...) \
OPENVINO_ASSERT_HELPER(::ov::NotImplemented, ::ov::Exception::default_msg, false, __VA_ARGS__)

#define OPENVINO_NOT_IMPLEMENTED OPENVINO_ASSERT_HELPER(::ov::NotImplemented, ::ov::Exception::default_msg, false)

#define GLUE(x, y) x y
Expand Down
41 changes: 41 additions & 0 deletions src/core/include/openvino/op/fake_convert.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include "openvino/op/op.hpp"

namespace ov {
namespace op {
namespace v13 {
/// \ingroup ov_ops_cpp_api
class OPENVINO_API FakeConvert : public Op {
public:
OPENVINO_OP("FakeConvert", "opset13");

FakeConvert() = default;
FakeConvert(const ov::Output<ov::Node>& arg,
const ov::Output<ov::Node>& scale,
std::string destination_type = "f8e4m3");

FakeConvert(const ov::Output<ov::Node>& arg,
const ov::Output<ov::Node>& scale,
const ov::Output<ov::Node>& shift,
std::string destination_type = "f8e4m3");

void validate_and_infer_types() override;
std::shared_ptr<ov::Node> clone_with_new_inputs(const ov::OutputVector& new_args) const override;
bool visit_attributes(ov::AttributeVisitor& visitor) override;
bool has_evaluate() const override;

const std::string& get_destination_type() const;

private:
void validate_type() const;

std::string m_destination_type = "f8e4m3";
};
} // namespace v13
} // namespace op
} // namespace ov
1 change: 1 addition & 0 deletions src/core/include/openvino/op/ops.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#include "openvino/op/experimental_detectron_topkrois.hpp"
#include "openvino/op/extractimagepatches.hpp"
#include "openvino/op/eye.hpp"
#include "openvino/op/fake_convert.hpp"
#include "openvino/op/fake_quantize.hpp"
#include "openvino/op/floor.hpp"
#include "openvino/op/floor_mod.hpp"
Expand Down
1 change: 1 addition & 0 deletions src/core/include/openvino/opsets/opset13_tbl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,4 @@ _OPENVINO_OP_REG(BitwiseXor, ov::op::v13)
_OPENVINO_OP_REG(NMSRotated, ov::op::v13)
_OPENVINO_OP_REG(Multinomial, ov::op::v13)
_OPENVINO_OP_REG(ScaledDotProductAttention, ov::op::v13)
_OPENVINO_OP_REG(FakeConvert, ov::op::v13)
75 changes: 75 additions & 0 deletions src/core/src/op/fake_convert.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright (C) 2018-2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "openvino/op/fake_convert.hpp"

#include "itt.hpp"

namespace ov {
namespace op {
namespace v13 {
namespace fake_convert {
static const std::vector<std::string>& get_valid_types() {
static const std::vector<std::string> valid_types{"f8e4m3", "f8e5m2"};
return valid_types;
}
} // namespace fake_convert

FakeConvert::FakeConvert(const ov::Output<ov::Node>& arg,
const ov::Output<ov::Node>& scale,
std::string destination_type)
: Op({arg, scale}),
m_destination_type(std::move(destination_type)) {
constructor_validate_and_infer_types();
}

FakeConvert::FakeConvert(const ov::Output<ov::Node>& arg,
const ov::Output<ov::Node>& scale,
const ov::Output<ov::Node>& shift,
std::string destination_type)
: Op({arg, scale, shift}),
m_destination_type(std::move(destination_type)) {
constructor_validate_and_infer_types();
}

const std::string& FakeConvert::get_destination_type() const {
return m_destination_type;
}

void FakeConvert::validate_and_infer_types() {
OV_OP_SCOPE(v13_FakeConvert_validate_and_infer_types);
validate_type();
set_output_type(0, get_input_element_type(0), get_input_partial_shape(0));
}

std::shared_ptr<ov::Node> FakeConvert::clone_with_new_inputs(const ov::OutputVector& new_args) const {
OV_OP_SCOPE(v13_FakeConvert_clone_with_new_inputs);
if (new_args.size() == 2) {
return std::make_shared<FakeConvert>(new_args.at(0), new_args.at(1), m_destination_type);
} else if (new_args.size() == 3) {
return std::make_shared<FakeConvert>(new_args.at(0), new_args.at(1), new_args.at(2), m_destination_type);
} else {
OPENVINO_THROW("Incorrect number of FakeConvert new arguments.");
}
}

bool FakeConvert::visit_attributes(ov::AttributeVisitor& visitor) {
OV_OP_SCOPE(v13_FakeConvert_visit_attributes);
visitor.on_attribute("destination_type", m_destination_type);
return true;
}

void FakeConvert::validate_type() const {
const auto& valid_types = fake_convert::get_valid_types();
OPENVINO_ASSERT(std::find(valid_types.begin(), valid_types.end(), m_destination_type) != valid_types.end(),
"Bad format for f8 conversion type: " + m_destination_type);
}

bool FakeConvert::has_evaluate() const {
return false;
}

} // namespace v13
} // namespace op
} // namespace ov
2 changes: 1 addition & 1 deletion src/core/tests/opset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ INSTANTIATE_TEST_SUITE_P(opset,
OpsetTestParams{ov::get_opset10, 177},
OpsetTestParams{ov::get_opset11, 177},
OpsetTestParams{ov::get_opset12, 178},
OpsetTestParams{ov::get_opset13, 185}),
OpsetTestParams{ov::get_opset13, 186}),
OpsetTestNameGenerator{});

class MyOpOld : public ov::op::Op {
Expand Down
51 changes: 51 additions & 0 deletions src/core/tests/type_prop/fake_convert.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "openvino/op/fake_convert.hpp"

#include <gtest/gtest.h>

#include "common_test_utils/type_prop.hpp"

using namespace ov;
using ov::op::v0::Parameter;

TEST(type_prop, fake_convert_no_shift) {
const auto data = std::make_shared<Parameter>(element::f32, PartialShape{2, 3, 8, 6});
const auto scale = std::make_shared<Parameter>(element::f32, PartialShape{});

const auto op = std::make_shared<op::v13::FakeConvert>(data, scale);
EXPECT_EQ(op->get_output_element_type(0), element::f32);
EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{2, 3, 8, 6}));
}

TEST(type_prop, fake_convert_basic_f32) {
const auto data = std::make_shared<Parameter>(element::f32, PartialShape{2, 3, 8, 6});
const auto scale = std::make_shared<Parameter>(element::f32, PartialShape{});
const auto shift = std::make_shared<Parameter>(element::f32, PartialShape{});

const auto op = std::make_shared<op::v13::FakeConvert>(data, scale, shift);
EXPECT_EQ(op->get_output_element_type(0), element::f32);
EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{2, 3, 8, 6}));
}

TEST(type_prop, fake_convert_basic_f16) {
const auto data = std::make_shared<Parameter>(element::f16, PartialShape{2, 3, 8, 6});
const auto scale = std::make_shared<Parameter>(element::f16, PartialShape{});
const auto shift = std::make_shared<Parameter>(element::f16, PartialShape{});

const auto op = std::make_shared<op::v13::FakeConvert>(data, scale, shift);
EXPECT_EQ(op->get_output_element_type(0), element::f16);
EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{2, 3, 8, 6}));
}

TEST(type_prop, fake_convert_dynamic_shape) {
const auto data = std::make_shared<Parameter>(element::f32, PartialShape::dynamic());
const auto scale = std::make_shared<Parameter>(element::f32, PartialShape{});
const auto shift = std::make_shared<Parameter>(element::f32, PartialShape{});

const auto op = std::make_shared<op::v13::FakeConvert>(data, scale, shift);
EXPECT_EQ(op->get_output_element_type(0), element::f32);
EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape::dynamic()));
}
47 changes: 47 additions & 0 deletions src/core/tests/visitors/op/fake_convert.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "openvino/op/fake_convert.hpp"

#include <gtest/gtest.h>

#include "visitors/visitors.hpp"

using ov::Shape;
using ov::op::v0::Parameter;
using ov::test::NodeBuilder;

TEST(attributes, fake_convert_v13_attributes_default) {
using ov::op::v13::FakeConvert;
NodeBuilder::get_ops().register_factory<FakeConvert>();
const auto data = std::make_shared<Parameter>(ov::element::f32, ov::PartialShape{2, 3, 8, 6});
const auto scale = std::make_shared<Parameter>(ov::element::f32, ov::PartialShape{});
const auto shift = std::make_shared<Parameter>(ov::element::f32, ov::PartialShape{});

const auto op = std::make_shared<FakeConvert>(data, scale, shift);

NodeBuilder builder(op, {data, scale, shift});
auto g_op = ov::as_type_ptr<FakeConvert>(builder.create());

EXPECT_EQ(g_op->get_destination_type(), op->get_destination_type());
EXPECT_EQ(g_op->get_output_element_type(0), op->get_output_element_type(0));
EXPECT_EQ(g_op->get_output_partial_shape(0), op->get_output_partial_shape(0));
}

TEST(attributes, fake_convert_v13_attributes_custom) {
using ov::op::v13::FakeConvert;
NodeBuilder::get_ops().register_factory<FakeConvert>();
const auto data = std::make_shared<Parameter>(ov::element::f32, ov::PartialShape{2, 3, 8, 6});
const auto scale = std::make_shared<Parameter>(ov::element::f32, ov::PartialShape{});
const auto shift = std::make_shared<Parameter>(ov::element::f32, ov::PartialShape{});

const auto op = std::make_shared<FakeConvert>(data, scale, shift, "f8e5m2");

NodeBuilder builder(op, {data, scale, shift});
auto g_op = ov::as_type_ptr<FakeConvert>(builder.create());

EXPECT_EQ(g_op->get_destination_type(), op->get_destination_type());
EXPECT_EQ(g_op->get_output_element_type(0), op->get_output_element_type(0));
EXPECT_EQ(g_op->get_output_partial_shape(0), op->get_output_partial_shape(0));
}
2 changes: 1 addition & 1 deletion src/plugins/intel_cpu/src/compiled_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ ov::Any CompiledModel::get_metric_legacy(const std::string& name, const GraphGua
} else if (name == METRIC_KEY(OPTIMAL_NUMBER_OF_INFER_REQUESTS)) {
Config engConfig = graph.getConfig();
auto option = engConfig._config.find(CONFIG_KEY(CPU_THROUGHPUT_STREAMS));
IE_ASSERT(option != engConfig._config.end());
OPENVINO_ASSERT(option != engConfig._config.end());
auto streams = std::stoi(option->second);
IE_SET_METRIC_RETURN(OPTIMAL_NUMBER_OF_INFER_REQUESTS, static_cast<unsigned int>(streams ? streams : 1));
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/intel_cpu/src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ void Config::readProperties(const ov::AnyMap& prop, const ModelType modelType) {
<< ". Supported values: PERFORMANCE, ACCURACY";
}
} else {
IE_THROW(NotFound) << "Unsupported property " << key << " by CPU plugin";
OPENVINO_THROW("NotFound: Unsupported property ", key, " by CPU plugin.");
}
IE_SUPPRESS_DEPRECATED_END
}
Expand Down
18 changes: 9 additions & 9 deletions src/plugins/intel_cpu/src/cpu_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Memory::Memory(const dnnl::engine& eng, const MemoryDesc& desc, MemoryMngrPtr mn
size_t Memory::getSize() const {
auto size = getDesc().getCurrentMemSize();
if (size == MemoryDesc::UNDEFINED_SIZE) {
IE_THROW() << "Can't get memory size for undefined shape";
OPENVINO_THROW("Can't get memory size for undefined shape");
}
return size;
}
Expand Down Expand Up @@ -132,7 +132,7 @@ void Memory::nullify() {

void Memory::redefineDesc(MemoryDescPtr desc) {
if (!desc->hasDefinedMaxSize()) {
IE_THROW() << "Can not reset descriptor, memory upper bound is unknown.";
OPENVINO_THROW("Can not reset descriptor, memory upper bound is unknown.");
}

this->create(desc, nullptr, false);
Expand Down Expand Up @@ -162,7 +162,7 @@ dnnl::memory Memory::DnnlMemPrimHandle::getPrim() const {
std::lock_guard<std::mutex> guard(m_primCachingLock);
if (!m_prim) {
if (!m_memObjPtr->getDesc().isDefined()) {
IE_THROW() << "Can not create oneDNN memory from undefined memory descriptor";
OPENVINO_THROW("Can not create oneDNN memory from undefined memory descriptor");
}

// ========================
Expand Down Expand Up @@ -205,7 +205,7 @@ void* Memory::getData() const {
if (data == nullptr &&
m_pMemDesc->getShape().isStatic() &&
m_pMemDesc->getShape().getElementsCount() != 0)
IE_THROW() << "Memory has not been allocated";
OPENVINO_THROW("Memory has not been allocated");
return data;
}

Expand All @@ -225,7 +225,7 @@ bool MemoryMngrWithReuse::resize(size_t size) {
if (size > m_memUpperBound) {
void *ptr = dnnl::impl::malloc(size, cacheLineSize);
if (!ptr) {
IE_THROW() << "Failed to allocate " << size << " bytes of memory";
OPENVINO_THROW("Failed to allocate ", size, " bytes of memory");
}
m_memUpperBound = size;
m_useExternalStorage = false;
Expand Down Expand Up @@ -289,7 +289,7 @@ void DnnlMemoryMngr::notifyUpdate() {
StaticMemory::StaticMemory(const dnnl::engine& eng, MemoryDescPtr desc, const void* data, bool pads_zeroing) :
m_eng(eng), m_pMemDesc(desc) {
if (!m_pMemDesc->isDefined()) {
IE_THROW() << "Can not create StaticMemory object. The memory desc is undefined";
OPENVINO_THROW("Can not create StaticMemory object. The memory desc is undefined");
}

m_size = m_pMemDesc->getCurrentMemSize();
Expand Down Expand Up @@ -346,7 +346,7 @@ const VectorDims& StaticMemory::getStaticDims() const {
}

void StaticMemory::redefineDesc(MemoryDescPtr desc) {
IE_THROW(Unexpected) << "Memory descriptor may not be modified in StaticMemory object";
OPENVINO_THROW("Unexpected: Memory descriptor may not be modified in StaticMemory object");
}

void StaticMemory::load(const IMemory& src, bool ftz) const {
Expand Down Expand Up @@ -381,12 +381,12 @@ void* StaticMemory::StaticMemoryMngr::getRawPtr() const noexcept {
}

void StaticMemory::StaticMemoryMngr::setExtBuff(void* ptr, size_t size) {
IE_THROW(Unexpected) << "StaticMemoryMngr may not be modified";
OPENVINO_THROW("Unexpected: StaticMemoryMngr may not be modified");
}

bool StaticMemory::StaticMemoryMngr::resize(size_t size) {
if (size != m_size) {
IE_THROW(Unexpected) << "StaticMemoryMngr may not resize the memory";
OPENVINO_THROW("Unexpected: StaticMemoryMngr may not resize the memory");
}
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/intel_cpu/src/dnnl_extension_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ InferenceEngine::Precision DnnlExtensionUtils::DataTypeToIEPrecision(memory::dat
case memory::data_type::undef:
return InferenceEngine::Precision::UNSPECIFIED;
default: {
IE_THROW() << "Unsupported data type.";
OPENVINO_THROW("Unsupported data type.");
}
}
}
Expand Down Expand Up @@ -178,7 +178,7 @@ std::shared_ptr<DnnlBlockedMemoryDesc> DnnlExtensionUtils::makeUndefinedDesc(con
if (desc.get_format_kind() == memory::format_kind::blocked) {
return std::shared_ptr<DnnlBlockedMemoryDesc>(new DnnlBlockedMemoryDesc(desc, shape));
} else {
IE_THROW(Unexpected) << "Cannot make undefined descriptor. Only dnnl_blocked type is allowed.";
OPENVINO_THROW("Unexpected: Cannot make undefined descriptor. Only dnnl_blocked type is allowed.");
}
}

Expand All @@ -187,7 +187,7 @@ DnnlMemoryDescPtr DnnlExtensionUtils::query_md(const const_dnnl_primitive_desc_t
const auto* cdesc = dnnl_primitive_desc_query_md(pd, query, idx);

if (!cdesc)
IE_THROW() << "query_md failed for query=" << query << " idx=" << idx << ".";
OPENVINO_THROW("query_md failed for query=", query, " idx=", idx, ".");

return DnnlExtensionUtils::makeDescriptor(cdesc);
}
Expand All @@ -196,7 +196,7 @@ std::string DnnlExtensionUtils::query_impl_info_str(const const_dnnl_primitive_d
const char *res;
dnnl_status_t status = dnnl_primitive_desc_query(pd, dnnl_query_impl_info_str, 0, &res);
if (status != dnnl_success)
IE_THROW() << "query_impl_info_str failed.";
OPENVINO_THROW("query_impl_info_str failed.");
return std::string(res);
}

Expand Down
Loading

0 comments on commit ff2d4a1

Please sign in to comment.