tensorflow: Errors when building iOS binaries with selective registration
The header file generated by print_selective_registration_header.py makes use of strcmp, which causes an error when compiling TensorFlow for iOS with selective registration enabled (-DSELECTIVE_REGISTRATION)
Apparently this was fixed in a commit back in October but that commit was reverted the same day for some reason.
I’ve tried building the tool from the commit of TensorFlow that has the fix, but ./configure fails for me on that version (missing targets & zlib download). I’ve also tried replacing calls to strcmp with a constexpr variant, but I’m not much help with C++ and couldn’t get anything to work there.
This prevents me from compiling a slimmed down TensorFlow binary for iOS.
You must complete this information or else your issue will be closed
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow)?: No, just following the instructions in print_selective_registration_header.py and selective_registration.h
- TensorFlow installed from (source or binary)?: Source
- TensorFlow version: master (45115c0a985815feef3a97a13d6b082997b38e5d)
- Bazel version (if compiling from source): 0.4.5
- CUDA/cuDNN version: N/A
- GPU Model and Memory: N/A
- Exact command to reproduce:
$ bazel build tensorflow/python/tools/print_selective_registration_header $ bazel-bin/tensorflow/python/tools/print_selective_registration_header \ --graphs=graph.pb > tensorflow/core/framework/ops_to_register.h $ tensorflow/contrib/makefile/compile_ios_tensorflow.sh "-Os -DSELECTIVE_REGISTRATION"
Source Code / Logs
Here is the relevant log output on the last command:
In file included from ./tensorflow/core/framework/selective_registration.h:46:
./tensorflow/core/framework/ops_to_register.h:4:23: error: constexpr function never produces a
constant expression [-Winvalid-constexpr]
constexpr inline bool ShouldRegisterOp(const char op[]) {
^
./tensorflow/core/framework/ops_to_register.h:6:10: note: non-constexpr function 'strcmp' cannot
be used in a constant expression
|| (strcmp(op, "Add") == 0)
^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.2.sdk/usr/include/string.h:77:6: note:
declared here
int strcmp(const char *__s1, const char *__s2);
^
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 23 (13 by maintainers)
Alright @cwhipkey it worked! The full solution I used is as follows:
strcmpwithstrcmpcIn my case, the resulting libtensorflow-core.a is 45% smaller, the universal .ipa is 6.1MB lighter, and the unzipped payload is 19.5MB lighter. (Of course, your mileage may vary depending on the graph you are using selective registration on.) Thanks everyone!
https://github.com/tensorflow/tensorflow/commit/f333979e0d8625bca09c96478503c896fda24f25
Yes, it looks like it’s not in 1.2 afaict: https://github.com/tensorflow/tensorflow/blob/r1.2/tensorflow/python/tools/print_selective_registration_header_test.py