Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 39 additions & 14 deletions source/cmake/Findtensorflow.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,19 @@ if (BUILD_CPP_IF AND INSTALL_TENSORFLOW)
)
endif ()

if (BUILD_CPP_IF AND USE_TF_PYTHON_LIBS)
if (BUILD_CPP_IF AND USE_TF_PYTHON_LIBS AND NOT SKBUILD)
# Here we try to install libtensorflow_cc.so as well as libtensorflow_framework.so using libs within the python site-package tensorflow folder.

if (NOT DEFINED TENSORFLOW_ROOT)
set (TENSORFLOW_ROOT ${CMAKE_INSTALL_PREFIX})
endif ()
# execute install script
execute_process(
COMMAND sh ${DEEPMD_SOURCE_DIR}/source/install/install_tf.sh ${Python_SITELIB} ${TENSORFLOW_ROOT}
)
COMMAND ${Python_EXECUTABLE} -c "import tensorflow; print(tensorflow.sysconfig.get_lib())"
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE TENSORFLOW_ROOT
RESULT_VARIABLE TENSORFLOW_ROOT_RESULT_VAR
ERROR_VARIABLE TENSORFLOW_ROOT_ERROR_VAR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (NOT ${TENSORFLOW_ROOT_RESULT_VAR} EQUAL 0)
message(FATAL_ERROR "Cannot determine tensorflow root, error code: ${TENSORFLOW_ROOT_RESULT_VAR}, error message: ${TENSORFLOW_ROOT_ERROR_VAR}")
endif()
endif ()

if(DEFINED TENSORFLOW_ROOT)
Expand All @@ -50,12 +53,12 @@ endif(DEFINED TENSORFLOW_ROOT)

# define the search path
list(APPEND TensorFlow_search_PATHS ${TENSORFLOW_ROOT})
if(BUILD_CPP_IF)
if(BUILD_CPP_IF AND NOT USE_TF_PYTHON_LIBS)
list(APPEND TensorFlow_search_PATHS ${TENSORFLOW_ROOT_NO64})
list(APPEND TensorFlow_search_PATHS "/usr/")
list(APPEND TensorFlow_search_PATHS "/usr/local/")
endif()
if(BUILD_PY_IF)
if(BUILD_PY_IF OR USE_TF_PYTHON_LIBS)
# here TENSORFLOW_ROOT is path to site-packages/tensorflow
# for conda libraries, append extra paths
list(APPEND TensorFlow_search_PATHS "${TENSORFLOW_ROOT}/../tensorflow_core")
Expand All @@ -80,7 +83,7 @@ if (NOT TensorFlow_INCLUDE_DIRS AND tensorflow_FIND_REQUIRED)
"You can manually set the tensorflow install path by -DTENSORFLOW_ROOT ")
endif ()

if (BUILD_CPP_IF)
if (BUILD_CPP_IF AND NOT USE_TF_PYTHON_LIBS)
message (STATUS "Enabled cpp interface build, looking for tensorflow_cc and tensorflow_framework")
# tensorflow_cc and tensorflow_framework
if (NOT TensorFlow_FIND_COMPONENTS)
Expand All @@ -105,9 +108,9 @@ if (BUILD_CPP_IF)
"You can manually set the tensorflow install path by -DTENSORFLOW_ROOT ")
endif ()
endforeach ()
else (BUILD_CPP_IF)
else (BUILD_CPP_IF AND NOT USE_TF_PYTHON_LIBS)
message (STATUS "Disabled cpp interface build, looking for tensorflow_framework")
endif (BUILD_CPP_IF)
endif (BUILD_CPP_IF AND NOT USE_TF_PYTHON_LIBS)


# tensorflow_framework
Expand Down Expand Up @@ -139,11 +142,33 @@ foreach (module ${TensorFlowFramework_FIND_COMPONENTS})
list(APPEND TensorFlowFramework_LIBRARY_PATH ${TensorFlowFramework_LIBRARY_PATH_${module}})
elseif (tensorflow_FIND_REQUIRED)
message(FATAL_ERROR
"Not found lib/'${module}' in '${TensorFlow_search_PATHS}' "
"Not found ${TF_SUFFIX}/${module} in '${TensorFlow_search_PATHS}' "
"You can manually set the tensorflow install path by -DTENSORFLOW_ROOT ")
endif ()
endforeach ()

# find _pywrap_tensorflow_internal and set it as tensorflow_cc
if (BUILD_CPP_IF AND USE_TF_PYTHON_LIBS)
set(TF_SUFFIX python)
set(TensorFlow_FIND_COMPONENTS _pywrap_tensorflow_internal${CMAKE_SHARED_LIBRARY_SUFFIX})
foreach (module ${TensorFlow_FIND_COMPONENTS})
find_library(TensorFlow_LIBRARY_${module}
NAMES ${module}
PATHS ${TensorFlow_search_PATHS} PATH_SUFFIXES ${TF_SUFFIX} NO_DEFAULT_PATH
)
if (TensorFlow_LIBRARY_${module})
list(APPEND TensorFlow_LIBRARY ${TensorFlow_LIBRARY_${module}})
get_filename_component(TensorFlow_LIBRARY_PATH_${module} ${TensorFlow_LIBRARY_${module}} PATH)
list(APPEND TensorFlow_LIBRARY_PATH ${TensorFlow_LIBRARY_PATH_${module}})
set (TensorFlow_LIBRARY_tensorflow_cc ${TensorFlow_LIBRARY_${module}})
elseif (tensorflow_FIND_REQUIRED)
message(FATAL_ERROR
"Not found ${TF_SUFFIX}/${module} in '${TensorFlow_search_PATHS}' ")
endif ()
endforeach ()
endif()


# find protobuf header
find_path(TensorFlow_INCLUDE_DIRS_GOOGLE
NAMES
Expand Down
3 changes: 2 additions & 1 deletion source/lmp/env_py.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ PYTHON_LIBRARY_PATH="@Python_LIBRARY_DIRS@"

TF_INCLUDE_DIRS=`echo $TENSORFLOW_INCLUDE_DIRS | sed "s/;/ -I/g"`
TF_LIBRARY_PATH=`echo $TENSORFLOW_LIBRARY_PATH | sed "s/;/ -L/g"`
PY_LIBRARY_PATH=`echo $PYTHON_LIBRARY_PATH | sed "s/;/ -L/g"`
TF_RPATH=`echo $TENSORFLOW_LIBRARY_PATH | sed "s/;/ -Wl,-rpath=/g"`
PYTHON_RPATH=`echo $PYTHON_LIBRARY_PATH | sed "s/;/ -Wl,-rpath=/g"`

NNP_INC=" -D_GLIBCXX_USE_CXX11_ABI=@OP_CXX_ABI@ -std=c++@CMAKE_CXX_STANDARD@ -D@prec_def@ -DLAMMPS_VERSION_NUMBER=$(./lmp_version.sh) -I$TF_INCLUDE_DIRS -I$DEEPMD_ROOT/include/ "
NNP_PATH=" -L$TF_LIBRARY_PATH -L$DEEPMD_ROOT/lib"
NNP_PATH=" -L$TF_LIBRARY_PATH -L$DEEPMD_ROOT/lib -L$PY_LIBRARY_PATH"
NNP_LIB=" -Wl,--no-as-needed -l@LIB_DEEPMD_CC@ -ltensorflow_cc -ltensorflow_framework -lpython@Python_VERSION_MAJOR@.@Python_VERSION_MINOR@ -Wl,-rpath=$TF_RPATH -Wl,-rpath=$DEEPMD_ROOT/lib -Wl,-rpath=$PYTHON_RPATH "