Commit Graph

29 Commits

Author SHA1 Message Date
30587195d3 Migrate c10/macros/cmake_macros.h.in to torch/headeronly (#158035)
Summary: As above, also changes a bunch of the build files to be better

Test Plan:
internal and external CI

did run buck2 build fbcode//caffe2:torch and it succeeded

Rollback Plan:

Reviewed By: swolchok

Differential Revision: D78016591

Pull Request resolved: https://github.com/pytorch/pytorch/pull/158035
Approved by: https://github.com/swolchok
2025-07-15 19:52:59 +00:00
630593d3cc [bazel] add python targets (#101003)
This PR adds bazel python, so that bazel build could be used from python like `import torch`.

Notable changes:
- Add the python targets.
- Add the version.py.tpl generation.
- In order to archive the `USE_GLOBAL_DEPS = False` just for the bazel build, employ a monkey-patch hack in the mentioned `version.py.tpl`.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/101003
Approved by: https://github.com/huydhn
2023-05-12 19:44:01 +00:00
fab2e3971f enable -Werror=sign-compare in our Bazel build (#98671)
enable -Werror=sign-compare in our Bazel build

Summary:
This is already turned on for CMake, let's see what breaks.

Test Plan: Rely on CI.

Reviewers: sahanp

Subscribers:

Tasks:

Tags:

Pull Request resolved: https://github.com/pytorch/pytorch/pull/98671
Approved by: https://github.com/kit1980
2023-04-26 23:23:24 +00:00
ea58955dda Move bazel to c++17 (#89297)
Splitting out various smaller pieces from https://github.com/pytorch/pytorch/pull/85969
Pull Request resolved: https://github.com/pytorch/pytorch/pull/89297
Approved by: https://github.com/huydhn
2022-11-19 01:13:08 +00:00
6f0c253956 Add sparse, quantized and nested tensor meta support to codegen (#81793)
Signed-off-by: Edward Z. Yang <ezyang@fb.com>
Pull Request resolved: https://github.com/pytorch/pytorch/pull/81793
Approved by: https://github.com/cpuhrsch, https://github.com/bdhirsh
2022-07-21 21:23:56 +00:00
972a209284 [bazel] Add --config=shell for easier debugging (#79350)
Bazel quality of life improvement.

This change adds a new option `--config=shell` which allows you to drop-in the shell right before the `bazel run` command is executed. For example you will have ability to examine bazel sandbox this way, run things under gdb instead of a normal run and so on.

Example usage:

```
bazel run --config=shell //:init_test
```
Pull Request resolved: https://github.com/pytorch/pytorch/pull/79350
Approved by: https://github.com/dagitses
2022-06-25 02:00:40 +00:00
34b0285185 turn on -Werror=extra in Bazel
Summary:
These are mostly helpful warnings but we explicitly disable two of
them that are problematic in our codebase.

We also remove -Werror=type-limits and -Werror=unused-but-set-variable
since they are both included as part of -Wextra.

Test Plan: Rely on CI.

Reviewers: alband

Subscribers:

Tasks:

Tags:

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

Approved by: https://github.com/malfet
2022-06-13 21:07:31 +00:00
3db1092da6 disable warnings for external repositories
Summary:
We don't own this code, don't spam our logs with their issues.

Test Plan: Verified actions manually with --subcommands.

Reviewers: seemethere

Subscribers:

Tasks:

Tags:

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

Approved by: https://github.com/malfet
2022-06-13 21:05:35 +00:00
70810a3691 turn on -Wall with a few exceptions in Bazel build
Summary:
We add the following exceptions:
 * sign-compare: this is heavily violated in our codebase
 * unknown-pragmas: we use this intentionally for some loop unrolling
   in CUDA

Because they are included in -Wall by default, we remove the following
warnings from our explicit list:
 * unused-function
 * unused-variable

Test Plan: Rely on CI.

Reviewers: alband, seemethere

Subscribers:

Tasks:

Tags:

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

Approved by: https://github.com/malfet
2022-06-13 20:29:14 +00:00
52a5266aab turn on -Werror=unused-but-set-variable
Summary:
Also fix the one violation.

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:

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

Approved by: https://github.com/malfet
2022-06-13 20:23:50 +00:00
9c6579f8f7 move CUDA flags out of --per_file_copts into the cu_library macro
Summary:
This has a few advantages:
 * changes do not discard the Bazel analysis cache
 * allows for per-target overrides

Test Plan: Verified with `bazel build --subcommands`.

Reviewers: seemethere

Subscribers:

Tasks:

Tags:

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

Approved by: https://github.com/malfet
2022-06-13 17:22:34 +00:00
9cca8ae41a precisely specify the regexps of our unused-function exemptions
Summary:

The previous values were not obviously regular expressions, but they
were evaluated as such. Thus, they could have failed under a few
circumstances:
 * the same path exists under a different repository (^ at the
   beginning protects against this)
 * the file matches with the prefix, any character, and then cpp, and
   then has some additional suffix ($ at the end and \. protects against this)

Test Plan: Relied on CI.

Reviewers: seemethere

Subscribers:

Tasks:

Tags:

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

Approved by: https://github.com/malfet
2022-06-13 17:20:42 +00:00
8b03f2a93a quote all of the regular expressions
Summary:
Without the quote, the \ is not properly forwarded to Bazel.

Test Plan: Verify subcommands.

Reviewers: seemethere

Subscribers:

Tasks:

Tags:

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

Approved by: https://github.com/malfet, https://github.com/seemethere
2022-06-13 17:18:14 +00:00
3ac27bb6ad avoid multiline strings in our warning flag overrides
Summary:
This is a little cleaner and less maintenance since lines are now
independent.

Test Plan: Rely on CI.

Reviewers: seemethere

Subscribers:

Tasks:

Tags:

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

Approved by: https://github.com/malfet, https://github.com/seemethere
2022-06-13 17:15:36 +00:00
ab2ca95dd1 turn on -Werror=unused-variable in our Bazel CPU build
Summary:
We also fix any existing issues. Note that we only do this for the CPU
build because nvcc is considered a C++ toolchain but it does not have
the same flag support. Adding flags to the GPU build will cause nvcc
errors.

Test Plan: Built locally, rely on CI to confirm.

Reviewers: malfet

Subscribers:

Tasks:

Tags:

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

Approved by: https://github.com/seemethere, https://github.com/osalpekar, https://github.com/albanD
2022-06-11 02:46:34 +00:00
606b234336 turn on -Werror=unused-function in our Bazel CPU build
Summary:
We also fix any existing issues. Note that we only do this for the CPU
build because nvcc is considered a C++ toolchain but it does not have
the same flag support. Adding flags to the GPU build will cause nvcc
errors.

Test Plan: Built locally, rely on CI to confirm.

Reviewers: malfet

Subscribers:

Tasks:

Tags:

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

Approved by: https://github.com/seemethere, https://github.com/osalpekar, https://github.com/albanD
2022-06-10 22:11:54 +00:00
bcd7a20953 Revert "turn on -Werror=unused-function in our Bazel CPU build"
This reverts commit 67d313a03259be4da7a1d623a9df6791e02248e8.

Reverted https://github.com/pytorch/pytorch/pull/79154 on behalf of https://github.com/malfet due to Breaks bazel build: 67d313a032
2022-06-10 20:43:03 +00:00
67d313a032 turn on -Werror=unused-function in our Bazel CPU build
Summary:
We also fix any existing issues. Note that we only do this for the CPU
build because nvcc is considered a C++ toolchain but it does not have
the same flag support. Adding flags to the GPU build will cause nvcc
errors.

Test Plan: Built locally, rely on CI to confirm.

Reviewers: malfet

Subscribers:

Tasks:

Tags:

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

Approved by: https://github.com/seemethere, https://github.com/osalpekar, https://github.com/albanD
2022-06-10 18:30:08 +00:00
f96d96a7fc turn on -Werror=type-limits in our Bazel CPU build
Summary:
We also fix any existing issues.

Test Plan: Built locally, rely on CI to confirm.

Reviewers: malfet

Subscribers:

Tasks:

Tags:

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

Approved by: https://github.com/seemethere, https://github.com/osalpekar, https://github.com/albanD
2022-06-10 10:04:08 +00:00
a0a23c6ef8 [bazel] make it possible to build the whole world, update CI (#78870)
Fixes https://github.com/pytorch/pytorch/issues/77509

This PR supersedes https://github.com/pytorch/pytorch/pull/77510.
It allows both `bazel query //...` and `bazel build --config=gpu //...` to work.

Concretely the changes are:
1. Add "GenerateAten" mnemonic -- this is a convenience thing, so anybody who uses [Remote Execution](https://bazel.build/docs/remote-execution) can add a

```
build:rbe --strategy=GenerateAten=sandboxed,local
```

line to the `~/.bazelrc` and build this action locally (it doesn't have hermetic dependencies at the moment).

2. Replaced few `http_archive` repos by the proper existing submodules to avoid code drift.
3. Updated `pybind11_bazel` and added `python_version="3"` to `python_configure`. This prevents hard-to-debug error that are caused by an attempt to build with python2 on the systems where it's a default python (Ubuntu 18.04 for example).
4. Added `unused_` repos, they purpose is to hide the unwanted submodules of submodules that often have bazel targets in them.
5. Updated CI to build //... -- this is a great step forward to prevent regressions in targets not only in the top-level BUILD.bazel file, but in other folders too.
6. Switch default bazel build to use gpu support.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/78870
Approved by: https://github.com/ezyang
2022-06-06 21:58:47 +00:00
715c000cf1 setup system includes for generated files on MacOS (#73591)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/73591

Test Plan: Imported from OSS

Reviewed By: malfet

Differential Revision: D34558342

Pulled By: dagitses

fbshipit-source-id: 6914a9a95d73105356e7b9c1543deab8bbdeec57
(cherry picked from commit 8b2e338827e39fcb35c3031fa22b2b1575a2c399)
2022-03-02 20:56:24 +00:00
5dcc24963b only pass --std=c++14 to C++ compilation actions (#73593)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/73593

Clang is a bit more persnickety than GCC for this flag.

Test Plan: Imported from OSS

Reviewed By: malfet

Differential Revision: D34558339

Pulled By: dagitses

fbshipit-source-id: 5b5e4e474edfb5e800e8db634327afa212d08c7e
(cherry picked from commit 02b9ffe0a26a0f0652311407f734878c6bdcc4b5)
2022-03-02 20:56:23 +00:00
40e88b75c4 extract out //c10/util:base library (#70854)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/70854

We can't do the entire package since parts of it depend on //c10/core.
ghstack-source-id: 147170901

Test Plan: Rely on CI.

Reviewed By: malfet

Differential Revision: D33321821

fbshipit-source-id: 6d634da872a382a60548e2eea37a0f9f93c6f080
(cherry picked from commit 0afa808367ff92b6011b61dcbb398a2a32e5e90d)
2022-01-26 11:51:45 +00:00
e35bf56461 [Bazel] Add CUDA build to CI (#66241)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/35316
On master, bazel cuda build is disabled due to lack of a proper `cu_library` rule. This PR:
- Add `rules_cuda` to the WORKSPACE and forward `cu_library` to `rules_cuda`.
- Use a simple local cuda and cudnn repositories (adopted from TRTorch) for cuda 11.3.
- Fix current broken cuda build.
- Enable cuda build in CI, not just for `:torch` target but all the test binaries to catch undefined symbols.

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

Reviewed By: ejguan

Differential Revision: D31544091

Pulled By: malfet

fbshipit-source-id: fd3c34d0e8f80fee06f015694a4c13a8e9e12206
2021-12-17 13:44:29 -08:00
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
b37578b3c0 Make bazel output less verbose in CI (#62601)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/62600

Adds `bazel --config=no-tty` that is useful for less verbose output in environments that don't implement full tty like CI.

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

Reviewed By: soulitzer

Differential Revision: D30070154

Pulled By: malfet

fbshipit-source-id: 5b89af8441c3c6c7ca7e9a0ebdfddee00c9ab576
2021-08-03 07:59:01 -07:00
447bcd341d Bazel build of pytorch with gating CI (#36011)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/36011

Differential Revision: D20873430

Pulled By: malfet

fbshipit-source-id: 8ffffd10ca0ff8bdab578a70a9b2b777aed985d0
2020-04-06 22:50:33 -07:00
6be9c77998 Revert D20783179: [pytorch][PR] Bazel build of pytorch
Test Plan: revert-hammer

Differential Revision:
D20783179

Original commit changeset: b160908a3e10

fbshipit-source-id: 5b7b36305525e7ccc49540b48991149cf0a759f4
2020-04-03 17:59:10 -07:00
585f153d00 Bazel build of pytorch (#35220)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/35220

Reviewed By: seemethere

Differential Revision: D20783179

Pulled By: malfet

fbshipit-source-id: b160908a3e107790fa06057a77de9d6d23493bbc
2020-04-03 17:13:58 -07:00