parent
1f4222edfb
commit
174d308cfa
@ -1,7 +1,3 @@
|
||||
file(GLOB_RECURSE _IR_SRC_LIST ./*.cc dtype/*.cc)
|
||||
file(GLOB_RECURSE _IR_LITE_SRC_FILES
|
||||
./lite/tensor.cc
|
||||
)
|
||||
list(REMOVE_ITEM _IR_SRC_LIST ${_IR_LITE_SRC_FILES})
|
||||
set_property(SOURCE ${_IR_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_IR)
|
||||
add_library(_mindspore_ir_obj OBJECT ${_IR_SRC_LIST})
|
||||
|
@ -1,88 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 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 <vector>
|
||||
#include <utility>
|
||||
#include "ir/lite/tensor.h"
|
||||
#include "securec/include/securec.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace tensor {
|
||||
#define kMaxMallocSize 1024 * 1024 * 100
|
||||
Tensor::Tensor(const TypeId data_type, const std::vector<int> &shape) : MetaTensor(data_type, shape) {}
|
||||
|
||||
Tensor::Tensor(const TypePtr &type_ptr, const std::vector<int> &shape) : MetaTensor(type_ptr, shape) {}
|
||||
|
||||
Tensor::Tensor(const Tensor &tensor) : MetaTensor(tensor) {
|
||||
this->data_type_ = tensor.data_type_;
|
||||
this->shape_ = tensor.shape_;
|
||||
auto ret = CopyTensorData(tensor);
|
||||
if (0 != ret) {
|
||||
MS_LOG(EXCEPTION) << "CopyTensorData error";
|
||||
}
|
||||
}
|
||||
|
||||
int Tensor::CopyTensorData(const Tensor &srcTensor) {
|
||||
if (srcTensor.data_ == nullptr) {
|
||||
MS_LOG(ERROR) << "data of srcTensor is nullptr";
|
||||
return -1;
|
||||
}
|
||||
size_t data_size = this->Size();
|
||||
MS_ASSERT(data_size == tensor.Size());
|
||||
if (this->data_ == nullptr) {
|
||||
if (data_size > kMaxMallocSize) {
|
||||
MS_LOG(ERROR) << "Malloc size is too big while coping data, " << data_size << " bytes";
|
||||
return -1;
|
||||
}
|
||||
this->data_ = malloc(data_size);
|
||||
}
|
||||
memcpy_s(this->data_, data_size, tensor.data_, tensor.Size());
|
||||
return 0;
|
||||
}
|
||||
|
||||
Tensor::~Tensor() {
|
||||
if (nullptr != this->data_) {
|
||||
free(this->data_);
|
||||
}
|
||||
}
|
||||
|
||||
Tensor &Tensor::operator=(const Tensor &tensor) {
|
||||
if (&tensor == this) {
|
||||
return *this;
|
||||
}
|
||||
this->shape_ = tensor.shape_;
|
||||
this->data_type_ = tensor.data_type_;
|
||||
auto ret = CopyTensorData(tensor);
|
||||
if (0 != ret) {
|
||||
MS_LOG(EXCEPTION) << "CopyTensorData error";
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Tensor::operator==(const Tensor &tensor) {
|
||||
return data_ == tensor.data_ && shape_ == tensor.shape_ && data_type_ == tensor.data_type_;
|
||||
}
|
||||
|
||||
bool Tensor::operator==(const Value &other) const {
|
||||
if (other.isa<Tensor>()) {
|
||||
auto other_ = static_cast<const Tensor &>(other);
|
||||
return *this == other_;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} // namespace tensor
|
||||
} // namespace mindspore
|
@ -1,61 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef MINDSPORE_CORE_IR_LITE_TENSOR_H_
|
||||
#define MINDSPORE_CORE_IR_LITE_TENSOR_H_
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include "ir/meta_tensor.h"
|
||||
#include "ir/dtype/type.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace tensor {
|
||||
class Tensor : public MetaTensor {
|
||||
public:
|
||||
Tensor() : MetaTensor() {}
|
||||
|
||||
Tensor(const TypeId data_type, const std::vector<int> &shape);
|
||||
|
||||
Tensor(const TypePtr &type_ptr, const std::vector<int> &shape);
|
||||
|
||||
Tensor(const Tensor &tensor);
|
||||
|
||||
~Tensor();
|
||||
|
||||
int CopyTensorData(const Tensor &srcTensor);
|
||||
|
||||
MS_DECLARE_PARENT(Tensor, MetaTensor)
|
||||
|
||||
virtual Tensor &operator=(const Tensor &tensor);
|
||||
|
||||
virtual bool operator==(const Tensor &tensor);
|
||||
|
||||
bool operator==(const Value &other) const override;
|
||||
|
||||
size_t Size() const { return MetaTensor::ElementsNum() * GetTypeByte(TypeIdToType(this->data_type_)); }
|
||||
|
||||
void *Data() const { return data_; }
|
||||
|
||||
protected:
|
||||
void *data_;
|
||||
};
|
||||
|
||||
using TensorPtr = std::shared_ptr<Tensor>;
|
||||
} // namespace tensor
|
||||
} // namespace mindspore
|
||||
|
||||
#endif // MINDSPORE_CORE_IR_LITE_TENSOR_H_
|
@ -0,0 +1,119 @@
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
project (Lite)
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.3.0)
|
||||
message(FATAL_ERROR "GCC vesion ${CMAKE_CXX_COMPILER_VERSION} must not be less than 7.3.0")
|
||||
endif ()
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
|
||||
set(TOP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../..)
|
||||
set(CORE_DIR ${TOP_DIR}/mindspore/core)
|
||||
set(CCSRC_DIR ${TOP_DIR}/mindspore/ccsrc)
|
||||
include_directories(${TOP_DIR})
|
||||
include_directories(${CORE_DIR})
|
||||
include_directories(${CCSRC_DIR})
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
include_directories(${TOP_DIR}/third_party)
|
||||
include_directories(${TOP_DIR}/third_party/flatbuffers/include)
|
||||
|
||||
include(${TOP_DIR}/cmake/utils.cmake)
|
||||
include(${TOP_DIR}/cmake/external_libs/json.cmake)
|
||||
include(${TOP_DIR}/cmake/dependency_securec.cmake)
|
||||
set(CMAKE_VERBOSE_MAKEFILE on)
|
||||
add_compile_definitions(USE_ANDROID_LOG)
|
||||
add_compile_definitions(NO_DLIB)
|
||||
add_compile_options(-fPIC)
|
||||
|
||||
option(BUILD_DEVICE "if build device" on)
|
||||
option(SUPPORT_TRAIN "if build for on-device train" off)
|
||||
option(PLATFORM_ARM64 "if build device for arm64" off)
|
||||
option(PLATFORM_ARM32 "if build device for arm32" off)
|
||||
option(BUILD_CONVERTER "if build converter" on)
|
||||
option(ENABLE_FP16 "if build fp16 ops" off)
|
||||
option(SUPPORT_GPU "if support gpu" off)
|
||||
option(OFFLINE_COMPILE "if offline compile OpenCL kernel" off)
|
||||
|
||||
if (BUILD_DEVICE)
|
||||
add_compile_definitions(BUILD_DEVICE)
|
||||
endif()
|
||||
if (SUPPORT_TRAIN)
|
||||
add_compile_definitions(SUPPORT_TRAIN)
|
||||
endif()
|
||||
if (ENABLE_NEON)
|
||||
add_compile_definitions(ENABLE_NEON)
|
||||
endif ()
|
||||
if (ENABLE_FP16)
|
||||
add_compile_definitions(ENABLE_FP16)
|
||||
endif ()
|
||||
if (SUPPORT_GPU)
|
||||
add_definitions(-DUSE_OPENCL_WRAPPER)
|
||||
add_definitions(-DMS_OPENCL_PROFILE=false)
|
||||
add_definitions(-DCL_HPP_TARGET_OPENCL_VERSION=200)
|
||||
add_compile_definitions(SUPPORT_GPU)
|
||||
if(OFFLINE_COMPILE)
|
||||
add_compile_definitions(PROGRAM_WITH_IL)
|
||||
endif()
|
||||
include_directories(${TOP_DIR}/third_party/OpenCL-Headers)
|
||||
include_directories(${TOP_DIR}/third_party/OpenCL-CLHPP/include)
|
||||
endif()
|
||||
|
||||
set(ANF_SRC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../core/ir/meta_tensor.cc
|
||||
${CCSRC_DIR}/gvar/logging_level.cc
|
||||
${CCSRC_DIR}/gvar/typeid_manager.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../core/base/base.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../core/utils/log_adapter.cc
|
||||
)
|
||||
if (BUILD_CONVERTER)
|
||||
if (PLATFORM_ARM64 OR PLATFORM_ARM32)
|
||||
MESSAGE(FATAL_ERROR "Cannot build converter in arm platform")
|
||||
endif()
|
||||
find_package(Python3 3.7 COMPONENTS Interpreter Development)
|
||||
if(Python3_FOUND)
|
||||
set(PYTHON_INCLUDE_DIRS "${Python3_INCLUDE_DIRS}")
|
||||
set(PYTHON_LIBRARIES "${Python3_LIBRARIES}")
|
||||
if (WIN32)
|
||||
if (Python3_DIR)
|
||||
message("Python3_DIR set already: " ${Python3_DIR})
|
||||
else()
|
||||
string(LENGTH ${PYTHON_LIBRARIES} PYTHON_LIBRARIES_LEN)
|
||||
string(LENGTH "libpythonxx.a" Python3_NAME_LEN)
|
||||
math(EXPR Python3_DIR_LEN ${PYTHON_LIBRARIES_LEN}-${Python3_NAME_LEN})
|
||||
string(SUBSTRING ${Python3_LIBRARIES} 0 ${Python3_DIR_LEN} Python3_DIR)
|
||||
message("Python3_DIR: " ${Python3_DIR})
|
||||
endif()
|
||||
link_directories(${Python3_DIR})
|
||||
endif()
|
||||
else()
|
||||
find_python_package(py_inc py_lib)
|
||||
set(PYTHON_INCLUDE_DIRS "${py_inc}")
|
||||
set(PYTHON_LIBRARIES "${py_lib}")
|
||||
endif()
|
||||
include_directories(${PYTHON_INCLUDE_DIRS})
|
||||
include(${TOP_DIR}/cmake/external_libs/pybind11.cmake)
|
||||
include(${TOP_DIR}/cmake/external_libs/eigen.cmake)
|
||||
include_directories(${TOP_DIR}/third_party/protobuf/build/include)
|
||||
link_directories(${TOP_DIR}/third_party/protobuf/build/lib)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/converter)
|
||||
add_subdirectory(src/common/anf_exporter)
|
||||
endif()
|
||||
|
||||
if (BUILD_DEVICE)
|
||||
if (PLATFORM_ARM32 OR PLATFORM_ARM64)
|
||||
if (NOT DEFINED ENV{ANDROID_NDK})
|
||||
message(FATAL_ERROR "env ANDROID_NDK should be setted for ARM compile")
|
||||
endif()
|
||||
add_compile_definitions(ENABLE_ARM)
|
||||
endif()
|
||||
if (PLATFORM_ARM32)
|
||||
add_definitions(-mfloat-abi=softfp -mfpu=neon)
|
||||
add_compile_definitions(ENABLE_ARM32)
|
||||
endif()
|
||||
if (PLATFORM_ARM64)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8.2-a+dotprod+fp16")
|
||||
add_compile_definitions(ENABLE_ARM64)
|
||||
endif()
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/benchmark)
|
||||
# add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test)
|
||||
endif()
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@ -0,0 +1,7 @@
|
||||
# CMake generated Testfile for
|
||||
# Source directory: /mnt/data/workspace/OpenAI/Huawei/mindspore/third_party/googletest
|
||||
# Build directory: /mnt/data/workspace/OpenAI/Huawei/mindspore/mindspore/lite/cmake-build-cloud/googletest
|
||||
#
|
||||
# This file includes the relevant testing commands required for
|
||||
# testing this directory and lists subdirectories to be tested as well.
|
||||
subdirs("googlemock")
|
@ -0,0 +1,7 @@
|
||||
# CMake generated Testfile for
|
||||
# Source directory: /mnt/data/workspace/OpenAI/Huawei/mindspore/third_party/googletest/googlemock
|
||||
# Build directory: /mnt/data/workspace/OpenAI/Huawei/mindspore/mindspore/lite/cmake-build-cloud/googletest/googlemock
|
||||
#
|
||||
# This file includes the relevant testing commands required for
|
||||
# testing this directory and lists subdirectories to be tested as well.
|
||||
subdirs("gtest")
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,6 @@
|
||||
# CMake generated Testfile for
|
||||
# Source directory: /mnt/data/workspace/OpenAI/Huawei/mindspore/third_party/googletest/googletest
|
||||
# Build directory: /mnt/data/workspace/OpenAI/Huawei/mindspore/mindspore/lite/cmake-build-cloud/googletest/googlemock/gtest
|
||||
#
|
||||
# This file includes the relevant testing commands required for
|
||||
# testing this directory and lists subdirectories to be tested as well.
|
@ -0,0 +1,33 @@
|
||||
|
||||
####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
|
||||
####### Any changes to this file will be overwritten by the next CMake run ####
|
||||
####### The input file was Config.cmake.in ########
|
||||
|
||||
get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)
|
||||
|
||||
macro(set_and_check _var _file)
|
||||
set(${_var} "${_file}")
|
||||
if(NOT EXISTS "${_file}")
|
||||
message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
macro(check_required_components _NAME)
|
||||
foreach(comp ${${_NAME}_FIND_COMPONENTS})
|
||||
if(NOT ${_NAME}_${comp}_FOUND)
|
||||
if(${_NAME}_FIND_REQUIRED_${comp})
|
||||
set(${_NAME}_FOUND FALSE)
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
endmacro()
|
||||
|
||||
####################################################################################
|
||||
include(CMakeFindDependencyMacro)
|
||||
if (ON)
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_dependency(Threads)
|
||||
endif()
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/GTestTargets.cmake")
|
||||
check_required_components("")
|
@ -0,0 +1,37 @@
|
||||
# This is a basic version file for the Config-mode of find_package().
|
||||
# It is used by write_basic_package_version_file() as input file for configure_file()
|
||||
# to create a version-file which can be installed along a config.cmake file.
|
||||
#
|
||||
# The created file sets PACKAGE_VERSION_EXACT if the current version string and
|
||||
# the requested version string are exactly the same and it sets
|
||||
# PACKAGE_VERSION_COMPATIBLE if the current version is >= requested version.
|
||||
# The variable CVF_VERSION must be set before calling configure_file().
|
||||
|
||||
set(PACKAGE_VERSION "1.9.0")
|
||||
|
||||
if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
|
||||
set(PACKAGE_VERSION_COMPATIBLE FALSE)
|
||||
else()
|
||||
set(PACKAGE_VERSION_COMPATIBLE TRUE)
|
||||
if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
|
||||
set(PACKAGE_VERSION_EXACT TRUE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
# if the installed project requested no architecture check, don't perform the check
|
||||
if("FALSE")
|
||||
return()
|
||||
endif()
|
||||
|
||||
# if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it:
|
||||
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "8" STREQUAL "")
|
||||
return()
|
||||
endif()
|
||||
|
||||
# check that the installed version has the same 32/64bit-ness as the one which is currently searching:
|
||||
if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "8")
|
||||
math(EXPR installedBits "8 * 8")
|
||||
set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)")
|
||||
set(PACKAGE_VERSION_UNSUITABLE TRUE)
|
||||
endif()
|
@ -0,0 +1,9 @@
|
||||
libdir=/usr/local/lib
|
||||
includedir=/usr/local/include
|
||||
|
||||
Name: gmock
|
||||
Description: GoogleMock (without main() function)
|
||||
Version: 1.9.0
|
||||
URL: https://github.com/google/googletest
|
||||
Libs: -L${libdir} -lgmock -pthread
|
||||
Cflags: -I${includedir} -DGTEST_HAS_PTHREAD=1 -pthread
|
@ -0,0 +1,9 @@
|
||||
libdir=/usr/local/lib
|
||||
includedir=/usr/local/include
|
||||
|
||||
Name: gmock_main
|
||||
Description: GoogleMock (with main() function)
|
||||
Version: 1.9.0
|
||||
URL: https://github.com/google/googletest
|
||||
Libs: -L${libdir} -lgmock_main -pthread
|
||||
Cflags: -I${includedir} -DGTEST_HAS_PTHREAD=1 -pthread
|
@ -0,0 +1,9 @@
|
||||
libdir=/usr/local/lib
|
||||
includedir=/usr/local/include
|
||||
|
||||
Name: gtest
|
||||
Description: GoogleTest (without main() function)
|
||||
Version: 1.9.0
|
||||
URL: https://github.com/google/googletest
|
||||
Libs: -L${libdir} -lgtest -pthread
|
||||
Cflags: -I${includedir} -DGTEST_HAS_PTHREAD=1 -pthread
|
@ -0,0 +1,10 @@
|
||||
libdir=/usr/local/lib
|
||||
includedir=/usr/local/include
|
||||
|
||||
Name: gtest_main
|
||||
Description: GoogleTest (with main() function)
|
||||
Version: 1.9.0
|
||||
URL: https://github.com/google/googletest
|
||||
Requires: gtest
|
||||
Libs: -L${libdir} -lgtest_main -pthread
|
||||
Cflags: -I${includedir} -DGTEST_HAS_PTHREAD=1 -pthread
|
File diff suppressed because one or more lines are too long
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue