-
Notifications
You must be signed in to change notification settings - Fork 74.4k
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
Packaged TensorFlow C++ library for bazel-independent use #2412
Comments
The |
Yes, that is what I need. It would be nice if this was documented somewhere too! |
could you give a more specific example? suppose I have this file, and I want to compile it with tensorflow with g++ directly (no bazel, not in tensorflow"s repo), how should I do this?? |
@MisayaZ That depends on what you"re building. The most reliable interface is the C API, which you can include with |
@asimshankar I think we can call this resolved once c distributable is ready, right? |
Yes and no :) FWIW, for using the C API you need just |
Hi, I"m trying to play around with the C API. After running dyld: Library not loaded: bazel-out/local-py3-opt/bin/tensorflow/libtensorflow.so
Referenced from: /Users/inflation/workspace/link_test/./a.out
Reason: image not found I must put the library in the same folder structure as it said to run it without error. So what is wrong here? |
Maybe you should set
DYLD_LIBRARY_PATH ?
---------- Forwarded message ----------
From: Aaron Hu <[email protected]>
Date: Sun, Feb 5, 2017 at 12:30 PM
Subject: Re: [tensorflow/tensorflow] Tensorflow as C++ library (#2412)
To: tensorflow/tensorflow <[email protected]>
Cc: cgao3 <[email protected]>, Mention <[email protected]>
Hi, I"m trying to play around with the C API. After running bazel build
//tensorflow:libtensorflow.so
and copy the shared library into another folder, I successfully compiled
and linked a small example. But when I tried to run it, it showed something
like this:
dyld: Library not loaded:
bazel-out/local-py3-opt/bin/tensorflow/libtensorflow.so
Referenced from: /Users/inflation/workspace/link_test/./a.out
Reason: image not found
I must put the library in the same folder structure as it said to run it
without error. So what is wrong here?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2412 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/APhNiYAGXNVHAPTjpal5Ru-z1r4eg1TOks5rZiNIgaJpZM4Ig4U3>
.
|
Seems like you"re using OS X.
Hope that helps |
@asimshankar Thanks a lot! |
@mrry bit off topic, what would be needed to build it as a lib for windows and is there a plan for this do you know? |
@acomarce Two things, really:
Part 1 will probably be easier if we focus on the C API, which has been designed as a stable API for consumption by many different projects, and has stronger versioning guarantees. The C++ API is more sprawling, and it would require invasive changes to set up the appropriate annotations. (I was just chatting with @guschmue, who observed that CMake has a newish feature for generating these definitions without code modification, but the resulting DLL ends up with more than the maximum 65536 symbols exported....) I"m not aware of anyone who is working on this right now. Contributions would be welcome! |
The cmake support for this is called CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS. In theory this would be perfect but it adds everything public to the .def which the linker is unhappy about (just too much). Doing the c-api with dllexport is fine (I have a version of this) but I think even to do an user_op to be loaded with tf.load_library() you need some of the c++ api and the doc shows a lot of classes for the c++ api: https://www.tensorflow.org/api_docs/cc/. |
Maybe let me double check: is the c++ api one needs to support this |
@guschmue I think it should be the later. |
i made the changes in my local tree for https://github.com/tensorflow/tensorflow/tree/master/tensorflow/g3doc/api_docs/cc - around 130 methods/classes. With that I got the c# bindings to work. Going to try if I can get tensorflow/user_ops to work with that. |
@guschmue Do you think the project would ever consider explicitly exposing just the public API for all platforms? Would it be fair to say this is currently implicit based on the doc generation process? Looks like GCC 4 supports something similar to __declspec(dllexport) - http://gcc.gnu.org/wiki/Visibility. Although, the caveats on that page regarding exceptions sound messy, so perhaps this has already been discussed and decided against... |
Yes - for windows this would be perfect. But its a lot of classes/files to be touched and its hard for me as external contributor to decide what is long term public and what is private on the tensorflow api; I think a tensorflow team member would need to go over the entire api and make that call. |
For the c# binding: I actually got https://github.com/migueldeicaza/tensorflowsharp to work with my changes. The "tensorflow.dll" is in the python wheel, only that it is called _pywrap_tensorflow.pyd. |
For the public client API, it should be relatively easy to make a DLL that exports just the symbols in The All of which is a long-winded way of saying (in my opinion) the de facto public API for the framework (i.e. to support custom ops) is too unwieldy, and I don"t think we should exhaustively trace down every symbol that needs to be exported. It would be better to spend time defining a clean, self-contained, and possibly versioned API for creating extension modules, probably exporting C bindings like the client API, and then we could have more confidence about modules working across different builds of TensorFlow. This would be a big undertaking though.... |
Totally agree. _pywrap_tensorflow.pyd includes a ton more than the public c api and exporting the c api only would be easy (+ maybe tensorflow::ops?). We added the TF_EXPORT define so we could just annotate the c api with TF_EXPORT. |
This is still an open issue. Even when creating the libfile-file by:
I cannot build the file #include <tensorflow/core/framework/tensor.pb.h>
int main(int argc, char const *argv[])
{
tensorflow::TensorProto tensor;
return 0;
} because it misses some important parts:
This basically prevents to build a c++ project with tensorflow as dependencies without messing files around in the official repo. |
@PatWie : |
@mrry @asimshankar : What would be the steps to build and link to TF as a static C++ library then? Or would that not be a feasible task outside of |
@skye is looking into a distribution for the C++ library (i.e., library + all required header files). If you need a static library, we"re currently blocked on bazelbuild/bazel#1920 |
fixes: include/tensorflow/core/platform/default/mutex.h:25:22: fatal error: nsync_cv.h: No such file or directory https://travis-ci.org/rwth-i6/returnn/jobs/296165271 tensorflow/tensorflow#2412
Not official, but I provide C++ libraries and headers for use outside bazel, and build instructions too (mainly to be used with openFrameworks, but not limited to). |
Hey @memo ;) Out of curiosity, have you had reports of linker issues with ofxMSATensorFlow on OS X with TF 1.3 and TF 1.4? Ive been getting the following linker issue in my Synopsis project which is basically your instructions the wiki you linked almost verbatim: Trying to isolate - but I cant quite deduce where my issues lies. |
Hey @vade, I haven"t built on OSX since r1.0 I"m afraid. Linux only now. Did you update the headers? This is a bit of a dirty solution, but right now (I think because the C++ API is changing), you need to change headers for each lib (not always, but sometimes). So it might be that if you"re using the 1.2 headers, it"s not finding the implementations in the 1.3 lib? This script updates the headers Otherwise I"m not sure what it might be. |
Memo- thanks. I had done that before, but had a different compiler error (Nsync issue as noted here: But the new fixes in that thread resolved the issue. Much appreciated! |
@memo sir does the source code https://github.com/memo/ofxMSATensorFlow.git has GPU support ? |
I"ve written a small guide for C++ CMake TensorFlow on Mac: https://medium.com/@TomPJacobs/c-tensorflow-a-journey-bdecbbdd0f65 |
@vade @kikirizki |
Closing the issue. There"s a lot of discussion here, but we already release shared objects which are usable without bazel on many platforms. Please file new specific issues if this is not enough. |
Hi @alextp Maybe a naive question: where do we get the released shared objects you mentioned? I can get |
@prclibo You have to build tensorflow from source for that. |
For those who like Docker, the tensorflow_cc project provides images with prebuilt TensorFlow C++ API. |
I have success compile the libtensorflow_cc.so, and managed to complie my release version of classification so. However, if I tried to compile my demo to use the so file in release mode, it failed with many undefined link errrors. If I tried in the default debug mode, I succeed. The log of errors is:
|
I can also recommend FloopCZ"s project, especially if you want to use Tensorflow inference with GPU. Those who wants a packaged version, I packaged both the C and C++ API in my project and I release Debian packages time to time. The disadvantage of my project that it is based on contrib/makefiles therefore it is CPU-only. |
@kikirizki |
Guys i tried to build libtensorflow.so using bazel and tried to import it in my qt-based project but getting the following error. |
If you guys have same demand on Windows, I have asked a question which may help you to some extent. |
@guikarist : Ok :) |
I"ve just published my old code and some prebuilt stuff here: https://github.com/hluu11/SimpleTF-CPP |
Hey all, visitor from the future here who also needed/needs exactly this build rule. Looks like this is still only documented in this issue---I"d be happy to put a note in the docs on building from source about this, but I haven"t contributed to TensorFlow before*, so perhaps if somebody who"s a known contributor could add that in, that would be awesome. *If this isn"t likely to be an issue, I can do that |
Doc PRs are super easy for us to approve, and might take you just as long
to do that as to write the issue in the first place.
Thanks for bringing this up!
…On Wed, Jun 3, 2020 at 10:14 AM Zane Jakobs ***@***.***> wrote:
The "//tensorflow:libtensorflow.so" bazel target enables you to build a
standalone TensorFlow library that you can dynamically link into your other
project. Would that be sufficient?
Visitor from the future here --
Yes, that is what I need. It would be nice if this was documented
somewhere too!
Hey all, visitor from the future here who also needed/needs exactly this
build rule. Looks like this is still only documented in this issue---I"d be
happy to put a note in the docs on building from source about this, but I
haven"t contributed to TensorFlow before*, so perhaps if somebody who"s a
known contributor could add that in, that would be awesome.
*If this isn"t likely to be an issue, I can do that
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2412 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAABHRIVNWGV6EB7XGIWGODRU2AGBANCNFSM4CEDQU3Q>
.
--
- Alex
|
Currently, building a C++ application in tensorflow requires creating a project in the tensorflow source tree and compiling with bazel. In my case I would like to use tensorflow in a (fairly large) existing application with an existing build system that would be difficult to port to bazel. The solution to me seems to be exposing tensorflow as a library that can be linked with.
The text was updated successfully, but these errors were encountered: