Skip to content

Commit

Permalink
Fix default dbg and fastbuild optimization level for nvcc
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudhan committed Jul 10, 2023
1 parent b9cf8ec commit 0872806
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cuda/private/toolchain_configs/nvcc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def _impl(ctx):
flag_sets = [
flag_set(
actions = [ACTION_NAMES.cuda_compile],
flag_groups = [flag_group(flags = ["-g"])],
flag_groups = [flag_group(flags = ["-O0", "-g"])],
),
],
provides = ["compilation_mode"],
Expand Down Expand Up @@ -331,7 +331,7 @@ def _impl(ctx):
flag_sets = [
flag_set(
actions = [ACTION_NAMES.cuda_compile],
flag_groups = [flag_group(flags = ["--generate-line-info", "-Xcompiler", "-g1"])],
flag_groups = [flag_group(flags = ["-O0", "--generate-line-info", "-Xcompiler", "-g1"])],
),
],
provides = ["compilation_mode"],
Expand Down
15 changes: 14 additions & 1 deletion tests/flag/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,17 @@ cuda_library_flag_test(
)

# https://docs.bazel.build/versions/main/user-manual.html#flag--compilation_mode
#
# NOTE: -O specify optimization level for **host** code only, see
# https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#optimize-level-o
cuda_library_c_dbg_flag_test(
name = "cuda_library_c_dbg_flag_test",
action_mnemonic = "CudaCompile",
contain_flags = ["-g"],
contain_flags = [
# gcc default to -O0 so bazel does not explicitly set the flag. Whereas nvcc defaults to -O3.
"-O0",
"-g",
],
target_compatible_with = ["@platforms//os:linux"],
target_under_test = "@rules_cuda_examples//basic:kernel",
)
Expand All @@ -48,8 +55,14 @@ cuda_library_c_fastbuild_flag_test(
name = "cuda_library_c_fastbuild_flag_test",
action_mnemonic = "CudaCompile",
contain_flags = [
# gcc default to -O0 so bazel does not explicitly set the flag. Whereas nvcc defaults to -O3.
"-O0",
"--generate-line-info",
"-g1",
# There is no -gmlt option (not merged) as claimed in bazel user manual
# https://codereview.appspot.com/4440072
# https://gcc.gnu.org/legacy-ml/gcc-patches/2011-04/msg02075.html
# "-Xcompiler -gmlt",
],
not_contain_flags = ["-DNDEBUG"],
target_compatible_with = ["@platforms//os:linux"],
Expand Down

0 comments on commit 0872806

Please sign in to comment.