Skip to content

Commit

Permalink
Move TORCH_MLIR_USE_INSTALLED_PYTORCH to top-level.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stellaraccident committed Nov 23, 2023
1 parent 1b7d6f2 commit 66b73ed
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion projects/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()

Expand Down
2 changes: 0 additions & 2 deletions projects/pt1/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down

0 comments on commit 66b73ed

Please sign in to comment.