diff --git a/.ci/docker/common/install_conda.sh b/.ci/docker/common/install_conda.sh index 99036a0bb6ea..76dd424e70e1 100755 --- a/.ci/docker/common/install_conda.sh +++ b/.ci/docker/common/install_conda.sh @@ -80,7 +80,7 @@ if [ -n "$ANACONDA_PYTHON_VERSION" ]; then # following builds that we know should use conda. Specifically, Ubuntu bionic # and focal cannot find conda mkl with stock cmake, so we need a cmake from conda if [ -n "${CONDA_CMAKE}" ]; then - conda_install cmake==3.31.2 + conda_install cmake fi # Magma package names are concatenation of CUDA major and minor ignoring revision diff --git a/.ci/pytorch/windows/condaenv.bat b/.ci/pytorch/windows/condaenv.bat index 2e43fafa995a..53ab89a730e7 100644 --- a/.ci/pytorch/windows/condaenv.bat +++ b/.ci/pytorch/windows/condaenv.bat @@ -9,12 +9,12 @@ FOR %%v IN (%DESIRED_PYTHON%) DO ( set PYTHON_VERSION_STR=%%v set PYTHON_VERSION_STR=!PYTHON_VERSION_STR:.=! conda remove -n py!PYTHON_VERSION_STR! --all -y || rmdir %CONDA_HOME%\envs\py!PYTHON_VERSION_STR! /s - if "%%v" == "3.9" call conda create -n py!PYTHON_VERSION_STR! -y numpy=2.0.1 boto3 cmake=3.31.2 ninja typing_extensions setuptools=72.1.0 python=%%v - if "%%v" == "3.10" call conda create -n py!PYTHON_VERSION_STR! -y -c=conda-forge numpy=2.0.1 boto3 cmake=3.31.2 ninja typing_extensions setuptools=72.1.0 python=%%v - if "%%v" == "3.11" call conda create -n py!PYTHON_VERSION_STR! -y -c=conda-forge numpy=2.0.1 boto3 cmake=3.31.2 ninja typing_extensions setuptools=72.1.0 python=%%v - if "%%v" == "3.12" call conda create -n py!PYTHON_VERSION_STR! -y -c=conda-forge numpy=2.0.1 boto3 cmake=3.31.2 ninja typing_extensions setuptools=72.1.0 python=%%v - if "%%v" == "3.13" call conda create -n py!PYTHON_VERSION_STR! -y -c=conda-forge numpy=2.1.2 boto3 cmake=3.31.2 ninja typing_extensions setuptools=72.1.0 python=%%v - if "%%v" == "3.13t" call conda create -n py!PYTHON_VERSION_STR! -y -c=conda-forge numpy=2.1.2 boto3 cmake=3.31.2 ninja typing_extensions setuptools=72.1.0 python-freethreading python=3.13 + if "%%v" == "3.9" call conda create -n py!PYTHON_VERSION_STR! -y numpy=2.0.1 boto3 cmake ninja typing_extensions setuptools=72.1.0 python=%%v + if "%%v" == "3.10" call conda create -n py!PYTHON_VERSION_STR! -y -c=conda-forge numpy=2.0.1 boto3 cmake ninja typing_extensions setuptools=72.1.0 python=%%v + if "%%v" == "3.11" call conda create -n py!PYTHON_VERSION_STR! -y -c=conda-forge numpy=2.0.1 boto3 cmake ninja typing_extensions setuptools=72.1.0 python=%%v + if "%%v" == "3.12" call conda create -n py!PYTHON_VERSION_STR! -y -c=conda-forge numpy=2.0.1 boto3 cmake ninja typing_extensions setuptools=72.1.0 python=%%v + if "%%v" == "3.13" call conda create -n py!PYTHON_VERSION_STR! -y -c=conda-forge numpy=2.1.2 boto3 cmake ninja typing_extensions setuptools=72.1.0 python=%%v + if "%%v" == "3.13t" call conda create -n py!PYTHON_VERSION_STR! -y -c=conda-forge numpy=2.1.2 boto3 cmake ninja typing_extensions setuptools=72.1.0 python-freethreading python=3.13 call conda run -n py!PYTHON_VERSION_STR! pip install pyyaml call conda run -n py!PYTHON_VERSION_STR! pip install mkl-include call conda run -n py!PYTHON_VERSION_STR! pip install mkl-static diff --git a/aten/src/ATen/native/quantized/cpu/qnnpack/CMakeLists.txt b/aten/src/ATen/native/quantized/cpu/qnnpack/CMakeLists.txt index 86897fe9f8d0..7ea66d9fe8bc 100644 --- a/aten/src/ATen/native/quantized/cpu/qnnpack/CMakeLists.txt +++ b/aten/src/ATen/native/quantized/cpu/qnnpack/CMakeLists.txt @@ -391,6 +391,12 @@ elseif(NOT TARGET fxdiv AND USE_SYSTEM_FXDIV) endif() target_link_libraries(pytorch_qnnpack PRIVATE fxdiv) +# -- [ CMake-4 compat mode +if(CMAKE_VERSION VERSION_GREATER_EQUAL "4.0.0" AND NOT (USE_SYSTEM_PSIMD OR USE_SYSTEM_FP16)) + message(WARNING "Ancient psimd/FP16 forces CMake compatibility") + set(CMAKE_POLICY_VERSION_MINIMUM 3.5) +endif() + # ---[ Configure psimd if(NOT TARGET psimd AND NOT USE_SYSTEM_PSIMD) add_subdirectory( @@ -423,6 +429,11 @@ elseif(NOT TARGET fp16 AND USE_SYSTEM_FP16) endif() target_link_libraries(pytorch_qnnpack PRIVATE fp16) +# -- [ Undo cmake-4 compat mode +if(CMAKE_VERSION VERSION_GREATER_EQUAL "4.0.0") + unset(CMAKE_POLICY_VERSION_MINIMUM) +endif() + install(TARGETS pytorch_qnnpack LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index 84d6862a167c..bd8f7792214e 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -784,7 +784,14 @@ if(USE_NUMA) endif() if(USE_ITT) - find_package(ITT) + if(CMAKE_VERSION VERSION_GREATER_EQUAL "4.0.0") + message(WARNING "ITT is only cmake-2.8 compatible") + set(CMAKE_POLICY_VERSION_MINIMUM 3.5) + find_package(ITT) + unset(CMAKE_POLICY_VERSION_MINIMUM) + else() + find_package(ITT) + endif() if(ITT_FOUND) include_directories(SYSTEM ${ITT_INCLUDE_DIR}) list(APPEND Caffe2_DEPENDENCY_LIBS ${ITT_LIBRARIES}) @@ -1150,7 +1157,14 @@ if(USE_DISTRIBUTED AND USE_TENSORPIPE) # Tensorpipe uses cuda_add_library torch_update_find_cuda_flags() + if(CMAKE_VERSION VERSION_GREATER_EQUAL "4.0.0") + message(WARNING "Archived TensorPipe forces CMake compatibility mode") + set(CMAKE_POLICY_VERSION_MINIMUM 3.5) + endif() add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/tensorpipe) + if(CMAKE_VERSION VERSION_GREATER_EQUAL "4.0.0") + unset(CMAKE_POLICY_VERSION_MINIMUM) + endif() list(APPEND Caffe2_DEPENDENCY_LIBS tensorpipe) list(APPEND Caffe2_DEPENDENCY_LIBS nlohmann) @@ -1192,7 +1206,15 @@ if(USE_GLOO) set(NCCL_EXTERNAL ON) endif() set(GLOO_USE_CUDA_TOOLKIT ON CACHE BOOL "" FORCE) - add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../third_party/gloo) + if(CMAKE_VERSION VERSION_GREATER_EQUAL "4.0.0") + # Remove me when https://github.com/facebookincubator/gloo/pull/424 is landed + message(WARNING "Downgrading cmake-policy-version for gloo build") + set(CMAKE_POLICY_VERSION_MINIMUM 3.5) + add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../third_party/gloo) + unset(CMAKE_POLICY_VERSION_MINIMUM) + else() + add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../third_party/gloo) + endif() # Here is a little bit hacky. We have to put PROJECT_BINARY_DIR in front # of PROJECT_SOURCE_DIR with/without conda system. The reason is that # gloo generates a new config.h in the binary diretory. diff --git a/cmake/External/nnpack.cmake b/cmake/External/nnpack.cmake index 7890e1f8a8b7..8a4a310d6292 100644 --- a/cmake/External/nnpack.cmake +++ b/cmake/External/nnpack.cmake @@ -62,9 +62,16 @@ if(ANDROID OR IOS OR ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAM set(NNPACK_LIBRARY_TYPE "static" CACHE STRING "") set(PTHREADPOOL_LIBRARY_TYPE "static" CACHE STRING "") set(CPUINFO_LIBRARY_TYPE "static" CACHE STRING "") + if(CMAKE_VERSION VERSION_GREATER_EQUAL "4.0.0") + message(WARNING "Ancient nnpack forces CMake compatibility") + set(CMAKE_POLICY_VERSION_MINIMUM 3.5) + endif() add_subdirectory( "${NNPACK_SOURCE_DIR}" "${CONFU_DEPENDENCIES_BINARY_DIR}/NNPACK") + if(CMAKE_VERSION VERSION_GREATER_EQUAL "4.0.0") + unset(CMAKE_POLICY_VERSION_MINIMUM) + endif() # We build static versions of nnpack and pthreadpool but link # them into a shared library for Caffe2, so they need PIC. set_property(TARGET nnpack PROPERTY POSITION_INDEPENDENT_CODE ON) diff --git a/cmake/ProtoBuf.cmake b/cmake/ProtoBuf.cmake index 66acb1269efe..4c436dcd6451 100644 --- a/cmake/ProtoBuf.cmake +++ b/cmake/ProtoBuf.cmake @@ -52,7 +52,14 @@ macro(custom_protobuf_find) endif(MSVC_Z7_OVERRIDE) endif(MSVC) - add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../third_party/protobuf/cmake) + if(CMAKE_VERSION VERSION_GREATER_EQUAL "4.0.0") + message(WARNING "Ancient protobuf forces CMake compatibility") + set(CMAKE_POLICY_VERSION_MINIMUM 3.5) + add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../third_party/protobuf/cmake) + unset(CMAKE_POLICY_VERSION_MINIMUM) + else() + add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../third_party/protobuf/cmake) + endif() set(CMAKE_POSITION_INDEPENDENT_CODE ${__caffe2_CMAKE_POSITION_INDEPENDENT_CODE}) diff --git a/requirements.txt b/requirements.txt index c0156047bfb3..01f358ec9e9e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ # Python dependencies required for development astunparse -cmake==3.31.6 # Temp pin until we support 4.0.0? +cmake expecttest>=0.3.0 filelock fsspec diff --git a/test/custom_backend/CMakeLists.txt b/test/custom_backend/CMakeLists.txt index 835f17850a84..9ab888c5f5b1 100644 --- a/test/custom_backend/CMakeLists.txt +++ b/test/custom_backend/CMakeLists.txt @@ -1,5 +1,5 @@ # Basic CMake setup -cmake_minimum_required(VERSION 3.1 FATAL_ERROR) +cmake_minimum_required(VERSION 3.15 FATAL_ERROR) project(custom_backend) if(USE_ROCM) diff --git a/test/custom_operator/CMakeLists.txt b/test/custom_operator/CMakeLists.txt index 6d1a4988fe38..cc5cd7337f22 100644 --- a/test/custom_operator/CMakeLists.txt +++ b/test/custom_operator/CMakeLists.txt @@ -1,5 +1,5 @@ # Basic CMake setup -cmake_minimum_required(VERSION 3.1 FATAL_ERROR) +cmake_minimum_required(VERSION 3.15 FATAL_ERROR) project(custom_ops) if(USE_ROCM) diff --git a/test/edge/CMakeLists.txt b/test/edge/CMakeLists.txt index 72c01a2d3649..9eef3f7a2f22 100644 --- a/test/edge/CMakeLists.txt +++ b/test/edge/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.15) set(TORCH_ROOT ${CMAKE_CURRENT_LIST_DIR}/../..) set(TEST_ROOT ${TORCH_ROOT}/test/edge) diff --git a/test/jit_hooks/CMakeLists.txt b/test/jit_hooks/CMakeLists.txt index 91d5a2bf4e01..ba32390b0b36 100644 --- a/test/jit_hooks/CMakeLists.txt +++ b/test/jit_hooks/CMakeLists.txt @@ -1,5 +1,5 @@ # Basic CMake setup -cmake_minimum_required(VERSION 3.1 FATAL_ERROR) +cmake_minimum_required(VERSION 3.15 FATAL_ERROR) project(jit_hooks) if(USE_ROCM) diff --git a/test/mobile/custom_build/CMakeLists.txt b/test/mobile/custom_build/CMakeLists.txt index 426371f4d296..52e713895ff8 100644 --- a/test/mobile/custom_build/CMakeLists.txt +++ b/test/mobile/custom_build/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.15) project(custom_build_project) diff --git a/test/mobile/lightweight_dispatch/CMakeLists.txt b/test/mobile/lightweight_dispatch/CMakeLists.txt index 5ab3232f6a44..06a836848da0 100644 --- a/test/mobile/lightweight_dispatch/CMakeLists.txt +++ b/test/mobile/lightweight_dispatch/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.15) set(TORCH_ROOT ${CMAKE_CURRENT_LIST_DIR}/../../..) set(TEST_ROOT ${TORCH_ROOT}/test/mobile/lightweight_dispatch)