-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Serialization of old API map in nGraph. (#7840)
* Added serialization of old API map in ngraph. * Changed order type to int64_t. * Fixed uint64_t error, added comments. * Apply suggestions from code review Co-authored-by: Gleb Kazantaev <[email protected]> * Added tests with undefined type and empty order. * Added set, get and has methods. * Fix in tests. * Apply suggestions from code review Co-authored-by: Ilya Churaev <[email protected]> * Made inline methods, changed to shared_ptr. * Small fix. * Moved methods to header file. * Small fix. Co-authored-by: Gleb Kazantaev <[email protected]> Co-authored-by: Ilya Churaev <[email protected]>
- Loading branch information
1 parent
e20cefb
commit 623117f
Showing
6 changed files
with
196 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
...ence-engine/src/transformations/include/transformations/rt_info/old_api_map_attribute.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// Copyright (C) 2018-2021 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
/** | ||
* @brief Defines old API map attribute | ||
* @file old_api_map_attribute.hpp | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <assert.h> | ||
|
||
#include <functional> | ||
#include <memory> | ||
#include <ngraph/attribute_visitor.hpp> | ||
#include <ngraph/node.hpp> | ||
#include <ngraph/variant.hpp> | ||
#include <openvino/core/rtti.hpp> | ||
#include <set> | ||
#include <string> | ||
#include <transformations_visibility.hpp> | ||
#include <utility> | ||
|
||
namespace ov { | ||
|
||
class OldApiMap; | ||
/** | ||
* @ingroup ie_runtime_attr_api | ||
* @brief OldApiMapAttr class stores the value of OldApiMap class. | ||
* | ||
* OldApiMap stores the following information. | ||
* Parameter: | ||
* Order of the transpose which should be applied to Parameter with old API layout to | ||
* obtain Parameter with new API layout. | ||
* Element type of the Parameter in old API. | ||
* | ||
* Result: | ||
* Order of the transpose which should be applied to Result with new API layout to | ||
* obtain Result with old API layout. | ||
* | ||
*/ | ||
class TRANSFORMATIONS_API OldApiMapAttr { | ||
private: | ||
std::vector<uint64_t> m_order; | ||
ngraph::element::Type m_legacy_type = ngraph::element::Type_t::undefined; | ||
|
||
public: | ||
friend class OldApiMap; | ||
|
||
/** | ||
* A default constructor | ||
*/ | ||
OldApiMapAttr() = default; | ||
|
||
/** | ||
* @brief Constructs a new OldApiMapAttr object. | ||
* @param[in] order Transpose order. | ||
* @param[in] legacy_type Legacy type. | ||
*/ | ||
explicit OldApiMapAttr(std::vector<uint64_t> order, const ngraph::element::Type& legacy_type) | ||
: m_order(std::move(order)), m_legacy_type(legacy_type) {} | ||
|
||
/** | ||
* @brief Returns the transpose order that should be used for obtain a node with old API layout. | ||
* @return transpose order. | ||
*/ | ||
const std::vector<uint64_t> & get_order() const { | ||
return m_order; | ||
} | ||
|
||
/** | ||
* @brief Returns the legacy type of the node. | ||
* @return legacy type. | ||
*/ | ||
ngraph::element::Type get_type() const { | ||
return m_legacy_type; | ||
} | ||
}; | ||
|
||
/** | ||
* @ingroup ie_runtime_attr_api | ||
* @brief OldApiMap class represents runtime info attribute that stores legacy type | ||
* and order of the transpose that is required for obtaining IR in old API. | ||
*/ | ||
class TRANSFORMATIONS_API OldApiMap : public VariantImpl<OldApiMapAttr> { | ||
public: | ||
OPENVINO_RTTI("old_api_map", "0"); | ||
|
||
/** | ||
* A default constructor | ||
*/ | ||
OldApiMap() = default; | ||
|
||
/** | ||
* Constructs a new OldApiMap object. | ||
* @param[in] value The object that stores values of OldApiMap. | ||
*/ | ||
OldApiMap(const value_type& value) : VariantImpl<value_type>(value) {} | ||
|
||
bool is_copyable() const override { | ||
return false; | ||
} | ||
|
||
bool visit_attributes(AttributeVisitor& visitor) override; | ||
}; | ||
|
||
inline bool has_old_api_map(const std::shared_ptr<Node>& node) { | ||
const auto& rt_map = node->get_rt_info(); | ||
return rt_map.count(OldApiMap::get_type_info_static()); | ||
} | ||
|
||
inline OldApiMap get_old_api_map(const std::shared_ptr<Node>& node) { | ||
const auto& rt_map = node->get_rt_info(); | ||
const auto& var = rt_map.at(OldApiMap::get_type_info_static()); | ||
return ngraph::as_type_ptr<OldApiMap>(var)->get(); | ||
} | ||
|
||
inline void set_old_api_map(std::shared_ptr<Node>& node, const OldApiMap& old_api_map) { | ||
auto& rt_map = node->get_rt_info(); | ||
rt_map[OldApiMap::get_type_info_static()] = std::make_shared<OldApiMap>(old_api_map); | ||
} | ||
|
||
} // namespace ov |
14 changes: 14 additions & 0 deletions
14
inference-engine/src/transformations/src/transformations/rt_info/old_api_map_attribute.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright (C) 2018-2021 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "transformations/rt_info/old_api_map_attribute.hpp" | ||
|
||
using namespace ov; | ||
|
||
bool OldApiMap::visit_attributes(AttributeVisitor& visitor) { | ||
visitor.on_attribute("order", m_value.m_order); | ||
visitor.on_attribute("element_type", m_value.m_legacy_type); | ||
return true; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters