7

I am looking for a way to set up or modify an existing Docker image for installing tensorflow that will install it such that the SSE4, AVX, AVX2, and FMA instructions can be utilized for CPU speed up. So far I have found how to install from source using bazel How to Compile Tensorflow... and CPU instructions not compiled.... Neither of these explain how to do this within Docker. So I think what I am looking for is what you need to add to an existing docker image that installs without these options so that you can get a compile version of tensorflow with the CPU options enabled. The existing docker images do not do this because they want the image to run on as many machines as possible. I am using Ubuntu 14.04 on linux PC. I am new to docker but have installed tensorflow and have it working without getting the CPU warnings I get when I use the docker images. I may not need this for speed, but I have seen posts that claim the speed up can be significant. I searched for existing docker images that do this and could not find anything. I need this to work with gpu so needs to be compatible with nvidia-docker.

I just found this docker support for bazel and it might provide an answer, however I do not understand it well enough to know for sure. I believe this is saying that you can not build tensorflow with bazel inside a Dockerfile. You have to build a Dockerfile using bazel. Is my understanding correct and is this the only way to get a docker image with tensorflow compiled from source? If so, I could still use help in how to do it and still get the other dependencies that I would get if using an existing docker image for tensorflow.

Community
  • 1
  • 1
Zak Keirn
  • 807
  • 13
  • 22
  • 1
    The [devel Dockerfile](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/docker/Dockerfile.devel) contains a bazel build step. – Matt Mar 29 '17 at 00:51
  • 1
    Thanks. I see it can be done. That is helpful. It looks like the gpu version is here: [devel-gpu](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/docker/Dockerfile.devel-gpu). Would I need to change the first line to run on Ubuntu 14.04? The FROM uses `FROM nvidia/cuda:8.0-cudnn5-devel-ubuntu16.04` – Zak Keirn Mar 29 '17 at 15:44
  • @ZakKeirn were you able to create that dockerfile? I'm looking for exactly the same. – Diego Orellana Jan 29 '18 at 23:14
  • Sorry no. Got busy with other stuff but still interested in it. Post here if you make progress. – Zak Keirn Jan 30 '18 at 00:02
  • @Matt Your comment answered the question for me. Could you write it as an answer? – miguelmorin Jan 15 '19 at 18:38
  • @Matt Those images are now deprecated and have moved [here](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/tools/dockerfiles). – miguelmorin Jan 15 '19 at 18:44

2 Answers2

1

Dockerfiles that build with CPU support can be found here.

Hope that helps! Spent many a late night here on Stack Overflow and Github Issues and stuff. Now it's my turn to give back! :)

The GPU stuff in particular is really hairy - especially when enabling the XLA/JIT/AOT stuff as well as the Graph Transform Tools.

Lots of hacks embedded in my Dockerfiles. Feel free to review and ask me questions!

miguelmorin
  • 5,025
  • 4
  • 29
  • 64
Chris Fregly
  • 1,490
  • 1
  • 12
  • 8
  • Thank you. The first response from @matt seems to be leading me where I want to go. I am hoping to only slightly modify an existing maintained dockerfile from the tensorflow site. Do you see any issues with simply adding compile flags to the [devel-gpu](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/docker/Dockerfile.devel-gpu) ? – Zak Keirn Mar 29 '17 at 16:30
0

The contributing guidelines mention building TensorFlow from source with Docker to run the unit tests:

Refer to the CPU-only developer Dockerfile and GPU developer Dockerfile for the required packages. Alternatively, use the said Docker images, e.g., tensorflow/tensorflow:nightly-devel and tensorflow/tensorflow:nightly-devel-gpu for development to avoid installing the packages directly on your system.

miguelmorin
  • 5,025
  • 4
  • 29
  • 64