optimizing python package build and release

This commit is contained in:
sunsuodong 2022-05-07 09:35:52 -07:00
parent c29d6bb764
commit 6feb35d50d
5 changed files with 31 additions and 21 deletions

View File

@ -774,7 +774,7 @@ if(NOT APPLE AND NOT ENABLE_CLOUD_AND_LITE)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/file_list.cmake)
include(${TOP_DIR}/cmake/package_lite.cmake)
if(PLATFORM_X86_64)
if(PLATFORM_X86_64 OR MACHINE_LINUX_ARM64)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/python)
endif()
endif()

View File

@ -241,9 +241,13 @@ build_lite_aarch64_jni_and_jar() {
}
build_python_wheel_package() {
local python_version=`python3 -V 2>&1 | awk '{print $2}' | awk -F '.' '{print $1}'`
local python_version=`python -V 2>&1 | awk '{print $2}' | awk -F '.' '{print $1}'`
if [[ "${python_version}" == "3" ]]; then
cd ${BASEPATH}/mindspore/lite/build/
local lite_wrapper_so=`ls python/*.so`
if [ ! -f "${lite_wrapper_so}" ]; then
return 0
fi
mkdir -pv package/mindspore_lite/lib/
cp ../python/api/* package/mindspore_lite/
cp src/*.so package/mindspore_lite/lib/
@ -264,7 +268,7 @@ build_python_wheel_package() {
export TOP_DIR=${BASEPATH}
cd package
python setup.py bdist_wheel
local minor_version=`python3 -V 2>&1 | awk '{print $2}' | awk -F '.' '{print $2}'`
local minor_version=`python -V 2>&1 | awk '{print $2}' | awk -F '.' '{print $2}'`
local py_tags="cp${python_version}${minor_version}-cp${python_version}${minor_version}"
if [[ "${minor_version}" == "7" ]]; then
py_tags="cp37-cp37m"
@ -448,6 +452,7 @@ build_lite() {
echo -e "\e[31mIf you want to compile the JAR package, please set $JAVA_HOME. For example: export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64 \e[0m"
fi
elif [[ "${local_lite_platform}" == "arm64" ]] && [[ "${machine}" == "aarch64" ]]; then
build_python_wheel_package "aarch64"
if [ "${JAVA_HOME}" ]; then
echo -e "\e[31mJAVA_HOME=$JAVA_HOME \e[0m"
build_lite_aarch64_jni_and_jar "${CMAKE_ARGS}"

View File

@ -10,22 +10,26 @@ find_package(Python3 COMPONENTS Interpreter Development)
if(Python3_FOUND)
find_package(Python3 COMPONENTS NumPy Development)
include_directories(${Python3_INCLUDE_DIRS})
include_directories(${Python3_NumPy_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../core/)
if(Python3_NumPy_FOUND)
include_directories(${Python3_INCLUDE_DIRS})
include_directories(${Python3_NumPy_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../core/)
if(NOT ENABLE_CLOUD_AND_LITE)
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/utils.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/external_libs/pybind11.cmake)
endif()
if(NOT ENABLE_CLOUD_AND_LITE)
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/utils.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/external_libs/pybind11.cmake)
endif()
file(GLOB_RECURSE PY_SRC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc")
pybind11_add_module(_c_lite_wrapper NO_EXTRAS ${PY_SRC_LIST})
file(GLOB_RECURSE PY_SRC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc")
pybind11_add_module(_c_lite_wrapper NO_EXTRAS ${PY_SRC_LIST})
target_link_libraries(_c_lite_wrapper PRIVATE -Wl,--whole-archive mindspore-lite_static -Wl,--no-whole-archive)
if(MSLITE_ENABLE_CONVERTER OR MSLITE_ENABLE_RUNTIME_GLOG)
target_link_libraries(_c_lite_wrapper PRIVATE mindspore::glog)
target_link_libraries(_c_lite_wrapper PRIVATE -Wl,--whole-archive mindspore-lite_static -Wl,--no-whole-archive)
if(MSLITE_ENABLE_CONVERTER OR MSLITE_ENABLE_RUNTIME_GLOG)
target_link_libraries(_c_lite_wrapper PRIVATE mindspore::glog)
endif()
else()
message(WARNING "NumPy not found, so Python API will not be compiled.")
endif()
else()
message(WARNING "Python3 not found, so Python API will not be compiled.")

View File

@ -348,6 +348,7 @@ class Tensor:
if numpy_obj.nbytes != self.get_data_size():
raise RuntimeError(
f"data size not equal! Numpy size: {numpy_obj.nbytes}, Tensor size: {self.get_data_size()}")
numpy_obj.flatten()
self._tensor.set_data_from_numpy(numpy_obj)
self._numpy_obj = numpy_obj # keep reference count of numpy objects

View File

@ -52,11 +52,11 @@ function linux_release_package()
mkdir -p ${output_path}/release/linux/x86_64/server/
mkdir -p ${output_path}/release/linux/aarch64/server/
cp ${input_path}/centos_x86/avx/*.tar.gz* ${output_path}/release/linux/x86_64/
cp ${input_path}/linux_aarch64/*.tar.gz* ${output_path}/release/linux/aarch64/
cp ${input_path}/centos_x86/ascend/*.tar.gz* ${output_path}/release/linux/x86_64/ascend/
cp ${input_path}/linux_aarch64/ascend/*.tar.gz* ${output_path}/release/linux/aarch64/ascend/
cp ${input_path}/centos_x86/tensorrt/*.tar.gz* ${output_path}/release/linux/x86_64/tensorrt/
cp ${input_path}/centos_x86/avx/mindspore-lite-* ${output_path}/release/linux/x86_64/
cp ${input_path}/linux_aarch64/mindspore-lite-* ${output_path}/release/linux/aarch64/
cp ${input_path}/centos_x86/ascend/mindspore-lite-* ${output_path}/release/linux/x86_64/ascend/
cp ${input_path}/linux_aarch64/ascend/mindspore-lite-* ${output_path}/release/linux/aarch64/ascend/
cp ${input_path}/centos_x86/tensorrt/mindspore-lite-* ${output_path}/release/linux/x86_64/tensorrt/
cp -r ${input_path}/centos_x86/server/* ${output_path}/release/linux/x86_64/server/
cp -r ${input_path}/linux_aarch64/server/* ${output_path}/release/linux/aarch64/server/