| @@ -1,70 +1,73 @@ | |||
| ## define customized find fucntions, print customized error messages | |||
| function(find_required_package pkg_name) | |||
| find_package(${pkg_name}) | |||
| if (NOT ${pkg_name}_FOUND) | |||
| message(FATAL_ERROR "Required package ${pkg_name} not found, please install the package and try building MindSpore again.") | |||
| if(NOT ${pkg_name}_FOUND) | |||
| message(FATAL_ERROR "Required package ${pkg_name} not found, " | |||
| "please install the package and try building MindSpore again.") | |||
| endif() | |||
| endfunction() | |||
| function(find_required_program prog_name) | |||
| find_program(${prog_name}_EXE ${prog_name}) | |||
| if (NOT ${prog_name}_EXE) | |||
| message(FATAL_ERROR "Required program ${prog_name} not found, please install the package and try building MindSpore again.") | |||
| endif () | |||
| if(NOT ${prog_name}_EXE) | |||
| message(FATAL_ERROR "Required program ${prog_name} not found, " | |||
| "please install the package and try building MindSpore again.") | |||
| endif() | |||
| endfunction() | |||
| ## find python, quit if the found python is static | |||
| set(Python3_USE_STATIC_LIBS FALSE) | |||
| find_package(Python3 COMPONENTS Interpreter Development) | |||
| if (Python3_FOUND) | |||
| if(Python3_FOUND) | |||
| message("Python3 found, version: ${Python3_VERSION}") | |||
| message("Python3 library path: ${Python3_LIBRARY}") | |||
| message("Python3 interpreter: ${Python3_EXECUTABLE}") | |||
| elseif (Python3_LIBRARY AND Python3_EXECUTABLE AND | |||
| ${Python3_VERSION} VERSION_GREATER_EQUAL "3.7.0" AND ${Python3_VERSION} VERSION_LESS "3.8.0") | |||
| elseif(Python3_LIBRARY AND Python3_EXECUTABLE AND | |||
| ${Python3_VERSION} VERSION_GREATER_EQUAL "3.7.0" AND ${Python3_VERSION} VERSION_LESS "3.8.9") | |||
| message(WARNING "Maybe python3 environment is broken.") | |||
| message("Python3 library path: ${Python3_LIBRARY}") | |||
| message("Python3 interpreter: ${Python3_EXECUTABLE}") | |||
| else () | |||
| else() | |||
| message(FATAL_ERROR "Python3 not found, please install Python>=3.7.5, and set --enable-shared " | |||
| "if you are building Python locally") | |||
| endif () | |||
| endif() | |||
| ## packages used both on windows and linux | |||
| if (DEFINED ENV{MS_PATCH_PATH}) | |||
| if(DEFINED ENV{MS_PATCH_PATH}) | |||
| find_program(Patch_EXECUTABLE patch PATHS $ENV{MS_PATCH_PATH}) | |||
| set(Patch_FOUND ${Patch_EXECUTABLE}) | |||
| else () | |||
| else() | |||
| find_package(Patch) | |||
| endif () | |||
| if (NOT Patch_FOUND) | |||
| message(FATAL_ERROR "Patch not found, please set environment variable MS_PATCH_PATH to path where Patch is located, " | |||
| endif() | |||
| if(NOT Patch_FOUND) | |||
| message(FATAL_ERROR "Patch not found, " | |||
| "please set environment variable MS_PATCH_PATH to path where Patch is located, " | |||
| "usually found in GIT_PATH/usr/bin on Windows") | |||
| endif () | |||
| endif() | |||
| message(PATCH_EXECUTABLE = ${Patch_EXECUTABLE}) | |||
| find_required_package(Threads) | |||
| ## packages used on Linux | |||
| if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows") | |||
| if (ENABLE_MINDDATA) | |||
| if(NOT CMAKE_SYSTEM_NAME MATCHES "Windows") | |||
| if(ENABLE_MINDDATA) | |||
| find_required_program(tclsh) | |||
| endif () | |||
| endif() | |||
| if (MS_BUILD_GRPC) | |||
| if(MS_BUILD_GRPC) | |||
| find_required_package(OpenSSL) | |||
| endif () | |||
| endif() | |||
| ## packages used in GPU mode only | |||
| if (ENABLE_GPU) | |||
| if(ENABLE_GPU) | |||
| find_library(gmp_LIB gmp) | |||
| find_library(gmpxx_LIB gmpxx) | |||
| find_file(gmp_HEADER gmp.h) | |||
| if (NOT gmp_LIB OR NOT gmpxx_LIB OR NOT gmp_HEADER) | |||
| if(NOT gmp_LIB OR NOT gmpxx_LIB OR NOT gmp_HEADER) | |||
| message(FATAL_ERROR "Required package gmp not found, please install gmp and try building MindSpore again.") | |||
| endif () | |||
| endif() | |||
| find_required_program(automake) | |||
| find_required_program(autoconf) | |||
| find_required_program(libtoolize) | |||
| @@ -1,10 +1,28 @@ | |||
| if (ENABLE_GITEE) | |||
| set(REQ_URL "https://gitee.com/mirrors/pybind11/repository/archive/v2.4.3.tar.gz") | |||
| set(MD5 "b473a37987ce456ea8cc7aab3f9486f9") | |||
| set(PYTHON_VERSION ${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}) | |||
| if(ENABLE_GITEE) | |||
| if(PYTHON_VERSION MATCHES "3.8") | |||
| set(REQ_URL "https://gitee.com/mirrors/pybind11/repository/archive/v2.6.1.tar.gz") | |||
| set(MD5 "dcbb02cc2da9653ec91860bb0594c91d") | |||
| elseif(PYTHON_VERSION MATCHES "3.7") | |||
| set(REQ_URL "https://gitee.com/mirrors/pybind11/repository/archive/v2.4.3.tar.gz") | |||
| set(MD5 "b473a37987ce456ea8cc7aab3f9486f9") | |||
| else() | |||
| message("Could not find 'Python 3.8' or 'Python 3.7'") | |||
| return() | |||
| endif() | |||
| else() | |||
| set(REQ_URL "https://github.com/pybind/pybind11/archive/v2.4.3.tar.gz") | |||
| set(MD5 "62254c40f89925bb894be421fe4cdef2") | |||
| endif () | |||
| if(PYTHON_VERSION MATCHES "3.8") | |||
| set(REQ_URL "https://github.com/pybind/pybind11/archive/v2.6.1.tar.gz") | |||
| set(MD5 "32a7811f3db423df4ebfc731a28e5901") | |||
| elseif(PYTHON_VERSION MATCHES "3.7") | |||
| set(REQ_URL "https://github.com/pybind/pybind11/archive/v2.4.3.tar.gz") | |||
| set(MD5 "62254c40f89925bb894be421fe4cdef2") | |||
| else() | |||
| message("Could not find 'Python 3.8' or 'Python 3.7'") | |||
| return() | |||
| endif() | |||
| endif() | |||
| set(pybind11_CXXFLAGS "-D_FORTIFY_SOURCE=2 -O2") | |||
| set(pybind11_CFLAGS "-D_FORTIFY_SOURCE=2 -O2") | |||
| mindspore_add_pkg(pybind11 | |||
| @@ -1,21 +1,21 @@ | |||
| # find exec | |||
| find_package(Python3 3.7 COMPONENTS Interpreter) | |||
| if (NOT Python3_FOUND) | |||
| if(NOT Python3_FOUND) | |||
| message(FATAL_ERROR "No python3 found.") | |||
| endif () | |||
| endif() | |||
| set(PYTHON ${Python3_EXECUTABLE}) | |||
| set(PYTHON_VERSION ${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}) | |||
| if (NOT PYTHON_VERSION MATCHES "3.7") | |||
| message(FATAL_ERROR "FIND PYTHON VERSION ${PYTHON_VERSION} BUT CAN NOT MATCH PYTHON VERSION 3.7") | |||
| endif () | |||
| if(NOT (PYTHON_VERSION MATCHES "3.8" OR PYTHON_VERSION MATCHES "3.7")) | |||
| message(FATAL_ERROR "FIND PYTHON VERSION ${PYTHON_VERSION} BUT CAN NOT MATCH PYTHON VERSION 3.8 OR 3.7") | |||
| endif() | |||
| find_package(Git) | |||
| if (NOT GIT_FOUND) | |||
| if(NOT GIT_FOUND) | |||
| message("No git found.") | |||
| return () | |||
| endif () | |||
| return() | |||
| endif() | |||
| set(GIT ${GIT_EXECUTABLE}) | |||
| # set path | |||
| @@ -23,33 +23,39 @@ set(MS_ROOT_DIR ${CPACK_PACKAGE_DIRECTORY}/../../) | |||
| set(MS_PACK_ROOT_DIR ${MS_ROOT_DIR}/build/package) | |||
| # set package file name | |||
| if (CMAKE_SYSTEM_NAME MATCHES "Linux") | |||
| if (PYTHON_VERSION MATCHES "3.7") | |||
| if(CMAKE_SYSTEM_NAME MATCHES "Linux") | |||
| if(PYTHON_VERSION MATCHES "3.8") | |||
| set(PY_TAGS "cp38-cp38") | |||
| elseif(PYTHON_VERSION MATCHES "3.7") | |||
| set(PY_TAGS "cp37-cp37m") | |||
| else () | |||
| message("Could not find 'Python 3.7'") | |||
| else() | |||
| message("Could not find 'Python 3.8' or 'Python 3.7'") | |||
| return() | |||
| endif () | |||
| endif() | |||
| string(TOLOWER linux_${CMAKE_HOST_SYSTEM_PROCESSOR} PLATFORM_TAG) | |||
| elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin") | |||
| if (PYTHON_VERSION MATCHES "3.7") | |||
| elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin") | |||
| if(PYTHON_VERSION MATCHES "3.8") | |||
| set(PY_TAGS "py38-none") | |||
| elseif(PYTHON_VERSION MATCHES "3.7") | |||
| set(PY_TAGS "py37-none") | |||
| else () | |||
| message("Could not find 'Python 3.7'") | |||
| else() | |||
| message("Could not find 'Python 3.8' or 'Python 3.7'") | |||
| return() | |||
| endif () | |||
| endif() | |||
| set(PLATFORM_TAG "any") | |||
| elseif (CMAKE_SYSTEM_NAME MATCHES "Windows") | |||
| if (PYTHON_VERSION MATCHES "3.7") | |||
| elseif(CMAKE_SYSTEM_NAME MATCHES "Windows") | |||
| if(PYTHON_VERSION MATCHES "3.8") | |||
| set(PY_TAGS "cp38-cp38") | |||
| elseif(PYTHON_VERSION MATCHES "3.7") | |||
| set(PY_TAGS "cp37-cp37m") | |||
| else () | |||
| message("Could not find 'Python 3.7'") | |||
| else() | |||
| message("Could not find 'Python 3.8' or 'Python 3.7'") | |||
| return() | |||
| endif () | |||
| endif() | |||
| set(PLATFORM_TAG "win_amd64") | |||
| else () | |||
| else() | |||
| message(FATAL_ERROR "other platform: ${CMAKE_SYSTEM_NAME}") | |||
| endif () | |||
| endif() | |||
| # get git commit id | |||
| set(GIT_COMMIT_ID "") | |||
| @@ -72,13 +78,13 @@ execute_process( | |||
| # finally | |||
| set(PACKAGE_NAME ${CPACK_MS_PACKAGE_NAME}) | |||
| if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows") | |||
| if(NOT CMAKE_SYSTEM_NAME MATCHES "Windows") | |||
| string(REPLACE "-" "_" PACKAGE_NAME ${PACKAGE_NAME}) | |||
| execute_process( | |||
| COMMAND chmod -R 700 ${MS_PACK_ROOT_DIR}/mindspore/ | |||
| COMMAND chmod -R 700 ${MS_PACK_ROOT_DIR}/${PACKAGE_NAME}.egg-info/ | |||
| ) | |||
| endif () | |||
| endif() | |||
| file(GLOB WHL_FILE ${MS_PACK_ROOT_DIR}/dist/*.whl) | |||
| get_filename_component(ORIGIN_FILE_NAME ${WHL_FILE} NAME) | |||
| @@ -16,6 +16,7 @@ | |||
| """Parameter for cell.""" | |||
| from copy import copy | |||
| import numbers | |||
| import numpy as np | |||
| from .._c_expression import ParamInfo | |||
| from . import dtype as mstype | |||
| from .initializer import initializer | |||
| @@ -154,12 +155,17 @@ class Parameter(Tensor_): | |||
| self._cast_type = None | |||
| self._unique = False | |||
| self.is_in_parallel = _is_in_parallel_mode() | |||
| if isinstance(default_input, Tensor): | |||
| if isinstance(default_input, (Tensor_, Tensor)): | |||
| Tensor_.__init__(self, default_input.dtype, default_input.shape) | |||
| elif isinstance(default_input, int): | |||
| Tensor_.__init__(self, mstype.int64, ()) | |||
| elif isinstance(default_input, float): | |||
| Tensor_.__init__(self, mstype.float32, ()) | |||
| elif isinstance(default_input, np.ndarray): | |||
| Tensor_.__init__(self, default_input) | |||
| else: | |||
| raise TypeError(f"Parameter input must be [`Tensor`, `Number`]." | |||
| f"But with type {type(default_input)}.") | |||
| def __deepcopy__(self, memodict): | |||
| new_obj = Parameter(self) | |||
| @@ -395,7 +395,7 @@ def _clear_handler(logger): | |||
| logger.removeHandler(handler) | |||
| def _find_caller(stack_info=False): | |||
| def _find_caller(stack_info=False, stacklevel=1): | |||
| """ | |||
| Find the stack frame of the caller. | |||