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

[tensorflow] add new port for linux #7568

Merged
merged 16 commits into from
Aug 20, 2019
Merged
7 changes: 7 additions & 0 deletions ports/tensorflow-cc/CONTROL
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Source: tensorflow-cc
Version: 1.14
Description: Library for computation using data flow graphs for scalable machine learning
[1] https://github.com/Microsoft/vcpkg/issues/3048
[2] https://github.com/FloopCZ/tensorflow_cc
[3] https://www.archlinux.org/packages/community/x86_64/tensorflow
Build-Depends: c-ares
79 changes: 79 additions & 0 deletions ports/tensorflow-cc/TensorflowCCConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
find_path(
TENSORFLOW_CC_INCLUDE_DIR_
NAMES client_session.h
PATH_SUFFIXES include/tensorflow/cc/client
)

set(TENSORFLOW_CC_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/../../include/)

if (NOT TENSORFLOW_CC_LIBRARY)
set(libraries
libtensorflow_framework.so.1.14.0 libtensorflow_cc.so.1.14.0)
find_library(
TENSORFLOW_LIBRARY_FRAMEWORK
NAMES
libtensorflow_framework.so.1.14.0
PATH_SUFFIXES lib)
find_library(
TENSORFLOW_LIBRARY_CC
NAMES
libtensorflow_cc.so.1.14.0
PATH_SUFFIXES lib)
if (NOT TENSORFLOW_LIBRARY_CC OR NOT TENSORFLOW_LIBRARY_FRAMEWORK)
message(FATAL_ERROR "Can't find ${libraries}")
endif()

set(TENSORFLOW_CC_LIBRARY_RELEASE
${TENSORFLOW_LIBRARY_CC}
${TENSORFLOW_LIBRARY_FRAMEWORK})

set(TENSORFLOW_CC_LIBRARY
optimized "${TENSORFLOW_CC_LIBRARY_RELEASE}")
endif()


mark_as_advanced(TENSORFLOW_CC_INCLUDE_DIR)

include(FindPackageHandleStandardArgs)

FIND_PACKAGE_HANDLE_STANDARD_ARGS(
TENSORFLOW_CC
REQUIRED_VARS
TENSORFLOW_CC_LIBRARY TENSORFLOW_CC_INCLUDE_DIR
VERSION_VAR)

if (TENSORFLOW_CC_FOUND)
set(TENSORFLOW_CC_INCLUDE_DIRS
${TENSORFLOW_CC_INCLUDE_DIR}
${TENSORFLOW_CC_INCLUDE_DIR}/tensorflow-external
${TENSORFLOW_CC_INCLUDE_DIR}/tensorflow-external/tensorflow
${TENSORFLOW_CC_INCLUDE_DIR}/tensorflow-external/external/com_google_absl
${TENSORFLOW_CC_INCLUDE_DIR}/tensorflow-external/bazel-out/k8-opt/bin/
)

if (NOT TARGET tensorflow_cc::tensorflow_framework)
add_library(tensorflow_cc::tensorflow_framework UNKNOWN IMPORTED)
set_target_properties(tensorflow_cc::tensorflow_framework
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${TENSORFLOW_CC_INCLUDE_DIRS}")

set_target_properties(tensorflow_cc::tensorflow_framework PROPERTIES
IMPORTED_LOCATION_RELEASE ${TENSORFLOW_LIBRARY_FRAMEWORK})
set_property(TARGET tensorflow_cc::tensorflow_framework APPEND PROPERTY
IMPORTED_CONFIGURATIONS RELEASE)
endif()

if (NOT TARGET tensorflow_cc::tensorflow_cc)
add_library(tensorflow_cc::tensorflow_cc UNKNOWN IMPORTED)
set_target_properties(tensorflow_cc::tensorflow_cc
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${TENSORFLOW_CC_INCLUDE_DIRS}")

set_target_properties(tensorflow_cc::tensorflow_cc PROPERTIES
IMPORTED_LOCATION_RELEASE ${TENSORFLOW_LIBRARY_CC})
set_property(TARGET tensorflow_cc::tensorflow_cc APPEND PROPERTY
IMPORTED_CONFIGURATIONS RELEASE)
set_property(TARGET tensorflow_cc::tensorflow_cc APPEND PROPERTY
INTERFACE_LINK_LIBRARIES tensorflow_cc::tensorflow_framework)
endif()
endif()
13 changes: 13 additions & 0 deletions ports/tensorflow-cc/file-exists.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/configure.py b/configure.py
index 43af22d..7989b1f 100644
--- a/configure.py
+++ b/configure.py
@@ -183,7 +183,7 @@ def get_python_path(environ_cp, python_bin_path):

paths = []
for path in all_paths:
- if os.path.isdir(path):
+ if os.path.isdir(path) or True:
paths.append(path)
return paths

123 changes: 123 additions & 0 deletions ports/tensorflow-cc/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
include(vcpkg_common_functions)

if(CMAKE_HOST_WIN32)
message(WARNING "This tensorflow port currently is experimental on Windows and Linux platforms.")
endif()

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO tensorflow/tensorflow
REF v1.14.0
SHA512 ac9ea5a2d1c761aaafbdc335259e29c128127b8d069ec5b206067935180490aa95e93c7e13de57f7f54ce4ba4f34a822face22b4a028f60185edb380e5cd4787
HEAD_REF master
PATCHES
file-exists.patch # required or otherwise it cant find python lib path on windows
)

# due to https://github.com/bazelbuild/bazel/issues/8028, bazel must be version 25.0 or higher
vcpkg_find_acquire_program(BAZEL)
get_filename_component(BAZEL_DIR "${BAZEL}" DIRECTORY)
vcpkg_add_to_path(PREPEND ${BAZEL_DIR})
set(ENV{BAZEL_BIN_PATH} "${BAZEL}")

vcpkg_find_acquire_program(PYTHON3)
get_filename_component(PYTHON3_DIR "${PYTHON3}" DIRECTORY)
vcpkg_add_to_path(PREPEND ${PYTHON3_DIR})
set(ENV{PYTHON_BIN_PATH} "${PYTHON3}")

function(tensorflow_try_remove_recurse_wait PATH_TO_REMOVE)
file(REMOVE_RECURSE ${PATH_TO_REMOVE})
if (EXISTS "${PATH_TO_REMOVE}")
execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 5)
file(REMOVE_RECURSE ${PATH_TO_REMOVE})
endif()
endfunction()

# we currently only support the release version
tensorflow_try_remove_recurse_wait(${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel)
file(MAKE_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel)
file(GLOB SOURCES ${SOURCE_PATH}/*)
file(COPY ${SOURCES} DESTINATION ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel)

if(CMAKE_HOST_WIN32)
vcpkg_acquire_msys(MSYS_ROOT PACKAGES unzip patch diffutils git)
set(BASH ${MSYS_ROOT}/usr/bin/bash.exe)
set(ENV{BAZEL_SH} ${MSYS_ROOT}/usr/bin/bash.exe)

set(ENV{BAZEL_VS} $ENV{VSInstallDir})
set(ENV{BAZEL_VC} $ENV{VCInstallDir})
endif()

# tensorflow has long file names, which will not work on windows
# we are temporarily putting it here (will be changed later)
set(ENV{TEST_TMPDIR} ${DOWNLOADS}/bzl)

set(ENV{CURRENT_PACKAGES_DIR} ${CURRENT_PACKAGES_DIR})

set(ENV{USE_DEFAULT_PYTHON_LIB_PATH} 1)
#set(ENV{TF_NEED_JEMALLOC} 0)
set(ENV{TF_NEED_KAFKA} 0)
set(ENV{TF_NEED_OPENCL_SYCL} 0)
set(ENV{TF_NEED_AWS} 0)
set(ENV{TF_NEED_GCP} 0)
set(ENV{TF_NEED_HDFS} 0)
set(ENV{TF_NEED_S3} 0)
set(ENV{TF_ENABLE_XLA} 0)
set(ENV{TF_NEED_GDR} 0)
set(ENV{TF_NEED_VERBS} 0)
set(ENV{TF_NEED_OPENCL} 0)
set(ENV{TF_NEED_MPI} 0)
set(ENV{TF_NEED_TENSORRT} 0)
set(ENV{TF_NEED_NGRAPH} 0)
set(ENV{TF_NEED_IGNITE} 0)
set(ENV{TF_NEED_ROCM} 0)
set(ENV{TF_SET_ANDROID_WORKSPACE} 0)
set(ENV{TF_DOWNLOAD_CLANG} 0)
set(ENV{TF_NCCL_VERSION} 2.3)
set(ENV{NCCL_INSTALL_PATH} "/usr")
set(ENV{CC_OPT_FLAGS} "/arch:AVX")
# for gcc only https://gcc.gnu.org/onlinedocs/gcc-4.5.3/gcc/i386-and-x86_002d64-Options.html
set(ENV{TF_NEED_CUDA} 0)

message(STATUS "Configuring TensorFlow")

vcpkg_execute_required_process(
COMMAND ${PYTHON3} ${SOURCE_PATH}/configure.py
WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel
LOGNAME config-${TARGET_TRIPLET}-rel
)
message(STATUS "Warning: Building TensorFlow can take an hour or more.")

if(CMAKE_HOST_WIN32)
vcpkg_execute_build_process(
COMMAND ${BASH} --noprofile --norc -c "${BAZEL} build -c opt --python_path=${PYTHON3} --incompatible_disable_deprecated_attr_params=false --define=no_tensorflow_py_deps=true ///tensorflow:libtensorflow_cc.so ///tensorflow:install_headers"
WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel
LOGNAME build-${TARGET_TRIPLET}-rel
)
else()
vcpkg_execute_build_process(
COMMAND ${BAZEL} build -c opt --python_path=${PYTHON3} --incompatible_disable_deprecated_attr_params=false --define=no_tensorflow_py_deps=true //tensorflow:libtensorflow_cc.so //tensorflow:install_headers
WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel
LOGNAME build-${TARGET_TRIPLET}-rel
)
endif()

file(COPY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/bazel-genfiles/tensorflow/include/ DESTINATION ${CURRENT_PACKAGES_DIR}/include/tensorflow-external)

if(CMAKE_HOST_WIN32)
file(COPY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/bazel-bin/tensorflow/libtensorflow_cc.so.1.14.0 DESTINATION ${CURRENT_PACKAGES_DIR}/lib)
file(COPY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/bazel-bin/tensorflow/libtensorflow_cc.so.1.14.0.if.lib DESTINATION ${CURRENT_PACKAGES_DIR}/lib)
file(COPY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/bazel-bin/tensorflow/libtensorflow_cc.so.1.14.0 DESTINATION ${CURRENT_PACKAGES_DIR}/debug/lib)
file(COPY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/bazel-bin/tensorflow/libtensorflow_cc.so.1.14.0.if.lib DESTINATION ${CURRENT_PACKAGES_DIR}/debug/lib)
else()
file(COPY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/bazel-bin/tensorflow/libtensorflow_cc.so.1.14.0 DESTINATION ${CURRENT_PACKAGES_DIR}/lib)
file(COPY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/bazel-bin/tensorflow/libtensorflow_framework.so.1.14.0 DESTINATION ${CURRENT_PACKAGES_DIR}/lib)
file(COPY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/bazel-bin/tensorflow/libtensorflow_cc.so.1.14.0 DESTINATION ${CURRENT_PACKAGES_DIR}/debug/lib)
file(COPY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/bazel-bin/tensorflow/libtensorflow_framework.so.1.14.0 DESTINATION ${CURRENT_PACKAGES_DIR}/debug/lib)
endif()

file(COPY ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/tensorflow-cc)
file(RENAME ${CURRENT_PACKAGES_DIR}/share/tensorflow-cc/LICENSE ${CURRENT_PACKAGES_DIR}/share/tensorflow-cc/copyright)

file(COPY ${CMAKE_CURRENT_LIST_DIR}/TensorflowCCConfig.cmake DESTINATION ${CURRENT_PACKAGES_DIR}/share/unofficial-tensorflow-cc)
file(RENAME ${CURRENT_PACKAGES_DIR}/share/unofficial-tensorflow-cc/TensorflowCCConfig.cmake ${CURRENT_PACKAGES_DIR}/share/unofficial-tensorflow-cc/unofficial-tensorflow-cc-config.cmake)
24 changes: 21 additions & 3 deletions scripts/cmake/vcpkg_find_acquire_program.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function(vcpkg_find_acquire_program VAR)
unset(_vfa_RENAME)
unset(SUBDIR)
unset(REQUIRED_INTERPRETER)
unset(_vfa_SUPPORTED)
unset(POST_INSTALL_COMMAND)

vcpkg_get_program_files_platform_bitness(PROGRAM_FILES_PLATFORM_BITNESS)
Expand Down Expand Up @@ -231,6 +232,23 @@ function(vcpkg_find_acquire_program VAR)
set(URL "http://doxygen.nl/files/doxygen-1.8.15.windows.bin.zip")
set(ARCHIVE "doxygen-1.8.15.windows.bin.zip")
set(HASH 89482dcb1863d381d47812c985593e736d703931d49994e09c7c03ef67e064115d0222b8de1563a7930404c9bc2d3be323f3d13a01ef18861be584db3d5a953c)
elseif(VAR MATCHES "BAZEL")
set(_vfa_SUPPORTED ON) # may remove this later
set(PROGNAME bazel)
set(BAZEL_VERSION 0.25.2)
set(SUBDIR ${BAZEL_VERSION})
set(PATHS ${DOWNLOADS}/tools/bazel/${SUBDIR})
set(_vfa_RENAME "bazel")
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
set(URL "https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-linux-x86_64")
set(ARCHIVE "bazel-${BAZEL_VERSION}-linux-x86_64")
set(NOEXTRACT ON)
set(HASH db4a583cf2996aeb29fd008261b12fe39a4a5faf0fbf96f7124e6d3ffeccf6d9655d391378e68dd0915bc91c9e146a51fd9661963743857ca25179547feceab1)
else()
set(URL "https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-windows-x86_64.zip")
set(ARCHIVE "bazel-${BAZEL_VERSION}-windows-x86_64.zip")
set(HASH 6482f99a0896f55ef65739e7b53452fd9c0adf597b599d0022a5e0c5fa4374f4a958d46f98e8ba25af4b065adacc578bfedced483d8c169ea5cb1777a99eea53)
endif()
# Download Tools
elseif(VAR MATCHES "ARIA2")
set(PROGNAME aria2c)
Expand All @@ -254,7 +272,7 @@ function(vcpkg_find_acquire_program VAR)

do_find()
if("${${VAR}}" MATCHES "-NOTFOUND")
if(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
if(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows" AND NOT _vfa_SUPPORTED)
set(EXAMPLE ".")
if(DEFINED BREW_PACKAGE_NAME AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
set(EXAMPLE ":\n brew install ${BREW_PACKAGE_NAME}")
Expand All @@ -274,9 +292,9 @@ function(vcpkg_find_acquire_program VAR)
file(MAKE_DIRECTORY ${PROG_PATH_SUBDIR})
if(DEFINED NOEXTRACT)
if(DEFINED _vfa_RENAME)
file(INSTALL ${ARCHIVE_PATH} DESTINATION ${PROG_PATH_SUBDIR} RENAME ${_vfa_RENAME})
file(INSTALL ${ARCHIVE_PATH} DESTINATION ${PROG_PATH_SUBDIR} RENAME ${_vfa_RENAME} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
else()
file(COPY ${ARCHIVE_PATH} DESTINATION ${PROG_PATH_SUBDIR})
file(COPY ${ARCHIVE_PATH} DESTINATION ${PROG_PATH_SUBDIR} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
endif()
else()
get_filename_component(ARCHIVE_EXTENSION ${ARCHIVE} EXT)
Expand Down