{"id":12,"date":"2018-04-11T09:54:21","date_gmt":"2018-04-11T09:54:21","guid":{"rendered":"http:\/\/eddedmondson.co.uk\/blog\/?p=12"},"modified":"2018-11-05T11:04:15","modified_gmt":"2018-11-05T11:04:15","slug":"installing-tensorflow-1-7-0-on-centos-6","status":"publish","type":"post","link":"https:\/\/eddedmondson.co.uk\/blog\/index.php\/2018\/04\/11\/installing-tensorflow-1-7-0-on-centos-6\/","title":{"rendered":"Installing Tensorflow 1.7.0 on CentOS 6"},"content":{"rendered":"<p>Tensorflow is a continuous pain to get working on any Linux other than a recent Ubuntu. Unfortunately most of my production systems are on some variant of CentOS 6&#8230;<\/p>\n<p>Here&#8217;s what I currently do to get Tensorflow 1.7.0 working on it. These instructions are brief and not absolutely step by step, but you can probably figure out what to do from them, and certainly I should be able to look back at these notes and figure out what I was doing. I&#8217;m not going to do things like explicitly tell you when to cd or mkdir a new place to drop things in. There aren&#8217;t proper patchfiles. These are scribbled notes as I went along getting bits from various links around the place.<\/p>\n<ol>\n<li>Download source and install to some\u00a0<span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">&#8211;prefix=\/location <\/span>a recent binutils &#8211; 2.30 at time of writing<\/li>\n<li>Download source and install to some <span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">&#8211;prefix=\/location<\/span> a recent GCC (I used 7.3.0 initially but CUDA doesn&#8217;t like GCC 6 or later, so you probably want a v5.4.0 compiler, but not v5.5 or later as that breaks stuff too! v4.9.4 didn&#8217;t work so just go with v5.4.0!) &#8211; note also there&#8217;s some references below to 7.3.0 which I&#8217;m too lazy to fix.<\/li>\n<li><span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">yum install java-1.8.0-openjdk-devel<\/span><\/li>\n<li>Grab a suitably new Python (I used an Anaconda installation)<\/li>\n<li>Get bazel (I used v0.11.1) &#8211; make sure it&#8217;s the -dist.zip download<br \/>\nUnpack bazel<\/li>\n<li>Patch bazel &#8211; in <span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">tools\/cpp\/unix_cc_configure.bzl<\/span> comment out<br \/>\n<span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">&#8220;-B\/usr\/bin&#8221;,<\/span><br \/>\n&#8211; it&#8217;ll be prefixed by a comment like<br \/>\n<span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\"># Always have -B\/usr\/bin, see https:\/\/github.com\/bazelbuild\/bazel\/issues\/760.<\/span><br \/>\nwhich is totally rubbish, as that very link will tell you in one of the github comments.<\/li>\n<li>Set <span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">$PATH<\/span> to add python, gcc, and binutils bin locations. Set <span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">$INCLUDE<\/span> to add gcc and binutils include location. Set <span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">$LD_LIBRARY_PATH<\/span> and <span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">LIBRARY_PATH<\/span> to add gcc lib64 location and binutils lib location. Set <span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">$JAVA_HOME<\/span> to <span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">\/usr\/lib\/jvm\/java-1.8.0<\/span>.<\/li>\n<li>Backup if wanted, then <span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">rm -rf ~\/.cache<\/span> and <span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">mkdir \/tmp\/someplace<\/span> and <span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">ln -s \/tmp\/someplace ~\/.cache<\/span> (prevents NFS headaches with bazel)<\/li>\n<li>In bazelsrc directory do <span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">.\/compile.sh<\/span>, then copy resulting output\/bazel somewhere and add that somewhere to <span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">$PATH<\/span><\/li>\n<li><span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">git clone\u00a0https:\/\/github.com\/tensorflow\/tensorflow.git<\/span><br \/>\n(and checkout a specific version if wanted)<\/li>\n<li>Patch tensorflow &#8211;\n<ol>\n<li>tensorflow\/tensorflow.bzl:\n<pre>def tf_extension_linkopts():\r\n\r\n return [\"-lrt\"] # No extension link opts<\/pre>\n<p>(add <span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">&#8220;-lrt&#8221;<\/span> inside []s)<\/p>\n<pre>def tf_cc_shared_object(\r\n\r\n name,\r\n\r\n srcs=[],\r\n\r\n deps=[],\r\n\r\n linkopts=[\"-lrt\"],<\/pre>\n<p>(ditto)<\/p>\n<pre> args += [src.path]\r\n\r\n outputs = [ctx.outputs.cc_out, ctx.outputs.py_out]\r\n\r\n ctx.action(\r\n\r\nuse_default_shell_env = True,\r\n\r\n executable=ctx.executable._swig,\r\n\r\n arguments=args,<\/pre>\n<p>(adding <span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">use_default_shell_env=True,<\/span>)<\/li>\n<li><span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">tensorflow\/third_party\/gpus\/crosstool\/CROSSTOOL_clang.tpl,\u00a0tensorflow\/third_party\/gpus\/crosstool\/CROSSTOOL_nvcc.tpl,\u00a0tensorflow\/third_party\/sycl\/crosstool\/CROSSTOOL.tpl,\u00a0tensorflow\/third_party\/toolchains\/cpus\/arm\/CROSSTOOL.tpl,\u00a0tensorflow\/third_party\/toolchains\/gpus\/crosstool\/CROSSTOOL,<\/span><br \/>\nchange <span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">&#8220;-B\/usr\/bin&#8221;<\/span> to <span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">&#8220;-B\/path\/to\/binutils\/bin&#8221;<\/span><\/li>\n<li><span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">tensorflow\/third_party\/gpus\/crosstool\/CROSSTOOL_nvcc.tpl<\/span><br \/>\nchange<br \/>\n<span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">linker_flag: &#8220;-Wl,-no-as-needed&#8221;<\/span><br \/>\nto<br \/>\n<span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">linker_flag: &#8220;-Wl,-R\/share\/apps\/gnu\/gcc\/7.3.0\/lib64,-no-as-needed&#8221;<\/span><br \/>\nChange <span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">\/usr\/bin<\/span> paths for ar, compat-ld, ld, nm, objcopy, objdump, strip to installed binutils and cpp to installed gcc<br \/>\nAfter<br \/>\n<span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">cxx_builtin_include_directory: &#8220;\/&#8221;<\/span><br \/>\nadd<br \/>\n<span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">cxx_builtin_include_directory: &#8220;\/path\/to\/gcc\/lib\/gcc\/x86_64-pc-linux-gnu\/7.3.0\/include&#8221;<br \/>\ncxx_builtin_include_directory: &#8220;\/path\/to\/gcc\/lib\/gcc\/x86_64-pc-linux-gnu\/7.3.0\/include-fixed&#8221;<br \/>\ncxx_builtin_include_directory: &#8220;\/path\/to\/include\/c++\/7.3.0&#8221;<\/span><\/li>\n<\/ol>\n<\/li>\n<li>Configure tensorflow &#8211; most defaults should be ok especially if it picks your python up correctly. Notable exception &#8211;\u00a0answer no to jemalloc question.<\/li>\n<li><span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">bazel build &#8211;config=opt \/\/tensorflow\/tools\/pip_package:build_pip_package<\/span> may also need <span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">&#8211;config=cuda<\/span><\/li>\n<li><span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">bazel-bin\/tensorflow\/tools\/pip_package\/build_pip_package \/tmp\/tensorflow_pkg<\/span><\/li>\n<li>Find .whl file in <span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">\/tmp\/tensorflow_pkg<\/span>, copy it somewhere safe and <span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">pip install tensorflow-&#8230;.longname.whl<\/span><\/li>\n<\/ol>\n<p>Note &#8211; <span style=\"font-family: Inconsolata, monospace; white-space: pre-wrap;\">&#8211;verbose_failures<\/span> is a useful flag at the bazel build stage.<\/p>\n<p>(You can comment below but I&#8217;m unlikely to offer much help. I&#8217;ve had enough of this.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tensorflow is a continuous pain to get working on any Linux other than a recent Ubuntu. Unfortunately most of my production systems are on some variant of CentOS 6&#8230; Here&#8217;s what I currently do to get Tensorflow 1.7.0 working on it. These instructions are brief and not absolutely step by step, but you can probably &hellip; <a href=\"https:\/\/eddedmondson.co.uk\/blog\/index.php\/2018\/04\/11\/installing-tensorflow-1-7-0-on-centos-6\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Installing Tensorflow 1.7.0 on CentOS 6&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/eddedmondson.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/posts\/12","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eddedmondson.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eddedmondson.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eddedmondson.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/eddedmondson.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=12"}],"version-history":[{"count":13,"href":"https:\/\/eddedmondson.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/posts\/12\/revisions"}],"predecessor-version":[{"id":25,"href":"https:\/\/eddedmondson.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/posts\/12\/revisions\/25"}],"wp:attachment":[{"href":"https:\/\/eddedmondson.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=12"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eddedmondson.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=12"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eddedmondson.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=12"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}