mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Simplify CMake code (#127683)
Due to the recent adoption of find(python), it is possible to further simplify some CMake code. Pull Request resolved: https://github.com/pytorch/pytorch/pull/127683 Approved by: https://github.com/ezyang
This commit is contained in:
@ -386,6 +386,7 @@ if(UNIX AND NOT APPLE)
|
|||||||
endif(UNIX AND NOT APPLE)
|
endif(UNIX AND NOT APPLE)
|
||||||
|
|
||||||
if(UNIX)
|
if(UNIX)
|
||||||
|
include(CheckFunctionExists)
|
||||||
set(CMAKE_EXTRA_INCLUDE_FILES "sys/mman.h")
|
set(CMAKE_EXTRA_INCLUDE_FILES "sys/mman.h")
|
||||||
CHECK_FUNCTION_EXISTS(mmap HAVE_MMAP)
|
CHECK_FUNCTION_EXISTS(mmap HAVE_MMAP)
|
||||||
if(HAVE_MMAP)
|
if(HAVE_MMAP)
|
||||||
|
@ -346,7 +346,7 @@ add_custom_command(
|
|||||||
OUTPUT
|
OUTPUT
|
||||||
${TORCH_GENERATED_CODE}
|
${TORCH_GENERATED_CODE}
|
||||||
COMMAND
|
COMMAND
|
||||||
"${Python_EXECUTABLE}" tools/setup_helpers/generate_code.py
|
Python::Interpreter tools/setup_helpers/generate_code.py
|
||||||
--native-functions-path "aten/src/ATen/native/native_functions.yaml"
|
--native-functions-path "aten/src/ATen/native/native_functions.yaml"
|
||||||
--tags-path "aten/src/ATen/native/tags.yaml"
|
--tags-path "aten/src/ATen/native/tags.yaml"
|
||||||
$<$<BOOL:${INTERN_DISABLE_AUTOGRAD}>:--disable-autograd>
|
$<$<BOOL:${INTERN_DISABLE_AUTOGRAD}>:--disable-autograd>
|
||||||
@ -1094,7 +1094,7 @@ if(BUILD_LITE_INTERPRETER AND SELECTED_OP_LIST)
|
|||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${CMAKE_BINARY_DIR}/aten/src/ATen/selected_mobile_ops.h
|
OUTPUT ${CMAKE_BINARY_DIR}/aten/src/ATen/selected_mobile_ops.h
|
||||||
COMMAND
|
COMMAND
|
||||||
"${Python_EXECUTABLE}"
|
Python::Interpreter
|
||||||
-m tools.code_analyzer.gen_oplist
|
-m tools.code_analyzer.gen_oplist
|
||||||
--model_file_list_path "${SELECTED_OP_LIST}"
|
--model_file_list_path "${SELECTED_OP_LIST}"
|
||||||
--output_dir "${CMAKE_BINARY_DIR}/aten/src/ATen"
|
--output_dir "${CMAKE_BINARY_DIR}/aten/src/ATen"
|
||||||
@ -1109,7 +1109,7 @@ if(BUILD_LITE_INTERPRETER AND SELECTED_OP_LIST)
|
|||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${CMAKE_BINARY_DIR}/aten/src/ATen/selected_mobile_ops.h
|
OUTPUT ${CMAKE_BINARY_DIR}/aten/src/ATen/selected_mobile_ops.h
|
||||||
COMMAND
|
COMMAND
|
||||||
"${Python_EXECUTABLE}"
|
Python::Interpreter
|
||||||
-m tools.lite_interpreter.gen_selected_mobile_ops_header
|
-m tools.lite_interpreter.gen_selected_mobile_ops_header
|
||||||
--yaml_file_path "${SELECTED_OP_LIST}"
|
--yaml_file_path "${SELECTED_OP_LIST}"
|
||||||
--output_file_path "${CMAKE_BINARY_DIR}/aten/src/ATen"
|
--output_file_path "${CMAKE_BINARY_DIR}/aten/src/ATen"
|
||||||
@ -1887,50 +1887,10 @@ endif()
|
|||||||
# only rerun when needed.
|
# only rerun when needed.
|
||||||
|
|
||||||
if(BUILD_PYTHON)
|
if(BUILD_PYTHON)
|
||||||
# Python site-packages
|
|
||||||
# Get canonical directory for python site packages (relative to install
|
|
||||||
# location). It varies from system to system.
|
|
||||||
# We should pin the path separator to the forward slash on Windows.
|
|
||||||
# More details can be seen at
|
|
||||||
# https://github.com/pytorch/pytorch/tree/main/tools/build_pytorch_libs.bat#note-backslash-munging-on-windows
|
|
||||||
pycmd(PYTHON_SITE_PACKAGES "
|
|
||||||
import os
|
|
||||||
import sysconfig
|
|
||||||
relative_site_packages = sysconfig.get_path('purelib').replace(sysconfig.get_path('data'), '').lstrip(os.path.sep)
|
|
||||||
print(relative_site_packages)
|
|
||||||
")
|
|
||||||
file(TO_CMAKE_PATH ${PYTHON_SITE_PACKAGES} PYTHON_SITE_PACKAGES)
|
|
||||||
set(PYTHON_SITE_PACKAGES ${PYTHON_SITE_PACKAGES} PARENT_SCOPE) # for Summary
|
|
||||||
# ---[ Options.
|
# ---[ Options.
|
||||||
set(PYTHON_LIB_REL_PATH "${PYTHON_SITE_PACKAGES}" CACHE STRING "Python installation path (relative to CMake installation prefix)")
|
set(PYTHON_LIB_REL_PATH "${Python_SITELIB}" CACHE STRING "Python installation path (relative to CMake installation prefix)")
|
||||||
message(STATUS "Using ${PYTHON_LIB_REL_PATH} as python relative installation path")
|
message(STATUS "Using ${PYTHON_LIB_REL_PATH} as python relative installation path")
|
||||||
# Python extension suffix
|
|
||||||
# Try to get from python through sysconfig.get_env_var('EXT_SUFFIX') first,
|
|
||||||
# fallback to ".pyd" if windows and ".so" for all others.
|
|
||||||
pycmd(PY_EXT_SUFFIX "
|
|
||||||
def get_ext_suffix():
|
|
||||||
import sys
|
|
||||||
import sysconfig
|
|
||||||
return sysconfig.get_config_var('EXT_SUFFIX')
|
|
||||||
|
|
||||||
suffix = get_ext_suffix()
|
|
||||||
if suffix is not None:
|
|
||||||
print(suffix)
|
|
||||||
else:
|
|
||||||
print()
|
|
||||||
")
|
|
||||||
if("${PY_EXT_SUFFIX}" STREQUAL "")
|
|
||||||
if(MSVC)
|
|
||||||
set(PY_EXT_SUFFIX ".pyd")
|
|
||||||
else()
|
|
||||||
set(PY_EXT_SUFFIX ".so")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
|
||||||
# Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80947 in EmbeddingBag.cpp
|
|
||||||
set_source_files_properties(../aten/src/ATen/native/EmbeddingBag.cpp PROPERTIES COMPILE_FLAGS -Wno-attributes)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(build_files)
|
set(build_files)
|
||||||
foreach(python_src ${PYTHON_SRCS})
|
foreach(python_src ${PYTHON_SRCS})
|
||||||
|
@ -1,11 +1,3 @@
|
|||||||
if(UNIX)
|
|
||||||
# prevent Unknown CMake command "check_function_exists".
|
|
||||||
include(CheckFunctionExists)
|
|
||||||
endif()
|
|
||||||
include(CheckIncludeFile)
|
|
||||||
include(CheckCSourceCompiles)
|
|
||||||
include(CheckCSourceRuns)
|
|
||||||
include(CheckCCompilerFlag)
|
|
||||||
include(CheckCXXSourceCompiles)
|
include(CheckCXXSourceCompiles)
|
||||||
include(CheckCXXCompilerFlag)
|
include(CheckCXXCompilerFlag)
|
||||||
include(CMakePushCheckState)
|
include(CMakePushCheckState)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
INCLUDE(CheckCSourceRuns)
|
INCLUDE(CheckCSourceRuns)
|
||||||
|
INCLUDE(CheckCSourceCompiles)
|
||||||
INCLUDE(CheckCXXSourceRuns)
|
INCLUDE(CheckCXXSourceRuns)
|
||||||
|
|
||||||
SET(AVX_CODE "
|
SET(AVX_CODE "
|
||||||
|
Reference in New Issue
Block a user