Can't run on GPU
I'm unable to get tensorflow-serving to find my GPU. I can checkout and build Tensorflow from source, and get it to run on the GPU. However, using the same configuration but building with bazel build tensorflow_serving/... does not work. I can also successfully build tensor-flow serving without gpu support, and when running with log_device_placement=True, no devices are found and all operations run on '/cpu:0'.
Issue 1: Passing --config=cuda to bazel build tensorflow_serving/... does not seem to have any effect. I'm not too familiar with bazel, so I'm guessing that this is an issue where configuration options don't propagate to dependencies. What is the correct way to pass this option when building tensorflow-serving?
Issue 2: To attempt to manually set --config=cuda, I modified the function if_cuda in tensorflow/tensorflow/tensorflow.bzl in the following way to (hopefully) always build with cuda:
# ORIGINAL
def if_cuda(a, b=[]):
return select({
"//third_party/gpus/cuda:cuda_crosstool_condition": a,
"//conditions:default": b,
})
# MODIFIED
def if_cuda(a, b=[]):
return a
With this modification, bazel build -c opt tensorflow_serving/... fails with this error
ERROR: /data/sda1/.cache/external/tf/third_party/gpus/cuda/BUILD:163:1: declared output 'external/tf/third_party/gpus/cuda/cuda.config' was not created by genrule. This is probably because the genrule actually didn't create this output, or because the output was a directory and the genrule was run remotely (note that only the contents of declared file outputs are copied from genrules run remotely).
ERROR: /data/sda1/.cache/external/tf/third_party/gpus/cuda/BUILD:163:1: not all outputs were created.
INFO: Elapsed time: 38.194s, Critical Path: 0.18s
GPU: Tesla K20c OS: Ubuntu 14.04 cuda: 7.5 cudnn: 4.0.7
Hi Dan, We unfortunately did not do much testing on GPUs in the open source release yet, though we have internally. Not sure if this will solve the problem, but I have some possible suggestions:
Issue 1: I believe the problem is that our bazel.rc file doesn't mention cuda that Tensorflow depends on. Could you try including the content of tensorflow/tools/bazel.rc (generated from this template https://github.com/tensorflow/tensorflow/blob/master/tools/bazel.rc.template by running ./configure) in Tensorflow Serving's bazel.rc (tools/bazel.rc) and see if that fixes it? (you may need to keep the use of --genrule_strategy=standalone that we have in our bazel.rc)
issue 2: This may be because it's insufficient to just override if_cuda and perhaps the other flags in bazel.rc will help. Let's see if issue 1 can be resolved this way first, and if issue 2 still persists.
Thanks for the help. No luck so far. This is what I get if I copy the contents of tensorflow/tools/bazel.rc into tools/bazel.rc.
build:cuda --crosstool_top=//third_party/gpus/crosstool
build:cuda --define=using_cuda=true
build --force_python=py2
build --python2_path=/data/sda1/anaconda2/envs/clipper/bin/python
build --spawn_strategy=standalone --genrule_strategy=standalone
test --spawn_strategy=standalone --genrule_strategy=standalone
run --spawn_strategy=standalone --genrule_strategy=standalone
This unsurprisingly fails with the error:
ERROR: ~serving/tools/defaults/BUILD:11:1: no such package 'third_party/gpus/crosstool': BUILD file not found on package path and referenced by '//tools/defaults:crosstool'.
ERROR: Loading of target '//third_party/gpus/crosstool:crosstool' failed; build aborted: no such package 'third_party/gpus/crosstool': BUILD file not found on package path.
ERROR: Loading failed; build aborted.
I'm not sure how to tell bazel where to find the crosstool. I tried changing the first line to build:cuda --crosstool_top=//tensorflow/third_party/gpus/crosstool. That got further into compilation, then failed with the error
ERROR: /data/sda1/.cache/external/tf/third_party/gpus/cuda/BUILD:163:1: declared output 'external/tf/third_party/gpus/cuda/cuda.config' was not created by genrule. This is probably because the genrule actually didn't create this output, or because the output was a directory and the genrule was run remotely (note that only the contents of declared file outputs are copied from genrules run remotely).
ERROR: /data/sda1/.cache/external/tf/third_party/gpus/cuda/BUILD:163:1: not all outputs were created.
Quick shot in the dark, can you try changing it to: --crosstool_top=@tf//third_party/gpus/crosstool ?
--crosstool_top=@tf//third_party/gpus/crosstool produces the same error as --crosstool_top=//tensorflow/third_party/gpus/crosstool
@kirilg any update on this?
Sorry for the delay, not yet. I'll try to get to it soon and update this issue.
I have a very similar problem.
declared output 'third_party/gpus/cuda/cuda.config' was not created by genrule. This is probably because the genrule actually didn't create this output, or because the output was a directory and the genrule was run remotely (note that only the contents of declared file outputs are copied from genrules run remotely).
Good news! I was able to reproduce and fix the problem to get TensorFlow Serving to compile with cuda. There's one fix to TensorFlow and one to Serving. I'll update this issue when both are submitted and pushed to Github (likely tomorrow).
Both changes were pushed to Github. If you sync to head (and make sure to also recursively update the submodules to pick up the TensorFlow change), you should be able to run bazel build -c opt --config=cuda tensorflow_serving/...
If you get the problem described here, add the line cxx_builtin_include_directory: "/usr/local/cuda-7.0/include" (or the path where your cuda is installed) to tensorflow/third_party/gpus/crosstool/CROSSTOOL
Let me know if this works for you or if you encounter any issues.
@kirilg I'm confirming that this works for me. Thanks for all the help!
add the line cxx_builtin_include_directory: "/usr/local/cuda-7.0/include" (or the path where your cuda is installed) to tensorflow/third_party/gpus/crosstool/CROSSTOOL
works for me. Thanks
My serving is not running on gpu and when I tried to build with --config=cuda, I got the following error: ERROR: no such target '@org_tensorflow//third_party/gpus/crosstool:crosstool': target 'crosstool' not declared in package 'third_party/gpus/crosstool' defined by /home/jyq/.cache/bazel/_bazel_jyq/db4d4e9700d471e5484e5ef33c1a2aff/external/org_tensorflow/third_party/gpus/crosstool/BUILD.
Same as @Michael-Jing
@dylanrandle The solution provied in this issue solves the problem in my case.
@Michael-Jing You could modify tools/bazel.rc , change
@org_tensorflow//third_party/gpus/crosstool
to
@local_config_cuda//crosstool:toolchain