Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/labels.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
//cuda:gpu_compute_capability string_flag ""
//cuda:gpu_driver string_flag ""
//cuda:gpu_undeclared config_setting
//cuda:toolchain_type toolchain_type
//d:coverage config_setting
//d:toolchain_type toolchain_type
//dart:runfiles alias
Expand Down
17 changes: 13 additions & 4 deletions cuda/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("@rules_dx//core/quality:fixtures.bzl", "real_source_target")
load("//cuda/private:defs.bzl", "CUDA_COMPATIBLE_WITH", "cuda_component_library")
load("//core:platform_support.bzl", "compatible_with")
load("//cuda/private:components.bzl", "cuda_component_library")
load("//cuda/private/toolchain:settings.bzl", "PLATFORM_SUPPORT")

exports_files([
"README.md",
Expand Down Expand Up @@ -33,6 +35,13 @@ string_flag(
visibility = ["//visibility:public"],
)

# Public so users can register their own CUDA toolchain. Declared here, not in rules_cuda,
# so toolchain resolution never loads a rules_cuda .bzl file.
toolchain_type(
name = "toolchain_type",
visibility = ["//visibility:public"],
)

config_setting(
name = "gpu_undeclared",
flag_values = {":gpu_compute_capability": ""},
Expand All @@ -43,7 +52,7 @@ cuda_component_library(
name = "cublas",
component = "@cuda//:cublas",
component_name = "cublas",
target_compatible_with = CUDA_COMPATIBLE_WITH,
target_compatible_with = compatible_with(PLATFORM_SUPPORT),
visibility = ["//visibility:public"],
)

Expand All @@ -52,7 +61,7 @@ cuda_component_library(
component = "@cuda//:cufft",
component_name = "cufft",
tags = ["manual"],
target_compatible_with = CUDA_COMPATIBLE_WITH,
target_compatible_with = compatible_with(PLATFORM_SUPPORT),
visibility = ["//visibility:public"],
)

Expand All @@ -61,7 +70,7 @@ cuda_component_library(
component = "@cuda//:curand",
component_name = "curand",
tags = ["manual"],
target_compatible_with = CUDA_COMPATIBLE_WITH,
target_compatible_with = compatible_with(PLATFORM_SUPPORT),
visibility = ["//visibility:public"],
)

Expand Down
8 changes: 3 additions & 5 deletions cuda/private/toolchain/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("//core:cells.bzl", "cell_settings", "cells_compatible_with")
load("//core/modules:cuda.bzl", "CUDA_CELLS", "cuda_qualified_cells")
load("//core/quality:fixtures.bzl", "real_source_target")
load(":check.bzl", "cuda_toolkit_check")
load(":static_runtime.bzl", "cuda_windows_static_runtime")
load(":toolkit_check.bzl", "cuda_toolkit_check")

package(default_visibility = ["//visibility:public"])

Expand Down Expand Up @@ -75,16 +75,14 @@ real_source_target(
"check.bzl",
"settings.bzl",
"static_runtime.bzl",
"toolkit_check.bzl",
"transition.bzl",
],
tags = ["corpus"],
)

filegroup(
name = "module_srcs",
srcs = glob([
"*.bzl",
"BUILD.bazel",
]),
srcs = glob(["*.bzl"]) + ["BUILD.bazel"],
visibility = ["//:__subpackages__"],
)
23 changes: 0 additions & 23 deletions cuda/private/toolchain/check.bzl
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
"""Analysis-time checks for dx CUDA targets."""

load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("@rules_cuda//cuda/private:providers.bzl", "CudaToolkitInfo")
load("//core/modules:cuda.bzl", "CUDA_ARCHS", "CUDA_CELLS", "CUDA_REDIST_VERSION", "CUDA_VERSION", "cuda_qualified_cells")

_TOOLCHAIN_TYPE = "//cuda/private/toolchain/hub:toolchain_type"

def arch_errors(archs):
"""Returns one error per arch spec token that the pinned nvcc does not support."""
if not archs:
Expand Down Expand Up @@ -169,23 +166,3 @@ cuda_check = rule(
"_compiler": attr.label(default = "@rules_cuda//cuda:compiler"),
},
)

def _toolkit_check_impl(ctx):
toolchain = ctx.toolchains[_TOOLCHAIN_TYPE]
if toolchain == None:
fail("dx_cuda: no nvcc toolchain for this target; dx CUDA targets build for " + ", ".join(cuda_qualified_cells()))
toolkit = toolchain.cuda_toolkit[CudaToolkitInfo]
errors = toolkit_errors(
toolchain.compiler_executable,
toolkit.path,
"{}.{}".format(toolkit.version_major, toolkit.version_minor),
)
if errors:
fail("\n".join(errors))
return [DefaultInfo()]

cuda_toolkit_check = rule(
implementation = _toolkit_check_impl,
doc = "Fails analysis when the resolved CUDA toolchain is not the pinned nvcc toolkit.",
toolchains = [config_common.toolchain_type(_TOOLCHAIN_TYPE, mandatory = False)],
)
8 changes: 3 additions & 5 deletions cuda/private/toolchain/hub/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
load("@rules_dx//core/quality:fixtures.bzl", "real_source_target")

package(default_visibility = ["//visibility:public"])

toolchain_type(name = "toolchain_type")
package(default_visibility = ["//:__subpackages__"])

toolchain(
name = "nvcc_linux",
exec_compatible_with = ["@platforms//os:linux"],
target_compatible_with = ["@platforms//os:linux"],
target_settings = ["//config:toolchains_on"],
toolchain = "@dx_cuda_toolchain//toolchain:nvcc-linux",
toolchain_type = ":toolchain_type",
toolchain_type = "//cuda:toolchain_type",
)

toolchain(
Expand All @@ -19,7 +17,7 @@ toolchain(
target_compatible_with = ["@platforms//os:windows"],
target_settings = ["//config:toolchains_on"],
toolchain = "@dx_cuda_toolchain//toolchain:nvcc-windows",
toolchain_type = ":toolchain_type",
toolchain_type = "//cuda:toolchain_type",
)

real_source_target(
Expand Down
27 changes: 27 additions & 0 deletions cuda/private/toolchain/toolkit_check.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Analysis-time check that the resolved CUDA toolchain is the pinned nvcc toolkit."""

load("@rules_cuda//cuda/private:providers.bzl", "CudaToolkitInfo")
load("//core/modules:cuda.bzl", "cuda_qualified_cells")
load(":check.bzl", "toolkit_errors")

_TOOLCHAIN_TYPE = "//cuda:toolchain_type"

def _toolkit_check_impl(ctx):
toolchain = ctx.toolchains[_TOOLCHAIN_TYPE]
if toolchain == None:
fail("dx_cuda: no nvcc toolchain for this target; dx CUDA targets build for " + ", ".join(cuda_qualified_cells()))
toolkit = toolchain.cuda_toolkit[CudaToolkitInfo]
errors = toolkit_errors(
toolchain.compiler_executable,
toolkit.path,
"{}.{}".format(toolkit.version_major, toolkit.version_minor),
)
if errors:
fail("\n".join(errors))
return [DefaultInfo()]

cuda_toolkit_check = rule(
implementation = _toolkit_check_impl,
doc = "Fails analysis when the resolved CUDA toolchain is not the pinned nvcc toolkit.",
toolchains = [config_common.toolchain_type(_TOOLCHAIN_TYPE, mandatory = False)],
)
1 change: 1 addition & 0 deletions docs/supported-surface.md
Original file line number Diff line number Diff line change
Expand Up @@ -7380,6 +7380,7 @@ Pass a platform to Bazel with `--platforms=<platform>`.

Use a toolchain type when you register your own toolchain.

- `@rules_dx//cuda:toolchain_type`
- `@rules_dx//d:toolchain_type`
- `@rules_dx//elixir:toolchain_type`
- `@rules_dx//erlang:exec_toolchain_type`
Expand Down
2 changes: 1 addition & 1 deletion patches/rules_cuda/toolchain_type_alias.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Upstream: none (rules_dx only: aliases the toolchain type to rules_dx)
)

-toolchain_type(name = "toolchain_type")
+alias(name = "toolchain_type", actual = "@rules_dx//cuda/private/toolchain/hub:toolchain_type")
+alias(name = "toolchain_type", actual = "@rules_dx//cuda:toolchain_type")

# Command line flag to set ":is_enabled" config setting.
#
2 changes: 2 additions & 0 deletions tools/ci/pr_check_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ fn shards_come_from_the_plan() {
// target, 25,758 of them, instead of the tests `bazel test //...` runs.
assert!(plan_run.contains("let t = tests(set("), "{plan_run}");
assert!(plan_run.contains("(manual|"), "{plan_run}");
// dx test takes main-workspace labels only.
assert!(plan_run.contains("($t intersect //...)"), "{plan_run}");
assert!(plan_run.contains("range(0; length; $per)"), "{plan_run}");
assert!(plan_run.contains("echo \"labels=$slices\""), "{plan_run}");
let affected = job(WORKFLOW, "affected").unwrap();
Expand Down
Loading