Skip to content
4 changes: 2 additions & 2 deletions include/tvm/ir/attrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
#define TVM_IR_ATTRS_H_

#include <tvm/ffi/container/map.h>
#include <tvm/ffi/extra/structural_equal.h>
#include <tvm/ffi/extra/structural_hash.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/reflection/accessor.h>
#include <tvm/ffi/reflection/registry.h>
#include <tvm/ir/expr.h>
#include <tvm/node/structural_equal.h>
#include <tvm/node/structural_hash.h>

#include <functional>
#include <string>
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/ir/env_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include <tvm/ffi/function.h>
#include <tvm/ffi/reflection/registry.h>
#include <tvm/node/node.h>
#include <tvm/runtime/object.h>

#include <string>
#include <utility>
Expand Down
4 changes: 3 additions & 1 deletion include/tvm/ir/expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
#include <tvm/ffi/string.h>
#include <tvm/ir/source_map.h>
#include <tvm/ir/type.h>
#include <tvm/node/node.h>
#include <tvm/node/cast.h>
#include <tvm/node/repr_printer.h>
#include <tvm/node/script_printer.h>
#include <tvm/runtime/object.h>

#include <algorithm>
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/ir/instrument.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#include <tvm/ffi/reflection/registry.h>
#include <tvm/ffi/string.h>
#include <tvm/node/node.h>
#include <tvm/runtime/object.h>

#include <utility>
#include <vector>
Expand Down
1 change: 1 addition & 0 deletions include/tvm/ir/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <tvm/ir/global_info.h>
#include <tvm/ir/source_map.h>
#include <tvm/ir/type.h>
#include <tvm/node/script_printer.h>

#include <string>
#include <unordered_map>
Expand Down
55 changes: 55 additions & 0 deletions include/tvm/ir/serialization.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/*!
* \file tvm/ir/serialization.h
* \brief Utility functions for serialization.
*
* This is a thin forwarding header to ffi/extra/serialization.h.
* Prefer using ffi::ToJSONGraph / ffi::FromJSONGraph directly.
*/
#ifndef TVM_IR_SERIALIZATION_H_
#define TVM_IR_SERIALIZATION_H_

#include <tvm/ffi/extra/json.h>
#include <tvm/ffi/extra/serialization.h>
#include <tvm/runtime/base.h>

#include <string>

namespace tvm {

/*!
* \brief Save the node as well as all the node it depends on as json.
* This can be used to serialize any TVM object.
*
* \return the string representation of the node.
*/
TVM_DLL std::string SaveJSON(ffi::Any node);

/*!
* \brief Load tvm Node object from json and return a shared_ptr of Node.
* \param json_str The json string to load from.
*
* \return The shared_ptr of the Node.
*/
TVM_DLL ffi::Any LoadJSON(std::string json_str);

} // namespace tvm
#endif // TVM_IR_SERIALIZATION_H_
2 changes: 1 addition & 1 deletion include/tvm/ir/source_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
#ifndef TVM_IR_SOURCE_MAP_H_
#define TVM_IR_SOURCE_MAP_H_

#include <tvm/ffi/container/array.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/reflection/registry.h>
#include <tvm/node/node.h>
#include <tvm/runtime/object.h>

#include <fstream>
Expand Down
1 change: 0 additions & 1 deletion include/tvm/ir/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
#include <tvm/ffi/container/array.h>
#include <tvm/ffi/reflection/registry.h>
#include <tvm/ir/source_map.h>
#include <tvm/node/node.h>
#include <tvm/runtime/data_type.h>
#include <tvm/runtime/object.h>

Expand Down
63 changes: 0 additions & 63 deletions include/tvm/node/node.h

This file was deleted.

41 changes: 0 additions & 41 deletions include/tvm/node/reflection.h

This file was deleted.

27 changes: 3 additions & 24 deletions include/tvm/node/serialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,13 @@
*/

/*!
* Utility functions for serialization.
* \file tvm/node/serialization.h
* \brief Forwarding header. Use tvm/ir/serialization.h instead.
*/
#ifndef TVM_NODE_SERIALIZATION_H_
#define TVM_NODE_SERIALIZATION_H_

#include <tvm/runtime/base.h>
#include <tvm/runtime/object.h>
// This header has moved to tvm/ir/serialization.h
#include <tvm/ir/serialization.h>

#include <string>

namespace tvm {
/*!
* \brief save the node as well as all the node it depends on as json.
* This can be used to serialize any TVM object
*
* \return the string representation of the node.
*/
TVM_DLL std::string SaveJSON(ffi::Any node);

/*!
* \brief Internal implementation of LoadJSON
* Load tvm Node object from json and return a shared_ptr of Node.
* \param json_str The json string to load from.
*
* \return The shared_ptr of the Node.
*/
TVM_DLL ffi::Any LoadJSON(std::string json_str);

} // namespace tvm
#endif // TVM_NODE_SERIALIZATION_H_
90 changes: 3 additions & 87 deletions include/tvm/node/structural_equal.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,96 +18,12 @@
*/
/*!
* \file tvm/node/structural_equal.h
* \brief Structural equality comparison.
* \brief Forwarding header. Use tvm/ffi/extra/structural_equal.h instead.
*/
#ifndef TVM_NODE_STRUCTURAL_EQUAL_H_
#define TVM_NODE_STRUCTURAL_EQUAL_H_

#include <tvm/ffi/container/array.h>
#include <tvm/ffi/reflection/access_path.h>
#include <tvm/node/functor.h>
#include <tvm/runtime/data_type.h>
// This header has moved to tvm/ffi/extra/structural_equal.h
#include <tvm/ffi/extra/structural_equal.h>

#include <cmath>
#include <string>

namespace tvm {

/*!
* \brief Equality definition of base value class.
*/
class BaseValueEqual {
public:
bool operator()(const double& lhs, const double& rhs) const {
if (std::isnan(lhs) && std::isnan(rhs)) {
// IEEE floats do not compare as equivalent to each other.
// However, for the purpose of comparing IR representation, two
// NaN values are equivalent.
return true;
} else if (std::isnan(lhs) || std::isnan(rhs)) {
return false;
} else if (lhs == rhs) {
return true;
} else {
// fuzzy float pt comparison
constexpr double atol = 1e-9;
double diff = lhs - rhs;
return diff > -atol && diff < atol;
}
}

bool operator()(const int64_t& lhs, const int64_t& rhs) const { return lhs == rhs; }
bool operator()(const uint64_t& lhs, const uint64_t& rhs) const { return lhs == rhs; }
bool operator()(const ffi::Optional<int64_t>& lhs, const ffi::Optional<int64_t>& rhs) const {
return lhs == rhs;
}
bool operator()(const ffi::Optional<double>& lhs, const ffi::Optional<double>& rhs) const {
return lhs == rhs;
}
bool operator()(const int& lhs, const int& rhs) const { return lhs == rhs; }
bool operator()(const bool& lhs, const bool& rhs) const { return lhs == rhs; }
bool operator()(const std::string& lhs, const std::string& rhs) const { return lhs == rhs; }
bool operator()(const DataType& lhs, const DataType& rhs) const { return lhs == rhs; }
template <typename ENum, typename = typename std::enable_if<std::is_enum<ENum>::value>::type>
bool operator()(const ENum& lhs, const ENum& rhs) const {
return lhs == rhs;
}
};

/*!
* \brief Content-aware structural equality comparator for objects.
*
* The structural equality is recursively defined in the DAG of IR nodes via SEqual.
* There are two kinds of nodes:
*
* - Graph node: a graph node in lhs can only be mapped as equal to
* one and only one graph node in rhs.
* - Normal node: equality is recursively defined without the restriction
* of graph nodes.
*
* Vars(tir::Var, relax::Var) nodes are graph nodes.
*
* A var-type node(e.g. tir::Var) can be mapped as equal to another var
* with the same type if one of the following condition holds:
*
* - They appear in a same definition point(e.g. function argument).
* - They points to the same VarNode via the same_as relation.
* - They appear in a same usage point, and map_free_vars is set to be True.
*/
class StructuralEqual : public BaseValueEqual {
public:
// inheritate operator()
using BaseValueEqual::operator();
/*!
* \brief Compare objects via strutural equal.
* \param lhs The left operand.
* \param rhs The right operand.
* \param map_free_params Whether or not to map free variables.
* \return The comparison result.
*/
TVM_DLL bool operator()(const ffi::Any& lhs, const ffi::Any& rhs,
const bool map_free_params = false) const;
};

} // namespace tvm
#endif // TVM_NODE_STRUCTURAL_EQUAL_H_
Loading
Loading