tensorflow / tensorflow

An Open Source Machine Learning Framework for Everyone

Home Page:https://tensorflow.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Failed to build for iOS using Xcode 9.3: thread-local storage is not supported for the current target

sadlerjw opened this issue · comments

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): no
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): macOS High Sierra 10.13.3
  • TensorFlow installed from (source or binary): source
  • TensorFlow version (use command below): 1.6.0
  • Python version: 2.7.14
  • Bazel version (if compiling from source): 0.9.0
  • GCC/Compiler version (if compiling from source): Xcode 9.3: Apple LLVM version 9.1.0 (clang-902.0.39.1)
  • CUDA/cuDNN version: n/a
  • GPU model and memory: n/a
  • Exact command to reproduce: tensorflow/contrib/makefile/build_all_ios.sh -g /path/to/model.pb

Describe the problem

As of Xcode 9.3 (was working fine on 9.2), compiling TF for iOS using build_all_ios.sh fails, complaining that "thread-local storage is not supported for the current target". This is related to #12573, which introduced the thread_local attribute for iOS builds.

Source code / logs

$ tensorflow/contrib/makefile/build_all_ios.sh -g /path/to/model.pb
[...]
gcc --std=c++11 -DIS_SLIM_BUILD -fno-exceptions -DNDEBUG -O3 -DANDROID_TYPES=__ANDROID_TYPES_FULL__ -DSELECTIVE_REGISTRATION -DSUPPORT_SELECTIVE_REGISTRATION -mios-simulator-version-min=9.0 -arch i386 -mno-sse -fembed-bitcode -D__thread=thread_local -DUSE_GEMM_FOR_CONV -Wno-c++11-narrowing -DTF_LEAN_BINARY -D__ANDROID_TYPES_FULL__ -fno-exceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.3.sdk -MT /Users/json/everalbum/ios-sdk/submodules/tensorflow/tensorflow/contrib/makefile/gen/obj/ios_I386/tensorflow/core/common_runtime/local_device.o -MMD -MP -MF /Users/json/everalbum/ios-sdk/submodules/tensorflow/tensorflow/contrib/makefile/gen/dep/ios_I386//tensorflow/core/common_runtime/local_device.Td -I. -I/Users/json/everalbum/ios-sdk/submodules/tensorflow/tensorflow/contrib/makefile/downloads/ -I/Users/json/everalbum/ios-sdk/submodules/tensorflow/tensorflow/contrib/makefile/downloads/eigen -I/Users/json/everalbum/ios-sdk/submodules/tensorflow/tensorflow/contrib/makefile/downloads/gemmlowp -I/Users/json/everalbum/ios-sdk/submodules/tensorflow/tensorflow/contrib/makefile/downloads/nsync/public -I/Users/json/everalbum/ios-sdk/submodules/tensorflow/tensorflow/contrib/makefile/downloads/fft2d -I/Users/json/everalbum/ios-sdk/submodules/tensorflow/tensorflow/contrib/makefile/gen/proto/ -I/Users/json/everalbum/ios-sdk/submodules/tensorflow/tensorflow/contrib/makefile/gen/proto_text/ -I/Users/json/everalbum/ios-sdk/submodules/tensorflow/tensorflow/contrib/makefile/gen/protobuf-host/include -I/usr/local/include -c tensorflow/core/common_runtime/local_device.cc -o /Users/json/everalbum/ios-sdk/submodules/tensorflow/tensorflow/contrib/makefile/gen/obj/ios_I386/tensorflow/core/common_runtime/local_device.o
In file included from tensorflow/core/common_runtime/local_device.cc:18:
In file included from ./tensorflow/core/common_runtime/local_device.h:19:
In file included from ./tensorflow/core/common_runtime/device.h:35:
In file included from ./tensorflow/core/framework/allocator.h:23:
In file included from ./tensorflow/core/framework/numeric_types.h:21:
In file included from ./third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1:
In file included from /Users/json/everalbum/ios-sdk/submodules/tensorflow/tensorflow/contrib/makefile/downloads/eigen/unsupported/Eigen/CXX11/Tensor:79:
In file included from /Users/json/everalbum/ios-sdk/submodules/tensorflow/tensorflow/contrib/makefile/downloads/eigen/unsupported/Eigen/CXX11/ThreadPool:58:
/Users/json/everalbum/ios-sdk/submodules/tensorflow/tensorflow/contrib/makefile/downloads/eigen/unsupported/Eigen/CXX11/src/ThreadPool/SimpleThreadPool.h:153:5: error:
      thread-local storage is not supported for the current target
    EIGEN_THREAD_LOCAL PerThread per_thread;
    ^
/Users/json/everalbum/ios-sdk/submodules/tensorflow/tensorflow/contrib/makefile/downloads/eigen/unsupported/Eigen/CXX11/src/ThreadPool/ThreadLocal.h:15:35: note:
      expanded from macro 'EIGEN_THREAD_LOCAL'
#define EIGEN_THREAD_LOCAL static __thread
                                  ^
<command line>:6:18: note: expanded from here
#define __thread thread_local

@petewarden here's an iOS build issue potentially related to a change you made.

I changed -D__thread=thread_local \ to -D__thread= \ in tensorflow/contrib/makefile/Makefile (for the i386 architecture only) and that's an okay workaround for now. It (probably) re-introduces the problem that #12573 solved for that architecture, but at least for my use that's acceptable until this gets a proper solution.

+1
Any update on this ?

@sadlerjw I am working on Mac sierra 10.13.5 (17F77) , and what I did is here:
checked out tensorflow 1.9.0-rc1
did export ANDROID_TYPES="-D__ANDROID_TYPES_FULL__"
and then launched the script tensorflow/contrib/makefile/buils_all_ios.sh .

On building stage for the arch i386 I got the error:

tensorflow/tensorflow/contrib/makefile/downloads/eigen/unsupported/Eigen/CXX11/src/ThreadPool/SimpleThreadPool.h:153:5: error: 
      thread-local storage is not supported for the current target
    EIGEN_THREAD_LOCAL PerThread per_thread;
    ^
/pj/tensorflow/tensorflow/contrib/makefile/downloads/eigen/unsupported/Eigen/CXX11/src/ThreadPool/ThreadLocal.h:15:35: note: 
      expanded from macro 'EIGEN_THREAD_LOCAL'
#define EIGEN_THREAD_LOCAL static __thread
                                  ^
<command line>:3:18: note: expanded from here
#define __thread thread_local
                 ^
In file included from tensorflow/core/common_runtime/local_device.cc:18:
In file included from ./tensorflow/core/common_runtime/local_device.h:19:
In file included from ./tensorflow/core/common_runtime/device.h:35:
In file included from ./tensorflow/core/framework/allocator.h:23:
In file included from ./tensorflow/core/framework/numeric_types.h:20:
In file included from ./third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1:
In file included from /pj/tensorflow/tensorflow/contrib/makefile/downloads/eigen/unsupported/Eigen/CXX11/Tensor:79:
In file included from /pj/tensorflow/tensorflow/contrib/makefile/downloads/eigen/unsupported/Eigen/CXX11/ThreadPool:59:
/pj/tensorflow/tensorflow/contrib/makefile/downloads/eigen/unsupported/Eigen/CXX11/src/ThreadPool/NonBlockingThreadPool.h:326:5: error: 
      thread-local storage is not supported for the current target
    EIGEN_THREAD_LOCAL PerThread per_thread_;
    ^
/pj/tensorflow/tensorflow/contrib/makefile/downloads/eigen/unsupported/Eigen/CXX11/src/ThreadPool/ThreadLocal.h:15:35: note: 
      expanded from macro 'EIGEN_THREAD_LOCAL'
#define EIGEN_THREAD_LOCAL static __thread
                                  ^
<command line>:3:18: note: expanded from here
#define __thread thread_local
                 ^
2 errors generated.
make: *** [pj/tensorflow/tensorflow/contrib/makefile/gen/obj/ios_I386/tensorflow/core/common_runtime/local_device.o] Error 1
+ '[' 2 -ne 0 ']'
+ echo 'i386 compilation failed.'
i386 compilation failed.
+ exit 1

I'm up for sadlerjw's fix because when most people use this library i386 is more about just making sure one of the simulators compiles, but it is unnecessary for testing or production, just that it passes automated testing and whatnot.

sadlerjw's fix does not work for tensorflow 1.10 + xcode 9.4.1. It fixed for Eigen, but there is another similar error:
tensorflow/core/util/work_sharder.cc:23:23: error: thread-local storage is not supported for the current target

@sadlerjw 's fix doesn't seem to work anymore on TF 1.10. Getting the same error like @robinqhuang

Specifically it's line 23 in tensorflow/tensorflow/core/util/work_sharder.cc

/* ABSL_CONST_INIT */ thread_local int per_thread_max_parallism = 1000000;

I fixed it by replacing thread_local with __thread since it is defined as empty in @sadlerjw 's fix for i386 and that's what we want

/* ABSL_CONST_INIT */ __thread int per_thread_max_parallism = 1000000;

I had the same problem as @eaigner on TF 1.11, and used the same workaround

Thanks @eaigner for the workaround. I think it was resolved. Please open a new ticket if you see a similar issue. Thanks!

I am facing a similar issue. I tried both @eaigner and @sadlerjw solutions but I am still getting the error. Anyone else facing same problem?

I had the same issue. After so many trials and continuous errors, I've finally generated the framework simply by updating
TFL_MINIMUM_OS_VERSION = "12.0" from "9.0" in path 'tensorflow/lite/ios/ios.bzl' file.