Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: use pip to install tensorflow #2858

Merged
merged 2 commits into from
Sep 25, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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