未验证 提交 f7514772 编写于 作者: R risemeup1 提交者: GitHub

Support ninja (#48932)

* move inplace_apis_indygraph_only from paddle.flud.dygraph.inplace_utils to paddle.utils

* modify conflict

* modify conflict

* modify conflict

* modify conflict

* modify conflict

* modify conflict

* modify conflict

* modify static-check ci error

* fix conflict

* modify failed tests

* fix conflict

* fix conflict

* fix pool2d examples

* modify conflict

* fix failed tests

* fix conflict

* fix failed tests

* modfiy problem of deleting pool2d

* support Ninja in setup.py

* support different cmake_generators

* modify after reviewed

* delete unused denotes
上级 e6cabea1
...@@ -557,12 +557,21 @@ def options_process(args, build_options): ...@@ -557,12 +557,21 @@ def options_process(args, build_options):
args.append("-D{}={}".format(key, value)) args.append("-D{}={}".format(key, value))
def get_cmake_generator():
if os.getenv("CMAKE_GENERATOR"):
cmake_generator = os.getenv("CMAKE_GENERATOR")
else:
cmake_generator = "Unix Makefiles"
return cmake_generator
def cmake_run(args, build_path): def cmake_run(args, build_path):
with cd(build_path): with cd(build_path):
cmake_args = [] cmake_args = []
cmake_args.append(CMAKE) cmake_args.append(CMAKE)
cmake_args.append('-DWITH_SETUP_INSTALL=ON')
cmake_args += args cmake_args += args
cmake_args.append('-DWITH_SETUP_INSTALL=ON')
cmake_args.append(TOP_DIR) cmake_args.append(TOP_DIR)
print("cmake_args:", cmake_args) print("cmake_args:", cmake_args)
subprocess.check_call(cmake_args) subprocess.check_call(cmake_args)
...@@ -573,7 +582,6 @@ def build_run(args, build_path, envrion_var): ...@@ -573,7 +582,6 @@ def build_run(args, build_path, envrion_var):
build_args = [] build_args = []
build_args.append(CMAKE) build_args.append(CMAKE)
build_args += args build_args += args
# cmake_args.append(TOP_DIR)
print(" ".join(build_args)) print(" ".join(build_args))
try: try:
subprocess.check_call(build_args, cwd=build_path, env=envrion_var) subprocess.check_call(build_args, cwd=build_path, env=envrion_var)
...@@ -581,6 +589,23 @@ def build_run(args, build_path, envrion_var): ...@@ -581,6 +589,23 @@ def build_run(args, build_path, envrion_var):
sys.exit(1) sys.exit(1)
def run_cmake_build(build_path):
build_args = ["--build", ".", "--target", "install", "--config", 'Release']
max_jobs = os.getenv("MAX_JOBS")
if max_jobs is not None:
max_jobs = max_jobs or str(multiprocessing.cpu_count())
build_args += ["--"]
if IS_WINDOWS:
build_args += ["/p:CL_MPCount={}".format(max_jobs)]
else:
build_args += ["-j", max_jobs]
else:
build_args += ["-j", str(multiprocessing.cpu_count())]
environ_var = os.environ.copy()
build_run(build_args, build_path, environ_var)
def build_steps(): def build_steps():
print('------- Building start ------') print('------- Building start ------')
build_dir = os.getenv("BUILD_DIR") build_dir = os.getenv("BUILD_DIR")
...@@ -596,7 +621,20 @@ def build_steps(): ...@@ -596,7 +621,20 @@ def build_steps():
# if rerun_cmake is True,remove CMakeCache.txt and rerun camke # if rerun_cmake is True,remove CMakeCache.txt and rerun camke
if os.path.isfile(cmake_cache_file_path) and rerun_cmake is True: if os.path.isfile(cmake_cache_file_path) and rerun_cmake is True:
os.remove(cmake_cache_file_path) os.remove(cmake_cache_file_path)
if not os.path.exists(cmake_cache_file_path):
CMAKE_GENERATOR = get_cmake_generator()
if CMAKE_GENERATOR == "Ninja":
build_ninja_file_path = os.path.join(build_path, "build.ninja")
# if os.path.exists(cmake_cache_file_path) and not (USE_NINJA and not os.path.exists(build_ninja_file_path)):
if os.path.exists(cmake_cache_file_path) and os.path.exists(
build_ninja_file_path
):
print("Do not need rerun camke,everything is ready,run build now")
run_cmake_build(build_path)
return
args = []
env_var = os.environ.copy() # get env variables env_var = os.environ.copy() # get env variables
paddle_build_options = {} paddle_build_options = {}
other_options = {} other_options = {}
...@@ -624,8 +662,8 @@ def build_steps(): ...@@ -624,8 +662,8 @@ def build_steps():
"NEW_RELEASE_JIT", "NEW_RELEASE_JIT",
"XPU_SDK_ROOT", "XPU_SDK_ROOT",
"MSVC_STATIC_CRT", "MSVC_STATIC_CRT",
"Ninja",
"NEW_RELEASE_ALL", "NEW_RELEASE_ALL",
"CMAKE_GENERATOR",
) )
} }
) )
...@@ -634,7 +672,6 @@ def build_steps(): ...@@ -634,7 +672,6 @@ def build_steps():
if option_key.startswith(("CMAKE_", "WITH_")): if option_key.startswith(("CMAKE_", "WITH_")):
paddle_build_options[option_key] = option_value paddle_build_options[option_key] = option_value
if option_key in other_options: if option_key in other_options:
print("type:", type(other_options[option_key]))
if ( if (
option_key == 'PYTHON_EXECUTABLE' option_key == 'PYTHON_EXECUTABLE'
or option_key == 'PYTHON_LIBRARY' or option_key == 'PYTHON_LIBRARY'
...@@ -649,7 +686,6 @@ def build_steps(): ...@@ -649,7 +686,6 @@ def build_steps():
key = other_options[option_key] key = other_options[option_key]
if key not in paddle_build_options: if key not in paddle_build_options:
paddle_build_options[key] = option_value paddle_build_options[key] = option_value
args = []
options_process(args, paddle_build_options) options_process(args, paddle_build_options)
print("args:", args) print("args:", args)
cmake_run(args, build_path) cmake_run(args, build_path)
...@@ -659,20 +695,7 @@ def build_steps(): ...@@ -659,20 +695,7 @@ def build_steps():
"You have finished running cmake, the program exited,run 'ccmake build' to adjust build options and 'python setup.py install to build'" "You have finished running cmake, the program exited,run 'ccmake build' to adjust build options and 'python setup.py install to build'"
) )
sys.exit() sys.exit()
build_args = ["--build", ".", "--target", "install", "--config", 'Release'] run_cmake_build(build_path)
max_jobs = os.getenv("MAX_JOBS")
if max_jobs is not None:
max_jobs = max_jobs or str(multiprocessing.cpu_count())
build_args += ["--"]
if IS_WINDOWS:
build_args += ["/p:CL_MPCount={}".format(max_jobs)]
else:
build_args += ["-j", max_jobs]
else:
build_args += ["-j", str(multiprocessing.cpu_count())]
environ_var = os.environ.copy()
build_run(build_args, build_path, environ_var)
def get_setup_requires(): def get_setup_requires():
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册