Skip to content

Commit

Permalink
cmake: use pip to install tensorflow (#2858)
Browse files Browse the repository at this point in the history
When setting the `INSTALL_TENSORFLOW` variable, previously CMake calls
conda to install tensorflow. Now we use pip to install it.

---------

Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
  • Loading branch information
njzjz authored Sep 25, 2023
1 parent c2c6476 commit e1ae5e0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
7 changes: 3 additions & 4 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ if((NOT BUILD_PY_IF) AND (NOT BUILD_CPP_IF))
endif()

if(BUILD_CPP_IF AND BUILD_TESTING)
if(NOT INSTALL_TENSORFLOW)
# some errors in conda packages...
find_package(GTest)
endif()
if(NOT GTEST_LIBRARIES)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/googletest.cmake.in
googletest-download/CMakeLists.txt @ONLY)
Expand Down Expand Up @@ -127,6 +123,9 @@ endif(USE_ROCM_TOOLKIT)
set(DEEPMD_SOURCE_DIR ${PROJECT_SOURCE_DIR}/..)

# setup tensorflow libraries by python
if(INSTALL_TENSORFLOW)
set(USE_TF_PYTHON_LIBS TRUE)
endif(INSTALL_TENSORFLOW)
if(USE_TF_PYTHON_LIBS)
if(NOT "$ENV{CIBUILDWHEEL}" STREQUAL "1")
find_package(
Expand Down
19 changes: 12 additions & 7 deletions source/cmake/Findtensorflow.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,30 @@ if(SKBUILD)
endif(SKBUILD)

if(BUILD_CPP_IF AND INSTALL_TENSORFLOW)
# Here we try to install libtensorflow_cc using conda install.
# Here we try to install libtensorflow_cc using pip install.

if(USE_CUDA_TOOLKIT)
set(VARIANT cuda)
set(VARIANT "")
else()
set(VARIANT cpu)
set(VARIANT "-cpu")
endif()

if(NOT DEFINED TENSORFLOW_ROOT)
set(TENSORFLOW_ROOT ${CMAKE_INSTALL_PREFIX})
endif()
# execute conda install
execute_process(COMMAND conda create libtensorflow_cc=*=${VARIANT}* -c
deepmodeling -y -p ${TENSORFLOW_ROOT})
# execute pip install
execute_process(
COMMAND ${Python_EXECUTABLE} -m pip install tensorflow${VARIANT} --no-deps
--target=${TENSORFLOW_ROOT})
set(TENSORFLOW_ROOT
${TENSORFLOW_ROOT}/lib/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages/tensorflow
)
endif()

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

0 comments on commit e1ae5e0

Please sign in to comment.