diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4bf62dc --- /dev/null +++ b/Makefile @@ -0,0 +1,134 @@ +PORTNAME= libtensorflow1 +DISTVERSIONPREFIX= v +DISTVERSION= 1.15.5 +DISTVERSIONSUFFIX= +CATEGORIES= science + +MAINTAINER= freebsd-ports@otoh.org +COMMENT= C API for TensorFlow, an open source platform for machine learning + +LICENSE= APACHE20 THIRD_PARTY_TF_C_LICENSES +LICENSE_COMB= multi +LICENSE_NAME_THIRD_PARTY_TF_C_LICENSES= Third-Party TensorFlow C Licenses +LICENSE_FILE_APACHE20= ${WRKSRC}/LICENSE +LICENSE_FILE_THIRD_PARTY_TF_C_LICENSES= ${WRKDIR}/THIRD_PARTY_TF_C_LICENSES +LICENSE_PERMS_THIRD_PARTY_TF_C_LICENSES= dist-mirror dist-sell pkg-mirror pkg-sell auto-accept + +CONFLICTS_INSTALL= science/libtensorflow2 + +ONLY_FOR_ARCHS= amd64 + +BUILD_DEPENDS= bash:shells/bash \ + bazel:devel/bazel029 \ + git:devel/git + +USES= gmake python:3.7-3.9,build +BINARY_ALIAS= python3=${PYTHON_CMD} +BINARY_ALIAS+= python=${PYTHON_CMD} + +USE_GITHUB= yes +GH_ACCOUNT= tensorflow +GH_PROJECT= tensorflow + +USE_LDCONFIG= yes + +OPTIONS_DEFINE= CUDA ROCM XLA + +OPTIONS_SINGLE= CPUFEATURE +OPTIONS_SINGLE_CPUFEATURE= NOAVX AVX AVX2 + +NOAVX_DESC= Disable Advanced Vector Extensions +AVX_DESC= Enable Advanced Vector Extensions (AVX) +AVX2_DESC= Enable Advanced Vector Extensions v2 (AVX2) + +NOAVX_VARS= BAZEL_ARGS="" +AVX_VARS= BAZEL_ARGS="--copt=-march=core-avx-i --host_copt=-march=core-avx-i" +AVX2_VARS= BAZEL_ARGS="--copt=-march=core-avx2 --host_copt=-march=core-avx2" + +CUDA_DESC= Enable Compute Unified Device Architecture (CUDA) for Nvidia GPUs +CUDA_VARS= TF_ENABLE_CUDA=1 +CUDA_VARS_OFF= TF_ENABLE_CUDA=0 + +ROCM_DESC= Enable Radeon Open Computer (ROCm) for AMD GPUs +ROCM_VARS= TF_ENABLE_ROCM=1 +ROCM_VARS_OFF= TF_ENABLE_ROCM=0 + +XLA_DESC= Enable Accelerated Linear Algebra (XLA) +XLA_VARS= TF_ENABLE_XLA=1 +XLA_VARS_OFF= TF_ENABLE_XLA=0 + +OPTIONS_DEFAULT= AVX + +BAZEL_OPTS= --output_user_root=${WRKDIR}/bazel_out +CC?= clang + +post-extract: + # THIRD_PARTY_TF_C_LICENSES is generated as a Bazel build target (see + # //tensorflow/tools/lib_package:clicenses) and the empty file written + # here will be overwritten. Creation of this file is to satisfy checks. + @${TOUCH} ${WRKDIR}/THIRD_PARTY_TF_C_LICENSES + +do-configure: + @cd ${WRKSRC} && ${SETENV} \ + CC_OPT_FLAGS="-I${LOCALBASE}/include" \ + PREFIX="${LOCALBASE}" \ + PYTHON_BIN_PATH=${PYTHON_CMD} \ + PYTHON_LIB_PATH="${PYTHON_SITELIBDIR}" \ + TF_CONFIGURE_IOS=0 \ + TF_DOWNLOAD_CLANG=0 \ + TF_ENABLE_XLA=${TF_ENABLE_XLA} \ + TF_IGNORE_MAX_BAZEL_VERSION=0 \ + TF_NEED_CUDA=${TF_ENABLE_CUDA} \ + TF_NEED_ROCM=${TF_ENABLE_ROCM} \ + TF_NEED_TENSORRT=0 \ + TF_SET_ANDROID_WORKSPACE=0 \ + ${LOCALBASE}/bin/bash ./configure + +do-build: + @cd ${WRKSRC} && ${LOCALBASE}/bin/bazel ${BAZEL_OPTS} build \ + ${BAZEL_ARGS} \ + --action_env=PATH=${PATH} \ + --local_cpu_resources=${MAKE_JOBS_NUMBER} \ + --noshow_loading_progress \ + --noshow_progress \ + --subcommands \ + --verbose_failures \ + //tensorflow/tools/lib_package:clicenses_generate \ + //tensorflow/tools/lib_package:libtensorflow.tar.gz + +do-test: + @cd ${WRKSRC} && ${LOCALBASE}/bin/bazel ${BAZEL_OPTS} test \ + ${BAZEL_ARGS} \ + --action_env=PATH=${PATH} \ + --local_cpu_resources=${MAKE_JOBS_NUMBER} \ + --noshow_loading_progress \ + --noshow_progress \ + --subcommands \ + --test_env=CC=${CC} \ + --verbose_failures \ + //tensorflow/tools/lib_package:libtensorflow_test + +pre-install: + @${CP} ${WRKSRC}/bazel-bin/tensorflow/tools/lib_package/THIRD_PARTY_TF_C_LICENSES ${WRKDIR}/THIRD_PARTY_TF_C_LICENSES + @${MKDIR} ${WRKDIR}/lib_package + @tar xz -C ${WRKDIR}/lib_package -f ${WRKSRC}/bazel-bin/tensorflow/tools/lib_package/libtensorflow.tar.gz + ${MKDIR} ${STAGEDIR}${PREFIX}/include/tensorflow + ${MKDIR} ${STAGEDIR}${PREFIX}/include/tensorflow/c + ${MKDIR} ${STAGEDIR}${PREFIX}/include/tensorflow/c/eager + +do-install: + ${INSTALL_DATA} ${WRKDIR}/lib_package/include/tensorflow/c/c_api_experimental.h ${STAGEDIR}${PREFIX}/include/tensorflow/c/c_api_experimental.h + ${INSTALL_DATA} ${WRKDIR}/lib_package/include/tensorflow/c/c_api.h ${STAGEDIR}${PREFIX}/include/tensorflow/c/c_api.h + ${INSTALL_DATA} ${WRKDIR}/lib_package/include/tensorflow/c/eager/c_api.h ${STAGEDIR}${PREFIX}/include/tensorflow/c/eager/c_api.h + ${INSTALL_DATA} ${WRKDIR}/lib_package/include/tensorflow/c/tf_attrtype.h ${STAGEDIR}${PREFIX}/include/tensorflow/c/tf_attrtype.h + ${INSTALL_DATA} ${WRKDIR}/lib_package/include/tensorflow/c/tf_datatype.h ${STAGEDIR}${PREFIX}/include/tensorflow/c/tf_datatype.h + ${INSTALL_DATA} ${WRKDIR}/lib_package/include/tensorflow/c/tf_status.h ${STAGEDIR}${PREFIX}/include/tensorflow/c/tf_status.h + ${INSTALL_DATA} ${WRKDIR}/lib_package/include/tensorflow/c/tf_tensor.h ${STAGEDIR}${PREFIX}/include/tensorflow/c/tf_tensor.h + ${INSTALL_PROGRAM} ${WRKDIR}/lib_package/lib/libtensorflow.so.${DISTVERSION} ${STAGEDIR}${PREFIX}/lib/libtensorflow.so.${DISTVERSION} + ${INSTALL_PROGRAM} ${WRKDIR}/lib_package/lib/libtensorflow_framework.so.${DISTVERSION} ${STAGEDIR}${PREFIX}/lib/libtensorflow_framework.so.${DISTVERSION} + @${RLN} ${STAGEDIR}${PREFIX}/lib/libtensorflow.so.${DISTVERSION} ${STAGEDIR}${PREFIX}/lib/libtensorflow.so.1 + @${RLN} ${STAGEDIR}${PREFIX}/lib/libtensorflow.so.1 ${STAGEDIR}${PREFIX}/lib/libtensorflow.so + @${RLN} ${STAGEDIR}${PREFIX}/lib/libtensorflow_framework.so.${DISTVERSION} ${STAGEDIR}${PREFIX}/lib/libtensorflow_framework.so.1 + @${RLN} ${STAGEDIR}${PREFIX}/lib/libtensorflow_framework.so.1 ${STAGEDIR}${PREFIX}/lib/libtensorflow_framework.so + +.include diff --git a/README.md b/README.md index 3468b0f..d815b7e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,19 @@ -# libtensorflow1-freebsd-port -FreeBSD port for Tensorflow 1.15 +FreeBSD port for Tensorflow 1.15 + +This provides an easy to use copy of *science/libtensorflow1* until the port is +committed to the repository. + +You can follow the port progress in [bug +260694](https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=260694) + +# Usage + +``` +cd /usr/ports/science +git clone https://github.com/psa/libtensorflow1-freebsd-port libtensorflow1 +cd libtensorflow1 +make package +``` + +This takes a long time to build (~90 minutes with 4 Xeon E31275 @ 3.40GHz +cores) and 8 GiB of RAM. diff --git a/distinfo b/distinfo new file mode 100644 index 0000000..46eaa7b --- /dev/null +++ b/distinfo @@ -0,0 +1,3 @@ +TIMESTAMP = 1640438990 +SHA256 (tensorflow-tensorflow-v1.15.5_GH0.tar.gz) = 4c4d23e311093ded2d2e287b18d7c45b07b5984ab88a1d2f91f8f13c886123db +SIZE (tensorflow-tensorflow-v1.15.5_GH0.tar.gz) = 46212258 diff --git a/files/patch-.bazelrc b/files/patch-.bazelrc new file mode 100644 index 0000000..a83c5c8 --- /dev/null +++ b/files/patch-.bazelrc @@ -0,0 +1,52 @@ +--- .bazelrc.orig 2021-01-04 20:18:42.000000000 +0000 ++++ .bazelrc 2021-12-25 17:26:39.181508000 +0000 +@@ -195,7 +195,7 @@ + build:c++1z --config=c++17 + + # Default paths for TF_SYSTEM_LIBS +-build --define=PREFIX=/usr ++build --define=PREFIX=/usr/local + build --define=LIBDIR=$(PREFIX)/lib + build --define=INCLUDEDIR=$(PREFIX)/include + +@@ -208,6 +208,9 @@ + # Instruction set optimizations + # TODO(gunan): Create a feature in toolchains for avx/avx2 to + # avoid having to define linux/win separately. ++build:avx_freebsd --copt=-mavx ++build:avx2_freebsd --copt=-mavx2 ++build:native_arch_freebsd --copt=-march=native + build:avx_linux --copt=-mavx + build:avx2_linux --copt=-mavx2 + build:native_arch_linux --copt=-march=native +@@ -295,6 +298,20 @@ + build:rbe_linux_py3 --python_path="/usr/bin/python3" + build:rbe_linux_py3 --repo_env=TF_PYTHON_CONFIG_REPO="@org_tensorflow//third_party/toolchains/preconfig/ubuntu16.04/py3" + ++build:rbe_cpu_freebsd --config=rbe_cpu_linux ++build:rbe_freebsd_cuda_nvcc --config=rbe_linux_cuda_nvcc ++common:rbe_gpu_freebsd --config=rbe_gpu_linux ++ ++build:rbe_freebsd_py2 --config=rbe_linux ++build:rbe_freebsd_py2 --repo_env=PYTHON_BIN_PATH="/usr/local/bin/python2" ++build:rbe_freebsd_py2 --python_path="/usr/local/bin/python2" ++build:rbe_freebsd_py2 --repo_env=TF_PYTHON_CONFIG_REPO="@org_tensorflow//third_party/toolchains/preconfig/ubuntu16.04/py" ++ ++build:rbe_freebsd_py3 --config=rbe_linux ++build:rbe_freebsd_py3 --repo_env=PYTHON_BIN_PATH="/usr/local/bin/python3" ++build:rbe_freebsd_py3 --python_path="/usr/local/bin/python3" ++build:rbe_freebsd_py3 --repo_env=TF_PYTHON_CONFIG_REPO="@org_tensorflow//third_party/toolchains/preconfig/ubuntu16.04/py3" ++ + build:rbe_win --config=rbe + build:rbe_win --crosstool_top="@org_tensorflow//third_party/toolchains/preconfig/win_1803/bazel_026:toolchain" + build:rbe_win --extra_execution_platforms="@org_tensorflow//third_party/toolchains/preconfig/win_1803:rbe_windows_1803" +@@ -334,6 +351,9 @@ + build:tensorflow_testing_rbe_linux --config=tensorflow_testing_rbe + build:tensorflow_testing_rbe_linux --config=rbe + build:tensorflow_testing_rbe_linux --config=rbe_linux ++ ++common:tensorflow_testing_rbe_freebsd --config=tensorflow_testing_rbe_linux ++build:tensorflow_testing_rbe_freebsd --config=tensorflow_testing_rbe_linux + + common:tensorflow_testing_rbe_win --remote_instance_name=projects/tensorflow-testing/instances/windows + build:tensorflow_testing_rbe_win --config=tensorflow_testing_rbe diff --git a/files/patch-configure.py b/files/patch-configure.py new file mode 100644 index 0000000..47cf07d --- /dev/null +++ b/files/patch-configure.py @@ -0,0 +1,11 @@ +--- configure.py.orig 2021-12-25 17:58:29.902610000 +0000 ++++ configure.py 2021-12-25 17:59:34.301740000 +0000 +@@ -475,7 +475,7 @@ + print('Cannot find bazel. Please install bazel.') + sys.exit(0) + curr_version = run_shell( +- ['bazel', '--batch', '--bazelrc=/dev/null', 'version']) ++ ['bazel', '--batch', '--output_user_root=/tmp/.bazel', '--bazelrc=/dev/null', 'version']) + + for line in curr_version.split('\n'): + if 'Build label: ' in line: diff --git a/pkg-descr b/pkg-descr new file mode 100644 index 0000000..7496c29 --- /dev/null +++ b/pkg-descr @@ -0,0 +1,9 @@ +TensorFlow is an end-to-end open source platform for machine learning. It has a +comprehensive, flexible ecosystem of tools, libraries, and community resources +that lets researchers push the state-of-the-art in ML and developers easily +build and deploy ML-powered applications. The TensorFlow C API is typically a +requirement of TensorFlow APIs in other languages such as Go and Rust. + +This is version 1 of the API, which is deprecated but still widely used. + +WWW: https://www.tensorflow.org/install/lang_c diff --git a/pkg-plist b/pkg-plist new file mode 100644 index 0000000..69ba1fc --- /dev/null +++ b/pkg-plist @@ -0,0 +1,16 @@ +@dir include/tensorflow +@dir include/tensorflow/c +@dir include/tensorflow/c/eager +include/tensorflow/c/c_api_experimental.h +include/tensorflow/c/c_api.h +include/tensorflow/c/eager/c_api.h +include/tensorflow/c/tf_attrtype.h +include/tensorflow/c/tf_datatype.h +include/tensorflow/c/tf_status.h +include/tensorflow/c/tf_tensor.h +lib/libtensorflow.so +lib/libtensorflow.so.1 +lib/libtensorflow.so.1.15.5 +lib/libtensorflow_framework.so +lib/libtensorflow_framework.so.1 +lib/libtensorflow_framework.so.1.15.5