How to compile a demo running TensorFlow

Source: Internet
Author: User

1. Install the compilation tool Bazel, you can refer to the official tutorial.
https://docs.bazel.build/versions/master/install-ubuntu.html
2. Configure the TensorFlow compilation environment
Run the Configure file under the TensorFlow directory and configure it according to your environment. For example, the following:

**root@fly-virtual-machine:/home/share/tensorflow#./configure** Please specify the location of Python. [Default Is/root/anaconda3/bin//python]:/root/anaconda3/bin/python **do you wish to use Jemalloc as the malloc implement ation? (Linux only) [y/n] y** Jemalloc enabled on Linux **do your wish to builds TensorFlow with Google Cloud Platform? [y/n] n** No Google Cloud Platform support'll is enabled for TensorFlow **do your wish to builds TensorFlow with Hadoop Fi Le System support? [y/n] n** No Hadoop File System support'll be enabled for TensorFlow **do your wish to builds tensorflow with the XLA just -in-time compiler (experimental)? [y/n] n** No XLA JIT support'll is enabled for TensorFlow Found possible Python library paths: **/root/anaconda3/lib/p  ython3.5/site-packages** please input the desired Python library path to use. The Default is [/root/anaconda3/lib/python3.5/site-packages] Using python library path:/root/anaconda3/lib/python3.5/ Site-packages do your wish to build TensorFlow with o** key content **pencl support? [y/n] N No OpenCL support will be enable** key content **d for TensorFlow does you wish to builds TensorFlow with CUDA support? [y/n] N No CUDA support is enabled for TensorFlow Configuration finished info:starting? .
Consider using--expunge_async if the takes more than several minutes.
............... Building:no Action running Building:no action running Building:no action running Building:no action running:
 No action running Building:no action running Building:no action running Building:no action running
Compiling TensorFlow Dynamic Libraries
According to Bazel syntax rules, find the corresponding build file, the path is tensorflow/build. Can see
Cc_binary (
    name = "Libtensorflow_cc.so",
    linkshared = 1,
    deps = [
        "//tensorflow/c:c_api",
        "// Tensorflow/cc:cc_ops ","
        //tensorflow/core:tensorflow ",
    ],

Under the current Tensorflow/build directory to perform Bazel build:libtensorflow.so, the operation effect is as follows:

Compile time about 2000 seconds, look at the computer performance, this compilation uses dual core four threads, 4GB memory.
When the execution is complete, the following directories are generated in the directory where the workspace file resides: Bazel-bin, Bazel-genfiles,bazel-out, Bazel-tensorflow-master, and Bazel-testlogs. Enter the Bazel-out/local-py3-fastbuild/bin/tensorflow directory to see the libtensorflow_cc.so Dynamic Library.
4. Compile demo, take TENSORFLOW\CC as example, compile C + + Demo
Also find the build file in the directory and find the Bazel definition to compile the demo

Tf_cc_test (
    name = "Client_client_session_test",
    srcs = ["client/client_session_test.cc"],
    deps = [
        ": Cc_ops",
        ": client_session",
        "//tensorflow/core:all_kernels",
        "//tensorflow/core:core_cpu_ Internal ","
        //tensorflow/core:framework ",
        "//tensorflow/core:lib ","
        //tensorflow/core:tensorflow ",
        "//tensorflow/core:test",
        "//tensorflow/core:test_main",
        "//tensorflow/core:testlib",
    ],

Executing Bazel build:client_client_session_test at the build directory location, the resulting path is as follows: tensorflow-master/bazel-out/local-py3-fastbuild/ BIN/TENSORFLOW/CC, the path below has executable program client_client_session_test, the result of the successful operation is as follows

Root@fly-virtual-machine:/home/fly/tensorpro/tensorflow-master/tensorflow-master/bazel-out/local-py3-fastbuild  /bin/tensorflow/cc#./client_client_session_test add by Zgh, Running Main () from test_main.cc [==========] Running 4 tests
From the 1 test case. [----------]
Global test environment set-up. [----------] 4 tests from Clientsessiontest [RUN] clientsessiontest.basic W tensorflow/core/platform/cpu_feature_gu ARD.CC:45] The TensorFlow library wasn ' t compiled to use SSE4.2 instructions, but this are available on your machine and
Could speed up CPU computations. W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn ' t compiled to use AVX instructions, but th
ESE are available on your machine and could the up CPU speed. W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn ' t compiled to use FMA instructions, but th
ESE are available on your machine and could the up CPU speed. [OK] Clientsessiontest.basic (184 MS) [Run] clientsessiontest.feed [OK] Clientsessiontest.feed (ms) [run] Clientsessiontest.extend [OK]  Clientsessiontest.extend (MS) [RUN] clientsessiontest.multithreaded [OK] clientsessiontest.multithreaded
(MS) [----------] 4 tests from clientsessiontest (273 ms total) [----------] Global test Environment Tear-down [==========] 4 Tests from 1 Test case ran.
(274 ms Total)
 [Passed] 4 tests.

The

Supplemental Bazel Purge command is: Bazel clean

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.