Skip to content

Commit

Permalink
Add flag "--host_copts" to specify global host copts (#141)
Browse files Browse the repository at this point in the history
Add cmd line options support to specify global host copts
  • Loading branch information
noaxp authored Aug 3, 2023
1 parent a2b9624 commit 5e62be5
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ build --flag_alias=enable_cuda=//cuda:enable
build --flag_alias=cuda_archs=//cuda:archs
build --flag_alias=cuda_compiler=//cuda:compiler
build --flag_alias=cuda_copts=//cuda:copts
build --flag_alias=cuda_host_copts=//cuda:host_copts
build --flag_alias=cuda_runtime=//cuda:runtime

build --enable_cuda=True
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ bazel build --cuda_archs=compute_61:compute_61,sm_61

Add the copts to all cuda compile actions.

- `@rules_cuda//cuda:host_copts`

Add the copts to the host compiler.

- `@rules_cuda//cuda:runtime`

Set the default cudart to link, for example, `--@rules_cuda//cuda:runtime=@local_cuda//:cuda_runtime_static` link the static cuda runtime.
Expand Down
5 changes: 5 additions & 0 deletions cuda/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ repeatable_string_flag(
build_setting_default = "",
)

repeatable_string_flag(
name = "host_copts",
build_setting_default = "",
)

# Command line flag to specify the CUDA runtime. Use this target as CUDA
# runtime dependency.
#
Expand Down
2 changes: 1 addition & 1 deletion cuda/private/cuda_helper.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def _create_common(ctx):
link_flags.extend([o for o in attr.linkopts if _check_opts(o)])
host_defines = []
host_local_defines = [i for i in attr.host_local_defines]
host_compile_flags = [i for i in attr.host_copts]
host_compile_flags = attr._default_host_copts[BuildSettingInfo].value + [i for i in attr.host_copts]
host_link_flags = []
if hasattr(attr, "host_linkopts"):
host_link_flags.extend([i for i in attr.host_linkopts])
Expand Down
1 change: 1 addition & 0 deletions cuda/private/rules/cuda_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ cuda_library = rule(
"_builtin_deps": attr.label_list(default = ["//cuda:runtime"]),
"_cc_toolchain": attr.label(default = "@bazel_tools//tools/cpp:current_cc_toolchain"), # legacy behaviour
"_default_cuda_copts": attr.label(default = "//cuda:copts"),
"_default_host_copts": attr.label(default = "//cuda:host_copts"),
"_default_cuda_archs": attr.label(default = "//cuda:archs"),
},
fragments = ["cpp"],
Expand Down
1 change: 1 addition & 0 deletions cuda/private/rules/cuda_objects.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ code and device link time optimization source files.""",
"ptxasopts": attr.string_list(doc = "Add these flags to the ptxas command."),
"_cc_toolchain": attr.label(default = "@bazel_tools//tools/cpp:current_cc_toolchain"), # legacy behaviour
"_default_cuda_copts": attr.label(default = "//cuda:copts"),
"_default_host_copts": attr.label(default = "//cuda:host_copts"),
"_default_cuda_archs": attr.label(default = "//cuda:archs"),
},
fragments = ["cpp"],
Expand Down

0 comments on commit 5e62be5

Please sign in to comment.