[IE][nG][LoadTime] speed up constant folding (#15476)
* speed up constant folding and improved load time for FP16 * fix unit-tests * added OPENVINO_SUPPRESS_DEPRECATED_START * new evaluate for Convert; added constructor for Constant; constant copying by reference during constant_fold * removed deprecation macro from Convert evaluate * returned back Convert evaluate to old HostTensorPtr because it's used in tests accuracy comparator
This commit is contained in:
parent
b300df1be6
commit
63dd0685fc
@ -30,6 +30,10 @@ public:
|
|||||||
/// \param tensor The tensor with data
|
/// \param tensor The tensor with data
|
||||||
Constant(const std::shared_ptr<ngraph::runtime::Tensor>& tensor);
|
Constant(const std::shared_ptr<ngraph::runtime::Tensor>& tensor);
|
||||||
|
|
||||||
|
/// \brief Initialize a constant from ov::Tensor
|
||||||
|
/// \param tensor The ov::Tensor with data
|
||||||
|
Constant(const ov::Tensor& tensor);
|
||||||
|
|
||||||
/// \brief Constructs a tensor constant.
|
/// \brief Constructs a tensor constant.
|
||||||
///
|
///
|
||||||
/// \param type The element type of the tensor constant.
|
/// \param type The element type of the tensor constant.
|
||||||
|
@ -794,8 +794,8 @@ bool ov::Node::constant_fold(OutputVector& output_values, const OutputVector& in
|
|||||||
for (const auto& input : input_values) {
|
for (const auto& input : input_values) {
|
||||||
nodes.push_back(input.get_node_shared_ptr());
|
nodes.push_back(input.get_node_shared_ptr());
|
||||||
auto constant = ov::as_type_ptr<ngraph::op::v0::Constant>(input.get_node_shared_ptr());
|
auto constant = ov::as_type_ptr<ngraph::op::v0::Constant>(input.get_node_shared_ptr());
|
||||||
auto tensor = ov::Tensor(input.get_element_type(), input.get_shape());
|
void* data = (void*)constant->get_data_ptr();
|
||||||
std::copy_n(constant->get_data_ptr<uint8_t>(), constant->get_byte_size(), static_cast<uint8_t*>(tensor.data()));
|
auto tensor = ov::Tensor(input.get_element_type(), input.get_shape(), data);
|
||||||
input_tensors.push_back(tensor);
|
input_tensors.push_back(tensor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -807,9 +807,7 @@ bool ov::Node::constant_fold(OutputVector& output_values, const OutputVector& in
|
|||||||
OPENVINO_SUPPRESS_DEPRECATED_START
|
OPENVINO_SUPPRESS_DEPRECATED_START
|
||||||
if (evaluate(output_tensors, input_tensors)) {
|
if (evaluate(output_tensors, input_tensors)) {
|
||||||
for (size_t i = 0; i < output_tensors.size(); ++i) {
|
for (size_t i = 0; i < output_tensors.size(); ++i) {
|
||||||
output_values[i] = make_shared<ngraph::op::Constant>(output_tensors[i].get_element_type(),
|
output_values[i] = make_shared<ngraph::op::Constant>(output_tensors[i]);
|
||||||
output_tensors[i].get_shape(),
|
|
||||||
output_tensors[i].data());
|
|
||||||
copy_runtime_info(nodes, output_values[i].get_node_shared_ptr());
|
copy_runtime_info(nodes, output_values[i].get_node_shared_ptr());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -50,6 +50,17 @@ ov::op::v0::Constant::Constant(const shared_ptr<ngraph::runtime::Tensor>& tensor
|
|||||||
constructor_validate_and_infer_types();
|
constructor_validate_and_infer_types();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ov::op::v0::Constant::Constant(const ov::Tensor& tensor) {
|
||||||
|
m_element_type = tensor.get_element_type();
|
||||||
|
m_shape = tensor.get_shape();
|
||||||
|
// Share data from ov::Tensor
|
||||||
|
m_data = make_shared<ngraph::runtime::SharedBuffer<ov::Tensor>>(static_cast<char*>(tensor.data()),
|
||||||
|
tensor.get_byte_size(),
|
||||||
|
tensor);
|
||||||
|
|
||||||
|
constructor_validate_and_infer_types();
|
||||||
|
}
|
||||||
|
|
||||||
ov::op::v0::Constant::Constant(const element::Type& type,
|
ov::op::v0::Constant::Constant(const element::Type& type,
|
||||||
const ov::Shape& shape,
|
const ov::Shape& shape,
|
||||||
const std::vector<std::string>& values)
|
const std::vector<std::string>& values)
|
||||||
|
Loading…
Reference in New Issue
Block a user