!1433 add tensor_minnie and separate py from ir

Merge pull request !1433 from leopz/tensor_base
pull/1433/MERGE
mindspore-ci-bot 5 years ago committed by Gitee
commit 04398cf88e

@ -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.
@ -34,6 +34,7 @@
#include "utils/ordered_set.h"
#include "utils/utils.h"
#include "debug/trace.h"
#include "debug/label.h"
#include "utils/context/ms_context.h"
#include "operator/ops.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.
@ -16,7 +16,9 @@
#include "debug/draw.h"
#include <algorithm>
#include <iostream>
#include <iterator>
#include <map>
#include <vector>
#include <string>
@ -28,7 +30,7 @@
#include "utils/graph_utils.h"
#include "utils/utils.h"
#include "operator/composite/composite.h"
#include "ir/meta_tensor.h"
#include "ir/tensor.h"
namespace py = pybind11;
@ -323,15 +325,17 @@ void BaseDigraph::FuncGraphParameters(const FuncGraphPtr &key) {
auto py_p = param_value->value();
if (py::hasattr(py_p, "default_input")) {
py_p = py_p.attr("default_input");
std::vector<int> shape;
if (py::hasattr(py_p, PYTHON_TENSOR_FLAG)) {
auto m_tensor = py_p.cast<std::shared_ptr<tensor::Tensor>>();
py::tuple shape = m_tensor->GetPyTupleShape();
buffer_ << "[" << py::str(shape) << "]";
shape = m_tensor->shape();
} else if (py::hasattr(py_p, PYTHON_META_TENSOR_FLAG)) {
auto m_tensor = py_p.cast<std::shared_ptr<tensor::MetaTensor>>();
py::tuple shape = m_tensor->GetPyTupleShape();
buffer_ << "[" << py::str(shape) << "]";
shape = m_tensor->shape();
}
std::ostringstream shape_str;
std::copy(shape.begin(), shape.end(), std::ostream_iterator<int>(shape_str, ","));
buffer_ << "[" << shape_str.str() << "]";
}
}
buffer_ << "</td></tr>";

@ -1,5 +1,5 @@
/**
* Copyright 2020 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,7 +30,7 @@
#include "ir/meta_func_graph.h"
#include "utils/graph_utils.h"
#include "operator/composite/composite.h"
#include "ir/meta_tensor.h"
#include "ir/tensor.h"
#include "debug/anf_ir_utils.h"
#include "pipeline/static_analysis/evaluator.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.
@ -22,7 +22,7 @@
#include "device/kernel_runtime_manager.h"
#include "device/convert_tensor_utils.h"
#include "ir/dtype/type.h"
#include "ir/meta_tensor.h"
#include "ir/tensor.h"
#include "kernel/common_utils.h"
#include "utils/utils.h"
#include "common/utils.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.
@ -19,7 +19,7 @@
#include <iostream>
#include <vector>
#include "ir/meta_tensor.h"
#include "ir/tensor.h"
namespace mindspore {
namespace device {

@ -26,7 +26,7 @@
#include "session/kernel_graph.h"
#include "kernel/kernel_build_info.h"
#include "session/session_context.h"
#include "ir/meta_tensor.h"
#include "ir/tensor.h"
#include "device/ascend/profiling/profiling_utils.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.
@ -22,7 +22,7 @@
#include <map>
#include "device/device_address.h"
#include "ir/meta_tensor.h"
#include "ir/tensor.h"
#include "predict/generator/utils/ir_model_util.h"
#ifdef ENABLE_DUMP_E2E
#include "debug/e2e_dump.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.
@ -24,7 +24,7 @@
#include <unordered_map>
#include "ir/func_graph.h"
#include "ir/primitive.h"
#include "ir/primitive_base.h"
namespace mindspore {
// namespace to support intermediate representation definition

@ -25,6 +25,7 @@
#include "pipeline/static_analysis/static_analysis.h"
#include "operator/ops.h"
#include "parallel/ops_info/ops_utils.h"
#include "debug/label.h"
namespace mindspore {
// namespace to support intermediate representation definition

File diff suppressed because it is too large Load Diff

@ -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.
@ -30,9 +30,9 @@
#include "ir/anf.h"
#include "ir/manager.h"
#include "utils/any.h"
#include "utils/ordered_set.h"
#include "pipeline/static_analysis/abstract_value.h"
#include "utils/ordered_map.h"
#include "utils/base_ref.h"
namespace mindspore {
using BaseRefCounterMap = OrderedMap<BaseRef, int, BaseRefHash>;
@ -50,6 +50,16 @@ const char FUNC_GRAPH_FLAG_DEFER_INLINE[] = "defer_inline";
const char FUNC_GRAPH_FLAG_CORE[] = "core";
const char FUNC_GRAPH_FLAG_SPECIALIZE_PARAMETER[] = "spec_param";
namespace abstract {
class AbstractKeywordArg;
using AbstractKeywordArgPtr = std::shared_ptr<AbstractKeywordArg>;
class AbstractFunction;
using AbstractFunctionPtr = std::shared_ptr<AbstractFunction>;
} // namespace abstract
class FuncGraphManager;
using FuncGraphManagerPtr = std::shared_ptr<FuncGraphManager>;
// ANF transform class
// either a primitive or a func_graph
class FuncGraphTransform {

File diff suppressed because it is too large Load Diff

@ -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,11 +17,14 @@
*/
#include "ir/manager.h"
#include <algorithm>
#include <numeric>
#include <list>
#include "./common.h"
#include "ir/func_graph.h"
#include "utils/profile.h"
#include "utils/convert_utils.h"
#include "operator/ops.h"
#include "debug/trace.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.
@ -37,6 +37,7 @@
#include "utils/graph_utils.h"
#include "utils/counter.h"
#include "utils/hashing.h"
#include "utils/base_ref.h"
#include "ir/anf.h"
namespace mindspore {

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,41 @@
/**
* 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 "ir/meta_tensor.h"
#include <functional>
#include <numeric>
#include <vector>
#include <sstream>
#include <string>
#include "pipeline/static_analysis/abstract_value.h"
namespace mindspore {
namespace tensor {
abstract::AbstractBasePtr MetaTensor::ToAbstract() {
auto tens = shared_from_base<MetaTensor>();
auto dtype = tens->Dtype();
if (!IsSubType(dtype, kNumber)) {
MS_LOG(EXCEPTION) << "Expect MetaTensor type kNumber but got: " << dtype->ToString() << ".";
}
auto tensor_shape = tens->shape();
auto abs_tensor = std::make_shared<abstract::AbstractTensor>(dtype, tensor_shape);
abs_tensor->set_value(shared_from_base<MetaTensor>());
return abs_tensor;
}
} // namespace tensor
} // namespace mindspore

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -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,7 +22,7 @@
#include "ir/anf.h"
#include "ir/dtype.h"
#include "utils/utils.h"
#include "ir/meta_tensor.h"
#include "ir/tensor.h"
#include "pipeline/static_analysis/dshape.h"
#include "utils/log_adapter.h"

@ -14,8 +14,8 @@
* limitations under the License.
*/
#ifndef MINDSPORE_CCSRC_IR_PARAM_VALUE_MINNIE_H_
#define MINDSPORE_CCSRC_IR_PARAM_VALUE_MINNIE_H_
#ifndef MINDSPORE_CCSRC_MINNIE_PARAM_VALUE_MINNIE_H_
#define MINDSPORE_CCSRC_MINNIE_PARAM_VALUE_MINNIE_H_
#include <memory>
@ -39,5 +39,6 @@ class ParamValueMinnie : public ParamValue {
};
using ParamValueMinniePtr = std::shared_ptr<ParamValueMinnie>;
} // namespace mindspore
#endif // MINDSPORE_CCSRC_IR_PARAM_VALUE_MINNIE_H_
#endif // MINDSPORE_CCSRC_MINNIE_PARAM_VALUE_MINNIE_H_

@ -0,0 +1,34 @@
/**
* 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 "minnie/tensor_minnie.h"
namespace mindspore {
namespace tensor {
TensorMinnie &TensorMinnie::operator=(const TensorMinnie &tensor) {
if (&tensor == this) {
return *this;
}
this->tensor_addr_ = tensor.tensor_addr();
this->tensor_size_ = tensor.tensor_size();
return *this;
}
bool TensorMinnie::operator==(const TensorMinnie &tensor) {
return tensor_addr_ == tensor.tensor_addr() && tensor_size_ == tensor.tensor_size();
}
} // namespace tensor
} // namespace mindspore

@ -0,0 +1,77 @@
/**
* 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_MINNIE_TENSOR_MINNIE_H_
#define MINDSPORE_CCSRC_MINNIE_TENSOR_MINNIE_H_
#include <memory>
#include "ir/meta_tensor.h"
namespace mindspore {
namespace tensor {
// definition of Tensor Minnie
class TensorMinnie : public MetaTensor {
public:
TensorMinnie() : MetaTensor() {}
~TensorMinnie() override = default;
MS_DECLARE_PARENT(TensorMinnie, MetaTensor)
// brief Overloads operator = for TensorMinnie.
//
// The constructed TensorMinnie object has the same type and shape with tensor_base.
//
// param meta_tensor An existing TensorMinnie object.
virtual TensorMinnie &operator=(const TensorMinnie &tensor);
// brief Compares two TensorMinnie objects.
//
// The constructed TensorMinnie object has the same type and shape with tensor_base.
//
// param meta_tensor The TensorMinnie object to be compared.
// return true: If having same type and shape, return true, or return false.
virtual bool operator==(const TensorMinnie &tensor);
// brief Get the tensor's size for C++
//
// return size_t
size_t tensor_size() const { return tensor_size_; }
// brief Set Tensor data size for c++ type
void set_tensor_size(size_t size) { tensor_size_ = size; }
// brief Get Tensor data pointer for c++ type
//
// return The pointer to the object
void *tensor_addr() const { return tensor_addr_; }
// brief Set Tensor data pointer for c++ type
void set_tensor_addr(void *addr) { tensor_addr_ = addr; }
protected:
// brief Data addr of the tensor.
void *tensor_addr_;
// brief Data size of the tensor.
size_t tensor_size_;
};
using TensorMinniePtr = std::shared_ptr<TensorMinnie>;
} // namespace tensor
} // namespace mindspore
#endif // MINDSPORE_CCSRC_MINNIE_TENSOR_MINNIE_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.
@ -17,8 +17,6 @@
#include "operator/ops.h"
#include <memory>
#include <string>
#include "pipeline/parse/python_adapter.h"
#include "pipeline/parse/data_converter.h"
namespace mindspore {
// namespace to support primitive operators
@ -255,15 +253,5 @@ const PrimitivePtr kPrimScalarSummary = std::make_shared<Primitive>("ScalarSumma
const PrimitivePtr kPrimImageSummary = std::make_shared<Primitive>("ImageSummary");
const PrimitivePtr kPrimTensorSummary = std::make_shared<Primitive>("TensorSummary");
const PrimitivePtr kPrimHistogramSummary = std::make_shared<Primitive>("HistogramSummary");
ValuePtr GetPythonOps(const std::string &op_name, const std::string &module_name) {
py::object obj = parse::python_adapter::GetPyFn(module_name, op_name);
ValuePtr node = nullptr;
bool succ = parse::ConvertData(obj, &node);
if (!succ) {
MS_LOG(EXCEPTION) << "get Python op " << op_name << " from " << module_name << " fail";
}
return node;
}
} // namespace prim
} // 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,7 +21,7 @@
#include <string>
#include <memory>
#include "ir/anf.h"
#include "ir/primitive.h"
#include "ir/primitive_base.h"
namespace mindspore {
// namespace to support primitive operators

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

Loading…
Cancel
Save