!1371 separate py from debug and utils

Merge pull request !1371 from leopz/tensor_utils
pull/1371/MERGE
mindspore-ci-bot 5 years ago committed by Gitee
commit ad21780a54

@ -6,6 +6,7 @@ set(_DEBUG_SRC_LIST
"${CMAKE_CURRENT_SOURCE_DIR}/info.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/label.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/trace_info.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/trace_base.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/trace.cc"
)

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -20,7 +20,7 @@
#include <sstream>
#include <climits>
#include "ir/anf.h"
#include "utils/convert_utils.h"
#include "utils/convert_utils_base.h"
namespace mindspore {
std::string HighLightLine(const std::string &line, int col_begin, int col_end, SourceLineTip tip) {

@ -54,91 +54,6 @@ std::string GetAbstractStr(const abstract::AbstractBasePtr &abs) {
return oss.str();
}
std::vector<DebugInfoPtr> GetSourceCodeDebugInfoVec(DebugInfoPtr debug_info) {
std::vector<DebugInfoPtr> debug_with_loc_vec;
while (debug_info != nullptr) {
if (debug_info->location() != nullptr) {
debug_with_loc_vec.push_back(debug_info);
}
if (debug_info->trace_info() != nullptr) {
debug_info = debug_info->trace_info()->debug_info();
} else {
break;
}
}
return debug_with_loc_vec;
}
DebugInfoPtr GetSourceCodeDebugInfo(const DebugInfoPtr &info) {
auto debug_with_loc_vec = GetSourceCodeDebugInfoVec(info);
if (debug_with_loc_vec.size() > 0) {
return debug_with_loc_vec[0];
} else {
return info;
}
}
std::string GetDebugInfo(const DebugInfoPtr &info, SourceLineTip tip) {
if (info == nullptr) {
return "";
}
auto src_info = GetSourceCodeDebugInfo(info);
if (src_info->location() != nullptr) {
return src_info->location()->ToString(tip);
}
return "";
}
// a trace info identifies a node transform, so we can trace the node transform through
// a link of trace info and debug info
std::string GetInfoWithAction(const std::vector<DebugInfoPtr> &info_vec, SourceLineTip tip) {
if (info_vec.size() < 1) {
return "";
}
if (info_vec.size() == 1) {
return info_vec[0]->location()->ToString(tip);
}
std::string traced_info = info_vec[0]->location()->ToString(tip);
for (size_t i = 1; i < info_vec.size(); i++) {
auto action_name = info_vec[i - 1]->trace_info()->GetActionBetweenNode(info_vec[i]);
if (action_name == "") {
break;
}
traced_info = traced_info + action_name + info_vec[i]->location()->ToString(tip);
}
return traced_info;
}
std::string GetTracedDebugInfo(const DebugInfoPtr &info, SourceLineTip tip) {
if (info == nullptr) {
return "";
}
auto info_vec = GetSourceCodeDebugInfoVec(info);
if (info_vec.size() == 0) {
return "";
} else if (info_vec.size() == 1) {
return info_vec[0]->location()->ToString(tip);
} else if (info_vec.size() > 1) {
return GetInfoWithAction(info_vec, tip);
}
return "";
}
std::string GetDebugInfo(const DebugInfoPtr &info, const std::string &prefix, SourceLineTip tip) {
std::ostringstream oss;
if (info == nullptr) {
return "";
}
auto debug_info = GetTracedDebugInfo(info, tip);
if (tip == kSourceLineTipDiscard) {
std::replace(debug_info.begin(), debug_info.end(), '\r', '/');
std::replace(debug_info.begin(), debug_info.end(), '\n', '/');
}
oss << prefix << debug_info;
return oss.str();
}
std::string GetGraphParamString(const FuncGraphPtr &graph, abstract::AbstractBasePtrList args_spec_list) {
std::ostringstream oss;
oss << "graph:" << graph->ToString() << " with args[";

@ -23,17 +23,15 @@
#include <utility>
#include <stack>
#include "debug/trace_base.h"
#include "debug/info.h"
#include "ir/anf.h"
#include "utils/any.h"
#include "ir/func_graph.h"
#include "debug/info.h"
#include "pipeline/static_analysis/static_analysis.h"
#include "utils/any.h"
namespace mindspore {
namespace trace {
std::string GetDebugInfo(const DebugInfoPtr &info, SourceLineTip tip = kSourceLineTipNextLine);
std::string GetDebugInfo(const DebugInfoPtr &info, const std::string &prefix,
SourceLineTip tip = kSourceLineTipNextLine);
DebugInfoPtr GetSourceCodeDebugInfo(const DebugInfoPtr &info);
void TraceGraphEval();
void GetEvalStackInfo(std::ostringstream &oss);

@ -0,0 +1,120 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed 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.
*/
#include "debug/trace_base.h"
#include <iostream>
#include <fstream>
#include <map>
#include <unordered_map>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <stack>
#include <algorithm>
#include "utils/graph_utils.h"
namespace mindspore {
// namespace to support debug trace infomation
namespace trace {
std::vector<DebugInfoPtr> GetSourceCodeDebugInfoVec(DebugInfoPtr debug_info) {
std::vector<DebugInfoPtr> debug_with_loc_vec;
while (debug_info != nullptr) {
if (debug_info->location() != nullptr) {
debug_with_loc_vec.push_back(debug_info);
}
if (debug_info->trace_info() != nullptr) {
debug_info = debug_info->trace_info()->debug_info();
} else {
break;
}
}
return debug_with_loc_vec;
}
DebugInfoPtr GetSourceCodeDebugInfo(const DebugInfoPtr &info) {
auto debug_with_loc_vec = GetSourceCodeDebugInfoVec(info);
if (debug_with_loc_vec.size() > 0) {
return debug_with_loc_vec[0];
} else {
return info;
}
}
std::string GetDebugInfo(const DebugInfoPtr &info, SourceLineTip tip) {
if (info == nullptr) {
return "";
}
auto src_info = GetSourceCodeDebugInfo(info);
if (src_info->location() != nullptr) {
return src_info->location()->ToString(tip);
}
return "";
}
// a trace info identifies a node transform, so we can trace the node transform through
// a link of trace info and debug info
std::string GetInfoWithAction(const std::vector<DebugInfoPtr> &info_vec, SourceLineTip tip) {
if (info_vec.size() < 1) {
return "";
}
if (info_vec.size() == 1) {
return info_vec[0]->location()->ToString(tip);
}
std::string traced_info = info_vec[0]->location()->ToString(tip);
for (size_t i = 1; i < info_vec.size(); i++) {
auto action_name = info_vec[i - 1]->trace_info()->GetActionBetweenNode(info_vec[i]);
if (action_name == "") {
break;
}
traced_info = traced_info + action_name + info_vec[i]->location()->ToString(tip);
}
return traced_info;
}
std::string GetTracedDebugInfo(const DebugInfoPtr &info, SourceLineTip tip) {
if (info == nullptr) {
return "";
}
auto info_vec = GetSourceCodeDebugInfoVec(info);
if (info_vec.size() == 0) {
return "";
} else if (info_vec.size() == 1) {
return info_vec[0]->location()->ToString(tip);
} else if (info_vec.size() > 1) {
return GetInfoWithAction(info_vec, tip);
}
return "";
}
std::string GetDebugInfo(const DebugInfoPtr &info, const std::string &prefix, SourceLineTip tip) {
std::ostringstream oss;
if (info == nullptr) {
return "";
}
auto debug_info = GetTracedDebugInfo(info, tip);
if (tip == kSourceLineTipDiscard) {
std::replace(debug_info.begin(), debug_info.end(), '\r', '/');
std::replace(debug_info.begin(), debug_info.end(), '\n', '/');
}
oss << prefix << debug_info;
return oss.str();
}
} // namespace trace
} // namespace mindspore

@ -0,0 +1,39 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed 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.
*/
#ifndef MINDSPORE_CCSRC_DEBUG_TRACE_BASE_H_
#define MINDSPORE_CCSRC_DEBUG_TRACE_BASE_H_
#include <fstream>
#include <memory>
#include <string>
#include <vector>
#include <utility>
#include <stack>
#include "debug/info.h"
#include "ir/anf.h"
#include "ir/func_graph.h"
#include "utils/any.h"
namespace mindspore {
namespace trace {
std::string GetDebugInfo(const DebugInfoPtr &info, SourceLineTip tip = kSourceLineTipNextLine);
std::string GetDebugInfo(const DebugInfoPtr &info, const std::string &prefix,
SourceLineTip tip = kSourceLineTipNextLine);
} // namespace trace
} // namespace mindspore
#endif // MINDSPORE_CCSRC_DEBUG_TRACE_BASE_H_

@ -1,7 +1,7 @@
/**
* This is the C++ adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/).
*
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -17,12 +17,14 @@
*/
#include "ir/dtype/type.h"
#include <string>
#include <cstdlib>
#include <algorithm>
#include "utils/log_adapter.h"
#include <cstdlib>
#include <string>
#include "ir/dtype/number.h"
#include "utils/convert_utils.h"
#include "utils/log_adapter.h"
#include "utils/convert_utils_base.h"
namespace mindspore {
TypeId IntBitsToTypeId(const int nbits) {

@ -1,7 +1,7 @@
/**
* This is the C++ adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/).
*
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -31,6 +31,7 @@
#include <type_traits>
#include <unordered_map>
#include <algorithm>
#include "ir/base.h"
#include "ir/named.h"

@ -27,7 +27,7 @@
#include "operator/ops.h"
#include "pybind_api/export_flags.h"
#include "utils/ordered_set.h"
#include "utils/convert_utils.h"
#include "utils/convert_utils_base.h"
namespace mindspore {
/*

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -21,6 +21,7 @@
#include "ir/manager.h"
#include "ir/param_value_py.h"
#include "operator/ops.h"
#include "utils/convert_utils_base.h"
#include "utils/log_adapter.h"
#include "utils/profile.h"
#include "utils/context/ms_context.h"

@ -22,11 +22,11 @@
#include <numeric>
#include <list>
#include "debug/trace_base.h"
#include "ir/func_graph.h"
#include "utils/profile.h"
#include "utils/convert_utils.h"
#include "utils/convert_utils_base.h"
#include "operator/ops.h"
#include "debug/trace.h"
namespace mindspore {

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -23,7 +23,7 @@
#include "pipeline/parse/python_adapter.h"
#include "pipeline/parse/data_converter.h"
#include "pybind11/pytypes.h"
#include "utils/convert_utils.h"
#include "utils/convert_utils_base.h"
#include "utils/primitive_utils.h"
#include "pybind_api/api_register.h"

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -15,11 +15,13 @@
*/
#include "ir/value.h"
#include <algorithm>
#include <memory>
#include <cmath>
#include <cfloat>
#include "utils/convert_utils.h"
#include "utils/convert_utils_base.h"
namespace mindspore {
const ValuePtr ValueSequeue::operator[](const std::size_t &dim) const {

@ -1,7 +1,7 @@
/**
* This is the C++ adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/).
*
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -33,7 +33,6 @@
#include "utils/config_manager.h"
#include "utils/convert_utils.h"
#include "utils/utils.h"
#include "utils/base_ref.h"
#include "vm/segment_runner.h"
#include "parallel/context.h"
#include "parallel/graph_util/get_parallel_info.h"

@ -24,6 +24,8 @@
#include <unordered_map>
#include <map>
#include <mutex>
#include "utils/base_ref_extends.h"
#include "debug/draw.h"
#include "ir/anf.h"
#include "ir/tensor.h"

@ -1,7 +1,7 @@
/**
* This is the C++ adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/).
*
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,6 +26,7 @@
#include "optimizer/opt.h"
#include "ir/anf.h"
#include "utils/convert_utils_base.h"
#include "utils/overload.h"
namespace mindspore {

@ -42,6 +42,7 @@
#include "device/kernel_runtime_manager.h"
#include "kernel/tbe/tbe_python_funcs.h"
#include "utils/config_manager.h"
#include "utils/base_ref_extends.h"
namespace mindspore {
namespace session {

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -27,6 +27,7 @@
#include "common/utils.h"
#include "common/trans.h"
#include "utils/context/ms_context.h"
#include "utils/base_ref_extends.h"
namespace mindspore {
namespace session {

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -22,12 +22,13 @@
#include <utility>
#include <memory>
#include <map>
#include "utils/base_ref_extends.h"
#include "session/session_context.h"
#include "session/kernel_graph.h"
#include "ir/anf.h"
#include "ir/tensor.h"
#include "utils/any.h"
#include "utils/base_ref.h"
#include "utils/contract.h"
#include "pynative/pynative_execute.h"
#include "device/kernel_info.h"

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -30,11 +30,6 @@ bool AnyIsLiteral(const Any &any) {
return typeid_int == typeid_any || typeid_float == typeid_any || typeid_bool == typeid_any;
}
std::ostream &operator<<(std::ostream &os, const pybind11::object &obj) {
os << "[py::object]";
return os;
}
Any &Any::operator=(const Any &other) {
if (m_ptr == other.m_ptr || &other == this) {
return *this;

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,8 +26,6 @@
#include <vector>
#include <utility>
#include "pybind11/pybind11.h"
#include "utils/overload.h"
#include "utils/log_adapter.h"
#include "utils/misc.h"
@ -39,8 +37,6 @@ std::string type(const T &t) {
return demangle(typeid(t).name());
}
std::ostream &operator<<(std::ostream &os, const pybind11::object &obj);
class Any {
public:
// constructors

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -185,13 +185,4 @@ bool RunFunctionRef::operator==(const BaseRef &other) const {
}
bool RunFunctionRef::operator==(const RunFunctionRef &other) const { return func_ == other.func_; }
bool PyObjectRef::operator==(const BaseRef &other) const {
if (!utils::isa<PyObjectRef>(other)) {
return false;
}
return *this == utils::cast<PyObjectRef>(other);
}
bool PyObjectRef::operator==(const PyObjectRef &other) const { return object_ == other.object_; }
} // namespace mindspore

@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -25,20 +25,16 @@
#include <sstream>
#include <utility>
#include <iterator>
#include "pybind11/pybind11.h"
#include "ir/value.h"
namespace py = pybind11;
#include "ir/value.h"
namespace mindspore {
class BaseRef;
class VectorRef;
class SetRef;
class PyObjectRef;
class RunFunctionRef;
using iterator = std::vector<BaseRef>::iterator;
using const_iterator = std::vector<BaseRef>::const_iterator;
using const_reverse_iterator = std::vector<BaseRef>::const_reverse_iterator;
@ -88,8 +84,6 @@ inline std::shared_ptr<VectorRef> MakeNode(const AnfNodePtrList &a) {
}
inline std::shared_ptr<SetRef> MakeNode(const SetRef &a) { return std::make_shared<SetRef>(std::move(a)); }
inline std::shared_ptr<RunFunctionRef> MakeNode(const RunFuncPtr &a) { return std::make_shared<RunFunctionRef>(a); }
inline std::shared_ptr<PyObjectRef> MakeNode(const py::object &a) { return std::make_shared<PyObjectRef>(a); }
inline std::shared_ptr<PyObjectRef> MakeNode(const py::tuple &a) { return std::make_shared<PyObjectRef>(a); }
class BaseRef : public Base {
public:
@ -367,24 +361,6 @@ class SetRef : public BaseRef {
using SetRefPtr = std::shared_ptr<SetRef>;
class PyObjectRef : public BaseRef {
public:
explicit PyObjectRef(const py::object &py_object) : object_(py_object) {}
explicit PyObjectRef(const py::tuple &tuple_obj) : object_(tuple_obj) {}
~PyObjectRef() override = default;
std::shared_ptr<Base> copy() const override { return std::make_shared<PyObjectRef>(object_); }
MS_DECLARE_PARENT(PyObjectRef, BaseRef)
uint32_t type() const override { return tid(); }
std::string ToString() const override { return py::str(object_); }
bool operator==(const BaseRef &other) const override;
bool operator==(const PyObjectRef &other) const;
py::object object_;
};
class RunFunctionRef : public BaseRef {
public:
RunFunctionRef() {}

@ -0,0 +1,28 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed 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.
*/
#include "utils/base_ref_extends.h"
namespace mindspore {
bool PyObjectRef::operator==(const BaseRef &other) const {
if (!utils::isa<PyObjectRef>(other)) {
return false;
}
return *this == utils::cast<PyObjectRef>(other);
}
bool PyObjectRef::operator==(const PyObjectRef &other) const { return object_ == other.object_; }
} // namespace mindspore

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save