tensorflow: Problem on building target with GPU support

Result of bazel build -c opt --config=cuda //tensorflow/cc:tutorials_example_trainer:

ERROR: /home/darth/.cache/bazel/_bazel_darth/08554d152596e5a7df399506682a63f3/external/local_config_cuda/crosstool/BUILD:4:1: Traceback (most recent call last):
    File "/home/darth/.cache/bazel/_bazel_darth/08554d152596e5a7df399506682a63f3/external/local_config_cuda/crosstool/BUILD", line 4
        error_gpu_disabled()
    File "/home/darth/.cache/bazel/_bazel_darth/08554d152596e5a7df399506682a63f3/external/local_config_cuda/crosstool/error_gpu_disabled.bzl", line 3, in error_gpu_disabled
        fail("ERROR: Building with --config=c...")
ERROR: Building with --config=cuda but TensorFlow is not configured to build with GPU support. Please re-run ./configure and enter 'Y' at the prompt to build with GPU support.
ERROR: no such target '@local_config_cuda//crosstool:toolchain': target 'toolchain' not declared in package 'crosstool' defined by /home/darth/.cache/bazel/_bazel_darth/08554d152596e5a7df399506682a63f3/external/local_config_cuda/crosstool/BUILD.
INFO: Elapsed time: 0.097s

And yes, I have GPU enabled when I did sudo ./configure

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 24 (5 by maintainers)

Most upvoted comments

@AFAgarap @tatatodd I found a work around method to fixed this issue in my machine. In ./third_party/gpus/cuda_configure.bzl file, there is a function to check whether cuda is enabled, def _enable_cuda(repository_ctx): if "TF_NEED_CUDA" in repository_ctx.os.environ: enable_cuda = repository_ctx.os.environ["TF_NEED_CUDA"].strip() print (enable_cuda) return enable_cuda == "1" return False In my case, even I run the configure with CUDA enabled. The environment variable “TF_NEED_CUDA” was still no in the list of repository_ctx.os.environ. So It would say CUDA was not enabled when compiled from source. Then I export “TF_NEED_CUDA=1” in my ~/.bashrc. And it compiled successfully.

So I am not sure whether it works for your case? @AFAgarap

@jinhou you are the man! Exporting the environment variable worked for me!

export TF_NEED_CUDA="1"

bazel build -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-mfpmath=both --copt=-msse4.2 --copt=-msse4.1 --copt=-msse3 --config=cuda -k //tensorflow/tools/pip_package:build_pip_package

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

By-the-way, I compile TF in a ramdisk. If you’re impatient, you can really boost the compilation time. I went from 35 minutes on my RAID-10 SSDs to ~14 minutes in my ram disk. Jfyi, you’ll need about 8GB of free ram to do this.

Hello @AFAgarap, I think you had intended to tag @jinhou but tagged me by mistake 😃

Had to also export CUDNN_INSTALL_PATH for Bazel to recognize CuDNN.