diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 00000000..e69de29b diff --git a/index.html b/index.html new file mode 100644 index 00000000..3fb6f617 --- /dev/null +++ b/index.html @@ -0,0 +1,18 @@ + + + + +
+ ++actions.compile(ctx, cuda_toolchain, cc_toolchain, srcs, common, pic, rdc) +
Perform CUDA compilation, return compiled object files.
+Notes:
+rdc
is set to True
, then an additional step of device link must be performed.foo/kernel.cu
and bar/kernel.cu
.PARAMETERS
+Name | +Description | +Default Value | +
---|---|---|
ctx | +A context object. | +none | +
cuda_toolchain | +A platform_common.ToolchainInfo of a cuda toolchain, Can be obtained with find_cuda_toolchain(ctx) . |
+none | +
cc_toolchain | +A CcToolchainInfo . Can be obtained with find_cpp_toolchain(ctx) . |
+none | +
srcs | +A list of File s to be compiled. |
+none | +
common | +A cuda common object. Can be obtained with cuda_helper.create_common(ctx) |
+none | +
pic | +Whether the srcs are compiled for position independent code. |
+False |
+
rdc | +Whether the srcs are compiled for relocatable device code. |
+False |
+
RETURNS
+An compiled object File
.
+actions.device_link(ctx, cuda_toolchain, cc_toolchain, objects, common, pic, rdc, dlto) +
Perform device link, return a dlink-ed object file.
+Notes:
+ Compilation is carried out during device linking, which involves the embeeding of the fatbin into the resulting object File
.
PARAMETERS
+Name | +Description | +Default Value | +
---|---|---|
ctx | +A context object. | +none | +
cuda_toolchain | +A platform_common.ToolchainInfo of a cuda toolchain, Can be obtained with find_cuda_toolchain(ctx) . |
+none | +
cc_toolchain | +A CcToolchainInfo . Can be obtained with find_cpp_toolchain(ctx) . |
+none | +
objects | +A depset of File s to be device linked. |
+none | +
common | +A cuda common object. Can be obtained with cuda_helper.create_common(ctx) |
+none | +
pic | +Whether the objects are compiled for position independent code. |
+False |
+
rdc | +Whether the objects are device linked for relocatable device code. |
+False |
+
dlto | +Whether the device link time optimization is enabled. | +False |
+
RETURNS
+An deviced linked object File
.
+config_helper.collect_selectables_info(selectables) +
Constructor of _SelectablesInfo
.
PARAMETERS
+Name | +Description | +Default Value | +
---|---|---|
selectables | +List of action_config s and/or feature s. |
+none | +
+config_helper.is_configured(selectables_info, name) +
Whether an action or a feature exists
+PARAMETERS
++config_helper.configure_features(selectables, selectables_info, requested_features, + unsupported_features, _debug) +
Constructor of _FeatureConfigurationInfo
.
PARAMETERS
++config_helper.get_default_features_and_action_configs(info) +
Get all default enabled features and action configs.
+Notes: + For testing purpose. Default enabled maybe disabled after configuration.
+PARAMETERS
+Name | +Description | +Default Value | +
---|---|---|
info | +A _FeatureConfigurationInfo , returned by configure_features , to be queried. |
+none | +
+config_helper.get_enabled_feature(info) +
Get all enabled features.
+Notes: + For testing purpose.
+PARAMETERS
+Name | +Description | +Default Value | +
---|---|---|
info | +A _FeatureConfigurationInfo , returned by configure_features , to be queried. |
+none | +
Returns flattened command line flags for given action, using given variables for expansion.
+PARAMETERS
++config_helper.get_tool_for_action(info, action_name) +
Returns tool path for given action.
+PARAMETERS
+Name | +Description | +Default Value | +
---|---|---|
info | +A _FeatureConfigurationInfo , returned by configure_features , to be queried. |
+none | +
action_name | +Name of the action. | +none | +
Returns whether a selectable is enable or not.
+PARAMETERS
+Returns whether a selectable is enable or not.
+PARAMETERS
+Returns environment variables to be set for the given action.
+PARAMETERS
++config_helper.get_artifact_name(artifact_name_patterns, category_name, basename) +
Returns artifact_name in form of prefix + basename + extension
.
PARAMETERS
++cuda_helper.get_arch_specs(specs_str) +
Convert string into a list of ArchSpecInfo.
+PARAMETERS
+Name | +Description | +Default Value | +
---|---|---|
specs_str | +a string to be parsed, e.g., "compute_70:sm_70;compute_80:sm_80,sm_86". | +none | +
RETURNS
+A list of ArchSpecInfo
s
+cuda_helper.check_srcs_extensions(ctx, allowed_src_files, rule_name) +
Ensure ctx.attr.srcs is valid.
+PARAMETERS
+Name | +Description | +Default Value | +
---|---|---|
ctx | +- |
+none | +
allowed_src_files | +- |
+none | +
rule_name | +- |
+none | +
+cuda_helper.check_must_enforce_rdc(arch_specs, cuda_archs_info) +
Force enable rdc if dlto is enabled.
+PARAMETERS
+Name | +Description | +Default Value | +
---|---|---|
arch_specs | +- |
+None |
+
cuda_archs_info | +- |
+None |
+
+cuda_helper.get_basename_without_ext(basename, allow_exts, fail_if_not_match) +
PARAMETERS
+Name | +Description | +Default Value | +
---|---|---|
basename | +- |
+none | +
allow_exts | +- |
+none | +
fail_if_not_match | +- |
+True |
+
+cuda_helper.create_common_info(cuda_archs_info, includes, quote_includes, system_includes, headers, + transitive_headers, defines, local_defines, compile_flags, link_flags, + host_defines, host_local_defines, host_compile_flags, host_link_flags, + ptxas_flags, transitive_cc_info, transitive_linking_contexts) +
Constructor of the common object.
+PARAMETERS
++cuda_helper.create_common(ctx) +
Helper to gather and process various information from ctx
object to ease the parameter passing for internal macros.
See cuda_helper.create_common_info
what information a common object encapsulates.
PARAMETERS
+Name | +Description | +Default Value | +
---|---|---|
ctx | +- |
+none | +
+cuda_helper.create_cuda_info(defines, objects, rdc_objects, pic_objects, rdc_pic_objects) +
Constructor for CudaInfo
. See the providers documentation for detail.
PARAMETERS
+Name | +Description | +Default Value | +
---|---|---|
defines | +- |
+None |
+
objects | +- |
+None |
+
rdc_objects | +- |
+None |
+
pic_objects | +- |
+None |
+
rdc_pic_objects | +- |
+None |
+
+cuda_helper.get_artifact_category_from_action(action_name, use_pic, use_rdc) +
Query the canonical artifact category name.
+PARAMETERS
+Name | +Description | +Default Value | +
---|---|---|
action_name | +- |
+none | +
use_pic | +- |
+None |
+
use_rdc | +- |
+None |
+
+cuda_helper.get_artifact_name(cuda_toolchain, category_name, output_basename) +
Create the artifact name that follow the toolchain configuration.
+PARAMETERS
++cuda_helper.create_compile_variables(cuda_toolchain, feature_configuration, cuda_archs_info, + source_file, output_file, host_compiler, compile_flags, + host_compile_flags, include_paths, quote_include_paths, + system_include_paths, defines, host_defines, ptxas_flags, + use_pic, use_rdc) +
Returns variables used for compile
actions.
PARAMETERS
++cuda_helper.create_device_link_variables(cuda_toolchain, feature_configuration, cuda_archs_info, + output_file, host_compiler, host_compile_flags, + user_link_flags, use_pic) +
Returns variables used for device_link
actions.
PARAMETERS
++cuda_helper.configure_features(ctx, cuda_toolchain, requested_features, unsupported_features, + _debug) +
Creates a feature_configuration instance.
+PARAMETERS
+Returns flattened command line flags for given action, using given variables for expansion.
+PARAMETERS
++cuda_helper.get_tool_for_action(info, action_name) +
Returns tool path for given action.
+PARAMETERS
+Name | +Description | +Default Value | +
---|---|---|
info | +A _FeatureConfigurationInfo , returned by configure_features , to be queried. |
+none | +
action_name | +Name of the action. | +none | +
Returns whether a selectable is enable or not.
+PARAMETERS
+Returns whether a selectable is enable or not.
+PARAMETERS
+Returns environment variables to be set for the given action.
+PARAMETERS
++repositories.config_clang(repository_ctx, cuda, clang_path) +
Generate @local_cuda//toolchain/clang/BUILD
PARAMETERS
++repositories.config_cuda_toolkit_and_nvcc(repository_ctx, cuda) +
Generate @local_cuda//BUILD
and @local_cuda//defs.bzl
and @local_cuda//toolchain/BUILD
PARAMETERS
+Name | +Description | +Default Value | +
---|---|---|
repository_ctx | +repository_ctx | +none | +
cuda | +The struct returned from detect_cuda_toolkit | +none | +
+repositories.detect_clang(repository_ctx) +
Detect local clang installation.
+The path to clang is determined by:
+CUDA_CLANG_PATH
environment variable orBAZEL_LLVM
environment variable as $BAZEL_LLVM/bin/clang
orwhich clang
orPARAMETERS
+Name | +Description | +Default Value | +
---|---|---|
repository_ctx | +repository_ctx | +none | +
RETURNS
+clang_path (str | None): Optionally return a string of path to clang executable if detected.
+ ++repositories.detect_cuda_toolkit(repository_ctx) +
Detect CUDA Toolkit.
+The path to CUDA Toolkit is determined as:
+ - the value of toolkit_path
passed to local_cuda as an attribute
+ - taken from CUDA_PATH
environment variable or
+ - determined through 'which ptxas' or
+ - defaults to '/usr/local/cuda'
PARAMETERS
+Name | +Description | +Default Value | +
---|---|---|
repository_ctx | +repository_ctx | +none | +
RETURNS
+A struct contains the information of CUDA Toolkit.
+ ++toolchain.use_cpp_toolchain(mandatory) +
Helper to depend on the C++ toolchain.
+Notes: + Copied from toolchain_utils.bzl
+PARAMETERS
+Name | +Description | +Default Value | +
---|---|---|
mandatory | +- |
+True |
+
+toolchain.use_cuda_toolchain() +
Helper to depend on the CUDA toolchain.
+ ++toolchain.find_cuda_toolchain(ctx) +
Helper to get the cuda toolchain from context object.
+PARAMETERS
+Name | +Description | +Default Value | +
---|---|---|
ctx | +The rule context for which to find a toolchain. | +none | +
RETURNS
+A platform_common.ToolchainInfo
that wraps around the necessary information of a cuda toolchain.
+toolchain.find_cuda_toolkit(ctx) +
Finds the CUDA toolchain.
+PARAMETERS
+Name | +Description | +Default Value | +
---|---|---|
ctx | +The rule context for which to find a toolchain. | +none | +
RETURNS
+A CudaToolkitInfo.
+ + + + + + ++ArchSpecInfo(stage1_arch, stage2_archs) +
Provides the information of how GPU compilation +is carried out of a single virtual architecture.
+FIELDS
+Name | +Description | +
---|---|
stage1_arch | +A virtual architecture, str, arch number only | +
stage2_archs | +A list of virtual or gpu architecture, list of Stage2ArchInfo | +
+CudaArchsInfo(arch_specs) +
Provides a list of CUDA archs to compile for.
+Read the whole Chapter 5 of CUDA Compiler Driver NVCC Reference Guide +if more detail is needed.
+FIELDS
+Name | +Description | +
---|---|
arch_specs | +A list of ArchSpecInfo | +
+CudaInfo(defines, objects, rdc_objects, pic_objects, rdc_pic_objects) +
Provides cuda build artifacts that can be consumed by device linking or linking process.
+This provider is analog to CcInfo but only contains necessary information for +linking in a flat structure.
+FIELDS
++CudaToolchainConfigInfo(action_configs, artifact_name_patterns, cuda_toolkit, features, + toolchain_identifier) +
Provides the information of what the toolchain is and how the toolchain is configured.
+FIELDS
++CudaToolkitInfo(path, version_major, version_minor, nvlink, link_stub, bin2c, fatbinary) +
Provides the information of CUDA Toolkit.
+FIELDS
+Provides the information of how the stage 2 complation is carried out.
+One and only one of virtual
, gpu
and lto
must be set to True. For example, if arch
is set to 80
and virtual
is True
, then a
+ptx embedding process is carried out for compute_80
. Multiple Stage2ArchInfo
can be used for specifying how a stage 1 result is
+transformed into its final form.
FIELDS
+Name | +Description | +
---|---|
arch | +str, arch number | +
virtual | +bool, use virtual arch, default False | +
gpu | +bool, use gpu arch, default False | +
lto | +bool, use lto, default False | +
This repository contains Starlark implementation of CUDA rules in Bazel.
+These rules provide some macros and rules that make it easier to build CUDA with Bazel.
+Add the following to your WORKSPACE
file and replace the placeholders with actual values.
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+http_archive(
+ name = "rules_cuda",
+ sha256 = "{sha256_to_replace}",
+ strip_prefix = "rules_cuda-{git_commit_hash}",
+ urls = ["https://github.com/bazel-contrib/rules_cuda/archive/{git_commit_hash}.tar.gz"],
+)
+load("@rules_cuda//cuda:repositories.bzl", "register_detected_cuda_toolchains", "rules_cuda_dependencies")
+rules_cuda_dependencies()
+register_detected_cuda_toolchains()
+
+NOTE: the use of register_detected_cuda_toolchains
depends on the environment variable CUDA_PATH
. You must also
+ensure the host compiler is available. On windows, this means that you will also need to set the environment variable
+BAZEL_VC
properly.
detect_cuda_toolkit
+and detect_clang
+determains how the toolchains are detected.
cuda_library
: Can be used to compile and create static library for CUDA kernel code. The resulting targets can be
+ consumed by C/C++ Rules.cuda_objects
: If you don't understand what device link means, you must never use it. This rule produce incomplete
+ object files that can only be consumed by cuda_library
. It is created for relocatable device code and device link
+ time optimization source files.Some flags are defined in cuda/BUILD.bazel. To use them, for example:
+bazel build --@rules_cuda//cuda:archs=compute_61:compute_61,sm_61
+
+In .bazelrc
file, you can define shortcut alias for the flag, for example:
# Convenient flag shortcuts.
+build --flag_alias=cuda_archs=@rules_cuda//cuda:archs
+
+and then you can use it as following:
+bazel build --cuda_archs=compute_61:compute_61,sm_61
+
+@rules_cuda//cuda:enable
Enable or disable all rules_cuda related rules. When disabled, the detected cuda toolchains will also be disabled to avoid potential human error.
+ By default, rules_cuda rules are enabled. See examples/if_cuda
for how to support both cuda-enabled and cuda-free builds.
@rules_cuda//cuda:archs
Select the cuda archs to support. See cuda_archs specification DSL grammar.
+@rules_cuda//cuda:compiler
Select the cuda compiler, available options are nvcc
or clang
@rules_cuda//cuda:copts
Add the copts to all cuda compile actions.
+@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.
--features=cuda_device_debug
Sets nvcc flags to enable debug information in device code.
+ Currently ignored for clang, where --compilation_mode=debug
applies to both
+ host and device code.
Checkout the examples to see if it fits your needs.
+See examples for basic usage.
+See rules_cuda_examples for extended real world projects.
+Sometimes the following error occurs:
+cc1plus: fatal error: /tmp/tmpxft_00000002_00000019-2.cpp: No such file or directory
+
+The problem is caused by nvcc use PID to determine temporary file name, and with --spawn_strategy linux-sandbox
which is the default strategy on Linux, the PIDs nvcc sees are all very small numbers, say 2~4 due to sandboxing. linux-sandbox
is not hermetic because it mounts root into the sandbox, thus, /tmp
is shared between sandboxes, which is causing name conflict under high parallelism. Similar problem has been reported at nvidia forums.
To avoid it:
+--spawn_strategy local
should eliminate the case because it will let nvcc sees the true PIDs.--experimental_use_hermetic_linux_sandbox
should eliminate the case because it will avoid the sharing of /tmp
.-objtemp
option to the command should reduce the case from happening.This repository contains Starlark implementation of CUDA rules in Bazel.
These rules provide some macros and rules that make it easier to build CUDA with Bazel.
"},{"location":"#getting-started","title":"Getting Started","text":"Add the following to your WORKSPACE
file and replace the placeholders with actual values.
load(\"@bazel_tools//tools/build_defs/repo:http.bzl\", \"http_archive\")\nhttp_archive(\n name = \"rules_cuda\",\n sha256 = \"{sha256_to_replace}\",\n strip_prefix = \"rules_cuda-{git_commit_hash}\",\n urls = [\"https://github.com/bazel-contrib/rules_cuda/archive/{git_commit_hash}.tar.gz\"],\n)\nload(\"@rules_cuda//cuda:repositories.bzl\", \"register_detected_cuda_toolchains\", \"rules_cuda_dependencies\")\nrules_cuda_dependencies()\nregister_detected_cuda_toolchains()\n
NOTE: the use of register_detected_cuda_toolchains
depends on the environment variable CUDA_PATH
. You must also ensure the host compiler is available. On windows, this means that you will also need to set the environment variable BAZEL_VC
properly.
detect_cuda_toolkit
and detect_clang
determains how the toolchains are detected.
cuda_library
: Can be used to compile and create static library for CUDA kernel code. The resulting targets can be consumed by C/C++ Rules.cuda_objects
: If you don't understand what device link means, you must never use it. This rule produce incomplete object files that can only be consumed by cuda_library
. It is created for relocatable device code and device link time optimization source files.Some flags are defined in cuda/BUILD.bazel. To use them, for example:
bazel build --@rules_cuda//cuda:archs=compute_61:compute_61,sm_61\n
In .bazelrc
file, you can define shortcut alias for the flag, for example:
# Convenient flag shortcuts.\nbuild --flag_alias=cuda_archs=@rules_cuda//cuda:archs\n
and then you can use it as following:
bazel build --cuda_archs=compute_61:compute_61,sm_61\n
"},{"location":"#available-flags","title":"Available flags","text":"@rules_cuda//cuda:enable
Enable or disable all rules_cuda related rules. When disabled, the detected cuda toolchains will also be disabled to avoid potential human error. By default, rules_cuda rules are enabled. See examples/if_cuda
for how to support both cuda-enabled and cuda-free builds.
@rules_cuda//cuda:archs
Select the cuda archs to support. See cuda_archs specification DSL grammar.
@rules_cuda//cuda:compiler
Select the cuda compiler, available options are nvcc
or clang
@rules_cuda//cuda:copts
Add the copts to all cuda compile actions.
@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.
--features=cuda_device_debug
Sets nvcc flags to enable debug information in device code. Currently ignored for clang, where --compilation_mode=debug
applies to both host and device code.
Checkout the examples to see if it fits your needs.
See examples for basic usage.
See rules_cuda_examples for extended real world projects.
"},{"location":"#known-issue","title":"Known issue","text":"Sometimes the following error occurs:
cc1plus: fatal error: /tmp/tmpxft_00000002_00000019-2.cpp: No such file or directory\n
The problem is caused by nvcc use PID to determine temporary file name, and with --spawn_strategy linux-sandbox
which is the default strategy on Linux, the PIDs nvcc sees are all very small numbers, say 2~4 due to sandboxing. linux-sandbox
is not hermetic because it mounts root into the sandbox, thus, /tmp
is shared between sandboxes, which is causing name conflict under high parallelism. Similar problem has been reported at nvidia forums.
To avoid it:
--spawn_strategy local
should eliminate the case because it will let nvcc sees the true PIDs.--experimental_use_hermetic_linux_sandbox
should eliminate the case because it will avoid the sharing of /tmp
.-objtemp
option to the command should reduce the case from happening.\nactions.compile(ctx, cuda_toolchain, cc_toolchain, srcs, common, pic, rdc)\n
Perform CUDA compilation, return compiled object files.
Notes:
rdc
is set to True
, then an additional step of device link must be performed.foo/kernel.cu
and bar/kernel.cu
.PARAMETERS
Name Description Default Value ctx A context object. none cuda_toolchain Aplatform_common.ToolchainInfo
of a cuda toolchain, Can be obtained with find_cuda_toolchain(ctx)
. none cc_toolchain A CcToolchainInfo
. Can be obtained with find_cpp_toolchain(ctx)
. none srcs A list of File
s to be compiled. none common A cuda common object. Can be obtained with cuda_helper.create_common(ctx)
none pic Whether the srcs
are compiled for position independent code. False
rdc Whether the srcs
are compiled for relocatable device code. False
RETURNS
An compiled object File
.
\nactions.device_link(ctx, cuda_toolchain, cc_toolchain, objects, common, pic, rdc, dlto)\n
Perform device link, return a dlink-ed object file.
Notes: Compilation is carried out during device linking, which involves the embeeding of the fatbin into the resulting object File
.
PARAMETERS
Name Description Default Value ctx A context object. none cuda_toolchain Aplatform_common.ToolchainInfo
of a cuda toolchain, Can be obtained with find_cuda_toolchain(ctx)
. none cc_toolchain A CcToolchainInfo
. Can be obtained with find_cpp_toolchain(ctx)
. none objects A depset
of File
s to be device linked. none common A cuda common object. Can be obtained with cuda_helper.create_common(ctx)
none pic Whether the objects
are compiled for position independent code. False
rdc Whether the objects
are device linked for relocatable device code. False
dlto Whether the device link time optimization is enabled. False
RETURNS
An deviced linked object File
.
\nconfig_helper.collect_selectables_info(selectables)\n
Constructor of _SelectablesInfo
.
PARAMETERS
Name Description Default Value selectables List ofaction_config
s and/or feature
s. none "},{"location":"developer/developer_docs/#config_helperis_configured","title":"config_helper.is_configured","text":"\nconfig_helper.is_configured(selectables_info, name)\n
Whether an action or a feature exists
PARAMETERS
Name Description Default Value selectables_info The_SelectablesInfo
returned from _collect_selectables_info
none name Name of the selectable, that is, an action_config
or a feature
. none "},{"location":"developer/developer_docs/#config_helperconfigure_features","title":"config_helper.configure_features","text":"\nconfig_helper.configure_features(selectables, selectables_info, requested_features,\n unsupported_features, _debug)\n
Constructor of _FeatureConfigurationInfo
.
PARAMETERS
Name Description Default Value selectables List ofaction_config
s and/or feature
s. None
selectables_info The _SelectablesInfo
returned from _collect_selectables_info
None
requested_features List of names of action_config
s and/or feature
s to be enabled. None
unsupported_features List of names of action_config
s and/or feature
s to be disabled. None
_debug -
False
"},{"location":"developer/developer_docs/#config_helperget_default_features_and_action_configs","title":"config_helper.get_default_features_and_action_configs","text":"\nconfig_helper.get_default_features_and_action_configs(info)\n
Get all default enabled features and action configs.
Notes: For testing purpose. Default enabled maybe disabled after configuration.
PARAMETERS
Name Description Default Value info A_FeatureConfigurationInfo
, returned by configure_features
, to be queried. none "},{"location":"developer/developer_docs/#config_helperget_enabled_feature","title":"config_helper.get_enabled_feature","text":"\nconfig_helper.get_enabled_feature(info)\n
Get all enabled features.
Notes: For testing purpose.
PARAMETERS
Name Description Default Value info A_FeatureConfigurationInfo
, returned by configure_features
, to be queried. none "},{"location":"developer/developer_docs/#config_helperget_command_line","title":"config_helper.get_command_line","text":"\nconfig_helper.get_command_line(info, action, value)\n
Returns flattened command line flags for given action, using given variables for expansion.
PARAMETERS
Name Description Default Value info A_FeatureConfigurationInfo
, returned by configure_features
, to be queried. none action Name of the action. none value Build variables to be used for template expansion. none "},{"location":"developer/developer_docs/#config_helperget_tool_for_action","title":"config_helper.get_tool_for_action","text":"\nconfig_helper.get_tool_for_action(info, action_name)\n
Returns tool path for given action.
PARAMETERS
Name Description Default Value info A_FeatureConfigurationInfo
, returned by configure_features
, to be queried. none action_name Name of the action. none "},{"location":"developer/developer_docs/#config_helperaction_is_enabled","title":"config_helper.action_is_enabled","text":"\nconfig_helper.action_is_enabled(info, name)\n
Returns whether a selectable is enable or not.
PARAMETERS
Name Description Default Value info A_FeatureConfigurationInfo
, returned by configure_features
, to be queried. none name Name of the selectable, that is, an action_config
or a feature
. none "},{"location":"developer/developer_docs/#config_helperis_enabled","title":"config_helper.is_enabled","text":"\nconfig_helper.is_enabled(info, name)\n
Returns whether a selectable is enable or not.
PARAMETERS
Name Description Default Value info A_FeatureConfigurationInfo
, returned by configure_features
, to be queried. none name Name of the selectable, that is, an action_config
or a feature
. none "},{"location":"developer/developer_docs/#config_helperget_environment_variables","title":"config_helper.get_environment_variables","text":"\nconfig_helper.get_environment_variables(info, action, value)\n
Returns environment variables to be set for the given action.
PARAMETERS
Name Description Default Value info A_FeatureConfigurationInfo
, returned by configure_features
, to be queried. none action Name of the action. none value Build variables to be used for template expansion. none "},{"location":"developer/developer_docs/#config_helperget_artifact_name","title":"config_helper.get_artifact_name","text":"\nconfig_helper.get_artifact_name(artifact_name_patterns, category_name, basename)\n
Returns artifact_name in form of prefix + basename + extension
.
PARAMETERS
Name Description Default Value artifact_name_patterns A list ofartifact_name_pattern
. none category_name A string match the category_name
field in artifact_name_pattern
. none basename A string. none "},{"location":"developer/developer_docs/#cuda_helperget_arch_specs","title":"cuda_helper.get_arch_specs","text":"\ncuda_helper.get_arch_specs(specs_str)\n
Convert string into a list of ArchSpecInfo.
PARAMETERS
Name Description Default Value specs_str a string to be parsed, e.g., \"compute_70:sm_70;compute_80:sm_80,sm_86\". noneRETURNS
A list of ArchSpecInfo
s
\ncuda_helper.check_srcs_extensions(ctx, allowed_src_files, rule_name)\n
Ensure ctx.attr.srcs is valid.
PARAMETERS
Name Description Default Value ctx-
none allowed_src_files-
none rule_name-
none "},{"location":"developer/developer_docs/#cuda_helpercheck_must_enforce_rdc","title":"cuda_helper.check_must_enforce_rdc","text":"\ncuda_helper.check_must_enforce_rdc(arch_specs, cuda_archs_info)\n
Force enable rdc if dlto is enabled.
PARAMETERS
Name Description Default Value arch_specs-
None
cuda_archs_info -
None
"},{"location":"developer/developer_docs/#cuda_helperget_basename_without_ext","title":"cuda_helper.get_basename_without_ext","text":"\ncuda_helper.get_basename_without_ext(basename, allow_exts, fail_if_not_match)\n
PARAMETERS
Name Description Default Value basename-
none allow_exts-
none fail_if_not_match-
True
"},{"location":"developer/developer_docs/#cuda_helpercreate_common_info","title":"cuda_helper.create_common_info","text":"\ncuda_helper.create_common_info(cuda_archs_info, includes, quote_includes, system_includes, headers,\n transitive_headers, defines, local_defines, compile_flags, link_flags,\n host_defines, host_local_defines, host_compile_flags, host_link_flags,\n ptxas_flags, transitive_cc_info, transitive_linking_contexts)\n
Constructor of the common object.
PARAMETERS
Name Description Default Value cuda_archs_infoCudaArchsInfo
. None
includes include paths. Can be used with #include <...>
and #include \"...\"
. []
quote_includes include paths. Can be used with #include \"...\"
. []
system_includes include paths. Can be used with #include <...>
. []
headers headers directly relate with this target. []
transitive_headers headers transitively gather from deps
. []
defines public #define
s. Pass to compiler driver directly. Will be seen by downstream targets. []
local_defines private #define
s. Pass to compiler driver directly. Will not be seen by downstream targets. []
compile_flags flags pass to compiler driver directly. []
link_flags flags pass to device linker. []
host_defines public #define
s. Pass to host compiler. Will be seen by downstream targets. []
host_local_defines private #define
s. Pass to host compiler. Will not be seen by downstream targets. []
host_compile_flags flags pass to host compiler. []
host_link_flags flags pass to host linker. []
ptxas_flags flags pass to ptxas
. []
transitive_cc_info -
None
transitive_linking_contexts CcInfo.linking_context
extracted from deps
[]
"},{"location":"developer/developer_docs/#cuda_helpercreate_common","title":"cuda_helper.create_common","text":"\ncuda_helper.create_common(ctx)\n
Helper to gather and process various information from ctx
object to ease the parameter passing for internal macros.
See cuda_helper.create_common_info
what information a common object encapsulates.
PARAMETERS
Name Description Default Value ctx-
none "},{"location":"developer/developer_docs/#cuda_helpercreate_cuda_info","title":"cuda_helper.create_cuda_info","text":"\ncuda_helper.create_cuda_info(defines, objects, rdc_objects, pic_objects, rdc_pic_objects)\n
Constructor for CudaInfo
. See the providers documentation for detail.
PARAMETERS
Name Description Default Value defines-
None
objects -
None
rdc_objects -
None
pic_objects -
None
rdc_pic_objects -
None
"},{"location":"developer/developer_docs/#cuda_helperget_artifact_category_from_action","title":"cuda_helper.get_artifact_category_from_action","text":"\ncuda_helper.get_artifact_category_from_action(action_name, use_pic, use_rdc)\n
Query the canonical artifact category name.
PARAMETERS
Name Description Default Value action_name-
none use_pic-
None
use_rdc -
None
"},{"location":"developer/developer_docs/#cuda_helperget_artifact_name","title":"cuda_helper.get_artifact_name","text":"\ncuda_helper.get_artifact_name(cuda_toolchain, category_name, output_basename)\n
Create the artifact name that follow the toolchain configuration.
PARAMETERS
Name Description Default Value cuda_toolchain CUDA toolchain returned byfind_cuda_toolchain
. none category_name The canonical artifact category name return by cuda_helper.get_artifact_category_from_action
none output_basename The basename. none "},{"location":"developer/developer_docs/#cuda_helpercreate_compile_variables","title":"cuda_helper.create_compile_variables","text":"\ncuda_helper.create_compile_variables(cuda_toolchain, feature_configuration, cuda_archs_info,\n source_file, output_file, host_compiler, compile_flags,\n host_compile_flags, include_paths, quote_include_paths,\n system_include_paths, defines, host_defines, ptxas_flags,\n use_pic, use_rdc)\n
Returns variables used for compile
actions.
PARAMETERS
Name Description Default Value cuda_toolchain cuda_toolchain for which we are creating build variables. none feature_configuration Feature configuration to be queried. none cuda_archs_infoCudaArchsInfo
none source_file source file for the compilation. None
output_file output file of the compilation. None
host_compiler host compiler path. None
compile_flags flags pass to compiler driver directly. []
host_compile_flags flags pass to host compiler. []
include_paths include paths. Can be used with #include <...>
and #include \"...\"
. []
quote_include_paths include paths. Can be used with #include \"...\"
. []
system_include_paths include paths. Can be used with #include <...>
. []
defines #define
s. Pass to compiler driver directly. []
host_defines #define
s. Pass to host compiler. []
ptxas_flags flags pass to ptxas
. []
use_pic whether to compile for position independent code. False
use_rdc whether to compile for relocatable device code. False
"},{"location":"developer/developer_docs/#cuda_helpercreate_device_link_variables","title":"cuda_helper.create_device_link_variables","text":"\ncuda_helper.create_device_link_variables(cuda_toolchain, feature_configuration, cuda_archs_info,\n output_file, host_compiler, host_compile_flags,\n user_link_flags, use_pic)\n
Returns variables used for device_link
actions.
PARAMETERS
Name Description Default Value cuda_toolchain cuda_toolchain for which we are creating build variables. none feature_configuration Feature configuration to be queried. none cuda_archs_infoCudaArchsInfo
none output_file output file of the device linking. None
host_compiler host compiler path. None
host_compile_flags flags pass to host compiler. []
user_link_flags flags for device linking. []
use_pic whether to compile for position independent code. False
"},{"location":"developer/developer_docs/#cuda_helperconfigure_features","title":"cuda_helper.configure_features","text":"\ncuda_helper.configure_features(ctx, cuda_toolchain, requested_features, unsupported_features,\n _debug)\n
Creates a feature_configuration instance.
PARAMETERS
Name Description Default Value ctx The rule context. none cuda_toolchain cuda_toolchain for which we configure features. none requested_features List of features to be enabled.None
unsupported_features List of features that are unsupported by the current rule. None
_debug -
False
"},{"location":"developer/developer_docs/#cuda_helperget_command_line","title":"cuda_helper.get_command_line","text":"\ncuda_helper.get_command_line(info, action, value)\n
Returns flattened command line flags for given action, using given variables for expansion.
PARAMETERS
Name Description Default Value info A_FeatureConfigurationInfo
, returned by configure_features
, to be queried. none action Name of the action. none value Build variables to be used for template expansion. none "},{"location":"developer/developer_docs/#cuda_helperget_tool_for_action","title":"cuda_helper.get_tool_for_action","text":"\ncuda_helper.get_tool_for_action(info, action_name)\n
Returns tool path for given action.
PARAMETERS
Name Description Default Value info A_FeatureConfigurationInfo
, returned by configure_features
, to be queried. none action_name Name of the action. none "},{"location":"developer/developer_docs/#cuda_helperaction_is_enabled","title":"cuda_helper.action_is_enabled","text":"\ncuda_helper.action_is_enabled(info, name)\n
Returns whether a selectable is enable or not.
PARAMETERS
Name Description Default Value info A_FeatureConfigurationInfo
, returned by configure_features
, to be queried. none name Name of the selectable, that is, an action_config
or a feature
. none "},{"location":"developer/developer_docs/#cuda_helperis_enabled","title":"cuda_helper.is_enabled","text":"\ncuda_helper.is_enabled(info, name)\n
Returns whether a selectable is enable or not.
PARAMETERS
Name Description Default Value info A_FeatureConfigurationInfo
, returned by configure_features
, to be queried. none name Name of the selectable, that is, an action_config
or a feature
. none "},{"location":"developer/developer_docs/#cuda_helperget_environment_variables","title":"cuda_helper.get_environment_variables","text":"\ncuda_helper.get_environment_variables(info, action, value)\n
Returns environment variables to be set for the given action.
PARAMETERS
Name Description Default Value info A_FeatureConfigurationInfo
, returned by configure_features
, to be queried. none action Name of the action. none value Build variables to be used for template expansion. none "},{"location":"developer/developer_docs/#repositoriesconfig_clang","title":"repositories.config_clang","text":"\nrepositories.config_clang(repository_ctx, cuda, clang_path)\n
Generate @local_cuda//toolchain/clang/BUILD
PARAMETERS
Name Description Default Value repository_ctx repository_ctx none cuda The struct returned fromdetect_cuda_toolkit
none clang_path Path to clang executable returned from detect_clang
none "},{"location":"developer/developer_docs/#repositoriesconfig_cuda_toolkit_and_nvcc","title":"repositories.config_cuda_toolkit_and_nvcc","text":"\nrepositories.config_cuda_toolkit_and_nvcc(repository_ctx, cuda)\n
Generate @local_cuda//BUILD
and @local_cuda//defs.bzl
and @local_cuda//toolchain/BUILD
PARAMETERS
Name Description Default Value repository_ctx repository_ctx none cuda The struct returned from detect_cuda_toolkit none "},{"location":"developer/developer_docs/#repositoriesdetect_clang","title":"repositories.detect_clang","text":"\nrepositories.detect_clang(repository_ctx)\n
Detect local clang installation.
The path to clang is determined by:
CUDA_CLANG_PATH
environment variable orBAZEL_LLVM
environment variable as $BAZEL_LLVM/bin/clang
orwhich clang
orPARAMETERS
Name Description Default Value repository_ctx repository_ctx noneRETURNS
clang_path (str | None): Optionally return a string of path to clang executable if detected.
"},{"location":"developer/developer_docs/#repositoriesdetect_cuda_toolkit","title":"repositories.detect_cuda_toolkit","text":"\nrepositories.detect_cuda_toolkit(repository_ctx)\n
Detect CUDA Toolkit.
The path to CUDA Toolkit is determined as: - the value of toolkit_path
passed to local_cuda as an attribute - taken from CUDA_PATH
environment variable or - determined through 'which ptxas' or - defaults to '/usr/local/cuda'
PARAMETERS
Name Description Default Value repository_ctx repository_ctx noneRETURNS
A struct contains the information of CUDA Toolkit.
"},{"location":"developer/developer_docs/#toolchainuse_cpp_toolchain","title":"toolchain.use_cpp_toolchain","text":"\ntoolchain.use_cpp_toolchain(mandatory)\n
Helper to depend on the C++ toolchain.
Notes: Copied from toolchain_utils.bzl
PARAMETERS
Name Description Default Value mandatory-
True
"},{"location":"developer/developer_docs/#toolchainuse_cuda_toolchain","title":"toolchain.use_cuda_toolchain","text":"\ntoolchain.use_cuda_toolchain()\n
Helper to depend on the CUDA toolchain.
"},{"location":"developer/developer_docs/#toolchainfind_cuda_toolchain","title":"toolchain.find_cuda_toolchain","text":"\ntoolchain.find_cuda_toolchain(ctx)\n
Helper to get the cuda toolchain from context object.
PARAMETERS
Name Description Default Value ctx The rule context for which to find a toolchain. noneRETURNS
A platform_common.ToolchainInfo
that wraps around the necessary information of a cuda toolchain.
\ntoolchain.find_cuda_toolkit(ctx)\n
Finds the CUDA toolchain.
PARAMETERS
Name Description Default Value ctx The rule context for which to find a toolchain. noneRETURNS
A CudaToolkitInfo.
"},{"location":"developer/providers_docs/","title":"Providers","text":""},{"location":"developer/providers_docs/#archspecinfo","title":"ArchSpecInfo","text":"\nArchSpecInfo(stage1_arch, stage2_archs)\n
Provides the information of how GPU compilation is carried out of a single virtual architecture.
FIELDS
Name Description stage1_arch A virtual architecture, str, arch number only stage2_archs A list of virtual or gpu architecture, list of Stage2ArchInfo "},{"location":"developer/providers_docs/#cudaarchsinfo","title":"CudaArchsInfo","text":"\nCudaArchsInfo(arch_specs)\n
Provides a list of CUDA archs to compile for.
Read the whole Chapter 5 of CUDA Compiler Driver NVCC Reference Guide if more detail is needed.
FIELDS
Name Description arch_specs A list of ArchSpecInfo "},{"location":"developer/providers_docs/#cudainfo","title":"CudaInfo","text":"\nCudaInfo(defines, objects, rdc_objects, pic_objects, rdc_pic_objects)\n
Provides cuda build artifacts that can be consumed by device linking or linking process.
This provider is analog to CcInfo but only contains necessary information for linking in a flat structure.
FIELDS
Name Description defines A depset of strings. It is used for the compilation during device linking. objects A depset of objects. rdc_objects A depset of relocatable device code objects. pic_objects A depset of position indepentent code objects. rdc_pic_objects A depset of relocatable device code and position indepentent code objects. "},{"location":"developer/providers_docs/#cudatoolchainconfiginfo","title":"CudaToolchainConfigInfo","text":"\nCudaToolchainConfigInfo(action_configs, artifact_name_patterns, cuda_toolkit, features,\n toolchain_identifier)\n
Provides the information of what the toolchain is and how the toolchain is configured.
FIELDS
Name Description action_configs A list of action_configs. artifact_name_patterns A list of artifact_name_patterns. cuda_toolkit CudaToolkitInfo features A list of features. toolchain_identifier nvcc or clang "},{"location":"developer/providers_docs/#cudatoolkitinfo","title":"CudaToolkitInfo","text":"\nCudaToolkitInfo(path, version_major, version_minor, nvlink, link_stub, bin2c, fatbinary)\n
Provides the information of CUDA Toolkit.
FIELDS
Name Description path string of path to cuda toolkit root version_major int of the cuda toolkit major version, e.g, 11 for 11.6 version_minor int of the cuda toolkit minor version, e.g, 6 for 11.6 nvlink File to the nvlink executable link_stub File to the link.stub file bin2c File to the bin2c executable fatbinary File to the fatbinary executable "},{"location":"developer/providers_docs/#stage2archinfo","title":"Stage2ArchInfo","text":"\nStage2ArchInfo(arch, virtual, gpu, lto)\n
Provides the information of how the stage 2 complation is carried out.
One and only one of virtual
, gpu
and lto
must be set to True. For example, if arch
is set to 80
and virtual
is True
, then a ptx embedding process is carried out for compute_80
. Multiple Stage2ArchInfo
can be used for specifying how a stage 1 result is transformed into its final form.
FIELDS
Name Description arch str, arch number virtual bool, use virtual arch, default False gpu bool, use gpu arch, default False lto bool, use lto, default False"},{"location":"user/toolchain_config_docs/","title":"Configure the toolchain","text":""},{"location":"user/toolchain_config_docs/#cuda_toolchain","title":"cuda_toolchain","text":"\ncuda_toolchain(name, compiler_executable, compiler_files, toolchain_config)\n
This rule consumes a CudaToolchainConfigInfo
and provides a platform_common.ToolchainInfo
, a.k.a, the CUDA Toolchain.
ATTRIBUTES
Name Description Type Mandatory Default name A unique name for this target. Name required compiler_executable The path of the main executable of this toolchain. String required compiler_files The set of files that are needed when compiling using this toolchain. Label optionalNone
toolchain_config A target that provides a CudaToolchainConfigInfo
. Label required "},{"location":"user/toolchain_config_docs/#cuda_toolchain_config_clang","title":"cuda_toolchain_config_clang","text":"\ncuda_toolchain_config_clang(name, cuda_toolkit, toolchain_identifier)\n
This rule provides the predefined cuda toolchain configuration for Clang.
ATTRIBUTES
Name Description Type Mandatory Default name A unique name for this target. Name required cuda_toolkit A target that provides aCudaToolkitInfo
. Label required toolchain_identifier - String required "},{"location":"user/toolchain_config_docs/#cuda_toolchain_config_nvcc","title":"cuda_toolchain_config_nvcc","text":"\ncuda_toolchain_config_nvcc(name, cuda_toolkit, nvcc_version_major, nvcc_version_minor,\n toolchain_identifier)\n
This rule provides the predefined cuda toolchain configuration for NVCC with non MSVC as host compiler.
ATTRIBUTES
Name Description Type Mandatory Default name A unique name for this target. Name required cuda_toolkit A target that provides aCudaToolkitInfo
. Label required nvcc_version_major The CUDA Toolkit major version, e.g, 11 for 11.6 Integer optional 0
nvcc_version_minor The CUDA Toolkit minor version, e.g, 6 for 11.6 Integer optional 0
toolchain_identifier - String required "},{"location":"user/toolchain_config_docs/#cuda_toolchain_config_nvcc_msvc","title":"cuda_toolchain_config_nvcc_msvc","text":"\ncuda_toolchain_config_nvcc_msvc(name, cuda_toolkit, msvc_env_tmp, nvcc_version_major,\n nvcc_version_minor, toolchain_identifier)\n
This rule provides the predefined cuda toolchain configuration for NVCC with MSVC as host compiler.
ATTRIBUTES
Name Description Type Mandatory Default name A unique name for this target. Name required cuda_toolkit A target that provides aCudaToolkitInfo
. Label required msvc_env_tmp The TEMP directory. String optional \"\"
nvcc_version_major The CUDA Toolkit major version, e.g, 11 for 11.6 Integer optional 0
nvcc_version_minor The CUDA Toolkit minor version, e.g, 6 for 11.6 Integer optional 0
toolchain_identifier - String required "},{"location":"user/toolchain_config_docs/#cuda_toolkit","title":"cuda_toolkit","text":"\ncuda_toolkit(name, bin2c, fatbinary, link_stub, nvlink, path, version)\n
This rule provides CudaToolkitInfo.
ATTRIBUTES
Name Description Type Mandatory Default name A unique name for this target. Name required bin2c The bin2c executable. Label optionalNone
fatbinary The fatbinary executable. Label optional None
link_stub The link.stub text file. Label optional None
nvlink The nvlink executable. Label optional None
path Root path to the CUDA Toolkit. String required version Version of the CUDA Toolkit. String required"},{"location":"user/user_docs/","title":"Using the rules","text":""},{"location":"user/user_docs/#cuda_archs","title":"cuda_archs","text":"\ncuda_archs(name)\n
A build setting for specifying cuda archs to compile for.
To retain the flexiblity of NVCC, the extended notation is adopted.
When passing cuda_archs from commandline, its spec grammar is as follows:
ARCH_SPECS ::= ARCH_SPEC [ ';' ARCH_SPECS ]\nARCH_SPEC ::= [ VIRTUAL_ARCH ':' ] GPU_ARCHS\nGPU_ARCHS ::= GPU_ARCH [ ',' GPU_ARCHS ]\nGPU_ARCH ::= 'sm_' ARCH_NUMBER\n | 'lto_' ARCH_NUMBER\n | VIRTUAL_ARCH\nVIRTUAL_ARCH ::= 'compute_' ARCH_NUMBER\n | 'lto_' ARCH_NUMBER\nARCH_NUMBER ::= (a string in predefined cuda_archs list)\n
E.g.:
compute_80:sm_80,sm_86
: Use compute_80
PTX, generate cubin with sm_80
and sm_86
, no PTX embeddedcompute_80:compute_80,sm_80,sm_86
: Use compute_80
PTX, generate cubin with sm_80
and sm_86
, PTX embeddedcompute_80:compute_80
: Embed compute_80
PTX, fully relay on ptxas
sm_80,sm_86
: Same as compute_80:sm_80,sm_86
, the arch with minimum integer value will be automatically populated.sm_80;sm_86
: Two specs used.compute_80
: Same as compute_80:compute_80
Best Practices:
ATTRIBUTES
Name Description Type Mandatory Default name A unique name for this target. Name required "},{"location":"user/user_docs/#cuda_library","title":"cuda_library","text":"\ncuda_library(name, alwayslink, copts, defines, deps, hdrs, host_copts, host_defines, host_linkopts,\n host_local_defines, includes, linkopts, local_defines, ptxasopts, rdc, srcs)\n
This rule compiles and creates static library for CUDA kernel code. The resulting targets can then be consumed by C/C++ Rules.
ATTRIBUTES
Name Description Type Mandatory Default name A unique name for this target. Name required alwayslink - Boolean optionalFalse
copts Add these options to the CUDA device compilation command. List of strings optional []
defines List of defines to add to the compile line. List of strings optional []
deps - List of labels optional []
hdrs - List of labels optional []
host_copts Add these options to the CUDA host compilation command. List of strings optional []
host_defines List of defines to add to the compile line. List of strings optional []
host_linkopts Add these flags to the host library link command. List of strings optional []
host_local_defines List of defines to add to the compile line, but only apply to this rule. List of strings optional []
includes List of include dirs to be added to the compile line. List of strings optional []
linkopts Add these flags to the CUDA device link command. List of strings optional []
local_defines List of defines to add to the compile line, but only apply to this rule. List of strings optional []
ptxasopts Add these flags to the ptxas command. List of strings optional []
rdc whether to perform relocateable device code linking, otherwise, normal device link. Boolean optional False
srcs - List of labels optional []
"},{"location":"user/user_docs/#cuda_objects","title":"cuda_objects","text":"\ncuda_objects(name, copts, defines, deps, hdrs, host_copts, host_defines, host_local_defines,\n includes, local_defines, ptxasopts, srcs)\n
This rule produces incomplete object files that can only be consumed by cuda_library
. It is created for relocatable device code and device link time optimization source files.
ATTRIBUTES
Name Description Type Mandatory Default name A unique name for this target. Name required copts Add these options to the CUDA device compilation command. List of strings optional[]
defines List of defines to add to the compile line. List of strings optional []
deps - List of labels optional []
hdrs - List of labels optional []
host_copts Add these options to the CUDA host compilation command. List of strings optional []
host_defines List of defines to add to the compile line. List of strings optional []
host_local_defines List of defines to add to the compile line, but only apply to this rule. List of strings optional []
includes List of include dirs to be added to the compile line. List of strings optional []
local_defines List of defines to add to the compile line, but only apply to this rule. List of strings optional []
ptxasopts Add these flags to the ptxas command. List of strings optional []
srcs - List of labels optional []
"},{"location":"user/user_docs/#register_detected_cuda_toolchains","title":"register_detected_cuda_toolchains","text":"\nregister_detected_cuda_toolchains()\n
Helper to register the automatically detected CUDA toolchain(s).
User can setup their own toolchain if needed and ignore the detected ones by not calling this macro.
"},{"location":"user/user_docs/#rules_cuda_dependencies","title":"rules_cuda_dependencies","text":"\nrules_cuda_dependencies(toolkit_path)\n
Populate the dependencies for rules_cuda. This will setup workspace dependencies (other bazel rules) and local toolchains.
PARAMETERS
Name Description Default Value toolkit_path Optionally specify the path to CUDA toolkit. If not specified, it will be detected automatically.None
"}]}
\ No newline at end of file
diff --git a/latest/sitemap.xml b/latest/sitemap.xml
new file mode 100644
index 00000000..0f8724ef
--- /dev/null
+++ b/latest/sitemap.xml
@@ -0,0 +1,3 @@
+
++cuda_toolchain(name, compiler_executable, compiler_files, toolchain_config) +
This rule consumes a CudaToolchainConfigInfo
and provides a platform_common.ToolchainInfo
, a.k.a, the CUDA Toolchain.
ATTRIBUTES
+Name | +Description | +Type | +Mandatory | +Default | +
---|---|---|---|---|
name | +A unique name for this target. | +Name | +required | ++ |
compiler_executable | +The path of the main executable of this toolchain. | +String | +required | ++ |
compiler_files | +The set of files that are needed when compiling using this toolchain. | +Label | +optional | +None |
+
toolchain_config | +A target that provides a CudaToolchainConfigInfo . |
+Label | +required | ++ |
+cuda_toolchain_config_clang(name, cuda_toolkit, toolchain_identifier) +
This rule provides the predefined cuda toolchain configuration for Clang.
+ATTRIBUTES
+Name | +Description | +Type | +Mandatory | +Default | +
---|---|---|---|---|
name | +A unique name for this target. | +Name | +required | ++ |
cuda_toolkit | +A target that provides a CudaToolkitInfo . |
+Label | +required | ++ |
toolchain_identifier | +- | +String | +required | ++ |
+cuda_toolchain_config_nvcc(name, cuda_toolkit, nvcc_version_major, nvcc_version_minor, + toolchain_identifier) +
This rule provides the predefined cuda toolchain configuration for NVCC with non MSVC as host compiler.
+ATTRIBUTES
+Name | +Description | +Type | +Mandatory | +Default | +
---|---|---|---|---|
name | +A unique name for this target. | +Name | +required | ++ |
cuda_toolkit | +A target that provides a CudaToolkitInfo . |
+Label | +required | ++ |
nvcc_version_major | +The CUDA Toolkit major version, e.g, 11 for 11.6 | +Integer | +optional | +0 |
+
nvcc_version_minor | +The CUDA Toolkit minor version, e.g, 6 for 11.6 | +Integer | +optional | +0 |
+
toolchain_identifier | +- | +String | +required | ++ |
+cuda_toolchain_config_nvcc_msvc(name, cuda_toolkit, msvc_env_tmp, nvcc_version_major, + nvcc_version_minor, toolchain_identifier) +
This rule provides the predefined cuda toolchain configuration for NVCC with MSVC as host compiler.
+ATTRIBUTES
+Name | +Description | +Type | +Mandatory | +Default | +
---|---|---|---|---|
name | +A unique name for this target. | +Name | +required | ++ |
cuda_toolkit | +A target that provides a CudaToolkitInfo . |
+Label | +required | ++ |
msvc_env_tmp | +The TEMP directory. | +String | +optional | +"" |
+
nvcc_version_major | +The CUDA Toolkit major version, e.g, 11 for 11.6 | +Integer | +optional | +0 |
+
nvcc_version_minor | +The CUDA Toolkit minor version, e.g, 6 for 11.6 | +Integer | +optional | +0 |
+
toolchain_identifier | +- | +String | +required | ++ |
This rule provides CudaToolkitInfo.
+ATTRIBUTES
+Name | +Description | +Type | +Mandatory | +Default | +
---|---|---|---|---|
name | +A unique name for this target. | +Name | +required | ++ |
bin2c | +The bin2c executable. | +Label | +optional | +None |
+
fatbinary | +The fatbinary executable. | +Label | +optional | +None |
+
link_stub | +The link.stub text file. | +Label | +optional | +None |
+
nvlink | +The nvlink executable. | +Label | +optional | +None |
+
path | +Root path to the CUDA Toolkit. | +String | +required | ++ |
version | +Version of the CUDA Toolkit. | +String | +required | ++ |
+cuda_archs(name) +
A build setting for specifying cuda archs to compile for.
+To retain the flexiblity of NVCC, the extended notation is adopted.
+When passing cuda_archs from commandline, its spec grammar is as follows:
+ARCH_SPECS ::= ARCH_SPEC [ ';' ARCH_SPECS ]
+ARCH_SPEC ::= [ VIRTUAL_ARCH ':' ] GPU_ARCHS
+GPU_ARCHS ::= GPU_ARCH [ ',' GPU_ARCHS ]
+GPU_ARCH ::= 'sm_' ARCH_NUMBER
+ | 'lto_' ARCH_NUMBER
+ | VIRTUAL_ARCH
+VIRTUAL_ARCH ::= 'compute_' ARCH_NUMBER
+ | 'lto_' ARCH_NUMBER
+ARCH_NUMBER ::= (a string in predefined cuda_archs list)
+
+E.g.:
+compute_80:sm_80,sm_86
:
+ Use compute_80
PTX, generate cubin with sm_80
and sm_86
, no PTX embeddedcompute_80:compute_80,sm_80,sm_86
:
+ Use compute_80
PTX, generate cubin with sm_80
and sm_86
, PTX embeddedcompute_80:compute_80
:
+ Embed compute_80
PTX, fully relay on ptxas
sm_80,sm_86
:
+ Same as compute_80:sm_80,sm_86
, the arch with minimum integer value will be automatically populated.sm_80;sm_86
:
+ Two specs used.compute_80
:
+ Same as compute_80:compute_80
Best Practices:
+ATTRIBUTES
+Name | +Description | +Type | +Mandatory | +Default | +
---|---|---|---|---|
name | +A unique name for this target. | +Name | +required | ++ |
+cuda_library(name, alwayslink, copts, defines, deps, hdrs, host_copts, host_defines, host_linkopts, + host_local_defines, includes, linkopts, local_defines, ptxasopts, rdc, srcs) +
This rule compiles and creates static library for CUDA kernel code. The resulting targets can then be consumed by +C/C++ Rules.
+ATTRIBUTES
+Name | +Description | +Type | +Mandatory | +Default | +
---|---|---|---|---|
name | +A unique name for this target. | +Name | +required | ++ |
alwayslink | +- | +Boolean | +optional | +False |
+
copts | +Add these options to the CUDA device compilation command. | +List of strings | +optional | +[] |
+
defines | +List of defines to add to the compile line. | +List of strings | +optional | +[] |
+
deps | +- | +List of labels | +optional | +[] |
+
hdrs | +- | +List of labels | +optional | +[] |
+
host_copts | +Add these options to the CUDA host compilation command. | +List of strings | +optional | +[] |
+
host_defines | +List of defines to add to the compile line. | +List of strings | +optional | +[] |
+
host_linkopts | +Add these flags to the host library link command. | +List of strings | +optional | +[] |
+
host_local_defines | +List of defines to add to the compile line, but only apply to this rule. | +List of strings | +optional | +[] |
+
includes | +List of include dirs to be added to the compile line. | +List of strings | +optional | +[] |
+
linkopts | +Add these flags to the CUDA device link command. | +List of strings | +optional | +[] |
+
local_defines | +List of defines to add to the compile line, but only apply to this rule. | +List of strings | +optional | +[] |
+
ptxasopts | +Add these flags to the ptxas command. | +List of strings | +optional | +[] |
+
rdc | +whether to perform relocateable device code linking, otherwise, normal device link. | +Boolean | +optional | +False |
+
srcs | +- | +List of labels | +optional | +[] |
+
+cuda_objects(name, copts, defines, deps, hdrs, host_copts, host_defines, host_local_defines, + includes, local_defines, ptxasopts, srcs) +
This rule produces incomplete object files that can only be consumed by cuda_library
. It is created for relocatable device
+code and device link time optimization source files.
ATTRIBUTES
+Name | +Description | +Type | +Mandatory | +Default | +
---|---|---|---|---|
name | +A unique name for this target. | +Name | +required | ++ |
copts | +Add these options to the CUDA device compilation command. | +List of strings | +optional | +[] |
+
defines | +List of defines to add to the compile line. | +List of strings | +optional | +[] |
+
deps | +- | +List of labels | +optional | +[] |
+
hdrs | +- | +List of labels | +optional | +[] |
+
host_copts | +Add these options to the CUDA host compilation command. | +List of strings | +optional | +[] |
+
host_defines | +List of defines to add to the compile line. | +List of strings | +optional | +[] |
+
host_local_defines | +List of defines to add to the compile line, but only apply to this rule. | +List of strings | +optional | +[] |
+
includes | +List of include dirs to be added to the compile line. | +List of strings | +optional | +[] |
+
local_defines | +List of defines to add to the compile line, but only apply to this rule. | +List of strings | +optional | +[] |
+
ptxasopts | +Add these flags to the ptxas command. | +List of strings | +optional | +[] |
+
srcs | +- | +List of labels | +optional | +[] |
+
+register_detected_cuda_toolchains() +
Helper to register the automatically detected CUDA toolchain(s).
+User can setup their own toolchain if needed and ignore the detected ones by not calling this macro.
+ ++rules_cuda_dependencies(toolkit_path) +
Populate the dependencies for rules_cuda. This will setup workspace dependencies (other bazel rules) and local toolchains.
+PARAMETERS
+Name | +Description | +Default Value | +
---|---|---|
toolkit_path | +Optionally specify the path to CUDA toolkit. If not specified, it will be detected automatically. | +None |
+