mirror of https://github.com/llvm/torch-mlir
49 lines
1.4 KiB
CMake
49 lines
1.4 KiB
CMake
include(NpcompPython)
|
|
|
|
# Sharp edge: Torch extensions need to use the same pybind11 that torch
|
|
# was compiled with, or else there will be issues in cross module exception
|
|
# handling (which will abort instead of raise). We circumvent the possibility
|
|
# by forcing the torch directories first.
|
|
include_directories(BEFORE
|
|
${TORCH_INCLUDE_DIRS}
|
|
${CMAKE_CURRENT_SOURCE_DIR}
|
|
${CMAKE_CURRENT_BINARY_DIR}
|
|
${Python3_INCLUDE_DIRS}
|
|
)
|
|
link_directories("${TORCH_INSTALL_PREFIX}/lib")
|
|
|
|
add_library(NPCOMPTorchMLIRExt SHARED
|
|
builder/acap_dispatch.cpp
|
|
builder/class_annotator.cpp
|
|
builder/debug.cpp
|
|
builder/func_builder.cpp
|
|
builder/function_importer.cpp
|
|
builder/module_builder.cpp
|
|
builder/node_importer.cpp
|
|
builder/op_builder.cpp
|
|
builder/ivalue_importer.cpp
|
|
builder/python_bindings.cpp
|
|
builder/torch_to_mlir_utils.cpp
|
|
init_python_bindings.cpp
|
|
)
|
|
|
|
target_link_libraries(NPCOMPTorchMLIRExt
|
|
NPCOMPPythonCAPI
|
|
${TORCH_LIBRARIES}
|
|
${Python3_LIBRARIES}
|
|
torch_python
|
|
)
|
|
|
|
message(STATUS "TORCH_CXXFLAGS=${TORCH_CXXFLAGS}")
|
|
set_target_properties(NPCOMPTorchMLIRExt PROPERTIES
|
|
LIBRARY_OUTPUT_DIRECTORY "${MLIR_NPCOMP_PYTHON_PACKAGES_DIR}/npcomp_torch"
|
|
OUTPUT_NAME _torch_mlir
|
|
PREFIX "${PYTHON_MODULE_PREFIX}"
|
|
SUFFIX "${PYTHON_MODULE_EXTENSION}"
|
|
CXX_VISIBILITY_PRESET "hidden"
|
|
COMPILE_FLAGS "${TORCH_CXXFLAGS}"
|
|
)
|
|
|
|
npcomp_python_target_compile_options(NPCOMPTorchMLIRExt)
|
|
mlir_check_all_link_libraries(NPCOMPTorchMLIRExt)
|