!20181 [MS][LITE] Fixed double declaration of MSTensor::Impl

Merge pull request !20181 from ehaleva/fix_examples
This commit is contained in:
i-robot 2021-07-14 01:09:06 +00:00 committed by Gitee
commit 99f0a79623
3 changed files with 23 additions and 17 deletions

View File

@ -21,7 +21,11 @@
#include <memory> #include <memory>
#include "include/api/status.h" #include "include/api/status.h"
#include "include/api/types.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" #include "mindspore/core/ir/api_tensor_impl.h"
#endif
#include "minddata/dataset/core/tensor.h" #include "minddata/dataset/core/tensor.h"
namespace mindspore { namespace mindspore {
@ -29,7 +33,7 @@ namespace dataset {
class DETensor : public mindspore::MSTensor::Impl { class DETensor : public mindspore::MSTensor::Impl {
public: public:
DETensor() = default; DETensor() = default;
~DETensor() override = default; ~DETensor() = default;
explicit DETensor(std::shared_ptr<dataset::Tensor> tensor_impl); explicit DETensor(std::shared_ptr<dataset::Tensor> tensor_impl);
#ifndef ENABLE_ANDROID #ifndef ENABLE_ANDROID
explicit DETensor(std::shared_ptr<dataset::DeviceTensor> device_tensor_impl, bool is_device); explicit DETensor(std::shared_ptr<dataset::DeviceTensor> device_tensor_impl, bool is_device);

View File

@ -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 \ 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_LIBCPP_INLINE_VISIBILITY='' -D_LIBCPP_DISABLE_EXTERN_TEMPLATE=1 -DHALF_ENABLE_CPP11_USER_LITERALS=0 \
-D_FORTIFY_SOURCE=2 -Wno-cpp") -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-lambda-capture -Wno-sign-compare -Wno-overloaded-virtual -Wno-unneeded-internal-declaration \
-Wno-unused-variable -Wno-pessimizing-move -Wno-inconsistent-missing-override") -Wno-unused-variable -Wno-pessimizing-move -Wno-inconsistent-missing-override")

View File

@ -14,8 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef 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 #define MINDSPORE_LITE_SRC_CXX_API_TENSOR_TENSOR_IMPL_H_
#include <cstddef> #include <cstddef>
#include <numeric> #include <numeric>
@ -38,7 +38,7 @@ class MSTensor::Impl {
public: public:
Impl() {} Impl() {}
~Impl() { virtual ~Impl() {
if (lite_tensor_ == nullptr) { if (lite_tensor_ == nullptr) {
return; return;
} }
@ -65,7 +65,7 @@ class MSTensor::Impl {
static std::vector<std::string> MS_API TensorImplToStrings(const std::shared_ptr<Impl> &impl); static std::vector<std::string> MS_API TensorImplToStrings(const std::shared_ptr<Impl> &impl);
const std::string &Name() const { virtual const std::string &Name() const {
static std::string empty = ""; static std::string empty = "";
if (lite_tensor_ == nullptr) { if (lite_tensor_ == nullptr) {
MS_LOG(ERROR) << "Invalid tensor."; MS_LOG(ERROR) << "Invalid tensor.";
@ -82,7 +82,7 @@ class MSTensor::Impl {
lite_tensor_->set_tensor_name(name); lite_tensor_->set_tensor_name(name);
} }
enum DataType DataType() const { virtual enum DataType DataType() const {
if (lite_tensor_ == nullptr) { if (lite_tensor_ == nullptr) {
MS_LOG(ERROR) << "Invalid tensor."; MS_LOG(ERROR) << "Invalid tensor.";
return DataType::kTypeUnknown; return DataType::kTypeUnknown;
@ -106,18 +106,20 @@ class MSTensor::Impl {
return static_cast<int64_t>(lite_tensor_->ElementsNum()); return static_cast<int64_t>(lite_tensor_->ElementsNum());
} }
const std::vector<int64_t> &Shape() { virtual const std::vector<int64_t> &Shape() const {
static std::vector<int64_t> empty; static std::vector<int64_t> empty;
if (lite_tensor_ == nullptr) { if (lite_tensor_ == nullptr) {
MS_LOG(ERROR) << "Invalid tensor."; MS_LOG(ERROR) << "Invalid tensor.";
return empty; return empty;
} }
auto shape = lite_tensor_->shape(); auto shape = lite_tensor_->shape();
shape_.resize(shape.size()); lite_shape.resize(shape.size());
std::transform(shape.begin(), shape.end(), shape_.begin(), [](int c) { return static_cast<int64_t>(c); }); std::transform(shape.begin(), shape.end(), lite_shape.begin(), [](int c) { return static_cast<int64_t>(c); });
return shape_; return lite_shape;
} }
virtual std::shared_ptr<Impl> Clone() const { return nullptr; }
void SetShape(const std::vector<int64_t> &shape) { void SetShape(const std::vector<int64_t> &shape) {
if (lite_tensor_ == nullptr) { if (lite_tensor_ == nullptr) {
MS_LOG(ERROR) << "Invalid tensor."; MS_LOG(ERROR) << "Invalid tensor.";
@ -161,7 +163,7 @@ class MSTensor::Impl {
lite_tensor_->set_format(format); lite_tensor_->set_format(format);
} }
std::shared_ptr<const void> Data() const { virtual std::shared_ptr<const void> Data() const {
if (lite_tensor_ == nullptr) { if (lite_tensor_ == nullptr) {
MS_LOG(ERROR) << "Invalid tensor."; MS_LOG(ERROR) << "Invalid tensor.";
return nullptr; return nullptr;
@ -175,7 +177,7 @@ class MSTensor::Impl {
return std::shared_ptr<const void>(lite_tensor_->data(), [](const void *) {}); return std::shared_ptr<const void>(lite_tensor_->data(), [](const void *) {});
} }
void *MutableData() { virtual void *MutableData() {
if (lite_tensor_ == nullptr) { if (lite_tensor_ == nullptr) {
MS_LOG(ERROR) << "Invalid tensor."; MS_LOG(ERROR) << "Invalid tensor.";
return nullptr; return nullptr;
@ -183,7 +185,7 @@ class MSTensor::Impl {
return lite_tensor_->MutableData(); return lite_tensor_->MutableData();
} }
size_t DataSize() const { virtual size_t DataSize() const {
if (lite_tensor_ == nullptr) { if (lite_tensor_ == nullptr) {
MS_LOG(ERROR) << "Invalid tensor."; MS_LOG(ERROR) << "Invalid tensor.";
return 0; return 0;
@ -199,7 +201,7 @@ class MSTensor::Impl {
lite_tensor_->set_data(data); lite_tensor_->set_data(data);
} }
bool IsDevice() const { return false; } virtual bool IsDevice() const { return false; }
tensor::MSTensor *lite_tensor() const { return lite_tensor_; } tensor::MSTensor *lite_tensor() const { return lite_tensor_; }
@ -219,10 +221,10 @@ class MSTensor::Impl {
private: private:
tensor::MSTensor *lite_tensor_ = nullptr; tensor::MSTensor *lite_tensor_ = nullptr;
std::string tensor_name_ = ""; std::string tensor_name_ = "";
std::vector<int64_t> shape_ = {}; mutable std::vector<int64_t> lite_shape;
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 #endif // MINDSPORE_LITE_SRC_CXX_API_TENSOR_TENSOR_IMPL_H_