Tensorflow 1.12 in MacOS High Sierra with Cuda from Source

After numerous trial-and-error, Tensorflow 1.12 with Cuda is successfully compiled in MacOS High Sierra (in Mac Pro 2012).


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 bazel-0.18.0-installer-darwin-x86_64.sh from https://github.com/bazelbuild/bazel/releases.

chmod +x bazel-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.

git clone https://github.com/tensorflow/tensorflow

cd ./tensorflow

2. Checkout release 1.12

git checkout r1.12

3. Change the codes.

Remove all __align__(sizeof(T))  or __align__(8) from below files. (Be careful, not to make double space typo.)

(i.e. extern __shared__ __align__(sizeof(T)) unsigned char shared_memory[]; -> extern __shared__ unsigned char shared_memory[];)

  • tensorflow/core/kernels/depthwise_conv_op_gpu.cu.cc
  • tensorflow/core/kernels/split_lib_gpu.cu.cc
  • tensorflow/core/kernels/concat_lib_gpu_impl.cu.cc

Change  linkopts = [“-lgomp”] to #linkopts = [“-lgomp”]  in below file.

  • tensorflow/third_party/gpus/cuda/BUILD.tpl

Change constexpr Variant() noexcept = default; to Variant() noexcept = default; in below file. (Remove constexpr).

  • tensorflow/core/framework/variant.h

4. Export environment variables.

export CUDA_HOME=/usr/local/cuda

export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:/usr/local/cuda/extras/CUPTI/lib:/Developer/NVIDIA/CUDA-10.1/lib



export PATH=/Developer/NVIDIA/CUDA-10.1/bin${PATH:+:${PATH}}

5. Configuration.

cd tensorflow


specify python and python library path.

Google Cloud Platform support? -> n

Hadoop File System support? – > n

Amazon AWS Platform support? -> n

Apache Kafka Platform support? -> n

XLA JIT support? -> n

GDR support? -> n

VERBS support? -> n

OpenCL SYCL support? -> n

CUDA support? –> y

CUDA SDK version you want to use. -> 10.1

Then all default values.


6. Run Bazel. (It takes time).

bazel build –config=cuda –config=opt –action_env PATH –action_env LD_LIBRARY_PATH –action_env DYLD_LIBRARY_PATH //tensorflow/tools/pip_package:build_pip_package –verbose_failures –define=grpc_no_ares=true

7. Make whl installer file.

./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

8. Install using created whl. (You need numpy =>1.61).

pip install /tmp/tensorflow_pkg/tensorflow-1.12.1-cp36-cp36m-macosx_10_7_x86_64.whl

Leave a Reply

Your email address will not be published. Required fields are marked *