From: @lx0095 Reviewed-by: @hangangqiang,@zhang_xue_tong,@zhanghaibo5 Signed-off-by: @zhang_xue_tongpull/14358/MERGE
| @@ -16,7 +16,7 @@ | |||||
| #include "nnacl/fp32/prelu_fp32.h" | #include "nnacl/fp32/prelu_fp32.h" | ||||
| #ifdef ENABLE_ARM64 | #ifdef ENABLE_ARM64 | ||||
| inline void PRelu4x16(const float *in, float *out, float *cur_slope, size_t step) { | |||||
| static inline void PRelu4x16(const float *in, float *out, float *cur_slope, size_t step) { | |||||
| asm volatile( | asm volatile( | ||||
| "mov x10, %[in]\n" | "mov x10, %[in]\n" | ||||
| "mov x11, %[out]\n" | "mov x11, %[out]\n" | ||||
| @@ -13,11 +13,11 @@ | |||||
| * See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #include "include/api/cell.h" | #include "include/api/cell.h" | ||||
| #include "src/common/log_adapter.h" | #include "src/common/log_adapter.h" | ||||
| namespace mindspore { | namespace mindspore { | ||||
| class GraphImpl {}; | class GraphImpl {}; | ||||
| std::vector<Output> CellBase::operator()(const std::vector<Input> &inputs) const { | std::vector<Output> CellBase::operator()(const std::vector<Input> &inputs) const { | ||||
| @@ -90,5 +90,4 @@ InputAndOutput::InputAndOutput(const std::shared_ptr<CellBase> &cell, const std: | |||||
| int32_t index) { | int32_t index) { | ||||
| MS_LOG(ERROR) << "Unsupported feature."; | MS_LOG(ERROR) << "Unsupported feature."; | ||||
| } | } | ||||
| } // namespace mindspore | } // namespace mindspore | ||||
| @@ -13,6 +13,7 @@ | |||||
| * See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #include "include/api/context.h" | #include "include/api/context.h" | ||||
| #include <string> | #include <string> | ||||
| #include <memory> | #include <memory> | ||||
| @@ -262,5 +263,4 @@ enum DataType Ascend310DeviceInfo::GetOutputType() const { | |||||
| MS_LOG(ERROR) << "Unsupported Feature."; | MS_LOG(ERROR) << "Unsupported Feature."; | ||||
| return DataType::kTypeUnknown; | return DataType::kTypeUnknown; | ||||
| } | } | ||||
| } // namespace mindspore | } // namespace mindspore | ||||
| @@ -19,7 +19,6 @@ | |||||
| #include "src/cxx_api/graph/graph_data.h" | #include "src/cxx_api/graph/graph_data.h" | ||||
| namespace mindspore { | namespace mindspore { | ||||
| Graph::Graph() : graph_data_(nullptr) {} | Graph::Graph() : graph_data_(nullptr) {} | ||||
| Graph::Graph(const std::shared_ptr<GraphData> &graph_data) : graph_data_(graph_data) {} | Graph::Graph(const std::shared_ptr<GraphData> &graph_data) : graph_data_(graph_data) {} | ||||
| @@ -13,6 +13,7 @@ | |||||
| * See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #ifndef MINDSPORE_LITE_SRC_CXX_API_GRAPH_GRAPH_DATA_H | #ifndef MINDSPORE_LITE_SRC_CXX_API_GRAPH_GRAPH_DATA_H | ||||
| #define MINDSPORE_LITE_SRC_CXX_API_GRAPH_GRAPH_DATA_H | #define MINDSPORE_LITE_SRC_CXX_API_GRAPH_GRAPH_DATA_H | ||||
| @@ -39,4 +40,5 @@ class Graph::GraphData { | |||||
| std::shared_ptr<lite::Model> lite_model_; | std::shared_ptr<lite::Model> lite_model_; | ||||
| }; | }; | ||||
| } // namespace mindspore | } // namespace mindspore | ||||
| #endif // MINDSPORE_LITE_SRC_CXX_API_GRAPH_GRAPH_DATA_H | #endif // MINDSPORE_LITE_SRC_CXX_API_GRAPH_GRAPH_DATA_H | ||||
| @@ -13,6 +13,7 @@ | |||||
| * See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #include "include/api/model.h" | #include "include/api/model.h" | ||||
| #include "include/api/types.h" | #include "include/api/types.h" | ||||
| #include "include/api/context.h" | #include "include/api/context.h" | ||||
| @@ -21,7 +22,6 @@ | |||||
| #include "src/common/log_adapter.h" | #include "src/common/log_adapter.h" | ||||
| namespace mindspore { | namespace mindspore { | ||||
| Status Model::Build(GraphCell graph, const std::shared_ptr<Context> &model_context) { | Status Model::Build(GraphCell graph, const std::shared_ptr<Context> &model_context) { | ||||
| if (impl_ != nullptr) { | if (impl_ != nullptr) { | ||||
| MS_LOG(DEBUG) << "Model has been already built."; | MS_LOG(DEBUG) << "Model has been already built."; | ||||
| @@ -150,6 +150,11 @@ Status ModelImpl::Predict(const std::vector<MSTensor> &inputs, std::vector<MSTen | |||||
| << "."; | << "."; | ||||
| return kLiteInputTensorError; | return kLiteInputTensorError; | ||||
| } | } | ||||
| if (user_input.Data() == nullptr) { | |||||
| ResetTensorData(old_data, input_tensors); | |||||
| MS_LOG(ERROR) << "Tensor " << user_input.Name() << " has no data."; | |||||
| return kLiteInputTensorError; | |||||
| } | |||||
| if (user_input.Name() != input->tensor_name()) { | if (user_input.Name() != input->tensor_name()) { | ||||
| MS_LOG(WARNING) << "Tensor " << user_input.Name() << " has a different name from input" << input->tensor_name() | MS_LOG(WARNING) << "Tensor " << user_input.Name() << " has a different name from input" << input->tensor_name() | ||||
| << "."; | << "."; | ||||
| @@ -384,5 +389,4 @@ Status ModelImpl::Resize(const std::vector<MSTensor> &inputs, const std::vector< | |||||
| auto ret = session_->Resize(inner_input, truncated_shape); | auto ret = session_->Resize(inner_input, truncated_shape); | ||||
| return static_cast<StatusCode>(ret); | return static_cast<StatusCode>(ret); | ||||
| } | } | ||||
| } // namespace mindspore | } // namespace mindspore | ||||
| @@ -13,8 +13,10 @@ | |||||
| * See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #ifndef MINDSPORE_LITE_SRC_CXX_API_MODEL_MODEL_IMPL_H | #ifndef MINDSPORE_LITE_SRC_CXX_API_MODEL_MODEL_IMPL_H | ||||
| #define MINDSPORE_LITE_SRC_CXX_API_MODEL_MODEL_IMPL_H | #define MINDSPORE_LITE_SRC_CXX_API_MODEL_MODEL_IMPL_H | ||||
| #include <functional> | #include <functional> | ||||
| #include <map> | #include <map> | ||||
| #include <string> | #include <string> | ||||
| @@ -27,7 +27,6 @@ | |||||
| #include "src/common/log_adapter.h" | #include "src/common/log_adapter.h" | ||||
| namespace mindspore { | namespace mindspore { | ||||
| Status Serialization::Load(const void *model_data, size_t data_size, ModelType model_type, Graph *graph) { | Status Serialization::Load(const void *model_data, size_t data_size, ModelType model_type, Graph *graph) { | ||||
| if (model_type != kMindIR) { | if (model_type != kMindIR) { | ||||
| MS_LOG(ERROR) << "Unsupported IR."; | MS_LOG(ERROR) << "Unsupported IR."; | ||||
| @@ -13,6 +13,7 @@ | |||||
| * See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #include <cstddef> | #include <cstddef> | ||||
| #include <numeric> | #include <numeric> | ||||
| #include <memory> | #include <memory> | ||||
| @@ -33,8 +34,9 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| using mindspore::lite::RET_OK; | using mindspore::lite::RET_OK; | ||||
| MSTensor::Impl *MSTensor::Impl::CreateTensorImpl(const std::string &name, enum DataType type, | |||||
| const std::vector<int64_t> &shape, const void *data, size_t data_len) { | |||||
| std::shared_ptr<MSTensor::Impl> MSTensor::Impl::CreateTensorImpl(const std::string &name, enum DataType type, | |||||
| const std::vector<int64_t> &shape, const void *data, | |||||
| size_t data_len) { | |||||
| std::vector<int32_t> truncated_shape = TruncateShape(shape, static_cast<enum TypeId>(type), data_len, true); | std::vector<int32_t> truncated_shape = TruncateShape(shape, static_cast<enum TypeId>(type), data_len, true); | ||||
| if (truncated_shape.empty() && !(shape.empty())) { | if (truncated_shape.empty() && !(shape.empty())) { | ||||
| MS_LOG(ERROR) << "Invalid shape for creating tensor."; | MS_LOG(ERROR) << "Invalid shape for creating tensor."; | ||||
| @@ -45,7 +47,7 @@ MSTensor::Impl *MSTensor::Impl::CreateTensorImpl(const std::string &name, enum D | |||||
| MS_LOG(ERROR) << "Failed to allocate lite tensor."; | MS_LOG(ERROR) << "Failed to allocate lite tensor."; | ||||
| return nullptr; | return nullptr; | ||||
| } | } | ||||
| auto impl = new (std::nothrow) Impl(lite_tensor); | |||||
| auto impl = std::shared_ptr<MSTensor::Impl>(new (std::nothrow) Impl(lite_tensor)); | |||||
| if (impl == nullptr) { | if (impl == nullptr) { | ||||
| MS_LOG(ERROR) << "Failed to allocate tensor impl."; | MS_LOG(ERROR) << "Failed to allocate tensor impl."; | ||||
| return nullptr; | return nullptr; | ||||
| @@ -54,7 +56,8 @@ MSTensor::Impl *MSTensor::Impl::CreateTensorImpl(const std::string &name, enum D | |||||
| return impl; | return impl; | ||||
| } | } | ||||
| MSTensor::Impl *MSTensor::Impl::StringsToTensorImpl(const std::string &name, const std::vector<std::string> &str) { | |||||
| std::shared_ptr<MSTensor::Impl> MSTensor::Impl::StringsToTensorImpl(const std::string &name, | |||||
| const std::vector<std::string> &str) { | |||||
| auto lite_tensor = new (std::nothrow) lite::Tensor(); | auto lite_tensor = new (std::nothrow) lite::Tensor(); | ||||
| if (lite_tensor == nullptr) { | if (lite_tensor == nullptr) { | ||||
| MS_LOG(ERROR) << "Failed to allocate lite tensor."; | MS_LOG(ERROR) << "Failed to allocate lite tensor."; | ||||
| @@ -67,7 +70,7 @@ MSTensor::Impl *MSTensor::Impl::StringsToTensorImpl(const std::string &name, con | |||||
| delete lite_tensor; | delete lite_tensor; | ||||
| return nullptr; | return nullptr; | ||||
| } | } | ||||
| auto impl = new (std::nothrow) Impl(lite_tensor); | |||||
| auto impl = std::shared_ptr<MSTensor::Impl>(new (std::nothrow) Impl(lite_tensor)); | |||||
| if (impl == nullptr) { | if (impl == nullptr) { | ||||
| delete lite_tensor; | delete lite_tensor; | ||||
| MS_LOG(ERROR) << "Failed to allocate tensor impl."; | MS_LOG(ERROR) << "Failed to allocate tensor impl."; | ||||
| @@ -77,5 +80,4 @@ MSTensor::Impl *MSTensor::Impl::StringsToTensorImpl(const std::string &name, con | |||||
| impl->set_from_session(false); | impl->set_from_session(false); | ||||
| return impl; | return impl; | ||||
| } | } | ||||
| } // namespace mindspore | } // namespace mindspore | ||||
| @@ -13,6 +13,10 @@ | |||||
| * See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #ifndef MINDSPORE_LITE_SRC_CXX_API_TENSOR_TENSOR_IMPL_H | |||||
| #define MINDSPORE_LITE_SRC_CXX_API_TENSOR_TENSOR_IMPL_H | |||||
| #include <cstddef> | #include <cstddef> | ||||
| #include <numeric> | #include <numeric> | ||||
| #include <memory> | #include <memory> | ||||
| @@ -53,10 +57,10 @@ class MSTensor::Impl { | |||||
| } | } | ||||
| } | } | ||||
| static Impl *CreateTensorImpl(const std::string &name, enum DataType type, const std::vector<int64_t> &shape, | |||||
| const void *data, size_t data_len); | |||||
| static std::shared_ptr<Impl> CreateTensorImpl(const std::string &name, enum DataType type, | |||||
| const std::vector<int64_t> &shape, const void *data, size_t data_len); | |||||
| static Impl *StringsToTensorImpl(const std::string &name, const std::vector<std::string> &str); | |||||
| static std::shared_ptr<Impl> StringsToTensorImpl(const std::string &name, const std::vector<std::string> &str); | |||||
| static std::vector<std::string> TensorImplToStrings(const std::shared_ptr<Impl> &impl) { | static std::vector<std::string> TensorImplToStrings(const std::shared_ptr<Impl> &impl) { | ||||
| std::vector<std::string> empty; | std::vector<std::string> empty; | ||||
| @@ -116,7 +120,7 @@ class MSTensor::Impl { | |||||
| return nullptr; | return nullptr; | ||||
| } | } | ||||
| return std::shared_ptr<const void>(lite_tensor_->MutableData(), [](const void *) {}); | |||||
| return std::shared_ptr<const void>(lite_tensor_->data(), [](const void *) {}); | |||||
| } | } | ||||
| virtual void *MutableData() { | virtual void *MutableData() { | ||||
| @@ -158,5 +162,6 @@ class MSTensor::Impl { | |||||
| bool own_data_ = false; | bool own_data_ = false; | ||||
| bool from_session_ = false; | bool from_session_ = false; | ||||
| }; | }; | ||||
| } // namespace mindspore | } // namespace mindspore | ||||
| #endif // MINDSPORE_LITE_SRC_CXX_API_TENSOR_TENSOR_IMPL_H | |||||
| @@ -13,6 +13,10 @@ | |||||
| * See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #ifndef MINDSPORE_LITE_SRC_CXX_API_TENSOR_UTILS_H | |||||
| #define MINDSPORE_LITE_SRC_CXX_API_TENSOR_UTILS_H | |||||
| #include <limits.h> | #include <limits.h> | ||||
| #include <vector> | #include <vector> | ||||
| #include "ir/dtype/type_id.h" | #include "ir/dtype/type_id.h" | ||||
| @@ -45,5 +49,6 @@ static std::vector<int32_t> TruncateShape(const std::vector<int64_t> &shape, enu | |||||
| } | } | ||||
| return truncated_shape; | return truncated_shape; | ||||
| } | } | ||||
| } // namespace mindspore | } // namespace mindspore | ||||
| #endif // MINDSPORE_LITE_SRC_CXX_API_TENSOR_UTILS_H | |||||
| @@ -13,6 +13,7 @@ | |||||
| * See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #include "include/api/types.h" | #include "include/api/types.h" | ||||
| #include <string.h> | #include <string.h> | ||||
| #include <limits.h> | #include <limits.h> | ||||
| @@ -25,7 +26,6 @@ | |||||
| #include "src/common/log_adapter.h" | #include "src/common/log_adapter.h" | ||||
| namespace mindspore { | namespace mindspore { | ||||
| class Buffer::Impl { | class Buffer::Impl { | ||||
| public: | public: | ||||
| Impl() : data_() { MS_LOG(ERROR) << "Unsupported feature."; } | Impl() : data_() { MS_LOG(ERROR) << "Unsupported feature."; } | ||||
| @@ -64,7 +64,7 @@ MSTensor::MSTensor(std::nullptr_t) : impl_(nullptr) {} | |||||
| MSTensor::MSTensor(const std::shared_ptr<Impl> &impl) : impl_(impl) {} | MSTensor::MSTensor(const std::shared_ptr<Impl> &impl) : impl_(impl) {} | ||||
| MSTensor::MSTensor(const std::vector<char> &name, enum DataType type, const std::vector<int64_t> &shape, | MSTensor::MSTensor(const std::vector<char> &name, enum DataType type, const std::vector<int64_t> &shape, | ||||
| const void *data, size_t data_len) | const void *data, size_t data_len) | ||||
| : impl_(std::shared_ptr<Impl>(Impl::CreateTensorImpl(CharToString(name), type, shape, data, data_len))) {} | |||||
| : impl_(Impl::CreateTensorImpl(CharToString(name), type, shape, data, data_len)) {} | |||||
| MSTensor::~MSTensor() = default; | MSTensor::~MSTensor() = default; | ||||
| bool MSTensor::operator==(std::nullptr_t) const { return impl_ == nullptr; } | bool MSTensor::operator==(std::nullptr_t) const { return impl_ == nullptr; } | ||||
| @@ -79,7 +79,7 @@ MSTensor *MSTensor::CreateTensor(const std::vector<char> &name, enum DataType ty | |||||
| return nullptr; | return nullptr; | ||||
| } | } | ||||
| ::memcpy(new_data, data, data_len); | ::memcpy(new_data, data, data_len); | ||||
| auto impl = std::shared_ptr<Impl>(Impl::CreateTensorImpl(CharToString(name), type, shape, new_data, data_len)); | |||||
| auto impl = Impl::CreateTensorImpl(CharToString(name), type, shape, new_data, data_len); | |||||
| if (impl == nullptr) { | if (impl == nullptr) { | ||||
| MS_LOG(ERROR) << "Allocate tensor impl failed."; | MS_LOG(ERROR) << "Allocate tensor impl failed."; | ||||
| free(new_data); | free(new_data); | ||||
| @@ -97,7 +97,7 @@ MSTensor *MSTensor::CreateTensor(const std::vector<char> &name, enum DataType ty | |||||
| MSTensor *MSTensor::CreateRefTensor(const std::vector<char> &name, enum DataType type, | MSTensor *MSTensor::CreateRefTensor(const std::vector<char> &name, enum DataType type, | ||||
| const std::vector<int64_t> &shape, const void *data, size_t data_len) noexcept { | const std::vector<int64_t> &shape, const void *data, size_t data_len) noexcept { | ||||
| auto impl = std::shared_ptr<Impl>(Impl::CreateTensorImpl(CharToString(name), type, shape, data, data_len)); | |||||
| auto impl = Impl::CreateTensorImpl(CharToString(name), type, shape, data, data_len); | |||||
| if (impl == nullptr) { | if (impl == nullptr) { | ||||
| MS_LOG(ERROR) << "Allocate tensor impl failed."; | MS_LOG(ERROR) << "Allocate tensor impl failed."; | ||||
| return nullptr; | return nullptr; | ||||
| @@ -111,7 +111,7 @@ MSTensor *MSTensor::CreateRefTensor(const std::vector<char> &name, enum DataType | |||||
| } | } | ||||
| MSTensor *MSTensor::CharStringsToTensor(const std::vector<char> &name, const std::vector<std::vector<char>> &inputs) { | MSTensor *MSTensor::CharStringsToTensor(const std::vector<char> &name, const std::vector<std::vector<char>> &inputs) { | ||||
| auto impl = std::shared_ptr<Impl>(Impl::StringsToTensorImpl(CharToString(name), VectorCharToString(inputs))); | |||||
| auto impl = Impl::StringsToTensorImpl(CharToString(name), VectorCharToString(inputs)); | |||||
| if (impl == nullptr) { | if (impl == nullptr) { | ||||
| MS_LOG(ERROR) << "Allocate tensor impl failed."; | MS_LOG(ERROR) << "Allocate tensor impl failed."; | ||||
| return nullptr; | return nullptr; | ||||
| @@ -148,8 +148,7 @@ MSTensor *MSTensor::Clone() const { | |||||
| MS_LOG(ERROR) << "Allocate data failed."; | MS_LOG(ERROR) << "Allocate data failed."; | ||||
| return nullptr; | return nullptr; | ||||
| } | } | ||||
| auto impl = | |||||
| std::shared_ptr<Impl>(Impl::CreateTensorImpl(this->Name(), this->DataType(), this->Shape(), new_data, data_len)); | |||||
| auto impl = Impl::CreateTensorImpl(this->Name(), this->DataType(), this->Shape(), new_data, data_len); | |||||
| if (impl == nullptr) { | if (impl == nullptr) { | ||||
| MS_LOG(ERROR) << "Allocate tensor impl failed."; | MS_LOG(ERROR) << "Allocate tensor impl failed."; | ||||
| free(new_data); | free(new_data); | ||||