parent
a58b1a1435
commit
dfbb232468
@ -0,0 +1,42 @@
|
||||
/**
|
||||
* 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_INCLUDE_MS_SESSION_H
|
||||
#define MINDSPORE_INCLUDE_MS_SESSION_H
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "include/ms_tensor.h"
|
||||
|
||||
namespace mindspore {
|
||||
class FuncGraph;
|
||||
namespace inference {
|
||||
class MS_API MSSession {
|
||||
public:
|
||||
MSSession() = default;
|
||||
|
||||
static std::shared_ptr<MSSession> CreateSession(const std::string &device, uint32_t device_id);
|
||||
|
||||
virtual uint32_t CompileGraph(std::shared_ptr<FuncGraph> funcGraphPtr) = 0;
|
||||
|
||||
virtual MultiTensor RunGraph(uint32_t graph_id, const std::vector<std::shared_ptr<inference::MSTensor>> &inputs) = 0;
|
||||
};
|
||||
|
||||
std::shared_ptr<FuncGraph> MS_API LoadModel(const char *model_buf, size_t size, const std::string &device);
|
||||
} // namespace inference
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_INCLUDE_MS_SESSION_H
|
@ -0,0 +1,69 @@
|
||||
/**
|
||||
* 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_INCLUDE_MS_TENSOR_H_
|
||||
#define MINDSPORE_INCLUDE_MS_TENSOR_H_
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include "ir/dtype/type_id.h"
|
||||
|
||||
namespace mindspore {
|
||||
#define MS_API __attribute__((visibility("default")))
|
||||
namespace inference {
|
||||
class MS_API MSTensor {
|
||||
public:
|
||||
MSTensor() = default;
|
||||
// brief Create a MSTensor pointer.
|
||||
//
|
||||
// param data_type DataTypeId of tensor to be created.
|
||||
// param shape Shape of tensor to be created.
|
||||
// return MSTensor pointer.
|
||||
static MSTensor *CreateTensor(TypeId data_type, const std::vector<int> &shape);
|
||||
|
||||
~MSTensor() = default;
|
||||
|
||||
virtual TypeId data_type() const = 0;
|
||||
|
||||
virtual TypeId set_data_type(const TypeId data_type) = 0;
|
||||
|
||||
virtual std::vector<int> shape() const = 0;
|
||||
|
||||
virtual size_t set_shape(const std::vector<int> &shape) = 0;
|
||||
|
||||
virtual int DimensionSize(size_t index) const = 0;
|
||||
// brief Get number of element in MSTensor.
|
||||
//
|
||||
// return Number of element in MSTensor.
|
||||
virtual int ElementsNum() const = 0;
|
||||
|
||||
virtual std::size_t hash() const = 0;
|
||||
// brief Get byte size of data in MSTensor.
|
||||
//
|
||||
// return Byte size of data in MSTensor.
|
||||
virtual size_t Size() const = 0;
|
||||
// brief Get pointer of data in MSTensor.
|
||||
//
|
||||
// The data pointer can be used to both write or read data in MSTensor.
|
||||
//
|
||||
// return A pointer points to data in MSTensor.
|
||||
virtual void *MutableData() const = 0;
|
||||
};
|
||||
using MultiTensor = std::vector<std::vector<std::shared_ptr<inference::MSTensor>>>;
|
||||
} // namespace inference
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_INCLUDE_MS_TENSOR_H_
|
@ -1,3 +1,7 @@
|
||||
file(GLOB_RECURSE _IR_SRC_LIST ./*.cc dtype/*.cc)
|
||||
file(GLOB_RECURSE _IR_LITE_SRC_FILES
|
||||
./lite/tensor.cc
|
||||
)
|
||||
list(REMOVE_ITEM _IR_SRC_LIST ${_IR_LITE_SRC_FILES})
|
||||
set_property(SOURCE ${_IR_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_IR)
|
||||
add_library(_mindspore_ir_obj OBJECT ${_IR_SRC_LIST})
|
||||
|
@ -0,0 +1,81 @@
|
||||
/**
|
||||
* This is the C++ adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/).
|
||||
*
|
||||
* 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.
|
||||
* 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_IR_DTYPE_TYPE_ID_H_
|
||||
#define MINDSPORE_CCSRC_IR_DTYPE_TYPE_ID_H_
|
||||
|
||||
namespace mindspore {
|
||||
//
|
||||
// Supported meta type
|
||||
//
|
||||
enum TypeId : int {
|
||||
kTypeUnknown = 0,
|
||||
kMetaTypeBegin = kTypeUnknown,
|
||||
kMetaTypeType, // Type
|
||||
kMetaTypeAnything,
|
||||
kMetaTypeObject,
|
||||
kMetaTypeTypeType, // TypeType
|
||||
kMetaTypeProblem,
|
||||
kMetaTypeExternal,
|
||||
kMetaTypeNone,
|
||||
kMetaTypeNull,
|
||||
kMetaTypeEllipsis,
|
||||
kMetaTypeEnd,
|
||||
//
|
||||
// Object types
|
||||
//
|
||||
kObjectTypeBegin = kMetaTypeEnd,
|
||||
kObjectTypeNumber,
|
||||
kObjectTypeString,
|
||||
kObjectTypeList,
|
||||
kObjectTypeTuple,
|
||||
kObjectTypeSlice,
|
||||
kObjectTypeKeyword,
|
||||
kObjectTypeTensorType,
|
||||
kObjectTypeClass,
|
||||
kObjectTypeDictionary,
|
||||
kObjectTypeFunction,
|
||||
kObjectTypeJTagged,
|
||||
kObjectTypeSymbolicKeyType,
|
||||
kObjectTypeEnvType,
|
||||
kObjectTypeRefKey,
|
||||
kObjectTypeRef,
|
||||
kObjectTypeEnd,
|
||||
//
|
||||
// Number Types
|
||||
//
|
||||
kNumberTypeBegin = kObjectTypeEnd,
|
||||
kNumberTypeBool,
|
||||
kNumberTypeInt,
|
||||
kNumberTypeInt8,
|
||||
kNumberTypeInt16,
|
||||
kNumberTypeInt32,
|
||||
kNumberTypeInt64,
|
||||
kNumberTypeUInt,
|
||||
kNumberTypeUInt8,
|
||||
kNumberTypeUInt16,
|
||||
kNumberTypeUInt32,
|
||||
kNumberTypeUInt64,
|
||||
kNumberTypeFloat,
|
||||
kNumberTypeFloat16,
|
||||
kNumberTypeFloat32,
|
||||
kNumberTypeFloat64,
|
||||
kNumberTypeEnd
|
||||
};
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_IR_DTYPE_TYPE_ID_H_
|
@ -0,0 +1,152 @@
|
||||
/**
|
||||
* 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 <vector>
|
||||
#include <utility>
|
||||
#include "ir/lite/tensor.h"
|
||||
#include "securec/include/securec.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace tensor {
|
||||
#define kMaxMallocSize 1024 * 1024 * 100
|
||||
Tensor::Tensor(const TypeId data_type, const std::vector<int> &shape) : MetaTensor(data_type, shape) {}
|
||||
|
||||
Tensor::Tensor(const TypePtr &type_ptr, const std::vector<int> &shape) : MetaTensor(type_ptr, shape) {}
|
||||
|
||||
Tensor::Tensor(const Tensor &tensor) : MetaTensor(tensor) {
|
||||
this->data_type_ = tensor.data_type_;
|
||||
this->shape_ = tensor.shape_;
|
||||
auto ret = CopyTensorData(tensor);
|
||||
if (0 != ret) {
|
||||
MS_LOG(EXCEPTION) << "CopyTensorData error";
|
||||
}
|
||||
}
|
||||
|
||||
int Tensor::CopyTensorData(const Tensor &srcTensor) {
|
||||
if (srcTensor.data_ == nullptr) {
|
||||
MS_LOG(ERROR) << "data of srcTensor is nullptr";
|
||||
return -1;
|
||||
}
|
||||
size_t data_size = this->Size();
|
||||
MS_ASSERT(data_size == tensor.Size());
|
||||
if (this->data_ == nullptr) {
|
||||
if (data_size > kMaxMallocSize) {
|
||||
MS_LOG(ERROR) << "Malloc size is too big while coping data, " << data_size << " bytes";
|
||||
return -1;
|
||||
}
|
||||
this->data_ = malloc(data_size);
|
||||
}
|
||||
memcpy_s(this->data_, data_size, tensor.data_, tensor.Size());
|
||||
return 0;
|
||||
}
|
||||
|
||||
Tensor::~Tensor() {
|
||||
if (nullptr != this->data_) {
|
||||
free(this->data_);
|
||||
}
|
||||
}
|
||||
|
||||
Tensor &Tensor::operator=(const Tensor &tensor) {
|
||||
if (&tensor == this) {
|
||||
return *this;
|
||||
}
|
||||
this->shape_ = tensor.shape_;
|
||||
this->data_type_ = tensor.data_type_;
|
||||
auto ret = CopyTensorData(tensor);
|
||||
if (0 != ret) {
|
||||
MS_LOG(EXCEPTION) << "CopyTensorData error";
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Tensor::operator==(const Tensor &tensor) {
|
||||
return data_ == tensor.data_ && shape_ == tensor.shape_ && data_type_ == tensor.data_type_;
|
||||
}
|
||||
|
||||
bool Tensor::operator==(const Value &other) const {
|
||||
if (other.isa<Tensor>()) {
|
||||
auto other_ = static_cast<const Tensor &>(other);
|
||||
return *this == other_;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} // namespace tensor
|
||||
|
||||
namespace inference {
|
||||
MSTensor *MSTensor::CreateTensor(TypeId data_type, const std::vector<int> &shape) {
|
||||
return new Tensor(data_type, shape);
|
||||
}
|
||||
|
||||
Tensor::Tensor() { this->tensor_impl_ = std::make_shared<tensor::Tensor>(); }
|
||||
|
||||
Tensor::Tensor(TypeId data_type, const std::vector<int> &shape) {
|
||||
this->tensor_impl_ = std::make_shared<tensor::Tensor>(data_type, shape);
|
||||
}
|
||||
|
||||
Tensor::Tensor(std::shared_ptr<tensor::Tensor> tensor_ptr) { this->tensor_impl_ = std::move(tensor_ptr); }
|
||||
|
||||
TypeId Tensor::data_type() const {
|
||||
MS_ASSERT(this->tensor_impl_ != nullptr);
|
||||
return this->tensor_impl_->data_type();
|
||||
}
|
||||
|
||||
TypeId Tensor::set_data_type(TypeId data_type) {
|
||||
MS_ASSERT(this->tensor_impl_ != nullptr);
|
||||
return this->tensor_impl_->set_data_type(data_type);
|
||||
}
|
||||
|
||||
std::vector<int> Tensor::shape() const {
|
||||
MS_ASSERT(this->tensor_impl_ != nullptr);
|
||||
return this->tensor_impl_->shape();
|
||||
}
|
||||
|
||||
size_t Tensor::set_shape(const std::vector<int> &shape) {
|
||||
MS_ASSERT(this->tensor_impl_ != nullptr);
|
||||
return this->tensor_impl_->set_shape(shape);
|
||||
}
|
||||
|
||||
int Tensor::DimensionSize(size_t index) const {
|
||||
MS_ASSERT(this->tensor_impl_ != nullptr);
|
||||
return this->tensor_impl_->DimensionSize(index);
|
||||
}
|
||||
|
||||
int Tensor::ElementsNum() const {
|
||||
MS_ASSERT(this->tensor_impl_ != nullptr);
|
||||
return this->tensor_impl_->ElementsNum();
|
||||
}
|
||||
|
||||
std::size_t Tensor::hash() const {
|
||||
MS_ASSERT(this->tensor_impl_ != nullptr);
|
||||
return this->tensor_impl_->hash();
|
||||
}
|
||||
|
||||
std::shared_ptr<tensor::Tensor> Tensor::tensor() const {
|
||||
MS_ASSERT(this->tensor_impl_ != nullptr);
|
||||
return this->tensor_impl_;
|
||||
}
|
||||
|
||||
size_t Tensor::Size() const {
|
||||
MS_ASSERT(this->tensor_impl_ != nullptr);
|
||||
return this->tensor_impl_->Size();
|
||||
}
|
||||
|
||||
void *Tensor::MutableData() const {
|
||||
MS_ASSERT(this->tensor_impl_ != nullptr);
|
||||
return this->tensor_impl_->data();
|
||||
}
|
||||
} // namespace inference
|
||||
} // namespace mindspore
|
@ -0,0 +1,97 @@
|
||||
/**
|
||||
* 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_IR_LITE_TENSOR_H_
|
||||
#define MINDSPORE_CCSRC_IR_LITE_TENSOR_H_
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include "ir/meta_tensor.h"
|
||||
#include "ir/dtype/type.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace tensor {
|
||||
class Tensor : public MetaTensor {
|
||||
public:
|
||||
Tensor() : MetaTensor() {}
|
||||
|
||||
Tensor(const TypeId data_type, const std::vector<int> &shape);
|
||||
|
||||
Tensor(const TypePtr &type_ptr, const std::vector<int> &shape);
|
||||
|
||||
Tensor(const Tensor &tensor);
|
||||
|
||||
~Tensor();
|
||||
|
||||
int CopyTensorData(const Tensor &srcTensor);
|
||||
|
||||
MS_DECLARE_PARENT(Tensor, MetaTensor)
|
||||
|
||||
virtual Tensor &operator=(const Tensor &tensor);
|
||||
|
||||
virtual bool operator==(const Tensor &tensor);
|
||||
|
||||
bool operator==(const Value &other) const override;
|
||||
|
||||
size_t Size() const { return MetaTensor::ElementsNum() * GetTypeByte(TypeIdToType(this->data_type_)); }
|
||||
|
||||
void *Data() const { return data_; }
|
||||
|
||||
protected:
|
||||
void *data_;
|
||||
};
|
||||
|
||||
using TensorPtr = std::shared_ptr<Tensor>;
|
||||
} // namespace tensor
|
||||
|
||||
namespace inference {
|
||||
class Tensor : public MSTensor {
|
||||
public:
|
||||
Tensor();
|
||||
|
||||
Tensor(TypeId data_type, const std::vector<int> &shape);
|
||||
|
||||
explicit Tensor(std::shared_ptr<tensor::Tensor> tensor_ptr);
|
||||
|
||||
~Tensor() = default;
|
||||
|
||||
TypeId data_type() const override;
|
||||
|
||||
TypeId set_data_type(const TypeId data_type) override;
|
||||
|
||||
std::vector<int> shape() const override;
|
||||
|
||||
size_t set_shape(const std::vector<int> &shape) override;
|
||||
|
||||
int DimensionSize(size_t index) const override;
|
||||
|
||||
int ElementsNum() const override;
|
||||
|
||||
std::size_t hash() const override;
|
||||
|
||||
std::shared_ptr<tensor::Tensor> tensor() const;
|
||||
|
||||
size_t Size() const override;
|
||||
|
||||
void *MutableData() const override;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<tensor::Tensor> tensor_impl_;
|
||||
};
|
||||
} // namespace inference
|
||||
} // namespace mindspore
|
||||
|
||||
#endif // MINDSPORE_CCSRC_IR_LITE_TENSOR_H_
|
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* 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_OPLOADER_H
|
||||
#define MINDSPORE_OPLOADER_H
|
||||
|
||||
#include <vector>
|
||||
#include "kernel/oplib/oplib.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace kernel {
|
||||
class OpInfoLoaderPy {
|
||||
public:
|
||||
OpInfoLoaderPy() = default;
|
||||
|
||||
~OpInfoLoaderPy() = default;
|
||||
|
||||
size_t GetAllOpsInfo() {
|
||||
auto ops = OpLib::GetAllOpsInfo();
|
||||
auto op_infos = new std::vector<OpInfo *>();
|
||||
for (auto op_info : ops) {
|
||||
auto new_op_info = new OpInfo(*op_info);
|
||||
op_infos->emplace_back(new_op_info);
|
||||
}
|
||||
return (size_t)op_infos;
|
||||
}
|
||||
};
|
||||
} // namespace kernel
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_OPLOADER_H
|
@ -1,76 +0,0 @@
|
||||
/**
|
||||
* 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_
|
@ -0,0 +1,148 @@
|
||||
/**
|
||||
* 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 <memory>
|
||||
#include <algorithm>
|
||||
#include "include/inference.h"
|
||||
#include "session/session.h"
|
||||
#include "utils/load_onnx/anf_converter.h"
|
||||
#include "session/session_basic.h"
|
||||
#include "session/session_factory.h"
|
||||
#include "utils/base_ref_utils.h"
|
||||
#include "kernel/oplib/oplib.h"
|
||||
#ifdef ENABLE_D
|
||||
#include "utils/context/ms_context.h"
|
||||
#include "session/ascend_session.h"
|
||||
#else
|
||||
#include "session/cpu_session.h"
|
||||
#endif
|
||||
|
||||
namespace py = pybind11;
|
||||
namespace mindspore::inference {
|
||||
std::shared_ptr<FuncGraph> LoadModel(const char *model_buf, size_t size, const std::string &device) {
|
||||
inference::Session::RegAllOp();
|
||||
auto anf_graph = lite::AnfConverter::RunAnfConverter(model_buf, size);
|
||||
return anf_graph;
|
||||
}
|
||||
|
||||
std::shared_ptr<MSSession> MSSession::CreateSession(const std::string &device, uint32_t device_id) {
|
||||
auto session = std::make_shared<inference::Session>();
|
||||
auto ret = session->Init(device, device_id);
|
||||
if (ret != 0) {
|
||||
return nullptr;
|
||||
}
|
||||
return session;
|
||||
}
|
||||
|
||||
void Session::RegAllOp() {
|
||||
static std::mutex init_mutex;
|
||||
static bool Initialized = false;
|
||||
|
||||
std::lock_guard<std::mutex> lock(init_mutex);
|
||||
if (Initialized) {
|
||||
return;
|
||||
}
|
||||
Initialized = true;
|
||||
MsContext::GetInstance()->set_execution_mode(kGraphMode);
|
||||
Py_Initialize();
|
||||
auto c_expression = PyImport_ImportModule("mindspore._c_expression");
|
||||
if (c_expression == nullptr) {
|
||||
MS_LOG(EXCEPTION) << "Failed to import mindspore._c_expression module.";
|
||||
return;
|
||||
}
|
||||
PyObject *c_expression_dict = PyModule_GetDict(c_expression);
|
||||
|
||||
PyObject *op_info_loader_class = PyDict_GetItemString(c_expression_dict, "OpInfoLoaderPy");
|
||||
if (op_info_loader_class == nullptr) {
|
||||
MS_LOG(EXCEPTION) << "Failed to get op_info_loader_class from mindspore._c_expression.";
|
||||
return;
|
||||
}
|
||||
PyObject *op_info_loader = PyInstanceMethod_New(op_info_loader_class);
|
||||
if (op_info_loader == nullptr) {
|
||||
MS_LOG(EXCEPTION) << "Failed to create op_info_loader instance.";
|
||||
return;
|
||||
}
|
||||
PyObject *op_info_loader_ins = PyObject_CallObject(op_info_loader, nullptr);
|
||||
if (op_info_loader_ins == nullptr) {
|
||||
MS_LOG(EXCEPTION) << "Failed to call op_info_loader instance.";
|
||||
return;
|
||||
}
|
||||
auto all_ops_info_vector_addr_ul = PyObject_CallMethod(op_info_loader_ins, "get_all_ops_info", nullptr);
|
||||
if (all_ops_info_vector_addr_ul == nullptr) {
|
||||
MS_LOG(EXCEPTION) << "Failed to call get_all_ops_addr.";
|
||||
return;
|
||||
}
|
||||
auto all_ops_info_vector_addr = PyLong_AsVoidPtr(all_ops_info_vector_addr_ul);
|
||||
auto all_ops_info = static_cast<std::vector<kernel::OpInfo *> *>(all_ops_info_vector_addr);
|
||||
for (auto op_info : *all_ops_info) {
|
||||
kernel::OpLib::RegOpInfo(std::shared_ptr<kernel::OpInfo>(op_info));
|
||||
}
|
||||
all_ops_info->clear();
|
||||
delete all_ops_info;
|
||||
Py_DECREF(op_info_loader);
|
||||
Py_DECREF(op_info_loader_class);
|
||||
Py_DECREF(c_expression_dict);
|
||||
Py_DECREF(c_expression);
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t Session::CompileGraph(std::shared_ptr<FuncGraph> funcGraphPtr) {
|
||||
MS_ASSERT(session_impl_ != nullptr);
|
||||
return session_impl_->CompileGraph(NOT_NULL(funcGraphPtr));
|
||||
}
|
||||
|
||||
MultiTensor Session::RunGraph(uint32_t graph_id, const std::vector<std::shared_ptr<inference::MSTensor>> &inputs) {
|
||||
std::vector<tensor::TensorPtr> inTensors;
|
||||
bool has_error = false;
|
||||
std::transform(inputs.begin(), inputs.end(), inTensors.begin(),
|
||||
[&has_error](const std::shared_ptr<inference::MSTensor> &tensor_ptr) -> tensor::TensorPtr {
|
||||
if (tensor_ptr == nullptr) {
|
||||
MS_LOG(WARNING) << "input MSTensor is nullptr, return nullptr";
|
||||
has_error = true;
|
||||
return nullptr;
|
||||
}
|
||||
auto tensor = static_cast<inference::Tensor *>(tensor_ptr.get());
|
||||
if (tensor == nullptr) {
|
||||
MS_LOG(ERROR) << "Can not cast input MSTensor to tensor";
|
||||
has_error = true;
|
||||
return nullptr;
|
||||
}
|
||||
return tensor->tensor();
|
||||
});
|
||||
if (has_error) {
|
||||
MS_LOG(ERROR) << "Init Tensor failed, returning empty result";
|
||||
std::vector<std::vector<std::shared_ptr<inference::MSTensor>>> multiTensor;
|
||||
return multiTensor;
|
||||
}
|
||||
VectorRef outputs;
|
||||
session_impl_->RunGraph(graph_id, inTensors, &outputs);
|
||||
|
||||
return TransformVectorRefToMultiTensor(outputs);
|
||||
}
|
||||
|
||||
int Session::Init(const std::string &device, uint32_t device_id) {
|
||||
RegAllOp();
|
||||
session_impl_ = session::SessionFactory::Get().Create(device);
|
||||
if (session_impl_ == nullptr) {
|
||||
MS_LOG(ERROR) << "Session create failed!, please make sure target device:" << device << " is available.";
|
||||
return -1;
|
||||
}
|
||||
session_impl_->Init(device_id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Session::Session() = default;
|
||||
} // namespace mindspore::inference
|
@ -0,0 +1,50 @@
|
||||
/**
|
||||
* 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_SESSION_SESSION_H
|
||||
#define MINDSPORE_CCSRC_SESSION_SESSION_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
|
||||
#include "session/session_basic.h"
|
||||
#include "ir/anf.h"
|
||||
#include "include/inference.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace inference {
|
||||
class Session : public MSSession {
|
||||
public:
|
||||
Session();
|
||||
|
||||
uint32_t CompileGraph(std::shared_ptr<FuncGraph> funcGraphPtr) override;
|
||||
|
||||
MultiTensor RunGraph(uint32_t graph_id, const std::vector<std::shared_ptr<inference::MSTensor>> &inputs) override;
|
||||
|
||||
int Init(const std::string &device, uint32_t device_id);
|
||||
|
||||
static void RegAllOp();
|
||||
|
||||
private:
|
||||
std::shared_ptr<session::SessionBasic> session_impl_ = nullptr;
|
||||
std::vector<uint32_t> graph_id_;
|
||||
};
|
||||
} // namespace inference
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_SESSION_SESSION_BASIC_H
|
@ -0,0 +1,58 @@
|
||||
/**
|
||||
* 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 <vector>
|
||||
#include <memory>
|
||||
#include "utils/base_ref_utils.h"
|
||||
#include "include/ms_tensor.h"
|
||||
#include "ir/tensor.h"
|
||||
|
||||
namespace mindspore {
|
||||
std::vector<std::shared_ptr<inference::MSTensor>> TransformBaseRefToMSTensor(const BaseRef &base_ref) {
|
||||
std::vector<std::shared_ptr<inference::MSTensor>> msTensors;
|
||||
if (utils::isa<VectorRef>(base_ref)) {
|
||||
auto ref_list = utils::cast<VectorRef>(base_ref);
|
||||
for (size_t i = 0; i < ref_list.size(); ++i) {
|
||||
if (utils::isa<tensor::Tensor>(ref_list[i])) {
|
||||
auto tensor_ptr = utils::cast<std::shared_ptr<tensor::Tensor>>(ref_list[i]);
|
||||
MS_EXCEPTION_IF_NULL(tensor_ptr);
|
||||
auto tensor = new inference::Tensor(tensor_ptr);
|
||||
msTensors.emplace_back(std::shared_ptr<inference::MSTensor>(tensor));
|
||||
} else {
|
||||
MS_LOG(EXCEPTION) << "The output is not a tensor!";
|
||||
}
|
||||
}
|
||||
} else if (utils::isa<tensor::Tensor>(base_ref)) {
|
||||
auto tensor_ptr = utils::cast<std::shared_ptr<tensor::Tensor>>(base_ref);
|
||||
MS_EXCEPTION_IF_NULL(tensor_ptr);
|
||||
auto tensor = new inference::Tensor(tensor_ptr);
|
||||
msTensors.emplace_back(std::shared_ptr<inference::MSTensor>(tensor));
|
||||
} else {
|
||||
MS_LOG(EXCEPTION) << "The output is not a base ref list or a tensor!";
|
||||
}
|
||||
return msTensors;
|
||||
}
|
||||
|
||||
std::vector<std::vector<std::shared_ptr<inference::MSTensor>>> TransformVectorRefToMultiTensor(
|
||||
const VectorRef &vector_ref) {
|
||||
std::vector<std::vector<std::shared_ptr<inference::MSTensor>>> multiTensor;
|
||||
for (size_t i = 0; i < vector_ref.size(); ++i) {
|
||||
auto tensors = TransformBaseRefToMSTensor(vector_ref[i]);
|
||||
multiTensor.emplace_back(tensors);
|
||||
}
|
||||
return multiTensor;
|
||||
}
|
||||
} // namespace mindspore
|
@ -0,0 +1,143 @@
|
||||
/**
|
||||
* 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 <fcntl.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include "utils/load_onnx/anf_model_parser.h"
|
||||
#include "utils/load_onnx/anf_converter.h"
|
||||
#include "google/protobuf/io/zero_copy_stream_impl.h"
|
||||
#include "proto/onnx.pb.h"
|
||||
#include "utils/log_adapter.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
|
||||
const char WHITESPACE[] = "\t\n\v\f\r ";
|
||||
const int FLAG_PREFIX_LEN = 2;
|
||||
|
||||
void AnfConverter::Trim(std::string *input) {
|
||||
if (input == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (input->empty()) {
|
||||
return;
|
||||
}
|
||||
input->erase(0, input->find_first_not_of(WHITESPACE));
|
||||
input->erase(input->find_last_not_of(WHITESPACE) + 1);
|
||||
}
|
||||
|
||||
int AnfConverter::ValidateFileStr(const std::string &modelFile, std::string fileType) {
|
||||
if (modelFile.size() > fileType.size()) {
|
||||
if (modelFile.substr(modelFile.size() - fileType.size()) == fileType) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
bool AnfConverter::ReadOnnxFromBinary(const std::string &modelFile, google::protobuf::Message *onnx_model) {
|
||||
std::unique_ptr<char> onnx_file(new (std::nothrow) char[PATH_MAX]{0});
|
||||
int fd = open(onnx_file.get(), O_RDONLY);
|
||||
google::protobuf::io::FileInputStream input(fd);
|
||||
google::protobuf::io::CodedInputStream code_input(&input);
|
||||
code_input.SetTotalBytesLimit(INT_MAX, 536870912);
|
||||
bool ret = onnx_model->ParseFromCodedStream(&code_input);
|
||||
if (!ret) {
|
||||
MS_LOG(ERROR) << "load onnx file failed";
|
||||
return false;
|
||||
}
|
||||
(void)close(fd);
|
||||
MS_LOG(INFO) << "enter ReadProtoFromBinary success!" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<FuncGraph> AnfConverter::RunAnfConverter(const std::string &file_path) {
|
||||
std::string modelFile;
|
||||
|
||||
std::string tmp = file_path;
|
||||
Trim(&tmp);
|
||||
const std::string flagItem(tmp);
|
||||
|
||||
size_t pos = flagItem.find_first_of("=");
|
||||
if (pos == std::string::npos) {
|
||||
MS_LOG(ERROR) << "Trans data not support input format!";
|
||||
} else {
|
||||
modelFile = flagItem.substr(pos + 1);
|
||||
std::cout << "input protobuf file path is: " << flagItem.substr(pos + 1) << std::endl;
|
||||
}
|
||||
|
||||
if (ValidateFileStr(modelFile, ".pb") != 0) {
|
||||
MS_LOG(EXCEPTION) << "INPUT ILLEGAL: modelFile must be *.pb";
|
||||
}
|
||||
|
||||
onnx::ModelProto model_;
|
||||
ReadOnnxFromBinary(modelFile, &model_);
|
||||
MSANFModelParser model_parser;
|
||||
FuncGraphPtr dstgraph_ptr = model_parser.Parse(model_);
|
||||
MS_EXCEPTION_IF_NULL(dstgraph_ptr);
|
||||
TestFuncGraphBuild(dstgraph_ptr);
|
||||
return dstgraph_ptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<FuncGraph> AnfConverter::RunAnfConverter(const char *buf, const size_t buf_size) {
|
||||
Py_Initialize();
|
||||
MS_EXCEPTION_IF_NULL(buf);
|
||||
std::string str((const char *)buf, buf_size);
|
||||
onnx::ModelProto model_;
|
||||
if (!model_.ParseFromString(str)) {
|
||||
MS_LOG(EXCEPTION) << "Parse model from buffer fail!";
|
||||
}
|
||||
MSANFModelParser model_parser;
|
||||
FuncGraphPtr dstgraph_ptr = model_parser.Parse(model_);
|
||||
MS_EXCEPTION_IF_NULL(dstgraph_ptr);
|
||||
TestFuncGraphBuild(dstgraph_ptr);
|
||||
return dstgraph_ptr;
|
||||
}
|
||||
|
||||
int AnfConverter::TestFuncGraphBuild(const FuncGraphPtr &graph) {
|
||||
MS_EXCEPTION_IF_NULL(graph);
|
||||
auto node_return = graph->get_return();
|
||||
std::vector<AnfNodePtr> node_list = TopoSort(node_return);
|
||||
MS_LOG(INFO) << "node_list size is : " << node_list.size();
|
||||
for (auto &node : node_list) {
|
||||
if (node->isa<CNode>()) {
|
||||
auto node_CN = node->cast<CNodePtr>();
|
||||
MS_LOG(INFO) << "CN node: " << node_CN->input(0)->ToString() << ", input size :" << node_CN->size();
|
||||
} else if (node->isa<Parameter>()) {
|
||||
auto node_Para = node->cast<ParameterPtr>();
|
||||
if (node_Para->has_default()) {
|
||||
MS_LOG(INFO) << "Parameter node: " << node_Para->name() << "has default value!";
|
||||
} else {
|
||||
MS_LOG(INFO) << "Parameter node: " << node_Para->name();
|
||||
}
|
||||
} else if (node->isa<ValueNode>()) {
|
||||
auto node_Value = node->cast<ValueNodePtr>();
|
||||
MS_LOG(INFO) << "Value node: " << node_Value->ToString();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
@ -0,0 +1,40 @@
|
||||
/**
|
||||
* 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_UTILS_LOAD_ONNX_ANF_CONVERTER_H
|
||||
#define MINDSPORE_CCSRC_UTILS_LOAD_ONNX_ANF_CONVERTER_H
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include "google/protobuf/io/zero_copy_stream_impl.h"
|
||||
#include "proto/onnx.pb.h"
|
||||
#include "ir/func_graph.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
class AnfConverter {
|
||||
public:
|
||||
static int TestFuncGraphBuild(const FuncGraphPtr &graph);
|
||||
static std::shared_ptr<FuncGraph> RunAnfConverter(const std::string &file_path);
|
||||
static std::shared_ptr<FuncGraph> RunAnfConverter(const char *buf, const size_t buf_size);
|
||||
|
||||
private:
|
||||
static void Trim(std::string *input);
|
||||
static int ValidateFileStr(const std::string &modelFile, std::string fileType);
|
||||
static bool ReadOnnxFromBinary(const std::string &modelFile, google::protobuf::Message *onnx_model);
|
||||
};
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,79 @@
|
||||
/**
|
||||
* 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_UTILS_LOAD_ONNX_ANF_MODEL_PARSER_H
|
||||
#define MINDSPORE_CCSRC_UTILS_LOAD_ONNX_ANF_MODEL_PARSER_H
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include "google/protobuf/io/zero_copy_stream_impl.h"
|
||||
#include "ir/func_graph.h"
|
||||
#include "proto/onnx.pb.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
using int32 = int32_t;
|
||||
using int64 = int64_t;
|
||||
using uint64 = uint64_t;
|
||||
class MSANFModelParser {
|
||||
public:
|
||||
MSANFModelParser() = default;
|
||||
~MSANFModelParser() = default;
|
||||
|
||||
FuncGraphPtr Parse(const onnx::ModelProto &model_proto);
|
||||
bool MSANFParseModelConfigureInfo(const onnx::ModelProto &model_proto);
|
||||
|
||||
std::string GetProducerName() { return producer_name_; }
|
||||
std::string GetProducerVersion() { return producer_version_; }
|
||||
int GetIrVersion() { return ir_version_; }
|
||||
int GetOpsetVersion() { return opset_version_; }
|
||||
|
||||
private:
|
||||
bool BuildFuncGraph(const FuncGraphPtr &outputFuncGraph, const onnx::GraphProto &importProto);
|
||||
bool ImportParametersForGraph(const FuncGraphPtr &outputFuncGraph, const onnx::GraphProto &importProto);
|
||||
bool ImportNodesForGraph(const FuncGraphPtr &outputFuncGraph, const onnx::GraphProto &importProto);
|
||||
bool BuildParameterForFuncGraph(const ParameterPtr &node, const onnx::ValueInfoProto &value_proto);
|
||||
bool BuildCNodeForFuncGraph(const FuncGraphPtr &outputFuncGraph, const onnx::NodeProto &node_proto,
|
||||
const onnx::GraphProto &importProto, const bool &ret_flag);
|
||||
bool GetAttrValueForCNode(const PrimitivePtr &prim, const onnx::AttributeProto &attr_proto);
|
||||
bool ObtainCNodeAttrInTypeForm(const PrimitivePtr &prim, const std::string &attr_name,
|
||||
const onnx::TensorProto &attr_tensor);
|
||||
bool ObtainCNodeAttrInScalarForm(const PrimitivePtr &prim, const std::string &attr_name,
|
||||
const onnx::TensorProto &attr_tensor);
|
||||
bool ObtainCNodeAttrInTensorForm(const PrimitivePtr &prim, const std::string &attr_name,
|
||||
const onnx::TensorProto &attr_tensor);
|
||||
bool BuildValueNodeForFuncGraph(const onnx::NodeProto &node_proto);
|
||||
bool ObtainValueNodeInTensorForm(const string &value_node_name, const onnx::TensorProto &attr_tensor);
|
||||
|
||||
bool ObtainValueNodeInScalarForm(const string &value_node_name, const onnx::TensorProto &attr_tensor);
|
||||
bool GetAttrValueForValueNode(const string &ref_attr_name, const std::string &value_node_name,
|
||||
const onnx::TensorProto &attr_tensor);
|
||||
bool ObtainValueNodeInTypeForm(const string &value_node_name, const onnx::TensorProto &attr_tensor);
|
||||
|
||||
std::string producer_name_;
|
||||
std::string producer_version_;
|
||||
int ir_version_{};
|
||||
int opset_version_{};
|
||||
std::unordered_map<std::string, AnfNodePtr> anfnode_build_map_;
|
||||
std::map<std::string, onnx::TensorProto> default_para_map_;
|
||||
|
||||
AbstractBasePtr GetAbstractForCNode(const onnx::AttributeProto &attr_proto);
|
||||
};
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
|
||||
#endif // MINDSPORE_CCSRC_UTILS_LOAD_ONNX_ANF_MODEL_PARSER_H
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue