Skip to content

Commit

Permalink
Merge branch 'bazel-contrib:main' into aarch64Support
Browse files Browse the repository at this point in the history
  • Loading branch information
dmellosanjay authored Jan 3, 2024
2 parents acf49f9 + 9b7eccd commit 78ab2fd
Show file tree
Hide file tree
Showing 15 changed files with 135 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.3.2
6.4.0
9 changes: 5 additions & 4 deletions .github/workflows/github-pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
docs:
# { ref: <branch/tag name>, name: <docs drop down entry> }
- { ref: main, name: latest }
- { ref: v0.2.1, name: 0.2.1 }
steps:
- uses: actions/checkout@v4
if: ${{ matrix.docs.ref == 'main' }}
Expand All @@ -31,7 +32,7 @@ jobs:
path: ~/.cache/bazel
key: bazel-gen-docs-${{ matrix.docs.ref }}

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: pip
Expand All @@ -44,7 +45,7 @@ jobs:

- run: bazelisk shutdown

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: "${{ matrix.docs.name }}"
path: ${{ github.workspace }}/docs/site/
Expand All @@ -58,13 +59,13 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
path: ${{ github.workspace }}/docs/generated
- name: Inspect docs site directory structure
run: find ${{ github.workspace }}/docs/generated -maxdepth 2

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ jobs:
status: ${{ job.status }}

- name: Add comment to PR
uses: actions/github-script@v6
uses: actions/github-script@v7
if: always()
with:
script: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
echo "ARCHIVE_SHA256=$(shasum -a 256 ${{ github.workspace }}/.github/rules_cuda.tar.gz | cut -d ' ' -f 1)" >> $GITHUB_ENV
echo "RELEASE_VERSION=${GITHUB_REF_NAME}" >> $GITHUB_ENV
# Upload the artifact in case creating a release fails so all artifacts can then be manually recovered.
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: "rules_cuda.tar.gz"
path: ${{ github.workspace }}/.github/rules_cuda.tar.gz
Expand Down
5 changes: 5 additions & 0 deletions cuda/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ load("//cuda/private:providers.bzl", _CudaArchsInfo = "CudaArchsInfo", _cuda_arc
load("//cuda/private:os_helpers.bzl", _cc_import_versioned_sos = "cc_import_versioned_sos", _if_linux = "if_linux", _if_windows = "if_windows")
load("//cuda/private:rules/cuda_objects.bzl", _cuda_objects = "cuda_objects")
load("//cuda/private:rules/cuda_library.bzl", _cuda_library = "cuda_library")
load("//cuda/private:macros/cuda_binary.bzl", _cuda_binary = "cuda_binary")
load("//cuda/private:macros/cuda_test.bzl", _cuda_test = "cuda_test")
load("//cuda/private:rules/cuda_toolkit.bzl", _cuda_toolkit = "cuda_toolkit")
load(
Expand All @@ -29,8 +30,12 @@ cuda_toolchain_config_nvcc = _cuda_toolchain_config_nvcc
cuda_archs = _cuda_archs
CudaArchsInfo = _CudaArchsInfo

# rules
cuda_objects = _cuda_objects
cuda_library = _cuda_library

# macros
cuda_binary = _cuda_binary
cuda_test = _cuda_test

if_linux = _if_linux
Expand Down
5 changes: 5 additions & 0 deletions cuda/private/cuda_helper.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_skylib//lib:types.bzl", "types")
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
load("//cuda/private:action_names.bzl", "ACTION_NAMES")
load("//cuda/private:artifact_categories.bzl", "ARTIFACT_CATEGORIES")
load("//cuda/private:providers.bzl", "ArchSpecInfo", "CudaArchsInfo", "CudaInfo", "Stage2ArchInfo", "cuda_archs")
Expand Down Expand Up @@ -242,6 +243,8 @@ def _create_common(ctx):

merged_cc_info = cc_common.merge_cc_infos(cc_infos = [dep[CcInfo] for dep in all_cc_deps])

cc_toolchain = find_cpp_toolchain(ctx)

# gather include info
includes = merged_cc_info.compilation_context.includes.to_list()
system_includes = []
Expand Down Expand Up @@ -276,6 +279,8 @@ def _create_common(ctx):
host_defines = []
host_local_defines = [i for i in attr.host_local_defines]
host_compile_flags = attr._default_host_copts[BuildSettingInfo].value + [i for i in attr.host_copts]
if cc_toolchain.sysroot:
host_compile_flags.append("--sysroot={}".format(cc_toolchain.sysroot))
host_link_flags = []
if hasattr(attr, "host_linkopts"):
host_link_flags.extend([i for i in attr.host_linkopts])
Expand Down
21 changes: 21 additions & 0 deletions cuda/private/macros/cuda_binary.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
load("//cuda/private:rules/cuda_library.bzl", _cuda_library = "cuda_library")

def cuda_binary(name, **attrs):
"""Wrapper to ensure the binary is compiled with the CUDA compiler."""
cuda_library_only_attrs = ["deps", "srcs", "hdrs"]

# https://bazel.build/reference/be/common-definitions?hl=en#common-attributes-binaries
cc_binary_only_attrs = ["args", "env", "output_licenses"]

cuda_library_name = "_" + name

_cuda_library(
name = cuda_library_name,
**{k: v for k, v in attrs.items() if k not in cc_binary_only_attrs}
)

native.cc_binary(
name = name,
deps = [cuda_library_name],
**{k: v for k, v in attrs.items() if k not in cuda_library_only_attrs}
)
9 changes: 7 additions & 2 deletions cuda/private/macros/cuda_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@ load("//cuda/private:rules/cuda_library.bzl", _cuda_library = "cuda_library")

def cuda_test(name, **attrs):
"""Wrapper to ensure the test is compiled with the CUDA compiler."""
cuda_library_only_attrs = ["deps", "srcs", "hdrs"]

# https://bazel.build/reference/be/common-definitions?hl=en#common-attributes-tests
cc_test_only_attrs = ["args", "env", "env_inherit", "size", "timeout", "flaky", "shard_count", "local"]

cuda_library_name = "_" + name

_cuda_library(
name = cuda_library_name,
testonly = True,
**attrs
**{k: v for k, v in attrs.items() if k not in cc_test_only_attrs}
)

native.cc_test(
name = name,
deps = [cuda_library_name],
**{k: v for k, v in attrs.items() if k != "deps"}
**{k: v for k, v in attrs.items() if k not in cuda_library_only_attrs}
)
50 changes: 34 additions & 16 deletions cuda/runtime/BUILD.local_cuda
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,24 @@ filegroup(
name = "compiler_deps",
srcs = [
":_cuda_header_files",
] + glob([
"cuda/version.txt",
"cuda/version.json",
"cuda/bin/**",
"cuda/lib64/**",
"cuda/nvvm/**",
]),
] + glob(
[
"cuda/version.json",
"cuda/version.txt",
"cuda/bin/**",
"cuda/lib64/**",
"cuda/nvvm/**",
],
allow_empty = True,
),
)

filegroup(
name = "_cuda_header_files",
srcs = glob(["cuda/include/**"]),
srcs = glob(
["cuda/include/**"],
allow_empty = True,
),
visibility = ["//visibility:private"],
)

Expand Down Expand Up @@ -174,15 +180,21 @@ cc_library(

cc_library(
name = "cub",
hdrs = glob(["cuda/include/cub/**"]),
hdrs = glob(
["cuda/include/cub/**"],
allow_empty = True,
),
includes = [
"cuda/include",
],
)

cc_library(
name = "thrust",
hdrs = glob(["cuda/include/thrust/**"]),
hdrs = glob(
["cuda/include/thrust/**"],
allow_empty = True,
),
includes = [
"cuda/include",
],
Expand All @@ -204,7 +216,10 @@ cc_import(

cc_library(
name = "cupti_headers",
hdrs = glob(["cuda/extras/CUPTI/include/*.h"]),
hdrs = glob(
["cuda/extras/CUPTI/include/*.h"],
allow_empty = True,
),
includes = ["cuda/extras/CUPTI/include"],
)

Expand Down Expand Up @@ -337,11 +352,14 @@ cc_import(
cc_library(
name = "nvptxcompiler",
srcs = [],
hdrs = glob([
"cuda/include/fatbinary_section.h",
"cuda/include/nvPTXCompiler.h",
"cuda/include/crt/*",
]),
hdrs = glob(
[
"cuda/include/fatbinary_section.h",
"cuda/include/nvPTXCompiler.h",
"cuda/include/crt/*",
],
allow_empty = True,
),
includes = [
"cuda/include",
],
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mkdocs-material==9.4.2
mkdocs-material==9.5.3
4 changes: 3 additions & 1 deletion docs/user_docs.bzl
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
load("@rules_cuda//cuda:defs.bzl", _cuda_library = "cuda_library", _cuda_objects = "cuda_objects", _cuda_test = "cuda_test")
load("@rules_cuda//cuda:defs.bzl", _cuda_binary = "cuda_binary", _cuda_library = "cuda_library", _cuda_objects = "cuda_objects", _cuda_test = "cuda_test")
load("@rules_cuda//cuda:repositories.bzl", _register_detected_cuda_toolchains = "register_detected_cuda_toolchains", _rules_cuda_dependencies = "rules_cuda_dependencies")
load("@rules_cuda//cuda/private:rules/flags.bzl", _cuda_archs_flag = "cuda_archs_flag")

cuda_library = _cuda_library
cuda_objects = _cuda_objects

cuda_binary = _cuda_binary
cuda_test = _cuda_test

cuda_archs = _cuda_archs_flag
Expand Down
12 changes: 6 additions & 6 deletions examples/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ http_archive(
name = "nccl",
add_prefix = "nccl",
build_file = "@rules_cuda_examples//nccl:nccl.BUILD",
sha256 = "0de8aed51bf95c96c14bc801ba840eb5b5df527e7105b1f42a58ad5d4d617678",
strip_prefix = "nccl-4365458757e4107ecbf629b2fd6e0e19a5d237c2",
urls = ["https://github.com/nvidia/nccl/archive/4365458757e4107ecbf629b2fd6e0e19a5d237c2.tar.gz"],
sha256 = "83b299cfc2dfe63887dadf3590b3ac2b8b2fd68ec5515b6878774eda39a697d2",
strip_prefix = "nccl-9814c75eea18fc7374cde884592233b6b7dc055b",
urls = ["https://github.com/nvidia/nccl/archive/9814c75eea18fc7374cde884592233b6b7dc055b.tar.gz"],
)

http_archive(
Expand All @@ -41,7 +41,7 @@ http_archive(
"-p1",
],
patches = ["@rules_cuda_examples//nccl:nccl-tests-clang.patch"],
sha256 = "fe0bdc0fdfba75a9326b32381ce486b99aa5e6189181fbf92baa4f6153961c3f",
strip_prefix = "nccl-tests-6c46206a478203b6453035fe0d40dc6418acd089",
urls = ["https://github.com/nvidia/nccl-tests/archive/6c46206a478203b6453035fe0d40dc6418acd089.tar.gz"],
sha256 = "946adb84f63aec66aea7aab9739d41df81c24f783e85fba6328ba243cfc057e0",
strip_prefix = "nccl-tests-1a5f551ffd6e3271982b03a9d5653a3f6ba545fa",
urls = ["https://github.com/nvidia/nccl-tests/archive/1a5f551ffd6e3271982b03a9d5653a3f6ba545fa.tar.gz"],
)
13 changes: 13 additions & 0 deletions examples/basic_macros/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load("@rules_cuda//cuda:defs.bzl", "cuda_binary", "cuda_test")

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

cuda_binary(
name = "main",
srcs = ["main.cu"],
)

cuda_test(
name = "test",
srcs = ["main.cu"],
)
26 changes: 26 additions & 0 deletions examples/basic_macros/main.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <cstdio>

#define CUDA_CHECK(expr) \
do { \
cudaError_t err = (expr); \
if (err != cudaSuccess) { \
fprintf(stderr, "CUDA Error Code : %d\n Error String: %s\n", \
err, cudaGetErrorString(err)); \
exit(err); \
} \
} while (0)

__global__ void kernel() {
printf("cuda kernel called!\n");
}

void launch() {
kernel<<<1, 1>>>();
CUDA_CHECK(cudaGetLastError());
CUDA_CHECK(cudaDeviceSynchronize());
}

int main() {
launch();
return 0;
}
6 changes: 6 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["config:base"],
"ignorePaths": ["MODULE.bazel"],
"packageRules": [
{
"matchManagers": ["bazel", "bazel-module"],
"excludePackageNames": ["nccl", "nccl-tests"]
}
],
"schedule": ["on the first day of the month"]
}

0 comments on commit 78ab2fd

Please sign in to comment.