Browse Source

!14358 [MS][LITE][Develop]fix input tensor check

From: @lx0095
Reviewed-by: @hangangqiang,@zhang_xue_tong,@zhanghaibo5
Signed-off-by: @zhang_xue_tong
pull/14358/MERGE
mindspore-ci-bot Gitee 4 years ago
parent
commit
be6cd743bf
13 changed files with 43 additions and 27 deletions
  1. +1
    -1
      mindspore/lite/nnacl/fp32/prelu_fp32.c
  2. +1
    -2
      mindspore/lite/src/cxx_api/cell.cc
  3. +1
    -1
      mindspore/lite/src/cxx_api/context.cc
  4. +0
    -1
      mindspore/lite/src/cxx_api/graph/graph.cc
  5. +2
    -0
      mindspore/lite/src/cxx_api/graph/graph_data.h
  6. +1
    -1
      mindspore/lite/src/cxx_api/model/model.cc
  7. +5
    -1
      mindspore/lite/src/cxx_api/model/model_impl.cc
  8. +2
    -0
      mindspore/lite/src/cxx_api/model/model_impl.h
  9. +0
    -1
      mindspore/lite/src/cxx_api/serialization.cc
  10. +8
    -6
      mindspore/lite/src/cxx_api/tensor/tensor_impl.cc
  11. +10
    -5
      mindspore/lite/src/cxx_api/tensor/tensor_impl.h
  12. +6
    -1
      mindspore/lite/src/cxx_api/tensor_utils.h
  13. +6
    -7
      mindspore/lite/src/cxx_api/types.cc

+ 1
- 1
mindspore/lite/nnacl/fp32/prelu_fp32.c View File

@@ -16,7 +16,7 @@
#include "nnacl/fp32/prelu_fp32.h"

#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(
"mov x10, %[in]\n"
"mov x11, %[out]\n"


+ 1
- 2
mindspore/lite/src/cxx_api/cell.cc View File

@@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "include/api/cell.h"
#include "src/common/log_adapter.h"

namespace mindspore {

class GraphImpl {};

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) {
MS_LOG(ERROR) << "Unsupported feature.";
}

} // namespace mindspore

+ 1
- 1
mindspore/lite/src/cxx_api/context.cc View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "include/api/context.h"
#include <string>
#include <memory>
@@ -262,5 +263,4 @@ enum DataType Ascend310DeviceInfo::GetOutputType() const {
MS_LOG(ERROR) << "Unsupported Feature.";
return DataType::kTypeUnknown;
}

} // namespace mindspore

+ 0
- 1
mindspore/lite/src/cxx_api/graph/graph.cc View File

@@ -19,7 +19,6 @@
#include "src/cxx_api/graph/graph_data.h"

namespace mindspore {

Graph::Graph() : graph_data_(nullptr) {}

Graph::Graph(const std::shared_ptr<GraphData> &graph_data) : graph_data_(graph_data) {}


+ 2
- 0
mindspore/lite/src/cxx_api/graph/graph_data.h View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef 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_;
};
} // namespace mindspore

#endif // MINDSPORE_LITE_SRC_CXX_API_GRAPH_GRAPH_DATA_H

+ 1
- 1
mindspore/lite/src/cxx_api/model/model.cc View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "include/api/model.h"
#include "include/api/types.h"
#include "include/api/context.h"
@@ -21,7 +22,6 @@
#include "src/common/log_adapter.h"

namespace mindspore {

Status Model::Build(GraphCell graph, const std::shared_ptr<Context> &model_context) {
if (impl_ != nullptr) {
MS_LOG(DEBUG) << "Model has been already built.";


+ 5
- 1
mindspore/lite/src/cxx_api/model/model_impl.cc View File

@@ -150,6 +150,11 @@ Status ModelImpl::Predict(const std::vector<MSTensor> &inputs, std::vector<MSTen
<< ".";
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()) {
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);
return static_cast<StatusCode>(ret);
}

} // namespace mindspore

+ 2
- 0
mindspore/lite/src/cxx_api/model/model_impl.h View File

@@ -13,8 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MINDSPORE_LITE_SRC_CXX_API_MODEL_MODEL_IMPL_H
#define MINDSPORE_LITE_SRC_CXX_API_MODEL_MODEL_IMPL_H

#include <functional>
#include <map>
#include <string>


+ 0
- 1
mindspore/lite/src/cxx_api/serialization.cc View File

@@ -27,7 +27,6 @@
#include "src/common/log_adapter.h"

namespace mindspore {

Status Serialization::Load(const void *model_data, size_t data_size, ModelType model_type, Graph *graph) {
if (model_type != kMindIR) {
MS_LOG(ERROR) << "Unsupported IR.";


+ 8
- 6
mindspore/lite/src/cxx_api/tensor/tensor_impl.cc View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <cstddef>
#include <numeric>
#include <memory>
@@ -33,8 +34,9 @@
namespace mindspore {
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);
if (truncated_shape.empty() && !(shape.empty())) {
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.";
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) {
MS_LOG(ERROR) << "Failed to allocate tensor impl.";
return nullptr;
@@ -54,7 +56,8 @@ MSTensor::Impl *MSTensor::Impl::CreateTensorImpl(const std::string &name, enum D
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();
if (lite_tensor == nullptr) {
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;
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) {
delete lite_tensor;
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);
return impl;
}

} // namespace mindspore

+ 10
- 5
mindspore/lite/src/cxx_api/tensor/tensor_impl.h View File

@@ -13,6 +13,10 @@
* See the License for the specific language governing permissions and
* 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 <numeric>
#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) {
std::vector<std::string> empty;
@@ -116,7 +120,7 @@ class MSTensor::Impl {
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() {
@@ -158,5 +162,6 @@ class MSTensor::Impl {
bool own_data_ = false;
bool from_session_ = false;
};

} // namespace mindspore

#endif // MINDSPORE_LITE_SRC_CXX_API_TENSOR_TENSOR_IMPL_H

+ 6
- 1
mindspore/lite/src/cxx_api/tensor_utils.h View File

@@ -13,6 +13,10 @@
* See the License for the specific language governing permissions and
* 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 <vector>
#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;
}

} // namespace mindspore

#endif // MINDSPORE_LITE_SRC_CXX_API_TENSOR_UTILS_H

+ 6
- 7
mindspore/lite/src/cxx_api/types.cc View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "include/api/types.h"
#include <string.h>
#include <limits.h>
@@ -25,7 +26,6 @@
#include "src/common/log_adapter.h"

namespace mindspore {

class Buffer::Impl {
public:
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::vector<char> &name, enum DataType type, const std::vector<int64_t> &shape,
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;

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;
}
::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) {
MS_LOG(ERROR) << "Allocate tensor impl failed.";
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,
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) {
MS_LOG(ERROR) << "Allocate tensor impl failed.";
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) {
auto impl = std::shared_ptr<Impl>(Impl::StringsToTensorImpl(CharToString(name), VectorCharToString(inputs)));
auto impl = Impl::StringsToTensorImpl(CharToString(name), VectorCharToString(inputs));
if (impl == nullptr) {
MS_LOG(ERROR) << "Allocate tensor impl failed.";
return nullptr;
@@ -148,8 +148,7 @@ MSTensor *MSTensor::Clone() const {
MS_LOG(ERROR) << "Allocate data failed.";
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) {
MS_LOG(ERROR) << "Allocate tensor impl failed.";
free(new_data);


Loading…
Cancel
Save