pytorch/WORKSPACE
Sergei Vorobev f922b58b5f [bazel] GPU-support: add @local_config_cuda and @cuda (#63604)
Summary:
## Context

We take the first step at tackling the GPU-bazel support by adding bazel external workspaces `local_config_cuda` and `cuda`, where the first one has some hardcoded values and lists of files, and the second one provides a nicer, high-level wrapper that maps into the already expected by pytorch bazel targets that are guarded with `if_cuda` macro.

The prefix `local_config_` signifies the fact that we are breaking the bazel hermeticity philosophy by explicitly relaying on the CUDA installation that is present on the machine.

## Testing

Notice an important scenario that is unlocked by this change: compilation of cpp code that depends on cuda libraries (i.e. cuda.h and so on).

Before:
```
sergei.vorobev@cs-sv7xn77uoy-gpu-1628706590:~/src/pytorch4$ bazelisk build --define=cuda=true //:c10
ERROR: /home/sergei.vorobev/src/pytorch4/tools/config/BUILD:12:1: no such package 'tools/toolchain': BUILD file not found in any of the following directories. Add a BUILD file to a directory to mark it as a package.
 - /home/sergei.vorobev/src/pytorch4/tools/toolchain and referenced by '//tools/config:cuda_enabled_and_capable'
ERROR: While resolving configuration keys for //:c10: Analysis failed
ERROR: Analysis of target '//:c10' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.259s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (2 packages loaded, 2 targets configured)
```

After:
```
sergei.vorobev@cs-sv7xn77uoy-gpu-1628706590:~/src/pytorch4$ bazelisk build --define=cuda=true //:c10
INFO: Analyzed target //:c10 (6 packages loaded, 246 targets configured).
INFO: Found 1 target...
Target //:c10 up-to-date:
  bazel-bin/libc10.lo
  bazel-bin/libc10.so
INFO: Elapsed time: 0.617s, Critical Path: 0.04s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action
```

The `//:c10` target is a good testing one for this, because it has such cases where the [glob is different](075024b9a3/BUILD.bazel (L76-L81)), based on do we compile for CUDA or not.

## What is out of scope of this PR

This PR is a first in a series of providing the comprehensive GPU bazel build support. Namely, we don't tackle the [cu_library](11a40ad915/tools/rules/cu.bzl (L2)) implementation here. This would be a separate large chunk of work.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/63604

Reviewed By: soulitzer

Differential Revision: D30442083

Pulled By: malfet

fbshipit-source-id: b2a8e4f7e5a25a69b960a82d9e36ba568eb64595
2021-08-27 09:33:42 -07:00

184 lines
4.6 KiB
Python

workspace(name = "pytorch")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("//tools/rules:workspace.bzl", "new_patched_local_repository", "new_empty_repository")
http_archive(
name = "bazel_skylib",
urls = [
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz",
],
)
http_archive(
name = "com_google_googletest",
strip_prefix = "googletest-cd6b9ae3243985d4dc725abd513a874ab4161f3e",
urls = [
"https://github.com/google/googletest/archive/cd6b9ae3243985d4dc725abd513a874ab4161f3e.tar.gz",
],
)
http_archive(
name = "pybind11_bazel",
strip_prefix = "pybind11_bazel-7f397b5d2cc2434bbd651e096548f7b40c128044",
urls = ["https://github.com/pybind/pybind11_bazel/archive/7f397b5d2cc2434bbd651e096548f7b40c128044.zip"],
sha256 = "e4a9536f49d4a88e3c5a09954de49c4a18d6b1632c457a62d6ec4878c27f1b5b",
)
new_local_repository(
name = "pybind11",
build_file = "@pybind11_bazel//:pybind11.BUILD",
path = "third_party/pybind11",
)
http_archive(
name = "com_github_glog",
strip_prefix = "glog-0.4.0",
urls = [
"https://github.com/google/glog/archive/v0.4.0.tar.gz",
],
)
http_archive(
name = "com_github_gflags_gflags",
strip_prefix = "gflags-2.2.2",
urls = [
"https://github.com/gflags/gflags/archive/v2.2.2.tar.gz",
],
sha256 = "34af2f15cf7367513b352bdcd2493ab14ce43692d2dcd9dfc499492966c64dcf",
)
new_local_repository(
name = "gloo",
build_file = "//third_party:gloo.BUILD",
path = "third_party/gloo",
)
new_local_repository(
name = "onnx",
build_file = "//third_party:onnx.BUILD",
path = "third_party/onnx",
)
new_local_repository(
name = "foxi",
build_file = "//third_party:foxi.BUILD",
path = "third_party/foxi",
)
local_repository(
name = "com_google_protobuf",
path = "third_party/protobuf",
)
new_local_repository(
name = "eigen",
build_file = "//third_party:eigen.BUILD",
path = "third_party/eigen",
)
new_local_repository(
name = "fbgemm",
build_file = "//third_party:fbgemm/BUILD.bazel",
path = "third_party/fbgemm",
)
new_local_repository(
name = "ideep",
build_file = "//third_party:ideep.BUILD",
path = "third_party/ideep",
)
new_local_repository(
name = "mkl_dnn",
build_file = "//third_party:mkl-dnn.BUILD",
path = "third_party/ideep/mkl-dnn",
)
new_local_repository(
name = "cpuinfo",
build_file = "//third_party:cpuinfo.BUILD",
path = "third_party/cpuinfo",
)
new_local_repository(
name = "asmjit",
build_file = "//third_party:fbgemm/third_party/asmjit.BUILD",
path = "third_party/fbgemm/third_party/asmjit",
)
new_local_repository(
name = "sleef",
build_file = "//third_party:sleef.BUILD",
path = "third_party/sleef",
)
new_local_repository(
name = "fmt",
build_file = "//third_party:fmt.BUILD",
path = "third_party/fmt",
)
new_patched_local_repository(
name = "tbb",
patches = [
"@//third_party:tbb.patch",
],
patch_strip = 1,
build_file = "//third_party:tbb.BUILD",
path = "third_party/tbb",
)
new_local_repository(
name = "tensorpipe",
build_file = "//third_party:tensorpipe.BUILD",
path = "third_party/tensorpipe",
)
http_archive(
name = "mkl",
build_file = "//third_party:mkl.BUILD",
strip_prefix = "lib",
sha256 = "59154b30dd74561e90d547f9a3af26c75b6f4546210888f09c9d4db8f4bf9d4c",
urls = [
"https://anaconda.org/anaconda/mkl/2020.0/download/linux-64/mkl-2020.0-166.tar.bz2",
],
)
http_archive(
name = "mkl_headers",
build_file = "//third_party:mkl_headers.BUILD",
sha256 = "2af3494a4bebe5ddccfdc43bacc80fcd78d14c1954b81d2c8e3d73b55527af90",
urls = [
"https://anaconda.org/anaconda/mkl-include/2020.0/download/linux-64/mkl-include-2020.0-166.tar.bz2",
],
)
http_archive(
name = "rules_python",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.0.1/rules_python-0.0.1.tar.gz",
sha256 = "aa96a691d3a8177f3215b14b0edc9641787abaaa30363a080165d06ab65e1161",
)
load("@pybind11_bazel//:python_configure.bzl", "python_configure")
python_configure(name = "local_config_python")
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
protobuf_deps()
load("@rules_python//python:repositories.bzl", "py_repositories")
py_repositories()
local_repository(
name = "local_config_cuda",
path = "third_party/tensorflow_cuda_bazel_build",
)
# Wrapper to expose local_config_cuda in an agnostic way
new_empty_repository(
name = "cuda",
build_file = "//third_party:cuda.BUILD",
)