diff --git a/mindspore/ccsrc/minddata/dataset/core/de_tensor.h b/mindspore/ccsrc/minddata/dataset/core/de_tensor.h index ea22585e3c8..e9754b58f58 100644 --- a/mindspore/ccsrc/minddata/dataset/core/de_tensor.h +++ b/mindspore/ccsrc/minddata/dataset/core/de_tensor.h @@ -21,7 +21,11 @@ #include #include "include/api/status.h" #include "include/api/types.h" +#ifdef ENABLE_ANDROID +#include "mindspore/lite/src/cxx_api/tensor/tensor_impl.h" +#else #include "mindspore/core/ir/api_tensor_impl.h" +#endif #include "minddata/dataset/core/tensor.h" namespace mindspore { @@ -29,7 +33,7 @@ namespace dataset { class DETensor : public mindspore::MSTensor::Impl { public: DETensor() = default; - ~DETensor() override = default; + ~DETensor() = default; explicit DETensor(std::shared_ptr tensor_impl); #ifndef ENABLE_ANDROID explicit DETensor(std::shared_ptr device_tensor_impl, bool is_device); diff --git a/mindspore/lite/minddata/CMakeLists.txt b/mindspore/lite/minddata/CMakeLists.txt index 694f10f0ad1..74eee1946f4 100644 --- a/mindspore/lite/minddata/CMakeLists.txt +++ b/mindspore/lite/minddata/CMakeLists.txt @@ -12,7 +12,7 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -g2 -ggdb -fno-inline-functions -fno-omit-frame-pointer \ -D_LIBCPP_INLINE_VISIBILITY='' -D_LIBCPP_DISABLE_EXTERN_TEMPLATE=1 -DHALF_ENABLE_CPP11_USER_LITERALS=0 \ -D_FORTIFY_SOURCE=2 -Wno-cpp") -set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -Werror -Wno-return-std-move -Wno-unused-private-field \ +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Werror -Wno-return-std-move -Wno-unused-private-field \ -Wno-unused-lambda-capture -Wno-sign-compare -Wno-overloaded-virtual -Wno-unneeded-internal-declaration \ -Wno-unused-variable -Wno-pessimizing-move -Wno-inconsistent-missing-override") diff --git a/mindspore/lite/src/cxx_api/tensor/tensor_impl.h b/mindspore/lite/src/cxx_api/tensor/tensor_impl.h index 1c0d6896e4e..dceec3bc167 100644 --- a/mindspore/lite/src/cxx_api/tensor/tensor_impl.h +++ b/mindspore/lite/src/cxx_api/tensor/tensor_impl.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef MINDSPORE_LITE_SRC_CXX_API_TENSOR_TENSOR_IMPL_H -#define MINDSPORE_LITE_SRC_CXX_API_TENSOR_TENSOR_IMPL_H +#ifndef MINDSPORE_LITE_SRC_CXX_API_TENSOR_TENSOR_IMPL_H_ +#define MINDSPORE_LITE_SRC_CXX_API_TENSOR_TENSOR_IMPL_H_ #include #include @@ -38,7 +38,7 @@ class MSTensor::Impl { public: Impl() {} - ~Impl() { + virtual ~Impl() { if (lite_tensor_ == nullptr) { return; } @@ -65,7 +65,7 @@ class MSTensor::Impl { static std::vector MS_API TensorImplToStrings(const std::shared_ptr &impl); - const std::string &Name() const { + virtual const std::string &Name() const { static std::string empty = ""; if (lite_tensor_ == nullptr) { MS_LOG(ERROR) << "Invalid tensor."; @@ -82,7 +82,7 @@ class MSTensor::Impl { lite_tensor_->set_tensor_name(name); } - enum DataType DataType() const { + virtual enum DataType DataType() const { if (lite_tensor_ == nullptr) { MS_LOG(ERROR) << "Invalid tensor."; return DataType::kTypeUnknown; @@ -106,18 +106,20 @@ class MSTensor::Impl { return static_cast(lite_tensor_->ElementsNum()); } - const std::vector &Shape() { + virtual const std::vector &Shape() const { static std::vector empty; if (lite_tensor_ == nullptr) { MS_LOG(ERROR) << "Invalid tensor."; return empty; } auto shape = lite_tensor_->shape(); - shape_.resize(shape.size()); - std::transform(shape.begin(), shape.end(), shape_.begin(), [](int c) { return static_cast(c); }); - return shape_; + lite_shape.resize(shape.size()); + std::transform(shape.begin(), shape.end(), lite_shape.begin(), [](int c) { return static_cast(c); }); + return lite_shape; } + virtual std::shared_ptr Clone() const { return nullptr; } + void SetShape(const std::vector &shape) { if (lite_tensor_ == nullptr) { MS_LOG(ERROR) << "Invalid tensor."; @@ -161,7 +163,7 @@ class MSTensor::Impl { lite_tensor_->set_format(format); } - std::shared_ptr Data() const { + virtual std::shared_ptr Data() const { if (lite_tensor_ == nullptr) { MS_LOG(ERROR) << "Invalid tensor."; return nullptr; @@ -175,7 +177,7 @@ class MSTensor::Impl { return std::shared_ptr(lite_tensor_->data(), [](const void *) {}); } - void *MutableData() { + virtual void *MutableData() { if (lite_tensor_ == nullptr) { MS_LOG(ERROR) << "Invalid tensor."; return nullptr; @@ -183,7 +185,7 @@ class MSTensor::Impl { return lite_tensor_->MutableData(); } - size_t DataSize() const { + virtual size_t DataSize() const { if (lite_tensor_ == nullptr) { MS_LOG(ERROR) << "Invalid tensor."; return 0; @@ -199,7 +201,7 @@ class MSTensor::Impl { lite_tensor_->set_data(data); } - bool IsDevice() const { return false; } + virtual bool IsDevice() const { return false; } tensor::MSTensor *lite_tensor() const { return lite_tensor_; } @@ -219,10 +221,10 @@ class MSTensor::Impl { private: tensor::MSTensor *lite_tensor_ = nullptr; std::string tensor_name_ = ""; - std::vector shape_ = {}; + mutable std::vector lite_shape; bool own_data_ = false; bool from_session_ = false; }; } // namespace mindspore -#endif // MINDSPORE_LITE_SRC_CXX_API_TENSOR_TENSOR_IMPL_H +#endif // MINDSPORE_LITE_SRC_CXX_API_TENSOR_TENSOR_IMPL_H_