From 4352317d58f0e93f15fd6222260b679f90715c6a Mon Sep 17 00:00:00 2001 From: Eric Date: Tue, 15 Sep 2020 17:08:16 -0400 Subject: [PATCH] Added compiling lite --- .../ccsrc/minddata/dataset/api/de_tensor.cc | 7 +++--- .../minddata/dataset/include/de_tensor.h | 10 ++++---- .../lite/minddata/example/jni-example.cc | 2 +- .../lite/minddata/example/x86-example.cc | 2 +- .../test/ut/src/dataset/de_tensor_test.cc | 23 ++----------------- 5 files changed, 13 insertions(+), 31 deletions(-) diff --git a/mindspore/ccsrc/minddata/dataset/api/de_tensor.cc b/mindspore/ccsrc/minddata/dataset/api/de_tensor.cc index b8c6a5c163..190cc4efe9 100644 --- a/mindspore/ccsrc/minddata/dataset/api/de_tensor.cc +++ b/mindspore/ccsrc/minddata/dataset/api/de_tensor.cc @@ -20,7 +20,8 @@ #include "minddata/dataset/core/data_type.h" #include "mindspore/core/ir/dtype/type_id.h" #include "utils/hashing.h" -#include "mindspore/lite/src/ir/tensor.h" +#include "mindspore/lite/internal/include/ms_tensor.h" +#include "mindspore/core/utils/convert_utils_base.h" namespace mindspore { namespace tensor { @@ -59,7 +60,7 @@ DETensor::DETensor(std::shared_ptr tensor_ptr) { this->tensor_i MSTensor *DETensor::ConvertToLiteTensor() { // static MSTensor::CreateTensor is only for the LiteTensor - MSTensor *tensor = MSTensor::CreateTensor(this->data_type(), this->shape()); + MSTensor *tensor = CreateTensor(this->data_type(), this->shape()); MS_ASSERT(tensor->Size() == this->Size()); memcpy_s(tensor->MutableData(), tensor->Size(), this->MutableData(), this->Size()); return tensor; @@ -141,7 +142,7 @@ size_t DETensor::Size() const { return this->tensor_impl_->SizeInBytes(); } -void *DETensor::MutableData() const { +void *DETensor::MutableData() { MS_ASSERT(this->tensor_impl_ != nullptr); return this->tensor_impl_->GetMutableBuffer(); } diff --git a/mindspore/ccsrc/minddata/dataset/include/de_tensor.h b/mindspore/ccsrc/minddata/dataset/include/de_tensor.h index b73675c739..eb7c457b3f 100644 --- a/mindspore/ccsrc/minddata/dataset/include/de_tensor.h +++ b/mindspore/ccsrc/minddata/dataset/include/de_tensor.h @@ -24,7 +24,7 @@ #include "minddata/dataset/util/status.h" namespace mindspore { namespace tensor { -class DETensor : public MSTensor { +class DETensor : public mindspore::tensor::MSTensor { public: /// \brief Create a MSTensor pointer. /// \param[in] data_type DataTypeId of tensor to be created @@ -58,21 +58,21 @@ class DETensor : public MSTensor { TypeId data_type() const override; - TypeId set_data_type(const TypeId data_type) override; + TypeId set_data_type(const TypeId data_type); std::vector shape() const override; - size_t set_shape(const std::vector &shape) override; + size_t set_shape(const std::vector &shape); int DimensionSize(size_t index) const override; int ElementsNum() const override; - std::size_t hash() const override; + std::size_t hash() const; size_t Size() const override; - void *MutableData() const override; + void *MutableData() override; protected: std::shared_ptr tensor_impl_; diff --git a/mindspore/lite/minddata/example/jni-example.cc b/mindspore/lite/minddata/example/jni-example.cc index 356893ae69..9be60716df 100644 --- a/mindspore/lite/minddata/example/jni-example.cc +++ b/mindspore/lite/minddata/example/jni-example.cc @@ -65,7 +65,7 @@ extern "C" JNIEXPORT void JNICALL Java_com_example_mindsporepredict_MainActivity // Create a Cifar10 Dataset std::string folder_path = env->GetStringUTFChars(path, 0); - std::shared_ptr ds = Cifar10(folder_path, RandomSampler(false, 10)); + std::shared_ptr ds = Cifar10(folder_path, std::string(), RandomSampler(false, 10)); // Create an iterator over the result of the above dataset // This will trigger the creation of the Execution Tree and launch it. diff --git a/mindspore/lite/minddata/example/x86-example.cc b/mindspore/lite/minddata/example/x86-example.cc index 4dfddb7c2b..7458a81b2c 100644 --- a/mindspore/lite/minddata/example/x86-example.cc +++ b/mindspore/lite/minddata/example/x86-example.cc @@ -32,7 +32,7 @@ int main() { // Create a Cifar10 Dataset std::string folder_path = "./testCifar10Data/"; - std::shared_ptr ds = Cifar10(folder_path, RandomSampler(false, 10)); + std::shared_ptr ds = Cifar10(folder_path, std::string(), RandomSampler(false, 10)); // Create an iterator over the result of the above dataset // This will trigger the creation of the Execution Tree and launch it. diff --git a/mindspore/lite/test/ut/src/dataset/de_tensor_test.cc b/mindspore/lite/test/ut/src/dataset/de_tensor_test.cc index 21248e6dd5..343331c682 100644 --- a/mindspore/lite/test/ut/src/dataset/de_tensor_test.cc +++ b/mindspore/lite/test/ut/src/dataset/de_tensor_test.cc @@ -25,7 +25,7 @@ using MSTensor = mindspore::tensor::MSTensor; using DETensor = mindspore::tensor::DETensor; -using LiteTensor = mindspore::lite::tensor::LiteTensor; +using LiteTensor = mindspore::lite::Tensor; using Tensor = mindspore::dataset::Tensor; using DataType = mindspore::dataset::DataType; using TensorShape = mindspore::dataset::TensorShape; @@ -56,11 +56,6 @@ TEST_F(MindDataTestTensorDE, MSTensorShape) { auto ms_tensor = std::shared_ptr(new DETensor(t)); ASSERT_EQ(ms_tensor->DimensionSize(0) == 2, true); ASSERT_EQ(ms_tensor->DimensionSize(1) == 3, true); - ms_tensor->set_shape(std::vector{3, 2}); - ASSERT_EQ(ms_tensor->DimensionSize(0) == 3, true); - ASSERT_EQ(ms_tensor->DimensionSize(1) == 2, true); - ms_tensor->set_shape(std::vector{6}); - ASSERT_EQ(ms_tensor->DimensionSize(0) == 6, true); } TEST_F(MindDataTestTensorDE, MSTensorSize) { @@ -74,9 +69,6 @@ TEST_F(MindDataTestTensorDE, MSTensorDataType) { std::shared_ptr t = std::make_shared(TensorShape({2, 3}), DataType(DataType::DE_FLOAT32)); auto ms_tensor = std::shared_ptr(new DETensor(t)); ASSERT_EQ(ms_tensor->data_type() == mindspore::TypeId::kNumberTypeFloat32, true); - ms_tensor->set_data_type(mindspore::TypeId::kNumberTypeInt32); - ASSERT_EQ(ms_tensor->data_type() == mindspore::TypeId::kNumberTypeInt32, true); - ASSERT_EQ(std::dynamic_pointer_cast(ms_tensor)->tensor()->type() == DataType::DE_INT32, true); } TEST_F(MindDataTestTensorDE, MSTensorMutableData) { @@ -89,19 +81,8 @@ TEST_F(MindDataTestTensorDE, MSTensorMutableData) { ASSERT_EQ(x == tensor_vec, true); } -TEST_F(MindDataTestTensorDE, MSTensorHash) { - std::vector x = {2.5, 2.5, 2.5, 2.5}; - std::shared_ptr t; - Tensor::CreateFromVector(x, TensorShape({2, 2}), &t); - auto ms_tensor = std::shared_ptr(new DETensor(t)); - ASSERT_EQ(ms_tensor->hash() == 11093771382437, true); -} - TEST_F(MindDataTestTensorDE, MSTensorCreateFromMemory) { std::vector x = {2.5, 2.5, 2.5, 2.5}; auto mem_tensor = DETensor::CreateFromMemory(mindspore::TypeId::kNumberTypeFloat32, {2, 2}, &x[0]); - std::shared_ptr t; - Tensor::CreateFromVector(x, TensorShape({2, 2}), &t); - auto ms_tensor = std::shared_ptr(new DETensor(t)); - ASSERT_EQ(ms_tensor->hash() == mem_tensor->hash(), true); + ASSERT_EQ(mem_tensor->data_type() == mindspore::TypeId::kNumberTypeFloat32, true); }