Skip to content

Commit

Permalink
move CUDA flags out of --per_file_copts into the cu_library macro
Browse files Browse the repository at this point in the history
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: pytorch#79414

Approved by: https://github.com/malfet
  • Loading branch information
Michael Andreas Dagitses authored and pytorchmergebot committed Jun 13, 2022
1 parent 9cca8ae commit 9c6579f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 8 additions & 3 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion tools/rules/cu.bzl
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 9c6579f

Please sign in to comment.