From 567c3051d8b222f44305b7fbea38d8f9e7bbff71 Mon Sep 17 00:00:00 2001 From: Cloud Han Date: Wed, 10 Jan 2024 22:55:54 +0800 Subject: [PATCH 01/13] Update to v7 --- .bazelversion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bazelversion b/.bazelversion index 19b860c1..66ce77b7 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -6.4.0 +7.0.0 From a06ddda19f993f45d3663a23284499615f78ff72 Mon Sep 17 00:00:00 2001 From: Cloud Han Date: Wed, 10 Jan 2024 22:56:59 +0800 Subject: [PATCH 02/13] Support bzlmod for docs --- docs/MODULE.bazel | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 docs/MODULE.bazel diff --git a/docs/MODULE.bazel b/docs/MODULE.bazel new file mode 100644 index 00000000..8b57a410 --- /dev/null +++ b/docs/MODULE.bazel @@ -0,0 +1,15 @@ +module( + name = "rules_cuda_docs", + version = "0.0.0", + compatibility_level = 1, +) + +bazel_dep(name = "rules_cuda", version = "0.2.1") +local_path_override( + module_name = "rules_cuda", + path = "..", +) + +# NOTE: cuda toolchain needs to be additionally configured. But is not required for stardoc. + +bazel_dep(name = "stardoc", version = "0.6.2") From 0893bbb40a1052e08ceb9017d89c802da423422e Mon Sep 17 00:00:00 2001 From: Cloud Han Date: Wed, 10 Jan 2024 23:19:09 +0800 Subject: [PATCH 03/13] stardoc still needs cuda toolchain to be configured, but other docs gen process failed... --- docs/MODULE.bazel | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/MODULE.bazel b/docs/MODULE.bazel index 8b57a410..3f37a7a9 100644 --- a/docs/MODULE.bazel +++ b/docs/MODULE.bazel @@ -10,6 +10,11 @@ local_path_override( path = "..", ) -# NOTE: cuda toolchain needs to be additionally configured. But is not required for stardoc. +cuda = use_extension("@rules_cuda//cuda:extensions.bzl", "toolchain") +cuda.local_toolchain( + name = "local_cuda", + toolkit_path = "", +) +use_repo(cuda, "local_cuda") bazel_dep(name = "stardoc", version = "0.6.2") From 49dd760f85e012e07f3eb991b9b8c4ccd409d5e7 Mon Sep 17 00:00:00 2001 From: Cloud Han Date: Wed, 10 Jan 2024 23:21:26 +0800 Subject: [PATCH 04/13] Configure nccl example for bzlmod --- examples/MODULE.bazel | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/examples/MODULE.bazel b/examples/MODULE.bazel index 9fafb646..bbbd084b 100644 --- a/examples/MODULE.bazel +++ b/examples/MODULE.bazel @@ -16,3 +16,33 @@ cuda.local_toolchain( toolkit_path = "", ) use_repo(cuda, "local_cuda") + +################################# +# Dependencies for nccl example # +################################# +http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +bazel_dep(name = "bazel_skylib", version = "1.4.2") + +http_archive( + name = "nccl", + add_prefix = "nccl", + build_file = "@rules_cuda_examples//nccl:nccl.BUILD", + sha256 = "83b299cfc2dfe63887dadf3590b3ac2b8b2fd68ec5515b6878774eda39a697d2", + strip_prefix = "nccl-9814c75eea18fc7374cde884592233b6b7dc055b", + urls = ["https://github.com/nvidia/nccl/archive/9814c75eea18fc7374cde884592233b6b7dc055b.tar.gz"], +) + +http_archive( + name = "nccl-tests", + add_prefix = "nccl-tests", + build_file = "@rules_cuda_examples//nccl:nccl-tests.BUILD", + patch_args = [ + "--directory=nccl-tests", + "-p1", + ], + patches = ["@rules_cuda_examples//nccl:nccl-tests-clang.patch"], + sha256 = "946adb84f63aec66aea7aab9739d41df81c24f783e85fba6328ba243cfc057e0", + strip_prefix = "nccl-tests-1a5f551ffd6e3271982b03a9d5653a3f6ba545fa", + urls = ["https://github.com/nvidia/nccl-tests/archive/1a5f551ffd6e3271982b03a9d5653a3f6ba545fa.tar.gz"], +) From 203880fcfe1d34b340bc83dff834ae173c2c194b Mon Sep 17 00:00:00 2001 From: Cloud Han Date: Wed, 10 Jan 2024 23:42:04 +0800 Subject: [PATCH 05/13] Make docs gen work again --- docs/BUILD.bazel | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/BUILD.bazel b/docs/BUILD.bazel index 417a2191..0f25e5f8 100644 --- a/docs/BUILD.bazel +++ b/docs/BUILD.bazel @@ -1,32 +1,38 @@ load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc") +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + +bzl_library( + name = "bazel_tools_bzl_srcs", + srcs = ["@bazel_tools//tools:bzl_srcs"], +) # NOTE: when the `out` is changed, the `nav` part of `mkdocs.yaml` must be also be changed correspondingly. stardoc( name = "user_docs", out = "user/user_docs.md", input = "user_docs.bzl", - deps = ["@rules_cuda//:bzl_srcs"], + deps = ["@rules_cuda//:bzl_srcs", ":bazel_tools_bzl_srcs"], ) stardoc( name = "toolchain_config_docs", out = "user/toolchain_config_docs.md", input = "toolchain_config_docs.bzl", - deps = ["@rules_cuda//:bzl_srcs"], + deps = ["@rules_cuda//:bzl_srcs", ":bazel_tools_bzl_srcs"], ) stardoc( name = "providers_docs", out = "developer/providers_docs.md", input = "providers_docs.bzl", - deps = ["@rules_cuda//:bzl_srcs"], + deps = ["@rules_cuda//:bzl_srcs", ":bazel_tools_bzl_srcs"], ) stardoc( name = "developer_docs", out = "developer/developer_docs.md", input = "developer_docs.bzl", - deps = ["@rules_cuda//:bzl_srcs"], + deps = ["@rules_cuda//:bzl_srcs", ":bazel_tools_bzl_srcs"], ) filegroup( From 049a9bf02cbccf733ff70ec102c5e13811eda167 Mon Sep 17 00:00:00 2001 From: Cloud Han Date: Thu, 11 Jan 2024 09:20:27 +0800 Subject: [PATCH 06/13] Fix examples building from top-level rules_cuda dir --- MODULE.bazel | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 18571bb0..786cd3c4 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -7,8 +7,12 @@ module( bazel_dep(name = "bazel_skylib", version = "1.4.2") bazel_dep(name = "platforms", version = "0.0.6") -toolchain = use_extension("@rules_cuda//cuda:extensions.bzl", "toolchain") -use_repo(toolchain, "local_cuda") +cuda = use_extension("@rules_cuda//cuda:extensions.bzl", "toolchain") +cuda.local_toolchain( + name = "local_cuda", + toolkit_path = "", +) +use_repo(cuda, "local_cuda") register_toolchains( "@local_cuda//toolchain:nvcc-local-toolchain", From ec72b39b0146edff39bca6b5b4a9e512d3c5f71f Mon Sep 17 00:00:00 2001 From: Cloud Han Date: Thu, 11 Jan 2024 09:21:17 +0800 Subject: [PATCH 07/13] Format --- docs/BUILD.bazel | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/docs/BUILD.bazel b/docs/BUILD.bazel index 0f25e5f8..1da1241d 100644 --- a/docs/BUILD.bazel +++ b/docs/BUILD.bazel @@ -11,28 +11,40 @@ stardoc( name = "user_docs", out = "user/user_docs.md", input = "user_docs.bzl", - deps = ["@rules_cuda//:bzl_srcs", ":bazel_tools_bzl_srcs"], + deps = [ + ":bazel_tools_bzl_srcs", + "@rules_cuda//:bzl_srcs", + ], ) stardoc( name = "toolchain_config_docs", out = "user/toolchain_config_docs.md", input = "toolchain_config_docs.bzl", - deps = ["@rules_cuda//:bzl_srcs", ":bazel_tools_bzl_srcs"], + deps = [ + ":bazel_tools_bzl_srcs", + "@rules_cuda//:bzl_srcs", + ], ) stardoc( name = "providers_docs", out = "developer/providers_docs.md", input = "providers_docs.bzl", - deps = ["@rules_cuda//:bzl_srcs", ":bazel_tools_bzl_srcs"], + deps = [ + ":bazel_tools_bzl_srcs", + "@rules_cuda//:bzl_srcs", + ], ) stardoc( name = "developer_docs", out = "developer/developer_docs.md", input = "developer_docs.bzl", - deps = ["@rules_cuda//:bzl_srcs", ":bazel_tools_bzl_srcs"], + deps = [ + ":bazel_tools_bzl_srcs", + "@rules_cuda//:bzl_srcs", + ], ) filegroup( From 652c1d60aa4905ed3263e67e9142d8d665766c44 Mon Sep 17 00:00:00 2001 From: Cloud Han Date: Mon, 15 Jan 2024 23:41:10 +0800 Subject: [PATCH 08/13] Stop configuring toolchains for @rules_cuda --- MODULE.bazel | 4 ---- 1 file changed, 4 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 786cd3c4..db31f739 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -8,10 +8,6 @@ bazel_dep(name = "bazel_skylib", version = "1.4.2") bazel_dep(name = "platforms", version = "0.0.6") cuda = use_extension("@rules_cuda//cuda:extensions.bzl", "toolchain") -cuda.local_toolchain( - name = "local_cuda", - toolkit_path = "", -) use_repo(cuda, "local_cuda") register_toolchains( From aa18723e1780e913e9a4975a3ffc781cfe5c88e5 Mon Sep 17 00:00:00 2001 From: Cloud Han Date: Mon, 15 Jan 2024 23:42:00 +0800 Subject: [PATCH 09/13] Stop filtering INFO log --- examples/.bazelrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/.bazelrc b/examples/.bazelrc index 879679ea..d38c59e8 100644 --- a/examples/.bazelrc +++ b/examples/.bazelrc @@ -14,6 +14,6 @@ build:clang --repo_env=CC=clang build:clang --@rules_cuda//cuda:compiler=clang # https://github.com/bazel-contrib/rules_cuda/issues/1 -build --ui_event_filters=-INFO +# build --ui_event_filters=-INFO common:bzlmod --enable_bzlmod From e699888b2120c4941b11dc6fec3cd7daba3b4be7 Mon Sep 17 00:00:00 2001 From: Cloud Han Date: Mon, 15 Jan 2024 23:42:49 +0800 Subject: [PATCH 10/13] Adjust CI config for bazel7 and add some old versions for LTS --- .github/workflows/build-tests.yaml | 38 ++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-tests.yaml b/.github/workflows/build-tests.yaml index 1e1c2365..5dc421e7 100644 --- a/.github/workflows/build-tests.yaml +++ b/.github/workflows/build-tests.yaml @@ -56,14 +56,42 @@ jobs: echo "build --config=clang" > $HOME/.bazelrc echo "build:clang --@rules_cuda//cuda:archs=sm_80" >> $HOME/.bazelrc + # Check https://bazel.build/release#support-matrix, manually unroll the the strategy matrix to avoid exploding + # the combinations. + + # Use Bazel with version specified in .bazelversion + # out of @examples repo build requires WORKSPACE-based external dependency system + - run: bazelisk build --noenable_bzlmod @rules_cuda_examples//basic:all + - run: bazelisk build --noenable_bzlmod @rules_cuda_examples//rdc:all + - run: bazelisk build --noenable_bzlmod @rules_cuda_examples//if_cuda:main + - run: bazelisk build --noenable_bzlmod @rules_cuda_examples//if_cuda:main --enable_cuda=False + # in @examples repo build, bzlmod is enabled by default since Bazel 7 + - run: cd examples && bazelisk build //basic:all + - run: cd examples && bazelisk build //rdc:all + - run: cd examples && bazelisk build //if_cuda:main + - run: cd examples && bazelisk build //if_cuda:main --enable_cuda=False + - run: bazelisk shutdown + + # Use Bazel 6 + - run: echo "USE_BAZEL_VERSION=6.4.0" >> $GITHUB_ENV - run: bazelisk build @rules_cuda_examples//basic:all - run: bazelisk build @rules_cuda_examples//rdc:all - run: bazelisk build @rules_cuda_examples//if_cuda:main - run: bazelisk build @rules_cuda_examples//if_cuda:main --enable_cuda=False + - run: cd examples && bazelisk build --config=bzlmod //basic:all + - run: cd examples && bazelisk build --config=bzlmod //rdc:all + - run: cd examples && bazelisk build --config=bzlmod //if_cuda:main + - run: cd examples && bazelisk build --config=bzlmod //if_cuda:main --enable_cuda=False + - run: bazelisk shutdown - - run: cd examples && bazelisk build //basic:all --config=bzlmod - - run: cd examples && bazelisk build //rdc:all --config=bzlmod - - run: cd examples && bazelisk build //if_cuda:main --config=bzlmod - - run: cd examples && bazelisk build //if_cuda:main --enable_cuda=False --config=bzlmod - + # Use Bazel 5 + - run: echo "USE_BAZEL_VERSION=5.4.1" >> $GITHUB_ENV + - run: bazelisk build @rules_cuda_examples//basic:all + - run: bazelisk build @rules_cuda_examples//rdc:all + - run: bazelisk build @rules_cuda_examples//if_cuda:main + - run: bazelisk build @rules_cuda_examples//if_cuda:main --enable_cuda=False + - run: cd examples && bazelisk build --config=bzlmod //basic:all + - run: cd examples && bazelisk build --config=bzlmod //rdc:all + - run: cd examples && bazelisk build --config=bzlmod //if_cuda:main + - run: cd examples && bazelisk build --config=bzlmod //if_cuda:main --enable_cuda=False - run: bazelisk shutdown From 2c7bd52c8a85e10e1bd068e04d7a3f5102902cc2 Mon Sep 17 00:00:00 2001 From: Cloud Han Date: Tue, 16 Jan 2024 00:27:31 +0800 Subject: [PATCH 11/13] Move part of nccl example deps from MODULE.bazel to WORKSPACE.bzlmod due to `use_repo_rule` compatibility issue --- examples/MODULE.bazel | 26 +------------------------- examples/WORKSPACE.bzlmod | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/examples/MODULE.bazel b/examples/MODULE.bazel index bbbd084b..0a416fcd 100644 --- a/examples/MODULE.bazel +++ b/examples/MODULE.bazel @@ -20,29 +20,5 @@ use_repo(cuda, "local_cuda") ################################# # Dependencies for nccl example # ################################# -http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - +# See WORKSPACE.bzlmod for the remaining parts bazel_dep(name = "bazel_skylib", version = "1.4.2") - -http_archive( - name = "nccl", - add_prefix = "nccl", - build_file = "@rules_cuda_examples//nccl:nccl.BUILD", - sha256 = "83b299cfc2dfe63887dadf3590b3ac2b8b2fd68ec5515b6878774eda39a697d2", - strip_prefix = "nccl-9814c75eea18fc7374cde884592233b6b7dc055b", - urls = ["https://github.com/nvidia/nccl/archive/9814c75eea18fc7374cde884592233b6b7dc055b.tar.gz"], -) - -http_archive( - name = "nccl-tests", - add_prefix = "nccl-tests", - build_file = "@rules_cuda_examples//nccl:nccl-tests.BUILD", - patch_args = [ - "--directory=nccl-tests", - "-p1", - ], - patches = ["@rules_cuda_examples//nccl:nccl-tests-clang.patch"], - sha256 = "946adb84f63aec66aea7aab9739d41df81c24f783e85fba6328ba243cfc057e0", - strip_prefix = "nccl-tests-1a5f551ffd6e3271982b03a9d5653a3f6ba545fa", - urls = ["https://github.com/nvidia/nccl-tests/archive/1a5f551ffd6e3271982b03a9d5653a3f6ba545fa.tar.gz"], -) diff --git a/examples/WORKSPACE.bzlmod b/examples/WORKSPACE.bzlmod index e69de29b..97c6ca7f 100644 --- a/examples/WORKSPACE.bzlmod +++ b/examples/WORKSPACE.bzlmod @@ -0,0 +1,31 @@ +################################# +# Dependencies for nccl example # +################################# +# NOTE: this should have been placed in MODULE.bazel, but use_repo_rule is introduced in Bazel 7. +# See https://github.com/bazelbuild/bazel/issues/17141 + +# http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") # For MODULE.bazel +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") # For WORKSPACE.bazel + +http_archive( + name = "nccl", + add_prefix = "nccl", + build_file = "@rules_cuda_examples//nccl:nccl.BUILD", + sha256 = "83b299cfc2dfe63887dadf3590b3ac2b8b2fd68ec5515b6878774eda39a697d2", + strip_prefix = "nccl-9814c75eea18fc7374cde884592233b6b7dc055b", + urls = ["https://github.com/nvidia/nccl/archive/9814c75eea18fc7374cde884592233b6b7dc055b.tar.gz"], +) + +http_archive( + name = "nccl-tests", + add_prefix = "nccl-tests", + build_file = "@rules_cuda_examples//nccl:nccl-tests.BUILD", + patch_args = [ + "--directory=nccl-tests", + "-p1", + ], + patches = ["@rules_cuda_examples//nccl:nccl-tests-clang.patch"], + sha256 = "946adb84f63aec66aea7aab9739d41df81c24f783e85fba6328ba243cfc057e0", + strip_prefix = "nccl-tests-1a5f551ffd6e3271982b03a9d5653a3f6ba545fa", + urls = ["https://github.com/nvidia/nccl-tests/archive/1a5f551ffd6e3271982b03a9d5653a3f6ba545fa.tar.gz"], +) From fb840752885616acf08b1d143aa9060654e15257 Mon Sep 17 00:00:00 2001 From: Cloud Han Date: Tue, 16 Jan 2024 00:39:27 +0800 Subject: [PATCH 12/13] Remove tests for old versions, leaving them for future PR --- .github/workflows/build-tests.yaml | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/.github/workflows/build-tests.yaml b/.github/workflows/build-tests.yaml index 5dc421e7..e1fe1625 100644 --- a/.github/workflows/build-tests.yaml +++ b/.github/workflows/build-tests.yaml @@ -56,9 +56,6 @@ jobs: echo "build --config=clang" > $HOME/.bazelrc echo "build:clang --@rules_cuda//cuda:archs=sm_80" >> $HOME/.bazelrc - # Check https://bazel.build/release#support-matrix, manually unroll the the strategy matrix to avoid exploding - # the combinations. - # Use Bazel with version specified in .bazelversion # out of @examples repo build requires WORKSPACE-based external dependency system - run: bazelisk build --noenable_bzlmod @rules_cuda_examples//basic:all @@ -71,27 +68,3 @@ jobs: - run: cd examples && bazelisk build //if_cuda:main - run: cd examples && bazelisk build //if_cuda:main --enable_cuda=False - run: bazelisk shutdown - - # Use Bazel 6 - - run: echo "USE_BAZEL_VERSION=6.4.0" >> $GITHUB_ENV - - run: bazelisk build @rules_cuda_examples//basic:all - - run: bazelisk build @rules_cuda_examples//rdc:all - - run: bazelisk build @rules_cuda_examples//if_cuda:main - - run: bazelisk build @rules_cuda_examples//if_cuda:main --enable_cuda=False - - run: cd examples && bazelisk build --config=bzlmod //basic:all - - run: cd examples && bazelisk build --config=bzlmod //rdc:all - - run: cd examples && bazelisk build --config=bzlmod //if_cuda:main - - run: cd examples && bazelisk build --config=bzlmod //if_cuda:main --enable_cuda=False - - run: bazelisk shutdown - - # Use Bazel 5 - - run: echo "USE_BAZEL_VERSION=5.4.1" >> $GITHUB_ENV - - run: bazelisk build @rules_cuda_examples//basic:all - - run: bazelisk build @rules_cuda_examples//rdc:all - - run: bazelisk build @rules_cuda_examples//if_cuda:main - - run: bazelisk build @rules_cuda_examples//if_cuda:main --enable_cuda=False - - run: cd examples && bazelisk build --config=bzlmod //basic:all - - run: cd examples && bazelisk build --config=bzlmod //rdc:all - - run: cd examples && bazelisk build --config=bzlmod //if_cuda:main - - run: cd examples && bazelisk build --config=bzlmod //if_cuda:main --enable_cuda=False - - run: bazelisk shutdown From 23b726402b1f91a7b3adb4b882cfd9cc566beebe Mon Sep 17 00:00:00 2001 From: Cloud Han Date: Tue, 16 Jan 2024 09:24:28 +0800 Subject: [PATCH 13/13] Workaround bazel bug See https://github.com/bazelbuild/bazel/issues/20906 --- .bazelignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.bazelignore b/.bazelignore index 197a94b0..37fa09a7 100644 --- a/.bazelignore +++ b/.bazelignore @@ -1,3 +1,2 @@ -bazel-* docs examples