yelite commented on code in PR #12232: URL: https://github.com/apache/tvm/pull/12232#discussion_r933381946
########## cmake/modules/contrib/PT_TVMDSOOP.cmake: ########## @@ -21,38 +21,55 @@ if(NOT USE_PT_TVMDSOOP STREQUAL "OFF") execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import torch; print(torch.__path__[0].strip())" OUTPUT_VARIABLE PT_PATH RESULT_VARIABLE PT_STATUS) - if (NOT ${PT_STATUS} EQUAL 0) + + if(NOT ${PT_STATUS} EQUAL 0) message(FATAL_ERROR "Fail to get pytorch path") endif() string(REGEX REPLACE "\n" "" PT_PATH "${PT_PATH}") message(STATUS "PyTorch path: ${PT_PATH}") - set(PT_COMPILE_FLAGS_STR "-I${PT_PATH}/include -D_GLIBCXX_USE_CXX11_ABI=0") + execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import torch;print(torch.compiled_with_cxx11_abi())" + OUTPUT_VARIABLE PT_CXX_FLAG + RESULT_VARIABLE PT_STATUS) + + string(REGEX REPLACE "\n" "" PT_CXX_FLAG "${PT_CXX_FLAG}") + message(STATUS "Found TORCH_BUILT_WITH_CXX_ABI=${PT_CXX_FLAG} ") + + if(${PT_CXX_FLAG} STREQUAL "False") + set(CXX_ABI_ENABLED 0) + else() + set(CXX_ABI_ENABLED 1) + endif() + + set_property( + SOURCE + ${CMAKE_CURRENT_SOURCE_DIR}/src/contrib/torch/tvm_module_wrapper/RuntimeModuleWrapperTorch.cc + APPEND PROPERTY + COMPILE_OPTIONS + "-D_GLIBCXX_USE_CXX11_ABI=${CXX_ABI_ENABLED}" + "-I${PT_PATH}/include" + ) set(PT_LINK_FLAGS_STR "-L${PT_PATH}/lib -l:libtorch.so -l:libtorch_python.so") if(NOT USE_CUDA STREQUAL "OFF") add_definitions(-DPT_TVMDSOOP_ENABLE_GPU) endif() - string(REGEX REPLACE "\n" " " PT_FLAGS "${PT_COMPILE_FLAGS} ${PT_LINK_FLAGS}") - separate_arguments(PT_COMPILE_FLAGS UNIX_COMMAND ${PT_COMPILE_FLAGS_STR}) + separate_arguments(PT_COMPILE_FLAGS UNIX_COMMAND) separate_arguments(PT_LINK_FLAGS UNIX_COMMAND ${PT_LINK_FLAGS_STR}) - set(LIBRARY_NAME pt_tvmdsoop) - tvm_file_glob(GLOB_RECURSE PTTVM_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/src/contrib/torch/**/*.cc) + tvm_file_glob(GLOB_RECURSE PTTVM_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/src/contrib/torch/tvm_module_wrapper/*.cc) Review Comment: Instead of skipping compilation of `tvm_class.cc`, can you move the new code to a *separate dynamic library*? This can be done by adding a new `add_library` command and other related commands to the cmake file. This means, in addition to `libpt_tvmdsoop`, the build will produce another library for the new PyTorch integration. Then in the Python code, it should load those two libraries in two try-catch blocks (log error and continue if `dlopen` fails) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@tvm.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org