{"id":4184,"date":"2019-03-19T07:12:37","date_gmt":"2019-03-19T07:12:37","guid":{"rendered":"http:\/\/www.ipsych.me\/?p=4184"},"modified":"2019-03-19T07:12:42","modified_gmt":"2019-03-19T07:12:42","slug":"tensorflow-1-12-in-macos-high-sierra-with-cuda-from-source","status":"publish","type":"post","link":"https:\/\/www.ipsych.me\/?p=4184","title":{"rendered":"Tensorflow 1.12 in MacOS High Sierra with Cuda from Source"},"content":{"rendered":"<p>After numerous trial-and-error, Tensorflow 1.12 with Cuda is successfully compiled in MacOS High Sierra (in Mac Pro 2012).<\/p>\n<p>Prerequisites<\/p>\n<p style=\"padding-left: 30px;\">Cuda toolkit 10.1, cuDNN 7.5 Python 3.6 XCode 8.3.2<\/p>\n<p>0. Install bazel (for unknown reason 0.18.1 causes pip installer problem).<\/p>\n<p style=\"padding-left: 30px;\">Download\u00a0bazel-0.18.0-installer-darwin-x86_64.sh from https:\/\/github.com\/bazelbuild\/bazel\/releases.<\/p>\n<p style=\"padding-left: 30px;\">chmod +x\u00a0bazel-0.18.0-installer-darwin-x86_64.sh<\/p>\n<p style=\"padding-left: 30px;\">sudo .\/bazel-0.18.0-installer-darwin-x86_64.sh<\/p>\n<p>1. Make a working folder and clone Tensorflow code.<\/p>\n<p style=\"padding-left: 30px;\">git clone https:\/\/github.com\/tensorflow\/tensorflow<\/p>\n<p style=\"padding-left: 30px;\">cd\u00a0.\/tensorflow<\/p>\n<p>2. Checkout release 1.12<\/p>\n<p style=\"padding-left: 30px;\">git checkout r1.12<\/p>\n<p>3. Change the codes.<\/p>\n<p style=\"padding-left: 30px;\">Remove all\u00a0__align__(sizeof(T))\u00a0 or\u00a0__align__(8) from below files. (Be careful, not to make double space typo.)<\/p>\n<p style=\"padding-left: 30px;\">(i.e.\u00a0extern __shared__ __align__(sizeof(T)) unsigned char shared_memory[]; -&gt;\u00a0extern __shared__ unsigned char shared_memory[];)<\/p>\n<ul>\n<li>tensorflow\/core\/kernels\/depthwise_conv_op_gpu.cu.cc<\/li>\n<li>tensorflow\/core\/kernels\/split_lib_gpu.cu.cc<\/li>\n<li>tensorflow\/core\/kernels\/concat_lib_gpu_impl.cu.cc<\/li>\n<\/ul>\n<p style=\"padding-left: 30px;\">Change\u00a0 linkopts = [\u201c-lgomp\u201d] to #linkopts = [\u201c-lgomp\u201d]\u00a0 in below file.<\/p>\n<ul>\n<li>tensorflow\/third_party\/gpus\/cuda\/BUILD.tpl<\/li>\n<\/ul>\n<p style=\"padding-left: 30px;\">Change\u00a0constexpr Variant() noexcept = default; to\u00a0Variant() noexcept = default; in below file. (Remove constexpr).<\/p>\n<ul>\n<li>tensorflow\/core\/framework\/variant.h<\/li>\n<\/ul>\n<p>4. Export environment variables.<\/p>\n<p style=\"padding-left: 30px;\">export CUDA_HOME=\/usr\/local\/cuda<\/p>\n<p>export DYLD_LIBRARY_PATH=\/usr\/local\/cuda\/lib:\/usr\/local\/cuda\/extras\/CUPTI\/lib:\/Developer\/NVIDIA\/CUDA-10.1\/lib<\/p>\n<p>export LD_LIBRARY_PATH=$DYLD_LIBRARY_PATH<\/p>\n<p>export PATH=$DYLD_LIBRARY_PATH:$PATH<\/p>\n<p>export PATH=\/Developer\/NVIDIA\/CUDA-10.1\/bin${PATH:+:${PATH}}<\/p>\n<p>5. Configuration.<\/p>\n<p style=\"padding-left: 30px;\">cd tensorflow<\/p>\n<p style=\"padding-left: 30px;\">.\/configure<\/p>\n<p style=\"padding-left: 30px;\">specify python and python library path.<\/p>\n<p style=\"padding-left: 30px;\">Google Cloud Platform support? -&gt; n<\/p>\n<p style=\"padding-left: 30px;\">Hadoop File System support? &#8211; &gt; n<\/p>\n<p style=\"padding-left: 30px;\">Amazon AWS Platform support? -&gt; n<\/p>\n<p style=\"padding-left: 30px;\">Apache Kafka Platform support? -&gt; n<\/p>\n<p style=\"padding-left: 30px;\">XLA JIT support? -&gt; n<\/p>\n<p style=\"padding-left: 30px;\">GDR support? -&gt; n<\/p>\n<p style=\"padding-left: 30px;\">VERBS support? -&gt; n<\/p>\n<p style=\"padding-left: 30px;\">OpenCL SYCL support? -&gt; n<\/p>\n<p style=\"padding-left: 30px;\">CUDA support? &#8211;&gt; y<\/p>\n<p style=\"padding-left: 30px;\">CUDA SDK version you want to use. -&gt; 10.1<\/p>\n<p style=\"padding-left: 30px;\">Then all default values.<\/p>\n<p>&nbsp;<\/p>\n<p>6. Run Bazel. (It takes time).<\/p>\n<p class=\"p1\" style=\"padding-left: 30px;\"><span class=\"s1\">bazel build &#8211;config=cuda &#8211;config=opt &#8211;action_env PATH &#8211;action_env LD_LIBRARY_PATH &#8211;action_env DYLD_LIBRARY_PATH \/\/tensorflow\/tools\/pip_package:build_pip_package &#8211;verbose_failures &#8211;define=grpc_no_ares=true<\/span><\/p>\n<p>7. Make whl installer file.<\/p>\n<p style=\"padding-left: 30px;\">.\/bazel-bin\/tensorflow\/tools\/pip_package\/build_pip_package \/tmp\/tensorflow_pkg<\/p>\n<p>8. Install using created whl. (You need numpy =&gt;1.61).<\/p>\n<p style=\"padding-left: 30px;\">pip install \/tmp\/tensorflow_pkg\/tensorflow-1.12.1-cp36-cp36m-macosx_10_7_x86_64.whl<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After numerous trial-and-error, Tensorflow 1.12 with Cuda is successfully compiled in MacOS High Sierra (in Mac Pro 2012). Prerequisites Cuda toolkit 10.1, cuDNN 7.5 Python 3.6 XCode 8.3.2 0. Install bazel (for unknown reason 0.18.1 causes pip installer problem). Download\u00a0bazel-0.18.0-installer-darwin-x86_64.sh from https:\/\/github.com\/bazelbuild\/bazel\/releases. chmod +x\u00a0bazel-0.18.0-installer-darwin-x86_64.sh sudo .\/bazel-0.18.0-installer-darwin-x86_64.sh 1. Make a working folder and clone Tensorflow code. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4184","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.ipsych.me\/index.php?rest_route=\/wp\/v2\/posts\/4184","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ipsych.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ipsych.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ipsych.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ipsych.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4184"}],"version-history":[{"count":3,"href":"https:\/\/www.ipsych.me\/index.php?rest_route=\/wp\/v2\/posts\/4184\/revisions"}],"predecessor-version":[{"id":4187,"href":"https:\/\/www.ipsych.me\/index.php?rest_route=\/wp\/v2\/posts\/4184\/revisions\/4187"}],"wp:attachment":[{"href":"https:\/\/www.ipsych.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ipsych.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ipsych.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}