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
This commit is contained in:
Michael Andreas Dagitses
2022-06-13 06:21:22 -07:00
committed by PyTorch MergeBot
parent 9cca8ae41a
commit 9c6579f8f7
2 changed files with 15 additions and 4 deletions

View File

@ -48,12 +48,17 @@ build:cpu-only --@rules_cuda//cuda:enable_cuda=False
#
# On the bright side, this means we don't have to more broadly apply
# the exceptions to an entire target.
#
# Looking for CUDA flags? We have a cu_library macro that we can edit
# directly. Look in //tools/rules:cu.bzl for details. Editing the
# macro over this has the following advantages:
# * making changes does not require discarding the Bazel analysis
# cache
# * it allows for selective overrides on individual targets since the
# macro-level opts will come earlier than target level overrides
build --per_file_copt='^//.*\.(cpp|cc)$'@-Werror=type-limits
build --per_file_copt='^//.*\.cu$'@--compiler-options=-Werror=type-limits
build --per_file_copt='^//.*\.(cpp|cc)$'@-Werror=unused-function
build --per_file_copt='^//.*\.cu$'@--compiler-options=-Werror=unused-function
build --per_file_copt='^//.*\.(cpp|cc)$'@-Werror=unused-variable
build --per_file_copt='^//.*\.cu$'@--compiler-options=-Werror=unused-variable
build --per_file_copt='//:aten/src/ATen/RegisterCompositeExplicitAutograd\.cpp$'@-Wno-error=unused-function
build --per_file_copt='//:aten/src/ATen/RegisterCompositeImplicitAutograd\.cpp$'@-Wno-error=unused-function

View File

@ -1,6 +1,12 @@
load("@rules_cuda//cuda:defs.bzl", "cuda_library")
NVCC_COPTS = ["--expt-relaxed-constexpr", "--expt-extended-lambda"]
NVCC_COPTS = [
"--expt-relaxed-constexpr",
"--expt-extended-lambda",
"--compiler-options=-Werror=type-limits",
"--compiler-options=-Werror=unused-function",
"--compiler-options=-Werror=unused-variable",
]
def cu_library(name, srcs, copts = [], **kwargs):
cuda_library(name, srcs = srcs, copts = NVCC_COPTS + copts, **kwargs)