From 66b73edb286fb5c0f1ace2b0b4b147bf9edbc3e7 Mon Sep 17 00:00:00 2001 From: Stella Laurenzo Date: Wed, 22 Nov 2023 17:52:07 -0800 Subject: [PATCH] Move TORCH_MLIR_USE_INSTALLED_PYTORCH to top-level. This was unfortunately being initialized in a directory below its first use. This was causing the first configure to mis-detect the ABI flags, which was causing type conversion failures at runtime. Fixes #2298 and hardens some additional messages and checks to better make it clear when something goes awry. --- CMakeLists.txt | 2 ++ projects/CMakeLists.txt | 11 ++++++++++- projects/pt1/python/CMakeLists.txt | 2 -- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1114643a593b..ccbe7ccb3a98 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,8 @@ set(CMAKE_CXX_STANDARD 17) # Project options #------------------------------------------------------------------------------- +option(TORCH_MLIR_USE_INSTALLED_PYTORCH "If depending on PyTorch use it as installed in the current Python environment" ON) + option(TORCH_MLIR_ENABLE_REFBACKEND "Enable reference backend" ON) if(TORCH_MLIR_ENABLE_REFBACKEND) add_definitions(-DTORCH_MLIR_ENABLE_REFBACKEND) diff --git a/projects/CMakeLists.txt b/projects/CMakeLists.txt index 2838570a8797..4b54be65a79d 100644 --- a/projects/CMakeLists.txt +++ b/projects/CMakeLists.txt @@ -12,6 +12,9 @@ if(TORCH_MLIR_ENABLE_JIT_IR_IMPORTER OR TORCH_MLIR_ENABLE_LTC) # Assume it is a sibling to the overall project. set(Torch_DIR "${PROJECT_SOURCE_DIR}/../libtorch/share/cmake/Torch") message(STATUS "Attempting to locate libtorch as a sibling to the project: ${Torch_DIR}") + if(NOT EXISTS "${Torch_DIR}") + message(FATAL_ERROR "Without TORCH_MLIR_USE_INSTALLED_PYTORCH, expected to find Torch configuration at ${Torch_DIR}, which does not exist") + endif() endif() find_package(Torch 1.11 REQUIRED) @@ -23,7 +26,13 @@ if(TORCH_MLIR_ENABLE_JIT_IR_IMPORTER OR TORCH_MLIR_ENABLE_LTC) ${Python3_INCLUDE_DIRS} ) link_directories("${TORCH_INSTALL_PREFIX}/lib") - message(STATUS "libtorch_python CXXFLAGS is ...${TORCH_CXXFLAGS}") + message(STATUS "TORCH_CXXFLAGS is = ${TORCH_CXXFLAGS}") + if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND NOT TORCH_CXXFLAGS) + message(WARNING + "When building on Linux TORCH_CXXFLAGS are almost always required but were not detected. " + "It is very likely this this will produce a non-functional installation. " + "See notes in build_tools/cmake/TorchMLIRPyTorch.cmake.") + endif() message(STATUS "TORCH_LIBRARIES = ${TORCH_LIBRARIES}") endif() diff --git a/projects/pt1/python/CMakeLists.txt b/projects/pt1/python/CMakeLists.txt index 23dd5be4071c..e951772df935 100644 --- a/projects/pt1/python/CMakeLists.txt +++ b/projects/pt1/python/CMakeLists.txt @@ -15,8 +15,6 @@ add_compile_definitions("MLIR_PYTHON_PACKAGE_PREFIX=torch_mlir.") # PyTorch ################################################################################ -option(TORCH_MLIR_USE_INSTALLED_PYTORCH "Build from local PyTorch in environment" ON) - if (NOT TORCH_MLIR_USE_INSTALLED_PYTORCH) # Source builds set(ENV{TORCH_MLIR_SRC_PYTORCH_REPO} ${TORCH_MLIR_SRC_PYTORCH_REPO})