serving icon indicating copy to clipboard operation
serving copied to clipboard

Can't run on GPU

Open dcrankshaw opened this issue 10 years ago • 15 comments

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

dcrankshaw avatar Mar 15 '16 22:03 dcrankshaw

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.

kirilg avatar Mar 18 '16 18:03 kirilg

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.

dcrankshaw avatar Mar 24 '16 18:03 dcrankshaw

Quick shot in the dark, can you try changing it to: --crosstool_top=@tf//third_party/gpus/crosstool ?

kirilg avatar Mar 24 '16 19:03 kirilg

--crosstool_top=@tf//third_party/gpus/crosstool produces the same error as --crosstool_top=//tensorflow/third_party/gpus/crosstool

dcrankshaw avatar Mar 24 '16 19:03 dcrankshaw

@kirilg any update on this?

dcrankshaw avatar Apr 04 '16 18:04 dcrankshaw

Sorry for the delay, not yet. I'll try to get to it soon and update this issue.

kirilg avatar Apr 04 '16 23:04 kirilg

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).

esd100 avatar Apr 07 '16 01:04 esd100

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).

kirilg avatar Apr 07 '16 22:04 kirilg

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 avatar Apr 08 '16 22:04 kirilg

@kirilg I'm confirming that this works for me. Thanks for all the help!

dcrankshaw avatar Apr 11 '16 03:04 dcrankshaw

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

LiberiFatali avatar May 25 '16 07:05 LiberiFatali

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.

Michael-Jing avatar Jul 14 '17 06:07 Michael-Jing

Same as @Michael-Jing

dylanrandle avatar Jul 25 '17 18:07 dylanrandle

@dylanrandle The solution provied in this issue solves the problem in my case.

Michael-Jing avatar Jul 27 '17 11:07 Michael-Jing

@Michael-Jing You could modify tools/bazel.rc , change

@org_tensorflow//third_party/gpus/crosstool  

to

@local_config_cuda//crosstool:toolchain

elvys-zhang avatar Jul 19 '18 14:07 elvys-zhang