From 1f16fe2b01324ce7e4dd5dbbab4157d48bc9db28 Mon Sep 17 00:00:00 2001 From: Gleb Popov <6yearold@gmail.com> Date: Mon, 13 May 2019 21:14:31 +0400 Subject: [PATCH 1/6] Pass "-lexecinfo" for some TensorFlow targets on FreeBSD. --- tensorflow/BUILD | 4 ++++ tensorflow/compiler/xla/BUILD | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/tensorflow/BUILD b/tensorflow/BUILD index a04ddf9f8a1..d185eb32ae1 100644 --- a/tensorflow/BUILD +++ b/tensorflow/BUILD @@ -497,6 +497,10 @@ tf_cc_shared_object( linkopts = select({ "//tensorflow:macos": [], "//tensorflow:windows": [], + "//tensorflow:freebsd": [ + "-Wl,--version-script,$(location //tensorflow:tf_framework_version_script.lds)", + "-lexecinfo" + ], "//conditions:default": [ "-Wl,--version-script,$(location //tensorflow:tf_framework_version_script.lds)", ], diff --git a/tensorflow/compiler/xla/BUILD b/tensorflow/compiler/xla/BUILD index 91f33ff914e..06b66a2910f 100644 --- a/tensorflow/compiler/xla/BUILD +++ b/tensorflow/compiler/xla/BUILD @@ -165,6 +165,10 @@ cc_library( "statusor.h", ], visibility = ["//visibility:public"], + linkopts = select({ + "@org_tensorflow//tensorflow:freebsd": ["-lexecinfo"], + "//conditions:default": [] + }), deps = [ ":status", "//tensorflow/stream_executor/lib", From 4295de104c0d4fcde5c2dc1523498b68b2043a57 Mon Sep 17 00:00:00 2001 From: Gleb Popov <6yearold@gmail.com> Date: Mon, 13 May 2019 21:15:13 +0400 Subject: [PATCH 2/6] Fix llvm.bzl for FreeBSD: - Set CMake variables - Link needed libraries --- third_party/llvm/llvm.bzl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/third_party/llvm/llvm.bzl b/third_party/llvm/llvm.bzl index 2009c991a51..1d2cbdac122 100644 --- a/third_party/llvm/llvm.bzl +++ b/third_party/llvm/llvm.bzl @@ -247,6 +247,12 @@ linux_cmake_vars = { "HAVE_FUTIMENS": 1, } +# CMake variables specific to the FreeBSD platform +freebsd_cmake_vars = { + "HAVE_MALLOC_H": 1, + "HAVE_LINK_H": 1, +} + # CMake variables specific to the Darwin (Mac OS X) platform. darwin_cmake_vars = { "HAVE_MALLOC_MALLOC_H": 1, @@ -314,6 +320,13 @@ llvm_all_cmake_vars = select({ win32_cmake_vars, ), ), + "@org_tensorflow//tensorflow:freebsd": cmake_var_string( + _dict_add( + cmake_vars, + llvm_target_cmake_vars("X86", "x86_64-unknown-freebsd"), + posix_cmake_vars + ), + ), "//conditions:default": cmake_var_string( _dict_add( cmake_vars, @@ -326,6 +339,7 @@ llvm_all_cmake_vars = select({ llvm_linkopts = select({ "@org_tensorflow//tensorflow:windows": [], + "@org_tensorflow//tensorflow:freebsd": ["-ldl", "-lm", "-lpthread", "-lexecinfo"], "//conditions:default": ["-ldl", "-lm", "-lpthread"], }) From cbea2355ec08186643f4369199b60fce49c74f08 Mon Sep 17 00:00:00 2001 From: Gleb Popov <6yearold@gmail.com> Date: Mon, 13 May 2019 21:16:06 +0400 Subject: [PATCH 3/6] Fix ROCm build on FreeBSD. --- third_party/gpus/rocm_configure.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/gpus/rocm_configure.bzl b/third_party/gpus/rocm_configure.bzl index 758cce88eec..0b8f7a939b2 100644 --- a/third_party/gpus/rocm_configure.bzl +++ b/third_party/gpus/rocm_configure.bzl @@ -301,7 +301,7 @@ def _lib_name(lib, cpu_value, version = "", static = False): Returns: The platform-specific name of the library. """ - if cpu_value in ("Linux"): + if cpu_value in ("Linux", "FreeBSD"): if static: return "lib%s.a" % lib else: From 5bada68367cea484ca0f4a8bb352266a1296b66f Mon Sep 17 00:00:00 2001 From: Gleb Popov <6yearold@gmail.com> Date: Mon, 13 May 2019 21:16:44 +0400 Subject: [PATCH 4/6] Fix AWS build on FreeBSD. --- third_party/aws/BUILD.bazel | 3 +++ 1 file changed, 3 insertions(+) diff --git a/third_party/aws/BUILD.bazel b/third_party/aws/BUILD.bazel index 26ff2282fd0..5d7e39fcc26 100644 --- a/third_party/aws/BUILD.bazel +++ b/third_party/aws/BUILD.bazel @@ -27,6 +27,9 @@ cc_library( "@org_tensorflow//tensorflow:raspberry_pi_armeabi": glob([ "aws-cpp-sdk-core/source/platform/linux-shared/*.cpp", ]), + "@org_tensorflow//tensorflow:freebsd": glob([ + "aws-cpp-sdk-core/source/platform/linux-shared/*.cpp", + ]), "//conditions:default": [], }) + glob([ "aws-cpp-sdk-core/include/**/*.h", From 92188e34765da5e1e79fdae56ee6f20d24fe9f30 Mon Sep 17 00:00:00 2001 From: Gleb Popov <6yearold@gmail.com> Date: Mon, 13 May 2019 21:17:11 +0400 Subject: [PATCH 5/6] Fix compilation of some C++ code on FreeBSD. --- .../kernels/client/ignite_plain_client_unix.cc | 1 + tensorflow/core/platform/cloud/gcs_dns_cache.cc | 2 ++ tensorflow/core/platform/posix/env.cc | 14 ++++++++++---- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/tensorflow/contrib/ignite/kernels/client/ignite_plain_client_unix.cc b/tensorflow/contrib/ignite/kernels/client/ignite_plain_client_unix.cc index 54efb5b6176..0050a51138c 100644 --- a/tensorflow/contrib/ignite/kernels/client/ignite_plain_client_unix.cc +++ b/tensorflow/contrib/ignite/kernels/client/ignite_plain_client_unix.cc @@ -16,6 +16,7 @@ limitations under the License. #include "tensorflow/contrib/ignite/kernels/client/ignite_plain_client.h" #include +#include #include #include #include diff --git a/tensorflow/core/platform/cloud/gcs_dns_cache.cc b/tensorflow/core/platform/cloud/gcs_dns_cache.cc index f2e64662a92..13187a4a241 100644 --- a/tensorflow/core/platform/cloud/gcs_dns_cache.cc +++ b/tensorflow/core/platform/cloud/gcs_dns_cache.cc @@ -16,6 +16,8 @@ limitations under the License. #include "tensorflow/core/platform/cloud/gcs_dns_cache.h" #ifndef _WIN32 #include +#include +#include #include #else #include diff --git a/tensorflow/core/platform/posix/env.cc b/tensorflow/core/platform/posix/env.cc index 2700a269c4d..ba2a979df16 100644 --- a/tensorflow/core/platform/posix/env.cc +++ b/tensorflow/core/platform/posix/env.cc @@ -25,6 +25,10 @@ limitations under the License. #include #include +#ifdef __FreeBSD__ +#include +#endif + #include #include @@ -110,10 +114,7 @@ class PosixEnv : public Env { pthread_threadid_np(nullptr, &tid64); return static_cast(tid64); #elif defined(__FreeBSD__) - // Has to be casted to long first, else this error appears: - // static_cast from 'pthread_t' (aka 'pthread *') to 'int32' (aka 'int') - // is not allowed - return static_cast(static_cast(pthread_self())); + return pthread_getthreadid_np(); #else return static_cast(pthread_self()); #endif @@ -133,7 +134,12 @@ class PosixEnv : public Env { return false; #else char buf[100]; +#ifdef __FreeBSD__ + int res = 0; + pthread_get_name_np(pthread_self(), buf, static_cast(100)); +#else int res = pthread_getname_np(pthread_self(), buf, static_cast(100)); +#endif if (res != 0) { return false; } From 663d93c92593fa256e039abdc8cb0307c1a87164 Mon Sep 17 00:00:00 2001 From: Gleb Popov <6yearold@gmail.com> Date: Mon, 13 May 2019 21:17:53 +0400 Subject: [PATCH 6/6] Add case for FreeBSD. --- tensorflow/lite/kernels/internal/BUILD | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tensorflow/lite/kernels/internal/BUILD b/tensorflow/lite/kernels/internal/BUILD index 0f363f06a8c..ee83643416d 100644 --- a/tensorflow/lite/kernels/internal/BUILD +++ b/tensorflow/lite/kernels/internal/BUILD @@ -605,6 +605,9 @@ cc_library( ":darwin_x86_64": [ ":neon_tensor_utils", ], + ":freebsd": [ + ":neon_tensor_utils", + ], "//conditions:default": [ ":portable_tensor_utils", ],