Browse Source

move out MSTensor CreateTensor to ms_tensor.cc

pull/15328/head
zhaodezan 4 years ago
parent
commit
b761269ecc
8 changed files with 50 additions and 22 deletions
  1. +1
    -0
      mindspore/lite/minddata/CMakeLists.txt
  2. +1
    -0
      mindspore/lite/src/CMakeLists.txt
  3. +6
    -6
      mindspore/lite/src/common/loader_util.cc
  4. +2
    -2
      mindspore/lite/src/common/loader_util.h
  5. +38
    -0
      mindspore/lite/src/ms_tensor.cc
  6. +0
    -14
      mindspore/lite/src/tensor.cc
  7. +1
    -0
      mindspore/lite/test/CMakeLists.txt
  8. +1
    -0
      mindspore/lite/tools/converter/CMakeLists.txt

+ 1
- 0
mindspore/lite/minddata/CMakeLists.txt View File

@@ -110,6 +110,7 @@ if(BUILD_MINDDATA STREQUAL "full")
${TOP_DIR}/mindspore/lite/src/cxx_api/types.cc ${TOP_DIR}/mindspore/lite/src/cxx_api/types.cc
${TOP_DIR}/mindspore/lite/src/cxx_api/tensor/tensor_impl.cc ${TOP_DIR}/mindspore/lite/src/cxx_api/tensor/tensor_impl.cc
${TOP_DIR}/mindspore/lite/src/tensor.cc ${TOP_DIR}/mindspore/lite/src/tensor.cc
${TOP_DIR}/mindspore/lite/src/ms_tensor.cc
${TOP_DIR}/mindspore/lite/src/common/string_util.cc ${TOP_DIR}/mindspore/lite/src/common/string_util.cc
${CORE_DIR}/utils/status.cc ${CORE_DIR}/utils/status.cc
${MINDDATA_DIR}/api/datasets.cc ${MINDDATA_DIR}/api/datasets.cc


+ 1
- 0
mindspore/lite/src/CMakeLists.txt View File

@@ -54,6 +54,7 @@ set(LITE_SRC
${CMAKE_CURRENT_SOURCE_DIR}/runtime/thread_pool.c ${CMAKE_CURRENT_SOURCE_DIR}/runtime/thread_pool.c
${CMAKE_CURRENT_SOURCE_DIR}/runtime/infer_manager.cc ${CMAKE_CURRENT_SOURCE_DIR}/runtime/infer_manager.cc
${CMAKE_CURRENT_SOURCE_DIR}/tensor.cc ${CMAKE_CURRENT_SOURCE_DIR}/tensor.cc
${CMAKE_CURRENT_SOURCE_DIR}/ms_tensor.cc
${CMAKE_CURRENT_SOURCE_DIR}/tensorlist.cc ${CMAKE_CURRENT_SOURCE_DIR}/tensorlist.cc
${CMAKE_CURRENT_SOURCE_DIR}/executor.cc ${CMAKE_CURRENT_SOURCE_DIR}/executor.cc
${CMAKE_CURRENT_SOURCE_DIR}/inner_context.cc ${CMAKE_CURRENT_SOURCE_DIR}/inner_context.cc


+ 6
- 6
mindspore/lite/src/common/loader_util.cc View File

@@ -24,18 +24,18 @@


namespace mindspore { namespace mindspore {
namespace lite { namespace lite {
int SoLoader::Open(const char *SoPath, int mode) {
if ((strlen(SoPath)) >= PATH_MAX) {
int SoLoader::Open(const char *so_path, int mode) {
if ((strlen(so_path)) >= PATH_MAX) {
MS_LOG(ERROR) << "path is too long"; MS_LOG(ERROR) << "path is too long";
return RET_ERROR; return RET_ERROR;
} }
char resolved_path[PATH_MAX]; char resolved_path[PATH_MAX];
auto resolve_res = realpath(SoPath, resolved_path);
auto resolve_res = realpath(so_path, resolved_path);
if (resolve_res == nullptr) { if (resolve_res == nullptr) {
MS_LOG(ERROR) << "PATH NOT EXITS";
MS_LOG(ERROR) << "path not exist";
return RET_ERROR; return RET_ERROR;
} }
handler_ = dlopen(SoPath, mode);
handler_ = dlopen(so_path, mode);
if (handler_ == nullptr) { if (handler_ == nullptr) {
MS_LOG(ERROR) << "open path failed"; MS_LOG(ERROR) << "open path failed";
return RET_ERROR; return RET_ERROR;
@@ -43,7 +43,7 @@ int SoLoader::Open(const char *SoPath, int mode) {
return RET_OK; return RET_OK;
} }


void *SoLoader::GetFunc(const char *FuncName) { return dlsym(handler_, FuncName); }
void *SoLoader::GetFunc(const char *func_name) { return dlsym(handler_, func_name); }


int SoLoader::Close() { int SoLoader::Close() {
auto close_res = dlclose(handler_); auto close_res = dlclose(handler_);


+ 2
- 2
mindspore/lite/src/common/loader_util.h View File

@@ -25,8 +25,8 @@ namespace lite {


class SoLoader { class SoLoader {
public: public:
int Open(const char *SoPath, int mode = RTLD_LAZY);
void *GetFunc(const char *FuncName);
int Open(const char *so_path, int mode = RTLD_LAZY);
void *GetFunc(const char *func_name);
int Close(); int Close();


private: private:


+ 38
- 0
mindspore/lite/src/ms_tensor.cc View File

@@ -0,0 +1,38 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "include/ms_tensor.h"
#include "src/tensor.h"

namespace mindspore {
namespace tensor {

tensor::MSTensor *tensor::MSTensor::CreateTensor(const std::string &name, TypeId type, const std::vector<int> &shape,
const void *data, size_t data_len) {
auto tensor = new (std::nothrow) lite::Tensor();
if (tensor == nullptr) {
MS_LOG(ERROR) << "Failed to allocate tensor.";
return nullptr;
}
tensor->set_data(const_cast<void *>(data));
tensor->set_shape(shape);
tensor->set_tensor_name(name);
tensor->set_data_type(type);
return tensor;
}

} // namespace tensor
} // namespace mindspore

+ 0
- 14
mindspore/lite/src/tensor.cc View File

@@ -375,18 +375,4 @@ std::vector<tensor::MSTensor *> TensorVectorCast(const std::vector<Tensor *> &sr


} // namespace lite } // namespace lite


tensor::MSTensor *tensor::MSTensor::CreateTensor(const std::string &name, TypeId type, const std::vector<int> &shape,
const void *data, size_t data_len) {
auto tensor = new (std::nothrow) lite::Tensor();
if (tensor == nullptr) {
MS_LOG(ERROR) << "Failed to allocate tensor.";
return nullptr;
}
tensor->set_data(const_cast<void *>(data));
tensor->set_shape(shape);
tensor->set_tensor_name(name);
tensor->set_data_type(type);
return tensor;
}

} // namespace mindspore } // namespace mindspore

+ 1
- 0
mindspore/lite/test/CMakeLists.txt View File

@@ -137,6 +137,7 @@ set(TEST_LITE_SRC
${LITE_DIR}/src/runtime/parallel_executor.cc ${LITE_DIR}/src/runtime/parallel_executor.cc
${LITE_DIR}/src/runtime/infer_manager.cc ${LITE_DIR}/src/runtime/infer_manager.cc
${LITE_DIR}/src/tensor.cc ${LITE_DIR}/src/tensor.cc
${LITE_DIR}/src/ms_tensor.cc
${LITE_DIR}/src/tensorlist.cc ${LITE_DIR}/src/tensorlist.cc
${LITE_DIR}/src/executor.cc ${LITE_DIR}/src/executor.cc
${LITE_DIR}/src/inner_context.cc ${LITE_DIR}/src/inner_context.cc


+ 1
- 0
mindspore/lite/tools/converter/CMakeLists.txt View File

@@ -104,6 +104,7 @@ set(LITE_SRC
${SRC_DIR}/runtime/infer_manager.cc ${SRC_DIR}/runtime/infer_manager.cc
${SRC_DIR}/inner_context.cc ${SRC_DIR}/inner_context.cc
${SRC_DIR}/tensor.cc ${SRC_DIR}/tensor.cc
${SRC_DIR}/ms_tensor.cc
${SRC_DIR}/tensorlist.cc ${SRC_DIR}/tensorlist.cc
${SRC_DIR}/kernel_registry.cc ${SRC_DIR}/kernel_registry.cc
${SRC_DIR}/lite_kernel.cc ${SRC_DIR}/lite_kernel.cc


Loading…
Cancel
Save