Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,14 @@ inline int32_t convert_value<uint32_t, int32_t>(uint32_t val) {
return static_cast<int32_t>(val);
}

template <>
inline int64_t convert_value<uint64_t, int64_t>(uint64_t val) {
if (val >= static_cast<uint64_t>(std::numeric_limits<int64_t>::max())) {
Comment thread
nshchego marked this conversation as resolved.
return std::numeric_limits<int64_t>::max();
}
return static_cast<int64_t>(val);
}

namespace {
template <ov::element::Type_t PREC_FROM, ov::element::Type_t PREC_TO>
std::shared_ptr<ngraph::Node> change_constant_precision(std::shared_ptr<opset4::Constant>& constant) {
Expand Down Expand Up @@ -1110,7 +1118,9 @@ bool fuse_type_to_constant(const std::shared_ptr<ngraph::Node>& node,
const auto& to = it->second;
if (auto constant = ov::as_type_ptr<opset4::Constant>(node)) {
std::shared_ptr<ngraph::Node> new_const;
if (from == ov::element::u64 && to == ov::element::i32) {
if (from == ov::element::u64 && to == ov::element::i64) {
new_const = change_constant_precision<ov::element::Type_t::u64, ov::element::Type_t::i64>(constant);
} else if (from == ov::element::u64 && to == ov::element::i32) {
new_const = change_constant_precision<ov::element::Type_t::u64, ov::element::Type_t::i32>(constant);
} else if (from == ov::element::i64 && to == ov::element::i32) {
new_const = change_constant_precision<ov::element::Type_t::i64, ov::element::Type_t::i32>(constant);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <ngraph/runtime/reference/multiply.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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ void reduce_l1(const T* arg, T* out, const Shape& in_shape, const AxisSet& reduc
const size_t out_idx =
std::inner_product(output_coord.begin(), output_coord.end(), out_strides.begin(), uint64_t(0));

out[out_idx] = out[out_idx] + std::abs(arg[in_idx]);
// WA for abs function, due to it's not defined for some data types.
auto val = arg[in_idx];
if (val < T(0)) {
val *= T(-1);
}
out[out_idx] = out[out_idx] + val;
}
OPENVINO_SUPPRESS_DEPRECATED_END
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void reduce_l2(const T* arg, T* out, const Shape& in_shape, const AxisSet& reduc
out[out_idx] = out[out_idx] + arg[in_idx] * arg[in_idx];
}
std::transform(out, out + shape_size(out_shape), out, [](T elem) {
return sqrt(elem);
return static_cast<T>(std::sqrt(static_cast<double>(elem)));
});
OPENVINO_SUPPRESS_DEPRECATED_END
}
Expand Down
2 changes: 2 additions & 0 deletions src/core/src/op/reduce_l1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ bool evaluate_sum(const HostTensorPtr& arg, const HostTensorPtr& out, const Axis
switch (arg->get_element_type()) {
NGRAPH_TYPE_CASE(evaluate_reducel1_sum, i32, arg, out, axes, keep_dims);
NGRAPH_TYPE_CASE(evaluate_reducel1_sum, i64, arg, out, axes, keep_dims);
NGRAPH_TYPE_CASE(evaluate_reducel1_sum, u64, arg, out, axes, keep_dims);
NGRAPH_TYPE_CASE(evaluate_reducel1_sum, bf16, arg, out, axes, keep_dims);
NGRAPH_TYPE_CASE(evaluate_reducel1_sum, f16, arg, out, axes, keep_dims);
NGRAPH_TYPE_CASE(evaluate_reducel1_sum, f32, arg, out, axes, keep_dims);
Expand Down Expand Up @@ -73,6 +74,7 @@ bool op::v4::ReduceL1::has_evaluate() const {
switch (get_input_element_type(0)) {
case ngraph::element::i32:
case ngraph::element::i64:
case ngraph::element::u64:
case ngraph::element::bf16:
case ngraph::element::f16:
case ngraph::element::f32:
Expand Down
4 changes: 4 additions & 0 deletions src/core/src/op/reduce_l2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ bool evaluate_reduce_l2(const HostTensorPtr& arg, const HostTensorPtr& out, cons
NGRAPH_TYPE_CASE(evaluate_reduce_l2, bf16, arg, out, axes, keep_dims);
NGRAPH_TYPE_CASE(evaluate_reduce_l2, f16, arg, out, axes, keep_dims);
NGRAPH_TYPE_CASE(evaluate_reduce_l2, f32, arg, out, axes, keep_dims);
NGRAPH_TYPE_CASE(evaluate_reduce_l2, i64, arg, out, axes, keep_dims);
NGRAPH_TYPE_CASE(evaluate_reduce_l2, u64, arg, out, axes, keep_dims);
default:
rc = false;
break;
Expand Down Expand Up @@ -72,6 +74,8 @@ bool op::v4::ReduceL2::has_evaluate() const {
case ngraph::element::bf16:
case ngraph::element::f16:
case ngraph::element::f32:
case ngraph::element::i64:
case ngraph::element::u64:
return true;
default:
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ INFERENCE_ENGINE_1_0_DEPRECATED DECLARE_CONFIG_VALUE(ENABLE);
INFERENCE_ENGINE_1_0_DEPRECATED DECLARE_CONFIG_VALUE(IGNORE_CALLBACK);
INFERENCE_ENGINE_1_0_DEPRECATED DECLARE_CONFIG_VALUE(DISABLE);

/**
* @brief Enables inference with INT64 data type in CPU plugin if it's presented in the original model.
*/
DECLARE_CONFIG_KEY(CPU_NATIVE_I64);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be discussed before merging


} // namespace PluginConfigInternalParams

} // namespace InferenceEngine
11 changes: 10 additions & 1 deletion src/plugins/intel_cpu/src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,15 @@ void Config::readProperties(const std::map<std::string, std::string> &prop) {
IE_THROW() << "Wrong value for property key " << ov::hint::execution_mode.name()
<< ". Supported values: PERFORMANCE, ACCURACY";
}
} else if (key == PluginConfigInternalParams::KEY_CPU_NATIVE_I64) {
if (val == PluginConfigParams::YES) {
enableNativeI64 = true;
} else if (val == PluginConfigParams::NO) {
enableNativeI64 = false;
} else {
IE_THROW() << "Wrong value for property key " << PluginConfigInternalParams::KEY_CPU_NATIVE_I64 << ": " << val
<< ". Expected only YES or NO values.";
}
} else {
IE_THROW(NotFound) << "Unsupported property " << key << " by CPU plugin";
}
Expand Down Expand Up @@ -314,4 +323,4 @@ void Config::updateProperties() {
}

} // namespace intel_cpu
} // namespace ov
} // namespace ov
1 change: 1 addition & 0 deletions src/plugins/intel_cpu/src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ struct Config {
// TODO: Executor cache may leads to incorrect behavior on oneDNN ACL primitives
size_t rtCacheCapacity = 0ul;
#endif
bool enableNativeI64 = false;
InferenceEngine::IStreamsExecutor::Config streamExecutorConfig;
InferenceEngine::PerfHintsConfig perfHintsConfig;
bool enableCpuPinning = true;
Expand Down
56 changes: 29 additions & 27 deletions src/plugins/intel_cpu/src/dnnl_extension_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,43 @@

#include "dnnl_extension_utils.h"

#include "utils/general_utils.h"
#include <oneapi/dnnl/dnnl.hpp>
#include "memory_desc/dnnl_blocked_memory_desc.h"
#include "onednn/iml_type_mapper.h"
#include <common/primitive_desc.hpp>
#include <common/primitive_desc_iface.hpp>

#include <vector>

using namespace dnnl;

namespace ov {
namespace intel_cpu {

uint8_t DnnlExtensionUtils::sizeOfDataType(dnnl::memory::data_type dataType) {
uint8_t DnnlExtensionUtils::sizeOfDataType(memory::data_type dataType) {
switch (dataType) {
case dnnl::memory::data_type::f32:
return 4;
case dnnl::memory::data_type::s32:
case memory::data_type::f64:
case memory::data_type::s64:
return 8;
case memory::data_type::f32:
case memory::data_type::s32:
return 4;
case dnnl::memory::data_type::bf16:
case memory::data_type::bf16:
case memory::data_type::f16:
return 2;
case dnnl::memory::data_type::s8:
return 1;
case dnnl::memory::data_type::u8:
case memory::data_type::s8:
case memory::data_type::u8:
case memory::data_type::bin:
return 1;
case dnnl::memory::data_type::bin:
return 1;
case dnnl::memory::data_type::f16:
return 2;
case dnnl::memory::data_type::undef:
case memory::data_type::undef:
return 0;
default:
IE_THROW() << "Unsupported data type.";
IE_THROW() << "Unsupported data type: " << DataTypeToIEPrecision(dataType);
}
}

memory::data_type DnnlExtensionUtils::IEPrecisionToDataType(const InferenceEngine::Precision& prec) {
switch (prec) {
case InferenceEngine::Precision::FP64:
return memory::data_type::f64;
case InferenceEngine::Precision::I64:
return memory::data_type::s64;
case InferenceEngine::Precision::FP32:
return memory::data_type::f32;
case InferenceEngine::Precision::I32:
Expand All @@ -68,6 +66,10 @@ memory::data_type DnnlExtensionUtils::IEPrecisionToDataType(const InferenceEngin

InferenceEngine::Precision DnnlExtensionUtils::DataTypeToIEPrecision(memory::data_type dataType) {
switch (dataType) {
case memory::data_type::f64:
return InferenceEngine::Precision::FP64;
case memory::data_type::s64:
return InferenceEngine::Precision::I64;
case memory::data_type::f32:
return InferenceEngine::Precision::FP32;
case memory::data_type::s32:
Expand All @@ -90,11 +92,11 @@ InferenceEngine::Precision DnnlExtensionUtils::DataTypeToIEPrecision(memory::dat
}
}

Dim DnnlExtensionUtils::convertToDim(const dnnl::memory::dim &dim) {
Dim DnnlExtensionUtils::convertToDim(const memory::dim &dim) {
return dim == DNNL_RUNTIME_DIM_VAL ? Shape::UNDEFINED_DIM : static_cast<size_t>(dim);
}
dnnl::memory::dim DnnlExtensionUtils::convertToDnnlDim(const Dim &dim) {
return dim == Shape::UNDEFINED_DIM ? DNNL_RUNTIME_DIM_VAL : static_cast<dnnl::memory::dim>(dim);
memory::dim DnnlExtensionUtils::convertToDnnlDim(const Dim &dim) {
return dim == Shape::UNDEFINED_DIM ? DNNL_RUNTIME_DIM_VAL : static_cast<memory::dim>(dim);
}

VectorDims DnnlExtensionUtils::convertToVectorDims(const memory::dims& dims) {
Expand Down Expand Up @@ -133,19 +135,19 @@ memory::format_tag DnnlExtensionUtils::GetPlainFormatByRank(size_t rank) {
}
}

DnnlMemoryDescPtr DnnlExtensionUtils::makeDescriptor(const dnnl::memory::desc &desc) {
DnnlMemoryDescPtr DnnlExtensionUtils::makeDescriptor(const memory::desc &desc) {
return makeDescriptor(desc.get());
}

DnnlMemoryDescPtr DnnlExtensionUtils::makeDescriptor(const_dnnl_memory_desc_t desc) {
if (desc->format_kind == dnnl::impl::format_kind_t::dnnl_blocked) {
if (desc->format_kind == impl::format_kind_t::dnnl_blocked) {
return std::shared_ptr<DnnlBlockedMemoryDesc>(new DnnlBlockedMemoryDesc(desc));
} else {
return std::shared_ptr<DnnlMemoryDesc>(new DnnlMemoryDesc(desc));
}
}

size_t DnnlExtensionUtils::getMemSizeForDnnlDesc(const dnnl::memory::desc& desc) {
size_t DnnlExtensionUtils::getMemSizeForDnnlDesc(const memory::desc& desc) {
auto tmpDesc = desc;

const auto offset0 = tmpDesc.get()->offset0;
Expand All @@ -167,8 +169,8 @@ std::shared_ptr<DnnlBlockedMemoryDesc> DnnlExtensionUtils::makeUndefinedDesc(con
}
}

DnnlMemoryDescPtr DnnlExtensionUtils::query_md(const const_dnnl_primitive_desc_t& pd, const dnnl::query& what, int idx) {
auto query = dnnl::convert_to_c(what);
DnnlMemoryDescPtr DnnlExtensionUtils::query_md(const const_dnnl_primitive_desc_t& pd, const query& what, int idx) {
auto query = convert_to_c(what);
const auto* cdesc = dnnl_primitive_desc_query_md(pd, query, idx);

if (!cdesc)
Expand Down
Loading