From 44ee251fdebc237b2e58e1c57b713f9048593f22 Mon Sep 17 00:00:00 2001 From: Zhou Wei <52485244+zhouwei25@users.noreply.github.com> Date: Tue, 23 Feb 2021 10:33:03 +0800 Subject: [PATCH] fix UNIX cmake problem (#31113) --- cmake/generic.cmake | 6 ++---- paddle/scripts/paddle_build.bat | 4 ++-- python/paddle/fluid/tests/CMakeLists.txt | 2 +- python/paddle/fluid/tests/custom_op/CMakeLists.txt | 2 +- .../paddle/fluid/tests/custom_op/test_dispatch.py | 14 ++++++-------- .../tests/custom_op/test_simple_custom_op_jit.py | 14 ++++++-------- .../paddle/utils/cpp_extension/extension_utils.py | 1 - 7 files changed, 18 insertions(+), 25 deletions(-) diff --git a/cmake/generic.cmake b/cmake/generic.cmake index 1e9fc878da8..cba338c2c49 100644 --- a/cmake/generic.cmake +++ b/cmake/generic.cmake @@ -794,16 +794,14 @@ function(py_test TARGET_NAME) if(WITH_COVERAGE AND NOT (WITH_INCREMENTAL_COVERAGE AND "$ENV{PADDLE_GIT_DIFF_PY_FILE}" STREQUAL "")) add_test(NAME ${TARGET_NAME} COMMAND ${CMAKE_COMMAND} -E env FLAGS_init_allocated_mem=true FLAGS_cudnn_deterministic=true - FLAGS_cpu_deterministic=true - PYTHONPATH=${PADDLE_BINARY_DIR}/python ${py_test_ENVS} + FLAGS_cpu_deterministic=true ${py_test_ENVS} COVERAGE_FILE=${PADDLE_BINARY_DIR}/python-coverage.data ${PYTHON_EXECUTABLE} -m coverage run --branch -p ${py_test_SRCS} ${py_test_ARGS} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) else() add_test(NAME ${TARGET_NAME} COMMAND ${CMAKE_COMMAND} -E env FLAGS_init_allocated_mem=true FLAGS_cudnn_deterministic=true - FLAGS_cpu_deterministic=true - PYTHONPATH=${PADDLE_BINARY_DIR}/python ${py_test_ENVS} + FLAGS_cpu_deterministic=true ${py_test_ENVS} ${PYTHON_EXECUTABLE} -u ${py_test_SRCS} ${py_test_ARGS} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) endif() diff --git a/paddle/scripts/paddle_build.bat b/paddle/scripts/paddle_build.bat index 8050e881a48..d516649e44e 100644 --- a/paddle/scripts/paddle_build.bat +++ b/paddle/scripts/paddle_build.bat @@ -114,8 +114,8 @@ rem ------pre install python requirement---------- where python where pip pip install wheel --user -pip install --force-reinstall -r %work_dir%\python\requirements.txt --user -pip install --force-reinstall -r %work_dir%\python\unittest_py\requirements.txt --user +pip install -r %work_dir%\python\unittest_py\requirements.txt --user +pip install -r %work_dir%\python\requirements.txt --user if %ERRORLEVEL% NEQ 0 ( echo pip install requirements.txt failed! exit /b 7 diff --git a/python/paddle/fluid/tests/CMakeLists.txt b/python/paddle/fluid/tests/CMakeLists.txt index 60be92b892f..4b6fb6de0d0 100644 --- a/python/paddle/fluid/tests/CMakeLists.txt +++ b/python/paddle/fluid/tests/CMakeLists.txt @@ -10,7 +10,7 @@ add_subdirectory(unittests) add_subdirectory(book) # TODO: support New Custom OP on Mac -if(Linux) +if(LINUX) add_subdirectory(custom_op) endif() diff --git a/python/paddle/fluid/tests/custom_op/CMakeLists.txt b/python/paddle/fluid/tests/custom_op/CMakeLists.txt index 0daf662f551..d7acab4d033 100644 --- a/python/paddle/fluid/tests/custom_op/CMakeLists.txt +++ b/python/paddle/fluid/tests/custom_op/CMakeLists.txt @@ -13,7 +13,7 @@ py_test(test_sysconfig SRCS test_sysconfig.py) py_test(test_dispatch SRCS test_dispatch.py) set_tests_properties(test_dispatch PROPERTIES TIMEOUT 180) -if(NOT Linux) +if(NOT LINUX) return() endif() diff --git a/python/paddle/fluid/tests/custom_op/test_dispatch.py b/python/paddle/fluid/tests/custom_op/test_dispatch.py index aaca7333561..484eb760beb 100644 --- a/python/paddle/fluid/tests/custom_op/test_dispatch.py +++ b/python/paddle/fluid/tests/custom_op/test_dispatch.py @@ -20,20 +20,18 @@ from paddle.utils.cpp_extension import load, get_build_directory from utils import paddle_includes, extra_compile_args from paddle.utils.cpp_extension.extension_utils import run_cmd -# Because the shared lib already exists in the cache dir, -# it will not be compiled again unless the cache dir is cleared. +# Because Windows don't use docker, the shared lib already exists in the +# cache dir, it will not be compiled again unless the shared lib is removed. if os.name == 'nt': - cmd = 'rmdir {} /s/q'.format(get_build_directory()) -else: - cmd = 'rm -rf {}'.format(get_build_directory()) - -run_cmd(cmd, True) + cmd = 'del {}\\dispatch_op.pyd'.format(get_build_directory()) + run_cmd(cmd, True) dispatch_op = load( name='dispatch_op', sources=['dispatch_test_op.cc'], extra_include_paths=paddle_includes, # add for Coverage CI - extra_cflags=extra_compile_args) # add for Coverage CI + extra_cflags=extra_compile_args, # add for Coverage CI + verbose=True) class TestJitDispatch(unittest.TestCase): diff --git a/python/paddle/fluid/tests/custom_op/test_simple_custom_op_jit.py b/python/paddle/fluid/tests/custom_op/test_simple_custom_op_jit.py index 2832e8070d1..f4d3c4f6597 100644 --- a/python/paddle/fluid/tests/custom_op/test_simple_custom_op_jit.py +++ b/python/paddle/fluid/tests/custom_op/test_simple_custom_op_jit.py @@ -22,21 +22,19 @@ from paddle.utils.cpp_extension.extension_utils import run_cmd from utils import paddle_includes, extra_compile_args from test_simple_custom_op_setup import relu2_dynamic, relu2_static -# Because the shared lib already exists in the cache dir, -# it will not be compiled again unless the cache dir is cleared. +# Because Windows don't use docker, the shared lib already exists in the +# cache dir, it will not be compiled again unless the shared lib is removed. if os.name == 'nt': - cmd = 'rmdir {} /s/q'.format(get_build_directory()) -else: - cmd = 'rm -rf {}'.format(get_build_directory()) - -run_cmd(cmd, True) + cmd = 'del {}\\simple_jit_relu2.pyd'.format(get_build_directory()) + run_cmd(cmd, True) # Compile and load custom op Just-In-Time. custom_module = load( name='simple_jit_relu2', sources=['relu_op_simple.cc', 'relu_op_simple.cu', 'relu_op3_simple.cc'], extra_include_paths=paddle_includes, # add for Coverage CI - extra_cflags=extra_compile_args) # add for Coverage CI + extra_cflags=extra_compile_args, # add for Coverage CI + verbose=True) class TestJITLoad(unittest.TestCase): diff --git a/python/paddle/utils/cpp_extension/extension_utils.py b/python/paddle/utils/cpp_extension/extension_utils.py index f4a801fe3ec..e53df3f083d 100644 --- a/python/paddle/utils/cpp_extension/extension_utils.py +++ b/python/paddle/utils/cpp_extension/extension_utils.py @@ -323,7 +323,6 @@ def find_cuda_home(): if six.PY3: nvcc_path = nvcc_path.decode() nvcc_path = nvcc_path.rstrip('\r\n') - log_v(nvcc_path) # for example: /usr/local/cuda/bin/nvcc cuda_home = os.path.dirname(os.path.dirname(nvcc_path)) except: -- GitLab